From eefa8e6de5cd056892afdfd9b2189507dc9e2cbb Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Thu, 16 Apr 2020 17:22:18 -0400 Subject: [PATCH] Add word "BLK!" as well as emulator support for it. We can now write an edited block back to "blkfs". --- emul/forth/forth.c | 23 ++++++++++++++++------- emul/forth/run.fs | 10 +++++++++- forth/blk.fs | 4 ++++ 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/emul/forth/forth.c b/emul/forth/forth.c index e177006..127a8ad 100644 --- a/emul/forth/forth.c +++ b/emul/forth/forth.c @@ -12,8 +12,9 @@ // failing, send a non-zero value to RET_PORT to indicate failure #define RET_PORT 0x01 // Port for block reads. Write 2 bytes, MSB first, on that port and then -// read 1024 bytes from the same port. +// read 1024 bytes from the DATA port. #define BLK_PORT 0x03 +#define BLKDATA_PORT 0x04 static int running; static FILE *fp; @@ -44,7 +45,16 @@ static void iowr_ret(uint8_t val) retcode = val; } -static uint8_t iord_blk() +static void iowr_blk(uint8_t val) +{ + blkid <<= 8; + blkid |= val; + if (blkfp != NULL) { + fseek(blkfp, blkid*1024, SEEK_SET); + } +} + +static uint8_t iord_blkdata() { uint8_t res = 0; if (blkfp != NULL) { @@ -56,12 +66,10 @@ static uint8_t iord_blk() return res; } -static void iowr_blk(uint8_t val) +static void iowr_blkdata(uint8_t val) { - blkid <<= 8; - blkid |= val; if (blkfp != NULL) { - fseek(blkfp, blkid*1024, SEEK_SET); + putc(val, blkfp); } } @@ -99,8 +107,9 @@ int main(int argc, char *argv[]) m->iord[STDIO_PORT] = iord_stdio; m->iowr[STDIO_PORT] = iowr_stdio; m->iowr[RET_PORT] = iowr_ret; - m->iord[BLK_PORT] = iord_blk; m->iowr[BLK_PORT] = iowr_blk; + m->iord[BLKDATA_PORT] = iord_blkdata; + m->iowr[BLKDATA_PORT] = iowr_blkdata; // initialize memory for (int i=0; imem[i] = KERNEL[i]; diff --git a/emul/forth/run.fs b/emul/forth/run.fs index 2e6916e..068c0a0 100644 --- a/emul/forth/run.fs +++ b/emul/forth/run.fs @@ -1,14 +1,22 @@ : EFS@ 256 /MOD 3 PC! 3 PC! 1024 0 DO - 3 PC@ + 4 PC@ BLK( I + C! LOOP ; +: EFS! + 256 /MOD 3 PC! 3 PC! + 1024 0 DO + BLK( I + C@ 4 PC! + LOOP +; + : INIT CURRENT @ HERE ! BLK$ ['] EFS@ BLK@* ! + ['] EFS! BLK!* ! RDLN$ Z80A$ LIT< _sys [entry] diff --git a/forth/blk.fs b/forth/blk.fs index d28c259..e4fde66 100644 --- a/forth/blk.fs +++ b/forth/blk.fs @@ -19,11 +19,15 @@ -1 BLK> ! ; +( n -- ) : BLK@ DUP BLK> @ = IF DROP EXIT THEN DUP BLK> ! BLK@* @ EXECUTE ; +( -- ) +: BLK! BLK> @ BLK!* @ EXECUTE ; + : .2 DUP 10 < IF SPC THEN . ; : LIST