commit 8f38d8b

neauoire  ·  2023-11-01 17:57:12 +0000 UTC
parent ea65f7d
(uxn.c) Wrap RAM
2 files changed,  +81, -15
+79, -13
  1@@ -1,5 +1,4 @@
  2 ( Opcode Tester )
  3-( Source: https://git.sr.ht/~rabbits/uxn-utils/tree/main/item/cli/opctest/opctest.tal )
  4 
  5 |0013
  6 
  7@@ -7,15 +6,20 @@
  8 
  9 |0100
 10 
 11+@on-reset ( -> )
 12+
 13 	( part 1
 14 		> LIT2: Puts a short on the stack
 15-		> #18 DEO: Write a letter in terminal )
 16+		> LIT: Puts a byte on the stack
 17+		> #18 DEO: Write a letter in terminal
 18+		> ;meta: Push short
 19+		> #06 DEO: Write to metadata ports )
 20 
 21 	[ LIT2 "kO ] #18 DEO #18 DEO #0a18 DEO
 22+	;meta #06 DEO2
 23 
 24 	( part 2
 25 		> LITr: Put a byte on return stack
 26-		> LIT: Puts a byte on the stack
 27 		> STH: Move a byte from working stack to return stack
 28 		> STH2r: Move a short from return stack to working stack )
 29 
 30@@ -50,22 +54,76 @@
 31 	[ LIT2r 0000 ]
 32 	;tests/end ;tests
 33 	&l
 34-		run-test STH ADDr
 35+		run-test [ LITr 00 ] STH ADD2r
 36 		INC2 INC2 GTH2k ?&l
 37 	POP2 POP2
 38-	STH2r ;Dict/done pstr
 39+	STH2r ;tests/end ;tests SUB2 #01 SFT2
 40+	EQU2 ;Dict/opctests test-part
 41+
 42+	( Part 7
 43+		> Testing that stacks are circular and wrapping
 44+		> Storing 12 at -1 and 34 at 0 )
 45+
 46+	POP #12 #34 ADD #46 EQU STH
 47+	POP #1234 ADD #46 EQU STH
 48+	POP2 #1111 #2222 ADD2 #3333 EQU2
 49+	STHr AND STHr AND
 50+	;Dict/stack-wrap test-part
 51+
 52+	( Part 8
 53+		> Testing RAM wrapping
 54+		> Storing 12 in 0xffff, and 34 in 0x0000 )
 55+
 56+	#1234 #ffff STA2
 57+	#ffff LDA #0000 LDA ADD #46 EQU
 58+	#ffff LDA2 ADD #46 EQU
 59+	AND ;Dict/ram-wrap test-part
 60 
 61-	( halt )
 62+	( Part 9
 63+		> Testing that zero-page is wrapping )
 64 
 65-	#800f DEO
 66+	#0000 STZ #00ff STZ
 67+	#1234 #ff STZ2
 68+	#00ff LDA #0000 LDA ADD #46 EQU
 69+	;Dict/zp-wrap test-part
 70+
 71+	( Part 10
 72+		> Testing that device page is wrapping )
 73+
 74+	#1234 #ff DEO2
 75+	#ff DEI #00 DEI ADD #46 EQU
 76+	;Dict/dev-wrap test-part
 77+	#0000 DEO #00ff DEO
 78+
 79+	( end )
 80+
 81+	[ LIT &fail 80 ]
 82+		DUP #80 EQU ;Dict/result test-part
 83+		#0f DEO
 84+
 85+	#0a18 DEO
 86+	#010e DEO
 87 
 88 BRK
 89 
 90+@meta 00
 91+	( name ) "Opctest 0a
 92+	( details ) "A 20 "Testing 20 "Program 0a
 93+	( author ) "By 20 "Devine 20 "Lu 20 "Linvega 0a
 94+	( date ) "1 20 "Nov 20 "2023 $2
 95+
 96+@test-part ( f name* -- )
 97+	pstr ?{
 98+		#01 ;on-reset/fail STA
 99+		;Dict/failed !pstr }
100+	;Dict/passed !pstr
101+
102 @run-test ( addr* -- addr* f )
103 
104 	LDA2k JSR2 DUP ?&pass
105-		;Dict/failed pstr
106-		[ LIT2 &name $2 ] pstr/ #0a18 DEO JMP2r
107+		;Dict/missed pstr
108+		[ LIT2 &name $2 ] pstr/ #0a18 DEO
109+		#01 ;on-reset/fail STA JMP2r
110 		&pass
111 
112 JMP2r
113@@ -167,7 +225,7 @@ JMP2r
114 	&d #00 #ff EQU [ #00 ] EQU JMP2r
115 	&e #f801 #f801 EQU2 [ #01 ] EQU JMP2r
116 	&f #01f8 #01f8 EQU2 [ #01 ] EQU JMP2r
117-	&g #f801 #01f8 EQU2 [ #00 ] EQU JMP2r ( HERE )
118+	&g #f801 #01f8 EQU2 [ #00 ] EQU JMP2r
119 	&h #01f8 #f801 EQU2 [ #00 ] EQU JMP2r
120 @op-neq ;Dict/neq !set
121 	&a #f8 #f8 NEQ [ #00 ] EQU JMP2r
122@@ -224,12 +282,12 @@ JMP2r
123 	&g #8000 #0200 MUL2 [ #0000 ] EQU2 JMP2r
124 	&h #2222 #0003 MUL2 [ #6666 ] EQU2 JMP2r
125 @op-div ;Dict/div !set
126-	&a #10 #02 DIV [ #08 ] EQU JMP2r
127+	&a #10 #06 DIV [ #02 ] EQU JMP2r
128 	&b #20 #20 DIV [ #01 ] EQU JMP2r
129 	&c #34 #01 DIV [ #34 ] EQU JMP2r
130 	&d #02 #ef DIV [ #00 ] EQU JMP2r
131 	&e #02 #00 DIV [ #00 ] EQU JMP2r
132-	&f #1000 #0040 DIV2 [ #0040 ] EQU2 JMP2r
133+	&f #03e8 #0006 DIV2 [ #00a6 ] EQU2 JMP2r
134 	&g #abcd #1234 DIV2 [ #0009 ] EQU2 JMP2r
135 	&h #8000 #0200 DIV2 [ #0040 ] EQU2 JMP2r
136 	&i #2222 #0003 DIV2 [ #0b60 ] EQU2 JMP2r
137@@ -363,7 +421,15 @@ JMP2r
138 @Dict [
139 	&ok "Ok $1
140 	&done "Tests 20 "Complete. 0a $1
141-	&failed "-- 20 "failed: 20 $1
142+	&opctests "Opcodes $1
143+	&stack-wrap "Stack-wrap $1
144+	&ram-wrap "RAM-wrap $1
145+	&zp-wrap "Zeropage-wrap $1
146+	&dev-wrap "Devices-wrap $1
147+	&result "Result: $1
148+	&passed 20 "passed! 0a $1
149+	&missed "Opcode 20 "Failed 20 "-- 20 $1
150+	&failed 20 "failed. 0a $1
151 	&equ "EQU $1 &neq "NEQ $1 &gth "GTH $1 &lth "LTH $1
152 	&add "ADD $1 &sub "SUB $1 &mul "MUL $1 &div "DIV $1
153 	&inc "INC $1 &pop "POP $1 &dup "DUP $1 &nip "NIP $1
+2, -2
 1@@ -13,8 +13,8 @@ WITH REGARD TO THIS SOFTWARE.
 2 
 3 #define FLIP       { s = ins & 0x40 ? &u->wst : &u->rst; }
 4 #define JUMP(x)    { if(m2) pc = (x); else pc += (Sint8)(x); }
 5-#define POKE(x, y) { if(m2) { tp = &ram[x]; POKE2(tp, y) } else ram[(x)] = (y); }
 6-#define PEEK(o, x) { if(m2) { tp = &ram[x]; o = PEEK2(tp); } else o = ram[(x)]; }
 7+#define POKE(x, y) { if(m2) { t = (x); ram[t++] = y >> 8; ram[t] = y; } else ram[(x)] = (y); }
 8+#define PEEK(o, x) { if(m2) { t = (x); o = ram[t++] << 8 | ram[t]; } else o = ram[(x)]; }
 9 #define DEVR(o, p) { if(m2) { o = (emu_dei(u, p) << 8) | emu_dei(u, p + 1); } else o = emu_dei(u, p); }
10 #define DEVW(p, y) { if(m2) { emu_deo(u, p, y >> 8); emu_deo(u, p + 1, y); } else emu_deo(u, p, y); }
11 #define PUSH1(y)   { s->dat[s->ptr++] = (y); }