... | ... |
@@ -35,7 +35,7 @@ system_print(Stack *s, char *name) |
35 | 35 |
static void |
36 | 36 |
system_cmd(Uint8 *ram, Uint16 addr) |
37 | 37 |
{ |
38 |
- if(ram[addr] == 0x01) { |
|
38 |
+ if(ram[addr] == 0x1) { |
|
39 | 39 |
Uint16 i, length = PEEK2(ram + addr + 1); |
40 | 40 |
Uint16 a_page = PEEK2(ram + addr + 1 + 2), a_addr = PEEK2(ram + addr + 1 + 4); |
41 | 41 |
Uint16 b_page = PEEK2(ram + addr + 1 + 6), b_addr = PEEK2(ram + addr + 1 + 8); |
... | ... |
@@ -86,7 +86,7 @@ system_deo(Uxn *u, Uint8 *d, Uint8 port) |
86 | 86 |
int |
87 | 87 |
uxn_halt(Uxn *u, Uint8 instr, Uint8 err, Uint16 addr) |
88 | 88 |
{ |
89 |
- Uint8 *d = &u->dev[0x00]; |
|
89 |
+ Uint8 *d = &u->dev[0]; |
|
90 | 90 |
Uint16 handler = PEEK2(d); |
91 | 91 |
if(handler) { |
92 | 92 |
u->wst.ptr = 4; |
... | ... |
@@ -101,3 +101,27 @@ uxn_halt(Uxn *u, Uint8 instr, Uint8 err, Uint16 addr) |
101 | 101 |
} |
102 | 102 |
return 0; |
103 | 103 |
} |
104 |
+ |
|
105 |
+int |
|
106 |
+console_input(Uxn *u, char c, int type) |
|
107 |
+{ |
|
108 |
+ Uint8 *d = &u->dev[0x10]; |
|
109 |
+ d[0x2] = c; |
|
110 |
+ d[0x7] = type; |
|
111 |
+ return uxn_eval(u, PEEK2(d)); |
|
112 |
+} |
|
113 |
+ |
|
114 |
+void |
|
115 |
+console_deo(Uint8 *d, Uint8 port) |
|
116 |
+{ |
|
117 |
+ switch(port) { |
|
118 |
+ case 0x8: |
|
119 |
+ fputc(d[port], stdout); |
|
120 |
+ fflush(stdout); |
|
121 |
+ return; |
|
122 |
+ case 0x9: |
|
123 |
+ fputc(d[port], stderr); |
|
124 |
+ fflush(stderr); |
|
125 |
+ return; |
|
126 |
+ } |
|
127 |
+} |
... | ... |
@@ -11,6 +11,13 @@ WITH REGARD TO THIS SOFTWARE. |
11 | 11 |
|
12 | 12 |
#define RAM_PAGES 0x10 |
13 | 13 |
|
14 |
+#define CONSOLE_STD 0x0 |
|
15 |
+#define CONSOLE_ARG 0x2 |
|
16 |
+#define CONSOLE_EOA 0x3 |
|
17 |
+#define CONSOLE_END 0x4 |
|
18 |
+ |
|
14 | 19 |
int system_load(Uxn *u, char *filename); |
15 |
-void system_deo(Uxn *u, Uint8 *d, Uint8 port); |
|
16 | 20 |
void system_inspect(Uxn *u); |
21 |
+void system_deo(Uxn *u, Uint8 *d, Uint8 port); |
|
22 |
+int console_input(Uxn *u, char c, int type); |
|
23 |
+void console_deo(Uint8 *d, Uint8 port); |
|
17 | 24 |
\ No newline at end of file |
... | ... |
@@ -27,29 +27,6 @@ emu_error(char *msg, const char *err) |
27 | 27 |
return 1; |
28 | 28 |
} |
29 | 29 |
|
30 |
-static int |
|
31 |
-console_input(Uxn *u, char c) |
|
32 |
-{ |
|
33 |
- Uint8 *d = &u->dev[0x10]; |
|
34 |
- d[0x02] = c; |
|
35 |
- return uxn_eval(u, PEEK2(d)); |
|
36 |
-} |
|
37 |
- |
|
38 |
-static void |
|
39 |
-console_deo(Uint8 *d, Uint8 port) |
|
40 |
-{ |
|
41 |
- switch(port) { |
|
42 |
- case 0x8: |
|
43 |
- fputc(d[port], stdout); |
|
44 |
- fflush(stdout); |
|
45 |
- return; |
|
46 |
- case 0x9: |
|
47 |
- fputc(d[port], stderr); |
|
48 |
- fflush(stderr); |
|
49 |
- return; |
|
50 |
- } |
|
51 |
-} |
|
52 |
- |
|
53 | 30 |
Uint8 |
54 | 31 |
uxn_dei(Uxn *u, Uint8 addr) |
55 | 32 |
{ |
... | ... |
@@ -86,13 +63,12 @@ main(int argc, char **argv) |
86 | 63 |
return u.dev[0x0f] & 0x7f; |
87 | 64 |
for(i = 2; i < argc; i++) { |
88 | 65 |
char *p = argv[i]; |
89 |
- while(*p) console_input(&u, *p++); |
|
90 |
- console_input(&u, '\n'); |
|
66 |
+ while(*p) console_input(&u, *p++, CONSOLE_ARG); |
|
67 |
+ console_input(&u, '\n', CONSOLE_EOA); |
|
91 | 68 |
} |
92 | 69 |
while(!u.dev[0x0f]) { |
93 | 70 |
int c = fgetc(stdin); |
94 |
- if(c != EOF) |
|
95 |
- console_input(&u, (Uint8)c); |
|
71 |
+ if(c != EOF) console_input(&u, (Uint8)c, CONSOLE_STD); |
|
96 | 72 |
} |
97 | 73 |
return u.dev[0x0f] & 0x7f; |
98 | 74 |
} |
... | ... |
@@ -71,35 +71,12 @@ error(char *msg, const char *err) |
71 | 71 |
return 0; |
72 | 72 |
} |
73 | 73 |
|
74 |
-static int |
|
75 |
-console_input(Uxn *u, char c) |
|
76 |
-{ |
|
77 |
- Uint8 *d = &u->dev[0x10]; |
|
78 |
- d[0x02] = c; |
|
79 |
- return uxn_eval(u, PEEK2(d)); |
|
80 |
-} |
|
81 |
- |
|
82 | 74 |
static int |
83 | 75 |
clamp(int val, int min, int max) |
84 | 76 |
{ |
85 | 77 |
return (val >= min) ? (val <= max) ? val : max : min; |
86 | 78 |
} |
87 | 79 |
|
88 |
-static void |
|
89 |
-console_deo(Uint8 *d, Uint8 port) |
|
90 |
-{ |
|
91 |
- switch(port) { |
|
92 |
- case 0x8: |
|
93 |
- fputc(d[port], stdout); |
|
94 |
- fflush(stdout); |
|
95 |
- return; |
|
96 |
- case 0x9: |
|
97 |
- fputc(d[port], stderr); |
|
98 |
- fflush(stderr); |
|
99 |
- return; |
|
100 |
- } |
|
101 |
-} |
|
102 |
- |
|
103 | 80 |
static Uint8 |
104 | 81 |
audio_dei(int instance, Uint8 *d, Uint8 port) |
105 | 82 |
{ |
... | ... |
@@ -475,7 +452,7 @@ handle_events(Uxn *u) |
475 | 452 |
} |
476 | 453 |
/* Console */ |
477 | 454 |
else if(event.type == stdin_event) |
478 |
- console_input(u, event.cbutton.button); |
|
455 |
+ console_input(u, event.cbutton.button, CONSOLE_STD); |
|
479 | 456 |
} |
480 | 457 |
return 1; |
481 | 458 |
} |
... | ... |
@@ -533,8 +510,8 @@ main(int argc, char **argv) |
533 | 510 |
rom_path = argv[i]; |
534 | 511 |
} else { |
535 | 512 |
char *p = argv[i]; |
536 |
- while(*p) console_input(&u, *p++); |
|
537 |
- console_input(&u, '\n'); |
|
513 |
+ while(*p) console_input(&u, *p++, CONSOLE_ARG); |
|
514 |
+ console_input(&u, '\n', i == argc ? CONSOLE_END : CONSOLE_EOA); |
|
538 | 515 |
} |
539 | 516 |
} |
540 | 517 |
if(!loaded && !start(&u, "launcher.rom")) |