Fix the same speed issues as with inserting, listing, and deleting lines with copying them

This commit is contained in:
CrazyEttin 2022-09-05 20:30:57 +03:00
parent 0e4dbc6b68
commit 47d2589da1
2 changed files with 203 additions and 205 deletions

View File

@ -286,7 +286,7 @@ cmdesc: load r0, #20
;Insert a line
;Reset the line number
insln: xor r0, r0
insln: xor r0, r0
store lnnum, r0
store lnnum + 1, r0
@ -337,6 +337,7 @@ inline: cleq r0, r0, input
;Save the line
cleq r0, r0, eofchk
cleq r0, r0, save
;Insert the next line
breq r0, r0, nextln
@ -363,7 +364,7 @@ setmrk: load r0, target
;Copy to mark
;Check the counter
;Check for an empty counter
copy: xor r0, r0
load r1, count
breq r0, r1, cmdp
@ -387,11 +388,11 @@ copy: xor r0, r0
;Get the save address of the line
;High byte
load r0, eoflod + 1
store readch + 1, r0
store strsz, r0
store chsend + 1, r0
;Low byte
load r0, eoflod + 2
store readch + 2, r0
store strsz + 1, r0
store chsend + 2, r0
;Check for the save end
@ -399,119 +400,64 @@ chsend: load r0, 0
load r1, #1a
breq r0, r1, cmdp
;Restore the buffer start address
;High byte
load r0, bfstrt
store stoch + 1, r0
;Save the buffer address to tmp1 and increment it
;Low byte
load r0, bfstrt + 1
store stoch + 2, r0
;Initialise the character counter
xor r0, r0
;Read a character
readch: load r1, 0
;Check for save and buffer ends
;Save end
load r2, #1a
breq r1, r2, feol
;Buffer end
load r2, bfsize
breq r0, r2, feol
;Store the character in the buffer
stoch: store 0, r1
;Check for line and save ends
;Line end
load r2, #a
breq r1, r2, incsz
;Increment the character counter and store it in r3
;Increment
load r2, #1
cleq r0, r0, sum
;Store
xor r3, r3
xor r3, r0
;Increment the save address
;Low byte
load r0, readch + 2
load r2, #1
cleq r0, r0, sum
store readch + 2, r0
;Add the overflow to the high byte
load r0, readch + 1
xor r2, r2
xor r2, r1
cleq r0, r0, sum
store readch + 1, r0
;Increment the buffer address
;Low byte
load r0, stoch + 2
load r2, #1
cleq r0, r0, sum
store stoch + 2, r0
;Add the overflow to the high byte
load r0, stoch + 1
xor r2, r2
xor r2, r1
cleq r0, r0, sum
store stoch + 1, r0
;Reload the character counter to r0
xor r0, r0
xor r0, r3
;Read the next character
breq r0, r0, readch
;Increment and store the string size
feol: load r2, #2
cleq r0, r0, sum
store strsz, r0
;Force line end
load r1, stoch + 1
store stocr + 1 ,r1
load r1, stoch + 2
store stocr + 2 ,r1
;Store the CR of a newline in the buffer
load r0, #d
stocr: store 0, r0
;Increment the buffer address
;Load the address
load r0, stoch + 1
load r1, stoch + 2
;Increment
cleq r0, r0, incdw
;Store the address
store stolf + 1, r0
store stolf + 2, r1
;Store the LF of a newline in the buffer
load r0, #a
stolf: store 0, r0
;Jump to saving
breq r0, r0, svtarg
;Increment and store the string size
incsz: load r2, #1
cleq r0, r0, sum
store strsz, r0
;Save the target at tmp
svtarg: load r0, target
store tmp, r0
load r0, target + 1
store tmp + 1, r0
store tmp1 + 1, r0
load r2, count
cleq r0, r0, sum
store target + 1, r0
;Add the overflow to the high byte
load r0, target
store tmp1, r0
xor r2, r2
xor r2, r1
cleq r0, r0, sum
store target, r0
;Find the next line in the save and store its number
cleq r0, r0, fend
;Get the save address of the line
;High byte
load r0, eoflod + 1
store tmp2, r0
;Low byte
load r0, eoflod + 2
store tmp2 + 1, r0
;Negate the first address
;Low byte
load r0, strsz + 1
nand r0, r0
load r2, #1
cleq r0, r0, sum
store strsz + 1, r0
;Reverse and add the overflow to the high byte
load r0, strsz
nand r0, r0
xor r2, r2
xor r2, r1
cleq r0, r0, sum
store strsz, r0
;Get the copy length
;High byte
load r0, tmp2
load r2, strsz
cleq r0, r0, sum
store strsz, r0
;Low byte
load r0, tmp2 + 1
load r2, strsz + 1
cleq r0, r0, sum
store strsz + 1, r0
;Reverse and add the overflow to the high byte
load r0, strsz
xor r2, r2
xor r2, r1
cleq r0, r0, sum
store strsz, r0
;Load the mark to target
load r0, mark
@ -540,77 +486,120 @@ svtarg: load r0, target
load r3, eoflod + 1
store eofchk + 1, r3
store cmpadr, r3
store cstor + 1, r3
store cinit + 1, r3
;Low byte
load r0, eoflod + 2
store eofchk + 2, r0
store cmpadr + 1, r0
store cstor + 2, r0
store cinit + 2, r0
;Save the marked line
;Make room for the copy
cleq r0, r0, eofchk
;Loop
;Check for the end of the space
cendsp: load r0, movsto + 1
load r1, cinit + 1
brneq r0, r1, cinist
load r0, movsto + 2
load r1, cinit + 2
brneq r0, r1, cinist
breq r0, r1, relodt
;Initialise a character
cinist: load r0, #0
cinit: store 0, r0
;Increment the source address
;Load the address
incini: load r0, cinit + 1
load r1, cinit + 2
;Increment
cleq r0, r0, incdw
;Store the address
store cinit + 1, r0
store cinit + 2, r1
;Initialise the next character
breq r0, r0, cendsp
;Reload the target from tmp1
relodt: load r0, tmp1
store target, r0
load r0, tmp1 + 1
store target + 1, r0
;Reset the line number
xor r0, r0
store lnnum, r0
store lnnum + 1, r0
;Get the save start address
;High byte
load r0, svstrt
store eoflod + 1, r0
;Low byte
load r0, svstrt + 1
store eoflod + 2, r0
;Find the marked line in the save and store its number
cleq r0, r0, fend
;Store the save address
;High byte
load r3, eoflod + 1
store cload + 1, r3
;Low byte
load r0, eoflod + 2
store cload + 2, r0
;Copy a character
;Load
cload: load r1, 0
;Check for save end
load r2, #1a
breq r1, r2, cmdp
;Save
cstor: store 0, r1
;Check for line end
load r2, #a
brneq r1, r2, cincs
;Decrement the counter
load r0, count
load r2, #ff
cleq r0, r0, sum
store count, r0
;Check if the mark is a hash
load r2, #ff
load r0, target
brneq r0, r2, incmrk
load r1, target + 1
breq r1, r2, incln
;Increment the mark
incmrk: load r1, target + 1
cleq r0, r0, incdw
store mark, r0
store mark + 1, r1
;Increment the line number
incln: load r0, tmp
load r1, tmp + 1
cleq r0, r0, incdw
store target, r0
store target + 1, r1
;Check if the mark is less than the line number
;Negate the mark and store in tmp
load r0, mark
nand r0, r0
load r1, mark + 1
nand r1, r1
cleq r0, r0, incdw
store tmp, r0
store tmp + 1, r1
;Add the high bytes
load r0, target
load r2, tmp
cleq r0, r0, sum
store tmp, r0
;Store the overflow in r3
xor r3, r3
xor r3, r1
;Add the low bytes
load r0, target + 1
load r2, tmp + 1
cleq r0, r0, sum
;Add the overflow to the high byte
load r0, tmp
xor r2, r2
xor r2, r1
cleq r0, r0, sum
;Check
xor r1, r3
xor r3, r3
breq r1, r3, cpend
;Re-increment the mark
load r0, target
load r1, target + 1
cleq r0, r0, incdw
store target, r0
store target + 1, r1
;Check the counter
xor r0, r0
load r1, count
breq r0, r1, cmdp
;Loop
cpend: breq r0, r0, copy
;Increment the source address
;Load the address
cincs: load r0, cload + 1
load r1, cload + 2
;Increment
cleq r0, r0, incdw
;Store the address
store cload + 1, r0
store cload + 2, r1
;Increment the copy address
;Load the address
load r0, cstor + 1
load r1, cstor + 2
;Increment
cleq r0, r0, incdw
;Store the address
store cstor + 1, r0
store cstor + 2, r1
;Load and save the next character
breq r0, r0, cload
;***
@ -1401,6 +1390,8 @@ lfbr: load r1, #d
;Increment and store the string size
endnl: load r2, #2
cleq r0, r0, sum
store strsz + 1, r0
load r0, #0
store strsz, r0
;Get the buffer address
@ -1452,31 +1443,31 @@ eofchk: load r0, 0
;Store the end of the save address
;High byte
endfnd: load r3, eofchk + 1
store movlod + 1, r3
endfnd: load r0, eofchk + 1
store movlod + 1, r0
;Low byte
load r0, eofchk + 2
store movlod + 2, r0
load r3, eofchk + 2
store movlod + 2, r3
;Calculate the new end of the save
;Increment the low byte
;High byte
load r2, strsz
cleq r0, r0, sum
;Move the high byte to r2
xor r2, r2
xor r2, r3
;Store the low byte to r3
xor r3, r3
xor r3, r0
;Load the high byte to r0
store strsz, r0
;Low byte
xor r0, r0
xor r0, r2
xor r0, r3
load r2, strsz + 1
cleq r0, r0, sum
store strsz + 1, r0
;Add the overflow to the high byte
load r0, strsz
xor r2, r2
xor r2, r1
cleq r0, r0, sum
;Store the new end of the save
store movsto + 1, r0
load r3, strsz + 1
store movsto + 2, r3
;Move the End-of-file
@ -1490,7 +1481,7 @@ movsto: store 0, r0
load r0, cmpadr + 1
load r1, movlod + 2
brneq r0, r1, decsav
breq r0, r1, save
breq r0, r1, roomnd
;Decrement the old save address
;load the address
@ -1515,6 +1506,9 @@ decsav: load r0, movlod + 1
;Move the next character
breq r0, r0, movlod
;Return
roomnd: ret
;***
;Save the line
@ -1715,6 +1709,7 @@ ovrflw: data 0
lnnum: data 0
data 0
strsz: data 0
data 0
dgtcnt: data 0
dgtadr: addr buffer + 2
cmd: data 0
@ -1735,7 +1730,9 @@ mrkadr: data 0
data 0
cmpadr: data 0
data 0
tmp: data 0
tmp1: data 0
data 0
tmp2: data 0
data 0
;Buffer and save

