Make delete discard the previous character, remove unnecessary output alignment, fix a bug in the copy function, and reword the readme.

This commit is contained in:
CrazyEttin 2022-08-22 23:27:50 +03:00
parent 62329e91d1
commit 807e67c800
2 changed files with 133 additions and 89 deletions

View File

@ -2,8 +2,8 @@
;***
;Save a substitute at the start address
load r0, sub
;Save an end-of-file at the start address
load r0, eof
store buffer + 100, r0
;***
@ -17,9 +17,13 @@ cmdp: load r0, prompt
;Input the command
cleq r0, r0, input
;Check for escape
;Check for control characters
;Escape
load r0, esc
breq r0, r2, cmdp
;End-of-file
load r0, eof
breq r0, r2, end
;Initialise the command and argument
xor r0, r0
@ -267,11 +271,6 @@ cnarg: load r1, ucp
breq r0, r1, read
load r1, lcr
breq r0, r1, read
;Halt
load r1, uch
breq r0, r1, end
load r1, lch
breq r0, r1, end
;Print an error and return to the command prompt
cmderr: cleq r0, r0, error
@ -294,8 +293,8 @@ instrt: cleq r0, r0, prnln
;Escape
load r0, esc
breq r0, r2, instrt
;Substitute
load r0, sub
;End-of-file
load r0, eof
breq r0, r2, cmdp
;Increment the line number
@ -310,16 +309,16 @@ instrt: cleq r0, r0, prnln
;Store the save address
;High byte
load r3, sublod + 1
store subchk + 1, r3
load r3, eoflod + 1
store eofchk + 1, r3
store cmpadr, r3
;Low byte
load r0, sublod + 2
store subchk + 2, r0
load r0, eoflod + 2
store eofchk + 2, r0
store cmpadr + 1, r0
;Save the line
cleq r0, r0, subchk
cleq r0, r0, eofchk
;Insert the next line
breq r0, r0, insln
@ -342,17 +341,17 @@ copy: cleq r0, r0, fend
;Get the save address of the line
;High byte
load r0, sublod + 1
load r0, eoflod + 1
store test1 + 1, r0
store testa + 1, r0
;Low byte
load r0, sublod + 2
load r0, eoflod + 2
store test1 + 2, r0
store testa + 2, r0
;Check for the save end
testa: load r0, 0
load r1, sub
load r1, eof
breq r0, r1, cmdp
;Restore the buffer start address
@ -371,7 +370,7 @@ test1: load r1, 0
;Check for save and buffer ends
;Save end
load r2, sub
load r2, eof
breq r1, r2, test3
;Buffer end
load r2, bfsize
@ -428,9 +427,9 @@ test2: store 0, r1
;Force line end
test3: load r1, test2 + 1
store test5 ,r1
store test5 + 1 ,r1
load r1, test2 + 2
store test5 ,r1
store test5 + 2 ,r1
;Store the CR of a newline in the buffer
load r0, cr
@ -467,17 +466,17 @@ delete: xor r0, r0
;Get the save address of the line
;High byte
load r0, sublod + 1
load r0, eoflod + 1
store stomov + 1, r0
store dchend + 1, r0
;Low byte
load r0, sublod + 2
load r0, eoflod + 2
store stomov + 2, r0
store dchend + 2, r0
;Check for the save end
dchend: load r0, 0
load r1, sub
load r1, eof
breq r0, r1, cmdp
;Increment the line number
@ -495,10 +494,10 @@ dchend: load r0, 0
;Get the save address of the line
;High byte
load r0, sublod + 1
load r0, eoflod + 1
store lodmov + 1, r0
;Low byte
load r0, sublod + 2
load r0, eoflod + 2
store lodmov + 2, r0
;Move the remainder of the text back
@ -506,7 +505,7 @@ lodmov: load r0, 0
stomov: store 0, r0
;Check for the save end
load r1, sub
load r1, eof
breq r0, r1, delend
;Increment the first save address
@ -561,17 +560,17 @@ list: xor r0, r0
;Get the save address of the line
;High byte
load r0, sublod + 1
load r0, eoflod + 1
store chlist + 1, r0
store lchend + 1, r0
;Low byte
load r0, sublod + 2
load r0, eoflod + 2
store chlist + 2, r0
store lchend + 2, r0
;Check for the save end
lchend: load r0, 0
load r1, sub
load r1, eof
breq r0, r1, cmdp
;Print a line number prompt
@ -581,7 +580,7 @@ lchend: load r0, 0
chlist: load r1, 0
;Check for the save end
load r2, sub
load r2, eof
breq r1, r2, prnwln
;Print the character
@ -655,8 +654,8 @@ write: load r0, cstff
;Write
cleq r0, r0, prwr
;Write a substitute
load r0, sub
;Write an end-of-file
load r0, eof
store fffd, r0
;Return to the command prompt
@ -687,18 +686,18 @@ chread: load r1, fffd
;Trailer
chkend: xor r2, r2
brneq r1, r2, chkntp
load r1, sub
load r1, eof
breq r0, r0, chrsto
;Empty tape reader
chkntp: nand r2, r2
brneq r1, r2, chrsto
load r1, sub
load r1, eof
;Store a character
chrsto: store buffer + 100, r1
;Check for the save end
load r2, sub
load r2, eof
breq r1, r2, redend
;Increment the save address
@ -734,10 +733,7 @@ newln: load r0, cr
;***
;Print an error
error: load r0, space
store ffff, r0
store ffff, r0
load r0, qmark
error: load r0, qmark
store ffff, r0
cleq r0, r0, newln
@ -1100,12 +1096,15 @@ input: load r0, bfstrt
inloop: load r1, ffff
;Check for control characters and the buffer end
;Delete
load r2, del
breq r1, r2, delbr
;Escape
load r2, esc
breq r1, r2, escbr
;Substitute
load r2, sub
breq r1, r2, subbr
;End-of-file
load r2, eof
breq r1, r2, eofbr
;Carriage return
load r2, cr
breq r1, r2, crbr
@ -1149,6 +1148,47 @@ chstor: store buffer, r1
;Read the next character
breq r0, r0, inloop
;Print an underscore
delbr: load r2, uscore
store ffff, r2
;Check for buffer start
xor r2, r2
breq r0, r2, inloop
;Decrement the character counter and store it in r3
;Decrement
load r2, cstff
cleq r0, r0, sum
;Store
xor r3, r3
xor r3, r0
;Decrement the buffer address
;High byte
load r0, chstor + 1
load r2, cstff
cleq r0, r0, sum
store chstor + 1, r0
;Low byte
load r0, chstor + 2
load r2, cstff
cleq r0, r0, sum
store chstor + 2, r0
;Add the overflow to the high byte
load r0, chstor + 1
xor r2, r2
xor r2, r1
cleq r0, r0, sum
store chstor + 1, r0
;Reload the character counter to r0
xor r0, r0
xor r0, r3
;Read the next character
breq r0, r0, inloop
;Print a backslash and a newline
;Backslash
escbr: load r0, space
@ -1162,9 +1202,9 @@ escbr: load r0, space
breq r0, r0, inend
;Print a newline
subbr: cleq r0, r0, newln
eofbr: cleq r0, r0, newln
;Return with substitute at r2
;Return with End-of-file at r2
breq r0, r0, inend
;Increment and store the string size
@ -1205,27 +1245,27 @@ inend: ret
;Make room for the line
;Find the end of the save address
;Check for a substitute
subchk: load r0, 0
load r1, sub
;Check for an end-of-file
eofchk: load r0, 0
load r1, eof
breq r0, r1, endfnd
;Load the address
load r0, subchk + 1
load r1, subchk + 2
load r0, eofchk + 1
load r1, eofchk + 2
;Increment
cleq r0, r0, incdw
;Store the address
store subchk + 1, r0
store subchk + 2, r1
store eofchk + 1, r0
store eofchk + 2, r1
;Check the next character
breq r0, r0, subchk
breq r0, r0, eofchk
;Store the end of the save address
;High byte
endfnd: load r3, subchk + 1
endfnd: load r3, eofchk + 1
store movlod + 1, r3
;Low byte
load r0, subchk + 2
load r0, eofchk + 2
store movlod + 2, r0
;Calculate the new end of the save
@ -1249,7 +1289,7 @@ endfnd: load r3, subchk + 1
store movsto + 1, r0
store movsto + 2, r3
;Move the substitute
;Move the End-of-file
movlod: load r0, 0
movsto: store 0, r0
@ -1299,10 +1339,10 @@ save: load r0, bfstrt
;Store the save address
;High byte
load r0, sublod + 1
load r0, eoflod + 1
store chsave + 1, r0
;Low byte
load r0, sublod + 2
load r0, eoflod + 2
store chsave + 2, r0
;Load and save a character from the buffer
@ -1353,23 +1393,23 @@ fend: xor r0, r0
;Get the save start address
;High byte
load r0, svstrt
store sublod + 1, r0
store eoflod + 1, r0
;Low byte
load r0, svstrt + 1
store sublod + 2, r0
store eoflod + 2, r0
;Check for the argument
charg: load r0, target
load r1, lnnum
brneq r0, r1, fsub
brneq r0, r1, feof
load r0, target + 1
load r1, lnnum + 1
breq r0, r1, fendnd
;Check for control characters
;Substitute
fsub: load r0, sub
sublod: load r1, 0
;End-of-file
feof: load r0, eof
eoflod: load r1, 0
breq r0, r1, fendnd
;Line feed
load r2, lf
@ -1387,13 +1427,13 @@ sublod: load r1, 0
;Increment the save address
;Load the address
incsav: load r0, sublod + 1
load r1, sublod + 2
incsav: load r0, eoflod + 1
load r1, eoflod + 2
;Increment
cleq r0, r0, incdw
;Store the address
store sublod + 1, r0
store sublod + 2, r1
store eoflod + 1, r0
store eoflod + 2, r1
;Check the next character
breq r0, r0, charg
@ -1467,7 +1507,7 @@ prwr: load r0, svstrt
chprwr: load r1, buffer + 100
;Check for the save end
load r2, sub
load r2, eof
breq r1, r2, pwend
;Print the character
@ -1519,7 +1559,7 @@ cstff: data ff
bs: data 8
lf: data a
cr: data d
sub: data 1a
eof: data 1a
esc: data 1b
space: data 20
hash: data 23
@ -1551,6 +1591,7 @@ ucr: data 52
ucs: data 53
ucw: data 57
bslash: data 5c
uscore: data 5f
lca: data 61
lcb: data 62
lcc: data 63
@ -1564,6 +1605,7 @@ lcp: data 70
lcr: data 72
lcs: data 73
lcw: data 77
del: data 7f
;Variables
ovrflw: data 0

