2019-05-01 05:51:39 +10:00
|
|
|
#include "user.inc"
|
|
|
|
|
|
|
|
; *** Code ***
|
|
|
|
.org USER_CODE
|
|
|
|
|
|
|
|
; Parse asm file in (HL) and outputs its upcodes in (DE). Returns the number
|
|
|
|
; of bytes written in C.
|
|
|
|
main:
|
|
|
|
ld bc, 0 ; C is our written bytes counter
|
|
|
|
.loop:
|
|
|
|
call parseLine
|
|
|
|
or a ; is zero? stop
|
|
|
|
jr z, .stop
|
|
|
|
add a, c
|
|
|
|
ld c, a
|
|
|
|
call gotoNextLine
|
|
|
|
jr nz, .stop ; error? stop
|
|
|
|
jr .loop
|
|
|
|
.stop:
|
|
|
|
ret
|
|
|
|
|
2019-05-01 11:40:22 +10:00
|
|
|
#include "util.asm"
|
|
|
|
#include "tok.asm"
|
|
|
|
#include "instr.asm"
|
|
|
|
#include "directive.asm"
|
|
|
|
|
2019-05-01 05:51:39 +10:00
|
|
|
; Parse line in (HL), write the resulting opcode(s) in (DE) and returns the
|
|
|
|
; number of written bytes in A. Advances HL where tokenization stopped and DE
|
|
|
|
; to where we should write the next upcode.
|
|
|
|
parseLine:
|
|
|
|
push bc
|
2019-05-01 07:04:42 +10:00
|
|
|
|
2019-05-01 06:24:45 +10:00
|
|
|
call gotoNextNotBlankLine
|
2019-05-01 11:40:22 +10:00
|
|
|
jr nz, .error
|
2019-05-01 07:04:42 +10:00
|
|
|
push de
|
|
|
|
ld de, tokInstr
|
2019-05-01 05:51:39 +10:00
|
|
|
call tokenize
|
2019-05-01 11:40:22 +10:00
|
|
|
ld a, (tokInstr) ; TOK_*
|
|
|
|
cp TOK_BAD
|
|
|
|
jr z, .error
|
2019-05-01 07:04:42 +10:00
|
|
|
ld de, tokArg1
|
|
|
|
call tokenizeInstrArg
|
|
|
|
ld de, tokArg2
|
|
|
|
call tokenizeInstrArg
|
|
|
|
pop de
|
2019-05-01 11:40:22 +10:00
|
|
|
cp TOK_INSTR
|
|
|
|
jr z, .instr
|
|
|
|
jr .error ; directive not supported yet
|
|
|
|
.instr:
|
|
|
|
ld a, (tokInstr+1) ; I_*
|
|
|
|
call parseInstruction
|
2019-05-01 05:51:39 +10:00
|
|
|
or a ; is zero?
|
|
|
|
jr z, .error
|
|
|
|
ld b, 0
|
|
|
|
ld c, a ; written bytes
|
|
|
|
push hl
|
|
|
|
ld hl, curUpcode
|
|
|
|
call copy
|
|
|
|
pop hl
|
|
|
|
call JUMP_ADDDE
|
|
|
|
jr .end
|
|
|
|
.error:
|
|
|
|
xor a
|
|
|
|
.end:
|
|
|
|
pop bc
|
|
|
|
ret
|
|
|
|
|
2019-05-01 07:04:42 +10:00
|
|
|
; *** Variables ***
|
|
|
|
|
|
|
|
tokInstr:
|
|
|
|
.fill 5
|
|
|
|
tokArg1:
|
|
|
|
.fill 9
|
|
|
|
tokArg2:
|
|
|
|
.fill 9
|
|
|
|
|