1 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2 ;; and now
for something completely different
...
5 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6 ;; Z80 Assembler
: main module
7 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9 $INCLUDE
-ONCE
<../zxdisasm
>
13 :noname
( addr
-- byte
)
14 0xffff and asm
-emit
:zx
-mem
+ c@
19 0 asm
-emit
:find
-used
" no code" ?not
-error
22 zxdis
:pc asm
-emit
:.hex4
." : "
23 zxdis
:disasm
-one
( addr count
)
25 zxdis
:pc asm
-emit
:used?
32 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
33 ;; DEFFMT
: ignore
for now
40 next
-token tok
-type tk
-id
<> " identifier expected" ?error
49 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
54 \
" AYMute.zas" false false
(include
)
55 \
" cls_ei.zas" false false
(include
)
56 argc
" assemble what?" ?not
-error
57 0 argv false false
(include
)
61 next
-token tok
-type tk
-eos
=
64 refill
-nocross ifnot
." EOF!\n" exit
endif
67 (tib
-in
) 0 begin dup tib
-peekch
-ofs
while 1+ repeat xtype
." >" cr
71 tk
-eos of
." <EOS>\n" endof
72 tk
-id of
." <ID>; str=<" token xtype
." >\n" endof
73 tk
-num of
." <NUM>; num=" tok
-num
. ." str=<" token xtype
." >\n" endof
74 tk
-str of
." <STR>; str=<" token xtype
." >\n" endof
75 tk
-punct of
." <PUNCT>; num=" tok
-num
. ." str=<" token xtype
." >\n" endof
76 tk
-label of
." <LABEL>; str=<" token xtype
." >\n" endof
77 tk
-mnemo of
." <MNEMO>; str=<" token xtype
." > cfa=" tok
-mnemo
-cfa
0 .r cr endof
78 tk
-resw of
." <RES-WORD>; str=<" token xtype
." > uo=" tok
-uo
. ." kind=" tok
-kind
0 .r cr endof
79 otherwise
. " wutafuck?" error
81 depth
" unbalanced stack" ?error
86 ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
87 ;; simple test assembler
90 : assemble
-simple
( -- )
91 \
" AYMute.zas" false false
(include
)
92 \
" cls_ei.zas" false false
(include
)
93 argc
" assemble what?" ?not
-error
94 0 argv false false
(include
)
95 true
to line
-start next
-token
100 ." *** NEWLINE ***\n"
101 refill
-nocross ifnot
." EOF!\n" exit
endif
104 (tib
-in
) 0 begin dup tib
-peekch
-ofs
while 1+ repeat xtype
." >" cr
105 true
to line
-start next
-token
108 asm
-emit
:instruction
-start
111 tk
-eos of
." <EOS>\n" endof
112 \ tk
-id of
." <ID>; str=<" token xtype
." >\n" endof
113 \ tk
-num of
." <NUM>; num=" tok
-num
. ." str=<" token xtype
." >\n" endof
114 \ tk
-str of
." <STR>; str=<" token xtype
." >\n" endof
117 ." <PUNCT>; num=" tok
-num
. ." str=<" token xtype
." >\n"
123 ." <LABEL>; str=<" token xtype
." >\n"
124 token string
:>pad next
-token pad count
125 token
-equ?
if asm
-equ
126 else token
-=?
if asm
-ass
127 else asm
-emit
:pc
-$ asm
-labels
:define
-code
131 \
." <MNEMO>; str=<" token xtype
." > cfa=" tok
-mnemo
-cfa
0 .r cr
132 tok
-mnemo
-cfa execute
133 token
-colon
-eol?
" end of instruction expected" ?not
-error
135 otherwise
. " wutafuck?" error
137 depth
" ASSEMBLER: unbalanced stack" ?error
151 " zxsnap.sna" files
:create
" cannot create output .SNA" ?not
-error
152 dup asm
-writers
:write-sna
-48
155 0 argv asm
-writers
:write-raw