... | ... |
@@ -132,12 +132,13 @@ void |
132 | 132 |
screen_deo(Device *d, Uint8 port) |
133 | 133 |
{ |
134 | 134 |
switch(port) { |
135 |
+ case 0x3: |
|
135 | 136 |
case 0x5: |
136 | 137 |
if(!FIXED_SIZE) { |
137 | 138 |
Uint16 w, h; |
138 | 139 |
DEVPEEK16(w, 0x2); |
139 | 140 |
DEVPEEK16(h, 0x4); |
140 |
- set_size(w, h, 1); |
|
141 |
+ screen_resize(&uxn_screen, clamp(w, 1, 1024), clamp(h, 1, 1024)); |
|
141 | 142 |
} |
142 | 143 |
break; |
143 | 144 |
case 0xe: { |
... | ... |
@@ -24,9 +24,6 @@ typedef struct UxnScreen { |
24 | 24 |
|
25 | 25 |
extern UxnScreen uxn_screen; |
26 | 26 |
|
27 |
-/* this should probably be done differently */ |
|
28 |
-int set_size(Uint16 width, Uint16 height, int is_resize); |
|
29 |
- |
|
30 | 27 |
void screen_palette(UxnScreen *p, Uint8 *addr); |
31 | 28 |
void screen_resize(UxnScreen *p, Uint16 width, Uint16 height); |
32 | 29 |
void screen_clear(UxnScreen *p, Layer *layer); |
... | ... |
@@ -100,14 +100,14 @@ set_window_size(SDL_Window *window, int w, int h) |
100 | 100 |
SDL_Point win, win_old; |
101 | 101 |
SDL_GetWindowPosition(window, &win.x, &win.y); |
102 | 102 |
SDL_GetWindowSize(window, &win_old.x, &win_old.y); |
103 |
+ if(w == win_old.x && h == win_old.y) return; |
|
103 | 104 |
SDL_SetWindowPosition(window, (win.x + win_old.x / 2) - w / 2, (win.y + win_old.y / 2) - h / 2); |
104 | 105 |
SDL_SetWindowSize(window, w, h); |
105 | 106 |
} |
106 | 107 |
|
107 | 108 |
int |
108 |
-set_size(Uint16 width, Uint16 height, int is_resize) |
|
109 |
+set_size(void) |
|
109 | 110 |
{ |
110 |
- screen_resize(&uxn_screen, clamp(width, 1, 1024), clamp(height, 1, 1024)); |
|
111 | 111 |
gRect.x = PAD; |
112 | 112 |
gRect.y = PAD; |
113 | 113 |
gRect.w = uxn_screen.width; |
... | ... |
@@ -119,14 +119,14 @@ set_size(Uint16 width, Uint16 height, int is_resize) |
119 | 119 |
return error("gTexture", SDL_GetError()); |
120 | 120 |
if(SDL_UpdateTexture(gTexture, NULL, uxn_screen.pixels, sizeof(Uint32)) != 0) |
121 | 121 |
return error("SDL_UpdateTexture", SDL_GetError()); |
122 |
- if(is_resize) |
|
123 |
- set_window_size(gWindow, (uxn_screen.width + PAD * 2) * zoom, (uxn_screen.height + PAD * 2) * zoom); |
|
122 |
+ set_window_size(gWindow, (uxn_screen.width + PAD * 2) * zoom, (uxn_screen.height + PAD * 2) * zoom); |
|
124 | 123 |
return 1; |
125 | 124 |
} |
126 | 125 |
|
127 | 126 |
static void |
128 | 127 |
redraw(void) |
129 | 128 |
{ |
129 |
+ if(gRect.w != uxn_screen.width || gRect.h != uxn_screen.height) set_size(); |
|
130 | 130 |
screen_redraw(&uxn_screen, uxn_screen.pixels); |
131 | 131 |
if(SDL_UpdateTexture(gTexture, NULL, uxn_screen.pixels, uxn_screen.width * sizeof(Uint32)) != 0) |
132 | 132 |
error("SDL_UpdateTexture", SDL_GetError()); |
... | ... |
@@ -306,7 +306,7 @@ capture_screen(void) |
306 | 306 |
static void |
307 | 307 |
restart(Uxn *u) |
308 | 308 |
{ |
309 |
- set_size(WIDTH, HEIGHT, 1); |
|
309 |
+ screen_resize(&uxn_screen, WIDTH, HEIGHT); |
|
310 | 310 |
start(u, "launcher.rom"); |
311 | 311 |
} |
312 | 312 |
|
... | ... |
@@ -391,7 +391,7 @@ run(Uxn *u) |
391 | 391 |
else if(event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_EXPOSED) |
392 | 392 |
redraw(); |
393 | 393 |
else if(event.type == SDL_DROPFILE) { |
394 |
- set_size(WIDTH, HEIGHT, 0); |
|
394 |
+ screen_resize(&uxn_screen, WIDTH, HEIGHT); |
|
395 | 395 |
start(u, event.drop.file); |
396 | 396 |
SDL_free(event.drop.file); |
397 | 397 |
} |
... | ... |
@@ -461,8 +461,7 @@ main(int argc, char **argv) |
461 | 461 |
|
462 | 462 |
if(!init()) |
463 | 463 |
return error("Init", "Failed to initialize emulator."); |
464 |
- if(!set_size(WIDTH, HEIGHT, 0)) |
|
465 |
- return error("Window", "Failed to set window size."); |
|
464 |
+ screen_resize(&uxn_screen, WIDTH, HEIGHT); |
|
466 | 465 |
|
467 | 466 |
/* set default zoom */ |
468 | 467 |
if(SDL_GetCurrentDisplayMode(0, &DM) == 0) |