Take the SplitLint findings that are one operation, leave the rest

Twenty four more sites, and the interesting part is which ones were left
alone. A rule emerged while reading them and it held all the way through:
apply where the repetition is INSIDE one operation, skip where the author's
own structure says it is a new thought, and never where two equal values
mean different things.

Taken:

- Five registers reassigned to a value they already held, where both are
  the same quantity: two masks in one expression in Snake, two spaces
  printed by the monitor, both halves of block zero in waitTest, and a RSTA
  in Pour that the very next instruction overwrote.
- Eighteen SETDs that reload a pointer inside one operation - a store back
  into the variable just read, or an INCD stepping to the second byte of a
  two byte value. Those read correctly without the reload.
- sbfsNext, which branched to the label on the line below it.

Left, with reasons that are the useful part of this:

- Eight registers where the same number means two different things. CosmOS
  and the loader set A to 1 for a blit command and then to 1 again for a
  bank number; Asm compares a type against 3 and then a status against 3.
  Removing those couples one quantity to another that is equal by accident
  and would part company silently.
- Ten RSTAs that open the RSTA/RSTB/CCF/ADD "return zero" block. The
  redundancy is what makes that idiom self contained; taking it out makes
  the return value depend on the line above.
- Eleven SETDs that begin an arm of a comparison chain. Each arm loads,
  compares and branches, and they get reordered - the repetition is the
  reason a new arm can be dropped in anywhere.
- Twenty five SETDs separated from their pointer by a blank line or a
  comment, which is the author saying a new thought starts here.
- Two CCFs before arithmetic, which this codebase writes unconditionally.
- Three redundant branches in test programs whose recorded output includes
  addresses, where three fewer bytes moves what the test demonstrates.

Nine recorded outputs moved and every one is a size in a listing or, for
Life, five more generations inside the same cycle budget. Behaviour is
unchanged everywhere: cosmosSnake and cosmosEdit pass byte for byte while
Snake loses eight bytes and Edit twelve.

