basic: add peek/poke/deek/doke commands

This commit is contained in:
Virgil Dupras 2019-11-23 16:07:10 -05:00
parent 585e9f3b6e
commit 9602f9b983
3 changed files with 72 additions and 0 deletions

View File

@ -103,3 +103,14 @@ stored where specified. For example, `input x` stores the result of the
evaluation in variable `x`. Before the variable name, a quoted string literal
can be specified. In that case, that string will be printed as-is just before
the prompt.
**peek/deek**: Put the value at specified memory address into specified
variable. peek is for a single byte, deek is for a word (little endian). For
example, `peek 42 a` puts the byte value contained in memory address 0x002a
into variable `a`. `deek 42 a` does the same as peek, but also puts the value
of 0x002b into `a`'s MSB.
**poke/doke**: Put the value of specified expression into specified memory
address. For example, `poke 42 0x102+0x40` puts `0x42` in memory address
0x2a (MSB is ignored) and `doke 42 0x102+0x40` does the same as poke, but also
puts `0x01` in memory address 0x2b.

View File

@ -267,6 +267,47 @@ basINPUT:
cp a ; ensure Z
ret
basPEEK:
call basDEEK
ret nz
ld d, 0
call varAssign
ret
basPOKE:
call rdExpr
ret nz
; peek address in IX. Save it for later
push ix ; --> lvl 1
call rdSep
call rdExpr
push ix \ pop hl
pop ix ; <-- lvl 1
ret nz
; Poke!
ld (ix), l
ret
basDEEK:
call rdExpr
ret nz
; peek address in IX. Let's peek and put result in DE
ld e, (ix)
ld d, (ix+1)
call rdSep
ld a, (hl)
call varChk
ret nz ; not in variable range
; All good assign
call varAssign
cp a ; ensure Z
ret
basDOKE:
call basPOKE
ld (ix+1), h
ret
; direct only
basCmds1:
.dw basBYE
@ -285,4 +326,12 @@ basCmds2:
.db "if", 0, 0, 0, 0
.dw basINPUT
.db "input", 0
.dw basPEEK
.db "peek", 0, 0
.dw basPOKE
.db "poke", 0, 0
.dw basDEEK
.db "deek", 0, 0
.dw basDOKE
.db "doke", 0, 0
.db 0xff, 0xff, 0xff ; end of table

View File

@ -85,3 +85,15 @@ rdWord:
pop de
pop af
ret
; Read word from HL in SCRATCHPAD and then intepret that word as an expression.
; Put the result in IX.
; Z for success.
rdExpr:
ld de, SCRATCHPAD
call rdWord
push hl
ex de, hl
call parseExpr
pop hl
ret