2019-05-10 04:09:40 +10:00
|
|
|
; Glue code for the emulated environment
|
2019-05-11 08:20:43 +10:00
|
|
|
.equ RAMSTART 0x4000
|
2019-05-20 05:03:34 +10:00
|
|
|
.equ USER_CODE 0x4800
|
2019-05-10 04:09:40 +10:00
|
|
|
.equ STDIO_PORT 0x00
|
2019-05-16 03:41:56 +10:00
|
|
|
.equ STDIN_SEEK 0x01
|
2019-05-17 03:23:23 +10:00
|
|
|
.equ FS_DATA_PORT 0x02
|
|
|
|
.equ FS_SEEK_PORT 0x03
|
2019-05-18 03:22:45 +10:00
|
|
|
.equ STDERR_PORT 0x04
|
2019-11-16 07:37:49 +11:00
|
|
|
.inc "err.h"
|
|
|
|
.inc "ascii.h"
|
|
|
|
.inc "blkdev.h"
|
|
|
|
.inc "fs.h"
|
2019-05-10 04:09:40 +10:00
|
|
|
|
2019-05-20 02:57:59 +10:00
|
|
|
jp init ; 3 bytes
|
|
|
|
; *** JUMP TABLE ***
|
2019-06-01 01:12:29 +10:00
|
|
|
jp strncmp
|
|
|
|
jp upcase
|
|
|
|
jp findchar
|
|
|
|
jp blkSel
|
2019-06-05 10:45:01 +10:00
|
|
|
jp blkSet
|
2019-06-01 01:12:29 +10:00
|
|
|
jp fsFindFN
|
|
|
|
jp fsOpen
|
2019-10-31 07:59:35 +11:00
|
|
|
jp fsGetB
|
|
|
|
jp _blkGetB
|
|
|
|
jp _blkPutB
|
2019-06-05 01:53:02 +10:00
|
|
|
jp _blkSeek
|
|
|
|
jp _blkTell
|
2019-06-20 01:42:39 +10:00
|
|
|
jp printstr
|
2019-05-10 04:09:40 +10:00
|
|
|
|
2019-10-07 05:32:23 +11:00
|
|
|
.inc "core.asm"
|
2019-11-15 01:55:31 +11:00
|
|
|
.inc "str.asm"
|
2019-05-17 03:23:23 +10:00
|
|
|
.equ BLOCKDEV_RAMSTART RAMSTART
|
|
|
|
.equ BLOCKDEV_COUNT 3
|
2019-10-07 05:32:23 +11:00
|
|
|
.inc "blockdev.asm"
|
2019-05-17 03:23:23 +10:00
|
|
|
; List of devices
|
2019-10-31 07:59:35 +11:00
|
|
|
.dw emulGetB, unsetZ
|
|
|
|
.dw unsetZ, emulPutB
|
|
|
|
.dw fsdevGetB, fsdevPutB
|
2019-05-17 03:23:23 +10:00
|
|
|
|
2019-06-20 01:42:39 +10:00
|
|
|
.equ STDIO_RAMSTART BLOCKDEV_RAMEND
|
2019-11-05 01:55:12 +11:00
|
|
|
.equ STDIO_GETC noop
|
|
|
|
.equ STDIO_PUTC stderrPutC
|
2019-10-07 05:32:23 +11:00
|
|
|
.inc "stdio.asm"
|
2019-06-20 01:42:39 +10:00
|
|
|
|
|
|
|
.equ FS_RAMSTART STDIO_RAMEND
|
2019-05-17 03:23:23 +10:00
|
|
|
.equ FS_HANDLE_COUNT 0
|
2019-10-07 05:32:23 +11:00
|
|
|
.inc "fs.asm"
|
2019-05-17 03:23:23 +10:00
|
|
|
|
2019-05-10 04:09:40 +10:00
|
|
|
init:
|
|
|
|
di
|
2019-05-19 23:14:40 +10:00
|
|
|
ld hl, 0xffff
|
2019-05-10 04:09:40 +10:00
|
|
|
ld sp, hl
|
2019-05-17 03:23:23 +10:00
|
|
|
ld a, 2 ; select fsdev
|
2019-06-04 23:56:36 +10:00
|
|
|
ld de, BLOCKDEV_SEL
|
2019-05-17 03:23:23 +10:00
|
|
|
call blkSel
|
|
|
|
call fsOn
|
2019-11-16 01:57:53 +11:00
|
|
|
; There's a special understanding between zasm.c and this unit: The
|
|
|
|
; addresses 0xff00 and 0xff01 contain the two ascii chars to send to
|
|
|
|
; zasm as the 3rd argument.
|
|
|
|
ld a, (0xff00)
|
|
|
|
ld (.zasmArgs+4), a
|
|
|
|
ld a, (0xff01)
|
|
|
|
ld (.zasmArgs+5), a
|
2019-06-03 04:05:20 +10:00
|
|
|
ld hl, .zasmArgs
|
2019-05-20 02:57:59 +10:00
|
|
|
call USER_CODE
|
2019-05-10 04:09:40 +10:00
|
|
|
; signal the emulator we're done
|
|
|
|
halt
|
|
|
|
|
2019-06-03 04:05:20 +10:00
|
|
|
.zasmArgs:
|
2019-11-16 01:57:53 +11:00
|
|
|
.db "0 1 XX", 0
|
2019-06-03 04:05:20 +10:00
|
|
|
|
2019-05-18 03:22:45 +10:00
|
|
|
; *** I/O ***
|
2019-10-31 07:59:35 +11:00
|
|
|
emulGetB:
|
2019-06-05 01:53:02 +10:00
|
|
|
; the STDIN_SEEK port works by poking it twice. First poke is for high
|
|
|
|
; byte, second poke is for low one.
|
|
|
|
ld a, h
|
|
|
|
out (STDIN_SEEK), a
|
|
|
|
ld a, l
|
|
|
|
out (STDIN_SEEK), a
|
2019-05-10 05:36:03 +10:00
|
|
|
in a, (STDIO_PORT)
|
|
|
|
or a ; cp 0
|
|
|
|
jr z, .eof
|
|
|
|
cp a ; ensure z
|
|
|
|
ret
|
|
|
|
.eof:
|
2019-11-12 12:21:13 +11:00
|
|
|
jp unsetZ
|
2019-05-10 05:36:03 +10:00
|
|
|
|
2019-10-31 07:59:35 +11:00
|
|
|
emulPutB:
|
2019-05-10 05:36:03 +10:00
|
|
|
out (STDIO_PORT), a
|
2019-06-16 06:48:30 +10:00
|
|
|
cp a ; ensure Z
|
2019-05-10 05:36:03 +10:00
|
|
|
ret
|
|
|
|
|
2019-06-20 01:42:39 +10:00
|
|
|
stderrPutC:
|
|
|
|
out (STDERR_PORT), a
|
|
|
|
cp a ; ensure Z
|
|
|
|
ret
|
|
|
|
|
2019-10-31 07:59:35 +11:00
|
|
|
fsdevGetB:
|
2019-06-05 01:53:02 +10:00
|
|
|
ld a, e
|
|
|
|
out (FS_SEEK_PORT), a
|
2019-05-16 03:41:56 +10:00
|
|
|
ld a, h
|
2019-06-05 01:53:02 +10:00
|
|
|
out (FS_SEEK_PORT), a
|
2019-05-16 03:41:56 +10:00
|
|
|
ld a, l
|
2019-06-05 01:53:02 +10:00
|
|
|
out (FS_SEEK_PORT), a
|
|
|
|
in a, (FS_SEEK_PORT)
|
|
|
|
or a
|
|
|
|
ret nz
|
2019-05-17 03:23:23 +10:00
|
|
|
in a, (FS_DATA_PORT)
|
|
|
|
cp a ; ensure Z
|
|
|
|
ret
|
|
|
|
|
2019-10-31 07:59:35 +11:00
|
|
|
fsdevPutB:
|
2019-05-17 03:23:23 +10:00
|
|
|
push af
|
2019-05-29 05:56:39 +10:00
|
|
|
ld a, e
|
|
|
|
out (FS_SEEK_PORT), a
|
2019-05-17 03:23:23 +10:00
|
|
|
ld a, h
|
|
|
|
out (FS_SEEK_PORT), a
|
2019-05-17 11:15:00 +10:00
|
|
|
ld a, l
|
|
|
|
out (FS_SEEK_PORT), a
|
2019-05-17 03:23:23 +10:00
|
|
|
in a, (FS_SEEK_PORT)
|
2019-06-05 01:53:02 +10:00
|
|
|
or a
|
|
|
|
jr nz, .error
|
2019-05-17 03:23:23 +10:00
|
|
|
pop af
|
2019-06-05 01:53:02 +10:00
|
|
|
out (FS_DATA_PORT), a
|
2019-06-16 06:48:30 +10:00
|
|
|
cp a ; ensure Z
|
2019-05-17 03:23:23 +10:00
|
|
|
ret
|
2019-06-05 01:53:02 +10:00
|
|
|
.error:
|
|
|
|
pop af
|
|
|
|
jp unsetZ ; returns
|
2019-05-17 03:23:23 +10:00
|
|
|
|