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:
co-authored by
Claude Opus 5
parent
978aec4809
commit
d6feddd1b6
+15
-1
@@ -18,7 +18,7 @@
|
||||
// does not change: writing sends a byte, reading takes one and waits for it. The other two
|
||||
// are additions, so a program written before they existed cannot notice them.
|
||||
#define PORT_CONSOLE 0x00
|
||||
#define PORT_CONSOLE_TOP 0x05
|
||||
#define PORT_CONSOLE_TOP 0x06
|
||||
#define CONSOLE_DATA 0x00
|
||||
#define CONSOLE_STATUS 0x01
|
||||
#define CONSOLE_CONTROL 0x02
|
||||
@@ -35,6 +35,13 @@
|
||||
#define CONSOLE_COMMAND 0x05
|
||||
#define CONSOLE_COMMAND_CLEAR 0x01
|
||||
|
||||
// ---- What colour to write in ----
|
||||
//
|
||||
// The attribute given to every cell the console draws from now on. Its low nibble picks one
|
||||
// of sixteen ink and paper pairs, and the default palette is arranged so that XOR 8 turns
|
||||
// any of them inside out - which is highlighting, and is also how the cursor is drawn.
|
||||
#define CONSOLE_ATTRIBUTE 0x06
|
||||
|
||||
#define PORT_TEST 0x10
|
||||
#define PORT_REFUSE 0x11
|
||||
#define PORT_MEMORY 0x12
|
||||
@@ -113,6 +120,10 @@
|
||||
// That is not especially useful, but a control bit that quietly did nothing depending on
|
||||
// another control bit would be worse than a burst of interrupts somebody asked for.
|
||||
#define CONSOLE_CONTROL_INTERRUPT 0x02
|
||||
// Show a cursor where the next character will go. Off when the machine starts, because a
|
||||
// machine draws what it is told to and a program painting its own screen does not want one
|
||||
// blinking in the middle of it. A system that reads lines from a person turns it on.
|
||||
#define CONSOLE_CONTROL_CURSOR 0x04
|
||||
|
||||
// Set when there is a byte to be had. NOT set at the end of input, although a read would
|
||||
// answer at once there: what it answers is 0xFF standing in for nothing, and calling that
|
||||
@@ -129,6 +140,9 @@
|
||||
// Whether the console is set to interrupt, for the same reason: everything a program can
|
||||
// ask the console to be, it can also ask the console what it currently is.
|
||||
#define CONSOLE_STATUS_INTERRUPT 0x08
|
||||
// And whether a cursor is being shown, for the same reason as the rest: everything a program
|
||||
// can ask the console to be, it can also ask the console what it currently is.
|
||||
#define CONSOLE_STATUS_CURSOR 0x10
|
||||
|
||||
// Puts the terminal back the way it was found. Registered with atexit and called from a
|
||||
// handler for every signal that can end this process and be caught, because a machine that
|
||||
|
||||
Reference in New Issue
Block a user