retroforth/doc/book/internals/io
crc d36068d72f begin working on making terminology around the Retro naming consistent
FossilOrigin-Name: 9ec7d6dee1b22e748cd1f00886b5c2ed76e4b6138c131f699cbbb0c640c561a3
2021-05-12 13:57:22 +00:00

35 lines
1.2 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 (type 0) with a version of 0
#1 io:query will return 1 3, since the second device is
block storage (type 3), with a version of 1
#2 io:query will return 0 1, since the last device is a
keyboard (type 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 ID, 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 ID of 0.
All other devices are optional and can be specified in any
order.