Grid took the disk's bank number, and gave the screen back untidy

Found by playing with it: after running Grid, the shell could not start
anything by name and dir said the disk was empty. Several commands after
the program that did it had exited, and nothing had said a word.

BANK NUMBERS ARE ONE NAMESPACE FOR THE WHOLE MACHINE. Grid registered video
memory as bank 3, which is the number CosmOS gives the disk's buffer when
it mounts - and that does not fail, it succeeds. Every read the filesystem
made afterwards came out of video memory. Grid uses 4 now, and the CosmOS
README has a table of who owns what, because the one place this was written
down was a line in a service description about sbfsMount.

Nothing hands bank numbers out and nothing refuses one that is taken. If
programs start wanting banks routinely, a service that allocates them is
what should exist rather than a longer table - noted there rather than
built, since one program wanting one bank is not yet a system.

Also puts the cursor home on the way out. The map was emptied and the
console was not told, so the shell carried on writing from wherever the
cursor had been standing when Grid started - twelve rows down a screen with
nothing on it. Clearing is what homes a cursor and it costs one write.

The regression test runs a program by name, then Grid, then the same
program again; the second one is the check. Putting Grid back on bank 3
fails it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01E2JrLzFvuFX9fgi1LDRjrW
This commit is contained in:
Anachronaut
2026-08-30 21:14:07 -04:00
co-authored by Claude Opus 5
parent 1aa45fcfc4
commit 3b650cabcd
8 changed files with 94 additions and 9 deletions
+22 -6
View File
@@ -30,7 +30,14 @@ start:
; ;
; The CPU cannot touch it. It belongs to the device, and the only way in is to give it a ; The CPU cannot touch it. It belongs to the device, and the only way in is to give it a
; bank number and go through the memory controller - the same as the disk's buffer. ; bank number and go through the memory controller - the same as the disk's buffer.
INIA 0d3 ;
; FOUR, BECAUSE THREE IS THE DISK'S. Bank numbers are one namespace for the whole machine
; and nothing hands them out: 0 is Program Memory, 1 is Data, 2 is the bank table, and
; CosmOS gives 3 to the disk's buffer when it mounts. This asked for 3, which does not
; fail - it succeeds, and the disk's buffer quietly becomes the screen. Every read the
; filesystem made after that came out of video memory, so the shell found an empty disk
; and could not start anything by name. Nothing said a word.
INIA 0d4
OUTA 0xE3 ; DestBank: the number it will answer to. OUTA 0xE3 ; DestBank: the number it will answer to.
INIA 0x30 INIA 0x30
OUTA 0xE2 ; SourceLow: the port of the device that owns it. OUTA 0xE2 ; SourceLow: the port of the device that owns it.
@@ -123,7 +130,7 @@ finished:
; grid underneath its own output. ; grid underneath its own output.
OUTA 0x34 ; A is still nought, from the three above. OUTA 0x34 ; A is still nought, from the three above.
INIA 0d3 INIA 0d4
OUTA 0xE3 OUTA 0xE3
INIA 0x40 INIA 0x40
OUTA 0xE4 OUTA 0xE4
@@ -137,6 +144,15 @@ finished:
INIA 0x02 INIA 0x02
OUTA 0xE8 ; Fill. OUTA 0xE8 ; Fill.
; ---- And the cursor back to the top ----
;
; The Fill above empties the map and says nothing to the console about it, so the shell
; carried on writing from wherever the cursor had been left standing when this program
; started - part way down a screen that no longer has anything on it. Clearing is what
; puts a cursor home, and it costs one write.
INIA 0x01
OUTA 0x05
; ---- And the colours it woke up with ---- ; ---- And the colours it woke up with ----
; ;
; Only the first pair, and that is worth being honest about. The console's own scheme is ; Only the first pair, and that is worth being honest about. The console's own scheme is
@@ -154,7 +170,7 @@ finished:
; THE REAL ANSWER IS A COMMAND TO THE SCREEN saying "give me back what you woke up with", ; THE REAL ANSWER IS A COMMAND TO THE SCREEN saying "give me back what you woke up with",
; the same way the console has one for clearing. There is not one, and this program is the ; the same way the console has one for clearing. There is not one, and this program is the
; first thing that ever wanted it. ; first thing that ever wanted it.
INIA 0d3 INIA 0d4
OUTA 0xE3 OUTA 0xE3
INIA 0xFC INIA 0xFC
OUTA 0xE4 OUTA 0xE4
@@ -206,7 +222,7 @@ putTile:
INCD.1 INCD.1
LDA.1 LDA.1
OUTA 0xE2 OUTA 0xE2
INIA 0d3 INIA 0d4
OUTA 0xE3 OUTA 0xE3
INIA 0x32 INIA 0x32
OUTA 0xE4 OUTA 0xE4
@@ -239,7 +255,7 @@ putTile:
; writes with no arithmetic in it at all. The colours that change do so by adding sixteen to ; writes with no arithmetic in it at all. The colours that change do so by adding sixteen to
; a running value, which is the same reason. ; a running value, which is the same reason.
putPalette: putPalette:
INIA 0d3 INIA 0d4
OUTA 0xE3 OUTA 0xE3
INIA 0xFC INIA 0xFC
OUTA 0xE4 OUTA 0xE4
@@ -330,7 +346,7 @@ putMap:
STA.0 STA.0
everyRow: everyRow:
INIA 0d3 INIA 0d4
OUTA 0xE3 OUTA 0xE3
SETD.0 MapRow SETD.0 MapRow
LDA.0 LDA.0
+25
View File
@@ -797,6 +797,31 @@ An application may also include its own libraries or access hardware ports direc
The services are an interface offered by the system, not the only way software is allowed The services are an interface offered by the system, not the only way software is allowed
to use the computer. to use the computer.
### Bank Numbers Are One Namespace:
A program that wants a device's memory registers it as a bank, and **bank numbers belong to
the whole machine**. Nothing hands them out and nothing refuses a number that is already
spoken for - registering one that is taken does not fail, it succeeds, and whatever held it
before quietly answers to nothing.
| Bank | Whose |
| --- | --- |
| 0 | Program Memory. The machine's. |
| 1 | Data Memory. The machine's. |
| 2 | The bank table. The machine's. |
| 3 | The disk's buffer, given at mount by `sbfsMount`. CosmOS needs it for as long as it is running. |
| 4 and up | Free for a program to use. |
`Grid` learned this the hard way and is the reason the table is here. It asked for 3, took the
disk's buffer, and every read the filesystem made afterwards came out of video memory - so the
shell found an empty disk and could not start anything by name, several commands after the
program that did it had exited. Nothing said a word, because from the controller's point of
view nothing went wrong.
**A program returns a bank by giving it back**, which today means knowing what was there
before. There is no service that hands out a free number, and if this becomes a common thing
for programs to want then that is what should exist rather than a longer table.
## What A Program May Ask The System For: ## What A Program May Ask The System For:
A loaded program is on its own hardware and can do anything the machine can do - it is a fence, not a wall. But the things it usually wants are things the system is already doing, and asking is both shorter and the only way to reach code that was assembled separately. `CALL` needs a label, and a label has to be in the same assembly; `SWI` needs only a number both sides agree on. A loaded program is on its own hardware and can do anything the machine can do - it is a fence, not a wall. But the things it usually wants are things the system is already doing, and asking is both shorter and the only way to reach code that was assembled separately. `CALL` needs a label, and a label has to be in the same assembly; `SWI` needs only a number both sides agree on.
+1 -1
View File
@@ -79,7 +79,7 @@ from `make`, not from here.
### 1. Recorded output ### 1. Recorded output
`Tests/run.sh` assembles each program named in `Tests/manifest`, runs it, and compares `Tests/run.sh` assembles each program named in `Tests/manifest`, runs it, and compares
everything it printed against a file in `Tests/expected`. 177 tests, of which 115 run, 35 everything it printed against a file in `Tests/expected`. 178 tests, of which 116 run, 35
only assemble, 16 are expected to fail to assemble, and 11 boot from ROM with no image only assemble, 16 are expected to fail to assemble, and 11 boot from ROM with no image
given at all. given at all.
+27
View File
@@ -0,0 +1,27 @@
CosmOS
> it says: before Grid
finished
> finished
> > it says: after Grid
finished
> greet.sbx 211
hello.sbx 53
Life.sbx 1396
Snake.sbx 2164
Keys.sbx 664
Say.sbx 156
Break.sbx 149
Grid.sbx 543
notes.txt 21
hi.script 121
bad.script 45
plain.script 24
cross.script 280
nonl.script 38
outer.script 376
inner.script 44
loop.script 35
17 files
> halted
Execution halted.
[exit 0]
+1 -1
View File
@@ -7,7 +7,7 @@ Snake.sbx 2164
Keys.sbx 664 Keys.sbx 664
Say.sbx 156 Say.sbx 156
Break.sbx 149 Break.sbx 149
Grid.sbx 539 Grid.sbx 543
notes.txt 21 notes.txt 21
hi.script 121 hi.script 121
bad.script 45 bad.script 45
+1 -1
View File
@@ -6,7 +6,7 @@ Snake.sbx 2164
Keys.sbx 664 Keys.sbx 664
Say.sbx 156 Say.sbx 156
Break.sbx 149 Break.sbx 149
Grid.sbx 539 Grid.sbx 543
notes.txt 21 notes.txt 21
hi.script 121 hi.script 121
bad.script 45 bad.script 45
+6
View File
@@ -0,0 +1,6 @@
Say before Grid
Grid
q
Say after Grid
dir
exit
+11
View File
@@ -791,6 +791,17 @@ cosmosStartup | CosmOS/Source/cosmos.asm | run | cosmosSta
# Present, and not a script. A missing one is ordinary and says nothing; one somebody meant # Present, and not a script. A missing one is ordinary and says nothing; one somebody meant
# to run and got wrong is worth a word. # to run and got wrong is worth a word.
cosmosStartupBad | CosmOS/Source/cosmos.asm | run | cosmosStartup.in | 200000000 | disks/startupbad.img cosmosStartupBad | CosmOS/Source/cosmos.asm | run | cosmosStartup.in | 200000000 | disks/startupbad.img
# ---- A program that takes the screen, and gives the disk back ----
#
# Grid registers video memory as a bank, and bank numbers are one namespace for the whole
# machine with nothing handing them out. It asked for 3, which is the one CosmOS gives the
# disk's buffer at mount - and that does not fail, it SUCCEEDS: every read the filesystem
# made afterwards came out of video memory. The shell found an empty disk and could not
# start anything by name, and nothing said a word.
#
# So this runs a program by name, then Grid, then the same program again. The second one is
# the check. dir at the end says the disk is still there to be read.
cosmosGrid | CosmOS/Source/cosmos.asm | run | cosmosGrid.in | 60000000 | disks/cosmos.img
printDecimalTest | testPrograms/printDecimalTest.asm | xfail | - | - printDecimalTest | testPrograms/printDecimalTest.asm | xfail | - | -
printDigitTest | testPrograms/printDigitTest.asm | xfail | - | - printDigitTest | testPrograms/printDigitTest.asm | xfail | - | -
printHexTest | testPrograms/printHexTest.asm | xfail | - | - printHexTest | testPrograms/printHexTest.asm | xfail | - | -