1
0
mirror of https://github.com/hsoft/collapseos.git synced 2024-09-29 09:20:55 +10:00

recipes/rc2014/sdcard: add instructions to write to SD card

This commit is contained in:
Virgil Dupras 2019-06-02 11:53:36 -04:00
parent 26e71ee580
commit 57356e47b4
2 changed files with 50 additions and 11 deletions

View File

@ -90,8 +90,9 @@ World!":
Then, insert your SD card in your SPI relay and boot the RC2014.
Run the `sdci` command which will initialize the card. Then, run `bsel 1` to
select the second blockdev, which is configured to be the sd card.
Run the `sdci` command which will initialize the card. The blockdev 0 is
already selected at initialization, but you could, to be sure, run `bsel 0` to
select the first blockdev, which is configured to be the sd card.
Set your memory pointer to somewhere you can write to with `mptr 9000` and then
you're ready to load your contents with `load d` (load the 13 bytes that you
@ -109,7 +110,6 @@ Then, you insert your SD card in your SPI relay and go:
Collapse OS
> sdci
> bsel 1
> fson
> fls
helo
@ -127,5 +127,41 @@ 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!
## Writing to a file in the SD card
Now what we're going to do is to write back to a file on the SD card. From a
system with the SD card initialized and the FS mounted, do:
> fopn 0 hello.txt
> bsel 1
> mptr 9000
9000
> load d
> peek d
48656C6C6F20576F726C64210A
Now that we have our "Hello World!\n" loaded in memory, let's modify it and make
it start with "XXX" and save it to the file. `sdcf` flushes the current SD card
buffer to the card. It's automatically ran whenever we change sector during a
read/write/seek, but was can also explicitly call it with `sdcf`.
> poke 3
[type "XXX"]
> peek d
5858586C6F20576F726C64210A
> seek 00 0000
0000
> save d
> sdcf
The new "XXXlo World!\n" is now written to the card, at its proper place in CFS!
You can verify this by pulling out the card (no need to unmount it from Collapse
OS, but if you insert it again, you'll need to run `sdci` again), insert it in
your modern system and run:
$ head -c 512 /dev/sdX | xxd
You'll see your "XXXlo World!\n" somewhere, normally at offset `0x120`!
[schematic]: spirelay/spirelay.pdf
[inspiration]: https://www.ecstaticlyrics.com/electronics/SPI/fast_z80_interface.html

View File

@ -25,10 +25,9 @@ jp aciaInt
.equ ACIA_RAMSTART RAMSTART
#include "acia.asm"
.equ BLOCKDEV_RAMSTART ACIA_RAMEND
.equ BLOCKDEV_COUNT 3
.equ BLOCKDEV_COUNT 2
#include "blockdev.asm"
; List of devices
.dw aciaGetC, aciaPutC, 0, 0
.dw sdcGetC, sdcPutC, sdcSeek, sdcTell
.dw blk2GetC, blk2PutC, blk2Seek, blk2Tell
@ -43,9 +42,10 @@ jp aciaInt
#include "fs_cmds.asm"
.equ SHELL_RAMSTART FS_RAMEND
.equ SHELL_EXTRA_CMD_COUNT 9
.equ SHELL_EXTRA_CMD_COUNT 11
#include "shell.asm"
.dw sdcInitializeCmd, sdcFlushCmd, blkBselCmd, blkSeekCmd
.dw sdcInitializeCmd, sdcFlushCmd
.dw blkBselCmd, blkSeekCmd, blkLoadCmd, blkSaveCmd
.dw fsOnCmd, flsCmd, fnewCmd, fdelCmd, fopnCmd
#include "pgm.asm"
@ -63,14 +63,17 @@ init:
ld sp, hl
im 1
call aciaInit
xor a
ld de, BLOCKDEV_GETC
call blkSel
ld hl, aciaGetC
ld de, aciaPutC
call stdioInit
call shellInit
ld hl, pgmShellHook
ld (SHELL_CMDHOOK), hl
xor a
ld de, BLOCKDEV_GETC
call blkSel
ei
jp shellLoop