mirror of
https://github.com/hsoft/collapseos.git
synced 2024-11-06 00:40:56 +11:00
ae028e3a86
This huge refactoring remove the Seek and Tell routine from blockdev implementation requirements and change GetC and PutC's API so that they take an address to read and write (through HL/DE) at each call. The "PTR" approach in blockdev implementation was very redundant from device to device and it made more sense to generalize. It's possible that future device aren't "random access", but we'll be able to add more device types later. Another important change in this commit is that the "blockdev handle" is now opaque. Previously, consumers of the API would happily call routines directly from one of the 4 offsets. We can't do that any more. This makes the API more solid for future improvements. This change forced me to change a lot of things in fs, but overall, things are now simpler. No more `FS_PTR`: the "device handle" now holds the active pointer. Lots, lots of changes, but it also feels a lot cleaner and solid.
120 lines
1.7 KiB
NASM
120 lines
1.7 KiB
NASM
; Glue code for the emulated environment
|
|
.equ RAMSTART 0x4000
|
|
.equ USER_CODE 0x4800
|
|
.equ STDIO_PORT 0x00
|
|
.equ STDIN_SEEK 0x01
|
|
.equ FS_DATA_PORT 0x02
|
|
.equ FS_SEEK_PORT 0x03
|
|
.equ STDERR_PORT 0x04
|
|
|
|
jp init ; 3 bytes
|
|
; *** JUMP TABLE ***
|
|
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 fsFindFN
|
|
jp fsOpen
|
|
jp fsGetC
|
|
jp fsSeek
|
|
jp fsTell
|
|
jp cpHLDE
|
|
jp parseArgs
|
|
jp _blkGetC
|
|
jp _blkPutC
|
|
jp _blkSeek
|
|
jp _blkTell
|
|
|
|
#include "core.asm"
|
|
#include "err.h"
|
|
#include "parse.asm"
|
|
.equ BLOCKDEV_RAMSTART RAMSTART
|
|
.equ BLOCKDEV_COUNT 3
|
|
#include "blockdev.asm"
|
|
; List of devices
|
|
.dw emulGetC, unsetZ
|
|
.dw unsetZ, emulPutC
|
|
.dw fsdevGetC, fsdevPutC
|
|
|
|
.equ FS_RAMSTART BLOCKDEV_RAMEND
|
|
.equ FS_HANDLE_COUNT 0
|
|
#include "fs.asm"
|
|
|
|
init:
|
|
di
|
|
ld hl, 0xffff
|
|
ld sp, hl
|
|
ld a, 2 ; select fsdev
|
|
ld de, BLOCKDEV_SEL
|
|
call blkSel
|
|
call fsOn
|
|
ld hl, .zasmArgs
|
|
call USER_CODE
|
|
; signal the emulator we're done
|
|
halt
|
|
|
|
.zasmArgs:
|
|
.db "0 1", 0
|
|
|
|
; *** I/O ***
|
|
emulGetC:
|
|
; 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
|
|
|
|
emulPutC:
|
|
out (STDIO_PORT), a
|
|
ret
|
|
|
|
fsdevGetC:
|
|
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
|
|
in a, (FS_DATA_PORT)
|
|
cp a ; ensure Z
|
|
ret
|
|
|
|
fsdevPutC:
|
|
push af
|
|
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
|
|
jr nz, .error
|
|
pop af
|
|
out (FS_DATA_PORT), a
|
|
ret
|
|
.error:
|
|
pop af
|
|
jp unsetZ ; returns
|
|
|