From 339f117e582fb482fa243c0fca48f075c0321253 Mon Sep 17 00:00:00 2001 From: CrazyEttin <> Date: Fri, 9 Sep 2022 18:27:36 +0300 Subject: [PATCH] Version 1.0: add checking for sufficient RAM and fix a bug where copying to the same address as the mark would not work --- gidubba.asm | 140 +++++++++++++++++++++++++++++++++++++++++++++++----- readme.md | 17 ++++--- 2 files changed, 138 insertions(+), 19 deletions(-) diff --git a/gidubba.asm b/gidubba.asm index 02517db..967163c 100644 --- a/gidubba.asm +++ b/gidubba.asm @@ -2,6 +2,32 @@ ;*** + ;Check the RAM size + + ;Initialise the comparison value + load r0, #1b + + ;Check a memory location +mchks: store ffef, r0 +mchkl: load r1, ffef + breq r0, r1, svlmit + + ;Decrement the pointer + load r0, mchks + 1 + load r2, #fc + cleq r0, r0, sum + store mchks + 1, r0 + store mchkl + 1, r0 + + ;Check the next location + breq r0, r0, mchks + + ;Save the RAM limit +svlmit: load r0, mchks + 1 + store limit, r0 + + ;*** + ;Save an end-of-file at the start address load r0, #1a store buffer + 100, r0 @@ -273,7 +299,9 @@ cnarg: load r1, #50 breq r0, r1, read ;Print an error and return to the command prompt -cmderr: cleq r0, r0, error +cmderr: load r0, #3f + store ffff, r0 + cleq r0, r0, newln breq r0, r0, cmdp cmdesc: load r0, #20 @@ -335,8 +363,12 @@ inline: cleq r0, r0, input store eofchk + 2, r0 store cmpadr + 1, r0 - ;Save the line + ;Make room for the line cleq r0, r0, eofchk + xor r0, r0 + brneq r0, r1, cmdp + + ;Save the line cleq r0, r0, save ;Insert the next line @@ -497,6 +529,8 @@ chsend: load r0, 0 ;Make room for the copy cleq r0, r0, eofchk + xor r0, r0 + brneq r0, r1, cmdp ;Check for the end of the space cendsp: load r0, movsto + 1 @@ -557,6 +591,9 @@ relodt: load r0, tmp1 ;Copy a character ;Load cload: load r1, 0 + ;Check for a null + xor r2, r2 + breq r1, r2, skip0 ;Check for save end load r2, #1a breq r1, r2, cmdp @@ -601,6 +638,19 @@ cincs: load r0, cload + 1 ;Load and save the next character breq r0, r0, cload + ;Increment the source address + ;Load the address +skip0: load r0, cload + 1 + load r1, cload + 2 + ;Increment + cleq r0, r0, incdw + ;Store the address + store cload + 1, r0 + store cload + 2, r1 + + ;Load the next character + breq r0, r0, cload + ;*** ;Delete a line @@ -845,6 +895,24 @@ iglead: load r1, fffd breq r1, r2, iglead breq r0, r0, chkend + ;Check for the RAM limit + load r0, chrsto + 1 + load r1, chrsto + 2 +chkram: load r2, limit + load r3, limit + 1 + brneq r0, r2, chread + brneq r1, r3, chread + + ;Save an end-of-file at the start address + load r0, #1a + store buffer + 100, r0 + + ;Print an error and return to the command prompt + load r0, #21 + store ffff, r0 + cleq r0, r0, newln + breq r0, r0, cmdp + ;Read a character chread: load r1, fffd @@ -877,7 +945,7 @@ chrsto: store buffer + 100, r1 store chrsto + 2, r1 ;Read the next character - breq r0, r0, chread + breq r0, r0, chkram ;Return to the command prompt redend: breq r0, r0, cmdp @@ -898,13 +966,6 @@ newln: load r0, #d ;*** - ;Print an error -error: load r0, #3f - store ffff, r0 - cleq r0, r0, newln - - ;*** - ;Add r2 to r0 with the overflow stored in r1 ;Reset overflow @@ -1454,6 +1515,9 @@ endfnd: load r0, eofchk + 1 load r2, strsz cleq r0, r0, sum store strsz, r0 + ;Check for overflow from the high byte + xor r0, r0 + brneq r0, r1, lmterr ;Low byte xor r0, r0 xor r0, r3 @@ -1469,6 +1533,48 @@ endfnd: load r0, eofchk + 1 store movsto + 1, r0 load r3, strsz + 1 store movsto + 2, r3 + ;Check for overflow from the high byte + xor r0, r0 + brneq r0, r1, lmterr + + ;Negate the RAM limit + ;Low byte + load r0, limit + 1 + nand r0, r0 + load r2, #1 + cleq r0, r0, sum + store tmp2 + 1, r0 + ;Reverse and add the overflow to the high byte + load r0, limit + nand r0, r0 + xor r2, r2 + xor r2, r1 + cleq r0, r0, sum + store tmp2, r0 + + ;Subtract the RAM limit from the new end of the save + ;High byte + load r0, movsto + 1 + load r2, tmp2 + cleq r0, r0, sum + store tmp2, r0 + ;Check for overflow from the high byte + xor r0, r0 + brneq r0, r1, lmterr + ;Low byte + load r0, movsto + 2 + load r2, tmp2 + 1 + cleq r0, r0, sum + store tmp2 + 1, r0 + ;Add the overflow to the high byte + load r0, tmp2 + xor r2, r2 + xor r2, r1 + cleq r0, r0, sum + store tmp2, r0 + ;Check for overflow from the high byte + xor r0, r0 + brneq r0, r1, lmterr ;Move the End-of-file movlod: load r0, 0 @@ -1506,8 +1612,16 @@ decsav: load r0, movlod + 1 ;Move the next character breq r0, r0, movlod - ;Return -roomnd: ret + ;Return with a null at r1 +roomnd: xor r1, r1 + ret + + ;Print an error and return with an exclamation mark at r1 +lmterr: load r0, #21 + store ffff, r0 + cleq r0, r0, newln + load r1, #21 + ret ;*** @@ -1739,6 +1853,8 @@ tmp2: data 0 bfstrt: addr buffer bfsize: data fe svstrt: addr buffer + 100 +limit: data 0 + data 0 buffer:  \ No newline at end of file diff --git a/readme.md b/readme.md index cd2d8f3..8e99b8a 100644 --- a/readme.md +++ b/readme.md @@ -1,5 +1,5 @@ -Gidubba -======= +Gidubba v1.0 +============ Gidubba (Sumerian for 'stylus') is a simple line editor for the Thingamajig computer architecture. Its git repository can be found at @@ -9,11 +9,11 @@ https://ahti.space/git/crazyettin/Thingamajig. System requirements ------------------- -Gidubba requires a setup with at least 4 KiB of RAM. It uses a terminal -with local echo at address FFFF, and optionally a character printer at -address FFFE and a punched tape reader and punch or a casette drive at -FFFD. Do not be afraid to modify the code yourself if your setup -requires it! (And if you do, apologies for the horrible code.) +Gidubba requires at least 4 KiB of RAM. It uses a terminal with local +echo at address FFFF, and optionally a character printer at address FFFE +and a punched tape reader and punch or a casette drive at FFFD. Do not +be afraid to modify the code yourself if your setup requires it! (And if +you do, apologies for the spaghetti.) Format ------ @@ -57,4 +57,7 @@ carriage return (^M) or a line feed (^J) inputs a newline and commits the current command or line. An end-of-file (^Z) discards the current command and halts the computer or discards the current line and returns to the command prompt. + +There are two kinds of error messages: a question mark (?) for an +erroneous command and an exclamation mark (!) for lack of RAM.  \ No newline at end of file