commit 2e8e2d5

Devine Lu Linvega  ·  2024-11-13 05:07:08 +0000 UTC
parent 8e8d627
Started BIOS drawing stacks
6 files changed,  +212, -28
+2, -0
1@@ -33,6 +33,8 @@ uninstall:
2 	@ rm -f ~/bin/uxn11 ~/bin/uxnasm ~/bin/uxncli
3 format:
4 	@ clang-format -i src/uxnasm.c src/uxncli.c src/uxn11.c src/devices/*
5+lint:
6+	@ bin/uxncli ~/roms/uxnlin.rom src/bios.tal
7 grab:
8 	@ cp ../uxn-utils/cli/opctest/opctest.tal etc/opctest.tal
9 archive:
+190, -9
  1@@ -1,6 +1,6 @@
  2 ( bios )
  3 
  4-|00 @System &vector $2 &pad $6 &r $2 &g $2 &b $2
  5+|00 @System &vector $2 &expansion $2 &wst $1 &rst $1 &metadata $2 &r $2 &g $2 &b $2 &debug $1 &state $1
  6 |10 @Console &vector $2 &read $1 &pad $5 &write $1
  7 |20 @Screen &vector $2 &width $2 &height $2 &auto $1 &pad $1 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1
  8 |80 @Controller &vector $2 &button $1 &key $1
  9@@ -10,19 +10,84 @@
 10 |100
 11 
 12 @on-reset ( -> )
 13-	#1234 <phex> #0a18 DEO
 14-	( ;on-frame .Screen/vector DEO2 ) 
 15+	;on-frame .Screen/vector DEO2
 16 	BRK
 17 
 18-@meta $1
 19-	( name ) "BIOS 0a
 20-	( details ) "A 20 "Uxn 20 "BIOS 0a
 21-	( author ) "By 20 "Hundred 20 "Rabbits 0a
 22-	( date ) "12 20 "Nov 20 "2024 $1 00
 23-
 24 @on-frame ( -> )
 25+	#0040 .Screen/x DEO2
 26+	#0070 .Screen/y DEO2
 27+	[ LIT2 15 -Screen/auto ] DEO
 28+	#8000 .System/wst DEI ;wst-txt <draw-stack>
 29+	#0040 .Screen/x DEO2
 30+	#0090 .Screen/y DEO2
 31+	#8100 .System/rst DEI ;rst-txt <draw-stack>
 32 	BRK
 33 
 34+%<draw-space> ( -- ) {
 35+	.Screen/x DEI2k #0008 ADD2 ROT DEO2 }
 36+
 37+@<draw-stack> ( addr* ptr name* -- )
 38+	<draw-text>
 39+	<draw-space>
 40+	#43 ;<draw-glyph>/color STA
 41+	DUP <draw-byte>
 42+	<draw-space>
 43+	#41 ;<draw-glyph>/color STA
 44+	#04 SUB #00 SWP ADD2 DUP2 #0009 ADD2 SWP2 [ LITr 00 ]
 45+	&>l ( -- )
 46+		STHkr #04 NEQ ?{ #44 ;<draw-glyph>/color STA }
 47+		STHkr #05 NEQ ?{ #41 ;<draw-glyph>/color STA }
 48+		LDAk <draw-byte>
 49+		.Screen/x DEI2k #0008 ADD2 ROT DEO2
 50+		INCr INC2 GTH2k ?&>l
 51+	POP2 POP2 POPr JMP2r
 52+
 53+@wst-txt "WST $1
 54+
 55+@rst-txt "RST $1
 56+
 57+@<draw-text> ( str* -- )
 58+	[ LIT2 15 -Screen/auto ] DEO
 59+	&>w ( -- )
 60+		LDAk #08 NEQ ?{ <draw-bs> !&res }
 61+		LDAk #0a NEQ ?{ <draw-lb> !&res }
 62+		( ) LDAk <draw-char> &res INC2 LDAk ?&>w
 63+	POP2 JMP2r
 64+
 65+@<draw-byte> ( byte -- )
 66+	DUP #04 SFT <draw-hex>
 67+
 68+@<draw-hex> ( byte -- )
 69+	#0f AND #00 SWP ;base16-lut ADD2 LDA
 70+
 71+@<draw-char> ( char -- )
 72+	get-glyph
 73+	( >> )
 74+
 75+@<draw-glyph> ( addr* -- )
 76+	.Screen/addr DEO2
 77+	[ LIT2 &color 41 -Screen/sprite ] DEO
 78+	JMP2r
 79+
 80+@get-glyph ( char -- addr* )
 81+	DUP #0a EQU ?&blank
 82+	DUP #09 EQU ?&blank
 83+	DUP #20 LTH ?&unknown
 84+	DUP #7e GTH ?&unknown
 85+	#20 SUB #00 SWP #40 SFT2 ;font-icn ADD2 JMP2r
 86+	&unknown POP ;halftone-icn JMP2r
 87+	&blank POP ;blank-icn JMP2r
 88+
 89+@<draw-lb> ( -- )
 90+	.Screen/y DEI2k #0010 ADD2 ROT DEO2
 91+	#0014 .Screen/x DEO2
 92+	JMP2r
 93+
 94+@<draw-bs> ( -- )
 95+	.Screen/x DEI2k #0008 SUB2 ROT DEO2
 96+	#20 <draw-char>
 97+	.Screen/x DEI2k #0008 SUB2 ROT DEO2
 98+	JMP2r
 99 
100 @<phex> ( short* -: )
101 	SWP /b
102@@ -32,4 +97,120 @@
103 	#0f AND DUP #09 GTH #27 MUL ADD [ LIT "0 ] ADD #19 DEO
104 	JMP2r
105 
106+@base16-lut [ "0123456789abcdef ]
107+
108+@cursor-icn [ 80c0 e0f0 f8e0 1000 ]
109+
110+@fill-icn [ ffff ffff ffff ffff ]
111+
112+@caret-icn [ 4040 4040 4040 4040 4040 4040 4040 4040 ]
113+
114+@blank-icn [ $10 ]
115+
116+@halftone-icn [ aa55 aa55 aa55 aa55 aa55 aa55 aa55 aa55 ]
117+
118+@ascii-icn [
119+	aa55 805f 9051 9357 aa55 02f9 0a89 cae9
120+	9753 9150 9f40 aa55 eac9 8a09 fa01 aa55 ]
121+
122+@hex-icn [
123+	aa55 805f 9057 9455 aa55 02f9 0ae9 2aa9
124+	9554 9750 9f40 aa55 aa29 ea09 fa01 aa55 ]
125+
126+@font-icn [
127+	0000 0000 0000 0000 0000 0000 0000 0000
128+	0038 3838 3838 3810 1010 1000 0010 3810
129+	6c6c 2424 4800 0000 0000 0000 0000 0000
130+	0012 1212 7f24 2424 2424 fe48 4848 4800
131+	1038 5492 9690 5038 1412 d292 9478 1010
132+	0262 9494 9498 6810 102c 3252 5252 8c80
133+	0030 4848 4850 202e 5454 9488 8c72 0000
134+	e0e0 2020 c000 0000 0000 0000 0000 0000
135+	0204 0808 1010 1010 1010 1010 0808 0402
136+	8040 2020 1010 1010 1010 1010 2020 4080
137+	0000 0010 3892 d638 d692 3810 0000 0000
138+	0000 0010 1010 10fe 1010 1010 0000 0000
139+	0000 0000 0000 0000 0000 00e0 e020 20c0
140+	0000 0000 0000 00fe 0000 0000 0000 0000
141+	0000 0000 0000 0000 0000 0040 e0e0 4000
142+	0202 0404 0808 0810 1010 2020 4040 8080
143+	0018 2424 4242 4242 4242 4242 2424 1800
144+	0010 7010 1010 1010 1010 1010 107c 0000
145+	0018 2442 6202 0408 0810 2022 427e 0000
146+	0038 4482 8202 0438 0402 8282 4438 0000
147+	0008 1828 2848 4888 88fe 0808 083c 0000
148+	00fc 8080 80b8 c482 0202 c282 4438 0000
149+	003c 4246 8080 b8c4 8282 8282 4438 0000
150+	00fe 8282 0404 0408 0808 0810 1010 1000
151+	0038 4482 8282 4438 4482 8282 4438 0000
152+	0038 4482 8282 8246 3a02 0282 4438 0000
153+	0000 0000 0038 3800 0000 0000 3838 0000
154+	0000 0000 0038 3800 0000 0038 3818 1030
155+	0204 0408 0810 1020 2010 1008 0804 0402
156+	0000 0000 00fe 0000 00fe 0000 0000 0000
157+	8040 4020 2010 1008 0810 1020 2040 4080
158+	0038 4482 c202 0404 0810 1000 0010 3810
159+	003c 4282 9aa6 a2a2 a2a6 9a80 423c 0000
160+	0010 2828 2844 4444 447c 8282 82c6 0000
161+	00f8 4442 4242 4478 4442 4242 42fc 0000
162+	003a 4642 8080 8080 8080 8242 423c 0000
163+	00f8 4444 4242 4242 4242 4244 44f8 0000
164+	00fe 4242 4048 4878 4848 4242 42fe 0000
165+	00fe 4242 4048 4878 4848 4040 40f0 0000
166+	001a 2642 4080 808f 8282 8242 661a 0000
167+	00e7 4242 4242 7e42 4242 4242 42e7 0000
168+	00fe 1010 1010 1010 1010 1010 10fe 0000
169+	001f 0202 0202 0202 0282 8282 4438 0000
170+	00e6 4444 4848 7050 4848 4444 42e3 0000
171+	00f0 4040 4040 4040 4040 4242 42fe 0000
172+	0082 c6aa aaaa 9292 9282 8282 82c6 0000
173+	0087 c2a2 a2a2 9292 928a 8a8a 86c2 0000
174+	0038 4482 8282 8282 8282 8282 4438 0000
175+	00f8 4442 4242 4244 7840 4040 40f0 0000
176+	0038 4444 8282 8282 8282 ba44 4438 0806
177+	00f8 4442 4242 4478 4844 4444 42e3 0000
178+	0034 4c84 8080 6018 0482 8282 c4b8 0000
179+	00fe 9292 1010 1010 1010 1010 107c 0000
180+	00e7 4242 4242 4242 4242 4242 423c 0000
181+	00c6 8282 8282 4444 4444 2828 1010 0000
182+	00c6 8282 8292 9292 aaaa aa44 4444 0000
183+	00ee 4444 2828 1028 2828 4444 82c6 0000
184+	00c6 8244 4444 2828 1010 1010 107c 0000
185+	00fe 8488 0810 1010 2020 4242 82fe 0000
186+	1e10 1010 1010 1010 1010 1010 1010 101e
187+	0080 8040 4020 2010 1008 0804 0402 0200
188+	f010 1010 1010 1010 1010 1010 1010 10f0
189+	1028 4482 0000 0000 0000 0000 0000 0000
190+	0000 0000 0000 0000 0000 0000 0000 00ff
191+	3030 2020 1000 0000 0000 0000 0000 0000
192+	0000 0000 003c 4202 3e42 8282 867b 0000
193+	00c0 4040 4078 4442 4242 4242 4478 0000
194+	0000 0000 003a 4682 8080 8082 423c 0000
195+	0006 0404 043c 4484 8484 8484 443e 0000
196+	0000 0000 0038 4482 fe80 8082 423c 0000
197+	000e 1110 10fe 1010 1010 1010 107c 0000
198+	0000 0000 003b 4444 4438 4078 8482 827c
199+	00c0 4040 405c 6242 4242 4242 42e7 0000
200+	1818 0000 0078 0808 0808 0808 08ff 0000
201+	0606 0000 003e 0202 0202 0202 8282 4438
202+	00c0 4040 4042 4448 5864 4442 42e3 0000
203+	0078 0808 0808 0808 0808 0808 08ff 0000
204+	0000 0000 006c 9292 9292 9292 92db 0000
205+	0000 0000 00dc 6242 4242 4242 42e7 0000
206+	0000 0000 0038 4482 8282 8282 4438 0000
207+	0000 0000 00f8 4442 4242 4244 7840 40f0
208+	0000 0000 003e 4484 8484 8444 3c04 041e
209+	0000 0000 00ec 3222 2020 2020 20fc 0000
210+	0000 0000 003a 4642 403c 0282 c2bc 0000
211+	0000 2020 20fc 2020 2020 2022 221c 0000
212+	0000 0000 00c6 4242 4242 4242 4639 0000
213+	0000 0000 00c6 8282 4444 4428 2810 0000
214+	0000 0000 0092 9292 92aa aa44 4444 0000
215+	0000 0000 00ee 4428 2810 2828 44ee 0000
216+	0000 0000 00e7 4222 2414 0808 1090 a040
217+	0000 0000 007e 4408 0810 1022 42fe 0000
218+	0608 0808 0808 1020 1008 0808 0808 0806
219+	1010 1010 1010 1010 1010 1010 1010 1010
220+	c020 2020 2020 1008 1020 2020 2020 20c0
221+	6092 0c00 0000 0000 0000 0000 0000 0000 ]
222 
+11, -11
 1@@ -238,7 +238,7 @@ screen_redraw(void)
 2 static int rX, rY, rA, rMX, rMY, rMA, rML, rDX, rDY;
 3 
 4 Uint8
 5-screen_dei(Uint8 addr)
 6+screen_dei(Uxn *u, Uint8 addr)
 7 {
 8 	switch(addr) {
 9 	case 0x22: return uxn_screen.width >> 8;
10@@ -251,25 +251,25 @@ screen_dei(Uint8 addr)
11 	case 0x2b: return rY;
12 	case 0x2c: return rA >> 8;
13 	case 0x2d: return rA;
14-	default: return uxn.dev[addr];
15+	default: return u->dev[addr];
16 	}
17 }
18 
19 void
20-screen_deo(Uint8 addr)
21+screen_deo(Uxn *u, Uint8 addr)
22 {
23 	switch(addr) {
24 	case 0x23: screen_resize(PEEK2(&uxn.dev[0x22]), uxn_screen.height, uxn_screen.scale); return;
25 	case 0x25: screen_resize(uxn_screen.width, PEEK2(&uxn.dev[0x24]), uxn_screen.scale); return;
26-	case 0x26: rMX = uxn.dev[0x26] & 0x1, rMY = uxn.dev[0x26] & 0x2, rMA = uxn.dev[0x26] & 0x4, rML = uxn.dev[0x26] >> 4, rDX = rMX << 3, rDY = rMY << 2; return;
27+	case 0x26: rMX = u->dev[0x26] & 0x1, rMY = u->dev[0x26] & 0x2, rMA = u->dev[0x26] & 0x4, rML = u->dev[0x26] >> 4, rDX = rMX << 3, rDY = rMY << 2; return;
28 	case 0x28:
29-	case 0x29: rX = (uxn.dev[0x28] << 8) | uxn.dev[0x29], rX = twos(rX); return;
30+	case 0x29: rX = (u->dev[0x28] << 8) | u->dev[0x29], rX = twos(rX); return;
31 	case 0x2a:
32-	case 0x2b: rY = (uxn.dev[0x2a] << 8) | uxn.dev[0x2b], rY = twos(rY); return;
33+	case 0x2b: rY = (u->dev[0x2a] << 8) | u->dev[0x2b], rY = twos(rY); return;
34 	case 0x2c:
35-	case 0x2d: rA = (uxn.dev[0x2c] << 8) | uxn.dev[0x2d]; return;
36+	case 0x2d: rA = (u->dev[0x2c] << 8) | u->dev[0x2d]; return;
37 	case 0x2e: {
38-		Uint8 ctrl = uxn.dev[0x2e];
39+		Uint8 ctrl = u->dev[0x2e];
40 		Uint8 color = ctrl & 0x3;
41 		Uint8 *layer = ctrl & 0x40 ? uxn_screen.fg : uxn_screen.bg;
42 		/* fill mode */
43@@ -299,7 +299,7 @@ screen_deo(Uint8 addr)
44 	}
45 	case 0x2f: {
46 		Uint8 i;
47-		Uint8 ctrl = uxn.dev[0x2f];
48+		Uint8 ctrl = u->dev[0x2f];
49 		Uint8 twobpp = !!(ctrl & 0x80);
50 		Uint8 color = ctrl & 0xf;
51 		Uint8 *layer = ctrl & 0x40 ? uxn_screen.fg : uxn_screen.bg;
52@@ -308,10 +308,10 @@ screen_deo(Uint8 addr)
53 		int dxy = rDX * fy, dyx = rDY * fx, addr_incr = rMA << (1 + twobpp);
54 		if(twobpp)
55 			for(i = 0; i <= rML; i++, x += dyx, y += dxy, rA += addr_incr)
56-				screen_2bpp(layer, &uxn.ram[rA], x, y, color, fx, fy);
57+				screen_2bpp(layer, &u->ram[rA], x, y, color, fx, fy);
58 		else
59 			for(i = 0; i <= rML; i++, x += dyx, y += dxy, rA += addr_incr)
60-				screen_1bpp(layer, &uxn.ram[rA], x, y, color, fx, fy);
61+				screen_1bpp(layer, &u->ram[rA], x, y, color, fx, fy);
62 		if(fx < 0)
63 			x1 = x, x2 = rX;
64 		else
+2, -2
 1@@ -25,7 +25,7 @@ void screen_palette(void);
 2 void screen_resize(Uint16 width, Uint16 height, int scale);
 3 void screen_redraw();
 4 
 5-Uint8 screen_dei(Uint8 addr);
 6-void screen_deo(Uint8 addr);
 7+Uint8 screen_dei(Uxn *u, Uint8 addr);
 8+void screen_deo(Uxn *u, Uint8 addr);
 9 
10 #define twos(v) (v & 0x8000 ? (int)v - 0x10000 : (int)v)
+0, -2
 1@@ -81,13 +81,11 @@ system_boot(Uint8 *ram, char *boot)
 2 {
 3 	/* Load rom(bios) */
 4 	if(system_load(&bios_ram[PAGE_PROGRAM], "bios.rom")) {
 5-		printf("FOUND BIOS!!!\n");
 6 		bios.ram = bios_ram;
 7 		bios.dev = bios_ram + 0x8300;
 8 		bios.wst.dat = bios_ram + 0x8400;
 9 		bios.rst.dat = bios_ram + 0x8500;
10 		bios.dev[0xe] = 0xff;
11-		uxn_eval(&bios, PAGE_PROGRAM);
12 	}
13 	/* Load rom(main) */
14 	if(system_load(&ram[PAGE_PROGRAM], boot)) {
+7, -4
 1@@ -51,7 +51,7 @@ emu_dei(Uxn *u, Uint8 addr)
 2 	switch(addr & 0xf0) {
 3 	case 0x00: return system_dei(addr);
 4 	case 0x10: return console_dei(u, addr);
 5-	case 0x20: return screen_dei(addr);
 6+	case 0x20: return screen_dei(u, addr);
 7 	case 0xc0: return datetime_dei(addr);
 8 	}
 9 	return u->dev[addr];
10@@ -68,7 +68,7 @@ emu_deo(Uxn *u, Uint8 addr, Uint8 value)
11 			screen_palette();
12 		break;
13 	case 0x10: console_deo(u, addr); break;
14-	case 0x20: screen_deo(addr); break;
15+	case 0x20: screen_deo(u, addr); break;
16 	case 0xa0: file_deo(addr); break;
17 	case 0xb0: file_deo(addr); break;
18 	}
19@@ -271,8 +271,11 @@ main(int argc, char **argv)
20 	else if(!system_boot(ram, argv[i++]))
21 		return !fprintf(stdout, "Could not load %s.\n", argv[i - 1]);
22 	uxn.dev[0x17] = argc - i;
23-	if(uxn_eval(&uxn, PAGE_PROGRAM))
24-		console_listen(i, argc, argv), emu_run();
25+	if(uxn_eval(&uxn, PAGE_PROGRAM)){
26+		uxn_eval(&bios, PAGE_PROGRAM);
27+		console_listen(i, argc, argv);
28+		emu_run();
29+	}
30 	close_console();
31 	XDestroyImage(ximage), XDestroyWindow(display, window), XCloseDisplay(display);
32 	return uxn.dev[0x0f] & 0x7f;