From f5b04fc02fc90c9e143201a3ef57c140fa980080 Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Mon, 18 Nov 2019 15:52:07 -0500 Subject: [PATCH] basic: add expression support to print Again, same thing as in zasm. --- apps/basic/glue.asm | 2 ++ apps/basic/main.asm | 2 +- apps/{zasm => lib}/expr.asm | 14 +++++++++++++- apps/lib/util.asm | 16 ++++++++++++++++ apps/zasm/glue.asm | 5 ++--- apps/zasm/util.asm | 16 ---------------- tools/tests/unit/test_expr.asm | 3 ++- tools/tests/unit/test_z_instr.asm | 4 ++-- 8 files changed, 38 insertions(+), 24 deletions(-) rename apps/{zasm => lib}/expr.asm (89%) diff --git a/apps/basic/glue.asm b/apps/basic/glue.asm index b03c088..8c409cb 100644 --- a/apps/basic/glue.asm +++ b/apps/basic/glue.asm @@ -14,6 +14,8 @@ .inc "lib/ari.asm" .inc "lib/parse.asm" .inc "lib/fmt.asm" +.equ EXPR_PARSE parseLiteral +.inc "lib/expr.asm" .inc "basic/tok.asm" .equ BAS_RAMSTART USER_RAMSTART .inc "basic/main.asm" diff --git a/apps/basic/main.asm b/apps/basic/main.asm index b28c251..c7b25b6 100644 --- a/apps/basic/main.asm +++ b/apps/basic/main.asm @@ -105,7 +105,7 @@ basBYE: .db "Goodbye!", 0 basPRINT: - call parseLiteral + call parseExpr jp nz, basERR push ix \ pop de ld hl, BAS_SCRATCHPAD diff --git a/apps/zasm/expr.asm b/apps/lib/expr.asm similarity index 89% rename from apps/zasm/expr.asm rename to apps/lib/expr.asm index 958af50..e04aeb6 100644 --- a/apps/zasm/expr.asm +++ b/apps/lib/expr.asm @@ -1,3 +1,15 @@ +; *** Requirements *** +; findchar +; multDEBC +; +; *** Defines *** +; +; EXPR_PARSE: routine to call to parse literals or symbols that are part of +; the expression. Routine's signature: +; String in (HL), returns its parsed value to IX. Z for success. +; +; *** Code *** +; ; Parse expression in string at (HL) and returns the result in IX. ; We expect (HL) to be disposable: we mutate it to avoid having to make a copy. ; Sets Z on success, unset on error. @@ -19,7 +31,7 @@ _parseExpr: ld a, '*' call _findAndSplit jp z, _applyMult - jp parseNumberOrSymbol + jp EXPR_PARSE ; Given a string in (HL) and a separator char in A, return a splitted string, ; that is, the same (HL) string but with the found A char replaced by a null diff --git a/apps/lib/util.asm b/apps/lib/util.asm index b8a187f..736208f 100644 --- a/apps/lib/util.asm +++ b/apps/lib/util.asm @@ -74,3 +74,19 @@ strlen: pop bc ret +; DE * BC -> DE (high) and HL (low) +multDEBC: + ld hl, 0 + ld a, 0x10 +.loop: + add hl, hl + rl e + rl d + jr nc, .noinc + add hl, bc + jr nc, .noinc + inc de +.noinc: + dec a + jr nz, .loop + ret diff --git a/apps/zasm/glue.asm b/apps/zasm/glue.asm index 4dcd46c..f577ff6 100644 --- a/apps/zasm/glue.asm +++ b/apps/zasm/glue.asm @@ -31,8 +31,6 @@ ; _blkSeek ; _blkTell ; printstr -; FS_HANDLE_SIZE -; BLOCKDEV_SIZE .inc "user.h" @@ -80,7 +78,8 @@ jp zasmMain .equ DIREC_RAMSTART INS_RAMEND .inc "zasm/directive.asm" .inc "zasm/parse.asm" -.inc "zasm/expr.asm" +.equ EXPR_PARSE parseNumberOrSymbol +.inc "lib/expr.asm" .equ SYM_RAMSTART DIREC_RAMEND .inc "zasm/symbol.asm" .equ ZASM_RAMSTART SYM_RAMEND diff --git a/apps/zasm/util.asm b/apps/zasm/util.asm index 4281761..262758b 100644 --- a/apps/zasm/util.asm +++ b/apps/zasm/util.asm @@ -171,19 +171,3 @@ findStringInList: ret -; DE * BC -> DE (high) and HL (low) -multDEBC: - ld hl, 0 - ld a, 0x10 -.loop: - add hl, hl - rl e - rl d - jr nc, .noinc - add hl, bc - jr nc, .noinc - inc de -.noinc: - dec a - jr nz, .loop - ret diff --git a/tools/tests/unit/test_expr.asm b/tools/tests/unit/test_expr.asm index c9e0f04..5b580cf 100644 --- a/tools/tests/unit/test_expr.asm +++ b/tools/tests/unit/test_expr.asm @@ -18,7 +18,8 @@ jp test .inc "zasm/parse.asm" .equ SYM_RAMSTART DIREC_LASTVAL+2 .inc "zasm/symbol.asm" -.inc "zasm/expr.asm" +.equ EXPR_PARSE parseNumberOrSymbol +.inc "lib/expr.asm" ; Pretend that we aren't in first pass zasmIsFirstPass: diff --git a/tools/tests/unit/test_z_instr.asm b/tools/tests/unit/test_z_instr.asm index 70166d5..04d2248 100644 --- a/tools/tests/unit/test_z_instr.asm +++ b/tools/tests/unit/test_z_instr.asm @@ -7,8 +7,8 @@ jp runTests .inc "lib/util.asm" .inc "zasm/util.asm" .inc "lib/parse.asm" -.inc "zasm/parse.asm" -.inc "zasm/expr.asm" +.equ EXPR_PARSE parseLiteral +.inc "lib/expr.asm" .equ INS_RAMSTART RAMSTART .inc "zasm/instr.asm"