commit e46d1e91958eefe8f337e549a11235feff303f86
parent 970c6f919df56e1b85d0580ed2c6bcc2fb6849e6
Author: Luxferre <lux@ferre>
Date: Sat, 13 Aug 2022 10:58:02 +0300
Revamped persistent storage ops to Forth-like 1K-aligned blocks
Diffstat:
2 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/README.md b/README.md
@@ -22,7 +22,7 @@ Main features of an Equi machine:
- Minification mode (MM) flag;
- 16-bit input buffer pointer;
- 42752 bytes of main RAM (0x0000-0xa6ff), 41984 bytes of which are available for the program and data and 768 bytes hold the three stacks and necessary service registers listed above;
-- Up to 4GB flat persistent storage (tape, disk, flash etc);
+- Up to 64 MiB flat persistent storage (tape, disk, flash etc);
- Serial terminal input and output;
- Up to 65535 peripheral extension ports, including several virtual ports.
@@ -116,8 +116,8 @@ Op |Stack state |Meaning
`,`|`( -- a ) ` |Non-blocking key input of an ASCII (or Unicode, if supported) value from the standard terminal
`?`|`( -- a ) ` |Blocking key input of an ASCII (or Unicode, if supported) value from the standard terminal
`P`|`( p1 p2 port -- r1 r2 status )`|**P**ort I/O: pass two 16-bit parameters to the port and read the operation status and results into the words on the stack top
-`}`|`( adh adl len maddr -- status)`|Persistent storage write operation. Stack parameters: persistent address high 2 bytes, low 2 bytes, data length, RAM address
-`{`|`( adh adl len maddr -- status)`|Persistent storage read operation. Stack parameters: persistent address high 2 bytes, low 2 bytes, data length, RAM address
+`}`|`( blk len maddr -- status)` |Persistent storage write operation. Stack parameters: block number (x1K), data length, RAM address
+`{`|`( blk len maddr -- status)` |Persistent storage read operation. Stack parameters: block number (x1K), data length, RAM address
`Q`|`( -- )` |**Q**uit the interpretation mode (unset IM flag if set), or the interpreter shell itself if in command mode (halt the machine when it's nowhere to exit to)
Note that, due to the dynamic nature of word allocation and ability to reconfigure the runtime environment for different offsets depending on the target, absolute jumps are not directly supported in Equi and generally not recommended, although one can easily do them with `]R` sequence and/or calculate absolute positions using `X` instruction.
diff --git a/equi.c b/equi.c
@@ -323,10 +323,10 @@ ushort tobig(ushort val) {
/* Persistent operation handler */
-ushort persistOp(FILE *pfd, ushort maddr, ushort dataLen, ushort adl, ushort adh, uchar isWrite) {
+ushort persistOp(FILE *pfd, ushort maddr, ushort dataLen, ushort blk, uchar isWrite) {
ushort status = 0, proc;
if(pfd) {
- fseek(pfd, ((unsigned long) adh << 16) | adl, SEEK_SET);
+ fseek(pfd, ((unsigned long) blk << 10), SEEK_SET); /* blocks are 1K-aligned */
if(isWrite) /* writing to the persistent area from the memory */
proc = (ushort) fwrite(&flatram[maddr], 1, dataLen, pfd);
else /* reading from the persistent area into the memory */
@@ -568,11 +568,11 @@ void equi_main_loop() {
trapout(STACK_UNDERFLOW);
portIO(popMain(), popMain(), popMain());
break;
- case INS_PERSIST_READ: /* ( adh adl len maddr -- status) */
- pushMain(persistOp(pfd, popMain(), popMain(), popMain(), popMain(), 0));
+ case INS_PERSIST_READ: /* ( blk len maddr -- status) */
+ pushMain(persistOp(pfd, popMain(), popMain(), popMain(), 0));
break;
- case INS_PERSIST_WRITE: /* ( adh adl len maddr -- status) */
- pushMain(persistOp(pfd, popMain(), popMain(), popMain(), popMain(), 1));
+ case INS_PERSIST_WRITE: /* ( blk len maddr -- status) */
+ pushMain(persistOp(pfd, popMain(), popMain(), popMain(), 1));
break;
default: /* all characters not processed before are invalid instructions */
trapout(INVALID_INSTRUCTION);