2019-05-09 12:58:41 -04:00
|
|
|
; named shell_.asm to avoid infinite include loop.
|
2019-05-20 07:29:19 -04:00
|
|
|
.equ RAMSTART 0x4000
|
2019-06-03 11:15:07 -04:00
|
|
|
; kernel ram is well under 0x100 bytes. We're giving us 0x200 bytes so that we
|
|
|
|
; never worry about the stack.
|
|
|
|
.equ KERNEL_RAMEND 0x4200
|
|
|
|
.equ USERCODE KERNEL_RAMEND
|
2019-05-20 07:29:19 -04:00
|
|
|
.equ STDIO_PORT 0x00
|
|
|
|
.equ FS_DATA_PORT 0x01
|
2019-06-04 11:53:02 -04:00
|
|
|
.equ FS_ADDR_PORT 0x02
|
2019-05-09 12:58:41 -04:00
|
|
|
|
2019-05-20 07:29:19 -04:00
|
|
|
jp init
|
2019-05-09 12:58:41 -04:00
|
|
|
|
2019-05-31 14:50:43 -04:00
|
|
|
; *** JUMP TABLE ***
|
2019-06-03 08:32:25 -04:00
|
|
|
jp strncmp
|
|
|
|
jp addDE
|
|
|
|
jp addHL
|
|
|
|
jp upcase
|
|
|
|
jp unsetZ
|
|
|
|
jp intoDE
|
|
|
|
jp intoHL
|
|
|
|
jp writeHLinDE
|
|
|
|
jp findchar
|
|
|
|
jp parseHex
|
|
|
|
jp parseHexPair
|
|
|
|
jp blkSel
|
2019-06-04 20:45:01 -04:00
|
|
|
jp blkSet
|
2019-06-03 08:32:25 -04:00
|
|
|
jp fsFindFN
|
|
|
|
jp fsOpen
|
|
|
|
jp fsGetC
|
2019-07-20 19:35:19 -04:00
|
|
|
jp fsPutC
|
2019-07-21 11:39:00 -04:00
|
|
|
jp fsSetSize
|
2019-06-03 08:32:25 -04:00
|
|
|
jp cpHLDE
|
|
|
|
jp parseArgs
|
2019-05-31 14:50:43 -04:00
|
|
|
jp printstr
|
2019-06-04 11:53:02 -04:00
|
|
|
jp _blkGetC
|
|
|
|
jp _blkPutC
|
|
|
|
jp _blkSeek
|
|
|
|
jp _blkTell
|
2019-07-13 09:57:37 -04:00
|
|
|
jp printcrlf
|
2019-07-13 14:01:20 -04:00
|
|
|
jp stdioPutC
|
2019-07-14 17:29:00 -04:00
|
|
|
jp stdioReadLine
|
2019-05-31 14:50:43 -04:00
|
|
|
|
2019-10-06 14:32:23 -04:00
|
|
|
.inc "core.asm"
|
|
|
|
.inc "err.h"
|
|
|
|
.inc "parse.asm"
|
2019-05-09 12:58:41 -04:00
|
|
|
|
2019-05-20 07:29:19 -04:00
|
|
|
.equ BLOCKDEV_RAMSTART RAMSTART
|
2019-06-03 11:15:07 -04:00
|
|
|
.equ BLOCKDEV_COUNT 4
|
2019-10-06 14:32:23 -04:00
|
|
|
.inc "blockdev.asm"
|
2019-05-09 12:58:41 -04:00
|
|
|
; List of devices
|
2019-06-04 11:53:02 -04:00
|
|
|
.dw fsdevGetC, fsdevPutC
|
|
|
|
.dw stdoutGetC, stdoutPutC
|
|
|
|
.dw stdinGetC, stdinPutC
|
|
|
|
.dw mmapGetC, mmapPutC
|
2019-05-09 12:58:41 -04:00
|
|
|
|
|
|
|
|
2019-06-03 11:15:07 -04:00
|
|
|
.equ MMAP_START 0xe000
|
2019-10-06 14:32:23 -04:00
|
|
|
.inc "mmap.asm"
|
2019-06-03 11:15:07 -04:00
|
|
|
|
2019-06-04 11:53:02 -04:00
|
|
|
.equ STDIO_RAMSTART BLOCKDEV_RAMEND
|
2019-10-06 14:32:23 -04:00
|
|
|
.inc "stdio.asm"
|
2019-05-17 08:14:19 -04:00
|
|
|
|
|
|
|
.equ FS_RAMSTART STDIO_RAMEND
|
2019-05-12 11:20:31 -04:00
|
|
|
.equ FS_HANDLE_COUNT 2
|
2019-10-06 14:32:23 -04:00
|
|
|
.inc "fs.asm"
|
2019-05-12 11:20:31 -04:00
|
|
|
|
2019-05-20 07:29:19 -04:00
|
|
|
.equ SHELL_RAMSTART FS_RAMEND
|
2019-06-02 10:50:18 -04:00
|
|
|
.equ SHELL_EXTRA_CMD_COUNT 9
|
2019-10-06 14:32:23 -04:00
|
|
|
.inc "shell.asm"
|
2019-06-02 10:50:18 -04:00
|
|
|
.dw blkBselCmd, blkSeekCmd, blkLoadCmd, blkSaveCmd
|
|
|
|
.dw fsOnCmd, flsCmd, fnewCmd, fdelCmd, fopnCmd
|
2019-05-12 11:20:31 -04:00
|
|
|
|
2019-10-06 14:32:23 -04:00
|
|
|
.inc "blockdev_cmds.asm"
|
|
|
|
.inc "fs_cmds.asm"
|
2019-06-04 09:56:36 -04:00
|
|
|
|
2019-06-03 09:24:43 -04:00
|
|
|
.equ PGM_RAMSTART SHELL_RAMEND
|
2019-05-31 14:50:43 -04:00
|
|
|
.equ PGM_CODEADDR USERCODE
|
2019-10-06 14:32:23 -04:00
|
|
|
.inc "pgm.asm"
|
2019-05-31 14:50:43 -04:00
|
|
|
|
2019-06-04 09:56:36 -04:00
|
|
|
;.out PGM_RAMEND
|
2019-06-03 11:15:07 -04:00
|
|
|
|
2019-05-12 11:20:31 -04:00
|
|
|
init:
|
|
|
|
di
|
|
|
|
; setup stack
|
2019-05-31 14:50:43 -04:00
|
|
|
ld hl, KERNEL_RAMEND
|
2019-05-12 11:20:31 -04:00
|
|
|
ld sp, hl
|
2019-06-02 10:50:18 -04:00
|
|
|
ld hl, emulGetC
|
|
|
|
ld de, emulPutC
|
2019-05-17 08:14:19 -04:00
|
|
|
call stdioInit
|
2019-05-12 11:20:31 -04:00
|
|
|
call fsInit
|
2019-06-02 10:50:18 -04:00
|
|
|
ld a, 0 ; select fsdev
|
2019-06-04 09:56:36 -04:00
|
|
|
ld de, BLOCKDEV_SEL
|
2019-05-12 11:20:31 -04:00
|
|
|
call blkSel
|
|
|
|
call fsOn
|
|
|
|
call shellInit
|
2019-05-31 14:50:43 -04:00
|
|
|
ld hl, pgmShellHook
|
|
|
|
ld (SHELL_CMDHOOK), hl
|
2019-05-12 11:20:31 -04:00
|
|
|
jp shellLoop
|
2019-05-09 12:58:41 -04:00
|
|
|
|
|
|
|
emulGetC:
|
|
|
|
; Blocks until a char is returned
|
|
|
|
in a, (STDIO_PORT)
|
|
|
|
cp a ; ensure Z
|
|
|
|
ret
|
|
|
|
|
|
|
|
emulPutC:
|
|
|
|
out (STDIO_PORT), a
|
|
|
|
ret
|
|
|
|
|
2019-05-12 11:20:31 -04:00
|
|
|
fsdevGetC:
|
2019-06-04 11:53:02 -04:00
|
|
|
ld a, e
|
|
|
|
out (FS_ADDR_PORT), a
|
|
|
|
ld a, h
|
|
|
|
out (FS_ADDR_PORT), a
|
|
|
|
ld a, l
|
|
|
|
out (FS_ADDR_PORT), a
|
|
|
|
in a, (FS_ADDR_PORT)
|
|
|
|
or a
|
|
|
|
ret nz
|
2019-05-12 11:20:31 -04:00
|
|
|
in a, (FS_DATA_PORT)
|
2019-05-12 15:38:58 -04:00
|
|
|
cp a ; ensure Z
|
2019-05-12 11:20:31 -04:00
|
|
|
ret
|
|
|
|
|
|
|
|
fsdevPutC:
|
2019-05-12 15:38:58 -04:00
|
|
|
push af
|
2019-05-28 15:56:39 -04:00
|
|
|
ld a, e
|
2019-06-04 11:53:02 -04:00
|
|
|
out (FS_ADDR_PORT), a
|
|
|
|
ld a, h
|
|
|
|
out (FS_ADDR_PORT), a
|
|
|
|
ld a, l
|
|
|
|
out (FS_ADDR_PORT), a
|
|
|
|
in a, (FS_ADDR_PORT)
|
2019-06-05 19:51:19 -04:00
|
|
|
cp 2 ; only A > 1 means error
|
|
|
|
jr nc, .error ; A >= 2
|
2019-05-12 15:38:58 -04:00
|
|
|
pop af
|
2019-06-04 11:53:02 -04:00
|
|
|
out (FS_DATA_PORT), a
|
2019-06-05 16:13:15 -04:00
|
|
|
cp a ; ensure Z
|
2019-05-12 11:20:31 -04:00
|
|
|
ret
|
2019-06-04 11:53:02 -04:00
|
|
|
.error:
|
2019-05-12 15:38:58 -04:00
|
|
|
pop af
|
2019-06-04 11:53:02 -04:00
|
|
|
jp unsetZ ; returns
|
2019-05-12 15:38:58 -04:00
|
|
|
|
|
|
|
.equ STDOUT_HANDLE FS_HANDLES
|
|
|
|
|
|
|
|
stdoutGetC:
|
2019-06-02 10:18:03 -04:00
|
|
|
ld ix, STDOUT_HANDLE
|
2019-05-12 15:38:58 -04:00
|
|
|
jp fsGetC
|
|
|
|
|
|
|
|
stdoutPutC:
|
2019-06-02 10:18:03 -04:00
|
|
|
ld ix, STDOUT_HANDLE
|
2019-05-12 15:38:58 -04:00
|
|
|
jp fsPutC
|
|
|
|
|
|
|
|
.equ STDIN_HANDLE FS_HANDLES+FS_HANDLE_SIZE
|
|
|
|
|
|
|
|
stdinGetC:
|
2019-06-02 10:18:03 -04:00
|
|
|
ld ix, STDIN_HANDLE
|
2019-05-12 15:38:58 -04:00
|
|
|
jp fsGetC
|
|
|
|
|
|
|
|
stdinPutC:
|
2019-06-02 10:18:03 -04:00
|
|
|
ld ix, STDIN_HANDLE
|
2019-05-12 15:38:58 -04:00
|
|
|
jp fsPutC
|
|
|
|
|