1
0
mirror of https://github.com/hsoft/collapseos.git synced 2024-11-28 04:38:06 +11:00
collapseos/tools/emul/zasm/glue.asm

133 lines
1.9 KiB
NASM
Raw Normal View History

2019-05-10 04:09:40 +10:00
; Glue code for the emulated environment
.equ RAMSTART 0x4000
.equ USER_CODE 0x4800
2019-05-10 04:09:40 +10:00
.equ STDIO_PORT 0x00
.equ STDIN_SEEK 0x01
2019-05-17 03:23:23 +10:00
.equ FS_DATA_PORT 0x02
.equ FS_SEEK_PORT 0x03
.equ STDERR_PORT 0x04
2019-05-10 04:09:40 +10:00
jp init ; 3 bytes
; *** JUMP TABLE ***
2019-06-01 01:12:29 +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
jp blkSet
2019-06-01 01:12:29 +10:00
jp fsFindFN
jp fsOpen
jp fsGetB
2019-06-01 01:12:29 +10:00
jp cpHLDE
jp parseArgs
jp _blkGetB
jp _blkPutB
jp _blkSeek
jp _blkTell
jp printstr
2019-05-10 04:09:40 +10:00
.inc "core.asm"
.inc "err.h"
.inc "parse.asm"
2019-05-17 03:23:23 +10:00
.equ BLOCKDEV_RAMSTART RAMSTART
.equ BLOCKDEV_COUNT 3
.inc "blockdev.asm"
2019-05-17 03:23:23 +10:00
; List of devices
.dw emulGetB, unsetZ
.dw unsetZ, emulPutB
.dw fsdevGetB, fsdevPutB
2019-05-17 03:23:23 +10:00
.equ STDIO_RAMSTART BLOCKDEV_RAMEND
.inc "stdio.asm"
.equ FS_RAMSTART STDIO_RAMEND
2019-05-17 03:23:23 +10:00
.equ FS_HANDLE_COUNT 0
.inc "fs.asm"
2019-05-17 03:23:23 +10:00
2019-05-10 04:09:40 +10:00
init:
di
ld hl, 0xffff
2019-05-10 04:09:40 +10:00
ld sp, hl
ld hl, unsetZ
ld de, stderrPutC
call stdioInit
2019-05-17 03:23:23 +10:00
ld a, 2 ; select fsdev
ld de, BLOCKDEV_SEL
2019-05-17 03:23:23 +10:00
call blkSel
call fsOn
ld hl, .zasmArgs
call USER_CODE
2019-05-10 04:09:40 +10:00
; signal the emulator we're done
halt
.zasmArgs:
.db "0 1", 0
; *** I/O ***
emulGetB:
; 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
in a, (STDIO_PORT)
or a ; cp 0
jr z, .eof
cp a ; ensure z
ret
.eof:
call unsetZ
ret
emulPutB:
out (STDIO_PORT), a
cp a ; ensure Z
ret
stderrPutC:
out (STDERR_PORT), a
cp a ; ensure Z
ret
fsdevGetB:
ld a, e
out (FS_SEEK_PORT), a
ld a, h
out (FS_SEEK_PORT), a
ld a, l
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
fsdevPutB:
2019-05-17 03:23:23 +10:00
push af
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)
or a
jr nz, .error
2019-05-17 03:23:23 +10:00
pop af
out (FS_DATA_PORT), a
cp a ; ensure Z
2019-05-17 03:23:23 +10:00
ret
.error:
pop af
jp unsetZ ; returns
2019-05-17 03:23:23 +10:00