2019-05-10 04:09:40 +10:00
|
|
|
; *** Requirements ***
|
2019-05-10 05:36:03 +10:00
|
|
|
; blockdev
|
2019-05-10 04:09:40 +10:00
|
|
|
; JUMP_STRNCMP
|
|
|
|
; JUMP_ADDDE
|
2019-05-10 11:21:08 +10:00
|
|
|
; JUMP_ADDHL
|
2019-05-10 04:09:40 +10:00
|
|
|
; JUMP_UPCASE
|
|
|
|
; JUMP_UNSETZ
|
|
|
|
; JUMP_INTODE
|
2019-05-10 11:21:08 +10:00
|
|
|
; JUMP_FINDCHAR
|
|
|
|
; RAMSTART (where we put our variables in RAM)
|
2019-05-01 05:51:39 +10:00
|
|
|
|
|
|
|
; *** Code ***
|
2019-05-10 05:36:03 +10:00
|
|
|
; Read file through GetC routine pointer at HL and outputs its upcodes through
|
|
|
|
; the PutC routine pointer at DE.
|
2019-05-01 05:51:39 +10:00
|
|
|
main:
|
2019-05-10 05:36:03 +10:00
|
|
|
ld (ioGetCPtr), hl
|
|
|
|
ld (ioPutCPtr), de
|
2019-05-10 11:21:08 +10:00
|
|
|
ld hl, 0
|
|
|
|
ld (curOutputOffset), hl
|
2019-05-01 05:51:39 +10:00
|
|
|
.loop:
|
2019-05-10 05:36:03 +10:00
|
|
|
call ioReadLine
|
|
|
|
or a ; is A 0?
|
|
|
|
jr z, .stop ; We have EOF
|
2019-05-01 05:51:39 +10:00
|
|
|
call parseLine
|
2019-05-02 00:16:57 +10:00
|
|
|
jr nz, .stop
|
2019-05-01 05:51:39 +10:00
|
|
|
jr .loop
|
|
|
|
.stop:
|
|
|
|
ret
|
|
|
|
|
2019-05-01 11:40:22 +10:00
|
|
|
#include "util.asm"
|
2019-05-10 05:36:03 +10:00
|
|
|
#include "io.asm"
|
2019-05-02 04:19:43 +10:00
|
|
|
#include "parse.asm"
|
2019-05-02 01:26:41 +10:00
|
|
|
#include "literal.asm"
|
2019-05-01 11:40:22 +10:00
|
|
|
#include "instr.asm"
|
|
|
|
#include "directive.asm"
|
2019-05-10 11:21:08 +10:00
|
|
|
.equ SYM_RAMSTART RAMSTART
|
|
|
|
#include "symbol.asm"
|
2019-05-01 11:40:22 +10:00
|
|
|
|
2019-05-10 11:21:08 +10:00
|
|
|
; Increase (curOutputOffset) by A
|
|
|
|
incOutputOffset:
|
|
|
|
push de
|
|
|
|
ld de, (curOutputOffset)
|
|
|
|
call JUMP_ADDDE
|
|
|
|
ld (curOutputOffset), de
|
|
|
|
pop de
|
|
|
|
ret
|
|
|
|
|
|
|
|
; Parse line in (HL), write the resulting opcode(s) in (DE) and increases
|
|
|
|
; (curOutputOffset) by the number of bytes written. Advances HL where
|
|
|
|
; tokenization stopped and DE to where we should write the next upcode.
|
2019-05-02 00:16:57 +10:00
|
|
|
; Sets Z if parse was successful, unset if there was an error or EOF.
|
2019-05-01 05:51:39 +10:00
|
|
|
parseLine:
|
|
|
|
push bc
|
2019-05-01 07:04:42 +10:00
|
|
|
|
2019-05-01 05:51:39 +10:00
|
|
|
call tokenize
|
2019-05-01 12:27:11 +10:00
|
|
|
ld a, b ; TOK_*
|
2019-05-01 11:40:22 +10:00
|
|
|
cp TOK_INSTR
|
|
|
|
jr z, .instr
|
2019-05-02 01:26:41 +10:00
|
|
|
cp TOK_DIRECTIVE
|
|
|
|
jr z, .direc
|
2019-05-10 11:21:08 +10:00
|
|
|
cp TOK_LABEL
|
|
|
|
jr z, .label
|
2019-05-10 05:36:03 +10:00
|
|
|
cp TOK_EMPTY
|
|
|
|
jr z, .success ; empty line? do nothing but don't error out.
|
2019-05-02 01:26:41 +10:00
|
|
|
jr .error ; token not supported
|
2019-05-01 11:40:22 +10:00
|
|
|
.instr:
|
2019-05-01 12:27:11 +10:00
|
|
|
ld a, c ; I_*
|
2019-05-01 11:40:22 +10:00
|
|
|
call parseInstruction
|
2019-05-01 05:51:39 +10:00
|
|
|
or a ; is zero?
|
|
|
|
jr z, .error
|
2019-05-10 11:21:08 +10:00
|
|
|
call incOutputOffset
|
2019-05-10 05:36:03 +10:00
|
|
|
ld b, a
|
2019-05-02 01:26:41 +10:00
|
|
|
ld hl, instrUpcode
|
2019-05-10 05:36:03 +10:00
|
|
|
.loopInstr:
|
|
|
|
ld a, (hl)
|
|
|
|
call ioPutC
|
|
|
|
inc hl
|
|
|
|
djnz .loopInstr
|
2019-05-02 01:26:41 +10:00
|
|
|
jr .success
|
|
|
|
.direc:
|
|
|
|
ld a, c ; D_*
|
|
|
|
call parseDirective
|
2019-05-10 11:21:08 +10:00
|
|
|
call incOutputOffset
|
2019-05-10 05:36:03 +10:00
|
|
|
ld b, a
|
2019-05-02 01:26:41 +10:00
|
|
|
ld hl, direcData
|
2019-05-10 05:36:03 +10:00
|
|
|
.loopDirec:
|
|
|
|
ld a, (hl)
|
|
|
|
call ioPutC
|
|
|
|
inc hl
|
|
|
|
djnz .loopDirec
|
2019-05-10 11:21:08 +10:00
|
|
|
jr .success
|
|
|
|
.label:
|
|
|
|
; The string in (scratchpad) is a label with its trailing ':' removed.
|
|
|
|
ld hl, scratchpad
|
|
|
|
ld de, (curOutputOffset)
|
|
|
|
call symRegister
|
|
|
|
|
2019-05-02 00:16:57 +10:00
|
|
|
jr .success
|
|
|
|
.success:
|
|
|
|
xor a ; ensure Z
|
2019-05-01 05:51:39 +10:00
|
|
|
jr .end
|
|
|
|
.error:
|
2019-05-02 00:16:57 +10:00
|
|
|
call JUMP_UNSETZ
|
2019-05-01 05:51:39 +10:00
|
|
|
.end:
|
|
|
|
pop bc
|
|
|
|
ret
|
|
|
|
|
2019-05-10 11:21:08 +10:00
|
|
|
; *** Variables ***
|
|
|
|
; The offset where we currently are with regards to outputting opcodes
|
|
|
|
curOutputOffset:
|
|
|
|
.fill 2
|