2019-05-09 14:09:40 -04:00
|
|
|
; Glue code for the emulated environment
|
2019-05-10 18:20:43 -04:00
|
|
|
.equ RAMSTART 0x4000
|
2019-05-19 15:03:34 -04:00
|
|
|
.equ USER_CODE 0x4800
|
2019-05-09 14:09:40 -04:00
|
|
|
.equ STDIO_PORT 0x00
|
2019-05-15 13:41:56 -04:00
|
|
|
.equ STDIN_SEEK 0x01
|
2019-05-16 13:23:23 -04:00
|
|
|
.equ FS_DATA_PORT 0x02
|
|
|
|
.equ FS_SEEK_PORT 0x03
|
2019-05-17 13:22:45 -04:00
|
|
|
.equ STDERR_PORT 0x04
|
2019-05-09 14:09:40 -04:00
|
|
|
|
2019-05-19 12:57:59 -04:00
|
|
|
jp init ; 3 bytes
|
|
|
|
; *** JUMP TABLE ***
|
2019-05-31 11:12:29 -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-05-31 11:12:29 -04:00
|
|
|
jp fsFindFN
|
|
|
|
jp fsOpen
|
|
|
|
jp fsGetC
|
|
|
|
jp cpHLDE
|
2019-06-02 14:05:20 -04:00
|
|
|
jp parseArgs
|
2019-06-04 11:53:02 -04:00
|
|
|
jp _blkGetC
|
|
|
|
jp _blkPutC
|
|
|
|
jp _blkSeek
|
|
|
|
jp _blkTell
|
2019-06-19 11:42:39 -04:00
|
|
|
jp printstr
|
2019-05-09 14:09:40 -04:00
|
|
|
|
2019-05-16 13:23:23 -04:00
|
|
|
#include "core.asm"
|
2019-06-02 14:05:20 -04:00
|
|
|
#include "err.h"
|
2019-05-17 09:33:20 -04:00
|
|
|
#include "parse.asm"
|
2019-05-16 13:23:23 -04:00
|
|
|
.equ BLOCKDEV_RAMSTART RAMSTART
|
|
|
|
.equ BLOCKDEV_COUNT 3
|
|
|
|
#include "blockdev.asm"
|
|
|
|
; List of devices
|
2019-06-04 11:53:02 -04:00
|
|
|
.dw emulGetC, unsetZ
|
|
|
|
.dw unsetZ, emulPutC
|
|
|
|
.dw fsdevGetC, fsdevPutC
|
2019-05-16 13:23:23 -04:00
|
|
|
|
2019-06-19 11:42:39 -04:00
|
|
|
.equ STDIO_RAMSTART BLOCKDEV_RAMEND
|
|
|
|
#include "stdio.asm"
|
|
|
|
|
|
|
|
.equ FS_RAMSTART STDIO_RAMEND
|
2019-05-16 13:23:23 -04:00
|
|
|
.equ FS_HANDLE_COUNT 0
|
|
|
|
#include "fs.asm"
|
|
|
|
|
2019-05-09 14:09:40 -04:00
|
|
|
init:
|
|
|
|
di
|
2019-05-19 09:14:40 -04:00
|
|
|
ld hl, 0xffff
|
2019-05-09 14:09:40 -04:00
|
|
|
ld sp, hl
|
2019-06-19 11:42:39 -04:00
|
|
|
ld hl, unsetZ
|
|
|
|
ld de, stderrPutC
|
|
|
|
call stdioInit
|
2019-05-16 13:23:23 -04:00
|
|
|
ld a, 2 ; select fsdev
|
2019-06-04 09:56:36 -04:00
|
|
|
ld de, BLOCKDEV_SEL
|
2019-05-16 13:23:23 -04:00
|
|
|
call blkSel
|
|
|
|
call fsOn
|
2019-06-02 14:05:20 -04:00
|
|
|
ld hl, .zasmArgs
|
2019-05-19 12:57:59 -04:00
|
|
|
call USER_CODE
|
2019-05-09 14:09:40 -04:00
|
|
|
; signal the emulator we're done
|
|
|
|
halt
|
|
|
|
|
2019-06-02 14:05:20 -04:00
|
|
|
.zasmArgs:
|
2019-06-02 14:46:07 -04:00
|
|
|
.db "0 1", 0
|
2019-06-02 14:05:20 -04:00
|
|
|
|
2019-05-17 13:22:45 -04:00
|
|
|
; *** I/O ***
|
2019-05-09 15:36:03 -04:00
|
|
|
emulGetC:
|
2019-06-04 11:53:02 -04: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-09 15:36:03 -04:00
|
|
|
in a, (STDIO_PORT)
|
|
|
|
or a ; cp 0
|
|
|
|
jr z, .eof
|
|
|
|
cp a ; ensure z
|
|
|
|
ret
|
|
|
|
.eof:
|
|
|
|
call unsetZ
|
|
|
|
ret
|
|
|
|
|
|
|
|
emulPutC:
|
|
|
|
out (STDIO_PORT), a
|
2019-06-15 16:48:30 -04:00
|
|
|
cp a ; ensure Z
|
2019-05-09 15:36:03 -04:00
|
|
|
ret
|
|
|
|
|
2019-06-19 11:42:39 -04:00
|
|
|
stderrPutC:
|
|
|
|
out (STDERR_PORT), a
|
|
|
|
cp a ; ensure Z
|
|
|
|
ret
|
|
|
|
|
2019-06-04 11:53:02 -04:00
|
|
|
fsdevGetC:
|
|
|
|
ld a, e
|
|
|
|
out (FS_SEEK_PORT), a
|
2019-05-15 13:41:56 -04:00
|
|
|
ld a, h
|
2019-06-04 11:53:02 -04:00
|
|
|
out (FS_SEEK_PORT), a
|
2019-05-15 13:41:56 -04:00
|
|
|
ld a, l
|
2019-06-04 11:53:02 -04:00
|
|
|
out (FS_SEEK_PORT), a
|
|
|
|
in a, (FS_SEEK_PORT)
|
|
|
|
or a
|
|
|
|
ret nz
|
2019-05-16 13:23:23 -04:00
|
|
|
in a, (FS_DATA_PORT)
|
|
|
|
cp a ; ensure Z
|
|
|
|
ret
|
|
|
|
|
|
|
|
fsdevPutC:
|
|
|
|
push af
|
2019-05-28 15:56:39 -04:00
|
|
|
ld a, e
|
|
|
|
out (FS_SEEK_PORT), a
|
2019-05-16 13:23:23 -04:00
|
|
|
ld a, h
|
|
|
|
out (FS_SEEK_PORT), a
|
2019-05-16 21:15:00 -04:00
|
|
|
ld a, l
|
|
|
|
out (FS_SEEK_PORT), a
|
2019-05-16 13:23:23 -04:00
|
|
|
in a, (FS_SEEK_PORT)
|
2019-06-04 11:53:02 -04:00
|
|
|
or a
|
|
|
|
jr nz, .error
|
2019-05-16 13:23:23 -04:00
|
|
|
pop af
|
2019-06-04 11:53:02 -04:00
|
|
|
out (FS_DATA_PORT), a
|
2019-06-15 16:48:30 -04:00
|
|
|
cp a ; ensure Z
|
2019-05-16 13:23:23 -04:00
|
|
|
ret
|
2019-06-04 11:53:02 -04:00
|
|
|
.error:
|
|
|
|
pop af
|
|
|
|
jp unsetZ ; returns
|
2019-05-16 13:23:23 -04:00
|
|
|
|