(screen.c) Fix sprite draw at screen edge

Problem - Sprites can be drawn at X/Y coordinates >= 0xfff9 to appear
partially over the left/upper screen boundary. But the dirty-rectangle
calculation doesn't account for this, so these updates will only appear
on the screen if something *else* dirties this area of the screen. This
can be observed in /projects/examples/devices/screen.tal where these
edges of the screen show stale content.

Solution - Detect wrapping and expand the dirty rectangle appropriately.
Change screen_change to take Uint16 to make sure values are truncated to
the intended range. Ignore changes that are fully off the screen.
This commit is contained in:
Weeble 2023-06-29 11:44:55 +01:00 committed by Devine Lu Linvega
parent 49d74b89d0
commit f5c816d215
1 changed files with 5 additions and 1 deletions

View File

@ -25,8 +25,12 @@ static Uint8 blending[4][16] = {
{2, 3, 1, 2, 2, 3, 1, 2, 2, 3, 1, 2, 2, 3, 1, 2}};
static void
screen_change(int x1, int y1, int x2, int y2)
screen_change(Uint16 x1, Uint16 y1, Uint16 x2, Uint16 y2)
{
if(x1 > uxn_screen.width && x2 > x1) return;
if(y1 > uxn_screen.height && y2 > y1) return;
if(x1 > x2) x1 = 0;
if(y1 > y2) y1 = 0;
if(x1 < uxn_screen.x1) uxn_screen.x1 = x1;
if(y1 < uxn_screen.y1) uxn_screen.y1 = y1;
if(x2 > uxn_screen.x2) uxn_screen.x2 = x2;