2019-05-10 02:58:41 +10:00
|
|
|
; named shell_.asm to avoid infinite include loop.
|
2019-05-20 21:29:19 +10:00
|
|
|
.equ RAMSTART 0x4000
|
2019-06-04 01:15:07 +10: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 21:29:19 +10:00
|
|
|
.equ STDIO_PORT 0x00
|
|
|
|
.equ FS_DATA_PORT 0x01
|
2019-06-05 01:53:02 +10:00
|
|
|
.equ FS_ADDR_PORT 0x02
|
2019-05-10 02:58:41 +10:00
|
|
|
|
2019-05-20 21:29:19 +10:00
|
|
|
jp init
|
2019-05-10 02:58:41 +10:00
|
|
|
|
2019-06-01 04:50:43 +10:00
|
|
|
; *** JUMP TABLE ***
|
2019-06-03 22:32:25 +10: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-05 10:45:01 +10:00
|
|
|
jp blkSet
|
2019-06-03 22:32:25 +10:00
|
|
|
jp fsFindFN
|
|
|
|
jp fsOpen
|
|
|
|
jp fsGetC
|
|
|
|
jp cpHLDE
|
|
|
|
jp parseArgs
|
2019-06-01 04:50:43 +10:00
|
|
|
jp printstr
|
2019-06-05 01:53:02 +10:00
|
|
|
jp _blkGetC
|
|
|
|
jp _blkPutC
|
|
|
|
jp _blkSeek
|
|
|
|
jp _blkTell
|
2019-07-13 23:57:37 +10:00
|
|
|
jp printcrlf
|
|
|
|
jp stdioReadC
|
|
|
|
jp stdioGetLine
|
2019-06-01 04:50:43 +10:00
|
|
|
|
2019-05-10 02:58:41 +10:00
|
|
|
#include "core.asm"
|
2019-06-03 04:05:20 +10:00
|
|
|
#include "err.h"
|
2019-05-17 23:33:20 +10:00
|
|
|
#include "parse.asm"
|
2019-05-10 02:58:41 +10:00
|
|
|
|
2019-05-20 21:29:19 +10:00
|
|
|
.equ BLOCKDEV_RAMSTART RAMSTART
|
2019-06-04 01:15:07 +10:00
|
|
|
.equ BLOCKDEV_COUNT 4
|
2019-05-10 02:58:41 +10:00
|
|
|
#include "blockdev.asm"
|
|
|
|
; List of devices
|
2019-06-05 01:53:02 +10:00
|
|
|
.dw fsdevGetC, fsdevPutC
|
|
|
|
.dw stdoutGetC, stdoutPutC
|
|
|
|
.dw stdinGetC, stdinPutC
|
|
|
|
.dw mmapGetC, mmapPutC
|
2019-05-10 02:58:41 +10:00
|
|
|
|
|
|
|
|
2019-06-04 01:15:07 +10:00
|
|
|
.equ MMAP_START 0xe000
|
|
|
|
#include "mmap.asm"
|
|
|
|
|
2019-06-05 01:53:02 +10:00
|
|
|
.equ STDIO_RAMSTART BLOCKDEV_RAMEND
|
2019-05-17 22:14:19 +10:00
|
|
|
#include "stdio.asm"
|
|
|
|
|
|
|
|
.equ FS_RAMSTART STDIO_RAMEND
|
2019-05-13 01:20:31 +10:00
|
|
|
.equ FS_HANDLE_COUNT 2
|
|
|
|
#include "fs.asm"
|
|
|
|
|
2019-05-20 21:29:19 +10:00
|
|
|
.equ SHELL_RAMSTART FS_RAMEND
|
2019-06-03 00:50:18 +10:00
|
|
|
.equ SHELL_EXTRA_CMD_COUNT 9
|
2019-05-10 02:58:41 +10:00
|
|
|
#include "shell.asm"
|
2019-06-03 00:50:18 +10:00
|
|
|
.dw blkBselCmd, blkSeekCmd, blkLoadCmd, blkSaveCmd
|
|
|
|
.dw fsOnCmd, flsCmd, fnewCmd, fdelCmd, fopnCmd
|
2019-05-13 01:20:31 +10:00
|
|
|
|
2019-06-04 23:56:36 +10:00
|
|
|
#include "blockdev_cmds.asm"
|
|
|
|
#include "fs_cmds.asm"
|
|
|
|
|
2019-06-03 23:24:43 +10:00
|
|
|
.equ PGM_RAMSTART SHELL_RAMEND
|
2019-06-01 04:50:43 +10:00
|
|
|
.equ PGM_CODEADDR USERCODE
|
|
|
|
#include "pgm.asm"
|
|
|
|
|
2019-06-04 23:56:36 +10:00
|
|
|
;.out PGM_RAMEND
|
2019-06-04 01:15:07 +10:00
|
|
|
|
2019-05-13 01:20:31 +10:00
|
|
|
init:
|
|
|
|
di
|
|
|
|
; setup stack
|
2019-06-01 04:50:43 +10:00
|
|
|
ld hl, KERNEL_RAMEND
|
2019-05-13 01:20:31 +10:00
|
|
|
ld sp, hl
|
2019-06-03 00:50:18 +10:00
|
|
|
ld hl, emulGetC
|
|
|
|
ld de, emulPutC
|
2019-05-17 22:14:19 +10:00
|
|
|
call stdioInit
|
2019-05-13 01:20:31 +10:00
|
|
|
call fsInit
|
2019-06-03 00:50:18 +10:00
|
|
|
ld a, 0 ; select fsdev
|
2019-06-04 23:56:36 +10:00
|
|
|
ld de, BLOCKDEV_SEL
|
2019-05-13 01:20:31 +10:00
|
|
|
call blkSel
|
|
|
|
call fsOn
|
|
|
|
call shellInit
|
2019-06-01 04:50:43 +10:00
|
|
|
ld hl, pgmShellHook
|
|
|
|
ld (SHELL_CMDHOOK), hl
|
2019-05-13 01:20:31 +10:00
|
|
|
jp shellLoop
|
2019-05-10 02:58:41 +10: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-13 01:20:31 +10:00
|
|
|
fsdevGetC:
|
2019-06-05 01:53:02 +10: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-13 01:20:31 +10:00
|
|
|
in a, (FS_DATA_PORT)
|
2019-05-13 05:38:58 +10:00
|
|
|
cp a ; ensure Z
|
2019-05-13 01:20:31 +10:00
|
|
|
ret
|
|
|
|
|
|
|
|
fsdevPutC:
|
2019-05-13 05:38:58 +10:00
|
|
|
push af
|
2019-05-29 05:56:39 +10:00
|
|
|
ld a, e
|
2019-06-05 01:53:02 +10: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-06 09:51:19 +10:00
|
|
|
cp 2 ; only A > 1 means error
|
|
|
|
jr nc, .error ; A >= 2
|
2019-05-13 05:38:58 +10:00
|
|
|
pop af
|
2019-06-05 01:53:02 +10:00
|
|
|
out (FS_DATA_PORT), a
|
2019-06-06 06:13:15 +10:00
|
|
|
cp a ; ensure Z
|
2019-05-13 01:20:31 +10:00
|
|
|
ret
|
2019-06-05 01:53:02 +10:00
|
|
|
.error:
|
2019-05-13 05:38:58 +10:00
|
|
|
pop af
|
2019-06-05 01:53:02 +10:00
|
|
|
jp unsetZ ; returns
|
2019-05-13 05:38:58 +10:00
|
|
|
|
|
|
|
.equ STDOUT_HANDLE FS_HANDLES
|
|
|
|
|
|
|
|
stdoutGetC:
|
2019-06-03 00:18:03 +10:00
|
|
|
ld ix, STDOUT_HANDLE
|
2019-05-13 05:38:58 +10:00
|
|
|
jp fsGetC
|
|
|
|
|
|
|
|
stdoutPutC:
|
2019-06-03 00:18:03 +10:00
|
|
|
ld ix, STDOUT_HANDLE
|
2019-05-13 05:38:58 +10:00
|
|
|
jp fsPutC
|
|
|
|
|
|
|
|
.equ STDIN_HANDLE FS_HANDLES+FS_HANDLE_SIZE
|
|
|
|
|
|
|
|
stdinGetC:
|
2019-06-03 00:18:03 +10:00
|
|
|
ld ix, STDIN_HANDLE
|
2019-05-13 05:38:58 +10:00
|
|
|
jp fsGetC
|
|
|
|
|
|
|
|
stdinPutC:
|
2019-06-03 00:18:03 +10:00
|
|
|
ld ix, STDIN_HANDLE
|
2019-05-13 05:38:58 +10:00
|
|
|
jp fsPutC
|
|
|
|
|