Code:
1 CONSTANT paintWhite
2 CONSTANT paintOrange
3 CONSTANT paintMagenta
4 CONSTANT paintLightBlue
5 CONSTANT paintYellow
6 CONSTANT paintLime
7 CONSTANT paintPink
8 CONSTANT paintGray
9 CONSTANT paintLightGray
10 CONSTANT paintCyan
11 CONSTANT paintPurple
12 CONSTANT paintBlue
13 CONSTANT paintBrown
14 CONSTANT paintGreen
15 CONSTANT paintRed
16 CONSTANT paintBlack
1 CONSTANT wireWhite
2 CONSTANT wireOrange
4 CONSTANT wireMagenta
8 CONSTANT wireLightBlue
16 CONSTANT wireYellow
32 CONSTANT wireLime
64 CONSTANT wirePink
128 CONSTANT wireGray
256 CONSTANT wireLightGray
512 CONSTANT wireCyan
1024 CONSTANT wirePurple
2048 CONSTANT wireBlue
4096 CONSTANT wireBrown
8192 CONSTANT wireGreen
16384 CONSTANT wireRed
32768 CONSTANT wireBlack
wireRed CONSTANT signalProcMacerate
wireOrange CONSTANT signalProcFurnace
wireYellow CONSTANT signalProcRecycle
wirePink CONSTANT signalProcSort
wireBlack CONSTANT signalProcStop
wireRed CONSTANT signalFlush1Over
wireOrange CONSTANT signalFlushEndOver
wireYellow CONSTANT signalFlushEndProc
wireBlack CONSTANT signalFlushStop
wireBlack CONSTANT signalBufferStop
paintRed CONSTANT tubeProcMacerate
paintOrange CONSTANT tubeProcFurnace
paintYellow CONSTANT tubeProcRecycle
paintPink CONSTANT tubeProcSort
paintRed CONSTANT tubeFlushOver
paintOrange CONSTANT tubeFlushProc
\ DOUBLE WORD (32 BIT) EQUALITY - USEFUL FOR SORTRON ITEM IDENTIFIERS.
\ D D -- F
: M= ROT = -ROT = AND ;
\ DOUBLE WORD (32 BIT) NON-EQUALITY
\ D D -- F
: M<> M= 0= ;
: pullAll
SORTSLOTS 0 ?DO
I SORTSLOT@
DUP 0<> IF I SORTPULL THEN
DROP 2DROP
LOOP
;
VARIABLE item1
VARIABLE item2
: pullAllMatch
0 SORTSLOT@
0<> IF
item2 ! item1 !
SORTSLOTS 0 ?DO
I SORTSLOT@
0<> IF
item1 @ item2 @ M= IF 255 I SORTPULL DROP THEN
ELSE
2DROP
THEN
LOOP
ELSE
2DROP
THEN
;
: pull1stack
0 SORTSLOT@
DUP 0<> IF 0 SORTPULL THEN
DROP 2DROP
;
: pullEnd
0 SORTSLOTS 1 - ?DO
I SORTSLOT@
DUP
0= IF DROP 2DROP LEAVE THEN
I SORTPULL
DROP 2DROP
-1 +LOOP
;
: signalQuiesce
BEGIN
IOX@
0= UNTIL ;
: signalFlush
0
BEGIN
1
IOX@ signalFlush1Over = IF tubeFlushOver SORTCOLOR! pull1stack signalQuiesce THEN
IOX@ signalFlushEndOver = IF tubeFlushOver SORTCOLOR! pullEnd signalQuiesce THEN
IOX@ signalFlushEndProc = IF tubeFlushProc SORTCOLOR! pullEnd signalQuiesce THEN
IOX@ signalFlushStop = IF 0 SORTCOLOR! DROP ." Stopping" THEN
TICK
0= UNTIL ;
: signalProc
0
BEGIN
1
IOX@ signalProcMacerate = IF tubeProcMacerate SORTCOLOR! pullAllMatch signalQuiesce THEN
IOX@ signalProcFurnace = IF tubeProcFurnace SORTCOLOR! pullAllMatch signalQuiesce THEN
IOX@ signalProcRecycle = IF tubeProcRecycle SORTCOLOR! pullAllMatch signalQuiesce THEN
IOX@ signalProcSort = IF tubeProcSort SORTCOLOR! pullAllMatch signalQuiesce THEN
IOX@ signalProcStop = IF 0 SORTCOLOR! DROP ." Stopping" THEN
TICK
0= UNTIL ;
VARIABLE slots
VARIABLE slot
: signalBuffer
SORTSLOTS slots !
0 slot !
0
BEGIN
1
slot @ SORTSLOT@
DUP 0<> IF slot @ SORTPULL THEN
DROP 2DROP
IOX@ signalBufferStop = IF 0 SORTCOLOR! DROP ." Stopping" THEN
20 TICKS
slot @ 1 + slot !
slot @ slots @ = IF 0 slot ! THEN
0= UNTIL ;
signalFlush has three operations: pull the first stack from the Enderchest into overflow; pull all the contiguous stacks at the end of the Enderchest into the overflow; and pull all the contiguous stacks at the and of the Enderchest into the processing Enderchest. You probably won't want this, it's a peculiarity of my sorting system that my input chest has no default route.
signalProc is the main event. It takes four signals, and sends the entire contents of my processing Enderchest to one of three destinations, the fourth signal terminates the program. After each signal is detected, it does what it needs to do and then waits for no signals to be detected on the input. That's what signalQuiesce is, it waits for all signals to stop. *Updated*: It now only sends items that match the item in the first slot. So if I've got a mixture of cobblestone and sand in the pouch, and sand is in the first slot, then only sand gets sent to be processed.
Here's my comms room:
Update: I've hooked up a Macerator, Electric Furnace, and Recycler and it's working like a charm. I also added a new signal to flush the processing Enderchest into the sorting Enderchest, so if I'm building something and I run out of refined iron then I can dump some iron in, click "Proc Furnace", and then send the refined iron to be sorted into my metals chest, all without having to visit my machine room. I'm a little bit paranoid about accidentally clicking "Recycle" with a bunch of valuable things in the chest...