mirror of
https://github.com/hsoft/collapseos.git
synced 2024-11-26 05:48:05 +11:00
Compare commits
4 Commits
871b06fecf
...
572e3566eb
Author | SHA1 | Date | |
---|---|---|---|
|
572e3566eb | ||
|
4c07639808 | ||
|
4ba84dac5c | ||
|
77485a0031 |
@ -149,6 +149,11 @@ input I/O on port 42 and stores the byte result in `A`.
|
||||
**out <port> <val>**: 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.
|
||||
|
||||
**getc**: Waits for a single character to be typed in the console and then puts
|
||||
that value in `A`.
|
||||
|
||||
**putc <char>**: Puts the specified character to the console.
|
||||
|
||||
**sleep <units>**: 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.
|
||||
|
@ -26,6 +26,8 @@ basGETB:
|
||||
call blkGetB
|
||||
ret nz
|
||||
ld (VAR_TBL), a
|
||||
xor a
|
||||
ld (VAR_TBL+1), a
|
||||
ret
|
||||
|
||||
basPUTB:
|
||||
@ -36,12 +38,12 @@ basPUTB:
|
||||
jp blkPutB
|
||||
|
||||
basBLKCmds:
|
||||
.db "bsel", 0
|
||||
.dw basBSEL
|
||||
.db "bsel", 0, 0
|
||||
.dw basBSEEK
|
||||
.db "bseek", 0
|
||||
.dw basBSEEK
|
||||
.db "getb", 0
|
||||
.dw basGETB
|
||||
.db "getb", 0, 0
|
||||
.db "putb", 0
|
||||
.dw basPUTB
|
||||
.db "putb", 0, 0
|
||||
.db 0xff, 0xff, 0xff ; end of table
|
||||
.db 0xff ; end of table
|
||||
|
@ -127,14 +127,14 @@ basPgmHook:
|
||||
ret
|
||||
|
||||
basFSCmds:
|
||||
.db "fls", 0
|
||||
.dw basFLS
|
||||
.db "fls", 0, 0, 0
|
||||
.dw basLDBAS
|
||||
.db "ldbas", 0
|
||||
.dw basFOPEN
|
||||
.dw basLDBAS
|
||||
.db "fopen", 0
|
||||
.dw basFOPEN
|
||||
.db "fnew", 0
|
||||
.dw basFNEW
|
||||
.db "fnew", 0, 0
|
||||
.db "fdel", 0
|
||||
.dw basFDEL
|
||||
.db "fdel", 0, 0
|
||||
.db 0xff, 0xff, 0xff ; end of table
|
||||
.db 0xff ; end of table
|
||||
|
@ -31,7 +31,7 @@ basStart:
|
||||
jr basLoop
|
||||
|
||||
.welcome:
|
||||
.db "OK", 0
|
||||
.db "Collapse OS", 0
|
||||
|
||||
basLoop:
|
||||
ld hl, .sPrompt
|
||||
@ -63,19 +63,18 @@ basLoop:
|
||||
; Destroys HL.
|
||||
; Z is set if found, unset otherwise.
|
||||
basFindCmd:
|
||||
; cmd table starts with routine pointer, skip
|
||||
inc hl \ inc hl
|
||||
.loop:
|
||||
call strcmp
|
||||
jr z, .found
|
||||
ld a, 8
|
||||
call addHL
|
||||
call strskip
|
||||
inc hl ; point to routine
|
||||
jr z, .found ; Z from strcmp
|
||||
inc hl \ inc hl ; skip routine
|
||||
ld a, (hl)
|
||||
cp 0xff
|
||||
jr nz, .loop
|
||||
jp unsetZ
|
||||
inc a ; was it 0xff?
|
||||
jr nz, .loop ; no
|
||||
dec a ; unset Z
|
||||
ret
|
||||
.found:
|
||||
dec hl \ dec hl
|
||||
call intoHL
|
||||
push hl \ pop ix
|
||||
ret
|
||||
@ -126,16 +125,11 @@ basERR:
|
||||
;
|
||||
; Commands are expected to set Z on success.
|
||||
basBYE:
|
||||
ld hl, .sBye
|
||||
call printstr
|
||||
call printcrlf
|
||||
; To quit the loop, let's return the stack to its initial value and
|
||||
; then return.
|
||||
xor a
|
||||
ld sp, (BAS_INITSP)
|
||||
ret
|
||||
.sBye:
|
||||
.db "Goodbye!", 0
|
||||
|
||||
basLIST:
|
||||
call bufFirst
|
||||
@ -349,6 +343,22 @@ basIN:
|
||||
; Z set from rdExpr
|
||||
ret
|
||||
|
||||
basGETC:
|
||||
call stdioGetC
|
||||
ld (VAR_TBL), a
|
||||
xor a
|
||||
ld (VAR_TBL+1), a
|
||||
ret
|
||||
|
||||
basPUTC:
|
||||
call rdExpr
|
||||
ret nz
|
||||
push ix \ pop hl
|
||||
ld a, l
|
||||
call stdioPutC
|
||||
xor a ; set Z
|
||||
ret
|
||||
|
||||
basSLEEP:
|
||||
call rdExpr
|
||||
ret nz
|
||||
@ -425,42 +435,49 @@ basR2Var: ; Just send reg to vars. Used in basPgmHook
|
||||
cp a ; USR never errors out
|
||||
ret
|
||||
|
||||
; Command table format: Null-terminated string followed by a 2-byte routine
|
||||
; pointer.
|
||||
|
||||
; direct only
|
||||
basCmds1:
|
||||
.db "bye", 0
|
||||
.dw basBYE
|
||||
.db "bye", 0, 0, 0
|
||||
.db "list", 0
|
||||
.dw basLIST
|
||||
.db "list", 0, 0
|
||||
.db "run", 0
|
||||
.dw basRUN
|
||||
.db "run", 0, 0, 0
|
||||
.dw bufInit
|
||||
.db "clear", 0
|
||||
.dw bufInit
|
||||
; statements
|
||||
basCmds2:
|
||||
.dw basPRINT
|
||||
.db "print", 0
|
||||
.dw basPRINT
|
||||
.db "goto", 0
|
||||
.dw basGOTO
|
||||
.db "goto", 0, 0
|
||||
.db "if", 0
|
||||
.dw basIF
|
||||
.db "if", 0, 0, 0, 0
|
||||
.dw basINPUT
|
||||
.db "input", 0
|
||||
.dw basINPUT
|
||||
.db "peek", 0
|
||||
.dw basPEEK
|
||||
.db "peek", 0, 0
|
||||
.db "poke", 0
|
||||
.dw basPOKE
|
||||
.db "poke", 0, 0
|
||||
.db "deek", 0
|
||||
.dw basDEEK
|
||||
.db "deek", 0, 0
|
||||
.db "doke", 0
|
||||
.dw basDOKE
|
||||
.db "doke", 0, 0
|
||||
.db "out", 0
|
||||
.dw basOUT
|
||||
.db "out", 0, 0, 0
|
||||
.db "in", 0
|
||||
.dw basIN
|
||||
.db "in", 0, 0, 0, 0
|
||||
.dw basSLEEP
|
||||
.db "getc", 0
|
||||
.dw basGETC
|
||||
.db "putc", 0
|
||||
.dw basPUTC
|
||||
.db "sleep", 0
|
||||
.dw basSLEEP
|
||||
.db "addr", 0
|
||||
.dw basADDR
|
||||
.db "addr", 0, 0
|
||||
.db "usr", 0
|
||||
.dw basUSR
|
||||
.db "usr", 0, 0, 0
|
||||
.db 0xff, 0xff, 0xff ; end of table
|
||||
.db 0xff ; end of table
|
||||
|
@ -52,6 +52,19 @@ strcmp:
|
||||
; early, set otherwise)
|
||||
ret
|
||||
|
||||
; Given a string at (HL), move HL until it points to the end of that string.
|
||||
strskip:
|
||||
push af
|
||||
xor a ; look for null char
|
||||
.loop:
|
||||
cp (hl)
|
||||
jp z, .found
|
||||
inc hl
|
||||
jr .loop
|
||||
.found:
|
||||
pop af
|
||||
ret
|
||||
|
||||
; Returns length of string at (HL) in A.
|
||||
; Doesn't include null termination.
|
||||
strlen:
|
||||
|
@ -126,3 +126,16 @@ You can then include that file in your "user" code, like this:
|
||||
|
||||
If you load that code at `0xa000` and call it, it will print "Hello World!" by
|
||||
using the `printstr` routine from `core.asm`.
|
||||
|
||||
## Doing the same with the BASIC shell
|
||||
|
||||
The BASIC shell also has the capacity to load code from serial console but its
|
||||
semantic is a bit different from the regular shell. Instead of peeking and
|
||||
poking, you use `getc` to send data and then `putc` to send the same data back
|
||||
for verification. Then, you can use `poke` to commit it to memory.
|
||||
|
||||
There's an upload tool that use these commands and it's `uploadb.py`. It is
|
||||
invoked with the same arguments as `upload.py`.
|
||||
|
||||
Once your code is uploaded, you will call it with BASIC's `usr` command. See
|
||||
BASIC's README for more details.
|
||||
|
67
tools/uploadb.py
Executable file
67
tools/uploadb.py
Executable file
@ -0,0 +1,67 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# Push specified file to specified device **running the BASIC shell** and verify
|
||||
# that the sent contents is correct.
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import sys
|
||||
|
||||
def sendcmd(fd, cmd):
|
||||
# The serial link echoes back all typed characters and expects us to read
|
||||
# them. We have to send each char one at a time.
|
||||
if isinstance(cmd, str):
|
||||
cmd = cmd.encode()
|
||||
for c in cmd:
|
||||
os.write(fd, bytes([c]))
|
||||
os.read(fd, 1)
|
||||
os.write(fd, b'\n')
|
||||
os.read(fd, 2) # sends back \r\n
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('device')
|
||||
parser.add_argument('memptr')
|
||||
parser.add_argument('filename')
|
||||
args = parser.parse_args()
|
||||
|
||||
try:
|
||||
memptr = int('0x' + args.memptr, 0)
|
||||
except ValueError:
|
||||
print("memptr are has to be hexadecimal without prefix.")
|
||||
return 1
|
||||
if memptr >= 0x10000:
|
||||
print("memptr out of range.")
|
||||
return 1
|
||||
maxsize = 0x10000 - memptr
|
||||
st = os.stat(args.filename)
|
||||
if st.st_size > maxsize:
|
||||
print("File too big. 0x{:04x} bytes max".format(maxsize))
|
||||
return 1
|
||||
fd = os.open(args.device, os.O_RDWR)
|
||||
with open(args.filename, 'rb') as fp:
|
||||
fcontents = fp.read()
|
||||
sendcmd(fd, f'm=0x{memptr:04x}')
|
||||
os.read(fd, 2) # read prompt
|
||||
|
||||
for i, c in enumerate(fcontents):
|
||||
c = bytes([c])
|
||||
sendcmd(fd, 'getc')
|
||||
os.write(fd, c)
|
||||
os.read(fd, 2) # read prompt
|
||||
sendcmd(fd, 'putc a')
|
||||
r = os.read(fd, 1) # putc result
|
||||
os.read(fd, 2) # read prompt
|
||||
if r != c:
|
||||
print(f"Mismatch at byte {i}! {c} != {r}")
|
||||
sendcmd(fd, 'poke m a')
|
||||
os.read(fd, 2) # read prompt
|
||||
sendcmd(fd, 'm=m+1')
|
||||
os.read(fd, 2) # read prompt
|
||||
print("Done!")
|
||||
os.close(fd)
|
||||
return 0
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main())
|
Loading…
Reference in New Issue
Block a user