CosmOS is 10,902 bytes of program against 10,937, and the native assembler
12,173 against 12,183. The CosmOS README's size for Edit moved twice in one
sitting, and this morning's check caught it both times - which it could not
have done before that claim was reworded to name what it was about.
This commit is contained in:
Anachronaut
2026-08-26 18:02:35 -04:00
parent e1273337c4
commit 9c144469b4
15 changed files with 9 additions and 32 deletions
-2
View File
@@ -529,7 +529,6 @@ listStep:
PSHD.3
POPD.0
DPUP.0 0d03
SETD.1 Leftover
LDA.1
BRA listEmpty
listChars:
@@ -723,7 +722,6 @@ writeOut:
CCF
SUB
MVQA
SETD.0 WroteSize
STA.0 ; WroteSize is now a count of bytes, which is what gets printed.
; And into the two registers the service takes a size in.
-3
View File
@@ -34,7 +34,6 @@ counted:
LDA.0
BNA haveCount
INIA 0d1
SETD.0 Blocks
STA.0
haveCount:
@@ -159,7 +158,6 @@ countLoop:
SETD.1 Blocks
LDB.1
PSHA
RSTA
INIA 0d10
CALL timesTen
POPA
@@ -191,7 +189,6 @@ tenLoop:
CCF
ADD
MVQA
SETD.0 Scratch
STA.0
POPA
DECA
-3
View File
@@ -334,7 +334,6 @@ takeKeyTurn:
XOR
POPA
BRQ takeKeyDone ; Opposite, so it is not a turn anybody can make.
SETD.0 Direction
STA.0
RET
@@ -430,7 +429,6 @@ stepDown:
INIB 0xF0
AND
MVQA
INIB 0xF0
XOR
POPA
BRQ stepWall ; The bottom row is where the high nibble is fifteen.
@@ -453,7 +451,6 @@ stepRight:
INIB 0x0F
AND
MVQA
INIB 0x0F
XOR
POPA
BRQ stepWall
-3
View File
@@ -1277,7 +1277,6 @@ dropColon:
LDA.0
BRA dropColonDone
DECA
SETD.0 TokLength
STA.0
SETD.0 TokText
SETD.1 DropWalk
@@ -1525,7 +1524,6 @@ checkImageRoom:
LDA.1
SETD.0 ImgOutBlocks
STA.0 ; The high half is whole blocks.
SETD.1 ImgAsk
INCD.1
LDA.1
SETD.0 ImgOutTail
@@ -2034,7 +2032,6 @@ writeImage:
LDA.1
SETD.0 ImgOutBlocks
STA.0
SETD.1 ImgTotal
INCD.1
LDA.1
SETD.0 ImgOutTail
-1
View File
@@ -189,7 +189,6 @@ vecReadFields:
STA.1
INCD.0
LDA.0
SETD.1 VecHandler
INCD.1
STA.1
INCD.0
+1 -1
View File
@@ -462,7 +462,7 @@ Typed in as bytes, checked by disassembling it back, and run. It ends with `SWI
`Edit` is the first program on this machine that makes a file a person typed - every byte on every disk before it was put there by the host tool. It is line oriented in the manner of `ed`: `l` lists, `a` adds at the end, `i` and `c` and `d` take a line number, `w` writes and `q` stops.
It includes nothing but `services.asm` and `text.asm`: the filesystem and the console are the system's, asked for rather than carried. That is what brought `Edit` down from 4,941 bytes to 1,995 bytes without a line of its own logic changing - and the way that was checked is worth knowing, because the recorded output of the `cosmosEdit` test did not move by a single byte across the rewrite.
It includes nothing but `services.asm` and `text.asm`: the filesystem and the console are the system's, asked for rather than carried. That is what brought `Edit` down from 4,941 bytes to 1,983 bytes without a line of its own logic changing - and the way that was checked is worth knowing, because the recorded output of the `cosmosEdit` test did not move by a single byte across the rewrite.
It keeps the document as a **linked list of lines** rather than one buffer with newlines in it. Each line says where the next one is, how long it is, and then its bytes. Inserting is two pointers changed and nothing moved; with a flat buffer it would mean shifting every byte after the edit, on a machine whose only block move is a device asked politely. The price is that deleted lines are not reused, so a heavy session uses more room than the document needs and writing it out is what tidies up.
-8
View File
@@ -402,7 +402,6 @@ dirCheck:
STA.1
SETD.0 SbfsFileTail
LDA.0
SETD.1 DirSize
INCD.1
STA.1
@@ -446,12 +445,10 @@ dirDone:
STA.1
SETD.0 DirSeen
LDA.0
SETD.1 DirTaken
LDB.1
CCF
SUB
MVQA
SETD.0 DirSeen
STA.0
SETD.0 DirSeen
@@ -2327,7 +2324,6 @@ bankSet:
LDB.0
SETD.1 BankWas
STB.1
SETD.0 DumpBank
STA.0
; Naming a bank puts the cursor at the start of it, which is the only answer that does
@@ -2390,10 +2386,8 @@ showAt:
LDA.0
SETD.1 DumpAt
STA.1
SETD.0 TextValue
INCD.0
LDA.0
SETD.1 DumpAt
INCD.1
STA.1
@@ -2694,7 +2688,6 @@ showInstruction:
CALL printByteHex
INIA 0x20
OUTA 0x00
INIA 0x20
OUTA 0x00
CALL aimAtDumpAt
@@ -3210,7 +3203,6 @@ takeMnemonicPad:
INIA 0x20
STA.1
INCD.1
SETD.2 AsmLeft
LDA.2
DECA
STA.2
+3 -3
View File
@@ -943,10 +943,10 @@ sbfsFirst:
STA.0
BRI sbfsWalkScan
; The pointer and the count were stepped when the last entry was handed out, so there is
; nothing to do here but carry on looking - which is what the next label does, so this one
; falls into it rather than branching to the line below itself.
sbfsNext:
; The pointer and the count were stepped when the last entry was handed out, so there
; is nothing to do here but carry on looking.
BRI sbfsWalkScan
sbfsWalkScan:
; Anything left in the block in hand?
-1
View File
@@ -272,7 +272,6 @@ textNumberLoop:
POPB
CCF
ADD ; And the digit.
SETD.1 TextValue
STQ.1
SETD.1 TextDigits
-1
View File
@@ -66,7 +66,6 @@ walkCheck:
STA.1
SETD.0 SbfsFileTail
LDA.0
SETD.1 Size
INCD.1
STA.1
-1
View File
@@ -26,7 +26,6 @@ start:
OUTA 0xE8
RSTA
OUTA 0x20
RSTA
OUTA 0x21
INIA 0x01
OUTA 0x22