1
0
mirror of https://github.com/hsoft/collapseos.git synced 2024-09-29 14:20:55 +10:00

basic: add in/out commands

Also, fixed the cmd matching algo to not accept partial matches. For example,
to stop matching "input" when the command was "in".
This commit is contained in:
Virgil Dupras 2019-11-23 20:35:21 -05:00
parent 7761cebb0a
commit b7d4860acf
3 changed files with 52 additions and 37 deletions

View File

@ -115,5 +115,11 @@ 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
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
output I/O on port 42 with value 3.
**sleep**: Sleep a number of "units" specified by the supplied expression. A **sleep**: Sleep a number of "units" specified by the supplied expression. A
"unit" depends on the CPU clock speed. At 4MHz, it is roughly 8 microseconds. "unit" depends on the CPU clock speed. At 4MHz, it is roughly 8 microseconds.

View File

@ -56,17 +56,17 @@ basCallCmd:
; let's see if it's a variable assignment. ; let's see if it's a variable assignment.
call varTryAssign call varTryAssign
ret z ; Done! ret z ; Done!
; Second, get cmd length push de ; --> lvl 1.
call fnWSIdx ld de, SCRATCHPAD
cp 7 call rdWord
jp nc, unsetZ ; Too long, can't possibly fit anything. ; cmdname to find in (DE)
; A contains whitespace IDX, save it in B ; How lucky, we have a legitimate use of "ex (sp), hl"! We have the
ld b, a ; cmd table in the stack, which we want in HL and we have the rest of
ex de, hl ; the cmdline in (HL), which we want in the stack!
ex (sp), hl
inc hl \ inc hl inc hl \ inc hl
.loop: .loop:
ld a, b ; whitespace IDX call strcmp
call strncmp
jr z, .found jr z, .found
ld a, 8 ld a, 8
call addHL call addHL
@ -74,15 +74,14 @@ basCallCmd:
cp 0xff cp 0xff
jr nz, .loop jr nz, .loop
; not found ; not found
pop hl ; <-- lvl 1
jp unsetZ jp unsetZ
.found: .found:
dec hl \ dec hl dec hl \ dec hl
call intoHL call intoHL
push hl \ pop ix push hl \ pop ix
; Bring back command string from DE to HL ; Bring back rest of the command string from the stack
ex de, hl pop hl ; <-- lvl 1
ld a, b ; cmd's length
call addHL
call rdSep call rdSep
jp (ix) jp (ix)
@ -309,6 +308,36 @@ basDOKE:
ld (ix+1), h ld (ix+1), h
ret ret
basOUT:
call rdExpr
ret nz
; out address in IX. Save it for later
push ix ; --> lvl 1
call rdSep
call rdExpr
push ix \ pop hl
pop bc ; <-- lvl 1
ret nz
; Out!
out (c), l
cp a ; ensure Z
ret
basIN:
call rdExpr
ret nz
push ix \ pop bc
ld d, 0
in e, (c)
call rdSep
ld a, (hl)
call varChk
ret nz ; not in variable range
; All good assign
call varAssign
cp a ; ensure Z
ret
basSLEEP: basSLEEP:
call rdExpr call rdExpr
ret nz ret nz
@ -346,6 +375,10 @@ basCmds2:
.db "deek", 0, 0 .db "deek", 0, 0
.dw basDOKE .dw basDOKE
.db "doke", 0, 0 .db "doke", 0, 0
.dw basOUT
.db "out", 0, 0, 0
.dw basIN
.db "in", 0, 0, 0, 0
.dw basSLEEP .dw basSLEEP
.db "sleep", 0 .db "sleep", 0
.db 0xff, 0xff, 0xff ; end of table .db 0xff, 0xff, 0xff ; end of table

View File

@ -32,30 +32,6 @@ rdSep:
inc a ; unset Z inc a ; unset Z
ret ret
; Find the first whitespace in (HL) and returns its index in A
; Sets Z if whitespace is found, unset if end of string was found.
; In the case where no whitespace was found, A returns the length of the string.
fnWSIdx:
push hl
push bc
ld b, 0
.loop:
ld a, (hl)
call isSep
jr z, .found
or a
jr z, .eos
inc hl
inc b
jr .loop
.eos:
inc a ; unset Z
.found: ; Z already set from isSep
ld a, b
pop bc
pop hl
ret
; Advance HL to the next separator or to the end of string. ; Advance HL to the next separator or to the end of string.
toSep: toSep:
ld a, (hl) ld a, (hl)