(system.tal) Made example dynamic

This commit is contained in:
Devine Lu Linvega 2023-04-15 20:06:34 -07:00
parent 07f9785fab
commit c70ba4238a
1 changed files with 26 additions and 10 deletions

View File

@ -1,25 +1,38 @@
|00 @System &vector $2 &wst $1 &rst $1 &pad $4 &r $2 &g $2 &b $2 &debug $1 &halt $1 |00 @System &vector $2 &wst $1 &rst $1 &pad $4 &r $2 &g $2 &b $2 &debug $1 &halt $1
|10 @Console &vector $2 &read $1 &pad $5 &write $1
|0100 |0100
;on-halt .System/vector DEO2 ;on-halt .System/vector DEO2
;on-console .Console/vector DEO2
( divzero ) #02 #00 DIV ;dict/instruction pstr
( underflow ) POP
( overflow ) #00 &l #ffff ROT INC DUP ?&l POP
#80 .System/halt DEO
BRK BRK
@on-console ( -> )
[ LIT2 &id =tests ] INC2k INC2 ,&id STR2 LDA2 JSR2
BRK
@tests
=try-divzero
=try-underflow
=try-overflow
=exit
@try-divzero ( -- ) #02 #00 DIV JMP2r
@try-underflow ( -- ) POP JMP2r
@try-overflow ( -- ) #00 &l #ffff ROT INC DUP ?&l POP JMP2r
@exit ( -- ) #0000 .Console/vector DEO2 #800f DEO BRK
@on-halt ( addr* inst code -> ) @on-halt ( addr* inst code -> )
#00 SWP DUP ADD ;err ADD2 LDA2 pstr #00 SWP DUP ADD ;err ADD2 LDA2 pstr
;dict/error pstr ;dict/error pstr
print-opcode print-opcode
;dict/at pstr ;dict/at pstr
phex LIT2 0a ". #18 DEO #18 DEO phex LIT ". #18 DEO
#01 .System/halt DEO
BRK BRK
@ -51,10 +64,12 @@ JMP2r
JMP2r JMP2r
@pstr ( str* -- ) @pstr ( str* -- )
&w &w
LDAk #18 DEO LDAk #18 DEO
INC2 LDAk ,&w JCN INC2 LDAk ?&w
POP2 POP2
JMP2r JMP2r
@err @err
@ -64,12 +79,13 @@ JMP2r
=dict/divzero =dict/divzero
@dict @dict
&error "Error, 20 "during 20 $1 &error "error, 20 "during 20 $1
&unknown "Unkown 20 $1 &unknown "Unkown 20 $1
&underflow "Underflow 20 $1 &underflow "Underflow 20 $1
&overflow "Overflow 20 $1 &overflow "Overflow 20 $1
&divzero "Division 20 "by 20 "zero 20 $1 &divzero "Division 20 "by 20 "zero 20 $1
&at ", 20 "at 20 "# $1 &at ", 20 "at 20 "# $1
&instruction "Press 20 "enter 20 "to 20 "test 20 "each 20 "error. 0a $1
@opcodes @opcodes
"LIT $1 "INC $1 "POP $1 "NIP $1 "SWP $1 "ROT $1 "DUP $1 "OVR $1 "LIT $1 "INC $1 "POP $1 "NIP $1 "SWP $1 "ROT $1 "DUP $1 "OVR $1