From 465da6a79d64532e97e3299d635168b6f1f5de20 Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Mon, 3 Jun 2019 11:13:31 -0400 Subject: [PATCH] zasm: add .out directive --- apps/zasm/README.md | 7 +++++++ apps/zasm/const.asm | 3 +++ apps/zasm/directive.asm | 32 +++++++++++++++++++++++++++++++- 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/apps/zasm/README.md b/apps/zasm/README.md index 45ebe27..c1bf700 100644 --- a/apps/zasm/README.md +++ b/apps/zasm/README.md @@ -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 diff --git a/apps/zasm/const.asm b/apps/zasm/const.asm index dfddfd6..e9d2fdd 100644 --- a/apps/zasm/const.asm +++ b/apps/zasm/const.asm @@ -19,3 +19,6 @@ ; Out of memory .equ ERR_OOM 0x07 + +; *** Other *** +.equ ZASM_DEBUG_PORT 42 diff --git a/apps/zasm/directive.asm b/apps/zasm/directive.asm index 181490d..4c9ab2b 100644 --- a/apps/zasm/directive.asm +++ b/apps/zasm/directive.asm @@ -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