retroforth/doc/book/internals/io
crc d027bf6f41 work on clarifications to terminology around devices
FossilOrigin-Name: adf08c8ec4aab7403fa807c1734d0ab4dd35822b035eec5df14656e23d8d89c7
2021-06-18 13:56:13 +00:00

38 lines
1.3 KiB
Text

# Internals: I/O
Retro provides three words for interacting with I/O. These are:
io:enumerate returns the number of attached devices
io:query returns information about a device
io:invoke invokes an interaction with a device
As an example, with an implementation providing an output source,
a block storage system, and keyboard:
io:enumerate will return `3` since there are three
i/o devices
#0 io:query will return 0 0, since the first device
is a screen (device class 0) with a version
of 0
#1 io:query will return 1 3, since the second device is
block storage (device class 3), with a version
of 1
#2 io:query will return 0 1, since the last device is a
keyboard (device class 1), with a version
of 0
In this case, some interactions can be defined:
:c:put #0 io:invoke ;
:c:get #2 io:invoke ;
Setup the stack, push the device handle, and then use `io:invoke`
to invoke the interaction.
A Retro system requires one I/O device (a generic output for a
single character). This must be the first device, and must have
a device class and handle of 0.
All other devices are optional and can be specified in any
order.