!c
plank,bundled_cable,plank:2,red_doped_wafer,plank:2,ribbon_cable,plank=io_expander;

Overview

The I/O Expander, or IOX for short, is a Redbus slave device that provides the ability to examine and control the state of redstone signals in the world. An IOX must be placed in the world and attached to a computer, either by placing it adjacent to the computer or by connecting the two with ribbon cable. The IOX interacts with 16 wires at a time in the form of a bundled cable, which plugs into a port on the back of the IOX. The front panel of the IOX contains 16 red indicator lights, each of which corresponds to a single wire within the bundle; an indicator light illuminates if the IOX is currently powering the corresponding wire (if the IOX is not powering the wire but some other device is, the indicator does not illuminate).

Wire colours

The 16 wires within the bundled cable are identified by colour. Each wire is allocated one bit within a 16-bit number; the following table shows the zero-based bit position, decimal and hexadecimal numerical values, and colour of each wire:
Bit position
Decimal value
Hexadecimal value
Colour
0
1
0x0001
White
1
2
0x0002
Orange
2
4
0x0004
Magenta
3
8
0x0008
Light blue
4
16
0x0010
Yellow
5
32
0x0020
Lime
6
64
0x0040
Pink
7
128
0x0080
Grey
8
256
0x0100
Light grey
9
512
0x0200
Cyan
10
1024
0x0400
Purple
11
2048
0x0800
Blue
12
4096
0x1000
Brown
13
8192
0x2000
Green
14
16384
0x4000
Red
15
32768
0x8000
Black
A single 16-bit number simultaneously contains the states of all 16 wires. The number is the sum of the decimal or hexadecimal values for the colours given in the table above. For example, a bundle with white, light blue, and grey wires powered is represented by the number 137 (in decimal) or 0x0089 (in hexadecimal), because 1+8+128=137 and, equivalently, 0x0001+0x0008+0x0080=0x0089. Note that each number in the “Decimal value” column is simply 2N, where N is the number from the “Bit position” column, and the number in the “Hexadecimal value” column is just that number converted from decimal to hexadecimal.

Redbus interface

A newly-placed IOX has Redbus slave ID 3; this can be changed by shift+right-clicking the IOX with a screwdriver in hand.

The IOX exposes the following memory locations over Redbus:
Offset
Length
Function
0x00
2
Input buffer
0x02
2
Output latch
Both locations are little-endian. Reading from [Input buffer] samples the levels on the wires in the attached cable and returns a number as described above indicating which wires are powered and which are not. Writing to [Output latch] sets which wires the IOX itself is powering; reading from [Output latch] simply returns the value most recently written to it.

Output delay

After writing to [Output buffer], the new value does not appear immediately on the connected wire. A few ticks must pass before the output drivers actually change state. One way to determine when a new output setting has taken effect is to read [Input buffer]—its value will not change to reflect the newly written output value until the drivers actually change state. However, this may be unreliable: if software deactivates a driver but some other device is still driving the same wire, then of course [Input buffer] will never read that wire as being unpowered.