blockdev: move the new seek mode logic into the seek command

It wasn't a good idea to complicate all blockdev impls with complicated
seeks. Let's just stay in absolute mode for now.
This commit is contained in:
Virgil Dupras 2019-04-23 08:28:00 -04:00
parent f87cd0485a
commit 07fde3cab5
3 changed files with 27 additions and 27 deletions

View File

@ -132,6 +132,33 @@ blkPutC:
; 4 : Move to the beginning
; Set position of selected device to the value specified in HL
blkSeek:
push de
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 .seek ; for absolute mode, HL is already correct
.forward:
ex hl, de ; DE has our offset
call blkTell ; HL has our curpos
add hl, de
jr nc, .seek ; no carry? alright!
; we have carry? out of bounds, set to maximum
.backward:
; TODO - subtraction are more complicated...
jr .seek
.beginning:
ld hl, 0
jr .seek
.end:
ld hl, 0xffff
.seek:
pop de
ld iyl, 4
jr _blkCall

View File

@ -31,7 +31,6 @@ blkSeekCmd:
ld h, a
pop af ; bring mode back
call blkSeek
ld hl, 42
call blkTell
ld a, h
call printHex

View File

@ -57,32 +57,6 @@ 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