diff options
author | Daniel Friesel <daniel.friesel@uos.de> | 2021-10-15 15:10:41 +0200 |
---|---|---|
committer | Daniel Friesel <daniel.friesel@uos.de> | 2021-10-15 15:10:41 +0200 |
commit | c19dcac092c594598e1ef3ab745189adf84b32d0 (patch) | |
tree | f955409767637cca47a681bf7909a399ab80e930 /src/os/object | |
parent | 4b0d2a30c0068ace46ae0cda442b01ae06a86e19 (diff) |
add framebuffer and pervasive aurora mb test app
Diffstat (limited to 'src/os/object')
-rw-r--r-- | src/os/object/framebuffer.cc | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/src/os/object/framebuffer.cc b/src/os/object/framebuffer.cc new file mode 100644 index 0000000..ad128dc --- /dev/null +++ b/src/os/object/framebuffer.cc @@ -0,0 +1,70 @@ +#include "object/framebuffer.h" + +#ifdef CONFIG_framebuffer_in_text_segment +__attribute__ ((section(".text"))) +#endif +static unsigned char framebuffer[(unsigned long int)CONFIG_framebuffer_width * (unsigned long int)CONFIG_framebuffer_height / 8]; + +void Framebuffer::clear() +{ + for (unsigned int i = 0; i < width * (height / 8); i++) { + data[i] = 0; + } +} + +void Framebuffer::fillBox(unsigned int x, unsigned int y, unsigned int w, unsigned int h) +{ + if (w == 0 || h == 0) { + return; + } + w -= 1; + h -= 1; + if ((x+w) >= width || (y+h) >= height) { + return; + } + + unsigned int x1 = (height/8)*x; + unsigned int x2 = (height/8)*(x+w); + unsigned int y2 = height-1-y; + unsigned int y1 = y2-h; + unsigned char y2_mask = 0xff << (8 - (y2 % 8)); // bits from 0 to y2%8 must be filled + unsigned char y1_mask = 0xff >> (y1 % 8); // bits from y1%8 to 7 must be filled + y1 = y1/8; + y2 = y2/8; + + if (y1 == y2) { + // y1_mask and y2_mask overlap + for (unsigned int pos_x = x1; pos_x < x2; pos_x += height/8) { + data[pos_x + y1] |= y1_mask & y2_mask; + } + } else { + if (y1_mask != 0xff) { + for (unsigned int pos_x = x1; pos_x < x2; pos_x += height/8) { + data[pos_x + y1] |= y1_mask; + } + y1++; + } + for (unsigned int pos_x = x1; pos_x < x2; pos_x += height/8) { + for (unsigned int pos_y = y1; pos_y < y2; pos_y++) { + data[pos_x + pos_y] = 0xff; + } + } + if (y2_mask) { + for (unsigned int pos_x = x1; pos_x < x2; pos_x += height/8) { + data[pos_x + y2] |= y2_mask; + } + } + } +} + +void Framebuffer::drawAt(unsigned int x, unsigned int y, unsigned int w, unsigned int h, unsigned char *image) +{ + y /= 8; + for (unsigned int pos_x = 0; pos_x < w; pos_x++) { + for (unsigned int pos_y = 0; pos_y < h/8; pos_y++) { + data[(x + pos_x) * (height/8) + y + pos_y] = image[pos_x * (h/8) + pos_y]; + } + } +} + +Framebuffer fb(framebuffer); |