... | ... |
@@ -25,27 +25,27 @@ static Uint8 blending[4][16] = { |
25 | 25 |
{2, 3, 1, 2, 2, 3, 1, 2, 2, 3, 1, 2, 2, 3, 1, 2}}; |
26 | 26 |
|
27 | 27 |
static void |
28 |
-screen_change(UxnScreen *s, Uint16 x1, Uint16 y1, Uint16 x2, Uint16 y2) |
|
28 |
+screen_change(Uint16 x1, Uint16 y1, Uint16 x2, Uint16 y2) |
|
29 | 29 |
{ |
30 |
- if(x1 < s->x1) s->x1 = x1; |
|
31 |
- if(y1 < s->y1) s->y1 = y1; |
|
32 |
- if(x2 > s->x2) s->x2 = x2; |
|
33 |
- if(y2 > s->y2) s->y2 = y2; |
|
30 |
+ if(x1 < uxn_screen.x1) uxn_screen.x1 = x1; |
|
31 |
+ if(y1 < uxn_screen.y1) uxn_screen.y1 = y1; |
|
32 |
+ if(x2 > uxn_screen.x2) uxn_screen.x2 = x2; |
|
33 |
+ if(y2 > uxn_screen.y2) uxn_screen.y2 = y2; |
|
34 | 34 |
} |
35 | 35 |
|
36 | 36 |
static void |
37 |
-screen_fill(UxnScreen *s, Uint8 *pixels, Uint16 x1, Uint16 y1, Uint16 x2, Uint16 y2, Uint8 color) |
|
37 |
+screen_fill(Uint8 *pixels, Uint16 x1, Uint16 y1, Uint16 x2, Uint16 y2, Uint8 color) |
|
38 | 38 |
{ |
39 |
- int x, y, width = s->width, height = s->height; |
|
39 |
+ int x, y, width = uxn_screen.width, height = uxn_screen.height; |
|
40 | 40 |
for(y = y1; y < y2 && y < height; y++) |
41 | 41 |
for(x = x1; x < x2 && x < width; x++) |
42 | 42 |
pixels[x + y * width] = color; |
43 | 43 |
} |
44 | 44 |
|
45 | 45 |
static void |
46 |
-screen_blit(UxnScreen *s, Uint8 *pixels, Uint16 x1, Uint16 y1, Uint8 *ram, Uint16 addr, Uint8 color, Uint8 flipx, Uint8 flipy, Uint8 twobpp) |
|
46 |
+screen_blit(Uint8 *pixels, Uint16 x1, Uint16 y1, Uint8 *ram, Uint16 addr, Uint8 color, Uint8 flipx, Uint8 flipy, Uint8 twobpp) |
|
47 | 47 |
{ |
48 |
- int v, h, width = s->width, height = s->height, opaque = (color % 5) || !color; |
|
48 |
+ int v, h, width = uxn_screen.width, height = uxn_screen.height, opaque = (color % 5) || !color; |
|
49 | 49 |
for(v = 0; v < 8; v++) { |
50 | 50 |
Uint16 c = ram[(addr + v) & 0xffff] | (twobpp ? (ram[(addr + v + 8) & 0xffff] << 8) : 0); |
51 | 51 |
Uint16 y = y1 + (flipy ? 7 - v : v); |
... | ... |
@@ -61,7 +61,7 @@ screen_blit(UxnScreen *s, Uint8 *pixels, Uint16 x1, Uint16 y1, Uint8 *ram, Uint1 |
61 | 61 |
} |
62 | 62 |
|
63 | 63 |
void |
64 |
-screen_palette(UxnScreen *p, Uint8 *addr) |
|
64 |
+screen_palette(Uint8 *addr) |
|
65 | 65 |
{ |
66 | 66 |
int i, shift; |
67 | 67 |
for(i = 0, shift = 4; i < 4; ++i, shift ^= 4) { |
... | ... |
@@ -69,49 +69,51 @@ screen_palette(UxnScreen *p, Uint8 *addr) |
69 | 69 |
r = (addr[0 + i / 2] >> shift) & 0xf, |
70 | 70 |
g = (addr[2 + i / 2] >> shift) & 0xf, |
71 | 71 |
b = (addr[4 + i / 2] >> shift) & 0xf; |
72 |
- p->palette[i] = 0x0f000000 | r << 16 | g << 8 | b; |
|
73 |
- p->palette[i] |= p->palette[i] << 4; |
|
72 |
+ uxn_screen.palette[i] = 0x0f000000 | r << 16 | g << 8 | b; |
|
73 |
+ uxn_screen.palette[i] |= uxn_screen.palette[i] << 4; |
|
74 | 74 |
} |
75 |
- screen_change(&uxn_screen, 0, 0, p->width, p->height); |
|
75 |
+ screen_change(0, 0, uxn_screen.width, uxn_screen.height); |
|
76 | 76 |
} |
77 | 77 |
|
78 | 78 |
void |
79 |
-screen_resize(UxnScreen *p, Uint16 width, Uint16 height) |
|
79 |
+screen_resize(Uint16 width, Uint16 height) |
|
80 | 80 |
{ |
81 | 81 |
Uint8 *bg, *fg; |
82 | 82 |
Uint32 *pixels; |
83 | 83 |
if(width < 0x8 || height < 0x8 || width >= 0x400 || height >= 0x400) |
84 | 84 |
return; |
85 |
- bg = realloc(p->bg, width * height), |
|
86 |
- fg = realloc(p->fg, width * height); |
|
87 |
- pixels = realloc(p->pixels, width * height * sizeof(Uint32)); |
|
85 |
+ bg = realloc(uxn_screen.bg, width * height), |
|
86 |
+ fg = realloc(uxn_screen.fg, width * height); |
|
87 |
+ pixels = realloc(uxn_screen.pixels, width * height * sizeof(Uint32)); |
|
88 | 88 |
if(!bg || !fg || !pixels) |
89 | 89 |
return; |
90 |
- p->bg = bg; |
|
91 |
- p->fg = fg; |
|
92 |
- p->pixels = pixels; |
|
93 |
- p->width = width; |
|
94 |
- p->height = height; |
|
95 |
- screen_fill(p, p->bg, 0, 0, p->width, p->height, 0); |
|
96 |
- screen_fill(p, p->fg, 0, 0, p->width, p->height, 0); |
|
90 |
+ uxn_screen.bg = bg; |
|
91 |
+ uxn_screen.fg = fg; |
|
92 |
+ uxn_screen.pixels = pixels; |
|
93 |
+ uxn_screen.width = width; |
|
94 |
+ uxn_screen.height = height; |
|
95 |
+ screen_fill(uxn_screen.bg, 0, 0, uxn_screen.width, uxn_screen.height, 0); |
|
96 |
+ screen_fill(uxn_screen.fg, 0, 0, uxn_screen.width, uxn_screen.height, 0); |
|
97 | 97 |
} |
98 | 98 |
|
99 | 99 |
void |
100 |
-screen_redraw(UxnScreen *p) |
|
100 |
+screen_redraw(void) |
|
101 | 101 |
{ |
102 |
- Uint32 i, x, y, w = p->width, palette[16], *pixels = p->pixels; |
|
103 |
- Uint8 *fg = p->fg, *bg = p->bg; |
|
104 |
- int x1 = p->x1, y1 = p->y1; |
|
105 |
- int x2 = p->x2 > p->width ? p->width : p->x2, y2 = p->y2 > p->height ? p->height : p->y2; |
|
102 |
+ Uint32 i, x, y, w = uxn_screen.width, palette[16], *pixels = uxn_screen.pixels; |
|
103 |
+ Uint8 *fg = uxn_screen.fg, *bg = uxn_screen.bg; |
|
104 |
+ int x1 = uxn_screen.x1; |
|
105 |
+ int y1 = uxn_screen.y1; |
|
106 |
+ int x2 = uxn_screen.x2 > uxn_screen.width ? uxn_screen.width : uxn_screen.x2; |
|
107 |
+ int y2 = uxn_screen.y2 > uxn_screen.height ? uxn_screen.height : uxn_screen.y2; |
|
106 | 108 |
for(i = 0; i < 16; i++) |
107 |
- palette[i] = p->palette[(i >> 2) ? (i >> 2) : (i & 3)]; |
|
109 |
+ palette[i] = uxn_screen.palette[(i >> 2) ? (i >> 2) : (i & 3)]; |
|
108 | 110 |
for(y = y1; y < y2; y++) |
109 | 111 |
for(x = x1; x < x2; x++) { |
110 | 112 |
i = x + y * w; |
111 | 113 |
pixels[i] = palette[fg[i] << 2 | bg[i]]; |
112 | 114 |
} |
113 |
- p->x1 = p->y1 = 0xffff; |
|
114 |
- p->x2 = p->y2 = 0; |
|
115 |
+ uxn_screen.x1 = uxn_screen.y1 = 0xffff; |
|
116 |
+ uxn_screen.x2 = uxn_screen.y2 = 0; |
|
115 | 117 |
} |
116 | 118 |
|
117 | 119 |
Uint8 |
... | ... |
@@ -131,10 +133,10 @@ screen_deo(Uint8 *ram, Uint8 *d, Uint8 port) |
131 | 133 |
{ |
132 | 134 |
switch(port) { |
133 | 135 |
case 0x3: |
134 |
- screen_resize(&uxn_screen, PEEK2(d + 2), uxn_screen.height); |
|
136 |
+ screen_resize(PEEK2(d + 2), uxn_screen.height); |
|
135 | 137 |
break; |
136 | 138 |
case 0x5: |
137 |
- screen_resize(&uxn_screen, uxn_screen.width, PEEK2(d + 4)); |
|
139 |
+ screen_resize(uxn_screen.width, PEEK2(d + 4)); |
|
138 | 140 |
break; |
139 | 141 |
case 0xe: { |
140 | 142 |
Uint8 ctrl = d[0xe]; |
... | ... |
@@ -148,8 +150,8 @@ screen_deo(Uint8 *ram, Uint8 *d, Uint8 port) |
148 | 150 |
Uint16 y2 = uxn_screen.height; |
149 | 151 |
if(ctrl & 0x10) x2 = x, x = 0; |
150 | 152 |
if(ctrl & 0x20) y2 = y, y = 0; |
151 |
- screen_fill(&uxn_screen, layer, x, y, x2, y2, color); |
|
152 |
- screen_change(&uxn_screen, x, y, x2, y2); |
|
153 |
+ screen_fill(layer, x, y, x2, y2, color); |
|
154 |
+ screen_change(x, y, x2, y2); |
|
153 | 155 |
} |
154 | 156 |
/* pixel mode */ |
155 | 157 |
else { |
... | ... |
@@ -157,7 +159,7 @@ screen_deo(Uint8 *ram, Uint8 *d, Uint8 port) |
157 | 159 |
Uint16 height = uxn_screen.height; |
158 | 160 |
if(x < width && y < height) |
159 | 161 |
layer[x + y * width] = color; |
160 |
- screen_change(&uxn_screen, x, y, x + 1, y + 1); |
|
162 |
+ screen_change(x, y, x + 1, y + 1); |
|
161 | 163 |
if(d[0x6] & 0x1) POKE2(d + 0x8, x + 1); /* auto x+1 */ |
162 | 164 |
if(d[0x6] & 0x2) POKE2(d + 0xa, y + 1); /* auto y+1 */ |
163 | 165 |
} |
... | ... |
@@ -176,10 +178,10 @@ screen_deo(Uint8 *ram, Uint8 *d, Uint8 port) |
176 | 178 |
Uint16 dy = (move & 0x2) << 2; |
177 | 179 |
Uint8 *layer = (ctrl & 0x40) ? uxn_screen.fg : uxn_screen.bg; |
178 | 180 |
for(i = 0; i <= length; i++) { |
179 |
- screen_blit(&uxn_screen, layer, x + dy * i, y + dx * i, ram, addr, ctrl & 0xf, ctrl & 0x10, ctrl & 0x20, twobpp); |
|
181 |
+ screen_blit(layer, x + dy * i, y + dx * i, ram, addr, ctrl & 0xf, ctrl & 0x10, ctrl & 0x20, twobpp); |
|
180 | 182 |
addr += (move & 0x04) << (1 + twobpp); |
181 | 183 |
} |
182 |
- screen_change(&uxn_screen, x, y, x + dy * length + 8, y + dx * length + 8); |
|
184 |
+ screen_change(x, y, x + dy * length + 8, y + dx * length + 8); |
|
183 | 185 |
if(move & 0x1) POKE2(d + 0x8, x + dx); /* auto x+8 */ |
184 | 186 |
if(move & 0x2) POKE2(d + 0xa, y + dy); /* auto y+8 */ |
185 | 187 |
if(move & 0x4) POKE2(d + 0xc, addr); /* auto addr+length */ |
... | ... |
@@ -17,10 +17,8 @@ typedef struct UxnScreen { |
17 | 17 |
} UxnScreen; |
18 | 18 |
|
19 | 19 |
extern UxnScreen uxn_screen; |
20 |
- |
|
21 |
-void screen_palette(UxnScreen *p, Uint8 *addr); |
|
22 |
-void screen_resize(UxnScreen *p, Uint16 width, Uint16 height); |
|
23 |
-void screen_redraw(UxnScreen *p); |
|
24 |
- |
|
20 |
+void screen_palette(Uint8 *addr); |
|
21 |
+void screen_resize(Uint16 width, Uint16 height); |
|
22 |
+void screen_redraw(void); |
|
25 | 23 |
Uint8 screen_dei(Uxn *u, Uint8 addr); |
26 | 24 |
void screen_deo(Uint8 *ram, Uint8 *d, Uint8 port); |
... | ... |
@@ -115,7 +115,7 @@ uxn_deo(Uxn *u, Uint8 addr) |
115 | 115 |
case 0x00: |
116 | 116 |
system_deo(u, &u->dev[d], p); |
117 | 117 |
if(p > 0x7 && p < 0xe) |
118 |
- screen_palette(&uxn_screen, &u->dev[0x8]); |
|
118 |
+ screen_palette(&u->dev[0x8]); |
|
119 | 119 |
break; |
120 | 120 |
case 0x10: console_deo(&u->dev[d], p); break; |
121 | 121 |
case 0x20: screen_deo(u->ram, &u->dev[d], p); break; |
... | ... |
@@ -194,8 +194,9 @@ set_size(void) |
194 | 194 |
static void |
195 | 195 |
redraw(void) |
196 | 196 |
{ |
197 |
- if(gRect.w != uxn_screen.width || gRect.h != uxn_screen.height) set_size(); |
|
198 |
- screen_redraw(&uxn_screen); |
|
197 |
+ if(gRect.w != uxn_screen.width || gRect.h != uxn_screen.height) |
|
198 |
+ set_size(); |
|
199 |
+ screen_redraw(); |
|
199 | 200 |
if(SDL_UpdateTexture(gTexture, NULL, uxn_screen.pixels, uxn_screen.width * sizeof(Uint32)) != 0) |
200 | 201 |
system_error("SDL_UpdateTexture", SDL_GetError()); |
201 | 202 |
SDL_RenderClear(gRenderer); |
... | ... |
@@ -289,7 +290,7 @@ capture_screen(void) |
289 | 290 |
static void |
290 | 291 |
restart(Uxn *u) |
291 | 292 |
{ |
292 |
- screen_resize(&uxn_screen, WIDTH, HEIGHT); |
|
293 |
+ screen_resize(WIDTH, HEIGHT); |
|
293 | 294 |
if(!start(u, "launcher.rom", 0)) |
294 | 295 |
start(u, rom_path, 0); |
295 | 296 |
} |
... | ... |
@@ -366,7 +367,7 @@ handle_events(Uxn *u) |
366 | 367 |
else if(event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_EXPOSED) |
367 | 368 |
redraw(); |
368 | 369 |
else if(event.type == SDL_DROPFILE) { |
369 |
- screen_resize(&uxn_screen, WIDTH, HEIGHT); |
|
370 |
+ screen_resize(WIDTH, HEIGHT); |
|
370 | 371 |
start(u, event.drop.file, 0); |
371 | 372 |
SDL_free(event.drop.file); |
372 | 373 |
} |
... | ... |
@@ -489,7 +490,7 @@ main(int argc, char **argv) |
489 | 490 |
if(!init()) |
490 | 491 |
return system_error("Init", "Failed to initialize emulator."); |
491 | 492 |
/* default resolution */ |
492 |
- screen_resize(&uxn_screen, WIDTH, HEIGHT); |
|
493 |
+ screen_resize(WIDTH, HEIGHT); |
|
493 | 494 |
/* default zoom */ |
494 | 495 |
if(argc > 1 && (strcmp(argv[i], "-1x") == 0 || strcmp(argv[i], "-2x") == 0 || strcmp(argv[i], "-3x") == 0)) |
495 | 496 |
set_zoom(argv[i++][1] - '0'); |