Browse code

Fixed crashing bug with zoom flag

neauoire authored on 21/09/2021 22:56:42
Showing 1 changed files
... ...
@@ -24,7 +24,6 @@ WITH REGARD TO THIS SOFTWARE.
24 24
 #define WIDTH 64 * 8
25 25
 #define HEIGHT 40 * 8
26 26
 #define PAD 4
27
-
28 27
 #define FIXED_SIZE 0
29 28
 #define POLYPHONY 4
30 29
 #define BENCH 0
... ...
@@ -34,7 +33,6 @@ static SDL_Texture *gTexture;
34 33
 static SDL_Renderer *gRenderer;
35 34
 static SDL_AudioDeviceID audio_id;
36 35
 static SDL_Rect gRect;
37
-
38 36
 /* devices */
39 37
 static Ppu ppu;
40 38
 static Apu apu[POLYPHONY];
... ...
@@ -110,17 +108,12 @@ stdin_handler(void *p)
110 108
 static void
111 109
 set_window_size(SDL_Window *window, int w, int h)
112 110
 {
113
-	int win_x, win_y;
114
-	int win_cent_x, win_cent_y;
115
-	int old_win_sz_x, old_win_sz_y;
116
-
117
-	SDL_GetWindowPosition(window, &win_x, &win_y);
118
-	SDL_GetWindowSize(window, &old_win_sz_x, &old_win_sz_y);
119
-
120
-	win_cent_x = win_x + old_win_sz_x / 2;
121
-	win_cent_y = win_y + old_win_sz_y / 2;
122
-
123
-	SDL_SetWindowPosition(window, win_cent_x - w / 2, win_cent_y - h / 2);
111
+	SDL_Point win, win_old, win_ratio;
112
+	SDL_GetWindowPosition(window, &win.x, &win.y);
113
+	SDL_GetWindowSize(window, &win_old.x, &win_old.y);
114
+	win_ratio.x = win.x + win_old.x / 2;
115
+	win_ratio.y = win.y + win_old.y / 2;
116
+	SDL_SetWindowPosition(window, win_ratio.x - w / 2, win_ratio.y - h / 2);
124 117
 	SDL_SetWindowSize(window, w, h);
125 118
 }
126 119
 
... ...
@@ -584,20 +577,14 @@ main(int argc, char **argv)
584 577
 	Uxn u;
585 578
 	int i;
586 579
 
587
-	if(argc < 2) return error("usage", "uxnemu file.rom");
588
-	if(!uxn_boot(&u)) return error("Boot", "Failed to start uxn.");
589
-	if(!load(&u, argv[argc - 1])) return error("Load", "Failed to open rom.");
590
-	if(!init(&u)) return error("Init", "Failed to initialize emulator.");
591
-	if(!set_size(WIDTH, HEIGHT, 0)) return error("Window", "Failed to set window size.");
592
-
593
-	for(i = 1; i < argc - 1; i++) {
594
-		if(strcmp(argv[i], "-s") == 0) {
595
-			if((i + 1) < argc - 1)
596
-				set_zoom(&u, atoi(argv[++i]));
597
-			else
598
-				return error("Opt", "-s No scale provided.");
599
-		}
600
-	}
580
+	if(argc < 2)
581
+		return error("usage", "uxnemu file.rom");
582
+	if(!uxn_boot(&u))
583
+		return error("Boot", "Failed to start uxn.");
584
+	if(!load(&u, argv[argc - 1]))
585
+		return error("Load", "Failed to open rom.");
586
+	if(!init(&u))
587
+		return error("Init", "Failed to initialize emulator.");
601 588
 
602 589
 	/* system   */ devsystem = uxn_port(&u, 0x0, system_talk);
603 590
 	/* console  */ devconsole = uxn_port(&u, 0x1, console_talk);
... ...
@@ -616,6 +603,18 @@ main(int argc, char **argv)
616 603
 	/* unused   */ uxn_port(&u, 0xe, nil_talk);
617 604
 	/* unused   */ uxn_port(&u, 0xf, nil_talk);
618 605
 
606
+	if(!set_size(WIDTH, HEIGHT, 0))
607
+		return error("Window", "Failed to set window size.");
608
+
609
+	for(i = 1; i < argc - 1; i++) {
610
+		if(strcmp(argv[i], "-s") == 0) {
611
+			if((i + 1) < argc - 1)
612
+				set_zoom(&u, atoi(argv[++i]));
613
+			else
614
+				return error("Opt", "-s No scale provided.");
615
+		}
616
+	}
617
+
619 618
 	run(&u);
620 619
 	quit();
621 620
 	return 0;