From 6b1679c811b5a433b86244a1654997e769975801 Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Tue, 28 May 2019 13:13:34 -0400 Subject: [PATCH] recipes/rc2014/sdcard: mount filesystem! --- recipes/rc2014/sdcard/.gitignore | 1 + recipes/rc2014/sdcard/Makefile | 3 +- recipes/rc2014/sdcard/README.md | 30 ++++++++++++++++++ recipes/rc2014/sdcard/glue.asm | 54 +++++++++++++++++++++----------- recipes/rc2014/sdcard/helo.asm | 10 ++++++ 5 files changed, 79 insertions(+), 19 deletions(-) create mode 100644 recipes/rc2014/sdcard/.gitignore create mode 100644 recipes/rc2014/sdcard/helo.asm diff --git a/recipes/rc2014/sdcard/.gitignore b/recipes/rc2014/sdcard/.gitignore new file mode 100644 index 0000000..4c1aa4e --- /dev/null +++ b/recipes/rc2014/sdcard/.gitignore @@ -0,0 +1 @@ +cfsin/helo diff --git a/recipes/rc2014/sdcard/Makefile b/recipes/rc2014/sdcard/Makefile index 7ebacbc..d408c7e 100644 --- a/recipes/rc2014/sdcard/Makefile +++ b/recipes/rc2014/sdcard/Makefile @@ -1,4 +1,4 @@ -TARGETS = os.bin +TARGETS = os.bin cfsin/helo TOOLS = ../../../tools ZASM = $(TOOLS)/emul/zasm/zasm CFSPACK = $(TOOLS)/cfspack/cfspack @@ -6,6 +6,7 @@ CFSPACK = $(TOOLS)/cfspack/cfspack .PHONY: all all: $(TARGETS) sdcard.cfs os.bin: glue.asm +cfsin/helo: helo.asm $(TARGETS): $(ZASM) < $< > $@ diff --git a/recipes/rc2014/sdcard/README.md b/recipes/rc2014/sdcard/README.md index 080f60d..fd07d6c 100644 --- a/recipes/rc2014/sdcard/README.md +++ b/recipes/rc2014/sdcard/README.md @@ -98,5 +98,35 @@ you're ready to load your contents with `load d` (load the 13 bytes that you wrote to your sd card earlier. You can then `peek d` and see that your "Hello World!\n" got loaded in memory! +## Mounting a filesystem from the SD card + +The Makefile compiles `helo.asm` in `cfsin` and then packs `cfsin` into a CFS +filesystem into the `sdcard.cfs` file. That can be mounted by Collapse OS! + + $ cat sdcard.cfs > /dev/sdX + +Then, you insert your SD card in your SPI relay and go: + + Collapse OS + > mptr 9000 + 9000 + > sdci + > bsel 1 + > fson + > fls + helo + hello.txt + > fopn 0 helo + > load 10 + > peek 10 + 210690C3030048656C6C6F210D0A0000 + > call 00 0000 + Hello! + > + +Now let that sink in for a minute. You've just mounted a filesystem on a SD +card, loaded a file from it in memory and executed that file, all that on a +kernel that weights less than 3 kilobytes! + [schematic]: spirelay/spirelay.pdf [inspiration]: https://www.ecstaticlyrics.com/electronics/SPI/fast_z80_interface.html diff --git a/recipes/rc2014/sdcard/glue.asm b/recipes/rc2014/sdcard/glue.asm index a0a6470..8d613ed 100644 --- a/recipes/rc2014/sdcard/glue.asm +++ b/recipes/rc2014/sdcard/glue.asm @@ -5,20 +5,14 @@ .equ ACIA_CTL 0x80 ; Control and status. RS off. .equ ACIA_IO 0x81 ; Transmit. RS on. -jp init +jp init ; 3 bytes -; *** JUMP TABLE *** -; Why not use this unused space between 0x03 and 0x38 for a jump table? - jp printstr - jp printHex - jp sdcInitialize - jp sdcSendRecv - jp sdcWaitResp - jp sdcCmd - jp sdcCmdR1 - jp sdcCmdR7 - jp sdcReadBlk - jp sdcSetBlkSize +; *** Jump Table *** +jp printstr +jp fsOpen +jp fsSeek +jp fsTell +jp fsGetC ; interrupt hook .fill 0x38-$ @@ -29,21 +23,28 @@ jp aciaInt .equ ACIA_RAMSTART RAMSTART #include "acia.asm" .equ BLOCKDEV_RAMSTART ACIA_RAMEND -.equ BLOCKDEV_COUNT 2 +.equ BLOCKDEV_COUNT 3 #include "blockdev.asm" ; List of devices .dw aciaGetC, aciaPutC, 0, 0 -.dw sdcGetC, 0, 0, 0 +.dw sdcGetC, 0, sdcSeek, sdcTell +.dw blk2GetC, blk2PutC, blk2Seek, blk2Tell #include "blockdev_cmds.asm" .equ STDIO_RAMSTART BLOCKDEV_RAMEND #include "stdio.asm" -.equ SHELL_RAMSTART STDIO_RAMEND -.equ SHELL_EXTRA_CMD_COUNT 4 +.equ FS_RAMSTART STDIO_RAMEND +.equ FS_HANDLE_COUNT 1 +#include "fs.asm" +#include "fs_cmds.asm" + +.equ SHELL_RAMSTART FS_RAMEND +.equ SHELL_EXTRA_CMD_COUNT 8 #include "shell.asm" -.dw sdcInitializeCmd, blkBselCmd, blkSeekCmd, sdcInitializeCmd +.dw sdcInitializeCmd, blkBselCmd, blkSeekCmd +.dw fsOnCmd, flsCmd, fnewCmd, fdelCmd, fopnCmd .equ SDC_RAMSTART SHELL_RAMEND .equ SDC_PORT_CSHIGH 6 @@ -67,3 +68,20 @@ init: ei jp shellLoop +; *** blkdev 2: file handle 0 *** + +blk2GetC: + ld de, FS_HANDLES + jp fsGetC + +blk2PutC: + ld de, FS_HANDLES + jp fsPutC + +blk2Seek: + ld de, FS_HANDLES + jp fsSeek + +blk2Tell: + ld de, FS_HANDLES + jp fsTell diff --git a/recipes/rc2014/sdcard/helo.asm b/recipes/rc2014/sdcard/helo.asm new file mode 100644 index 0000000..0c905b3 --- /dev/null +++ b/recipes/rc2014/sdcard/helo.asm @@ -0,0 +1,10 @@ +; prints "Hello!" on screen +.equ printstr 0x03 + +.org 0x9000 + + ld hl, sHello + jp printstr ; return + +sHello: + .db "Hello!", 0x0d, 0x0a, 0