This specification describes the system device of the Bedrock computer system.
The system device provides information about the configuration of the Bedrock system, and the ability to fork, sleep, and reset the system.
Ports
Port | Name | Description | Read | Write |
---|---|---|---|---|
0x00 |
Sleep | Enter sleep mode. | ✓ | ✓ |
0x01 |
grouped | grouped | ✓ | ✓ |
0x02 |
Wake ID | 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
Reading from this port group will return a device list representing all devices where the associated wake flag for that device is set.
Writing a value to this port group will perform an atomic write, putting the Bedrock system to sleep on commit. The value written will be interpreted as a device list, and the system will remain asleep until a wake flag associated with a device in that list is set, at which point the flag will be cleared, the value of the wake port will be set to the address of that device, and then the system will wake.
If there are multiple flagged devices in the list, the method to choose a device is implementation defined. The chosen method should give a fair chance to every device. The write request will not return until the system wakes.
Wake ID
Reading from this port will return the slot address of the device that most recently woke the system from sleep, as per the ‘Slot’ column of the table under the Device list section. The initial value of this port is zero.
Fork
Writing a non-zero value to this port will fork this Bedrock instance. The contents of the program memory of this instance will be copied into the program memory of the new instance. If a new instance could not be started, this instance will be reset, with the contents of the program memory being preserved.
Writing a zero value to this port will reset this Bedrock instance, with the contents of the program memory being preserved.
Device name
Each device name port is associated with a custom device slot in order from first to last, and a text buffer containing the name of the device connected to that slot. Each port exposes the associated text buffer for reading and writing. If no device is connected to a slot, a blank string is used in place of a device name.
Name
This port is associated with a text buffer containing the name and version of this Bedrock system, and exposes that text buffer for reading and writing. The string format is the program name, followed by the forward-slash character 0x2F
, followed by the program version.
Authors
This port is associated with a text buffer containing a list of the authors of this Bedrock system, and exposes that text buffer for reading and writing. The string format is a concatenated list of author names, with every name but the last followed by a newline character 0x0A
.
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 a value of 65,536 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 a value of 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 a value of 256 bytes.
Connected devices
Reading from this port group will return a device list representing the list of devices currently connected to this system.
Data structures
Text buffer
A text buffer is a fixed-width block of read-only memory with an associated pointer. The buffer memory contains a fixed UTF-8 encoded string, and is exactly long enough to fit that string and a trailing zero byte. The initial value of the pointer is zero.
Reading a byte from a text buffer will return the byte referenced by the pointer, and then will increment the pointer by 1. The behaviour when the pointer no longer references a byte of buffer memory is undefined.
Writing to a text buffer will restart the buffer, setting the value of the pointer to zero.
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.
Device list
A device list is a 16-bit value representing a set of devices. Each bit of the value corresponds with a slot on the device bus, and the device list contains a given device only if the bit corresponding with that device is set.
Each bit of the value from highest-order to lowest-order corresponds with each slot on the device bus from lowest-addressed to highest-addressed, as shown by the following table:
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 |
Wake flag
A wake flag is a flag associated with a device slot that indicates that the device attached to that slot has sent a wake request. When a wake request is received from a device, the flag associated with that device is set. The initial state of each wake flag is cleared.
This device contains 16 wake flags, one for each of the 16 device slots.
Wake
The wake flag for this device is always set.