Переглянути джерело

basic: add peek/poke/deek/doke commands

pull/85/head
Virgil Dupras 4 роки тому
джерело
коміт
9602f9b983
3 змінених файлів з 72 додано та 0 видалено
  1. +11
    -0
      apps/basic/README.md
  2. +49
    -0
      apps/basic/main.asm
  3. +12
    -0
      apps/basic/tok.asm

+ 11
- 0
apps/basic/README.md Переглянути файл

@@ -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.

+ 49
- 0
apps/basic/main.asm Переглянути файл

@@ -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

+ 12
- 0
apps/basic/tok.asm Переглянути файл

@@ -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

Завантаження…
Відмінити
Зберегти