1
0
mirror of https://github.com/hsoft/collapseos.git synced 2024-11-03 00:30:55 +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` **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. 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 **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 expression. A "unit" depends on the CPU clock speed. At 4MHz, it is roughly 8
microseconds. microseconds.

View File

@ -26,8 +26,6 @@ basGETB:
call blkGetB call blkGetB
ret nz ret nz
ld (VAR_TBL), a ld (VAR_TBL), a
xor a
ld (VAR_TBL+1), a
ret ret
basPUTB: basPUTB:
@ -38,12 +36,12 @@ basPUTB:
jp blkPutB jp blkPutB
basBLKCmds: basBLKCmds:
.db "bsel", 0
.dw basBSEL .dw basBSEL
.db "bseek", 0 .db "bsel", 0, 0
.dw basBSEEK .dw basBSEEK
.db "getb", 0 .db "bseek", 0
.dw basGETB .dw basGETB
.db "putb", 0 .db "getb", 0, 0
.dw basPUTB .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 ret
basFSCmds: basFSCmds:
.db "fls", 0
.dw basFLS .dw basFLS
.db "ldbas", 0 .db "fls", 0, 0, 0
.dw basLDBAS .dw basLDBAS
.db "fopen", 0 .db "ldbas", 0
.dw basFOPEN .dw basFOPEN
.db "fnew", 0 .db "fopen", 0
.dw basFNEW .dw basFNEW
.db "fdel", 0 .db "fnew", 0, 0
.dw basFDEL .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 jr basLoop
.welcome: .welcome:
.db "Collapse OS", 0 .db "OK", 0
basLoop: basLoop:
ld hl, .sPrompt ld hl, .sPrompt
@ -63,18 +63,19 @@ basLoop:
; Destroys HL. ; Destroys HL.
; Z is set if found, unset otherwise. ; Z is set if found, unset otherwise.
basFindCmd: basFindCmd:
; cmd table starts with routine pointer, skip
inc hl \ inc hl
.loop: .loop:
call strcmp call strcmp
call strskip jr z, .found
inc hl ; point to routine ld a, 8
jr z, .found ; Z from strcmp call addHL
inc hl \ inc hl ; skip routine
ld a, (hl) ld a, (hl)
inc a ; was it 0xff? cp 0xff
jr nz, .loop ; no jr nz, .loop
dec a ; unset Z jp unsetZ
ret
.found: .found:
dec hl \ dec hl
call intoHL call intoHL
push hl \ pop ix push hl \ pop ix
ret ret
@ -125,11 +126,16 @@ basERR:
; ;
; Commands are expected to set Z on success. ; Commands are expected to set Z on success.
basBYE: basBYE:
ld hl, .sBye
call printstr
call printcrlf
; To quit the loop, let's return the stack to its initial value and ; To quit the loop, let's return the stack to its initial value and
; then return. ; then return.
xor a xor a
ld sp, (BAS_INITSP) ld sp, (BAS_INITSP)
ret ret
.sBye:
.db "Goodbye!", 0
basLIST: basLIST:
call bufFirst call bufFirst
@ -343,22 +349,6 @@ basIN:
; Z set from rdExpr ; Z set from rdExpr
ret 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: basSLEEP:
call rdExpr call rdExpr
ret nz ret nz
@ -435,49 +425,42 @@ basR2Var: ; Just send reg to vars. Used in basPgmHook
cp a ; USR never errors out cp a ; USR never errors out
ret ret
; Command table format: Null-terminated string followed by a 2-byte routine
; pointer.
; direct only ; direct only
basCmds1: basCmds1:
.db "bye", 0
.dw basBYE .dw basBYE
.db "list", 0 .db "bye", 0, 0, 0
.dw basLIST .dw basLIST
.db "run", 0 .db "list", 0, 0
.dw basRUN .dw basRUN
.db "clear", 0 .db "run", 0, 0, 0
.dw bufInit .dw bufInit
.db "clear", 0
; statements ; statements
basCmds2: basCmds2:
.db "print", 0
.dw basPRINT .dw basPRINT
.db "goto", 0 .db "print", 0
.dw basGOTO .dw basGOTO
.db "if", 0 .db "goto", 0, 0
.dw basIF .dw basIF
.db "input", 0 .db "if", 0, 0, 0, 0
.dw basINPUT .dw basINPUT
.db "peek", 0 .db "input", 0
.dw basPEEK .dw basPEEK
.db "poke", 0 .db "peek", 0, 0
.dw basPOKE .dw basPOKE
.db "deek", 0 .db "poke", 0, 0
.dw basDEEK .dw basDEEK
.db "doke", 0 .db "deek", 0, 0
.dw basDOKE .dw basDOKE
.db "out", 0 .db "doke", 0, 0
.dw basOUT .dw basOUT
.db "in", 0 .db "out", 0, 0, 0
.dw basIN .dw basIN
.db "getc", 0 .db "in", 0, 0, 0, 0
.dw basGETC
.db "putc", 0
.dw basPUTC
.db "sleep", 0
.dw basSLEEP .dw basSLEEP
.db "addr", 0 .db "sleep", 0
.dw basADDR .dw basADDR
.db "usr", 0 .db "addr", 0, 0
.dw basUSR .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) ; early, set otherwise)
ret 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. ; Returns length of string at (HL) in A.
; Doesn't include null termination. ; Doesn't include null termination.
strlen: 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 If you load that code at `0xa000` and call it, it will print "Hello World!" by
using the `printstr` routine from `core.asm`. 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())