... | ... |
@@ -23,24 +23,25 @@ static Uint8 blending[4][16] = { |
23 | 23 |
{2, 3, 1, 2, 2, 3, 1, 2, 2, 3, 1, 2, 2, 3, 1, 2}}; |
24 | 24 |
|
25 | 25 |
static void |
26 |
-screen_write(UxnScreen *p, Layer *layer, Uint16 x, Uint16 y, Uint8 color) |
|
26 |
+screen_pixel(UxnScreen *p, Layer *layer, Uint16 x, Uint16 y, Uint8 color) |
|
27 | 27 |
{ |
28 |
- if(x < p->width && y < p->height) { |
|
29 |
- Uint32 i = x + y * p->width; |
|
30 |
- if(color != layer->pixels[i]) { |
|
31 |
- layer->pixels[i] = color; |
|
32 |
- layer->changed = 1; |
|
33 |
- } |
|
34 |
- } |
|
28 |
+ if(x >= p->width || y >= p->height) |
|
29 |
+ return; |
|
30 |
+ layer->pixels[x + y * p->width] = color; |
|
35 | 31 |
} |
36 | 32 |
|
37 | 33 |
static void |
38 | 34 |
screen_fill(UxnScreen *p, Layer *layer, Uint16 x1, Uint16 y1, Uint16 x2, Uint16 y2, Uint8 color) |
39 | 35 |
{ |
40 |
- int v, h; |
|
41 |
- for(v = y1; v < y2; v++) |
|
42 |
- for(h = x1; h < x2; h++) |
|
43 |
- screen_write(p, layer, h, v, color); |
|
36 |
+ int x, y; |
|
37 |
+ if(x2 >= p->width) x2 = p->width; |
|
38 |
+ if(y2 >= p->height) y2 = p->height; |
|
39 |
+ if(x1 >= x2 || y1 >= y2) |
|
40 |
+ return; |
|
41 |
+ for(y = y1; y < y2; y++) |
|
42 |
+ for(x = x1; x < x2; x++) |
|
43 |
+ layer->pixels[x + y * p->width] = color; |
|
44 |
+ layer->changed = 1; |
|
44 | 45 |
} |
45 | 46 |
|
46 | 47 |
static void |
... | ... |
@@ -52,13 +53,14 @@ screen_blit(UxnScreen *p, Layer *layer, Uint16 x, Uint16 y, Uint8 *sprite, Uint8 |
52 | 53 |
for(h = 7; h >= 0; --h, c >>= 1) { |
53 | 54 |
Uint8 ch = (c & 1) | ((c >> 7) & 2); |
54 | 55 |
if(opaque || ch) |
55 |
- screen_write(p, |
|
56 |
+ screen_pixel(p, |
|
56 | 57 |
layer, |
57 | 58 |
x + (flipx ? 7 - h : h), |
58 | 59 |
y + (flipy ? 7 - v : v), |
59 | 60 |
blending[ch][color]); |
60 | 61 |
} |
61 | 62 |
} |
63 |
+ layer->changed = 1; |
|
62 | 64 |
} |
63 | 65 |
|
64 | 66 |
void |
... | ... |
@@ -137,7 +139,8 @@ screen_deo(Uint8 *ram, Uint8 *d, Uint8 port) |
137 | 139 |
Uint8 xflip = d[0xe] & 0x10, yflip = d[0xe] & 0x20; |
138 | 140 |
screen_fill(&uxn_screen, layer, xflip ? 0 : x, yflip ? 0 : y, xflip ? x : uxn_screen.width, yflip ? y : uxn_screen.height, d[0xe] & 0x3); |
139 | 141 |
} else { |
140 |
- screen_write(&uxn_screen, layer, x, y, d[0xe] & 0x3); |
|
142 |
+ screen_pixel(&uxn_screen, layer, x, y, d[0xe] & 0x3); |
|
143 |
+ layer->changed = 1; |
|
141 | 144 |
if(d[0x6] & 0x1) POKE2(d + 0x8, x + 1); /* auto x+1 */ |
142 | 145 |
if(d[0x6] & 0x2) POKE2(d + 0xa, y + 1); /* auto y+1 */ |
143 | 146 |
} |