Each argument is followed by a newline character.
... | ... |
@@ -69,6 +69,8 @@ system_talk(Device *d, Uint8 b0, Uint8 w) |
69 | 69 |
static int |
70 | 70 |
console_talk(Device *d, Uint8 b0, Uint8 w) |
71 | 71 |
{ |
72 |
+ if(b0 == 0x1) |
|
73 |
+ d->vector = peek16(d->dat, 0x0); |
|
72 | 74 |
if(w && b0 > 0x7) |
73 | 75 |
write(b0 - 0x7, (char *)&d->dat[b0], 1); |
74 | 76 |
return 1; |
... | ... |
@@ -134,11 +136,17 @@ uxn_halt(Uxn *u, Uint8 error, char *name, int id) |
134 | 136 |
return 0; |
135 | 137 |
} |
136 | 138 |
|
139 |
+static int |
|
140 |
+console_input(Uxn *u, char c) |
|
141 |
+{ |
|
142 |
+ devconsole->dat[0x2] = c; |
|
143 |
+ return uxn_eval(u, devconsole->vector); |
|
144 |
+} |
|
145 |
+ |
|
137 | 146 |
static void |
138 | 147 |
run(Uxn *u) |
139 | 148 |
{ |
140 |
- Uint16 vec = PAGE_PROGRAM; |
|
141 |
- uxn_eval(u, vec); |
|
149 |
+ Uint16 vec; |
|
142 | 150 |
while((!u->dev[0].dat[0xf]) && (read(0, &devconsole->dat[0x2], 1) > 0)) { |
143 | 151 |
vec = peek16(devconsole->dat, 0); |
144 | 152 |
if(!vec) vec = u->ram.ptr; /* continue after last BRK */ |
... | ... |
@@ -161,13 +169,10 @@ int |
161 | 169 |
main(int argc, char **argv) |
162 | 170 |
{ |
163 | 171 |
Uxn u; |
172 |
+ int i, loaded = 0; |
|
164 | 173 |
|
165 |
- if(argc < 2) |
|
166 |
- return error("Input", "Missing"); |
|
167 | 174 |
if(!uxn_boot(&u)) |
168 | 175 |
return error("Boot", "Failed"); |
169 |
- if(!load(&u, argv[1])) |
|
170 |
- return error("Load", "Failed"); |
|
171 | 176 |
|
172 | 177 |
/* system */ devsystem = uxn_port(&u, 0x0, system_talk); |
173 | 178 |
/* console */ devconsole = uxn_port(&u, 0x1, console_talk); |
... | ... |
@@ -186,6 +191,21 @@ main(int argc, char **argv) |
186 | 191 |
/* empty */ uxn_port(&u, 0xe, nil_talk); |
187 | 192 |
/* empty */ uxn_port(&u, 0xf, nil_talk); |
188 | 193 |
|
194 |
+ for(i = 1; i < argc; ++i) { |
|
195 |
+ if(!loaded++) { |
|
196 |
+ if(!load(&u, argv[i])) |
|
197 |
+ return error("Load", "Failed"); |
|
198 |
+ if(!uxn_eval(&u, PAGE_PROGRAM)) |
|
199 |
+ return error("Init", "Failed"); |
|
200 |
+ } else { |
|
201 |
+ char *p = argv[i]; |
|
202 |
+ while(*p) console_input(&u, *p++); |
|
203 |
+ console_input(&u, '\n'); |
|
204 |
+ } |
|
205 |
+ } |
|
206 |
+ if(!loaded) |
|
207 |
+ return error("Input", "Missing"); |
|
208 |
+ |
|
189 | 209 |
run(&u); |
190 | 210 |
|
191 | 211 |
return 0; |
... | ... |
@@ -493,10 +493,16 @@ uxn_halt(Uxn *u, Uint8 error, char *name, int id) |
493 | 493 |
return 0; |
494 | 494 |
} |
495 | 495 |
|
496 |
+static int |
|
497 |
+console_input(Uxn *u, char c) |
|
498 |
+{ |
|
499 |
+ devconsole->dat[0x2] = c; |
|
500 |
+ return uxn_eval(u, devconsole->vector); |
|
501 |
+} |
|
502 |
+ |
|
496 | 503 |
static int |
497 | 504 |
run(Uxn *u) |
498 | 505 |
{ |
499 |
- uxn_eval(u, PAGE_PROGRAM); |
|
500 | 506 |
redraw(u); |
501 | 507 |
while(!devsystem->dat[0xf]) { |
502 | 508 |
SDL_Event event; |
... | ... |
@@ -528,8 +534,7 @@ run(Uxn *u) |
528 | 534 |
break; |
529 | 535 |
default: |
530 | 536 |
if(event.type == stdin_event) { |
531 |
- devconsole->dat[0x2] = event.cbutton.button; |
|
532 |
- uxn_eval(u, devconsole->vector); |
|
537 |
+ console_input(u, event.cbutton.button); |
|
533 | 538 |
} else if(event.type >= audio0_event && event.type < audio0_event + POLYPHONY) |
534 | 539 |
uxn_eval(u, peek16((devaudio0 + (event.type - audio0_event))->dat, 0)); |
535 | 540 |
} |
... | ... |
@@ -560,14 +565,10 @@ main(int argc, char **argv) |
560 | 565 |
{ |
561 | 566 |
SDL_DisplayMode DM; |
562 | 567 |
Uxn u; |
563 |
- int i; |
|
568 |
+ int i, loaded = 0; |
|
564 | 569 |
|
565 |
- if(argc < 2) |
|
566 |
- return error("usage", "uxnemu file.rom"); |
|
567 | 570 |
if(!uxn_boot(&u)) |
568 | 571 |
return error("Boot", "Failed to start uxn."); |
569 |
- if(!load(&u, argv[argc - 1])) |
|
570 |
- return error("Load", "Failed to open rom."); |
|
571 | 572 |
|
572 | 573 |
/* system */ devsystem = uxn_port(&u, 0x0, system_talk); |
573 | 574 |
/* console */ devconsole = uxn_port(&u, 0x1, console_talk); |
... | ... |
@@ -589,20 +590,30 @@ main(int argc, char **argv) |
589 | 590 |
/* set default zoom */ |
590 | 591 |
SDL_GetCurrentDisplayMode(0, &DM); |
591 | 592 |
set_zoom(DM.w / 1280); |
592 |
- /* get default zoom from flags */ |
|
593 |
- for(i = 1; i < argc - 1; i++) { |
|
593 |
+ for(i = 1; i < argc; ++i) { |
|
594 |
+ /* get default zoom from flags */ |
|
594 | 595 |
if(strcmp(argv[i], "-s") == 0) { |
595 |
- if((i + 1) < argc - 1) |
|
596 |
+ if(i < argc - 1) |
|
596 | 597 |
set_zoom(atoi(argv[++i])); |
597 | 598 |
else |
598 | 599 |
return error("Opt", "-s No scale provided."); |
600 |
+ } else if(!loaded++) { |
|
601 |
+ if(!load(&u, argv[i])) |
|
602 |
+ return error("Load", "Failed to open rom."); |
|
603 |
+ if(!init()) |
|
604 |
+ return error("Init", "Failed to initialize emulator."); |
|
605 |
+ if(!set_size(WIDTH, HEIGHT, 0)) |
|
606 |
+ return error("Window", "Failed to set window size."); |
|
607 |
+ if(!uxn_eval(&u, PAGE_PROGRAM)) |
|
608 |
+ return error("Init", "Failed"); |
|
609 |
+ } else { |
|
610 |
+ char *p = argv[i]; |
|
611 |
+ while(*p) console_input(&u, *p++); |
|
612 |
+ console_input(&u, '\n'); |
|
599 | 613 |
} |
600 | 614 |
} |
601 |
- |
|
602 |
- if(!init()) |
|
603 |
- return error("Init", "Failed to initialize emulator."); |
|
604 |
- if(!set_size(WIDTH, HEIGHT, 0)) |
|
605 |
- return error("Window", "Failed to set window size."); |
|
615 |
+ if(!loaded) |
|
616 |
+ return error("usage", "uxnemu file.rom"); |
|
606 | 617 |
|
607 | 618 |
run(&u); |
608 | 619 |
quit(); |