View File

@ -1,5 +1,5 @@
Gidubba
========
=======
Gidubba (Sumerian for 'stylus') is a simple line editor for the
Thingamajig computer architecture. Its git repository can be found at
@ -9,19 +9,19 @@ https://ahti.space/git/crazyettin/Thingamajig.
System requirements
-------------------
Gidubba 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!
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.)
Format
------
Gidubba works with texts consisting of lines and terminated with an
end-of-file (^Z). The lines consist of at most 256 characters terminated
by a newline of a carriage return (^M) followed by a line feed (^J),
included in the character count. Note that any characters following the
last newline and preceding the end-of-file are ignored.
Texts are terminated by an end-of-file (^Z) and lines within them by a
newline of a carriage return (^M) followed by a line feed (^J). Note
that the input buffer can store at most 256 characters, including the
newline.
Usage
-----
@ -29,14 +29,16 @@ Usage
The commands are individual letters that can be followed by one or two
arguments separated by a comma, all case-insensitive. The first argument
is a line number between 0 and FFFF and the second a range of lines
between 0 and FF. To append lines, insert or copy them to any line
number after the text or to the shortcut hash (#); in other commands
line numbers or parts of a range after the text are ignored. Instead of
a predetermined range a prompt to insert the next line appears
automatically after the previous one has been committed.
between 0 and FF. To append lines, insert them or set the mark to any
line number after the text or to the shortcut hash (#); in other
commands line numbers or parts of a range after the text are ignored and
a hash is not recognised as a valid argument. Instead of a predetermined
range a prompt to insert the next line appears automatically after the
previous one has been committed.
Commands with a single argument:
* I: Insert lines
* M: Set the mark
Commands with two arguments:
* C: Copy to the mark
@ -44,15 +46,14 @@ Commands with two arguments:
* L: List lines
Commands with no arguments:
* M: Set a mark
* P: Print
* R: Read from the tape reader or casette drive
* W: Write to the tape punch or casette drive
A delete (^?) discards the preceding character and outputs an underscore
to the terminal. An escape (^[) discards the contents of the current
command or line and outputs a backslash and a newline to the terminal.
A carriage return (^M) or a line feed (^J) inputs a newline that commits
command or line and outputs a backslash and a newline to the terminal. A
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.