mu

Reference documentation on available primitives

Data Structures

For memory safety, the following data structures are opaque and only modified using functions described further down. I still find it useful to understand how they work under the hood.

Mu will let you convert between byte, code-point-utf8 and code-point using copy, and trust that you know what you’re doing. Be aware that doing so is only correct for English/Latin characters, digits and symbols (ASCII).

Functions

The most useful functions from 400.mu and later .mu files. Look in signatures.mu for their full type signatures.

assertions for tests

predicates

arrays

streams

reading/writing hex representations of integers

printing to screen

pixel-on-real-screen draws a single pixel in one of 256 colors.

All text-mode screen primitives require a screen object, which can be either the real screen on the computer or a fake screen for tests.

The real screen on the Mu computer can currently display a subset of Unicode. There is only one font, and it’s mostly fixed-width, with individual glyphs for code-points being either 8 or 16 pixels wide.

Similar primitives for writing text top-to-bottom, left-to-right.

Screens remember the current cursor position. The following primitives automatically read and update the cursor position in various ways.

Assertions for tests:

pixel graphics

events

read-key reads a single key from the keyboard and returns it if it exists. Returns 0 if no key has been pressed. Currently only supports single-byte (ASCII) keys, which are identical to their code-point and code-point-utf8 representations.

read-line-from-keyboard reads keys from keyboard, echoes them to screen (with given fg/bg colors) and accumulates them in a stream until it encounters a newline.

read-mouse-event returns a recent change in x and y coordinate.

timer-counter returns a monotonically increasing counter with some fixed frequency. You can periodically poll it to check for intervals passing, but can’t make assumptions about how much time has passed.

Mu doesn’t currently support interrupt-based events.

We also don’t yet have a fake keyboard.

persistent storage

read-ata-disk synchronously reads a whole number of sectors from a disk of persistent storage. The disk must follow the ATA specification with a 28-bit sector address. Each sector is 512 bytes. Therefore, Mu currently supports ATA hard disks of up to 128GB capacity.

Similarly, write-ata-disk synchronously writes a whole number of sectors to disk.

Mu doesn’t currently support asynchronous transfers to or from a disk.