Give the console colour and a cursor

COLOUR COSTS A NIBBLE AND NO HARDWARE. A glyph is drawn in palette indices 0 and 1, paper
and ink, and a cell's attribute nibble adds sixteen to both - so sixteen banks is already
sixteen ink and paper pairs, and all that was missing was a register saying which one the
console draws in. That is port 0x06, read as well as written like the rest.

The palette a machine wakes up with is arranged so that HIGHLIGHTING IS ONE BIT: banks 0 to
7 are colours on black, banks 8 to 15 are the same colours as paper with black ink. So
attribute XOR 8 turns any pair inside out. That is a convention rather than a rule of the
machine - the device only ever adds the nibble and looks the answer up - but it is the
convention that makes a highlighted line and a cursor free.

Bank 0 is still grey on black, so nothing that was written before this has changed colour.

THE CURSOR IS THE SAME BIT AGAIN. It is drawn by turning its cell inside out rather than by
putting a block over it, so the character underneath stays readable, which matters to
somebody editing a line. The device draws it rather than the window, because on a machine
with a screen a cursor is a hardware feature - one drawn by the presenter would not be in a
picture the machine saved.

It blinks on the machine's own clock, half a second each way, so the phase is a pure
function of the cycle count and a screen saved at a given cycle is the same screen every
time. A blink on the host's clock would have made every saved picture a matter of luck.

Off unless asked for, with bit 2 of the control port. That is right for a machine - a
program painting its own screen does not want something blinking in the middle of it - and
CosmOS asks for one at boot. It also asks again when it takes the console back from a
program that has stopped, because a program handing key mode back the way it was told to
writes zero, which turns the cursor off. The shell owns the prompt, so the shell is what
makes sure there is something blinking at it.

Nine more checks in Tests/video.sh, to 41: that the attribute colours the ink and not the
paper, that XOR 8 turns both, that it reads back, that a cursor appears where the registers
put it and only when asked for, and that it goes dark again half a million cycles later.

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-29 08:13:28 -04:00
co-authored by Claude Opus 5
parent 978aec4809
commit d6feddd1b6
7 changed files with 235 additions and 21 deletions
+12 -2
View File
@@ -63,6 +63,12 @@ boot:
INIA 0x01
OUTA 0x31
; And a cursor, so that a person can see where the next thing they type will go. A machine
; wakes up without one, which is right: a program painting its own screen does not want one
; blinking in the middle of it. A system that reads lines from a person does.
INIA 0x04
OUTA 0x02
SETD.0 Banner
CALL printString
CALL newLine
@@ -2349,10 +2355,14 @@ handleExit:
; mode, and not interrupting. A program that wanted either is expected to put it back
; itself, but one that stopped early, or forgot, would otherwise hand back a shell with
; no echo and no backspace, or one being interrupted about keys it is reading anyway.
; Zero is both bits, so this undoes everything the control port can be asked for, and
; This undoes everything the control port can be asked for and puts the cursor back, and
; asking for what is already the case costs a byte out of a port and does nothing. That
; is the right price for not having to know.
RSTA
;
; THE CURSOR IS PUT BACK RATHER THAN LEFT, because a program that borrowed key mode and
; handed it back the way it was told to writes zero, which turns the cursor off. The shell
; owns the prompt, so the shell is what makes sure there is something blinking at it.
INIA 0x04
OUTA 0x02
SETD.0 Finished