From 25f43125230173aa9908e82916255c4b2e7f9d57 Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Fri, 7 Aug 2020 21:03:28 -0400 Subject: [PATCH] cvm: improve comments They were a bit terse. --- cvm/vm.c | 15 +++++++++++++++ cvm/vm.h | 24 +++++++++++++----------- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/cvm/vm.c b/cvm/vm.c index c1834ac..021a404 100644 --- a/cvm/vm.c +++ b/cvm/vm.c @@ -21,6 +21,8 @@ static VM vm; static uint64_t blkop = 0; // 5 bytes static FILE *blkfp; +// Read single byte from I/O handler, if set. addr is a word only because of +// Forth's cell size, but can't actually address more than a byte-ful of ports. static byte io_read(word addr) { addr &= 0xff; @@ -44,6 +46,9 @@ static void io_write(word addr, byte val) } } +// I/O hook to read/write a chunk of 1024 byte to blkfs at specified blkid. +// This is used by EFS@ and EFS! in xcomp.fs. +// See comment above BLK_PORT define for poking convention. static void iowr_blk(byte val) { blkop <<= 8; @@ -62,29 +67,37 @@ static void iowr_blk(byte val) } } +// get/set word from/to memory static word gw(word addr) { return vm.mem[addr+1] << 8 | vm.mem[addr]; } static void sw(word addr, word val) { vm.mem[addr] = val; vm.mem[addr+1] = val >> 8; } +// pop word from SP static word pop() { if (vm.uflw) return 0; if (vm.SP >= SP_ADDR) { vm.uflw = true; } return vm.mem[vm.SP++] | vm.mem[vm.SP++] << 8; } +// push word to SP static void push(word x) { vm.SP -= 2; sw(vm.SP, x); if (vm.SP < vm.minSP) { vm.minSP = vm.SP; } } +// pop word from RS static word popRS() { if (vm.uflw) return 0; if (vm.RS <= RS_ADDR) { vm.uflw = true; } word x = gw(vm.RS); vm.RS -= 2; return x; } +// push word to RS static void pushRS(word val) { vm.RS += 2; sw(vm.RS, val); if (vm.RS > vm.maxRS) { vm.maxRS = vm.RS; } } + +// The functions below directly map to native forth words defined in the +// dictionary (B30) static void execute(word wordref) { byte wtype = vm.mem[wordref]; if (wtype == 0) { // native @@ -242,6 +255,7 @@ static void MINUS2() { push(pop()-2); } static void PLUS2() { push(pop()+2); } static void RSHIFT() { word u = pop(); push(pop()>>u); } static void LSHIFT() { word u = pop(); push(pop()<