Twenty two lines was right when there was one screen size. It still is on the forty column screen and wastes three fifths of the eighty column one, so More asks the rows register instead - which is readable for exactly this sort of reason. Rows minus three is twenty two on a twenty five row screen, so nothing changed underneath anyone already reading files this way. It fills a bigger screen and leaves a smaller one alone. A bitmap screen has no rows and says so with a nought, which through an eight bit subtraction would be 253 lines. Anything under five falls back. The existing test stopped testing paging the moment this worked: 32 lines fits in a 47 line page, so the file never paged and the recording lost the prompt entirely. The fixture is 60 lines now - the INPUT needed moving, not just the output, which is the failure this project keeps meeting. And cosmosMoreNarrow, which runs Mode first and pages the same file on the forty column screen. Two recordings of one file at 47 lines and at 22: a More that went back to a constant would make them the same length. Both were verified with break.sh, and the first attempt was a bad break rather than a bad test - it replaced one of two reads of the rows port and the other still fetched the real value. Which is a fair argument against reading a port twice, so it is read once and kept now. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01E2JrLzFvuFX9fgi1LDRjrW
194 lines
4.3 KiB
NASM
194 lines
4.3 KiB
NASM
; Read a text file one screen at a time.
|
|
;
|
|
; A screenful of lines is shown before a prompt - as many as the screen has, asked for rather
|
|
; than assumed, so that the eighty column mode is not read three fifths empty. 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 0x5000
|
|
|
|
start:
|
|
SETD.0 Name
|
|
INIB 0d63
|
|
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
|
|
; ---- As many lines as the screen has, less the prompt ----
|
|
;
|
|
; Twenty two was written when there was one screen size. It is still right on the forty
|
|
; column screen and wastes half of the eighty column one, so this ASKS: the rows register
|
|
; says how tall the screen is, and it is readable for exactly this sort of reason.
|
|
;
|
|
; Rows minus three is twenty two on a twenty five row screen, so nothing changed underneath
|
|
; anyone who was already reading files this way - it fills a bigger screen and leaves a
|
|
; smaller one alone.
|
|
;
|
|
; A BITMAP SCREEN HAS NO ROWS AT ALL and says so with a nought, which would come out as 253
|
|
; lines through an eight bit subtraction. Anything under five falls back, because a page of
|
|
; two lines is not a page and a program should not be the thing that discovers this.
|
|
fullPage:
|
|
INA 0x33
|
|
SETD.3 LinesLeft
|
|
STA.3 ; Kept, because the sums below want A for themselves.
|
|
INIB 0d5
|
|
CCF
|
|
SUB
|
|
BRC fullPageFallback ; Borrowed, so there are fewer than five rows.
|
|
LDA.3
|
|
INIB 0d3
|
|
CCF
|
|
SUB
|
|
MVQA
|
|
STA.3
|
|
RET
|
|
fullPageFallback:
|
|
INIA 0d22
|
|
STA.3 ; DP3 is still LinesLeft, from above.
|
|
RET
|
|
|
|
noName:
|
|
SETD.0 Usage
|
|
SWI osPrintString
|
|
INIA 0d2
|
|
SWI osExit
|
|
; ---- What went wrong, in words ----
|
|
;
|
|
; It used to print the number the filesystem answered with, as "error 2". THERE IS NO SUCH
|
|
; VOCABULARY: the library documents its answer as zero or not zero and never as a code, so
|
|
; the number named nothing and could not be looked up - it just looked like it could.
|
|
;
|
|
; A name that is not on the disk is the only way opening fails that a person can do anything
|
|
; about, and it is nearly always a name typed slightly wrong. Saying so is more use than any
|
|
; number would have been.
|
|
openFailed:
|
|
SETD.0 OpenError
|
|
SWI osPrintString
|
|
BRI failed
|
|
readFailed:
|
|
SETD.0 ReadError
|
|
SWI osPrintString
|
|
failed:
|
|
; 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 0x3000
|
|
Usage:
|
|
"more: give me a file name
|
|
"
|
|
OpenError:
|
|
"more: there is no file by that name
|
|
"
|
|
ReadError:
|
|
"more: the disk would not give me that file
|
|
"
|
|
NewLine:
|
|
0x0A 0x00
|
|
MorePrompt:
|
|
"-- more --"
|
|
ClearPrompt:
|
|
0x0A 0x00
|
|
Name:
|
|
#Reserve 0d64
|
|
Remaining:
|
|
0x00 0x00
|
|
LinesLeft:
|
|
0x00
|
|
|
|
#Include fileStream.asm
|