diff --git a/doc/glue-code.md b/doc/glue-code.md index a1498bc..647c7a4 100644 --- a/doc/glue-code.md +++ b/doc/glue-code.md @@ -26,7 +26,7 @@ look like: im 1 call aciaInit xor a - ld de, BLOCKDEV_GETC + ld de, BLOCKDEV_SEL call blkSel call stdioInit call shellInit diff --git a/kernel/blockdev.asm b/kernel/blockdev.asm index bbe7ad3..e278c9f 100644 --- a/kernel/blockdev.asm +++ b/kernel/blockdev.asm @@ -59,15 +59,12 @@ ; Pointer to the selected block device. A block device is a 8 bytes block of ; memory with pointers to GetC, PutC, Seek and Tell routines, in that order. ; 0 means unsupported. -.equ BLOCKDEV_GETC BLOCKDEV_RAMSTART -.equ BLOCKDEV_PUTC BLOCKDEV_GETC+2 -.equ BLOCKDEV_SEEK BLOCKDEV_PUTC+2 -.equ BLOCKDEV_TELL BLOCKDEV_SEEK+2 -.equ BLOCKDEV_RAMEND BLOCKDEV_TELL+2 +.equ BLOCKDEV_SEL BLOCKDEV_RAMSTART +.equ BLOCKDEV_RAMEND BLOCKDEV_SEL+8 ; *** CODE *** ; Select block index specified in A and place them in routine pointers at (DE). -; For example, for a "regular" blkSel, you will want to set DE to BLOCKDEV_GETC. +; For example, for a "regular" blkSel, you will want to set DE to BLOCKDEV_SEL. blkSel: push af push de @@ -120,13 +117,13 @@ blkSel: ; Sets Z according to whether read was successful: Set if successful, unset ; if not. blkGetC: - ld ix, (BLOCKDEV_GETC) + ld ix, (BLOCKDEV_SEL) jp (ix) ; Reads B chars from blkGetC and copy them in (HL). ; Sets Z if successful, unset Z if there was an error. blkRead: - ld ix, (BLOCKDEV_GETC) + ld ix, (BLOCKDEV_SEL) _blkRead: push hl push bc @@ -145,16 +142,20 @@ _blkRead: ; Writes character in A in current position in the selected device. Sets Z ; according to whether the operation was successful. blkPutC: - ld ix, (BLOCKDEV_PUTC) + ld ix, (BLOCKDEV_SEL+2) jp (ix) ; Writes B chars to blkPutC from (HL). ; Sets Z if successful, unset Z if there was an error. blkWrite: - ld ix, (BLOCKDEV_PUTC) + ld ix, (BLOCKDEV_SEL) _blkWrite: + push ix push hl push bc + ; make IX point to PutC + inc ix + inc ix .loop: ld a, (hl) call callIX @@ -165,6 +166,7 @@ _blkWrite: .end: pop bc pop hl + pop ix ret ; Seeks the block device in one of 5 modes, which is the A argument: @@ -184,8 +186,8 @@ _blkWrite: ; If the device is "growable", it's possible that seeking to end when calling ; PutC doesn't necessarily result in a failure. blkSeek: - ld ix, (BLOCKDEV_SEEK) - ld iy, (BLOCKDEV_TELL) + ld ix, (BLOCKDEV_SEL+4) + ld iy, (BLOCKDEV_SEL+6) _blkSeek: ; we preserve DE so that it's possible to call blkSeek in mode != 0 ; while not discarding our current DE value. @@ -234,7 +236,7 @@ _blkSeek: ; Returns the current position of the selected device in HL (low) and DE (high). blkTell: ld de, 0 ; in case device ignores DE. - ld ix, (BLOCKDEV_TELL) + ld ix, (BLOCKDEV_SEL+6) jp (ix) ; This label is at the end of the file on purpose: the glue file should include diff --git a/kernel/blockdev_cmds.asm b/kernel/blockdev_cmds.asm index edce35c..0316f8b 100644 --- a/kernel/blockdev_cmds.asm +++ b/kernel/blockdev_cmds.asm @@ -8,7 +8,7 @@ blkBselCmd: cp BLOCKDEV_COUNT jr nc, .error ; if selection >= device count, error push de - ld de, BLOCKDEV_GETC + ld de, BLOCKDEV_SEL call blkSel pop de xor a diff --git a/kernel/fs.asm b/kernel/fs.asm index f161d30..64269a9 100644 --- a/kernel/fs.asm +++ b/kernel/fs.asm @@ -369,7 +369,7 @@ fsblkPutC: fsblkWrite: push ix - ld ix, (FS_PUTC) + ld ix, (FS_GETC) ; we have to point to blkdev's beginning call _blkWrite pop ix ret @@ -523,7 +523,7 @@ fsOn: push bc ; We have to set blkdev routines early before knowing whether the ; mounting succeeds because methods like fsReadMeta uses fsblk* methods. - ld hl, BLOCKDEV_GETC + ld hl, BLOCKDEV_SEL ld de, FS_GETC ld bc, 8 ; we have 8 bytes to copy ldir ; copy! diff --git a/recipes/rc2014/sdcard/glue.asm b/recipes/rc2014/sdcard/glue.asm index 36ff7c8..db034cc 100644 --- a/recipes/rc2014/sdcard/glue.asm +++ b/recipes/rc2014/sdcard/glue.asm @@ -72,7 +72,7 @@ init: ld (SHELL_CMDHOOK), hl xor a - ld de, BLOCKDEV_GETC + ld de, BLOCKDEV_SEL call blkSel ei diff --git a/recipes/rc2014/zasm/glue.asm b/recipes/rc2014/zasm/glue.asm index d24f17d..d3ac9e3 100644 --- a/recipes/rc2014/zasm/glue.asm +++ b/recipes/rc2014/zasm/glue.asm @@ -99,7 +99,7 @@ init: ld (SHELL_CMDHOOK), hl xor a - ld de, BLOCKDEV_GETC + ld de, BLOCKDEV_SEL call blkSel ei diff --git a/tools/emul/shell/shell_.asm b/tools/emul/shell/shell_.asm index 6c7bf9b..cab0228 100644 --- a/tools/emul/shell/shell_.asm +++ b/tools/emul/shell/shell_.asm @@ -47,7 +47,6 @@ .dw stdinGetC, stdinPutC, stdinSeek, stdinTell .dw mmapGetC, mmapPutC, mmapSeek, mmapTell -#include "blockdev_cmds.asm" .equ MMAP_RAMSTART BLOCKDEV_RAMEND .equ MMAP_START 0xe000 @@ -59,7 +58,6 @@ .equ FS_RAMSTART STDIO_RAMEND .equ FS_HANDLE_COUNT 2 #include "fs.asm" -#include "fs_cmds.asm" .equ SHELL_RAMSTART FS_RAMEND .equ SHELL_EXTRA_CMD_COUNT 9 @@ -67,11 +65,14 @@ .dw blkBselCmd, blkSeekCmd, blkLoadCmd, blkSaveCmd .dw fsOnCmd, flsCmd, fnewCmd, fdelCmd, fopnCmd +#include "blockdev_cmds.asm" +#include "fs_cmds.asm" + .equ PGM_RAMSTART SHELL_RAMEND .equ PGM_CODEADDR USERCODE #include "pgm.asm" -.out PGM_RAMEND +;.out PGM_RAMEND init: di @@ -84,7 +85,7 @@ init: call mmapInit call fsInit ld a, 0 ; select fsdev - ld de, BLOCKDEV_GETC + ld de, BLOCKDEV_SEL call blkSel call fsOn call shellInit diff --git a/tools/emul/zasm/glue.asm b/tools/emul/zasm/glue.asm index 0f92c73..111e9d0 100644 --- a/tools/emul/zasm/glue.asm +++ b/tools/emul/zasm/glue.asm @@ -49,7 +49,7 @@ init: ld hl, 0xffff ld sp, hl ld a, 2 ; select fsdev - ld de, BLOCKDEV_GETC + ld de, BLOCKDEV_SEL call blkSel call fsOn ld hl, .zasmArgs