1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|00 @System &vector $2 &wst $1 &rst $1 &pad $4 &r $2 &g $2 &b $2 &debug $1 &halt $1
|0100
;on-halt .System/vector DEO2
POP
#80 .System/halt DEO
BRK
@on-halt ( addr* inst code -> )
#00 SWP DUP ADD ;err ADD2 LDA2 pstr
;dict/error pstr
print-opcode
;dict/at pstr
phex LIT2 0a ". #18 DEO #18 DEO
#01 .System/halt DEO
BRK
@print-opcode ( byte -- )
DUP #20 EQU ?&jci
DUP #40 EQU ?&jmi
DUP #60 EQU ?&jsi
DUP #00 EQU ?&brk
#00 OVR #1f AND #20 SFT2 ;opcodes ADD2 pstr
DUP #20 AND #00 EQU ?&no-2 LIT "2 #18 DEO &no-2
DUP #1f AND #00 EQU ?&no-k
DUP #80 AND #00 EQU ?&no-k LIT "k #18 DEO &no-k
DUP #40 AND #00 EQU ?&no-r LIT "r #18 DEO &no-r
POP
JMP2r
&brk POP ;opcodes/brk !pstr
&jmi POP ;opcodes/jmi !pstr
&jci POP ;opcodes/jci !pstr
&jsi POP ;opcodes/jsi !pstr
@phex ( short* -- )
SWP phex/b
&b ( byte -- ) DUP #04 SFT phex/c
&c ( char -- ) #0f AND DUP #09 GTH #27 MUL ADD #30 ADD #18 DEO
JMP2r
@err
=dict/unknown
=dict/underflow
=dict/overflow
=dict/divzero
@dict
&error "Error, 20 "during 20 $1
&unknown "Unkown 20 $1
&underflow "Underflow 20 $1
&overflow "Overflow 20 $1
&divzero "Division 20 "by 20 "zero 20 $1
&at ", 20 "at 20 "# $1
@opcodes
"LIT $1 "INC $1 "POP $1 "NIP $1 "SWP $1 "ROT $1 "DUP $1 "OVR $1
"EQU $1 "NEQ $1 "GTH $1 "LTH $1 "JMP $1 "JCN $1 "JSR $1 "STH $1
"LDZ $1 "STZ $1 "LDR $1 "STR $1 "LDA $1 "STA $1 "DEI $1 "DEO $1
"ADD $1 "SUB $1 "MUL $1 "DIV $1 "AND $1 "ORA $1 "EOR $1 "SFT $1
&brk "BRK $1 &jmi "JMI $1 &jci "JCI $1 &jsi "JSI $1