mirror of
https://github.com/hsoft/collapseos.git
synced 2024-12-25 04:38:05 +11:00
basic: allow printing of quoted strings
This commit is contained in:
parent
704d32279a
commit
982d20f895
@ -41,11 +41,16 @@ is kept in order of lines. Line number don't need to be sequential. You can
|
||||
keep leeway in between your lines and then insert a line with a middle number
|
||||
later.
|
||||
|
||||
Some commands take arguments. Those are given by typing a whitespace after the
|
||||
command name and then the argument. Additional arguments are given the same way,
|
||||
by typing a whitespace.
|
||||
|
||||
### Numbers, expressions and variables
|
||||
|
||||
Only 16-bit integers (unsigned for now) are supported in this BASIC. When
|
||||
printed, they're printed in decimal form. When expressing number literals, you
|
||||
can do so either in decimal (`42`), hexadecimal (`0x2a`) or binary (`0b101010`).
|
||||
can do so either in decimal (`42`), hexadecimal (`0x2a`), binary (`0b101010`)
|
||||
or char ('a', resulting in number 97).
|
||||
|
||||
Expressions are accepted wherever a number is expected. For example,
|
||||
`print 2+3` will print `5`. Expressions can't have whitespace inside them and
|
||||
@ -75,9 +80,12 @@ with their associated line number.
|
||||
If `goto` was previously called in direct mode, we start from that line instead.
|
||||
|
||||
**print**. Prints the result of the specified expression, then CR/LF. Can be
|
||||
given multiple arguments, separated with `,`. In that case, all arguments are
|
||||
printed separately with a space in between. For example, `print 12 13` prints
|
||||
`12 13<cr><lf>`
|
||||
given multiple arguments. In that case, all arguments are printed separately
|
||||
with a space in between. For example, `print 12 13` prints `12 13<cr><lf>`
|
||||
|
||||
Unlike anywhere else, the `print` command can take a string inside a double
|
||||
quote. That string will be printed as-is. For example, `print "foo" 40+2` will
|
||||
print `foo 42`.
|
||||
|
||||
**goto**. Make the next line to be executed the line number specified as an
|
||||
argument. Errors out if line doesn't exist. Argument can be an expression. If
|
||||
|
@ -20,6 +20,7 @@
|
||||
.inc "lib/fmt.asm"
|
||||
.equ EXPR_PARSE parseLiteralOrVar
|
||||
.inc "lib/expr.asm"
|
||||
.inc "basic/util.asm"
|
||||
.inc "basic/parse.asm"
|
||||
.inc "basic/tok.asm"
|
||||
.equ VAR_RAMSTART SCRATCHPAD+SCRATCHPAD_SIZE
|
||||
|
@ -176,21 +176,31 @@ basRUN:
|
||||
ret
|
||||
|
||||
basPRINT:
|
||||
; Do we have arguments at all? if not, it's not an error, just print
|
||||
; crlf
|
||||
ld a, (hl)
|
||||
or a
|
||||
jr z, .end
|
||||
; Is our arg a string literal?
|
||||
call spitQuoted
|
||||
jr z, .chkAnother ; string printed, skip to chkAnother
|
||||
ld de, SCRATCHPAD
|
||||
call rdWord
|
||||
push hl ; --> lvl 1
|
||||
ex de, hl
|
||||
call parseExpr
|
||||
ret nz
|
||||
jr nz, .parseError
|
||||
push ix \ pop de
|
||||
ld hl, SCRATCHPAD
|
||||
call fmtDecimal
|
||||
call printstr
|
||||
pop hl ; <-- lvl 1
|
||||
.chkAnother:
|
||||
; Do we have another arg?
|
||||
call rdSep
|
||||
jr z, .another
|
||||
; no, we can stop here
|
||||
.end:
|
||||
cp a ; ensure Z
|
||||
jp printcrlf
|
||||
.another:
|
||||
@ -198,6 +208,11 @@ basPRINT:
|
||||
ld a, ' '
|
||||
call stdioPutC
|
||||
jr basPRINT
|
||||
.parseError:
|
||||
; unwind the stack before returning
|
||||
pop hl ; <-- lvl 1
|
||||
ret
|
||||
|
||||
|
||||
basGOTO:
|
||||
ld de, SCRATCHPAD
|
||||
|
15
apps/basic/util.asm
Normal file
15
apps/basic/util.asm
Normal file
@ -0,0 +1,15 @@
|
||||
; Is (HL) a double-quoted string? If yes, spit what's inside and place (HL)
|
||||
; at char after the closing quote.
|
||||
; Set Z if there was a string, unset otherwise.
|
||||
spitQuoted:
|
||||
ld a, (hl)
|
||||
cp '"'
|
||||
ret nz
|
||||
inc hl
|
||||
.loop:
|
||||
ld a, (hl)
|
||||
inc hl
|
||||
cp '"'
|
||||
ret z
|
||||
call stdioPutC
|
||||
jr .loop
|
Loading…
Reference in New Issue
Block a user