2019-04-30 15:51:39 -04: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
|
2019-05-01 10:16:57 -04:00
|
|
|
jr nz, .stop
|
|
|
|
ld a, c
|
|
|
|
add a, ixl
|
2019-04-30 15:51:39 -04:00
|
|
|
ld c, a
|
|
|
|
call gotoNextLine
|
|
|
|
jr nz, .stop ; error? stop
|
|
|
|
jr .loop
|
|
|
|
.stop:
|
|
|
|
ret
|
|
|
|
|
2019-04-30 21:40:22 -04:00
|
|
|
#include "util.asm"
|
|
|
|
#include "tok.asm"
|
|
|
|
#include "instr.asm"
|
|
|
|
#include "directive.asm"
|
|
|
|
|
2019-04-30 15:51:39 -04:00
|
|
|
; Parse line in (HL), write the resulting opcode(s) in (DE) and returns the
|
2019-05-01 10:16:57 -04:00
|
|
|
; number of written bytes in IXL. Advances HL where tokenization stopped and DE
|
2019-04-30 15:51:39 -04:00
|
|
|
; to where we should write the next upcode.
|
2019-05-01 10:16:57 -04:00
|
|
|
; Sets Z if parse was successful, unset if there was an error or EOF.
|
2019-04-30 15:51:39 -04:00
|
|
|
parseLine:
|
|
|
|
push bc
|
2019-04-30 17:04:42 -04:00
|
|
|
|
2019-04-30 16:24:45 -04:00
|
|
|
call gotoNextNotBlankLine
|
2019-04-30 21:40:22 -04:00
|
|
|
jr nz, .error
|
2019-04-30 15:51:39 -04:00
|
|
|
call tokenize
|
2019-04-30 22:27:11 -04:00
|
|
|
ld a, b ; TOK_*
|
2019-04-30 21:40:22 -04:00
|
|
|
cp TOK_BAD
|
|
|
|
jr z, .error
|
|
|
|
cp TOK_INSTR
|
|
|
|
jr z, .instr
|
|
|
|
jr .error ; directive not supported yet
|
|
|
|
.instr:
|
2019-04-30 22:27:11 -04:00
|
|
|
ld a, c ; I_*
|
2019-04-30 21:40:22 -04:00
|
|
|
call parseInstruction
|
2019-04-30 15:51:39 -04: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
|
2019-05-01 10:16:57 -04:00
|
|
|
jr .success
|
|
|
|
.success:
|
|
|
|
ld ixl, a
|
|
|
|
xor a ; ensure Z
|
2019-04-30 15:51:39 -04:00
|
|
|
jr .end
|
|
|
|
.error:
|
2019-05-01 10:16:57 -04:00
|
|
|
xor ixl
|
|
|
|
call JUMP_UNSETZ
|
2019-04-30 15:51:39 -04:00
|
|
|
.end:
|
|
|
|
pop bc
|
|
|
|
ret
|
|
|
|
|
2019-04-30 17:04:42 -04:00
|
|
|
; *** Variables ***
|
2019-04-30 21:55:18 -04:00
|
|
|
scratchpad:
|
|
|
|
.fill 0x20
|