Make a host, step 3: a driver shows hello
Text on a Terse32 screen comes from device 2, the terminal: 80 by 30 character cells. Rather than write it, use the device bus: each device is a separate program, a driver, that talks to your core over a local socket, and the Tersenet sources have a reference driver for every device. Your core starts terse-dev-terminal, passes it the terminal's calls, and asks it for the grid.
The drivers run on Linux and are not in the downloads. Build them from the sources, into target/release:
cargo build --release -p terse-devices -p terse-cli
The devices a program lists
Now read the header's device entries: a slot, then a version whose top bit (80h) marks the device optional. hello requires device 2 and lists device 10, full text, as optional: ask the terminal's driver for both, and the machine has 10 if the driver answers for it. A required device that no driver serves refuses the program.
Talking to the driver
Listen on a Unix-domain socket, start the driver with the socket's path in the environment variable TERSE_BUS_SOCKET, and accept its connection. Every message is a length (4 bytes, of the rest), an address (the instance, 4 bytes, 0 for your one machine; a slot; 3 zero bytes) and a body whose first byte is its type. In the order of a run:
- HELLO (
01h): the slots you ask for, a directory, no shared memory. The reply (81h) gives each slot's version and call table, 64 bytes per function. - OPEN (
03h): instance 0's image ID (the BLAKE3-256 hash of the program file), ROM and RAM lengths, its slots, and the ROM. The reply says if the driver took it. - BEGIN (
30h), as each frame starts: the frame counter, the Unix time (0 in a test), no events, an empty replay field. The terminal's reply (B0h) has no charge, events or writes. - CALL (
10h), for eachecallto slot 2: the function,a0toa5, the budget and the bytes of the buffer it reads. RESULT (90h) givesa0(anda1), a charge and bytes to write into RAM. - END (
31h), as each frame ends. No reply. - STATE (
40h), between frames: the reply starts with the grid. - SHUTDOWN (
60h) at the end.
Calls through the table
Look the function up in its slot's table. Not there: return FFFF_FFFFh and charge 4. Otherwise check the buffer and arguments as the entry says (DEVICES.md section 5); a call that fails gets the entry's failure result and is not sent. Every call costs its base charge, 4 if the entry marks it deferred, else 64, and a call that is sent the RESULT's charge on top.
See the grid
STATE's reply holds 2,400 cells of 4 bytes: a character (16 bits), a foreground and a background colour. Print the 30 rows as STATE.md section 6.3 says. (A host with a window asks the driver for pictures instead: DEVICES.md section 7.)
Check yourself
Run hello for 30 frames with no input. Your screen must be the reference's:
terse run programs/hello/hello.terse --frames 30 --dump
That is programs/hello/expected-30-frames.txt without its typed text: row 11 holds only >. tcore (make -C native/core-c builds it) shows the same:
native/core-c/tcore programs/hello/hello.terse --frames 30 \
--dump --drivers target/release
How much code
tcore talks to every reference driver in 639 lines of C (bus.c), with batching, which only makes it faster. Its BLAKE3 is 76 lines, printing the grid 26.
What you have now
A core that shows hello through a reference driver. Next: Make a host, step 4: prove it exact.
The detail is in DEVICES.md: sections 1 (the messages), 2 and 3 (starting a driver, the socket), 5 (the call table) and 12 (a minimal core, step by step); the terminal in The terminal (device 2); deferred and answered calls in The Terse32 machine, section "Call table" (SPEC §calls.table, §charges).