1
0
mirror of https://github.com/hsoft/collapseos.git synced 2024-11-02 22:10:56 +11:00

Compare commits

..

No commits in common. "572e3566eb6db088c6d320444027a98bf2a7c260" and "871b06fecf2623110c0e61cac1d38a151f3d493b" have entirely different histories.

7 changed files with 44 additions and 161 deletions

View File

@ -149,11 +149,6 @@ 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.

View File

@ -26,8 +26,6 @@ basGETB:
call blkGetB
ret nz
ld (VAR_TBL), a
xor a
ld (VAR_TBL+1), a
ret
basPUTB:
@ -38,12 +36,12 @@ basPUTB:
jp blkPutB
basBLKCmds:
.db "bsel", 0
.dw basBSEL
.db "bseek", 0
.db "bsel", 0, 0
.dw basBSEEK
.db "getb", 0
.db "bseek", 0
.dw basGETB
.db "putb", 0
.db "getb", 0, 0
.dw basPUTB
.db 0xff ; end of table
.db "putb", 0, 0
.db 0xff, 0xff, 0xff ; end of table

View File

@ -127,14 +127,14 @@ basPgmHook:
ret
basFSCmds:
.db "fls", 0
.dw basFLS
.db "ldbas", 0
.db "fls", 0, 0, 0
.dw basLDBAS
.db "fopen", 0
.db "ldbas", 0
.dw basFOPEN
.db "fnew", 0
.db "fopen", 0
.dw basFNEW
.db "fdel", 0
.db "fnew", 0, 0
.dw basFDEL
.db 0xff ; end of table
.db "fdel", 0, 0
.db 0xff, 0xff, 0xff ; end of table

View File

@ -31,7 +31,7 @@ basStart:
jr basLoop
.welcome:
.db "Collapse OS", 0
.db "OK", 0
basLoop:
ld hl, .sPrompt
@ -63,18 +63,19 @@ 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
call strskip
inc hl ; point to routine
jr z, .found ; Z from strcmp
inc hl \ inc hl ; skip routine
jr z, .found
ld a, 8
call addHL
ld a, (hl)
inc a ; was it 0xff?
jr nz, .loop ; no
dec a ; unset Z
ret
cp 0xff
jr nz, .loop
jp unsetZ
.found:
dec hl \ dec hl
call intoHL
push hl \ pop ix
ret
@ -125,11 +126,16 @@ 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
@ -343,22 +349,6 @@ 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
@ -435,49 +425,42 @@ 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 "list", 0
.db "bye", 0, 0, 0
.dw basLIST
.db "run", 0
.db "list", 0, 0
.dw basRUN
.db "clear", 0
.db "run", 0, 0, 0
.dw bufInit
.db "clear", 0
; statements
basCmds2:
.db "print", 0
.dw basPRINT
.db "goto", 0
.db "print", 0
.dw basGOTO
.db "if", 0
.db "goto", 0, 0
.dw basIF
.db "input", 0
.db "if", 0, 0, 0, 0
.dw basINPUT
.db "peek", 0
.db "input", 0
.dw basPEEK
.db "poke", 0
.db "peek", 0, 0
.dw basPOKE
.db "deek", 0
.db "poke", 0, 0
.dw basDEEK
.db "doke", 0
.db "deek", 0, 0
.dw basDOKE
.db "out", 0
.db "doke", 0, 0
.dw basOUT
.db "in", 0
.db "out", 0, 0, 0
.dw basIN
.db "getc", 0
.dw basGETC
.db "putc", 0
.dw basPUTC
.db "sleep", 0
.db "in", 0, 0, 0, 0
.dw basSLEEP
.db "addr", 0
.db "sleep", 0
.dw basADDR
.db "usr", 0
.db "addr", 0, 0
.dw basUSR
.db 0xff ; end of table
.db "usr", 0, 0, 0
.db 0xff, 0xff, 0xff ; end of table

View File

@ -52,19 +52,6 @@ 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:

View File

@ -126,16 +126,3 @@ 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.

View File

@ -1,67 +0,0 @@
#!/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())