This is simple code to control a bank of up to theoretically 30-31 in-line sortrons in order to request one sortron to match one stack of items. This can be combined with CC to work around limitations with the sorter in MiscPeripherals. Interfacing is done with a bundled cable. The corresponding bits are, starting from the LSB: Enable: 1 bit Bus ID: 5 bits Color: 4 bits Stack size: 6 bits Code: amount (6) bus ID (5) \/ \/ ###### #### ##### # /\ /\ color (4) enable (1) The enable bit must be set to high (1) briefly and then brought back to low (0) to signal a match. If the enable bit is not reset to low quickly enough (within 5 ticks), then another match will be performed. Matches can only be done once every 5 ticks with the following code. Code: BEGIN IOX@ DUP DUP DUP 1 AND IF 2/ 31 AND SORTADDR ! 6 U>> 15 AND SORTCOLOR! 10 U>> 255 AND SORTMATCH 5 TICKS ELSE DROP DROP DROP THEN AGAIN
This code supports one sortron (bus ID #20 in the code) that will pull from a chest into the mentioned bank of sortrons. Also, the item ID (the 32-bit number) of the item in this first sortron is available on two bundled cables going out on bus IDs 22 and 21 when the code is not busy processing a sort signal. Code: : OUTID ( -- ) \ output current item info 20 SORTADDR ! ( bus ID 20 for first sortron ) 0 SORTSLOT@ ( quantity ) DROP ( LSB ) 22 IOXADDR ! IOX! ( bus IDs 21/22 for item ID ) ( MSB ) 21 IOXADDR ! IOX! ; : SORT ( -- ) CR BEGIN OUTID \ check input to see whether we need to send 3 IOXADDR ! ( bus ID is incoming bundled cabling for signaling ) IOX@ DUP DUP DUP 1 AND IF 64 0 SORTPULL DROP ( pull out item ) 2/ 31 AND DUP IF DUP ." Bus:" . SORTADDR ! 6 U>> 15 AND DUP ." Color:" . SORTCOLOR! 10 U>> 255 AND DUP ." Amount:" . ." ..." SORTMATCH ELSE DROP ." Unsorted..." THEN ." OK" CR ELSE 5 TICKS DROP DROP DROP THEN AGAIN ;