You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 03_Video_Output/01_Framebuffer.md
+9-7Lines changed: 9 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,7 +15,7 @@ In these chapters we're going to use a linear framebuffer, since it's the only f
15
15
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).
16
16
17
17
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:
19
19
20
20
```assembly
21
21
framebuffer_tag_start:
@@ -28,7 +28,7 @@ framebuffer_tag_start:
28
28
framebuffer_tag_end:
29
29
```
30
30
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.
32
32
33
33
## Accessing the Framebuffer
34
34
@@ -148,16 +148,18 @@ where `logo_data` is a pointer to the image content and `pixel` is an array of 4
148
148
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:
149
149
150
150
```c
151
-
char pixel[4];
151
+
unsigned char pixel[4];
152
152
HEADER_PIXEL(logo_data, pixel)
153
153
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];
158
158
159
159
```
160
160
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
+
161
163
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.
162
164
163
165
With this value we can call the function we have created to plot the pixel with the color indicated by `num`.
0 commit comments