Skip to content

Commit 128578d

Browse files
authored
Fixes on framebuffer chapter (#90)
* Fixes on frambeuffer chapter * Fix typo
1 parent ce27ce2 commit 128578d

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

03_Video_Output/01_Framebuffer.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ In these chapters we're going to use a linear framebuffer, since it's the only f
1515
One way to enable framebuffer is asking grub to do it (this can be done also using uefi but it is not covered in this chapter).
1616

1717
To enable it, we need to add the relevant tag in the multiboot2 header.
18-
Simply we just need to add in the tag section a new item, like the one below, to request to grub to enable the framebuffer if avaiable, with the requested configuration:
18+
Simply we just need to add in the tag section a new item, like the one below, to request to grub to enable the framebuffer if available, with the requested configuration:
1919

2020
```assembly
2121
framebuffer_tag_start:
@@ -28,7 +28,7 @@ framebuffer_tag_start:
2828
framebuffer_tag_end:
2929
```
3030

31-
The comments are self explanatory.
31+
In this case we let the bootloader decide for us the framebuffer configuration. `Width` and `Heigth` field are self explanatory, while the `depth` field indicates the number of bits per pixel in a graphic mode.
3232

3333
## Accessing the Framebuffer
3434

@@ -148,16 +148,18 @@ where `logo_data` is a pointer to the image content and `pixel` is an array of 4
148148
Now since each pixel is identified by 3 colors and we have 4 elements into an array, we know that the last element (`pixel[3]`) is always zero. The color is encoded in RGB format with Blue being the least significant byte, and to plot that pixel we need to fill a 32 bit address, so the array need to be converted into a `uint32_t` variable, this can easily be done with some bitwise operations:
149149
150150
```c
151-
char pixel[4];
151+
unsigned char pixel[4];
152152
HEADER_PIXEL(logo_data, pixel)
153153
pixel[3] = 0;
154-
uint32_t num = (uint32_t) pixel[0] << 24 |
155-
(uint32_t)pixel[1] << 16 |
156-
(uint32_t)pixel[2] << 8 |
157-
(uint32_t)pixel[3];
154+
uint32_t num = (uint32_t) pixel[3] << 24 |
155+
(uint32_t)pixel[0] << 16 |
156+
(uint32_t)pixel[1] << 8 |
157+
(uint32_t)pixel[2];
158158
159159
```
160160

161+
Note that we used a `unsigned char` type, while gimp is providing for a `static char` type, the reason is because `char` type can be signed or unsigned depending on the platform. So if values are greater than 127 are used, they may be intended as negative values, if `char` is signed, when they are cast to `uint32_t` the sign can be extended, leading unexpected results.
162+
161163
In the code above we are making sure that the value of `pixel[3]` is zero, since the `HEADER_PIXEL` function is not touching it. Now the value of `num` will be the colour of the pixel to be plotted.
162164

163165
With this value we can call the function we have created to plot the pixel with the color indicated by `num`.

0 commit comments

Comments
 (0)