Browse code

(system.tal) Made example dynamic

Devine Lu Linvega authored on 16/04/2023 03:06:34
Showing 1 changed files
... ...
@@ -1,25 +1,38 @@
1 1
 |00 @System &vector $2 &wst $1 &rst $1 &pad $4 &r $2 &g $2 &b $2 &debug $1 &halt $1
2
+|10 @Console &vector $2 &read $1 &pad $5 &write $1
2 3
 
3 4
 |0100
4 5
 
5 6
 	;on-halt .System/vector DEO2
7
+	;on-console .Console/vector DEO2
8
+	;dict/instruction pstr
6 9
 
7
-	( divzero ) #02 #00 DIV
8
-	( underflow ) POP
9
-	( overflow ) #00 &l #ffff ROT INC DUP ?&l POP
10
-	
11
-	#80 .System/halt DEO
10
+BRK
11
+
12
+@on-console ( -> )
13
+
14
+	[ LIT2 &id =tests ] INC2k INC2 ,&id STR2 LDA2 JSR2
12 15
 
13 16
 BRK
14 17
 
18
+@tests
19
+	=try-divzero
20
+	=try-underflow
21
+	=try-overflow
22
+	=exit
23
+
24
+@try-divzero ( -- ) #02 #00 DIV JMP2r
25
+@try-underflow ( -- ) POP JMP2r
26
+@try-overflow ( -- ) #00 &l #ffff ROT INC DUP ?&l POP JMP2r
27
+@exit ( -- ) #0000 .Console/vector DEO2 #800f DEO BRK
28
+
15 29
 @on-halt ( addr* inst code -> )
16 30
 
17 31
 	#00 SWP DUP ADD ;err ADD2 LDA2 pstr
18 32
 	;dict/error pstr
19 33
 	print-opcode
20 34
 	;dict/at pstr
21
-	phex LIT2 0a ". #18 DEO #18 DEO
22
-	#01 .System/halt DEO
35
+	phex LIT ". #18 DEO
23 36
 
24 37
 BRK
25 38
 
... ...
@@ -51,10 +64,12 @@ JMP2r
51 64
 JMP2r
52 65
 
53 66
 @pstr ( str* -- )
67
+
54 68
 	&w
55 69
 		LDAk #18 DEO
56
-		INC2 LDAk ,&w JCN
70
+		INC2 LDAk ?&w
57 71
 	POP2
72
+
58 73
 JMP2r
59 74
 
60 75
 @err
... ...
@@ -64,12 +79,13 @@ JMP2r
64 79
 	=dict/divzero
65 80
 
66 81
 @dict
67
-	&error "Error, 20 "during 20 $1
82
+	&error "error, 20 "during 20 $1
68 83
 	&unknown "Unkown 20 $1
69 84
 	&underflow "Underflow 20 $1
70 85
 	&overflow "Overflow 20 $1
71 86
 	&divzero "Division 20 "by 20 "zero 20 $1
72 87
 	&at ", 20 "at 20 "# $1
88
+	&instruction "Press 20 "enter 20 "to 20 "test 20 "each 20 "error. 0a $1
73 89
 
74 90
 @opcodes
75 91
 	"LIT $1 "INC $1 "POP $1 "NIP $1 "SWP $1 "ROT $1 "DUP $1 "OVR $1