| ... | ... |
@@ -1,6 +1,5 @@ |
| 1 | 1 |
#include <stdio.h> |
| 2 | 2 |
#include <stdlib.h> |
| 3 |
-#include <unistd.h> |
|
| 4 | 3 |
|
| 5 | 4 |
#include "uxn.h" |
| 6 | 5 |
|
| ... | ... |
@@ -89,8 +88,11 @@ static void |
| 89 | 88 |
run(Uxn *u) |
| 90 | 89 |
{
|
| 91 | 90 |
Device *d = &u->dev[0]; |
| 92 |
- while((!d->dat[0xf]) && (read(0, &d->dat[0x2], 1) > 0)) |
|
| 93 |
- uxn_eval(u, GETVECTOR(d)); |
|
| 91 |
+ while(!d->dat[0xf]) {
|
|
| 92 |
+ int c = fgetc(stdin); |
|
| 93 |
+ if(c != EOF) |
|
| 94 |
+ console_input(u, (Uint8)c); |
|
| 95 |
+ } |
|
| 94 | 96 |
} |
| 95 | 97 |
|
| 96 | 98 |
static int |
| ... | ... |
@@ -106,50 +108,50 @@ load(Uxn *u, char *filepath) |
| 106 | 108 |
return 1; |
| 107 | 109 |
} |
| 108 | 110 |
|
| 109 |
-int |
|
| 110 |
-main(int argc, char **argv) |
|
| 111 |
+static int |
|
| 112 |
+start(Uxn *u) |
|
| 111 | 113 |
{
|
| 112 |
- Uxn u; |
|
| 113 |
- int i, loaded = 0; |
|
| 114 |
- |
|
| 115 | 114 |
bank0 = (Uint8 *)calloc(0x10000, sizeof(Uint8)); |
| 116 | 115 |
bank1 = (Uint8 *)calloc(0x10000, sizeof(Uint8)); |
| 117 |
- if(!uxn_boot(&u, bank1, bank0 + PAGE_DEV, (Stack *)(bank0 + PAGE_WST), (Stack *)(bank0 + PAGE_RST))) |
|
| 116 |
+ if(!uxn_boot(u, bank1, bank0 + PAGE_DEV, (Stack *)(bank0 + PAGE_WST), (Stack *)(bank0 + PAGE_RST))) |
|
| 118 | 117 |
return error("Boot", "Failed");
|
| 118 |
+ /* system */ uxn_port(u, 0x0, system_dei, system_deo); |
|
| 119 |
+ /* console */ uxn_port(u, 0x1, nil_dei, console_deo); |
|
| 120 |
+ /* empty */ uxn_port(u, 0x2, nil_dei, nil_deo); |
|
| 121 |
+ /* empty */ uxn_port(u, 0x3, nil_dei, nil_deo); |
|
| 122 |
+ /* empty */ uxn_port(u, 0x4, nil_dei, nil_deo); |
|
| 123 |
+ /* empty */ uxn_port(u, 0x5, nil_dei, nil_deo); |
|
| 124 |
+ /* empty */ uxn_port(u, 0x6, nil_dei, nil_deo); |
|
| 125 |
+ /* empty */ uxn_port(u, 0x7, nil_dei, nil_deo); |
|
| 126 |
+ /* empty */ uxn_port(u, 0x8, nil_dei, nil_deo); |
|
| 127 |
+ /* empty */ uxn_port(u, 0x9, nil_dei, nil_deo); |
|
| 128 |
+ /* file */ uxn_port(u, 0xa, nil_dei, file_deo); |
|
| 129 |
+ /* datetime */ uxn_port(u, 0xb, datetime_dei, nil_deo); |
|
| 130 |
+ /* empty */ uxn_port(u, 0xc, nil_dei, nil_deo); |
|
| 131 |
+ /* empty */ uxn_port(u, 0xd, nil_dei, nil_deo); |
|
| 132 |
+ /* empty */ uxn_port(u, 0xe, nil_dei, nil_deo); |
|
| 133 |
+ /* empty */ uxn_port(u, 0xf, nil_dei, nil_deo); |
|
| 134 |
+ return 1; |
|
| 135 |
+} |
|
| 119 | 136 |
|
| 120 |
- /* system */ uxn_port(&u, 0x0, system_dei, system_deo); |
|
| 121 |
- /* console */ uxn_port(&u, 0x1, nil_dei, console_deo); |
|
| 122 |
- /* empty */ uxn_port(&u, 0x2, nil_dei, nil_deo); |
|
| 123 |
- /* empty */ uxn_port(&u, 0x3, nil_dei, nil_deo); |
|
| 124 |
- /* empty */ uxn_port(&u, 0x4, nil_dei, nil_deo); |
|
| 125 |
- /* empty */ uxn_port(&u, 0x5, nil_dei, nil_deo); |
|
| 126 |
- /* empty */ uxn_port(&u, 0x6, nil_dei, nil_deo); |
|
| 127 |
- /* empty */ uxn_port(&u, 0x7, nil_dei, nil_deo); |
|
| 128 |
- /* empty */ uxn_port(&u, 0x8, nil_dei, nil_deo); |
|
| 129 |
- /* empty */ uxn_port(&u, 0x9, nil_dei, nil_deo); |
|
| 130 |
- /* file */ uxn_port(&u, 0xa, nil_dei, file_deo); |
|
| 131 |
- /* datetime */ uxn_port(&u, 0xb, datetime_dei, nil_deo); |
|
| 132 |
- /* empty */ uxn_port(&u, 0xc, nil_dei, nil_deo); |
|
| 133 |
- /* empty */ uxn_port(&u, 0xd, nil_dei, nil_deo); |
|
| 134 |
- /* empty */ uxn_port(&u, 0xe, nil_dei, nil_deo); |
|
| 135 |
- /* empty */ uxn_port(&u, 0xf, nil_dei, nil_deo); |
|
| 136 |
- |
|
| 137 |
- for(i = 1; i < argc; i++) {
|
|
| 138 |
- if(!loaded++) {
|
|
| 139 |
- if(!load(&u, argv[i])) |
|
| 140 |
- return error("Load", "Failed");
|
|
| 141 |
- if(!uxn_eval(&u, PAGE_PROGRAM)) |
|
| 142 |
- return error("Init", "Failed");
|
|
| 143 |
- } else {
|
|
| 144 |
- char *p = argv[i]; |
|
| 145 |
- while(*p) console_input(&u, *p++); |
|
| 146 |
- console_input(&u, '\n'); |
|
| 147 |
- } |
|
| 137 |
+int |
|
| 138 |
+main(int argc, char **argv) |
|
| 139 |
+{
|
|
| 140 |
+ Uxn u; |
|
| 141 |
+ int i; |
|
| 142 |
+ if(argc < 2) |
|
| 143 |
+ return error("Usage", "uxncli game.rom args");
|
|
| 144 |
+ if(!start(&u)) |
|
| 145 |
+ return error("Start", "Failed");
|
|
| 146 |
+ if(!load(&u, argv[1])) |
|
| 147 |
+ return error("Load", "Failed");
|
|
| 148 |
+ if(!uxn_eval(&u, PAGE_PROGRAM)) |
|
| 149 |
+ return error("Init", "Failed");
|
|
| 150 |
+ for(i = 2; i < argc; i++) {
|
|
| 151 |
+ char *p = argv[i]; |
|
| 152 |
+ while(*p) console_input(&u, *p++); |
|
| 153 |
+ console_input(&u, '\n'); |
|
| 148 | 154 |
} |
| 149 |
- if(!loaded) |
|
| 150 |
- return error("Input", "Missing");
|
|
| 151 |
- |
|
| 152 | 155 |
run(&u); |
| 153 |
- |
|
| 154 | 156 |
return 0; |
| 155 | 157 |
} |