2019-04-16 06:53:11 +10:00
|
|
|
; blockdev
|
|
|
|
;
|
|
|
|
; A block device is an abstraction over something we can read from, write to.
|
|
|
|
;
|
|
|
|
; A device that fits this abstraction puts the properly hook into itself, and
|
|
|
|
; then the glue code assigns a blockdev ID to that device. It then becomes easy
|
|
|
|
; to access arbitrary devices in a convenient manner.
|
|
|
|
;
|
|
|
|
; This part exposes a new "bsel" command to select the currently active block
|
|
|
|
; device.
|
|
|
|
|
|
|
|
; *** DEFINES ***
|
|
|
|
; BLOCKDEV_COUNT: The number of devices we manage.
|
|
|
|
|
|
|
|
; *** CONSTS ***
|
2019-04-16 10:38:25 +10:00
|
|
|
BLOCKDEV_ERR_OUT_OF_BOUNDS .equ 0x03
|
2019-04-16 22:36:26 +10:00
|
|
|
BLOCKDEV_ERR_UNSUPPORTED .equ 0x04
|
2019-04-16 10:38:25 +10:00
|
|
|
|
2019-04-16 06:53:11 +10:00
|
|
|
; *** VARIABLES ***
|
2019-04-16 11:56:15 +10:00
|
|
|
; Pointer to the selected block device. A block device is a 6 bytes block of
|
|
|
|
; memory with pointers to GetC, PutC and Seek routines, in that order. 0 means
|
|
|
|
; unsupported.
|
2019-04-17 00:17:25 +10:00
|
|
|
BLOCKDEV_SEL .equ BLOCKDEV_RAMSTART
|
2019-04-16 11:56:15 +10:00
|
|
|
BLOCKDEV_RAMEND .equ BLOCKDEV_SEL+2
|
2019-04-16 06:53:11 +10:00
|
|
|
|
|
|
|
; *** CODE ***
|
2019-04-17 00:17:25 +10:00
|
|
|
; Select block index specified in A
|
|
|
|
blkSel:
|
|
|
|
push af
|
|
|
|
push hl
|
|
|
|
ld hl, blkDevTbl
|
2019-04-16 06:53:11 +10:00
|
|
|
cp 0
|
2019-04-17 00:17:25 +10:00
|
|
|
jr z, .afterloop ; index is zero? don't loop
|
2019-04-16 06:53:11 +10:00
|
|
|
push bc
|
|
|
|
ld b, a
|
|
|
|
.loop:
|
2019-04-17 00:17:25 +10:00
|
|
|
ld a, 6
|
|
|
|
call addHL
|
2019-04-16 06:53:11 +10:00
|
|
|
djnz .loop
|
|
|
|
pop bc
|
2019-04-17 00:17:25 +10:00
|
|
|
.afterloop:
|
|
|
|
ld (BLOCKDEV_SEL), hl
|
|
|
|
pop Hl
|
|
|
|
pop af
|
2019-04-16 06:53:11 +10:00
|
|
|
ret
|
|
|
|
|
|
|
|
blkBselCmd:
|
|
|
|
.db "bsel", 0b001, 0, 0
|
|
|
|
ld a, (hl) ; argument supplied
|
|
|
|
cp BLOCKDEV_COUNT
|
2019-04-16 10:38:25 +10:00
|
|
|
jr nc, .error ; if selection >= device count, error
|
2019-04-16 06:53:11 +10:00
|
|
|
call blkSel
|
2019-04-16 10:38:25 +10:00
|
|
|
xor a
|
|
|
|
ret
|
|
|
|
.error:
|
|
|
|
ld a, BLOCKDEV_ERR_OUT_OF_BOUNDS
|
2019-04-16 06:53:11 +10:00
|
|
|
ret
|
|
|
|
|
2019-04-16 22:36:26 +10:00
|
|
|
|
2019-04-16 11:56:15 +10:00
|
|
|
; In those routines below, IY is destroyed (we don't push it to the stack). We
|
|
|
|
; seldom use it anyways...
|
|
|
|
|
|
|
|
; call routine in BLOCKDEV_SEL with offset IYL.
|
|
|
|
_blkCall:
|
2019-04-16 06:53:11 +10:00
|
|
|
push ix
|
|
|
|
push de
|
2019-04-16 11:56:15 +10:00
|
|
|
ld de, (BLOCKDEV_SEL)
|
|
|
|
; DE now points to the *address table*, not the routine addresses
|
|
|
|
; themselves. One layer of indirection left.
|
|
|
|
; slide by offset
|
|
|
|
push af
|
|
|
|
ld a, iyl
|
|
|
|
call addDE ; slide by offset
|
|
|
|
pop af
|
|
|
|
call intoDE
|
|
|
|
; Alright, now de points to what we want to call
|
2019-04-16 06:53:11 +10:00
|
|
|
ld ixh, d
|
|
|
|
ld ixl, e
|
|
|
|
pop de
|
2019-04-16 22:36:26 +10:00
|
|
|
; Before we call... is it zero? We don't want to call a zero.
|
|
|
|
push af
|
|
|
|
ld a, ixh
|
|
|
|
add a, ixl
|
|
|
|
jr c, .ok ; if there's a carry, it isn't zero
|
|
|
|
cp 0
|
|
|
|
jr z, .error ; if no carry and zero, then both numbers are
|
|
|
|
; zero
|
|
|
|
.ok:
|
|
|
|
pop af
|
2019-04-16 06:53:11 +10:00
|
|
|
call callIX
|
2019-04-16 22:36:26 +10:00
|
|
|
jr .end
|
|
|
|
|
|
|
|
.error:
|
|
|
|
pop af
|
|
|
|
ld a, BLOCKDEV_ERR_UNSUPPORTED
|
|
|
|
.end:
|
2019-04-16 06:53:11 +10:00
|
|
|
pop ix
|
|
|
|
ret
|
|
|
|
|
2019-04-16 22:36:26 +10:00
|
|
|
; Reads one character from selected device and returns its value in A. Always
|
|
|
|
; returns a character and waits until read if it has to.
|
2019-04-16 11:56:15 +10:00
|
|
|
blkGetC:
|
|
|
|
ld iyl, 0
|
|
|
|
jr _blkCall
|
|
|
|
|
2019-04-16 22:36:26 +10:00
|
|
|
; Writes character in A in current position in the selected device
|
2019-04-16 06:53:11 +10:00
|
|
|
blkPutC:
|
2019-04-16 11:56:15 +10:00
|
|
|
ld iyl, 2
|
|
|
|
jr _blkCall
|
|
|
|
|
2019-04-16 22:36:26 +10:00
|
|
|
blkSeekCmd:
|
|
|
|
.db "seek", 0b011, 0b001, 0
|
|
|
|
; HL points to two bytes that contain out address. Seek expects HL
|
|
|
|
; to directly contain that address.
|
|
|
|
ld a, (hl)
|
|
|
|
ex af, af'
|
|
|
|
inc hl
|
|
|
|
ld a, (hl)
|
|
|
|
ld l, a
|
|
|
|
ex af, af'
|
|
|
|
ld h, a
|
|
|
|
xor a
|
|
|
|
; Set position of selected device to the value specified in HL
|
2019-04-16 11:56:15 +10:00
|
|
|
blkSeek:
|
|
|
|
ld iyl, 4
|
|
|
|
jr _blkCall
|
|
|
|
|
2019-04-17 00:17:25 +10:00
|
|
|
; This label is at the end of the file on purpose: the glue file should include
|
|
|
|
; a list of device routine table entries just after the include. Each line
|
|
|
|
; has 3 word addresses: GetC, PutC and Seek. An entry could look like:
|
|
|
|
; .dw mmapGetC, mmapPutC, mmapSeek
|
|
|
|
blkDevTbl:
|