This is the specification for the system device of the Bedrock computer system.
This document is aimed at people who are implementing the Bedrock system from scratch. For people who are learning about or writing program for the Bedrock system, the system device manual will generally be more useful.
Concepts
Wake flag
A wake flag is a flag associated with a device slot. A wake flag is set when a wake request is received from the device connected to that slot. The initial state of each wake flag is unset.
A wake request is a signal sent to the system device by another device. The wake behaviour section in each device specification will specify when that device will send a wake request to the system device.
This device contains sixteen wake flags: one for each of the sixteen device slots.
Device list
A device list is a 16 bit value representing a set of devices. Each bit in the value represents a slot on the device bus, with a bit being set only if the list contains the corresponding device.
Slot | Bit | Device |
---|---|---|
0x0 |
0x8000 |
System device |
0x1 |
0x4000 |
Memory device |
0x2 |
0x2000 |
Math device |
0x3 |
0x1000 |
Clock device |
0x4 |
0x0800 |
Input device |
0x5 |
0x0400 |
Screen device |
0x6 |
0x0200 |
Tone device |
0x7 |
0x0100 |
Sampler device |
0x8 |
0x0080 |
Stream device |
0x9 |
0x0040 |
File device |
0xA |
0x0020 |
Clipboard device |
0xB |
0x0010 |
Registry device |
0xC |
0x0008 |
Custom device 1 |
0xD |
0x0004 |
Custom device 2 |
0xE |
0x0002 |
Custom device 3 |
0xF |
0x0001 |
Custom device 4 |
Text buffer
A text buffer is a UTF-8 encoded string with an associated pointer. The string is terminated with a zero byte. The initial value of the pointer is zero.
Reading a byte from a text buffer will return the byte of the string that is addressed by the pointer, and then will increment the pointer by 1. Reading a byte past the end of the string will return an undefined value.
This device contains six text buffers: one for the name port, one for the authors port, and one for each of the four device name ports.
Ports
Port | Name | Description | Read | Write |
---|---|---|---|---|
0x00 |
Sleep | Enter sleep mode. | ✗ | ✓ |
0x01 |
grouped | grouped | ✗ | ✓ |
0x02 |
Wake | Device that woke the system. | ✓ | ✗ |
0x03 |
Fork | Fork or reset the system. | ✗ | ✓ |
0x04 |
Device name | Name of custom device 1. | ✓ | ✓ |
0x05 |
Device name | Name of custom device 2. | ✓ | ✓ |
0x06 |
Device name | Name of custom device 3. | ✓ | ✓ |
0x07 |
Device name | Name of custom device 4. | ✓ | ✓ |
0x08 |
Name | Name of this Bedrock system. | ✓ | ✓ |
0x09 |
Authors | Authors of this Bedrock system. | ✓ | ✓ |
0x0A |
Program memory | Program memory size. | ✓ | ✗ |
0x0B |
grouped | grouped | ✓ | ✗ |
0x0C |
Working stack | Working stack size. | ✓ | ✗ |
0x0D |
Return stack | Return stack size. | ✓ | ✗ |
0x0E |
Connected devices | List of connected devices. | ✓ | ✗ |
0x0F |
grouped | grouped | ✓ | ✗ |
Sleep
Writing a value to this port group will perform an atomic write, putting the system to sleep on commit, with the value written being interpreted as a device list. The system will not wake until a wake flag associated with one of the devices in the list has been set, at which point that flag will be cleared, the value of the wake port will be set to the slot number of that device, and then the write request will return.
If the wake flags of multiple devices in the list are set, the device that least recently woke the system from sleep will be chosen. The system device will only be chosen if no other flag is set.
Wake
Reading from this port will return the slot number of the device that most recently woke the system from sleep. The initial value of this port is zero.
Fork
Writing a non-zero value to this port will start a new Bedrock instance, and will copy the program memory of the original instance to the new instance. If a new instance could not be started, the program counter and stack pointers will be set to zero and all devices will be reset to initial states.
Writing a zero value to this port will reset this Bedrock instance. The program counter and stack pointers will be set to zero and all devices will be reset to initial states. The contents of the program memory will not be affected.
Device name
Each device name port is associated with a custom device slot ordered from first to last, and a text buffer containing the name of the device connected to that slot. If no device is connected to a slot, the text buffer string will be empty.
Reading from one of these ports will read and return a byte from the associated text buffer. Writing any value to one of these ports will set the text buffer pointer to zero.
Name
This port is associated with a text buffer containing the name and version of this Bedrock system implemention. The format of the text buffer string is the system name, followed by the forward-slash character 0x2F
, followed by the system version.
Reading from this port will read and return a byte from the text buffer. Writing any value will set the text buffer pointer to zero.
Authors
This port is associated with a text buffer containing a list of the authors of this Bedrock system implementation. The format of the text buffer string is a concatenated list of author names, with every name but the last followed by the newline character 0x0A
.
Reading from this port will read and return a byte from the text buffer. Writing any value will set the text buffer pointer to zero.
Program memory
Reading from this port group will return the number of bytes of program memory available on this system. A value of zero represents 65536 bytes.
Working stack
Reading from this port will return the number of bytes of working stack memory available on this system. A value of zero represents 256 bytes.
Return stack
Reading from this port will return the number of bytes of return stack memory available on this system. A value of zero represents 256 bytes.
Connected devices
Reading from this port group will return a device list representing a list of the devices currently connected to this system.
Wake behaviour
The wake flag for this device will always be set.