Advertisement
Redxone

[CC - Redstone] RAM Interface Program

Feb 11th, 2017
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.32 KB | None | 0 0
  1. --]] Left = Read/Write , Back = Data Out, Top = Address
  2.  
  3. function RAMIO(rw, dt, add)
  4.  local data = 0
  5.     local readwrite = 0
  6.     local ramwrite = 1  
  7.     local ramread = 2
  8.     local w, h = term.getSize()
  9.     term.setBackgroundColor(colors.black)
  10.     term.setTextColor(colors.lime)
  11.     term.clear()
  12.     paintutils.drawLine(1,1,w,1,colors.gray)
  13.     term.setBackgroundColor(colors.gray)
  14.     term.setCursorPos(1, 1)
  15.     write("RAM Control")
  16.  term.setBackgroundColor(colors.black)
  17.  term.setCursorPos(1,2)
  18.     while true do
  19.   local x, y = term.getCursorPos()
  20.         write("Address :> ")
  21.         local address = tonumber(read())
  22.         if(address > 16)then
  23.             term.setCursorPos(x,y+1)
  24.             write("ERROR: Max RAM address index is 16")
  25.         elseif(address < 0)then
  26.             term.setCursorPos(x,y+1)
  27.             write("ERROR: Cannot Address a negative index!.")
  28.         end
  29.      write("IO (w/r/b): ")
  30.   term.setCursorBlink(true)
  31.         local _, key, h = os.pullEvent("key")
  32.         if(key == keys.w)then
  33.             write("Write")
  34.             readwrite = ramwrite
  35.         elseif(key == keys.r)then
  36.             write("Read")
  37.             readwrite = ramread
  38.         elseif(key == keys.b)then
  39.             write("Both")
  40.             readwrite = ramread + ramwrite
  41.   else
  42.     write("Invalid choice")
  43.     return false
  44.         end
  45.   sleep(0.1)
  46.         if(readwrite == ramwrite or readwrite == ramread + ramwrite)then
  47.    x,y = term.getCursorPos()
  48.             term.setCursorPos(1,y+1)
  49.    y = y + 1
  50.             write("Data :> ")
  51.          data = tonumber(read())
  52.             if(data > 65535)then
  53.                 print("ERROR: Max RAM segment is 16bits (65535) Decimal")
  54.             elseif(data < 0)then
  55.              print("ERROR: RAM does not support negative signed Decimal.")
  56.             end
  57.         end
  58.         --]] Attempt RAM poke
  59.         redstone.setBundledOutput(rw, readwrite)
  60.   if(data ~= nil)then
  61.     if(readwrite == ramread + ramwrite)then
  62.       data = data - 1
  63.     end
  64.           redstone.setBundledOutput(dt, tonumber(data))
  65.   end
  66.         redstone.setBundledOutput(add, address)
  67.         print("Poked RAM at: " .. address)
  68.         if(readwrite == ramwrite)then
  69.             print("With Value: " .. data)
  70.         end
  71.         sleep(0)
  72.     end
  73. end
  74. while true do
  75.   RAMIO("left","top","back")
  76. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement