The console had grown an ANSI parser, and that was the wrong shape. ANSI exists because a screen used to be on the other end of a serial line and a byte stream was the only channel there was. This screen is memory the program can already address, so reaching it by sending characters for a state machine to take apart is a middleman for something the machine does better - and it meant accepting an open protocol somebody else defines, in hardware, with no natural end to it. Everything else on this machine is registers. So the console gets three: cursor row at 0x03, cursor column at 0x04, and a command port at 0x05 where 1 clears the screen. Both cursor registers are READ as well as written, which is the thing an escape cannot do without sending a query and parsing a reply - a routine that wants to put the cursor back where it found it can now ask. Clearing is one command against a thousand cells walked one at a time. Snake and Life are smaller for it: 2,168 bytes to 2,163 and 1,410 to 1,396. A HOST TERMINAL STILL SPEAKS ANSI, and bridging to the host is the emulator's job, the same job it does reading standard input. So the escapes are now GENERATED, outbound, for the set this device chooses, rather than parsed inbound as though the machine were a terminal. The set cannot grow behind our backs because we are the ones saying it. The cursor is announced lazily, at the next character rather than at the register write, so setting a row and a column costs one sequence rather than two. The console's block widens from three ports to six, which registryTest noticed: it had been asking about port 0x05 precisely BECAUSE nothing was there, and the console had just moved in. Re-blessing it would have left it checking nothing, so it asks about 0x80 instead - clear of the console, the disk, the screen, the controller, and the sound device coming to 0x40. Six checks in Tests/video.sh swapped from the sequences to the registers, including that the cursor reads back and that one sent past the edge is clamped rather than refusing. Those checks also stopped counting bytes from the ends of a file, which had quietly started measuring an escape the moment the console began announcing the cursor. SplitLint caught the one thing worth catching in the port: the clear command leaves A at 1 and key mode is also 1, so the second load looks redundant. Acting on it would tie a console command to a console mode by coincidence, and break silently if either ever moved, so it is suppressed with that reason rather than removed. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01E2JrLzFvuFX9fgi1LDRjrW
262 lines
3.4 KiB
NASM
262 lines
3.4 KiB
NASM
; Conway's Game of Life rewritten for SplitBit's four-Data-Pointer ISA.
|
|
;
|
|
; The representation and display match 16x16Life.asm: a visible 16x16 field,
|
|
; a dead border, and interleaved current/next bytes. DP0 walks the board, DP1
|
|
; and DP2 address the loop counters, and volatile DP3 walks the neighborhood.
|
|
|
|
#Include print.asm
|
|
|
|
#Program
|
|
|
|
start:
|
|
CALL seedGlider
|
|
INIA 0x01
|
|
OUTA 0x05 ; Console command: clear the screen
|
|
|
|
generationLoop:
|
|
CALL renderBoard
|
|
CALL evolveBoard
|
|
CALL commitBoard
|
|
CALL frameDelay
|
|
BRI generationLoop
|
|
|
|
seedGlider:
|
|
SETD.0 Board
|
|
DPUP.0 0d42
|
|
INIA 0x01
|
|
STA.0
|
|
SETD.0 Board
|
|
DPUP.0 0d80
|
|
STA.0
|
|
SETD.0 Board
|
|
DPUP.0 0d112
|
|
STA.0
|
|
DPUP.0 0d02
|
|
STA.0
|
|
DPUP.0 0d02
|
|
STA.0
|
|
RET
|
|
|
|
renderBoard:
|
|
RSTA
|
|
OUTA 0x03
|
|
OUTA 0x04 ; Cursor to row 0, column 0
|
|
SETD.1 RowCount
|
|
SETD.2 ColCount
|
|
INIA 0d16
|
|
STA.1
|
|
SETD.0 Board
|
|
DPUP.0 0d38
|
|
|
|
renderRow:
|
|
INIA 0d16
|
|
STA.2
|
|
renderCell:
|
|
LDA.0
|
|
BRA renderDead
|
|
INIB 0x23
|
|
OUTB 0x00
|
|
BRI renderCellDone
|
|
renderDead:
|
|
INIB 0x20
|
|
OUTB 0x00
|
|
renderCellDone:
|
|
DPUP.0 0d02
|
|
LDA.2
|
|
DECA
|
|
STA.2
|
|
BRA renderRowDone
|
|
BRI renderCell
|
|
|
|
renderRowDone:
|
|
CALL lineFeed
|
|
DPUP.0 0d04
|
|
LDA.1
|
|
DECA
|
|
STA.1
|
|
BRA renderDone
|
|
BRI renderRow
|
|
renderDone:
|
|
RET
|
|
|
|
evolveBoard:
|
|
SETD.1 RowCount
|
|
SETD.2 ColCount
|
|
INIA 0d16
|
|
STA.1
|
|
SETD.0 Board
|
|
DPUP.0 0d38
|
|
|
|
evolveRow:
|
|
INIA 0d16
|
|
STA.2
|
|
evolveCellLoop:
|
|
CALL evolveCell
|
|
DPUP.0 0d02
|
|
LDA.2
|
|
DECA
|
|
STA.2
|
|
BRA evolveRowDone
|
|
BRI evolveCellLoop
|
|
|
|
evolveRowDone:
|
|
DPUP.0 0d04
|
|
LDA.1
|
|
DECA
|
|
STA.1
|
|
BRA evolveDone
|
|
BRI evolveRow
|
|
evolveDone:
|
|
RET
|
|
|
|
evolveCell:
|
|
CALL countNeighbors
|
|
MVQB ; B is the neighbor count from here down.
|
|
|
|
; Three neighbors always produces a live cell.
|
|
INIA 0d03
|
|
CCF
|
|
SUB
|
|
BRQ makeAlive
|
|
|
|
; Two neighbors preserve the current state.
|
|
INIA 0d02
|
|
CCF
|
|
SUB
|
|
BRQ preserveCell
|
|
|
|
makeDead:
|
|
RSTA
|
|
INCD.0
|
|
STA.0
|
|
DECD.0
|
|
RET
|
|
|
|
preserveCell:
|
|
LDA.0
|
|
BRA makeDead
|
|
|
|
makeAlive:
|
|
INIA 0x01
|
|
INCD.0
|
|
STA.0
|
|
DECD.0
|
|
RET
|
|
|
|
; Return the eight-neighbor sum in Q. One Stack round-trip copies DP0 into
|
|
; volatile DP3; MVQA then keeps the running total entirely in registers.
|
|
countNeighbors:
|
|
PSHD.0
|
|
POPD.3
|
|
RSTA
|
|
DPDN.3 0d38
|
|
|
|
LDB.3
|
|
CCF
|
|
ADD
|
|
MVQA
|
|
DPUP.3 0d02
|
|
|
|
LDB.3
|
|
CCF
|
|
ADD
|
|
MVQA
|
|
DPUP.3 0d02
|
|
|
|
LDB.3
|
|
CCF
|
|
ADD
|
|
MVQA
|
|
DPUP.3 0d32
|
|
|
|
LDB.3
|
|
CCF
|
|
ADD
|
|
MVQA
|
|
DPUP.3 0d04
|
|
|
|
LDB.3
|
|
CCF
|
|
ADD
|
|
MVQA
|
|
DPUP.3 0d32
|
|
|
|
LDB.3
|
|
CCF
|
|
ADD
|
|
MVQA
|
|
DPUP.3 0d02
|
|
|
|
LDB.3
|
|
CCF
|
|
ADD
|
|
MVQA
|
|
DPUP.3 0d02
|
|
|
|
LDB.3
|
|
CCF
|
|
ADD
|
|
RET
|
|
|
|
commitBoard:
|
|
SETD.1 RowCount
|
|
SETD.2 ColCount
|
|
INIA 0d18
|
|
STA.1
|
|
SETD.0 Board
|
|
|
|
commitRow:
|
|
INIA 0d18
|
|
STA.2
|
|
commitCell:
|
|
INCD.0
|
|
LDA.0
|
|
DECD.0
|
|
STA.0
|
|
DPUP.0 0d02
|
|
LDA.2
|
|
DECA
|
|
STA.2
|
|
BRA commitRowDone
|
|
BRI commitCell
|
|
|
|
commitRowDone:
|
|
LDA.1
|
|
DECA
|
|
STA.1
|
|
BRA commitDone
|
|
BRI commitRow
|
|
commitDone:
|
|
RET
|
|
|
|
frameDelay:
|
|
INIA 0xFF
|
|
delayOuter:
|
|
INIB 0xFF
|
|
delayInner:
|
|
DECB
|
|
BRB delayInnerDone
|
|
BRI delayInner
|
|
delayInnerDone:
|
|
DECA
|
|
BRA delayDone
|
|
BRI delayOuter
|
|
delayDone:
|
|
RET
|
|
|
|
#Data
|
|
|
|
RowCount:
|
|
0x00
|
|
ColCount:
|
|
0x00
|
|
|
|
|
|
; 18 by 18 cells with the current and next states interleaved, so 648 bytes. The
|
|
; original leaves this implicit and leans on Data Memory being zero, which works but
|
|
; means the assembler believes the board is one byte long: anything placed after it
|
|
; would land inside it, and nothing would say so. Reserving the region states how far
|
|
; it reaches, so a label added below here is safe.
|
|
Board:
|
|
#Reserve 0d648
|