1
0
mirror of https://github.com/hsoft/collapseos.git synced 2024-12-27 02:48:05 +11:00
collapseos/tools/emul/zasm/glue.asm

114 lines
1.6 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
2019-05-10 04:09:40 +10:00
2019-05-17 03:23:23 +10:00
jp init ; 3 bytes
2019-05-10 04:09:40 +10:00
; *** JUMP TABLE ***
jp strncmp
jp addDE
2019-05-10 11:21:08 +10:00
jp addHL
2019-05-10 04:09:40 +10:00
jp upcase
jp unsetZ
jp intoDE
2019-05-13 12:07:21 +10:00
jp intoHL
2019-05-10 11:21:08 +10:00
jp findchar
2019-05-10 12:14:11 +10:00
jp parseHexPair
jp blkSel
2019-05-17 11:15:00 +10:00
jp fsFindFN
jp fsOpen
jp fsGetC
jp fsSeek
jp fsTell
2019-05-10 04:09:40 +10:00
2019-05-17 03:23:23 +10:00
#include "core.asm"
#include "parse.asm"
2019-05-17 03:23:23 +10:00
.equ BLOCKDEV_RAMSTART RAMSTART
.equ BLOCKDEV_COUNT 3
#include "blockdev.asm"
; List of devices
.dw emulGetC, 0, emulSeek, emulTell
.dw 0, emulPutC, 0, 0
.dw fsdevGetC, fsdevPutC, fsdevSeek, fsdevTell
.equ FS_RAMSTART BLOCKDEV_RAMEND
.equ FS_HANDLE_COUNT 0
#include "fs.asm"
2019-05-10 04:09:40 +10:00
init:
di
; We put the stack at the end of the kernel memory
ld hl, USER_CODE-1
2019-05-10 04:09:40 +10:00
ld sp, hl
2019-05-17 03:23:23 +10:00
ld a, 2 ; select fsdev
ld de, BLOCKDEV_GETC
call blkSel
call fsOn
ld h, 0 ; input blkdev
ld l, 1 ; output blkdev
2019-05-10 04:09:40 +10:00
call USER_CODE
; signal the emulator we're done
halt
emulGetC:
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
ret
2019-05-11 10:32:05 +10:00
emulSeek:
; 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-11 10:32:05 +10:00
ret
2019-05-16 10:07:21 +10:00
emulTell:
; same principle as STDIN_SEEK
in a, (STDIN_SEEK)
ld h, a
in a, (STDIN_SEEK)
ld l, a
ret
2019-05-17 03:23:23 +10:00
fsdevGetC:
in a, (FS_DATA_PORT)
cp a ; ensure Z
ret
fsdevPutC:
out (FS_DATA_PORT), a
ret
fsdevSeek:
push af
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
pop af
ret
fsdevTell:
push af
in a, (FS_SEEK_PORT)
ld h, a
2019-05-17 11:15:00 +10:00
in a, (FS_SEEK_PORT)
ld l, a
2019-05-17 03:23:23 +10:00
pop af
ret