Double CosmOS's half of the machine, and check that it fits

The memory map gave CosmOS 0x0000 through 0x1FFF of Program Memory and
applications 0x2000 and above. CosmOS is 8141 bytes at the previous commit,
which is fifty one bytes short of the line, and the next thing added to it
went over.

GOING OVER DOES NOT FAIL WHERE IT HAPPENS. Nothing enforces the division: an
application says where it goes with #Base and the loader puts it there, so a
CosmOS that has grown past 0x1FFF simply has the next program loaded written
over the end of it. What breaks is whichever part of the shell that program
happened to cover, at whatever later moment somebody uses it. It turned up here
as the monitor's assemble command answering "I do not know" to valid
instructions, several commands into a session, on a machine that had booted
perfectly well.

Both halves are doubled: applications now start at 0x4000 in Program Memory and
0x2000 in Data Memory. That is 16K of code and 8K of data for the system,
against the 8775 and 2948 it uses today. Both were on the same trajectory, and
moving them together means the twenty files that say #Base are edited once
rather than twice.

The standalone loader's loadable.asm keeps its old base: it belongs to the
loader CosmOS grew out of, not to CosmOS, and its addresses answer to a
different program. The unbased-segment diagnostic keeps its old base too - it
exists to produce an error message that names the address, and the message is
what is recorded.

