commit 843bbb5
neauoire
·
2023-11-12 18:20:03 +0000 UTC
parent 805c925
Split 1bpp/2bpp drawing
1 files changed,
+31,
-12
+31,
-12
1@@ -56,19 +56,35 @@ screen_rect(Uint8 *layer, Uint16 x1, Uint16 y1, Uint16 x2, Uint16 y2, int color)
2 }
3
4 static void
5-screen_blit(Uint8 *layer, Uint8 *ram, Uint16 addr, Uint16 x1, Uint16 y1, Uint16 color, int flipx, int flipy, int twobpp)
6+screen_2bpp(Uint8 *layer, Uint8 *ram, Uint16 addr, Uint16 x1, Uint16 y1, Uint16 color, int flipx, int flipy)
7 {
8 int v, h, width = uxn_screen.width, height = uxn_screen.height, opaque = (color % 5);
9- /* TODO: Draw partial tile */
10- if(x1 + 8 >= width) return;
11- if(y1 + 8 >= height) return;
12+ Uint8 *ch1 = &ram[addr], *ch2 = ch1 + 8;
13 for(v = 0; v < 8; v++) {
14- Uint16 c = ram[(addr + v) & 0xffff] | (twobpp ? (ram[(addr + v + 8) & 0xffff] << 8) : 0);
15- int y = (y1 + (flipy ? 7 - v : v)) * width;
16+ Uint16 c = *ch1++ | (*ch2++ << 8);
17+ Uint16 y = (y1 + (flipy ? 7 - v : v));
18 for(h = 7; h >= 0; --h, c >>= 1) {
19 Uint8 ch = (c & 1) | ((c >> 7) & 2);
20- if(opaque || ch)
21- layer[(x1 + (flipx ? 7 - h : h)) + y] = blending[ch][color];
22+ Uint16 x = (x1 + (flipx ? 7 - h : h));
23+ if((opaque || ch) && x < width && y < height)
24+ layer[x + y * width] = blending[ch][color];
25+ }
26+ }
27+}
28+
29+static void
30+screen_1bpp(Uint8 *layer, Uint8 *ram, Uint16 addr, Uint16 x1, Uint16 y1, Uint16 color, int flipx, int flipy)
31+{
32+ int v, h, width = uxn_screen.width, height = uxn_screen.height, opaque = (color % 5);
33+ Uint8 *ch1 = &ram[addr];
34+ for(v = 0; v < 8; v++) {
35+ Uint16 c = *ch1++;
36+ Uint16 y = (y1 + (flipy ? 7 - v : v));
37+ for(h = 7; h >= 0; --h, c >>= 1) {
38+ Uint8 ch = (c & 1) | ((c >> 7) & 2);
39+ Uint16 x = (x1 + (flipx ? 7 - h : h));
40+ if((opaque || ch) && x < width && y < height)
41+ layer[x + y * width] = blending[ch][color];
42 }
43 }
44 }
45@@ -93,8 +109,8 @@ static Uint8 arrow[] = {
46 static void
47 draw_byte(Uint8 b, Uint16 x, Uint16 y, Uint8 color)
48 {
49- screen_blit(uxn_screen.fg, icons, (b >> 4) << 3, x, y, color, 0, 0, 0);
50- screen_blit(uxn_screen.fg, icons, (b & 0xf) << 3, x + 8, y, color, 0, 0, 0);
51+ screen_1bpp(uxn_screen.fg, icons, (b >> 4) << 3, x, y, color, 0, 0);
52+ screen_1bpp(uxn_screen.fg, icons, (b & 0xf) << 3, x + 8, y, color, 0, 0);
53 screen_change(x, y, x + 0x10, y + 0x8);
54 }
55
56@@ -116,7 +132,7 @@ screen_debugger(Uxn *u)
57 0x2;
58 draw_byte(u->rst.dat[pos], i * 0x18 + 0x8, uxn_screen.height - 0x10, color);
59 }
60- screen_blit(uxn_screen.fg, arrow, 0, 0x68, uxn_screen.height - 0x20, 3, 0, 0, 0);
61+ screen_1bpp(uxn_screen.fg, arrow, 0, 0x68, uxn_screen.height - 0x20, 3, 0, 0);
62 for(i = 0; i < 0x20; i++)
63 draw_byte(u->ram[i], (i & 0x7) * 0x18 + 0x8, ((i >> 3) << 3) + 0x8, 1 + !!u->ram[i]);
64 }
65@@ -253,7 +269,10 @@ screen_deo(Uint8 *ram, Uint8 *d, Uint8 port)
66 y = PEEK2(port_y), dy = (move & 0x2) << 2, dyx = dy * fx;
67 addr = PEEK2(port_addr), addr_incr = (move & 0x4) << (1 + twobpp);
68 for(i = 0; i <= length; i++) {
69- screen_blit(layer, ram, addr, x + dyx * i, y + dxy * i, color, flipx, flipy, twobpp);
70+ if(twobpp)
71+ screen_2bpp(layer, ram, addr, x + dyx * i, y + dxy * i, color, flipx, flipy);
72+ else
73+ screen_1bpp(layer, ram, addr, x + dyx * i, y + dxy * i, color, flipx, flipy);
74 addr += addr_incr;
75 }
76 screen_change(x, y, x + dyx * length + 8, y + dxy * length + 8);