commit 14263f3
neauoire
·
2023-08-02 03:39:16 +0000 UTC
parent 5c2c060
Updated screen device
3 files changed,
+38,
-21
+30,
-19
1@@ -25,8 +25,12 @@ static Uint8 blending[4][16] = {
2 {2, 3, 1, 2, 2, 3, 1, 2, 2, 3, 1, 2, 2, 3, 1, 2}};
3
4 static void
5-screen_change(int x1, int y1, int x2, int y2)
6+screen_change(Uint16 x1, Uint16 y1, Uint16 x2, Uint16 y2)
7 {
8+ if(x1 > uxn_screen.width && x2 > x1) return;
9+ if(y1 > uxn_screen.height && y2 > y1) return;
10+ if(x1 > x2) x1 = 0;
11+ if(y1 > y2) y1 = 0;
12 if(x1 < uxn_screen.x1) uxn_screen.x1 = x1;
13 if(y1 < uxn_screen.y1) uxn_screen.y1 = y1;
14 if(x2 > uxn_screen.x2) uxn_screen.x2 = x2;
15@@ -45,7 +49,7 @@ screen_fill(Uint8 *layer, int x1, int y1, int x2, int y2, int color)
16 static void
17 screen_blit(Uint8 *layer, Uint8 *ram, Uint16 addr, int x1, int y1, int color, int flipx, int flipy, int twobpp)
18 {
19- int v, h, width = uxn_screen.width, height = uxn_screen.height, opaque = (color % 5) || !color;
20+ int v, h, width = uxn_screen.width, height = uxn_screen.height, opaque = (color % 5);
21 for(v = 0; v < 8; v++) {
22 Uint16 c = ram[(addr + v) & 0xffff] | (twobpp ? (ram[(addr + v + 8) & 0xffff] << 8) : 0);
23 Uint16 y = y1 + (flipy ? 7 - v : v);
24@@ -79,21 +83,30 @@ void
25 screen_resize(Uint16 width, Uint16 height)
26 {
27 Uint8 *bg, *fg;
28- Uint32 *pixels;
29+ Uint32 *pixels = NULL;
30 if(width < 0x8 || height < 0x8 || width >= 0x400 || height >= 0x400)
31 return;
32- bg = realloc(uxn_screen.bg, width * height),
33- fg = realloc(uxn_screen.fg, width * height);
34- pixels = realloc(uxn_screen.pixels, width * height * sizeof(Uint32) * SCALE * SCALE);
35- if(!bg || !fg || !pixels)
36+ if(uxn_screen.width == width && uxn_screen.height == height)
37 return;
38+ bg = malloc(width * height),
39+ fg = malloc(width * height);
40+ if(bg && fg)
41+ pixels = realloc(uxn_screen.pixels, width * height * sizeof(Uint32));
42+ if(!bg || !fg || !pixels) {
43+ free(bg);
44+ free(fg);
45+ return;
46+ }
47+ free(uxn_screen.bg);
48+ free(uxn_screen.fg);
49 uxn_screen.bg = bg;
50 uxn_screen.fg = fg;
51 uxn_screen.pixels = pixels;
52 uxn_screen.width = width;
53 uxn_screen.height = height;
54- screen_fill(uxn_screen.bg, 0, 0, uxn_screen.width, uxn_screen.height, 0);
55- screen_fill(uxn_screen.fg, 0, 0, uxn_screen.width, uxn_screen.height, 0);
56+ screen_fill(uxn_screen.bg, 0, 0, width, height, 0);
57+ screen_fill(uxn_screen.fg, 0, 0, width, height, 0);
58+ emu_resize(width, height);
59 }
60
61 void
62@@ -101,21 +114,19 @@ screen_redraw(void)
63 {
64 Uint8 *fg = uxn_screen.fg, *bg = uxn_screen.bg;
65 Uint32 palette[16], *pixels = uxn_screen.pixels;
66- int i, j, x, y, w = uxn_screen.width, h = uxn_screen.height;
67- int x1 = uxn_screen.x1 * SCALE;
68- int y1 = uxn_screen.y1 * SCALE;
69- int x2 = (uxn_screen.x2 > w ? w : uxn_screen.x2) * SCALE;
70- int y2 = (uxn_screen.y2 > h ? h : uxn_screen.y2) * SCALE;
71+ int i, x, y, w = uxn_screen.width, h = uxn_screen.height;
72+ int x1 = uxn_screen.x1;
73+ int y1 = uxn_screen.y1;
74+ int x2 = uxn_screen.x2 > w ? w : uxn_screen.x2;
75+ int y2 = uxn_screen.y2 > h ? h : uxn_screen.y2;
76 for(i = 0; i < 16; i++)
77 palette[i] = uxn_screen.palette[(i >> 2) ? (i >> 2) : (i & 3)];
78 for(y = y1; y < y2; y++)
79 for(x = x1; x < x2; x++) {
80- i = x / SCALE + y / SCALE * w;
81- j = x + y * w * SCALE;
82- pixels[j] = palette[fg[i] << 2 | bg[i]];
83+ i = x + y * w;
84+ pixels[i] = palette[fg[i] << 2 | bg[i]];
85 }
86- uxn_screen.x1 = uxn_screen.y1 = 0xffff;
87- uxn_screen.x2 = uxn_screen.y2 = 0;
88+ uxn_screen.x1 = uxn_screen.y1 = uxn_screen.x2 = uxn_screen.y2 = 0;
89 }
90
91 Uint8
+2,
-2
1@@ -17,10 +17,10 @@ typedef struct UxnScreen {
2 } UxnScreen;
3
4 extern UxnScreen uxn_screen;
5+extern int emu_resize(int width, int height);
6+
7 void screen_palette(Uint8 *addr);
8 void screen_resize(Uint16 width, Uint16 height);
9 void screen_redraw(void);
10 Uint8 screen_dei(Uxn *u, Uint8 addr);
11 void screen_deo(Uint8 *ram, Uint8 *d, Uint8 port);
12-
13-#define SCALE 1
+6,
-0
1@@ -36,6 +36,7 @@ char *rom_path;
2 #define WIDTH (64 * 8)
3 #define HEIGHT (40 * 8)
4 #define PAD 2
5+#define SCALE 1
6 #define CONINBUFSIZE 256
7
8 Uint16 deo_mask[] = {0xff28, 0x0300, 0xc028, 0x8000, 0x8000, 0x8000, 0x8000, 0x0000, 0x0000, 0x0000, 0xa260, 0xa260, 0x0000, 0x0000, 0x0000, 0x0000};
9@@ -74,6 +75,11 @@ emu_deo(Uxn *u, Uint8 addr)
10 }
11 }
12
13+int
14+emu_resize(int width, int height) {
15+
16+}
17+
18 static int
19 emu_start(Uxn *u, char *rom)
20 {