From 9c144469b46fa2513f4e984ee1f410cc09ea8ec1 Mon Sep 17 00:00:00 2001 From: Anachronaut Date: Wed, 26 Aug 2026 18:02:35 -0400 Subject: [PATCH] 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. --- Programs/CosmOS/Apps/Edit.asm | 2 -- Programs/CosmOS/Apps/Pour.asm | 3 --- Programs/CosmOS/Apps/Snake.asm | 3 --- Programs/CosmOS/Assembler/Asm.asm | 3 --- Programs/CosmOS/Assembler/vectors.asm | 1 - Programs/CosmOS/README.md | 2 +- Programs/CosmOS/Source/cosmos.asm | 8 -------- Programs/CosmOS/Source/sbfs.asm | 6 +++--- Programs/CosmOS/Source/text.asm | 1 - Programs/testPrograms/sbfsWalkTest.asm | 1 - Programs/testPrograms/waitTest.asm | 1 - Tests/expected/cosmosMonitor.out | 2 +- Tests/expected/cosmosRun.out | 2 +- Tests/expected/cosmosSlowDisk.out | 2 +- Tests/expected/cosmosTreeWrite.out | 4 ++-- 15 files changed, 9 insertions(+), 32 deletions(-) diff --git a/Programs/CosmOS/Apps/Edit.asm b/Programs/CosmOS/Apps/Edit.asm index be4b28f..ddc3cde 100644 --- a/Programs/CosmOS/Apps/Edit.asm +++ b/Programs/CosmOS/Apps/Edit.asm @@ -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. diff --git a/Programs/CosmOS/Apps/Pour.asm b/Programs/CosmOS/Apps/Pour.asm index 197a0d2..5ec5afb 100644 --- a/Programs/CosmOS/Apps/Pour.asm +++ b/Programs/CosmOS/Apps/Pour.asm @@ -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 diff --git a/Programs/CosmOS/Apps/Snake.asm b/Programs/CosmOS/Apps/Snake.asm index 12f444c..4f5621b 100644 --- a/Programs/CosmOS/Apps/Snake.asm +++ b/Programs/CosmOS/Apps/Snake.asm @@ -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 diff --git a/Programs/CosmOS/Assembler/Asm.asm b/Programs/CosmOS/Assembler/Asm.asm index 0d03936..4c63542 100644 --- a/Programs/CosmOS/Assembler/Asm.asm +++ b/Programs/CosmOS/Assembler/Asm.asm @@ -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 diff --git a/Programs/CosmOS/Assembler/vectors.asm b/Programs/CosmOS/Assembler/vectors.asm index 2f6ee73..1e39956 100644 --- a/Programs/CosmOS/Assembler/vectors.asm +++ b/Programs/CosmOS/Assembler/vectors.asm @@ -189,7 +189,6 @@ vecReadFields: STA.1 INCD.0 LDA.0 - SETD.1 VecHandler INCD.1 STA.1 INCD.0 diff --git a/Programs/CosmOS/README.md b/Programs/CosmOS/README.md index a942d5f..16bb204 100644 --- a/Programs/CosmOS/README.md +++ b/Programs/CosmOS/README.md @@ -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. diff --git a/Programs/CosmOS/Source/cosmos.asm b/Programs/CosmOS/Source/cosmos.asm index c9dc41a..571f2e9 100644 --- a/Programs/CosmOS/Source/cosmos.asm +++ b/Programs/CosmOS/Source/cosmos.asm @@ -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 diff --git a/Programs/CosmOS/Source/sbfs.asm b/Programs/CosmOS/Source/sbfs.asm index 0044e5d..e7ae6d2 100644 --- a/Programs/CosmOS/Source/sbfs.asm +++ b/Programs/CosmOS/Source/sbfs.asm @@ -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? diff --git a/Programs/CosmOS/Source/text.asm b/Programs/CosmOS/Source/text.asm index 7fdda6f..b9033bf 100644 --- a/Programs/CosmOS/Source/text.asm +++ b/Programs/CosmOS/Source/text.asm @@ -272,7 +272,6 @@ textNumberLoop: POPB CCF ADD ; And the digit. - SETD.1 TextValue STQ.1 SETD.1 TextDigits diff --git a/Programs/testPrograms/sbfsWalkTest.asm b/Programs/testPrograms/sbfsWalkTest.asm index c8c24e1..2844f1d 100644 --- a/Programs/testPrograms/sbfsWalkTest.asm +++ b/Programs/testPrograms/sbfsWalkTest.asm @@ -66,7 +66,6 @@ walkCheck: STA.1 SETD.0 SbfsFileTail LDA.0 - SETD.1 Size INCD.1 STA.1 diff --git a/Programs/testPrograms/waitTest.asm b/Programs/testPrograms/waitTest.asm index 619d527..7c927bd 100644 --- a/Programs/testPrograms/waitTest.asm +++ b/Programs/testPrograms/waitTest.asm @@ -26,7 +26,6 @@ start: OUTA 0xE8 RSTA OUTA 0x20 - RSTA OUTA 0x21 INIA 0x01 OUTA 0x22 diff --git a/Tests/expected/cosmosMonitor.out b/Tests/expected/cosmosMonitor.out index 83fb026..7dcf55f 100644 --- a/Tests/expected/cosmosMonitor.out +++ b/Tests/expected/cosmosMonitor.out @@ -63,7 +63,7 @@ finished * > greet.sbx 210 hello.sbx 52 Life.sbx 1409 -Snake.sbx 2175 +Snake.sbx 2167 Keys.sbx 663 Say.sbx 155 Break.sbx 148 diff --git a/Tests/expected/cosmosRun.out b/Tests/expected/cosmosRun.out index c471318..d835bb6 100644 --- a/Tests/expected/cosmosRun.out +++ b/Tests/expected/cosmosRun.out @@ -3,7 +3,7 @@ CosmOS > greet.sbx 210 hello.sbx 52 Life.sbx 1409 -Snake.sbx 2175 +Snake.sbx 2167 Keys.sbx 663 Say.sbx 155 Break.sbx 148 diff --git a/Tests/expected/cosmosSlowDisk.out b/Tests/expected/cosmosSlowDisk.out index 153bdcc..c998466 100644 --- a/Tests/expected/cosmosSlowDisk.out +++ b/Tests/expected/cosmosSlowDisk.out @@ -2,7 +2,7 @@ CosmOS > greet.sbx 210 hello.sbx 52 Life.sbx 1409 -Snake.sbx 2175 +Snake.sbx 2167 Keys.sbx 663 Say.sbx 155 Break.sbx 148 diff --git a/Tests/expected/cosmosTreeWrite.out b/Tests/expected/cosmosTreeWrite.out index 561e2a3..6192d57 100644 --- a/Tests/expected/cosmosTreeWrite.out +++ b/Tests/expected/cosmosTreeWrite.out @@ -1,13 +1,13 @@ CosmOS > Folder -Edit.sbx 1995 +Edit.sbx 1983 1 file, 1 directory > loaded, starting at 4000 > note.txt, 0 lines > : : : > written, 67 bytes > finished > Folder -Edit.sbx 1995 +Edit.sbx 1983 note.txt 67 2 files, 1 directory > halted