Device: System
The system device provides information about the Bedrock system, and allows the system to enter sleep mode or fork a new instance.
Port | Name | Description | Read | Write |
---|---|---|---|---|
0x00 | Name | Name of this Bedrock system. | ✓ | ✓ |
0x01 | Authors | Authors of this Bedrock system. | ✓ | ✓ |
0x02 | Program memory | Length of program memory. | ✓ | ✗ |
0x03 | continued | continued | ✓ | ✗ |
0x04 | Working stack | Length of working stack. | ✓ | ✗ |
0x05 | Return stack | Length of return stack. | ✓ | ✗ |
0x06 | Available devices | List of connected devices. | ✓ | ✗ |
0x07 | continued | continued | ✓ | ✗ |
0x08 | Sleep | Enter sleep mode. | ✗ | ✓ |
0x09 | continued | continued | ✗ | ✓ |
0x0A | Wake | Cause of system wake. | ✓ | ✗ |
0x0B | Fork | Fork the current program. | ✗ | ✓ |
0x0C | Device name 1 | Name of custom device 1. | ✓ | ✓ |
0x0D | Device name 2 | Name of custom device 2. | ✓ | ✓ |
0x0E | Device name 3 | Name of custom device 3. | ✓ | ✓ |
0x0F | Device name 4 | Name of custom device 4. | ✓ | ✓ |
Ports
Name
Reading from this port will return the next byte of the text buffer associated with this port, or a zero byte if the end of the buffer has been reached.
Writing to this port will restart the buffer associated with this port.
The text buffer associated with this port contains a UTF-8 string representing the name and version of this Bedrock system implementation, with the name and version components separated by a forward-slash character (byte 0x2F
). The format of the version component is implementation defined, but should not contain the word “version” or any abbreviation for such.
Authors
Reading from this port will return the next byte of the text buffer associated with this port, or a zero byte if the end of the buffer has been reached.
Writing to this port will restart the buffer associated with this port.
The text buffer associated with this port contains a UTF-8 string representing a list of the names of the authors of this Bedrock system implementation. Each name is separated from the following name by a newline character (byte 0x0a
). The final name does not have a tailing newline character.
Program memory
Reading from this port group will return the number of bytes of program memory available on this Bedrock 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 Bedrock 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 Bedrock system. A value of zero represents 256 bytes.
Available devices
Reading from this port group will return a double representing the availability of each device on this Bedrock system. Each bit of the value represents a single slot on the device bus, with a bit being set only if a device is connected to the associated slot. The highest-order bit represents slot 0, and the lowest-order bit represents slot 15.
Sleep
Writing to this port group will perform a cached write, entering the Bedrock system into a sleep mode until woken. Each bit of the value written represents a single slot on the device bus, with a bit being set only if the device connected to that slot is allowed to wake the system from sleep. The highest-order bit represents slot 0, and the lowest-order bit represents slot 15. This write request will not return until the system is woken from sleep.
Each device connected to this Bedrock system is also connected directly to the system device, and is able to send wake requests through this connection. When the system device receives a wake request from a device, that device is flagged as ready to wake the system from sleep. When the Bedrock system is asleep and a flagged device is allowed to wake the system from sleep, the flag for that device will be cleared, the value of the wake port will become the slot number of that device, and the system will wake. If multiple flagged devices are allowed to wake the system from sleep, the choice of device is implementation defined, but should prioritise devices with a lower frequency of wake requests.
Wake
Reading from this port will return the slot number of the device which last woke the system from sleep, or zero if the system has not yet entered sleep mode.
Fork
Writing to this port will start a new Bedrock instance, if this Bedrock system supports multiple concurrent instances and has sufficient resources to start another instance. The contents of the program memory of this instance will be copied into the program memory of the new instance, the program counter and stack pointers of the new instance will be set to zero, and the new instance will become the active instance.
If this Bedrock system cannot start another instance, the program counter and stack pointers of this instance will be set to zero.
Device name
Reading from a device name port will return the next byte of the text buffer associated with that port, or a zero byte if the end of the buffer has been reached.
Writing to a device name port will restart the buffer associated with that port.
Each device name port is associated with one of the four custom device slots. The text buffer associated with each port contains a UTF-8 string representing the name of the device connected to the custom device slot associated with that port. If no device is connected, the buffer will be empty.
System wake
This device will send a wake request to the system device when the system enters sleep mode.