mirror of
https://github.com/hsoft/collapseos.git
synced 2024-11-02 20:20:55 +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`
|
**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.
|
||||||
|
@ -26,6 +26,8 @@ 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:
|
||||||
@ -36,12 +38,12 @@ basPUTB:
|
|||||||
jp blkPutB
|
jp blkPutB
|
||||||
|
|
||||||
basBLKCmds:
|
basBLKCmds:
|
||||||
|
.db "bsel", 0
|
||||||
.dw basBSEL
|
.dw basBSEL
|
||||||
.db "bsel", 0, 0
|
|
||||||
.dw basBSEEK
|
|
||||||
.db "bseek", 0
|
.db "bseek", 0
|
||||||
|
.dw basBSEEK
|
||||||
|
.db "getb", 0
|
||||||
.dw basGETB
|
.dw basGETB
|
||||||
.db "getb", 0, 0
|
.db "putb", 0
|
||||||
.dw basPUTB
|
.dw basPUTB
|
||||||
.db "putb", 0, 0
|
.db 0xff ; end of table
|
||||||
.db 0xff, 0xff, 0xff ; end of table
|
|
||||||
|
@ -127,14 +127,14 @@ basPgmHook:
|
|||||||
ret
|
ret
|
||||||
|
|
||||||
basFSCmds:
|
basFSCmds:
|
||||||
|
.db "fls", 0
|
||||||
.dw basFLS
|
.dw basFLS
|
||||||
.db "fls", 0, 0, 0
|
|
||||||
.dw basLDBAS
|
|
||||||
.db "ldbas", 0
|
.db "ldbas", 0
|
||||||
.dw basFOPEN
|
.dw basLDBAS
|
||||||
.db "fopen", 0
|
.db "fopen", 0
|
||||||
|
.dw basFOPEN
|
||||||
|
.db "fnew", 0
|
||||||
.dw basFNEW
|
.dw basFNEW
|
||||||
.db "fnew", 0, 0
|
.db "fdel", 0
|
||||||
.dw basFDEL
|
.dw basFDEL
|
||||||
.db "fdel", 0, 0
|
.db 0xff ; end of table
|
||||||
.db 0xff, 0xff, 0xff ; end of table
|
|
||||||
|
@ -31,7 +31,7 @@ basStart:
|
|||||||
jr basLoop
|
jr basLoop
|
||||||
|
|
||||||
.welcome:
|
.welcome:
|
||||||
.db "OK", 0
|
.db "Collapse OS", 0
|
||||||
|
|
||||||
basLoop:
|
basLoop:
|
||||||
ld hl, .sPrompt
|
ld hl, .sPrompt
|
||||||
@ -63,19 +63,18 @@ 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
|
||||||
jr z, .found
|
call strskip
|
||||||
ld a, 8
|
inc hl ; point to routine
|
||||||
call addHL
|
jr z, .found ; Z from strcmp
|
||||||
|
inc hl \ inc hl ; skip routine
|
||||||
ld a, (hl)
|
ld a, (hl)
|
||||||
cp 0xff
|
inc a ; was it 0xff?
|
||||||
jr nz, .loop
|
jr nz, .loop ; no
|
||||||
jp unsetZ
|
dec a ; unset Z
|
||||||
|
ret
|
||||||
.found:
|
.found:
|
||||||
dec hl \ dec hl
|
|
||||||
call intoHL
|
call intoHL
|
||||||
push hl \ pop ix
|
push hl \ pop ix
|
||||||
ret
|
ret
|
||||||
@ -126,16 +125,11 @@ 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
|
||||||
@ -349,6 +343,22 @@ 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
|
||||||
@ -425,42 +435,49 @@ 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 "bye", 0, 0, 0
|
.db "list", 0
|
||||||
.dw basLIST
|
.dw basLIST
|
||||||
.db "list", 0, 0
|
.db "run", 0
|
||||||
.dw basRUN
|
.dw basRUN
|
||||||
.db "run", 0, 0, 0
|
|
||||||
.dw bufInit
|
|
||||||
.db "clear", 0
|
.db "clear", 0
|
||||||
|
.dw bufInit
|
||||||
; statements
|
; statements
|
||||||
basCmds2:
|
basCmds2:
|
||||||
.dw basPRINT
|
|
||||||
.db "print", 0
|
.db "print", 0
|
||||||
|
.dw basPRINT
|
||||||
|
.db "goto", 0
|
||||||
.dw basGOTO
|
.dw basGOTO
|
||||||
.db "goto", 0, 0
|
.db "if", 0
|
||||||
.dw basIF
|
.dw basIF
|
||||||
.db "if", 0, 0, 0, 0
|
|
||||||
.dw basINPUT
|
|
||||||
.db "input", 0
|
.db "input", 0
|
||||||
|
.dw basINPUT
|
||||||
|
.db "peek", 0
|
||||||
.dw basPEEK
|
.dw basPEEK
|
||||||
.db "peek", 0, 0
|
.db "poke", 0
|
||||||
.dw basPOKE
|
.dw basPOKE
|
||||||
.db "poke", 0, 0
|
.db "deek", 0
|
||||||
.dw basDEEK
|
.dw basDEEK
|
||||||
.db "deek", 0, 0
|
.db "doke", 0
|
||||||
.dw basDOKE
|
.dw basDOKE
|
||||||
.db "doke", 0, 0
|
.db "out", 0
|
||||||
.dw basOUT
|
.dw basOUT
|
||||||
.db "out", 0, 0, 0
|
.db "in", 0
|
||||||
.dw basIN
|
.dw basIN
|
||||||
.db "in", 0, 0, 0, 0
|
.db "getc", 0
|
||||||
.dw basSLEEP
|
.dw basGETC
|
||||||
|
.db "putc", 0
|
||||||
|
.dw basPUTC
|
||||||
.db "sleep", 0
|
.db "sleep", 0
|
||||||
|
.dw basSLEEP
|
||||||
|
.db "addr", 0
|
||||||
.dw basADDR
|
.dw basADDR
|
||||||
.db "addr", 0, 0
|
.db "usr", 0
|
||||||
.dw basUSR
|
.dw basUSR
|
||||||
.db "usr", 0, 0, 0
|
.db 0xff ; end of table
|
||||||
.db 0xff, 0xff, 0xff ; end of table
|
|
||||||
|
@ -52,6 +52,19 @@ 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:
|
||||||
|
@ -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
|
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.
|
||||||
|
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