basic: add expression support to print

Again, same thing as in zasm.
This commit is contained in:
Virgil Dupras 2019-11-18 15:52:07 -05:00
parent 0bd58fd178
commit f5b04fc02f
8 changed files with 38 additions and 24 deletions

View File

@ -14,6 +14,8 @@
.inc "lib/ari.asm" .inc "lib/ari.asm"
.inc "lib/parse.asm" .inc "lib/parse.asm"
.inc "lib/fmt.asm" .inc "lib/fmt.asm"
.equ EXPR_PARSE parseLiteral
.inc "lib/expr.asm"
.inc "basic/tok.asm" .inc "basic/tok.asm"
.equ BAS_RAMSTART USER_RAMSTART .equ BAS_RAMSTART USER_RAMSTART
.inc "basic/main.asm" .inc "basic/main.asm"

View File

@ -105,7 +105,7 @@ basBYE:
.db "Goodbye!", 0 .db "Goodbye!", 0
basPRINT: basPRINT:
call parseLiteral call parseExpr
jp nz, basERR jp nz, basERR
push ix \ pop de push ix \ pop de
ld hl, BAS_SCRATCHPAD ld hl, BAS_SCRATCHPAD

View File

@ -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. ; 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. ; We expect (HL) to be disposable: we mutate it to avoid having to make a copy.
; Sets Z on success, unset on error. ; Sets Z on success, unset on error.
@ -19,7 +31,7 @@ _parseExpr:
ld a, '*' ld a, '*'
call _findAndSplit call _findAndSplit
jp z, _applyMult jp z, _applyMult
jp parseNumberOrSymbol jp EXPR_PARSE
; Given a string in (HL) and a separator char in A, return a splitted string, ; 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 ; that is, the same (HL) string but with the found A char replaced by a null

View File

@ -74,3 +74,19 @@ strlen:
pop bc pop bc
ret 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

View File

@ -31,8 +31,6 @@
; _blkSeek ; _blkSeek
; _blkTell ; _blkTell
; printstr ; printstr
; FS_HANDLE_SIZE
; BLOCKDEV_SIZE
.inc "user.h" .inc "user.h"
@ -80,7 +78,8 @@ jp zasmMain
.equ DIREC_RAMSTART INS_RAMEND .equ DIREC_RAMSTART INS_RAMEND
.inc "zasm/directive.asm" .inc "zasm/directive.asm"
.inc "zasm/parse.asm" .inc "zasm/parse.asm"
.inc "zasm/expr.asm" .equ EXPR_PARSE parseNumberOrSymbol
.inc "lib/expr.asm"
.equ SYM_RAMSTART DIREC_RAMEND .equ SYM_RAMSTART DIREC_RAMEND
.inc "zasm/symbol.asm" .inc "zasm/symbol.asm"
.equ ZASM_RAMSTART SYM_RAMEND .equ ZASM_RAMSTART SYM_RAMEND

View File

@ -171,19 +171,3 @@ findStringInList:
ret 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

View File

@ -18,7 +18,8 @@ jp test
.inc "zasm/parse.asm" .inc "zasm/parse.asm"
.equ SYM_RAMSTART DIREC_LASTVAL+2 .equ SYM_RAMSTART DIREC_LASTVAL+2
.inc "zasm/symbol.asm" .inc "zasm/symbol.asm"
.inc "zasm/expr.asm" .equ EXPR_PARSE parseNumberOrSymbol
.inc "lib/expr.asm"
; Pretend that we aren't in first pass ; Pretend that we aren't in first pass
zasmIsFirstPass: zasmIsFirstPass:

View File

@ -7,8 +7,8 @@ jp runTests
.inc "lib/util.asm" .inc "lib/util.asm"
.inc "zasm/util.asm" .inc "zasm/util.asm"
.inc "lib/parse.asm" .inc "lib/parse.asm"
.inc "zasm/parse.asm" .equ EXPR_PARSE parseLiteral
.inc "zasm/expr.asm" .inc "lib/expr.asm"
.equ INS_RAMSTART RAMSTART .equ INS_RAMSTART RAMSTART
.inc "zasm/instr.asm" .inc "zasm/instr.asm"