commit 7a9bc71
neauoire
·
2023-11-11 17:50:19 +0000 UTC
parent d98e8d4
Housekeeping
8 files changed,
+43,
-57
+2,
-2
1@@ -1,6 +1,6 @@
2 # Uxn11
3
4-An emulator for the [Uxn stack-machine](https://wiki.xxiivv.com/site/uxn.html), written in ANSI C.
5+An emulator for the [Uxn stack-machine](https://wiki.xxiivv.com/site/uxn.html), written in ANSI C. The emulator contains a few linux specific utilities in the Console device to allow for it to interface with the unix systems.
6
7 ## Building
8
9@@ -37,7 +37,7 @@ bin/uxnemu bin/polycat.rom arg1 arg2
10 The file device is _sandboxed_, meaning that it should not be able to read or write outside of the working directory.
11
12 - `00` system
13-- `10` console
14+- `10` console(+)
15 - `20` screen
16 - `80` controller
17 - `90` mouse
+36,
-35
1@@ -41,35 +41,38 @@ static int from_child_fd[2];
2 static int saved_in;
3 static int saved_out;
4
5+struct winsize ws = {24, 80, 8, 12};
6+
7 static void
8-parse_args(Uint8 *d, Uxn *u)
9+parse_args(Uxn *u, Uint8 *d)
10 {
11- int addr = (d[0x3] << 8) | d[0x4];
12+ Uint8 *port_addr = d + 0x3;
13+ int addr = PEEK2(port_addr);
14 char *pos = (char *)&u->ram[addr];
15 int i = 0;
16 do {
17 fork_args[i++] = pos;
18- while (*pos != 0) pos++;
19+ while(*pos != 0) pos++;
20 pos++;
21- } while (*pos != '\0');
22+ } while(*pos != '\0');
23 fork_args[i] = NULL;
24 }
25
26 /* call after we're sure the process has exited */
27 static void
28-clean_after_child()
29+clean_after_child(void)
30 {
31 child_pid = 0;
32- if (child_mode >= 0x80) {
33+ if(child_mode >= 0x80) {
34 close(pty_fd);
35 dup2(saved_in, 0);
36 dup2(saved_out, 1);
37 } else {
38- if (child_mode & 0x01) {
39+ if(child_mode & 0x01) {
40 close(to_child_fd[1]);
41 dup2(saved_out, 1);
42 }
43- if (child_mode & 0x06) {
44+ if(child_mode & 0x06) {
45 close(from_child_fd[0]);
46 dup2(saved_in, 0);
47 }
48@@ -99,14 +102,14 @@ console_listen(Uxn *u, int i, int argc, char **argv)
49 }
50
51 static void
52-start_fork_pty(Uint8 *d, Uxn *u)
53+start_fork_pty(Uint8 *d)
54 {
55 int fd = -1;
56 pid_t pid = forkpty(&fd, NULL, NULL, NULL);
57- if (pid < 0) { /* failure */
58+ if(pid < 0) { /* failure */
59 d[0x6] = 0xff;
60 fprintf(stderr, "fork failure\n");
61- } else if (pid == 0) { /* child */
62+ } else if(pid == 0) { /* child */
63 setenv("TERM", "ansi", 1);
64 execvp(fork_args[0], fork_args);
65 d[0x6] = 0xff;
66@@ -114,7 +117,6 @@ start_fork_pty(Uint8 *d, Uxn *u)
67 } else { /*parent*/
68 child_pid = pid;
69 pty_fd = fd;
70- struct winsize ws = {24, 80, 8, 12};
71 ioctl(fd, TIOCSWINSZ, &ws);
72 saved_in = dup(0);
73 saved_out = dup(1);
74@@ -124,20 +126,20 @@ start_fork_pty(Uint8 *d, Uxn *u)
75 }
76
77 static void
78-start_fork_pipe(Uint8 *d, Uxn *u)
79+start_fork_pipe(Uint8 *d)
80 {
81- if (child_mode & 0x01) {
82+ if(child_mode & 0x01) {
83 /* parent writes to child's stdin */
84- if (pipe(to_child_fd) == -1) {
85+ if(pipe(to_child_fd) == -1) {
86 d[0x6] = 0xff;
87 fprintf(stderr, "pipe error: to child\n");
88 return;
89 }
90 }
91
92- if (child_mode & 0x06) {
93+ if(child_mode & 0x06) {
94 /* parent reads from child's stdout and/or stderr */
95- if (pipe(from_child_fd) == -1) {
96+ if(pipe(from_child_fd) == -1) {
97 d[0x6] = 0xff;
98 fprintf(stderr, "pipe error: from child\n");
99 return;
100@@ -145,17 +147,17 @@ start_fork_pipe(Uint8 *d, Uxn *u)
101 }
102
103 pid_t pid = fork();
104- if (pid < 0) { /* failure */
105+ if(pid < 0) { /* failure */
106 d[0x6] = 0xff;
107 fprintf(stderr, "fork failure\n");
108- } else if (pid == 0) { /* child */
109- if (child_mode & 0x01) {
110+ } else if(pid == 0) { /* child */
111+ if(child_mode & 0x01) {
112 dup2(to_child_fd[0], 0);
113 close(to_child_fd[1]);
114 }
115- if (child_mode & 0x06) {
116- if (child_mode & 0x02) dup2(from_child_fd[1], 1);
117- if (child_mode & 0x04) dup2(from_child_fd[1], 2);
118+ if(child_mode & 0x06) {
119+ if(child_mode & 0x02) dup2(from_child_fd[1], 1);
120+ if(child_mode & 0x04) dup2(from_child_fd[1], 2);
121 close(from_child_fd[0]);
122 }
123 execvp(fork_args[0], fork_args);
124@@ -163,12 +165,12 @@ start_fork_pipe(Uint8 *d, Uxn *u)
125 fprintf(stderr, "exec failure\n");
126 } else { /*parent*/
127 child_pid = pid;
128- if (child_mode & 0x01) {
129+ if(child_mode & 0x01) {
130 saved_out = dup(1);
131 dup2(to_child_fd[1], 1);
132 close(to_child_fd[0]);
133 }
134- if (child_mode & 0x06) {
135+ if(child_mode & 0x06) {
136 saved_in = dup(0);
137 dup2(from_child_fd[0], 0);
138 close(from_child_fd[1]);
139@@ -179,10 +181,10 @@ start_fork_pipe(Uint8 *d, Uxn *u)
140 static void
141 kill_child(Uint8 *d)
142 {
143- if (child_pid) {
144+ if(child_pid) {
145 kill(child_pid, 9);
146 int wstatus;
147- if (waitpid(child_pid, &wstatus, 0)) {
148+ if(waitpid(child_pid, &wstatus, 0)) {
149 d[0x6] = 1;
150 d[0x7] = WEXITSTATUS(wstatus);
151 clean_after_child();
152@@ -196,12 +198,11 @@ start_fork(Uxn *u, Uint8 *d)
153 fflush(stderr);
154 kill_child(d);
155 child_mode = d[0x5];
156- parse_args(d, u);
157- if (child_mode >= 0x80) {
158- start_fork_pty(d, u);
159- } else {
160- start_fork_pipe(d, u);
161- }
162+ parse_args(u, d);
163+ if(child_mode >= 0x80)
164+ start_fork_pty(d);
165+ else
166+ start_fork_pipe(d);
167 }
168
169 Uint8
170@@ -211,9 +212,9 @@ console_dei(Uxn *u, Uint8 addr)
171 switch(port) {
172 case 0x6:
173 case 0x7:
174- if (child_pid) {
175+ if(child_pid) {
176 int wstatus;
177- if (waitpid(child_pid, &wstatus, WNOHANG)) {
178+ if(waitpid(child_pid, &wstatus, WNOHANG)) {
179 d[0x6] = 1;
180 d[0x7] = WEXITSTATUS(wstatus);
181 clean_after_child();
+0,
-2
1@@ -10,8 +10,6 @@ WITH REGARD TO THIS SOFTWARE.
2 */
3
4 #define CONSOLE_VERSION 1
5-#define CONSOLE_DEIMASK 0x0000
6-#define CONSOLE_DEOMASK 0x0300
7
8 #define CONSOLE_STD 0x1
9 #define CONSOLE_ARG 0x2
+0,
-2
1@@ -10,8 +10,6 @@ WITH REGARD TO THIS SOFTWARE.
2 */
3
4 #define CONTROL_VERSION 1
5-#define CONTROL_DEIMASK 0x0000
6-#define CONTROL_DEOMASK 0x0000
7
8 void controller_down(Uxn *u, Uint8 *d, Uint8 mask);
9 void controller_up(Uxn *u, Uint8 *d, Uint8 mask);
+0,
-2
1@@ -10,7 +10,5 @@ WITH REGARD TO THIS SOFTWARE.
2 */
3
4 #define DATETIME_VERSION 1
5-#define DATETIME_DEIMASK 0x07ff
6-#define DATETIME_DEOMASK 0x0000
7
8 Uint8 datetime_dei(Uxn *u, Uint8 addr);
+0,
-2
1@@ -10,8 +10,6 @@ WITH REGARD TO THIS SOFTWARE.
2 */
3
4 #define LINK_VERSION 1
5-#define LINK_DEIMASK 0x0000
6-#define LINK_DEOMASK 0xaaaa
7
8 Uint8 link_dei(Uxn *u, Uint8 addr);
9 void link_deo(Uint8 *ram, Uint8 *d, Uint8 port);
+3,
-6
1@@ -10,8 +10,6 @@ WITH REGARD TO THIS SOFTWARE.
2 */
3
4 #define SCREEN_VERSION 1
5-#define SCREEN_DEIMASK 0x003c
6-#define SCREEN_DEOMASK 0xc028
7
8 typedef struct UxnScreen {
9 int width, height, x1, y1, x2, y2;
10@@ -19,14 +17,13 @@ typedef struct UxnScreen {
11 Uint8 *fg, *bg;
12 } UxnScreen;
13
14-extern UxnScreen uxn_screen;
15-extern int emu_resize(int width, int height);
16-
17 void screen_fill(Uint8 *layer, int x1, int y1, int x2, int y2, int color);
18 void screen_palette(Uint8 *addr);
19 void screen_resize(Uint16 width, Uint16 height);
20 void screen_change(Uint16 x1, Uint16 y1, Uint16 x2, Uint16 y2);
21 void screen_redraw(Uxn *u);
22-
23 Uint8 screen_dei(Uxn *u, Uint8 addr);
24 void screen_deo(Uint8 *ram, Uint8 *d, Uint8 port);
25+
26+extern UxnScreen uxn_screen;
27+extern int emu_resize(int width, int height);
+2,
-6
1@@ -10,18 +10,14 @@ WITH REGARD TO THIS SOFTWARE.
2 */
3
4 #define SYSTEM_VERSION 2
5-#define SYSTEM_DEIMASK 0x0030
6-#define SYSTEM_DEOMASK 0xff38
7-
8 #define RAM_PAGES 0x10
9
10-extern char *boot_rom;
11-
12 void system_reboot(Uxn *u, char *rom, int soft);
13 void system_inspect(Uxn *u);
14 int system_version(char *emulator, char *date);
15 int system_error(char *msg, const char *err);
16 int system_init(Uxn *u, Uint8 *ram, char *rom);
17-
18 Uint8 system_dei(Uxn *u, Uint8 addr);
19 void system_deo(Uxn *u, Uint8 *d, Uint8 port);
20+
21+extern char *boot_rom;