Advertisement
Zarrab

FORTH machine regulator for Minecraft mod RedPower 6502 CPU

Jun 28th, 2012
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1.  
  2. This is for the machine controller/regulator that I've built
  3. in my Minecraft Server episode 08: http://youtu.be/eWZspf10QDQ
  4.  
  5. Find the Minecraft game here: http://www.minecraft.net
  6. Find the RedPower mod/blog here: http://www.eloraam.com
  7.  
  8. Note that I'm lacking practice in FORTH and this is more of a
  9. learning experience if anything.
  10.  
  11. If you re-build this and use this code, please note that how
  12. you choose the wire colours is VERY important, especially in
  13. the HALT? word. But also in using the RED and BLACK wires to
  14. start the machines, as well as the GREEN one to signal a jammed
  15. output.
  16.  
  17. HALT? expects that the machines are connected from the first
  18. bit on (white and orange insulated wires), for the DO...LOOP
  19. and bitshifting to work, for addressing the coloured wires
  20. in sets of two.
  21.  
  22. bits 0 and 1 (1 and 2 dec) are machine 0,
  23. bits 2 and 3 (4 and 8 dec) are machine 1,
  24. bits 4 and 5 (16 and 32 dec) are machine 2, and so on.
  25.  
  26. Feel free to use and/or improve on this code as you wish.
  27.  
  28. Best Regards,
  29. ~jack
  30.  
  31.  
  32. : PULSE \ ( n1 -- )
  33. DUP IOXSET 3 TICKS IOXRST ;
  34.  
  35. : EMPTY? \ ( n1 n2 -- )
  36. CR ." Is machine bit# " DUP . ." empty? "
  37. IOX@ AND 0<> IF IOXSET ." Yes, machine halted. " ELSE PULSE ." No, keep running. " THEN ;
  38.  
  39. : JAMMED? \ ( -- f )
  40. IOX@ 8192 AND 0<> ;
  41.  
  42. : ACTIVATE? \ ( -- f )
  43. IOX@ 16384 AND 0<> ;
  44.  
  45. : ACTIVATE! \ ( -- )
  46. 2730 IOXRST 32768 PULSE ;
  47.  
  48. : STOP? \ ( -- f )
  49. 2730 DUP IOX@ AND = ;
  50.  
  51. : HALTALL \ ( -- )
  52. 2730 IOX! ;
  53.  
  54. : STOP \ ( -- )
  55. HALTALL
  56. 32768 PULSE
  57. ;
  58.  
  59. : RUNNING? \ ( -- )
  60. 2730 DUP IOX@ AND <> ;
  61.  
  62. : HALT? \ ( -- )
  63. 12 0 DO
  64. 1 I 1 +<<
  65. 1 I <<
  66. EMPTY?
  67. 2 +LOOP
  68. ;
  69.  
  70. : run \ ( -- )
  71. CR ." Machine controller v1.0 "
  72. CR ." by jackd23 2012/06/29 "
  73.  
  74. \ INFINITE (main) LOOP HERE
  75. BEGIN
  76. CR ." Activate all machines? "
  77. ACTIVATE? IF ACTIVATE! ." Yes, all machines activated. " ELSE ." No. " THEN ;
  78.  
  79. CR ." Are any machines running? "
  80.  
  81. RUNNING? IF
  82. ." Yes. "
  83.  
  84. CR ." Is output jammed? "
  85. JAMMED? IF
  86. STOP ." Yes, controller stopped. "
  87. ELSE
  88. ." No, waiting for operations... "
  89. 250 TICKS
  90. HALT?
  91.  
  92. CR ." Controller status... "
  93. STOP? IF
  94. STOP ." all machines halt. Controller stopped. "
  95. ELSE
  96. ." keep running "
  97. THEN
  98. THEN
  99. ELSE
  100. ." No, standby for 300 ticks... "
  101. 300 TICKS
  102. THEN
  103. AGAIN
  104. ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement