commit 1c7c37f
Devine Lu Linvega
·
2025-01-19 19:34:04 +0000 UTC
parent 65c4799
Housekeeping
4 files changed,
+53,
-82
+0,
-1
1@@ -72,7 +72,6 @@ The file device is _sandboxed_, meaning that it should not be able to read or wr
2
3 - `F1` toggle zoom
4 - `F2` toggle debugger
5-- `F3` quit
6 - `F4` reboot
7 - `F5` reboot(soft)
8
+25,
-51
1@@ -6,7 +6,7 @@
2 #include "system.h"
3
4 /*
5-Copyright (c) 2022-2024 Devine Lu Linvega, Andrew Alderwick
6+Copyright (c) 2022-2025 Devine Lu Linvega, Andrew Alderwick
7
8 Permission to use, copy, modify, and distribute this software for any
9 purpose with or without fee is hereby granted, provided that the above
10@@ -16,31 +16,7 @@ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE.
12 */
13
14-char *boot_rom;
15-
16-static void
17-system_zero(int soft)
18-{
19- int i;
20- for(i = soft ? 0x100 : 0; i < 0x10000; i++)
21- uxn.ram[i] = 0;
22- for(i = 0x0; i < 0x100; i++)
23- uxn.dev[i] = 0;
24- uxn.wst.ptr = uxn.rst.ptr = 0;
25-}
26-
27-static int
28-system_load(Uint8 *ram, char *filename)
29-{
30- FILE *f = fopen(filename, "rb");
31- if(f) {
32- int i = 0, l = fread(ram, 0x10000 - PAGE_PROGRAM, 1, f);
33- while(l && ++i < RAM_PAGES)
34- l = fread(ram + 0x10000 * i - PAGE_PROGRAM, 0x10000, 1, f);
35- fclose(f);
36- }
37- return !!f;
38-}
39+char *boot_path;
40
41 static void
42 system_print(Stack *s)
43@@ -51,25 +27,6 @@ system_print(Stack *s)
44 fprintf(stderr, "< \n");
45 }
46
47-void
48-system_inspect(void)
49-{
50- fprintf(stderr, "WST "), system_print(&uxn.wst);
51- fprintf(stderr, "RST "), system_print(&uxn.rst);
52-}
53-
54-void
55-system_image(void)
56-{
57- int i, len = 0;
58- FILE *f = fopen("image.rom", "wb");
59- for(i = PAGE_PROGRAM; i < 0x10000; i++)
60- if(uxn.ram[i])
61- len = i;
62- fwrite(uxn.ram + PAGE_PROGRAM, len - PAGE_PROGRAM + 1, 1, f), fclose(f);
63- printf("Saved image.rom, %d bytes\n", len);
64-}
65-
66 int
67 system_error(char *msg, const char *err)
68 {
69@@ -77,19 +34,35 @@ system_error(char *msg, const char *err)
70 return 0;
71 }
72
73+static int
74+system_load(Uint8 *ram, char *rom_path)
75+{
76+ FILE *f = fopen(rom_path, "rb");
77+ if(f) {
78+ int i = 0, l = fread(ram, 0x10000 - PAGE_PROGRAM, 1, f);
79+ while(l && ++i < RAM_PAGES)
80+ l = fread(ram + 0x10000 * i - PAGE_PROGRAM, 0x10000, 1, f);
81+ fclose(f);
82+ }
83+ return !!f;
84+}
85+
86 void
87 system_reboot(int soft)
88 {
89- system_zero(soft);
90- if(system_load(&uxn.ram[PAGE_PROGRAM], boot_rom))
91+ int i;
92+ for(i = soft ? 0x100 : 0; i < 0x10000; i++) uxn.ram[i] = 0;
93+ for(i = 0x0; i < 0x100; i++) uxn.dev[i] = 0;
94+ uxn.wst.ptr = uxn.rst.ptr = 0;
95+ if(system_load(&uxn.ram[PAGE_PROGRAM], boot_path))
96 uxn_eval(PAGE_PROGRAM);
97 }
98
99 int
100-system_boot(Uint8 *ram, char *boot)
101+system_boot(Uint8 *ram, char *rom_path)
102 {
103- uxn.ram = ram, boot_rom = boot;
104- return system_load(uxn.ram + PAGE_PROGRAM, boot);
105+ uxn.ram = ram, boot_path = rom_path;
106+ return system_load(uxn.ram + PAGE_PROGRAM, rom_path);
107 }
108
109 /* IO */
110@@ -144,7 +117,8 @@ system_deo(Uint8 port)
111 uxn.rst.ptr = uxn.dev[5];
112 break;
113 case 0xe:
114- system_inspect();
115+ fprintf(stderr, "WST "), system_print(&uxn.wst);
116+ fprintf(stderr, "RST "), system_print(&uxn.rst);
117 break;
118 }
119 }
+2,
-4
1@@ -1,5 +1,5 @@
2 /*
3-Copyright (c) 2024 Devine Lu Linvega, Andrew Alderwick
4+Copyright (c) 2022-2025 Devine Lu Linvega, Andrew Alderwick
5
6 Permission to use, copy, modify, and distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8@@ -12,10 +12,8 @@ WITH REGARD TO THIS SOFTWARE.
9 #define RAM_PAGES 0x10
10
11 void system_reboot(int soft);
12-void system_inspect(void);
13-void system_image(void);
14 int system_error(char *msg, const char *err);
15-int system_boot(Uint8 *ram, char *rom);
16+int system_boot(Uint8 *ram, char *rompath);
17
18 Uint8 system_dei(Uint8 addr);
19 void system_deo(Uint8 addr);
+26,
-26
1@@ -20,7 +20,7 @@
2 Uxn uxn;
3
4 /*
5-Copyright (c) 2022-2024 Devine Lu Linvega
6+Copyright (c) 2022-2025 Devine Lu Linvega
7
8 Permission to use, copy, modify, and distribute this software for any
9 purpose with or without fee is hereby granted, provided that the above
10@@ -95,6 +95,12 @@ emu_restart(int soft)
11 system_reboot(soft);
12 }
13
14+static void
15+emu_rescale(void)
16+{
17+ screen_resize(uxn_screen.width, uxn_screen.height, uxn_screen.scale >= 3 ? 1 : uxn_screen.scale + 1);
18+}
19+
20 static Uint8
21 get_button(KeySym sym)
22 {
23@@ -112,12 +118,6 @@ get_button(KeySym sym)
24 return 0x00;
25 }
26
27-static void
28-toggle_scale(void)
29-{
30- screen_resize(uxn_screen.width, uxn_screen.height, uxn_screen.scale >= 3 ? 1 : uxn_screen.scale + 1);
31-}
32-
33 static void
34 emu_event(void)
35 {
36@@ -138,9 +138,8 @@ emu_event(void)
37 KeySym sym;
38 XLookupString((XKeyPressedEvent *)&ev, buf, 7, &sym, 0);
39 switch(sym) {
40- case XK_F1: toggle_scale(); break;
41- case XK_F2: system_inspect(), uxn.dev[0x0e] = !uxn.dev[0x0e]; break;
42- case XK_F3: system_image(); break;
43+ case XK_F1: emu_rescale(); break;
44+ case XK_F2: emu_deo(0xe, 0x1); break;
45 case XK_F4: emu_restart(0); break;
46 case XK_F5: emu_restart(1); break;
47 }
48@@ -178,15 +177,23 @@ emu_event(void)
49 }
50 }
51
52+static void
53+display_hidecursor(void)
54+{
55+ XColor black = {0};
56+ char empty[] = {0};
57+ Pixmap bitmap = XCreateBitmapFromData(display, window, empty, 1, 1);
58+ Cursor blank = XCreatePixmapCursor(display, bitmap, bitmap, &black, &black, 0, 0);
59+ XDefineCursor(display, window, blank);
60+ XFreeCursor(display, blank);
61+ XFreePixmap(display, bitmap);
62+}
63+
64 static int
65 display_init(void)
66 {
67 Atom wmDelete;
68 Visual *visual;
69- XColor black = {0};
70- char empty[] = {0};
71- Pixmap bitmap;
72- Cursor blank;
73 XClassHint class = {"uxn11", "Uxn"};
74 display = XOpenDisplay(NULL);
75 if(!display)
76@@ -204,19 +211,13 @@ display_init(void)
77 XSetClassHint(display, window, &class);
78 XMapWindow(display, window);
79 ximage = XCreateImage(display, visual, DefaultDepth(display, DefaultScreen(display)), ZPixmap, 0, (char *)uxn_screen.pixels, uxn_screen.width, uxn_screen.height, 32, 0);
80- /* hide cursor */
81- bitmap = XCreateBitmapFromData(display, window, empty, 1, 1);
82- blank = XCreatePixmapCursor(display, bitmap, bitmap, &black, &black, 0, 0);
83- XDefineCursor(display, window, blank);
84- XFreeCursor(display, blank);
85- XFreePixmap(display, bitmap);
86+ display_hidecursor();
87 return 1;
88 }
89
90 static int
91 emu_run(void)
92 {
93- int i = 1, n;
94 char expirations[8], coninp[CONINBUFSIZE];
95 struct pollfd fds[3];
96 static const struct itimerspec screen_tspec = {{0, 16666666}, {0, 16666666}};
97@@ -233,19 +234,18 @@ emu_run(void)
98 while(XPending(display))
99 emu_event();
100 if(poll(&fds[1], 1, 0)) {
101- int x, y, w, h;
102 read(fds[1].fd, expirations, 8);
103 if(uxn_screen.vector)
104 uxn_eval(uxn_screen.vector);
105 if(uxn_screen.x2 && uxn_screen.y2 && screen_changed()) {
106- x = uxn_screen.x1 * uxn_screen.scale, y = uxn_screen.y1 * uxn_screen.scale;
107- w = uxn_screen.x2 * uxn_screen.scale - x, h = uxn_screen.y2 * uxn_screen.scale - y;
108+ int x = uxn_screen.x1 * uxn_screen.scale, y = uxn_screen.y1 * uxn_screen.scale;
109+ int w = uxn_screen.x2 * uxn_screen.scale - x, h = uxn_screen.y2 * uxn_screen.scale - y;
110 screen_redraw();
111 XPutImage(display, window, DefaultGC(display, 0), ximage, x, y, x + PAD, y + PAD, w, h);
112 }
113 }
114 if((fds[2].revents & POLLIN) != 0) {
115- n = read(fds[2].fd, coninp, CONINBUFSIZE - 1);
116+ int i = 1, n = read(fds[2].fd, coninp, CONINBUFSIZE - 1);
117 coninp[n] = 0;
118 for(i = 0; i < n; i++)
119 console_input(coninp[i], CONSOLE_STD);
120@@ -259,7 +259,7 @@ main(int argc, char **argv)
121 {
122 int i = 1;
123 if(argc == 2 && argv[1][0] == '-' && argv[1][1] == 'v')
124- return !fprintf(stdout, "Uxn11 - Varvara Emulator, 17 Jan 2025.\n");
125+ return !fprintf(stdout, "Uxn11 - Varvara Emulator, 19 Jan 2025.\n");
126 else if(argc == 1)
127 return !fprintf(stdout, "usage: %s [-v] file.rom [args..]\n", argv[0]);
128 else if(!display_init())