From f87cd0485a9801794119f57457c39b864a069718 Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Mon, 22 Apr 2019 22:54:23 -0400 Subject: [PATCH] blockdev: make "seek" print out its resulting position Also, extract commands into blockdev_cmds to avoid making blockdev dependent on stdio. --- parts/blockdev.asm | 35 ++++----------------------------- parts/blockdev_cmds.asm | 43 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 31 deletions(-) create mode 100644 parts/blockdev_cmds.asm diff --git a/parts/blockdev.asm b/parts/blockdev.asm index 71fa992..7c40ee6 100644 --- a/parts/blockdev.asm +++ b/parts/blockdev.asm @@ -44,19 +44,6 @@ blkSel: pop af ret -blkBselCmd: - .db "bsel", 0b001, 0, 0 - ld a, (hl) ; argument supplied - cp BLOCKDEV_COUNT - jr nc, .error ; if selection >= device count, error - call blkSel - xor a - ret -.error: - ld a, BLOCKDEV_ERR_OUT_OF_BOUNDS - ret - - ; In those routines below, IY is destroyed (we don't push it to the stack). We ; seldom use it anyways... @@ -137,26 +124,12 @@ 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 +; Seeks the block device in one of 5 modes, which is the A argument: +; 0 : Move exactly to X, X being the HL argument. +; 1 : Move forward by X bytes, X being the HL argument +; 2 : Move backwards by X bytes, X being the HL argument ; 3 : Move to the end ; 4 : Move to the beginning -blkSeekCmd: - .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) - ex af, af' - inc hl - ld a, (hl) - ld l, a - ex af, af' - ld h, a ; Set position of selected device to the value specified in HL blkSeek: ld iyl, 4 diff --git a/parts/blockdev_cmds.asm b/parts/blockdev_cmds.asm new file mode 100644 index 0000000..74a1f97 --- /dev/null +++ b/parts/blockdev_cmds.asm @@ -0,0 +1,43 @@ +; *** REQUIREMENTS *** +; blockdev +; stdio + +blkBselCmd: + .db "bsel", 0b001, 0, 0 + ld a, (hl) ; argument supplied + cp BLOCKDEV_COUNT + jr nc, .error ; if selection >= device count, error + call blkSel + xor a + ret +.error: + ld a, BLOCKDEV_ERR_OUT_OF_BOUNDS + ret + +blkSeekCmd: + .db "seek", 0b001, 0b011, 0b001 + ; First, the mode + ld a, (hl) + inc hl + push af ; save mode for later + ; 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 + pop af ; bring mode back + call blkSeek + ld hl, 42 + call blkTell + ld a, h + call printHex + ld a, l + call printHex + call printcrlf + xor a + ret +