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.
132 lines
2.6 KiB
NASM
132 lines
2.6 KiB
NASM
; Walking the directory of a SplitBit filesystem.
|
|
;
|
|
; sbfsFind answers a question about one name. This is the other thing a directory is for:
|
|
; being listed. The disk was made by SplitDisk, so the order and contents here are what
|
|
; the other implementation of the format wrote, not what this one assumed.
|
|
;
|
|
; The cases that matter are all on this disk already. There are twelve files, which is
|
|
; more than the eight an entry block holds, so the walk has to cross from the first
|
|
; directory block into the second. aName22CharactersLong! fills the name field exactly and
|
|
; so has no zero byte to end it, which is what the twenty third byte of SbfsName is for.
|
|
; empty.txt has no blocks at all.
|
|
;
|
|
; The count at the end is the proof that the walk stopped where the directory did. A walk
|
|
; that stepped its pointer only when it took an entry would loop forever on a free one,
|
|
; and one that stepped only when it skipped would hand out every eighth file.
|
|
;
|
|
; Correct output is the twelve files with their sizes, then how many there were.
|
|
|
|
#Include console.asm
|
|
#Include sbfs.asm
|
|
|
|
#Program
|
|
|
|
start:
|
|
CALL sbfsMount
|
|
BRQ mounted
|
|
SETD.0 NoMount
|
|
CALL printString
|
|
CALL newLine
|
|
HALT
|
|
|
|
mounted:
|
|
; Nothing found yet.
|
|
RSTA
|
|
SETD.0 Seen
|
|
STA.0
|
|
|
|
CALL sbfsFirst
|
|
BRI walkCheck
|
|
|
|
walkStep:
|
|
CALL sbfsNext
|
|
walkCheck:
|
|
BNQ walkDone
|
|
|
|
SETD.0 Seen
|
|
LDA.0
|
|
INCA
|
|
STA.0
|
|
|
|
SETD.0 SbfsName
|
|
CALL printString
|
|
|
|
; Line the sizes up, so a name that fills the field and a short one both read cleanly.
|
|
SETD.0 SbfsName
|
|
CALL nameWidth
|
|
MVQA
|
|
CALL printSpaces
|
|
|
|
; A file is its blocks times 256 plus its tail, which is the block count in the high
|
|
; byte and the tail in the low one. Nothing has to multiply anything.
|
|
SETD.0 SbfsFileBlocks
|
|
INCD.0
|
|
LDA.0
|
|
SETD.1 Size
|
|
STA.1
|
|
SETD.0 SbfsFileTail
|
|
LDA.0
|
|
INCD.1
|
|
STA.1
|
|
|
|
SETD.0 Size
|
|
CALL printWordDecimal
|
|
CALL newLine
|
|
BRI walkStep
|
|
|
|
walkDone:
|
|
SETD.0 Total
|
|
CALL printString
|
|
SETD.0 Seen
|
|
LDA.0
|
|
CALL printByteDecimal
|
|
CALL newLine
|
|
HALT
|
|
|
|
; DP0 names a string. Q is how many spaces would pad it out to twenty four characters.
|
|
; A name that is already that long gets one space, because none at all would run the
|
|
; name into the number.
|
|
nameWidth:
|
|
INIA 0d24
|
|
SETD.1 Padding
|
|
STA.1
|
|
widthLoop:
|
|
LDA.0
|
|
BRA widthDone
|
|
SETD.1 Padding
|
|
LDA.1
|
|
DECA
|
|
STA.1
|
|
BRA widthFloor ; It is already too long to pad.
|
|
INCD.0
|
|
BRI widthLoop
|
|
widthFloor:
|
|
INIA 0d1
|
|
SETD.1 Padding
|
|
STA.1
|
|
widthDone:
|
|
SETD.1 Padding
|
|
LDA.1
|
|
RSTB
|
|
CCF
|
|
ADD
|
|
RET
|
|
|
|
#Data
|
|
|
|
NoMount:
|
|
"no filesystem on that disk"
|
|
Total:
|
|
"files: "
|
|
|
|
Seen:
|
|
0x00
|
|
Padding:
|
|
0x00
|
|
Size:
|
|
0x00 0x00
|
|
|
|
#Vectors
|
|
|
|
Boot start
|