From 8b7faa1f0284ffa5087a12713744bd05bd8bf6ec Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Mon, 22 Apr 2019 22:28:35 -0400 Subject: [PATCH] blockdev: add "type" argument to blkSeek Allows seeking forward, backwards, to the beginning, to the end. --- parts/blockdev.asm | 17 ++++++++++++++--- parts/mmap.asm | 26 ++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/parts/blockdev.asm b/parts/blockdev.asm index e101aba..71fa992 100644 --- a/parts/blockdev.asm +++ b/parts/blockdev.asm @@ -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 diff --git a/parts/mmap.asm b/parts/mmap.asm index 699660f..15a3a5a 100644 --- a/parts/mmap.asm +++ b/parts/mmap.asm @@ -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