View File

@ -9,36 +9,38 @@ https://ahti.space/git/crazyettin/Thingamajig.
System requirements
-------------------
Gidubba requires a terminal with local echo at address FFFF and
Gidubba requires a terminal with local echo at address FFFF, and
optionally a line printer at address FFFE and a punched tape reader and
punch at FFFD. If your setup differs from this you may have to modify
the code yourself.
punch or a casette drive at FFFD. If your setup differs from this you
have to modify the code yourself.
Usage
-----
The commands are individual letters that can be followed by one or two
arguments separated by a comma. The first argument is a target line
number between 0 and FFFF and the second the range of lines between 0
and FF the command affects. Inserting lines to a target that does not
exist or the shortcut hash (#) appends them to the text; otherwise
targets or parts of ranges that do not exist are ignored.
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 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.
Commands with a single argument:
* I: Insert a line or lines
* I: Insert lines
Commands with two arguments:
* D: Delete a line
* L: List a line
* D: Delete lines
* L: List lines
Commands with no argument:
Commands with no arguments:
* P: Print
* R: Read from the tape reader
* W: Write to the tape punch
* H: Halt
* R: Read from the tape reader or casette drive
* W: Write to the tape punch or casette drive
Both commands and arguments are case-insensitive. In both the command
prompt as well as when inserting lines sending an escape (^[) will allow
retyping the line in question. To finish inserting lines send a
substitute (^Z): the line on which this is done is not saved.
A delete (^?) discards the preceding character if any and outputs an
underscore to the terminal. An escape (^[) discards the current command
or line and gives a prompt for retyping it. An end-of-file (^Z) discards
the current command and halts the computer or discards the current line
and returns to the command prompt.