2019-11-15 15:37:49 -05:00
|
|
|
; Last check:
|
|
|
|
; Kernel size: 0x619
|
|
|
|
; Kernel RAM usage: 0x66
|
|
|
|
; Shell size: 0x411
|
|
|
|
; Shell RAM usage: 0x11
|
|
|
|
|
|
|
|
.inc "blkdev.h"
|
|
|
|
.inc "fs.h"
|
|
|
|
.inc "err.h"
|
|
|
|
.inc "ascii.h"
|
2019-05-20 07:29:19 -04:00
|
|
|
.equ RAMSTART 0x4000
|
2019-11-15 15:37:49 -05:00
|
|
|
; 0x100 - 0x66 gives us a nice space for the stack.
|
|
|
|
.equ KERNEL_RAMEND 0x4100
|
|
|
|
.equ SHELL_CODE 0x0700
|
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 upcase
|
|
|
|
jp findchar
|
2019-11-15 15:37:49 -05:00
|
|
|
jp blkSelPtr
|
2019-06-03 08:32:25 -04:00
|
|
|
jp blkSel
|
2019-06-04 20:45:01 -04:00
|
|
|
jp blkSet
|
2019-11-15 15:37:49 -05:00
|
|
|
jp blkSeek
|
|
|
|
jp blkTell
|
|
|
|
jp blkGetB
|
|
|
|
jp blkPutB
|
2019-06-03 08:32:25 -04:00
|
|
|
jp fsFindFN
|
|
|
|
jp fsOpen
|
2019-10-30 16:59:35 -04:00
|
|
|
jp fsGetB
|
|
|
|
jp fsPutB
|
2019-07-21 11:39:00 -04:00
|
|
|
jp fsSetSize
|
2019-11-15 15:37:49 -05:00
|
|
|
jp fsOn
|
|
|
|
jp fsIter
|
|
|
|
jp fsAlloc
|
|
|
|
jp fsDel
|
|
|
|
jp fsHandle
|
2019-05-31 14:50:43 -04:00
|
|
|
jp printstr
|
2019-11-15 15:37:49 -05:00
|
|
|
jp printnstr
|
2019-10-30 16:59:35 -04:00
|
|
|
jp _blkGetB
|
|
|
|
jp _blkPutB
|
2019-06-04 11:53:02 -04:00
|
|
|
jp _blkSeek
|
|
|
|
jp _blkTell
|
2019-07-13 09:57:37 -04:00
|
|
|
jp printcrlf
|
2019-11-15 15:37:49 -05:00
|
|
|
jp stdioGetC
|
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"
|
2019-11-14 09:55:31 -05:00
|
|
|
.inc "str.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-10-30 16:59:35 -04:00
|
|
|
.dw fsdevGetB, fsdevPutB
|
|
|
|
.dw stdoutGetB, stdoutPutB
|
|
|
|
.dw stdinGetB, stdinPutB
|
|
|
|
.dw mmapGetB, mmapPutB
|
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-11-04 09:55:12 -05:00
|
|
|
.equ STDIO_GETC emulGetC
|
|
|
|
.equ STDIO_PUTC emulPutC
|
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
|
|
|
|
|
|
|
init:
|
|
|
|
di
|
|
|
|
; setup stack
|
2019-11-15 15:37:49 -05:00
|
|
|
ld sp, KERNEL_RAMEND
|
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
|
2019-11-15 15:37:49 -05:00
|
|
|
call SHELL_CODE
|
2019-05-09 12:58:41 -04:00
|
|
|
|
2019-10-31 18:49:02 -04:00
|
|
|
emulGetC:
|
2019-05-09 12:58:41 -04:00
|
|
|
; Blocks until a char is returned
|
|
|
|
in a, (STDIO_PORT)
|
|
|
|
cp a ; ensure Z
|
|
|
|
ret
|
|
|
|
|
2019-10-31 18:49:02 -04:00
|
|
|
emulPutC:
|
2019-05-09 12:58:41 -04:00
|
|
|
out (STDIO_PORT), a
|
|
|
|
ret
|
|
|
|
|
2019-10-30 16:59:35 -04:00
|
|
|
fsdevGetB:
|
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
|
|
|
|
|
2019-10-30 16:59:35 -04:00
|
|
|
fsdevPutB:
|
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
|
|
|
|
|
2019-10-30 16:59:35 -04:00
|
|
|
stdoutGetB:
|
2019-06-02 10:18:03 -04:00
|
|
|
ld ix, STDOUT_HANDLE
|
2019-10-30 16:59:35 -04:00
|
|
|
jp fsGetB
|
2019-05-12 15:38:58 -04:00
|
|
|
|
2019-10-30 16:59:35 -04:00
|
|
|
stdoutPutB:
|
2019-06-02 10:18:03 -04:00
|
|
|
ld ix, STDOUT_HANDLE
|
2019-10-30 16:59:35 -04:00
|
|
|
jp fsPutB
|
2019-05-12 15:38:58 -04:00
|
|
|
|
|
|
|
.equ STDIN_HANDLE FS_HANDLES+FS_HANDLE_SIZE
|
|
|
|
|
2019-10-30 16:59:35 -04:00
|
|
|
stdinGetB:
|
2019-06-02 10:18:03 -04:00
|
|
|
ld ix, STDIN_HANDLE
|
2019-10-30 16:59:35 -04:00
|
|
|
jp fsGetB
|
2019-05-12 15:38:58 -04:00
|
|
|
|
2019-10-30 16:59:35 -04:00
|
|
|
stdinPutB:
|
2019-06-02 10:18:03 -04:00
|
|
|
ld ix, STDIN_HANDLE
|
2019-10-30 16:59:35 -04:00
|
|
|
jp fsPutB
|
2019-05-12 15:38:58 -04:00
|
|
|
|
2019-11-15 15:37:49 -05:00
|
|
|
.fill SHELL_CODE-$
|
|
|
|
.bin "shell.bin"
|