SWI osExit takes a status in A, and the shell keeps it. Fifty eight exits across twenty three programs now say deliberately whether they worked: 25 did what they were asked, 24 did not, 9 were asked wrongly. Compare is the exception and says so - one there means the files differ, which is a result rather than a failure, the way diff has always had it. IN A RATHER THAN Q, which is not a departure from the rule that a service answers in Q. This one takes an ARGUMENT, the way osPrintNumber takes A and B, and it never returns to answer anything. A is free precisely because a return would have put it back - and Q is the ALU's output, so a small number costs four instructions there against one in A. The shell does not print it. A program that failed has already said so in words and a number beside that is noise, so osLastStatus hands it back and Status is the program that shows it. That indirection is the point: the number exists for the thing that cannot read words. MARKING THE EXITS FOUND A DEFECT ON THE FIRST RUN. Type and More printed why they had failed and then fell through into the success exit, reporting that all was well. Nobody had noticed, because while the only reader was a person, the person could see both the complaint and the claim. Two smaller things. Snake sets the console to line mode and then exits with zero, and the linter flagged the second RSTA as redundant - an exit status and a console mode, equal by accident, which is the class that must never be collapsed. And the README still taught answering by writing into the frame, three months of habit that SRET replaced yesterday; that section is gone and the one describing SRET stands in its place.
160 lines
2.7 KiB
NASM
160 lines
2.7 KiB
NASM
; Read a text file one screen at a time.
|
|
;
|
|
; Twenty two lines are shown before a prompt. Space advances another screen, Return one
|
|
; line, and q gives the machine back to CosmOS. This is forward-only on purpose: the file
|
|
; stream holds one block and never asks the whole document to fit in memory.
|
|
;
|
|
; Written by ChatGPT for Anachronaut's SplitBit
|
|
|
|
#Include services.asm
|
|
#Program
|
|
#Base 0x4000
|
|
|
|
start:
|
|
SETD.0 Name
|
|
INIB 0d29
|
|
SWI osArgument
|
|
SETD.0 Name
|
|
LDA.0
|
|
BRA noName
|
|
CALL fileStreamOpen
|
|
BNQ openFailed
|
|
CALL fullPage
|
|
|
|
nextBlock:
|
|
CALL fileStreamNext
|
|
BNQ readFailed
|
|
PSHD.3
|
|
POPB
|
|
POPA
|
|
SETD.2 Remaining
|
|
STA.2
|
|
INCD.2
|
|
STB.2
|
|
OR
|
|
BRQ finished
|
|
SETD.1 FileStreamBlock
|
|
SETD.2 Remaining
|
|
|
|
printLoop:
|
|
LDA.1
|
|
OUTA 0x00
|
|
INIB 0x0A
|
|
XOR
|
|
BNQ bytePrinted
|
|
SETD.3 LinesLeft
|
|
LDA.3
|
|
DECA
|
|
STA.3
|
|
BNA bytePrinted
|
|
CALL pause
|
|
BNQ finished
|
|
bytePrinted:
|
|
INCD.1
|
|
CALL fileStreamTakeRemaining
|
|
BRQ nextBlock
|
|
BRI printLoop
|
|
|
|
; Ask for one key without asking for Return. The console is put back immediately,
|
|
; including on q and end of redirected input.
|
|
pause:
|
|
SETD.0 MorePrompt
|
|
SWI osPrintString
|
|
INIA 0x01
|
|
OUTA 0x02
|
|
INA 0x00
|
|
PSHA ; Keep the key while A is used to restore line mode.
|
|
RSTA
|
|
OUTA 0x02
|
|
POPA
|
|
SETD.0 ClearPrompt
|
|
SWI osPrintString
|
|
|
|
INIB 0x71 ; q
|
|
XOR
|
|
BRQ pauseQuit
|
|
INIB 0xFF ; end of redirected input
|
|
XOR
|
|
BRQ pauseQuit
|
|
INIB 0x0A ; Return: one more line.
|
|
XOR
|
|
BRQ oneLine
|
|
INIB 0x20 ; Space: one more screen.
|
|
XOR
|
|
BNQ pause ; Ignore every other key.
|
|
CALL fullPage
|
|
RSTA
|
|
RSTB
|
|
OR
|
|
RET
|
|
oneLine:
|
|
SETD.3 LinesLeft
|
|
INIA 0x01
|
|
STA.3
|
|
RSTA
|
|
RSTB
|
|
OR
|
|
RET
|
|
pauseQuit:
|
|
RSTA
|
|
INIB 0x01
|
|
OR
|
|
RET
|
|
fullPage:
|
|
SETD.3 LinesLeft
|
|
INIA 0d22
|
|
STA.3
|
|
RET
|
|
|
|
noName:
|
|
SETD.0 Usage
|
|
SWI osPrintString
|
|
INIA 0d2
|
|
SWI osExit
|
|
openFailed:
|
|
SETD.0 OpenError
|
|
SWI osPrintString
|
|
BRI printError
|
|
readFailed:
|
|
SETD.0 ReadError
|
|
SWI osPrintString
|
|
printError:
|
|
RSTA
|
|
MVQB
|
|
SWI osPrintNumber
|
|
SETD.0 NewLine
|
|
SWI osPrintString
|
|
; ITS OWN EXIT, and it did not have one. This fell through into finished and reported
|
|
; that everything was fine, having just printed the reason it was not - which nobody
|
|
; noticed while the only reader was a person, who could see both.
|
|
INIA 0d1
|
|
SWI osExit
|
|
|
|
finished:
|
|
RSTA
|
|
SWI osExit
|
|
|
|
#Data
|
|
#Base 0x2000
|
|
Usage:
|
|
"more: give me a file name
|
|
"
|
|
OpenError:
|
|
"more: cannot find the file, error "
|
|
ReadError:
|
|
"more: cannot read the file, error "
|
|
NewLine:
|
|
0x0A 0x00
|
|
MorePrompt:
|
|
"-- more --"
|
|
ClearPrompt:
|
|
0x0A 0x00
|
|
Name:
|
|
#Reserve 0d29
|
|
Remaining:
|
|
0x00 0x00
|
|
LinesLeft:
|
|
0x00
|
|
|
|
#Include fileStream.asm
|