1
0
mirror of https://github.com/hsoft/collapseos.git synced 2024-12-03 02:08:05 +11:00
collapseos/apps/zasm/main.asm

80 lines
1.3 KiB
NASM
Raw Normal View History

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
jr nz, .stop
ld a, c
add a, ixl
2019-05-01 05:51:39 +10:00
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 "parse.asm"
2019-05-02 01:26:41 +10:00
#include "literal.asm"
2019-05-01 11:40:22 +10:00
#include "instr.asm"
2019-05-02 01:26:41 +10:00
#include "tok.asm"
2019-05-01 11:40:22 +10:00
#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 IXL. Advances HL where tokenization stopped and DE
2019-05-01 05:51:39 +10:00
; to where we should write the next upcode.
; 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
call gotoNextNotBlankLine
2019-05-01 11:40:22 +10:00
jr nz, .error
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
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
ld b, 0
ld c, a ; written bytes
push hl
2019-05-02 01:26:41 +10:00
ld hl, instrUpcode
call copy
pop hl
call JUMP_ADDDE
jr .success
.direc:
ld a, c ; D_*
call parseDirective
ld b, 0
ld c, a ; written bytes
push hl
ld hl, direcData
2019-05-01 05:51:39 +10:00
call copy
pop hl
call JUMP_ADDDE
jr .success
.success:
ld ixl, a
xor a ; ensure Z
2019-05-01 05:51:39 +10:00
jr .end
.error:
xor ixl
call JUMP_UNSETZ
2019-05-01 05:51:39 +10:00
.end:
pop bc
ret