zasm: add .out directive

This commit is contained in:
Virgil Dupras 2019-06-03 11:13:31 -04:00
parent 40b3d5e11e
commit 465da6a79d
3 changed files with 41 additions and 1 deletions

View File

@ -127,6 +127,13 @@ allowed. An included file cannot have an `#inc` directive.
explicitly with `.fill`, if needed. Often used to assemble binaries
designed to run at offsets other than zero (userland).
**.out**: Outputs the value of the expression supplied as an argument to
`ZASM_DEBUG_PORT`. The value is always interpreted as a word, so
there's always two `out` instruction executed per directive. High byte
is sent before low byte. Useful or debugging, quickly figuring our
RAM constants, etc. The value is only outputted during the second
pass.
**#inc**: Takes a string literal as an argument. Open the file name specified
in the argument in the currently active filesystem, parse that file
and output its binary content as is the code has been in the includer

View File

@ -19,3 +19,6 @@
; Out of memory
.equ ERR_OOM 0x07
; *** Other ***
.equ ZASM_DEBUG_PORT 42

View File

@ -5,7 +5,8 @@
.equ D_EQU 0x02
.equ D_ORG 0x03
.equ D_FIL 0x04
.equ D_INC 0x05
.equ D_OUT 0x05
.equ D_INC 0x06
.equ D_BAD 0xff
; *** Variables ***
@ -20,6 +21,7 @@ directiveNames:
.db ".EQU"
.db ".ORG"
.db ".FIL"
.db ".OUT"
.db "#inc"
; This is a list of handlers corresponding to indexes in directiveNames
@ -29,6 +31,7 @@ directiveHandlers:
.dw handleEQU
.dw handleORG
.dw handleFIL
.dw handleOUT
.dw handleINC
handleDB:
@ -187,6 +190,33 @@ handleFIL:
call unsetZ
ret
handleOUT:
push hl
; Read our expression
call readWord
jr nz, .badfmt
call zasmIsFirstPass ; No .out during first pass
jr z, .end
ld hl, scratchpad
call parseExpr
jr nz, .badarg
push ix \ pop hl
ld a, h
out (ZASM_DEBUG_PORT), a
ld a, l
out (ZASM_DEBUG_PORT), a
jr .end
.badfmt:
ld a, ERR_BAD_FMT
jr .error
.badarg:
ld a, ERR_BAD_ARG
.error:
call unsetZ
.end:
pop hl
ret
handleINC:
call readWord
jr nz, .badfmt