Advertisement
nickey_CC

TD4 Instruction Decoder for CC and EP

Sep 2nd, 2014
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.12 KB | None | 0 0
  1. --constants
  2. input = "north"
  3. output = "south"
  4. pi = util.open("front")
  5. po = util.open("back")
  6. --functions
  7. ADD_A_Im = function()
  8.   return false,false,false,true,true,true
  9. end
  10. MOV_A_Im = function()
  11.   return true,true,false,true,true,true
  12. end
  13. MOV_A_B = function()
  14.   return true,false,false,true,true,true
  15. end
  16. IN_A = function()
  17.   return false,true,false,true,true,true
  18. end
  19. MOV_A_Im = function()
  20.   return true,true,false,true,true,true
  21. end
  22. MOV_B_A = function()
  23.   return false,false,true,false,true,true
  24. end
  25. ADD_B_Im = function()
  26.   return true,false,true,false,true,true
  27. end
  28. IN_B = function()
  29.   return false,true,true,false,true,true
  30. end
  31. MOV_B_Im = function()
  32.   return true,true,true,false,true,true
  33. end
  34. OUT_B = function()
  35.   return true,false,true,true,false,true
  36. end
  37. OUT_Im = function()
  38.   return true,true,true,true,false,true
  39. end
  40. JNC = function()
  41.   if not rs.getInput("left") then
  42.     return true,true,true,true,true,false
  43.   end
  44.   return true,true,true,true,true,true
  45. end
  46. JMP = function()
  47.   return true,true,true,true,true,false
  48. end
  49. NOP = function()
  50.   return true,true,true,true,true,true
  51. end
  52. decode = function(a,b,c,d)
  53.   ret = 0
  54.   if a then
  55.     ret = 8
  56.   end
  57.   if b then
  58.     ret = ret + 4
  59.   end
  60.   if c then
  61.     ret = ret + 2
  62.   end
  63.   if d then
  64.     ret = ret + 1
  65.   end
  66.   return ret
  67. end
  68. --table
  69. op_table = {ADD_A_Im,MOV_A_B,IN_A,MOV_A_Im,MOV_B_A,ADD_B_Im,IN_B,MOV_B_Im,NOP,OUT_B,NOP,OUT_Im,NOP,NOP,JNC,JMP}
  70. --main
  71. while not rs.getInput("top") do
  72.   out = 0
  73.   selA,selB,loadA,loadB,loadO,loadPC = op_table[decode(pi.testBundledInput(input,colors.white),pi.testBundledInput(input,colors.orange),pi.testBundledInput(input,colors.magenta),pi.testBundledInput(input,colors.lightBlue)) + 1]()
  74.   if selA then
  75.     out = colors.white
  76.   end
  77.   if selB then
  78.     out = out + colors.orange
  79.   end
  80.   if loadA then
  81.     out = out + colors.magenta
  82.   end
  83.   if loadB then
  84.     out = out + colors.lightBlue
  85.   end
  86.   if loadO then
  87.     out = out + colors.yellow
  88.   end
  89.   if loadPC then
  90.     out = out + colors.lime
  91.   end
  92.   po.setBundledOutput(output,out)
  93.   os.pullEvent("redstone")
  94. end
  95. po.setBundledOutput(output,0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement