Two mechanical fixes SplitLint found: MVQA, and RSTA for zero
Twenty four places moved Q into A or B by pushing it and popping it back. That is four bus cycles and two bytes to do what MVQA does in one of each, and several of them are inside loops - Life, the calculator, int8. Nineteen more loaded zero with INIA 0d0 where RSTA says the same thing in one byte. Both are equivalent at the CPU rather than by assertion: RSTA and INIA both leave Status alone, and PSHQ followed by POPA nets to A = Q with the Stack Pointer where it started. The one difference is that the pair leaves a copy of Q in memory just below the Stack Pointer and MVQA does not, which nothing here reads. Five recorded outputs moved and every one of them says the change worked: - 16x16Life fits five more generations into the same cycle budget, the first 457 lines identical, because the loop got cheaper. - Life.sbx is 1409 bytes rather than 1411, in three tests that list it. - Edit.sbx is 1995 rather than 1996. That last one broke a check I added this morning, and the hole is worth recording: the CosmOS README's claim about Edit's size did not have the word "Edit" on the same line as the number, because the subject was in the sentence before, so the check that measures quoted sizes skipped it silently. The sentence now names what it is talking about, which makes it both checkable and clearer, and the check fails on a wrong number there. Comments on either half of a replaced pair are carried onto the instruction that replaces them, so nothing anybody wrote was lost.
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
|
||||
start:
|
||||
; Load our initial values into A and B.
|
||||
INIA 0x00
|
||||
RSTA
|
||||
CALL printByteDecimal
|
||||
CALL blankSpace
|
||||
; Move the value into B.
|
||||
@@ -25,8 +25,7 @@ start:
|
||||
PSHA
|
||||
POPB
|
||||
; Copy Q into A
|
||||
PSHQ
|
||||
POPA
|
||||
MVQA
|
||||
; Print A.
|
||||
CALL printByteDecimal
|
||||
CALL blankSpace
|
||||
|
||||
@@ -33,7 +33,7 @@ clsToken:
|
||||
INIB 0x23 ; '#'
|
||||
XOR
|
||||
BNQ clsTryInstruction
|
||||
INIA 0d0
|
||||
RSTA
|
||||
SETD.0 ClsType
|
||||
STA.0
|
||||
BRI clsYes
|
||||
|
||||
@@ -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 took it from 4,941 bytes to 1,996 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,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 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.
|
||||
|
||||
|
||||
@@ -94,8 +94,7 @@ textHexWord:
|
||||
textHexLoop:
|
||||
LDA.0
|
||||
CALL textHexDigit
|
||||
PSHQ
|
||||
POPA
|
||||
MVQA
|
||||
INIB 0xFF
|
||||
CCF
|
||||
SUB
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#Program
|
||||
start:
|
||||
; Load our initial values into A and B.
|
||||
INIA 0x00
|
||||
RSTA
|
||||
CALL printByteDecimal
|
||||
CALL blankSpace
|
||||
; Move the value into B.
|
||||
@@ -22,8 +22,7 @@ start:
|
||||
PSHA
|
||||
POPB
|
||||
; Copy Q into A
|
||||
PSHQ
|
||||
POPA
|
||||
MVQA
|
||||
; Print A.
|
||||
CALL printByteDecimal
|
||||
CALL blankSpace
|
||||
|
||||
@@ -193,50 +193,43 @@ countNeighbors:
|
||||
LDB
|
||||
CCF
|
||||
ADD
|
||||
PSHQ
|
||||
POPA
|
||||
MVQA
|
||||
DPUP 0d02
|
||||
|
||||
LDB
|
||||
CCF
|
||||
ADD
|
||||
PSHQ
|
||||
POPA
|
||||
MVQA
|
||||
DPUP 0d02
|
||||
|
||||
LDB
|
||||
CCF
|
||||
ADD
|
||||
PSHQ
|
||||
POPA
|
||||
MVQA
|
||||
DPUP 0d32
|
||||
|
||||
LDB
|
||||
CCF
|
||||
ADD
|
||||
PSHQ
|
||||
POPA
|
||||
MVQA
|
||||
DPUP 0d04
|
||||
|
||||
LDB
|
||||
CCF
|
||||
ADD
|
||||
PSHQ
|
||||
POPA
|
||||
MVQA
|
||||
DPUP 0d32
|
||||
|
||||
LDB
|
||||
CCF
|
||||
ADD
|
||||
PSHQ
|
||||
POPA
|
||||
MVQA
|
||||
DPUP 0d02
|
||||
|
||||
LDB
|
||||
CCF
|
||||
ADD
|
||||
PSHQ
|
||||
POPA
|
||||
MVQA
|
||||
DPUP 0d02
|
||||
|
||||
LDB
|
||||
|
||||
@@ -20,7 +20,7 @@ start:
|
||||
INCD ; Increment to the next spot in the buffer.
|
||||
BRI inputLoop ; Loop again to grab more string.
|
||||
inputEnd:
|
||||
INIA 0x00 ; Set A to 0.
|
||||
RSTA ; Set A to 0.
|
||||
STA ; Store it in the buffer.
|
||||
SETD Buffer ; Set the Data Pointer to the start of the buffer again.
|
||||
CALL printString ; Print it out.
|
||||
|
||||
@@ -18,8 +18,7 @@ repl:
|
||||
CALL printString
|
||||
|
||||
CALL readNonSpace
|
||||
PSHQ
|
||||
POPA
|
||||
MVQA
|
||||
|
||||
; Q, q, or end-of-file exits.
|
||||
INIB 0xFF
|
||||
@@ -39,14 +38,12 @@ repl:
|
||||
BRQ inputError
|
||||
|
||||
CALL readNonSpace
|
||||
PSHQ
|
||||
POPA
|
||||
MVQA
|
||||
SETD Operator
|
||||
STA
|
||||
|
||||
CALL readNonSpace
|
||||
PSHQ
|
||||
POPA
|
||||
MVQA
|
||||
CALL readHexByteFirst
|
||||
SETD RightOperand
|
||||
STQ
|
||||
@@ -98,7 +95,7 @@ readNonSpaceLoop:
|
||||
INIB 0x0D
|
||||
XOR
|
||||
BRQ readNonSpaceLoop
|
||||
INIB 0x00
|
||||
RSTB
|
||||
CCF
|
||||
ADD
|
||||
RET
|
||||
@@ -108,12 +105,11 @@ readNonSpaceLoop:
|
||||
readHexByteFirst:
|
||||
CALL clearParseStatus
|
||||
CALL hexNibble
|
||||
PSHQ
|
||||
POPA
|
||||
MVQA
|
||||
INIB 0xFF
|
||||
XOR
|
||||
BRQ invalidByte
|
||||
INIB 0x00
|
||||
RSTB
|
||||
SHL
|
||||
SHL
|
||||
SHL
|
||||
@@ -121,11 +117,9 @@ readHexByteFirst:
|
||||
PSHA
|
||||
|
||||
CALL readNonSpace
|
||||
PSHQ
|
||||
POPA
|
||||
MVQA
|
||||
CALL hexNibble
|
||||
PSHQ
|
||||
POPA
|
||||
MVQA
|
||||
INIB 0xFF
|
||||
XOR
|
||||
BRQ invalidLowNibble
|
||||
@@ -142,7 +136,7 @@ invalidByte:
|
||||
STA
|
||||
POPD
|
||||
INIA 0xFF
|
||||
INIB 0x00
|
||||
RSTB
|
||||
CCF
|
||||
ADD
|
||||
RET
|
||||
@@ -157,8 +151,7 @@ hexNibble:
|
||||
CCF
|
||||
SUB
|
||||
BRC tryUpperHex
|
||||
PSHQ
|
||||
POPA
|
||||
MVQA
|
||||
INIB 0d10
|
||||
CCF
|
||||
SUB
|
||||
@@ -171,8 +164,7 @@ tryUpperHex:
|
||||
CCF
|
||||
SUB
|
||||
BRC tryLowerHex
|
||||
PSHQ
|
||||
POPA
|
||||
MVQA
|
||||
INIB 0d06
|
||||
CCF
|
||||
SUB
|
||||
@@ -185,8 +177,7 @@ tryLowerHex:
|
||||
CCF
|
||||
SUB
|
||||
BRC badNibble
|
||||
PSHQ
|
||||
POPA
|
||||
MVQA
|
||||
INIB 0d06
|
||||
CCF
|
||||
SUB
|
||||
@@ -195,14 +186,14 @@ tryLowerHex:
|
||||
badNibble:
|
||||
POPA
|
||||
INIA 0xFF
|
||||
INIB 0x00
|
||||
RSTB
|
||||
CCF
|
||||
ADD
|
||||
RET
|
||||
|
||||
decimalNibble:
|
||||
POPB
|
||||
INIB 0x00
|
||||
RSTB
|
||||
CCF
|
||||
ADD
|
||||
RET
|
||||
@@ -223,8 +214,7 @@ lowerNibble:
|
||||
|
||||
; Return Q=0 if Q was 0xFF, otherwise return a nonzero value.
|
||||
resultIsInvalid:
|
||||
PSHQ
|
||||
POPA
|
||||
MVQA
|
||||
INIB 0xFF
|
||||
XOR
|
||||
RET
|
||||
@@ -288,7 +278,7 @@ evaluate:
|
||||
INIA 0x01
|
||||
STA
|
||||
RSTA
|
||||
INIB 0x00
|
||||
RSTB
|
||||
CCF
|
||||
ADD
|
||||
RET
|
||||
@@ -360,7 +350,7 @@ multiplyLoop:
|
||||
multiplyDone:
|
||||
SETD Product
|
||||
LDA
|
||||
INIB 0x00
|
||||
RSTB
|
||||
CCF
|
||||
ADD
|
||||
RET
|
||||
|
||||
@@ -25,8 +25,7 @@ int8mult:
|
||||
DECA ; Subtract one from the multiplier.
|
||||
BRA int8multDone ; If the multiplier becomes zero, we're done.
|
||||
PSHA ; Push the multiplier back to the stack.
|
||||
PSHQ ; Push the running total to the stack.
|
||||
POPA ; Pop the running total into A.
|
||||
MVQA ; Push the running total to the stack. Pop the running total into A.
|
||||
BRI int8multLoop
|
||||
return0:
|
||||
RSTA
|
||||
@@ -58,8 +57,7 @@ int8div:
|
||||
POPA ; Pop the quotient counter from the stack.
|
||||
INCA ; Increment it.
|
||||
PSHA ; Push it back onto the stack.
|
||||
PSHQ ; Push the running total onto the stack.
|
||||
POPA ; Pop the runing total into A.
|
||||
MVQA ; Push the running total onto the stack. Pop the runing total into A.
|
||||
BRI int8divLoop ; Branch back to the loop.
|
||||
int8divDone:
|
||||
CCF ; Clear the Carry Flag.
|
||||
@@ -76,13 +74,11 @@ int8mod:
|
||||
int8modLoop:
|
||||
SUB ; Subtract B from A.
|
||||
BRC int8modDone
|
||||
PSHQ
|
||||
POPA
|
||||
MVQA
|
||||
BRI int8modLoop
|
||||
int8modDone:
|
||||
; Add the divisor to Q to get the remainder.
|
||||
CCF
|
||||
PSHQ
|
||||
POPA
|
||||
MVQA
|
||||
ADD
|
||||
RET
|
||||
|
||||
@@ -97,10 +97,10 @@ printByteDecimal:
|
||||
|
||||
; Expects A to contain the byte you want to print as a hexadecimal value.
|
||||
printByteHex:
|
||||
INIB 0x00 ; Set B to 0.
|
||||
RSTB ; Set B to 0.
|
||||
SHR SHR SHR SHR ; Shift Right four times to move the high nybble into the lower half of A.
|
||||
CALL printHexDigit ; Print the nybble.
|
||||
INIA 0x00 ; Set A to 0.
|
||||
RSTA ; Set A to 0.
|
||||
SHL SHL SHL SHL ; Shift left four times to move the low nybble back into the lower half of A.
|
||||
CALL printHexDigit ; Print the nybble.
|
||||
RET ; Return to the caller.
|
||||
|
||||
@@ -20,7 +20,7 @@ start:
|
||||
INCD ; Increment to the next spot in the buffer.
|
||||
BRI inputLoop ; Loop again to grab more string.
|
||||
inputEnd:
|
||||
INIA 0x00 ; Set A to 0.
|
||||
RSTA ; Set A to 0.
|
||||
STA ; Store it in the buffer.
|
||||
SETD Buffer ; Set the Data Pointer to the start of the buffer again.
|
||||
CALL printString ; Print it out.
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
#Program
|
||||
|
||||
clearRegisters:
|
||||
INIA 0x00;
|
||||
INIB 0x00;
|
||||
RSTA
|
||||
RSTB
|
||||
ADD
|
||||
RET
|
||||
|
||||
|
||||
@@ -36,12 +36,12 @@ start:
|
||||
|
||||
; ---- Offsetting by a whole sixteen bit value ----
|
||||
SETD.1 Text
|
||||
INIA 0x00
|
||||
RSTA
|
||||
INIB 0d13
|
||||
DPUW.1
|
||||
LDA.1
|
||||
OUTA 0x00
|
||||
INIA 0x00
|
||||
RSTA
|
||||
INIB 0d13
|
||||
DPDW.1
|
||||
LDA.1
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
#Program
|
||||
|
||||
start:
|
||||
INIA 0x00
|
||||
RSTA
|
||||
CALL reportPort
|
||||
INIA 0x10
|
||||
CALL reportPort
|
||||
|
||||
@@ -457,5 +457,10 @@
|
||||
#
|
||||
###
|
||||
|
||||
Execution stopped. (cycle limit reached)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Execution stopped. (cycle limit reached)
|
||||
[exit 0]
|
||||
|
||||
@@ -62,7 +62,7 @@ finished
|
||||
finished
|
||||
* > greet.sbx 210
|
||||
hello.sbx 52
|
||||
Life.sbx 1411
|
||||
Life.sbx 1409
|
||||
Snake.sbx 2175
|
||||
Keys.sbx 663
|
||||
Say.sbx 155
|
||||
|
||||
@@ -2,7 +2,7 @@ CosmOS
|
||||
> nothing is loaded
|
||||
> greet.sbx 210
|
||||
hello.sbx 52
|
||||
Life.sbx 1411
|
||||
Life.sbx 1409
|
||||
Snake.sbx 2175
|
||||
Keys.sbx 663
|
||||
Say.sbx 155
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
CosmOS
|
||||
> greet.sbx 210
|
||||
hello.sbx 52
|
||||
Life.sbx 1411
|
||||
Life.sbx 1409
|
||||
Snake.sbx 2175
|
||||
Keys.sbx 663
|
||||
Say.sbx 155
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
CosmOS
|
||||
> Folder <dir>
|
||||
Edit.sbx 1996
|
||||
Edit.sbx 1995
|
||||
1 file, 1 directory
|
||||
> loaded, starting at 4000
|
||||
> note.txt, 0 lines
|
||||
> : : : > written, 67 bytes
|
||||
> finished
|
||||
> Folder <dir>
|
||||
Edit.sbx 1996
|
||||
Edit.sbx 1995
|
||||
note.txt 67
|
||||
2 files, 1 directory
|
||||
> halted
|
||||
|
||||
Reference in New Issue
Block a user