@@ -872,11 +872,40 @@ Peripherals are a way to extend the emulator,
872
872
simulating a memory-mapped peripheral.
873
873
This is done through the use of dynamic library loading,
874
874
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
+
875
877
876
878
### Stateless Peripherals
877
879
878
880
Stateless peripherals are the simplest form of peripheral,
879
881
with state being managed by the peripheral rather than the emulator.
880
882
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