Browse code

(screen) sprite address wrapping

Devine Lu Linvega authored on 14/04/2023 17:05:15
Showing 1 changed files
... ...
@@ -34,11 +34,11 @@ screen_fill(UxnScreen *s, Uint8 *pixels, Uint16 x1, Uint16 y1, Uint16 x2, Uint16
34 34
 }
35 35
 
36 36
 static void
37
-screen_blit(UxnScreen *p, Uint8 *pixels, Uint16 x1, Uint16 y1, Uint8 *sprite, Uint8 color, Uint8 flipx, Uint8 flipy, Uint8 twobpp)
37
+screen_blit(UxnScreen *p, Uint8 *pixels, Uint16 x1, Uint16 y1, Uint8 *ram, Uint16 addr, Uint8 color, Uint8 flipx, Uint8 flipy, Uint8 twobpp)
38 38
 {
39 39
 	int v, h, width = p->width, height = p->height, opaque = (color % 5) || !color;
40 40
 	for(v = 0; v < 8; v++) {
41
-		Uint16 c = sprite[v] | (twobpp ? (sprite[v + 8] << 8) : 0);
41
+		Uint16 c = ram[(addr + v) & 0xffff] | (twobpp ? (ram[(addr + v + 8) & 0xffff] << 8) : 0);
42 42
 		Uint16 y = y1 + (flipy ? 7 - v : v);
43 43
 		for(h = 7; h >= 0; --h, c >>= 1) {
44 44
 			Uint8 ch = (c & 1) | ((c >> 7) & 2);
... ...
@@ -160,14 +160,12 @@ screen_deo(Uint8 *ram, Uint8 *d, Uint8 port)
160 160
 		Uint16 dx = (move & 0x1) << 3;
161 161
 		Uint16 dy = (move & 0x2) << 2;
162 162
 		Layer *layer = (ctrl & 0x40) ? &uxn_screen.fg : &uxn_screen.bg;
163
-		if(addr > 0x10000 - ((length + 1) << (3 + twobpp)))
164
-			return;
165 163
 		for(i = 0; i <= length; i++) {
166 164
 			if(!(ctrl & 0xf)) {
167 165
 				Uint16 ex = x + dy * i, ey = y + dx * i;
168 166
 				screen_fill(&uxn_screen, layer->pixels, ex, ey, ex + 8, ey + 8, 0);
169 167
 			} else {
170
-				screen_blit(&uxn_screen, layer->pixels, x + dy * i, y + dx * i, &ram[addr], ctrl & 0xf, ctrl & 0x10, ctrl & 0x20, twobpp);
168
+				screen_blit(&uxn_screen, layer->pixels, x + dy * i, y + dx * i, ram, addr, ctrl & 0xf, ctrl & 0x10, ctrl & 0x20, twobpp);
171 169
 				addr += (move & 0x04) << (1 + twobpp);
172 170
 			}
173 171
 		}