Tests/docs.sh now reads the two limits out of the table in the README and
measures both segments against them. It reads them rather than being told them
because the table is the specification, and this is the second time in this
project that the thing nobody checked is the thing that rotted.

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-24 22:21:02 -04:00
co-authored by Claude Opus 5
parent 36a1b07b5b
commit 588e02aff5
41 changed files with 126 additions and 86 deletions
+2 -2
View File
@@ -22,7 +22,7 @@
#Program
#Base 0x2000
#Base 0x4000
start:
SETD.0 Banner
@@ -50,7 +50,7 @@ deeper:
#Data
#Base 0x1000
#Base 0x2000
Banner:
"two stops, and what the registers were at each
+2 -2
View File
@@ -51,7 +51,7 @@
#Program
#Base 0x2000
#Base 0x4000
start:
SETD.0 FileName
@@ -780,7 +780,7 @@ addByteToWord:
#Data
#Base 0x1000
#Base 0x2000
Break:
0x0A 0x00
+2 -2
View File
@@ -4,7 +4,7 @@
#Program
#Base 0x2000
#Base 0x4000
start:
; Swap ValueB and ValueA.
@@ -71,7 +71,7 @@ start:
#Data
#Base 0x1000
#Base 0x2000
ValueA:
; Low byte, high byte.
+2 -2
View File
@@ -4,7 +4,7 @@
#Program
#Base 0x2000
#Base 0x4000
start:
; Swap ValueB and ValueA.
@@ -127,7 +127,7 @@ start:
#Data
#Base 0x1000
#Base 0x2000
ValueA:
; Lowest byte ... Highest byte.
+2 -2
View File
@@ -4,7 +4,7 @@
#Program
#Base 0x2000
#Base 0x4000
start:
; Load our initial values into A and B.
@@ -38,6 +38,6 @@ start:
#Data
#Base 0x1000
#Base 0x2000
#Include print.asm
+2 -2
View File
@@ -24,7 +24,7 @@
#Program
#Base 0x2000
#Base 0x4000
start:
; ---- Write it ----
@@ -127,7 +127,7 @@ noDelete:
#Data
#Base 0x1000
#Base 0x2000
Name:
"kept.txt"
+2 -2
View File
@@ -17,7 +17,7 @@
#Program
#Base 0x2000
#Base 0x4000
start:
CIF ; Nothing arrives until there is something to catch it.
@@ -82,7 +82,7 @@ keyStop:
#Data
#Base 0x1000
#Base 0x2000
Banner:
"keys, by interrupt. q stops."
+2 -2
View File
@@ -32,7 +32,7 @@
#Program
#Base 0x2000
#Base 0x4000
start:
CALL seedGlider
@@ -348,7 +348,7 @@ delayDone:
#Data
#Base 0x1000
#Base 0x2000
RowCount:
0x00
+2 -2
View File
@@ -8,7 +8,7 @@
#Include services.asm
#Program
#Base 0x2000
#Base 0x4000
start:
SETD.0 Name
@@ -127,7 +127,7 @@ finished:
SWI osExit
#Data
#Base 0x1000
#Base 0x2000
Usage:
"more: give me a file name
"
+2 -2
View File
@@ -16,7 +16,7 @@
#Program
#Base 0x2000
#Base 0x4000
start:
SETD.0 Given
@@ -44,7 +44,7 @@ sayEnd:
#Data
#Base 0x1000
#Base 0x2000
SaidText:
"it says: "
+2 -2
View File
@@ -9,7 +9,7 @@
#Program
#Base 0x2000
#Base 0x4000
start:
RSTA
@@ -139,7 +139,7 @@ printCandidateHex:
#Data
#Base 0x1000
#Base 0x2000
; Segment has to begin on a page boundary, and now says so itself rather than relying on
; whatever happens to have been assembled before it. The marking loop adds the prime to
+2 -2
View File
@@ -4,7 +4,7 @@
#Program
#Base 0x2000
#Base 0x4000
start:
; Search the list until we find a prime.
@@ -45,7 +45,7 @@ start:
#Data
#Base 0x1000
#Base 0x2000
; The table of our prime candidates. It has to begin on a page boundary: marking walks
; the pointer's low byte and treats the carry out as running off the end of the table,
+2 -2
View File
@@ -38,7 +38,7 @@
#Program
#Base 0x2000
#Base 0x4000
start:
; The two pointers whose low byte is a square number. Both regions are page aligned, so
@@ -605,7 +605,7 @@ pauseInner:
#Data
#Base 0x1000
#Base 0x2000
HeadCell:
0x00
+2 -2
View File
@@ -36,7 +36,7 @@
#Program
#Base 0x2000
#Base 0x4000
start:
; ---- 1. How big is something that will not fit ----
@@ -404,7 +404,7 @@ printWhy:
#Data
#Base 0x1000
#Base 0x2000
BigName:
"big.txt"
+2 -2
View File
@@ -6,7 +6,7 @@
#Include services.asm
#Program
#Base 0x2000
#Base 0x4000
start:
SETD.0 Name
@@ -62,7 +62,7 @@ finished:
SWI osExit
#Data
#Base 0x1000
#Base 0x2000
Usage:
"type: give me a file name
"
+2 -2
View File
@@ -17,7 +17,7 @@
#Program
#Base 0x2000 ; Above the system, which keeps below here.
#Base 0x4000 ; Above the system, which keeps below here.
greet:
SETD.0 Opening
@@ -43,7 +43,7 @@ greet:
#Data
#Base 0x1000 ; And its data above the system's.
#Base 0x2000 ; And its data above the system's.
Opening:
"a program, loaded off a disk, running on the system that loaded it
+2 -2
View File
@@ -6,7 +6,7 @@
#Program
#Base 0x2000 ; Change two:
#Base 0x4000 ; Change two:
SETD hello ; Change three
Start:
@@ -25,6 +25,6 @@ End:
#Data
#Base 0x1000 ; Five, adjust the base of the data segment.
#Base 0x2000 ; Five, adjust the base of the data segment.
hello: ; Throw a label here so we can explicitly point at this data. Six, actually.
"Hello, World!"
+2 -2
View File
@@ -38,7 +38,7 @@
#Program
#Base 0x2000
#Base 0x4000
start:
SETD.0 Argument
@@ -1915,7 +1915,7 @@ report:
#Data
#Base 0x1000
#Base 0x2000
Argument:
#Reserve 0d23
+2 -2
View File
@@ -14,7 +14,7 @@
#Program
#Base 0x2000
#Base 0x4000
start:
SETD.0 Wanted
@@ -60,7 +60,7 @@ noFile:
#Data
#Base 0x1000
#Base 0x2000
Wanted:
#Reserve 0d23
+2 -2
View File
@@ -15,7 +15,7 @@
#Program
#Base 0x2000
#Base 0x4000
start:
SETD.0 Wanted
@@ -128,7 +128,7 @@ noFile:
#Data
#Base 0x1000
#Base 0x2000
Wanted:
#Reserve 0d23
+10 -2
View File
@@ -322,8 +322,16 @@ CosmOS divides the two SplitBit address spaces by convention:
| Memory | CosmOS | Loaded application |
| -- | -- | -- |
| Program Memory | `0x0000` through `0x1FFF` | `0x2000` and above |
| Data Memory | `0x0000` through `0x0FFF` | `0x1000` and above |
| Program Memory | `0x0000` through `0x3FFF` | `0x4000` and above |
| Data Memory | `0x0000` through `0x3FFF` | `0x2000` and above |
Both of CosmOS's halves were doubled once it outgrew the first ones. **The division is a
convention and nothing enforced it**, so CosmOS quietly grew past `0x1FFF` and the next
program loaded landed on top of its own code - which does not fail where it happens, it
fails later, in whatever part of the shell the program happened to cover. `make test` now
measures both segments against the numbers in this table, so the table is checked rather
than merely written down.
Applications state their actual Program and Data addresses with `#Base`. The SplitBit
assembler then writes an SBEX loadable image containing those addresses, the entry point,
+32
View File
@@ -430,6 +430,38 @@ for heading in ["## An Example SplitBit Assembly Program:",
problems.append("the example under \"%s\" no longer assembles"
% heading.strip("# :"))
# ---- CosmOS fits in the half of the machine it says it does ----
#
# The memory map in the CosmOS README is a CONVENTION. Nothing in the assembler, the
# loader or the machine enforces it: an application says where it goes with #Base, and
# CosmOS puts it there. So when CosmOS grew past the address applications are based at,
# nothing said so - the next program loaded simply landed on top of the shell's own code,
# and what broke was whichever part of the shell that program happened to cover, at
# whatever later moment somebody used it.
#
# That is why this reads the numbers out of the table rather than being told them: the
# table is the specification, and a table nothing checks is the thing that goes stale.
readme = open("Programs/CosmOS/README.md").read()
row = re.compile(r"\|\s*(Program|Data) Memory\s*\|\s*`0x0000` through `0x([0-9A-Fa-f]{4})`")
limits = {kind: int(top, 16) + 1 for kind, top in row.findall(readme)}
if len(limits) != 2:
problems.append("the CosmOS README no longer states a memory map this can check")
else:
built = subprocess.run(["./Assembler", "-I", "Programs/CosmOS/Source",
"Programs/CosmOS/Source/cosmos.asm", "-o", os.devnull],
capture_output=True, text=True)
sizes = dict(re.findall(r"(Program|Data) Segment size: (\d+)", built.stdout))
if len(sizes) != 2:
problems.append("could not measure the CosmOS segments")
else:
for kind in ("Program", "Data"):
used, room = int(sizes[kind]), limits[kind]
if used > room:
problems.append(
"CosmOS's %s Segment is %d bytes and the map gives it %d - it now"
" reaches into the %d bytes an application is loaded at, and loading"
" one will overwrite it" % (kind, used, room, used - room))
if problems:
print("The manuals and the code disagree:")
for p in problems:
+5 -5
View File
@@ -1,13 +1,13 @@
CosmOS
> loaded, starting at 2000
> loaded, starting at 4000
> two stops, and what the registers were at each
break at 200E
break at 400E
A 11 B 22 Q 00 status 00
DP0 1030 DP1 0730 DP2 0000 DP3 2000 SP FFFF
DP0 2030 DP1 0730 DP2 0000 DP3 4000 SP FFFF
press a key
break at 2023
break at 4023
A 44 B 55 Q 00 status 00
DP0 1000 DP1 0730 DP2 0000 DP3 2000 SP FFF5
DP0 2000 DP1 0730 DP2 0000 DP3 4000 SP FFF5
press a key
carried on to the end
finished
+1 -1
View File
@@ -1,5 +1,5 @@
CosmOS
> loaded, starting at 2000
> loaded, starting at 4000
> poem.txt, 0 lines
> : : : : > : : > 1: alpha
2: INSERTED
+1 -1
View File
@@ -1,5 +1,5 @@
CosmOS
> loaded, starting at 2000
> loaded, starting at 4000
> Hello, World!
finished
> Hello, World!
+1 -1
View File
@@ -1,5 +1,5 @@
CosmOS
> loaded, starting at 2000
> loaded, starting at 4000
> keys, by interrupt. q stops.
ab
the console has been handed back
+1 -1
View File
@@ -1,5 +1,5 @@
CosmOS
> loaded, starting at 2000
> loaded, starting at 4000
>  #
#
###
+1 -1
View File
@@ -1,5 +1,5 @@
CosmOS
> loaded, starting at 2000
> loaded, starting at 4000
>  #
#
###
+17 -17
View File
@@ -2,25 +2,25 @@ CosmOS
> x examine, d disassemble, a assemble, s set, b bank, g go, exit leaves
* b <program|data|number>
* there is no such bank
* loaded, starting at 2000
* loaded, starting at 4000
* bank 00
* 2000 47 00 10 00 SETD.0 1000
2004 18 10 SWI 10
2006 47 00 10 44 SETD.0 1044
200A 18 10 SWI 10
200C 47 00 10 7A SETD.0 107A
2010 27 1F INIB 1F
2012 18 11 SWI 11
2014 47 00 10 5D SETD.0 105D
* 2000 47 00 10 00 18 10 47 00 10 44 18 10 47 00 10 7A G.....G..D..G..z
2010 27 1F 18 11 47 00 10 5D 18 10 47 00 10 7A 18 10 '...G..]..G..z..
2020 47 00 10 65 18 10 18 12 00 00 00 00 00 00 00 00 G..e............
2030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
* 4000 47 00 20 00 SETD.0 2000
4004 18 10 SWI 10
4006 47 00 20 44 SETD.0 2044
400A 18 10 SWI 10
400C 47 00 20 7A SETD.0 207A
4010 27 1F INIB 1F
4012 18 11 SWI 11
4014 47 00 20 5D SETD.0 205D
* 4000 47 00 20 00 18 10 47 00 20 44 18 10 47 00 20 7A G. ...G. D..G. z
4010 27 1F 18 11 47 00 20 5D 18 10 47 00 20 7A 18 10 '...G. ]..G. z..
4020 47 00 20 65 18 10 18 12 00 00 00 00 00 00 00 00 G. e............
4030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
* bank 01
* 1000 61 20 70 72 6F 67 72 61 6D 2C 20 6C 6F 61 64 65 a program, loade
1010 64 20 6F 66 66 20 61 20 64 69 73 6B 2C 20 72 75 d off a disk, ru
1020 6E 6E 69 6E 67 20 6F 6E 20 74 68 65 20 73 79 73 nning on the sys
1030 74 65 6D 20 74 68 61 74 20 6C 6F 61 64 65 64 20 tem that loaded
* 2000 61 20 70 72 6F 67 72 61 6D 2C 20 6C 6F 61 64 65 a program, loade
2010 64 20 6F 66 66 20 61 20 64 69 73 6B 2C 20 72 75 d off a disk, ru
2020 6E 6E 69 6E 67 20 6F 6E 20 74 68 65 20 73 79 73 nning on the sys
2030 74 65 6D 20 74 68 61 74 20 6C 6F 61 64 65 64 20 tem that loaded
* bank 02
* 0000 01 FF 00 00 00 00 00 00 01 FF 00 00 00 00 00 00 ................
0010 03 FF 08 00 00 00 00 00 01 20 01 00 00 00 00 00 ......... ......
+1 -1
View File
@@ -1,5 +1,5 @@
CosmOS
> loaded, starting at 2000
> loaded, starting at 4000
> first line
second line
line 00: ABCDEFGHIJKLMNOPQRSTUVWXYZ
+1 -1
View File
@@ -12,7 +12,7 @@ notes.txt 21
> load what?
> no such file
> not a program
> loaded, starting at 2000
> loaded, starting at 4000
> a program, loaded off a disk, running on the system that loaded it
what should I call you? hello, Anachronaut. that is all I do.
finished
+1 -1
View File
@@ -1,5 +1,5 @@
CosmOS
> loaded, starting at 2000
> loaded, starting at 4000
> nothing was said
finished
> it says: notes.txt
+1 -1
View File
@@ -1,5 +1,5 @@
CosmOS
> loaded, starting at 2000
> loaded, starting at 4000
> saved it
read it back, 22 bytes:
a file kept by asking
+1 -1
View File
@@ -1,5 +1,5 @@
CosmOS
> loaded, starting at 2000
> loaded, starting at 4000
> +----------------+
| |
| |
+1 -1
View File
@@ -1,5 +1,5 @@
CosmOS
> loaded, starting at 2000
> loaded, starting at 4000
> ; This is a basic hello world program for the SplitBit CPU.
; We'll create a loop that outputs each byte of our string to Output 0, the text console.
+1 -1
View File
@@ -1,5 +1,5 @@
CosmOS
> loaded, starting at 2000
> loaded, starting at 4000
> big.txt is 329 blocks
read 329 blocks, checksum 57368, stopped with 3
small.txt streamed is 15216, read whole is 15216
+1 -1
View File
@@ -1,5 +1,5 @@
CosmOS
> loaded, starting at 2000
> loaded, starting at 4000
> 4 keyword 0 [#Program]
6 label: 0 [Start:]
7 instr 2 [LDA]
+4 -4
View File
@@ -5,16 +5,16 @@ Say.sbx 155
Say.sbx 52
rooted.txt 21
3 files, 2 directories
> loaded, starting at 2000
> loaded, starting at 4000
> it says: the shallow one
finished
> loaded, starting at 2000
> loaded, starting at 4000
> Hello, World!
finished
> loaded, starting at 2000
> loaded, starting at 4000
> it says: the shallow one again
finished
> loaded, starting at 2000
> loaded, starting at 4000
> Hello, World!
finished
> no such file
+1 -1
View File
@@ -3,7 +3,7 @@ CosmOS
Inner <dir>
Edit.sbx 1996
1 file, 2 directories
> loaded, starting at 2000
> loaded, starting at 4000
> note.txt, 0 lines
> : : : > written, 67 bytes
> finished
+1 -1
View File
@@ -1,5 +1,5 @@
CosmOS
> loaded, starting at 2000
> loaded, starting at 4000
> first line
second line
line 00: ABCDEFGHIJKLMNOPQRSTUVWXYZ
+3 -3
View File
@@ -3,10 +3,10 @@ b nonsense
b 9
load greet.sbx
b program
d 2000
x 2000
d 4000
x 4000
b data
x 1000
x 2000
b 2
x 0
s 0 FF