| ... | ... |
@@ -104,9 +104,9 @@ screen_resize(Uint16 width, Uint16 height) |
| 104 | 104 |
uxn_screen.pixels = pixels; |
| 105 | 105 |
uxn_screen.width = width; |
| 106 | 106 |
uxn_screen.height = height; |
| 107 |
- screen_fill(uxn_screen.bg, 0, 0, uxn_screen.width, uxn_screen.height, 0); |
|
| 108 |
- screen_fill(uxn_screen.fg, 0, 0, uxn_screen.width, uxn_screen.height, 0); |
|
| 109 |
- emu_resize(); |
|
| 107 |
+ screen_fill(uxn_screen.bg, 0, 0, width, height, 0); |
|
| 108 |
+ screen_fill(uxn_screen.fg, 0, 0, width, height, 0); |
|
| 109 |
+ emu_resize(width, height); |
|
| 110 | 110 |
} |
| 111 | 111 |
|
| 112 | 112 |
void |
| ... | ... |
@@ -119,7 +119,7 @@ emu_deo(Uxn *u, Uint8 addr) |
| 119 | 119 |
} |
| 120 | 120 |
} |
| 121 | 121 |
|
| 122 |
-#pragma mark - Generics |
|
| 122 |
+/* Handlers */ |
|
| 123 | 123 |
|
| 124 | 124 |
static void |
| 125 | 125 |
audio_callback(void *u, Uint8 *stream, int len) |
| ... | ... |
@@ -166,22 +166,22 @@ set_window_size(SDL_Window *window, int w, int h) |
| 166 | 166 |
} |
| 167 | 167 |
|
| 168 | 168 |
int |
| 169 |
-emu_resize(void) |
|
| 169 |
+emu_resize(int width, int height) |
|
| 170 | 170 |
{
|
| 171 | 171 |
if(emu_texture != NULL) |
| 172 | 172 |
SDL_DestroyTexture(emu_texture); |
| 173 |
- SDL_RenderSetLogicalSize(emu_renderer, uxn_screen.width, uxn_screen.height); |
|
| 174 |
- emu_texture = SDL_CreateTexture(emu_renderer, SDL_PIXELFORMAT_RGB888, SDL_TEXTUREACCESS_STATIC, uxn_screen.width, uxn_screen.height); |
|
| 173 |
+ SDL_RenderSetLogicalSize(emu_renderer, width, height); |
|
| 174 |
+ emu_texture = SDL_CreateTexture(emu_renderer, SDL_PIXELFORMAT_RGB888, SDL_TEXTUREACCESS_STATIC, width, height); |
|
| 175 | 175 |
if(emu_texture == NULL || SDL_SetTextureBlendMode(emu_texture, SDL_BLENDMODE_NONE)) |
| 176 | 176 |
return system_error("SDL_SetTextureBlendMode", SDL_GetError());
|
| 177 | 177 |
if(SDL_UpdateTexture(emu_texture, NULL, uxn_screen.pixels, sizeof(Uint32)) != 0) |
| 178 | 178 |
return system_error("SDL_UpdateTexture", SDL_GetError());
|
| 179 |
- set_window_size(emu_window, (uxn_screen.width) * zoom, (uxn_screen.height) * zoom); |
|
| 179 |
+ set_window_size(emu_window, width * zoom, height * zoom); |
|
| 180 | 180 |
return 1; |
| 181 | 181 |
} |
| 182 | 182 |
|
| 183 | 183 |
static void |
| 184 |
-redraw(void) |
|
| 184 |
+emu_redraw(void) |
|
| 185 | 185 |
{
|
| 186 | 186 |
screen_redraw(); |
| 187 | 187 |
if(SDL_UpdateTexture(emu_texture, NULL, uxn_screen.pixels, uxn_screen.width * sizeof(Uint32)) != 0) |
| ... | ... |
@@ -226,8 +226,6 @@ init(void) |
| 226 | 226 |
return 1; |
| 227 | 227 |
} |
| 228 | 228 |
|
| 229 |
-#pragma mark - Devices |
|
| 230 |
- |
|
| 231 | 229 |
/* Boot */ |
| 232 | 230 |
|
| 233 | 231 |
static int |
| ... | ... |
@@ -287,7 +285,7 @@ capture_screen(void) |
| 287 | 285 |
} |
| 288 | 286 |
|
| 289 | 287 |
static void |
| 290 |
-restart(Uxn *u) |
|
| 288 |
+emu_restart(Uxn *u) |
|
| 291 | 289 |
{
|
| 292 | 290 |
screen_resize(WIDTH, HEIGHT); |
| 293 | 291 |
if(!start(u, "launcher.rom", 0)) |
| ... | ... |
@@ -342,19 +340,6 @@ get_key(SDL_Event *event) |
| 342 | 340 |
return 0x00; |
| 343 | 341 |
} |
| 344 | 342 |
|
| 345 |
-static void |
|
| 346 |
-do_shortcut(Uxn *u, SDL_Event *event) |
|
| 347 |
-{
|
|
| 348 |
- if(event->key.keysym.sym == SDLK_F1) |
|
| 349 |
- set_zoom(zoom == 3 ? 1 : zoom + 1); |
|
| 350 |
- else if(event->key.keysym.sym == SDLK_F2) |
|
| 351 |
- system_inspect(u); |
|
| 352 |
- else if(event->key.keysym.sym == SDLK_F3) |
|
| 353 |
- capture_screen(); |
|
| 354 |
- else if(event->key.keysym.sym == SDLK_F4) |
|
| 355 |
- restart(u); |
|
| 356 |
-} |
|
| 357 |
- |
|
| 358 | 343 |
static int |
| 359 | 344 |
handle_events(Uxn *u) |
| 360 | 345 |
{
|
| ... | ... |
@@ -364,7 +349,7 @@ handle_events(Uxn *u) |
| 364 | 349 |
if(event.type == SDL_QUIT) |
| 365 | 350 |
return 0; |
| 366 | 351 |
else if(event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_EXPOSED) |
| 367 |
- redraw(); |
|
| 352 |
+ emu_redraw(); |
|
| 368 | 353 |
else if(event.type == SDL_DROPFILE) {
|
| 369 | 354 |
screen_resize(WIDTH, HEIGHT); |
| 370 | 355 |
start(u, event.drop.file, 0); |
| ... | ... |
@@ -391,12 +376,17 @@ handle_events(Uxn *u) |
| 391 | 376 |
controller_key(u, &u->dev[0x80], get_key(&event)); |
| 392 | 377 |
else if(get_button(&event)) |
| 393 | 378 |
controller_down(u, &u->dev[0x80], get_button(&event)); |
| 394 |
- else |
|
| 395 |
- do_shortcut(u, &event); |
|
| 379 |
+ else if(event.key.keysym.sym == SDLK_F1) |
|
| 380 |
+ set_zoom(zoom == 3 ? 1 : zoom + 1); |
|
| 381 |
+ else if(event.key.keysym.sym == SDLK_F2) |
|
| 382 |
+ system_inspect(u); |
|
| 383 |
+ else if(event.key.keysym.sym == SDLK_F3) |
|
| 384 |
+ capture_screen(); |
|
| 385 |
+ else if(event.key.keysym.sym == SDLK_F4) |
|
| 386 |
+ emu_restart(u); |
|
| 396 | 387 |
ksym = event.key.keysym.sym; |
| 397 |
- if(SDL_PeepEvents(&event, 1, SDL_PEEKEVENT, SDL_KEYUP, SDL_KEYUP) == 1 && ksym == event.key.keysym.sym) {
|
|
| 388 |
+ if(SDL_PeepEvents(&event, 1, SDL_PEEKEVENT, SDL_KEYUP, SDL_KEYUP) == 1 && ksym == event.key.keysym.sym) |
|
| 398 | 389 |
return 1; |
| 399 |
- } |
|
| 400 | 390 |
} else if(event.type == SDL_KEYUP) |
| 401 | 391 |
controller_up(u, &u->dev[0x80], get_button(&event)); |
| 402 | 392 |
else if(event.type == SDL_JOYAXISMOTION) {
|
| ... | ... |
@@ -473,7 +463,7 @@ run(Uxn *u) |
| 473 | 463 |
next_refresh = now + frame_interval; |
| 474 | 464 |
uxn_eval(u, screen_vector); |
| 475 | 465 |
if(uxn_screen.x2) |
| 476 |
- redraw(); |
|
| 466 |
+ emu_redraw(); |
|
| 477 | 467 |
} |
| 478 | 468 |
if(BENCH) {
|
| 479 | 469 |
/* no delay */ |