commit 6ebc44b
neauoire
·
2023-08-16 20:01:50 +0000 UTC
parent 1cc1bbc
Delay window generation to after eval
1 files changed,
+25,
-25
+25,
-25
1@@ -86,12 +86,7 @@ emu_resize(int width, int height)
2 static int
3 emu_start(Uxn *u, char *rom)
4 {
5- if(!system_load(u, rom))
6- return 0;
7- if(!uxn_screen.width || !uxn_screen.height)
8- screen_resize(WIDTH, HEIGHT);
9- if(!uxn_eval(u, PAGE_PROGRAM))
10- return system_error("boot", "Failed to start rom.");
11+
12 return 1;
13 }
14
15@@ -182,8 +177,15 @@ emu_event(Uxn *u)
16 }
17
18 static int
19-display_start(char *title)
20+emu_run(Uxn *u, char *rom)
21 {
22+ int i = 1, n;
23+ char expirations[8];
24+ char coninp[CONINBUFSIZE];
25+ struct pollfd fds[3];
26+ static const struct itimerspec screen_tspec = {{0, 16666666}, {0, 16666666}};
27+
28+ /* display */
29 Atom wmDelete;
30 display = XOpenDisplay(NULL);
31 visual = DefaultVisual(display, 0);
32@@ -193,21 +195,10 @@ display_start(char *title)
33 XSelectInput(display, window, ButtonPressMask | ButtonReleaseMask | PointerMotionMask | ExposureMask | KeyPressMask | KeyReleaseMask);
34 wmDelete = XInternAtom(display, "WM_DELETE_WINDOW", True);
35 XSetWMProtocols(display, window, &wmDelete, 1);
36- XStoreName(display, window, title);
37+ XStoreName(display, window, rom);
38 XMapWindow(display, window);
39 ximage = XCreateImage(display, visual, DefaultDepth(display, DefaultScreen(display)), ZPixmap, 0, (char *)uxn_screen.pixels, uxn_screen.width * SCALE, uxn_screen.height * SCALE, 32, 0);
40 hide_cursor();
41- return 1;
42-}
43-
44-static int
45-emu_run(Uxn *u, char *rom)
46-{
47- int i = 1, n;
48- char expirations[8];
49- char coninp[CONINBUFSIZE];
50- struct pollfd fds[3];
51- static const struct itimerspec screen_tspec = {{0, 16666666}, {0, 16666666}};
52
53 /* timer */
54 fds[0].fd = XConnectionNumber(display);
55@@ -242,6 +233,13 @@ emu_run(Uxn *u, char *rom)
56 return 1;
57 }
58
59+static int
60+emu_end(Uxn *u)
61+{
62+ XDestroyImage(ximage);
63+ return u->dev[0x0f] & 0x7f;
64+}
65+
66 int
67 main(int argc, char **argv)
68 {
69@@ -266,10 +264,13 @@ main(int argc, char **argv)
70 if(!uxn_boot(&u, (Uint8 *)calloc(0x10000 * RAM_PAGES, sizeof(Uint8))))
71 return system_error("boot", "Failed");
72 /* start sequence */
73- if(!emu_start(&u, rom_path))
74- return system_error("start", rom_path);
75- if(!display_start(rom_path))
76- return system_error("display", "Failed");
77+ screen_resize(WIDTH, HEIGHT);
78+
79+ if(!system_load(&u, rom_path))
80+ return 0;
81+ if(!uxn_eval(&u, PAGE_PROGRAM))
82+ return system_error("boot", "Failed to start rom.");
83+
84 /* console vector */
85 for(i = 2; i < argc; i++) {
86 char *p = argv[i];
87@@ -277,6 +278,5 @@ main(int argc, char **argv)
88 console_input(&u, '\n', i == argc ? CONSOLE_END : CONSOLE_EOA);
89 }
90 emu_run(&u, rom_path);
91- XDestroyImage(ximage);
92- return 0;
93+ return emu_end(&u);
94 }