basic: make variable A the only input variable

Mechanism for assigning inputs to the specified variable is clumsy and uses
binary space. Always using A is much simpler and doesn't seem very limiting to
me. I do that because there's many more "input" commands I'd like to add.
This commit is contained in:
Virgil Dupras 2019-11-24 14:55:50 -05:00
parent e1df320d44
commit 381d57a513
2 changed files with 28 additions and 36 deletions

View File

@ -77,6 +77,16 @@ integer to them. You assign a value to a variable with `=`. For example,
be used in expressions. For example, `print a-6` will print `40`. All variables be used in expressions. For example, `print a-6` will print `40`. All variables
are initialized to zero on launch. are initialized to zero on launch.
### Arguments
Some commands take arguments and there are some common patterns regarding them.
One of them is that all commands that "return" something (`input`, `peek`,
etc.) always to so in variable `A`.
Another is that whenever a number is expected, expressions, including the ones
with variables in it, work fine.
### Commands ### Commands
There are two types of commands: normal and direct-only. The latter can only There are two types of commands: normal and direct-only. The latter can only
@ -109,26 +119,24 @@ by the next, and so on).
do nothing. For example, `if 2>1 print 12` prints `12` and `if 2<1 print 12` do nothing. For example, `if 2>1 print 12` prints `12` and `if 2<1 print 12`
does nothing. The argument for this command is a "thruth expression". does nothing. The argument for this command is a "thruth expression".
**input**: Prompts the user for a numerical value and puts that value in the **input**: Prompts the user for a numerical value and puts that value in `A`.
specified variable. The prompted value is evaluated as an expression and then The prompted value is evaluated as an expression and then stored. The command
stored where specified. For example, `input x` stores the result of the takes an optional string literal parameter. If present, that string will be
evaluation in variable `x`. Before the variable name, a quoted string literal printed before asking for input. Unlike a `print` call, there is no CR/LF after
can be specified. In that case, that string will be printed as-is just before that print.
the prompt.
**peek/deek**: Put the value at specified memory address into specified **peek/deek**: Put the value at specified memory address into `A`. peek is for
variable. peek is for a single byte, deek is for a word (little endian). For a single byte, deek is for a word (little endian). For example, `peek 42` puts
example, `peek 42 a` puts the byte value contained in memory address 0x002a the byte value contained in memory address 0x002a into variable `A`. `deek 42`
into variable `a`. `deek 42 a` does the same as peek, but also puts the value does the same as peek, but also puts the value of 0x002b into `A`'s MSB.
of 0x002b into `a`'s MSB.
**poke/doke**: Put the value of specified expression into specified memory **poke/doke**: Put the value of specified expression into specified memory
address. For example, `poke 42 0x102+0x40` puts `0x42` in memory address 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 0x2a (MSB is ignored) and `doke 42 0x102+0x40` does the same as poke, but also
puts `0x01` in memory address 0x2b. puts `0x01` in memory address 0x2b.
**in**: Same thing as `peek`, but for a I/O port. `in 42 a` generates an input **in**: Same thing as `peek`, but for a I/O port. `in 42` generates an input
I/O on port 42 and stores the byte result in `a`. I/O on port 42 and stores the byte result in `A`.
**out**: Same thing as `poke`, but for a I/O port. `out 42 1+2` generates an **out**: Same thing as `poke`, but for a I/O port. `out 42 1+2` generates an
output I/O on port 42 with value 3. output I/O on port 42 with value 3.

View File

@ -280,15 +280,9 @@ basINPUT:
; If our first arg is a string literal, spit it ; If our first arg is a string literal, spit it
call spitQuoted call spitQuoted
call rdSep call rdSep
ld a, (hl)
call varChk
ret nz ; not in variable range
push af ; --> lvl 1. remember var index
call stdioReadLine call stdioReadLine
call parseExpr call parseExpr
push ix \ pop de ld (VAR_TBL), ix
pop af ; <-- lvl 1. restore var index
call varAssign
call printcrlf call printcrlf
cp a ; ensure Z cp a ; ensure Z
ret ret
@ -296,9 +290,9 @@ basINPUT:
basPEEK: basPEEK:
call basDEEK call basDEEK
ret nz ret nz
ld d, 0 ; set MSB to 0
call varAssign xor a ; sets Z
cp a ; ensure Z ld (VAR_TBL+1), a
ret ret
basPOKE: basPOKE:
@ -321,12 +315,7 @@ basDEEK:
; peek address in IX. Let's peek and put result in DE ; peek address in IX. Let's peek and put result in DE
ld e, (ix) ld e, (ix)
ld d, (ix+1) ld d, (ix+1)
call rdSep ld (VAR_TBL), de
ld a, (hl)
call varChk
ret nz ; not in variable range
; All good assign
call varAssign
cp a ; ensure Z cp a ; ensure Z
ret ret
@ -356,13 +345,8 @@ basIN:
push ix \ pop bc push ix \ pop bc
ld d, 0 ld d, 0
in e, (c) in e, (c)
call rdSep ld (VAR_TBL), de
ld a, (hl) ; Z set from rdExpr
call varChk
ret nz ; not in variable range
; All good assign
call varAssign
cp a ; ensure Z
ret ret
basSLEEP: basSLEEP: