Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- This is for the machine controller/regulator that I've built
- in my Minecraft Server episode 08: http://youtu.be/eWZspf10QDQ
- Find the Minecraft game here: http://www.minecraft.net
- Find the RedPower mod/blog here: http://www.eloraam.com
- Note that I'm lacking practice in FORTH and this is more of a
- learning experience if anything.
- If you re-build this and use this code, please note that how
- you choose the wire colours is VERY important, especially in
- the HALT? word. But also in using the RED and BLACK wires to
- start the machines, as well as the GREEN one to signal a jammed
- output.
- HALT? expects that the machines are connected from the first
- bit on (white and orange insulated wires), for the DO...LOOP
- and bitshifting to work, for addressing the coloured wires
- in sets of two.
- bits 0 and 1 (1 and 2 dec) are machine 0,
- bits 2 and 3 (4 and 8 dec) are machine 1,
- bits 4 and 5 (16 and 32 dec) are machine 2, and so on.
- Feel free to use and/or improve on this code as you wish.
- Best Regards,
- ~jack
- : PULSE \ ( n1 -- )
- DUP IOXSET 3 TICKS IOXRST ;
- : EMPTY? \ ( n1 n2 -- )
- CR ." Is machine bit# " DUP . ." empty? "
- IOX@ AND 0<> IF IOXSET ." Yes, machine halted. " ELSE PULSE ." No, keep running. " THEN ;
- : JAMMED? \ ( -- f )
- IOX@ 8192 AND 0<> ;
- : ACTIVATE? \ ( -- f )
- IOX@ 16384 AND 0<> ;
- : ACTIVATE! \ ( -- )
- 2730 IOXRST 32768 PULSE ;
- : STOP? \ ( -- f )
- 2730 DUP IOX@ AND = ;
- : HALTALL \ ( -- )
- 2730 IOX! ;
- : STOP \ ( -- )
- HALTALL
- 32768 PULSE
- ;
- : RUNNING? \ ( -- )
- 2730 DUP IOX@ AND <> ;
- : HALT? \ ( -- )
- 12 0 DO
- 1 I 1 +<<
- 1 I <<
- EMPTY?
- 2 +LOOP
- ;
- : run \ ( -- )
- CR ." Machine controller v1.0 "
- CR ." by jackd23 2012/06/29 "
- \ INFINITE (main) LOOP HERE
- BEGIN
- CR ." Activate all machines? "
- ACTIVATE? IF ACTIVATE! ." Yes, all machines activated. " ELSE ." No. " THEN ;
- CR ." Are any machines running? "
- RUNNING? IF
- ." Yes. "
- CR ." Is output jammed? "
- JAMMED? IF
- STOP ." Yes, controller stopped. "
- ELSE
- ." No, waiting for operations... "
- 250 TICKS
- HALT?
- CR ." Controller status... "
- STOP? IF
- STOP ." all machines halt. Controller stopped. "
- ELSE
- ." keep running "
- THEN
- THEN
- ELSE
- ." No, standby for 300 ticks... "
- 300 TICKS
- THEN
- AGAIN
- ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement