Device API
device-apixyw devices may implement a few standard callbacks to manage their state:
typedef xyw_byte (*xyw_input)(xyw_byte *data, xyw_byte addr, xyw_byte *error);
typedef void (*xyw_output)(xyw_byte *data, xyw_byte addr, xyw_byte *error);
typedef void (*xyw_setup)(xyw_byte *data, xyw_byte *error);
typedef void (*xyw_teardown)(xyw_byte *data);
typedef int (*xyw_poll)(xyw_byte *data);
typedef void (*xyw_save)(xyw_byte *data, xyw_byte *state);
typedef void (*xyw_restore)(xyw_byte *data, const xyw_byte *state);
typedef void (*xyw_tick)(xyw_byte *data);
#define XYW_DEVICE_STATE_SIZE 64
typedef struct xyw_device
{
xyw_byte *data;
xyw_setup setup;
xyw_input input;
xyw_output output;
xyw_teardown teardown;
xyw_poll poll;
xyw_save save;
xyw_restore restore;
xyw_tick tick;
} xyw_device;
=== Data
Each device should only accessed the 16 bytes of the devices pages associated to it.
=== Callbacks
== setup
Called when the virtual machine is initialized, used to initialize a device.
== input
Called when a byte is read from the device data.
== output
Called when a byte is written to the device data.
== poll
Called once every cycle, to check if an event has been dispatched (return 1), if the device is inactive (return 0) or if the device is active but no event was fired (return -1).
== tick
Called once every cycle, to perform an operation. Currently, this is only implemented by the system decode to trigger the error handler and to start executing an child image.
== save
Called to save internal (not memory-mapped) device state (if any) before loading and executing another image.
== restore
Called to restore internal (not memory-mapped) device state (if any) before returning to the parent image afree executing a child image.
== teardown
Called before the virtual machine exists, used to terminate the device.