commit ea0a058

Devine Lu Linvega  ·  2025-01-20 23:55:55 +0000 UTC
parent 20cc034
Only close console on explicit shutdown
5 files changed,  +95, -8
+83, -0
 1@@ -0,0 +1,83 @@
 2+( usage: uxncli console.rom foo "bar baz"
 3+| Prints Welcome to Uxn!, and listens for incoming stdin events on enter. )
 4+
 5+|10 @Console &vector $2 &read $1 &pad $4 &type $1 &write $1 &error $1
 6+
 7+|000
 8+
 9+	@arg $40
10+	@std $40
11+
12+|100
13+
14+@on-reset ( -> )
15+	;Dict/hello <print-str>
16+	.Console/type DEI ?{
17+		( | no arguments )
18+		;on-std .Console/vector DEO2
19+		BRK }
20+	;on-arg .Console/vector DEO2
21+	BRK
22+
23+@on-arg ( -> )
24+	[ LIT2 02 -Console/type ] DEI NEQ ?{
25+		.Console/read DEI [ LIT2 00 &ptr -arg ] INCk ,&ptr STR
26+		STZ2
27+		BRK }
28+	;arg ;Dict/yousent <print-result>
29+	[ LIT2 -arg _&ptr ] STR
30+	[ LIT2 04 -Console/type ] DEI NEQ ?{ ;on-std .Console/vector DEO2 }
31+	BRK
32+
33+@on-std ( -> )
34+	[ LIT2 0a -Console/read ] DEI EQU ?{
35+		.Console/read DEI [ LIT2 00 &ptr -std ] INCk ,&ptr STR
36+		STZ2
37+		BRK }
38+	;std DUP2 ;Dict/yousaid <print-result>
39+	;Dict/quit scmp ?{
40+		[ LIT2 -std _&ptr ] STR
41+		BRK }
42+	( quit ) #800f DEO
43+	BRK
44+
45+@<print-result> ( buf* name* -- )
46+	<print-str>
47+	[ LIT2 "" 18 ] DEO
48+	<print-str>/
49+	[ LIT2 "" 18 ] DEO
50+	[ LIT2 00 -Console/type ] DEI DUP ADD ;Types ADD2 LDA2 <print-str>/
51+	#0a18 DEO
52+	JMP2r
53+
54+@<print-str> ( str* -- )
55+	LDAk #18 DEO
56+	INC2 & LDAk ?<print-str>
57+	POP2 JMP2r
58+
59+@scmp ( a* b* -- f )
60+	STH2
61+	&l ( a* b* -- f )
62+	LDAk LDAkr STHr NEQk ?&d
63+	DUP EOR EQUk ?&d
64+	POP2 INC2 INC2r !&l
65+
66+	&d ( a* c1 c2 b* -- f )
67+	NIP2 POP2r EQU JMP2r
68+
69+(
70+@|assets )
71+
72+@Types =Dict/arg-none =Dict/arg-stdin =Dict/arg-data =Dict/arg-spacer =Dict/arg-end
73+
74+@Dict
75+	&hello "Welcome 20 "to 20 "Uxn! 0a $1
76+	&yousaid "You 20 "said: 20 $1
77+	&yousent "You 20 "sent: 20 $1
78+	&quit "quit $1
79+	&arg-none "<none> $1
80+	&arg-stdin "<stdin> $1
81+	&arg-data "<data> $1
82+	&arg-spacer "<spacer> $1
83+	&arg-end "<end> $1
84+
+4, -1
 1@@ -12,8 +12,9 @@ all: bin/uxnasm bin/uxncli bin/uxn11
 2 
 3 run: all bin/mouse.rom
 4 	@ bin/uxn11 bin/mouse.rom
 5-debug: bin/uxnasm-debug bin/uxncli-debug bin/uxn11-debug bin/opctest.rom
 6+debug: bin/uxnasm-debug bin/uxncli-debug bin/uxn11-debug bin/opctest.rom bin/console.rom
 7 	@ bin/uxncli-debug bin/opctest.rom
 8+	@ bin/uxncli-debug bin/console.rom "foo bar" baz
 9 screen: bin/uxn11 
10 	@ uxnasm etc/screen.bounds.tal bin/test.rom
11 	@ bin/uxn11 bin/test.rom
12@@ -47,6 +48,8 @@ bin/opctest.rom: bin/uxnasm
13 	@ bin/uxnasm etc/opctest.tal bin/opctest.rom
14 bin/mouse.rom: bin/uxnasm etc/mouse.tal
15 	@ bin/uxnasm etc/mouse.tal bin/mouse.rom
16+bin/console.rom: bin/uxnasm etc/console.tal
17+	@ bin/uxnasm etc/console.tal bin/console.rom
18 
19 bin/uxnasm: src/uxnasm.c
20 	@ mkdir -p bin
+2, -1
 1@@ -205,7 +205,8 @@ console_arguments(int i, int argc, char **argv)
 2 {
 3 	for(; i < argc; i++) {
 4 		char *p = argv[i];
 5-		while(*p) console_input(*p++, CONSOLE_ARG);
 6+		while(*p)
 7+			console_input(*p++, CONSOLE_ARG);
 8 		console_input('\n', i == argc - 1 ? CONSOLE_END : CONSOLE_EOA);
 9 	}
10 }
+3, -2
 1@@ -262,8 +262,9 @@ main(int argc, char **argv)
 2 		return !fprintf(stdout, "Could not open display.\n");
 3 	else if(!system_boot((Uint8 *)calloc(0x10000 * RAM_PAGES, sizeof(Uint8)), argv[i++], argc > 2))
 4 		return !fprintf(stdout, "Could not load %s.\n", argv[i - 1]);
 5-	if(uxn_eval(PAGE_PROGRAM))
 6-		console_arguments(i, argc, argv), emu_run();
 7+	uxn_eval(PAGE_PROGRAM);
 8+	console_arguments(i, argc, argv);
 9+	emu_run();
10 	close_console();
11 	XDestroyImage(ximage), XDestroyWindow(display, window), XCloseDisplay(display);
12 	return uxn.dev[0x0f] & 0x7f;
+3, -4
 1@@ -52,9 +52,8 @@ main(int argc, char **argv)
 2 		return !fprintf(stdout, "usage: %s [-v] file.rom [args..]\n", argv[0]);
 3 	else if(!system_boot((Uint8 *)calloc(0x10000 * RAM_PAGES, sizeof(Uint8)), argv[i++], argc > 2))
 4 		return !fprintf(stdout, "Could not load %s.\n", argv[i - 1]);
 5-	if(uxn_eval(PAGE_PROGRAM) && uxn.dev[0x10]) {
 6-		console_arguments(i, argc, argv);
 7-		while(!uxn.dev[0x0f] && console_input(fgetc(stdin), 0x1));
 8-	}
 9+	uxn_eval(PAGE_PROGRAM);
10+	console_arguments(i, argc, argv);
11+	while(!uxn.dev[0x0f] && console_input(fgetc(stdin), 0x1));
12 	return uxn.dev[0x0f] & 0x7f;
13 }