commit e52db28
neauoire
·
2023-11-12 04:59:08 +0000 UTC
parent eaa05f8
(Screen) Fill function
3 files changed,
+36,
-30
+26,
-24
1@@ -39,7 +39,15 @@ screen_change(Uint16 x1, Uint16 y1, Uint16 x2, Uint16 y2)
2 }
3
4 void
5-screen_fill(Uint8 *layer, int x1, int y1, int x2, int y2, int color)
6+screen_fill(Uint8 *layer, int color)
7+{
8+ int i, length = uxn_screen.width * uxn_screen.height;
9+ for(i = 0; i < length; i++)
10+ layer[i] = color;
11+}
12+
13+void
14+screen_rect(Uint8 *layer, int x1, int y1, int x2, int y2, int color)
15 {
16 int x, y, width = uxn_screen.width, height = uxn_screen.height;
17 for(y = y1; y < y2 && y < height; y++)
18@@ -96,16 +104,16 @@ screen_debugger(Uxn *u)
19 int i;
20 for(i = 0; i < 0x08; i++) {
21 Uint8 pos = u->wst.ptr - 4 + i;
22- Uint8 color = i > 4 ? 0x01 : !pos ? 0xc :
23- i == 4 ? 0x8 :
24- 0x2;
25+ Uint8 color = i > 4 ? 0x01 : !pos ? 0xc
26+ : i == 4 ? 0x8
27+ : 0x2;
28 draw_byte(u->wst.dat[pos], i * 0x18 + 0x8, uxn_screen.height - 0x18, color);
29 }
30 for(i = 0; i < 0x08; i++) {
31 Uint8 pos = u->rst.ptr - 4 + i;
32- Uint8 color = i > 4 ? 0x01 : !pos ? 0xc :
33- i == 4 ? 0x8 :
34- 0x2;
35+ Uint8 color = i > 4 ? 0x01 : !pos ? 0xc
36+ : i == 4 ? 0x8
37+ : 0x2;
38 draw_byte(u->rst.dat[pos], i * 0x18 + 0x8, uxn_screen.height - 0x10, color);
39 }
40 screen_blit(uxn_screen.fg, arrow, 0, 0x68, uxn_screen.height - 0x20, 3, 0, 0, 0);
41@@ -137,24 +145,18 @@ screen_resize(Uint16 width, Uint16 height)
42 return;
43 if(uxn_screen.width == width && uxn_screen.height == height)
44 return;
45- bg = malloc(width * height),
46- fg = malloc(width * height);
47+ bg = malloc(width * height), fg = malloc(width * height);
48 if(bg && fg)
49 pixels = realloc(uxn_screen.pixels, width * height * sizeof(Uint32));
50 if(!bg || !fg || !pixels) {
51- free(bg);
52- free(fg);
53+ free(bg), free(fg);
54 return;
55 }
56- free(uxn_screen.bg);
57- free(uxn_screen.fg);
58- uxn_screen.bg = bg;
59- uxn_screen.fg = fg;
60+ free(uxn_screen.bg), free(uxn_screen.fg);
61+ uxn_screen.bg = bg, uxn_screen.fg = fg;
62 uxn_screen.pixels = pixels;
63- uxn_screen.width = width;
64- uxn_screen.height = height;
65- screen_fill(uxn_screen.bg, 0, 0, width, height, 0);
66- screen_fill(uxn_screen.fg, 0, 0, width, height, 0);
67+ uxn_screen.width = width, uxn_screen.height = height;
68+ screen_fill(uxn_screen.bg, 0), screen_fill(uxn_screen.fg, 0);
69 emu_resize(width, height);
70 screen_change(0, 0, width, height);
71 }
72@@ -194,13 +196,13 @@ screen_dei(Uxn *u, Uint8 addr)
73 void
74 screen_deo(Uint8 *ram, Uint8 *d, Uint8 port)
75 {
76- Uint8 *port_width, *port_height, *port_x, *port_y, *port_addr;
77+ Uint8 *port_height, *port_x, *port_y, *port_addr;
78 Uint16 x, y, dx, dy, dxy, dyx, addr, addr_incr;
79 switch(port) {
80- case 0x3:
81- port_width = d + 0x2;
82+ case 0x3: {
83+ Uint8 *port_width = d + 0x2;
84 screen_resize(PEEK2(port_width), uxn_screen.height);
85- break;
86+ } break;
87 case 0x5:
88 port_height = d + 0x4;
89 screen_resize(uxn_screen.width, PEEK2(port_height));
90@@ -219,7 +221,7 @@ screen_deo(Uint8 *ram, Uint8 *d, Uint8 port)
91 Uint16 y2 = uxn_screen.height;
92 if(ctrl & 0x10) x2 = x, x = 0;
93 if(ctrl & 0x20) y2 = y, y = 0;
94- screen_fill(layer, x, y, x2, y2, color);
95+ screen_rect(layer, x, y, x2, y2, color);
96 screen_change(x, y, x2, y2);
97 }
98 /* pixel mode */
+8,
-4
1@@ -10,6 +10,8 @@ WITH REGARD TO THIS SOFTWARE.
2 */
3
4 #define SCREEN_VERSION 1
5+#define SCREEN_DEIMASK 0x003c
6+#define SCREEN_DEOMASK 0xc028
7
8 typedef struct UxnScreen {
9 int width, height, x1, y1, x2, y2;
10@@ -17,13 +19,15 @@ typedef struct UxnScreen {
11 Uint8 *fg, *bg;
12 } UxnScreen;
13
14-void screen_fill(Uint8 *layer, int x1, int y1, int x2, int y2, int color);
15+extern UxnScreen uxn_screen;
16+extern int emu_resize(int width, int height);
17+
18+void screen_fill(Uint8 *layer, int color);
19+void screen_rect(Uint8 *layer, int x1, int y1, int x2, int y2, int color);
20 void screen_palette(Uint8 *addr);
21 void screen_resize(Uint16 width, Uint16 height);
22 void screen_change(Uint16 x1, Uint16 y1, Uint16 x2, Uint16 y2);
23 void screen_redraw(Uxn *u);
24+
25 Uint8 screen_dei(Uxn *u, Uint8 addr);
26 void screen_deo(Uint8 *ram, Uint8 *d, Uint8 port);
27-
28-extern UxnScreen uxn_screen;
29-extern int emu_resize(int width, int height);
+2,
-2
1@@ -86,8 +86,8 @@ static void
2 emu_restart(Uxn *u, char *rom, int soft)
3 {
4 screen_resize(WIDTH, HEIGHT);
5- screen_fill(uxn_screen.bg, 0, 0, uxn_screen.width, uxn_screen.height, 0);
6- screen_fill(uxn_screen.fg, 0, 0, uxn_screen.width, uxn_screen.height, 0);
7+ screen_rect(uxn_screen.bg, 0, 0, uxn_screen.width, uxn_screen.height, 0);
8+ screen_rect(uxn_screen.fg, 0, 0, uxn_screen.width, uxn_screen.height, 0);
9 system_reboot(u, rom, soft);
10 /* set window title */
11 }