Brendan wrote:
Hi,
scdown wrote:
The offending function is in drivers/screen.c (fillrect() - which generates the background)
On line 25 and 29 in "putpixel()", and on lines 35, 42 and 43 of "filrect()"; you're doing calculations wrong. Specifically, you're doing "COLOR_BITS/8" to calculate how many bytes a pixel takes up, but (for 15-bpp video mode) with integer arithmetic "15/8 = 1" which is wrong. You need something more like "(COLOR_BITS+7)/8" so that it rounds up and you get the correct result (2 bytes per pixel, not one byte per pixel); or even better you could do a "bytes_per_pixel = (COLOR_BITS+7)/8;" once in "setup_video()" so that you don't have to repeatedly calculate it everywhere.
This bug means that every time you write a pixel it gets put at the wrong place; and I suspect that all of the other code relies on either "putpixel()" (which is very bad for performance) or "fillrect()", so everything gets drawn at the wrong place. I'd also assume that on Qemu you got a 16-bpp video mode (where "16/8 = 2") so it was right and worked by accident.
Cheers,
Brendan
Thanks! I'll keep this in mind if I switch to a 15 bit colour mode in the future. I'll probably implement it sooner than that anyway, because why not?
Also, the putpixel() function isn't being used too much as it is, I've been working to make it obsolete.