1
0
mirror of https://github.com/hsoft/collapseos.git synced 2024-12-25 18:08:05 +11:00

blockdev: add "type" argument to blkSeek

Allows seeking forward, backwards, to the beginning, to the end.
This commit is contained in:
Virgil Dupras 2019-04-22 22:28:35 -04:00
parent d3d229a918
commit 8b7faa1f02
2 changed files with 40 additions and 3 deletions

View File

@ -119,13 +119,16 @@ blkGetCW:
; Reads B chars from blkGetC and copy them in (HL).
; Sets Z if successful, unset Z if there was an error.
blkRead:
push hl
.loop:
call blkGetC
ret nz
jr nz, .end ; Z already unset
ld (hl), a
inc hl
djnz .loop
cp a ; ensure Z
.end:
pop hl
ret
; Writes character in A in current position in the selected device. Sets Z
@ -134,8 +137,17 @@ blkPutC:
ld iyl, 2
jr _blkCall
; Seeks the block device in one of 5 modes, which is the first argument:
; 0 : Move exactly to X, X being the second argument.
; 1 : Move forward by X bytes, X being the second argument
; 2 : Move backwards by X bytes, X being the second argument
; 3 : Move to the end
; 4 : Move to the beginning
blkSeekCmd:
.db "seek", 0b011, 0b001, 0
.db "seek", 0b001, 0b011, 0b001
; First, the mode
ld a, (hl)
inc hl
; HL points to two bytes that contain out address. Seek expects HL
; to directly contain that address.
ld a, (hl)
@ -145,7 +157,6 @@ blkSeekCmd:
ld l, a
ex af, af'
ld h, a
xor a
; Set position of selected device to the value specified in HL
blkSeek:
ld iyl, 4

View File

@ -57,6 +57,32 @@ mmapPutC:
ret
mmapSeek:
cp 1
jr z, .forward
cp 2
jr z, .backward
cp 3
jr z, .beginning
cp 4
jr z, .end
; all other modes are considered absolute
jr .set ; for absolute mode, HL is already correct
.forward:
ld de, (MMAP_PTR)
add hl, de
jr nc, .set
; we have carry? out of bounds, set to maximum
ld hl, 0xffff
jr .set
.backward:
; TODO - subtraction are more complicated...
jr .set
.beginning:
ld hl, 0
jr .set
.end:
ld hl, 0xffff-MMAP_START
.set:
ld (MMAP_PTR), hl
ret