Skip to content

Commit 3d82163

Browse files
committed
Start documenting peripherals
1 parent d81b326 commit 3d82163

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

README.md

+31-2
Original file line numberDiff line numberDiff line change
@@ -872,11 +872,40 @@ Peripherals are a way to extend the emulator,
872872
simulating a memory-mapped peripheral.
873873
This is done through the use of dynamic library loading,
874874
so you can create a peripheral in any language that supports the C ABI.
875+
Peripherals can be attached to one or more slots in the top 48 bytes of RAM.
876+
875877

876878
### Stateless Peripherals
877879

878880
Stateless peripherals are the simplest form of peripheral,
879881
with state being managed by the peripheral rather than the emulator.
880882

881-
There is a Rust crate ([`fateful_peripheral`](https://github.com/commonkestrel/fateful_peripheral))
882-
to make creating peripherals easy.
883+
#### Initialization
884+
885+
Stateless peripherals are initialized by a function with the signiture `int init(unsigned char)`.
886+
The return value of this is expalined in [errors](#errors).
887+
The input parameter provides the number of slots that the peripheral has been attached to.
888+
889+
#### Reading and Writing
890+
891+
Peripherals can be written through a function with the signiture `void write(unsigned char, unsigned char)`.
892+
The first parameter is the slot index that is being written to, and the second parameter is the value being written.
893+
894+
Peripherals can be read from with a function with the signiture `unsigned char read(unsigned char)`
895+
The input parameter is the slot index that is being read from, and the return value should be the value at the slot.
896+
897+
### Errors
898+
899+
Errors are only checked upon initialization - after both `init` and `stateful_init`.
900+
If either of these functions return a non-zero value,
901+
the emulator will check for a function with the signiture `int last_error_length()`.
902+
If this function exists, the emulator will then check for a function with the signiture `*char last_error()`.
903+
`last_error_length` should return the length of the ASCII string pointed to by the result of `last_error`.
904+
905+
### Names
906+
907+
Peripherals can optionally have a name that will displayed when the emulator is `DUMP`ed.
908+
This must be supplied by a function with the following signiture: `*char name()`.
909+
910+
There is a Rust crate - ([`fateful_peripheral`](https://github.com/commonkestrel/fateful_peripheral)) -
911+
designed to make creating peripherals easy.

0 commit comments

Comments
 (0)