Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --]] Left = Read/Write , Back = Data Out, Top = Address
- function RAMIO(rw, dt, add)
- local data = 0
- local readwrite = 0
- local ramwrite = 1
- local ramread = 2
- local w, h = term.getSize()
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.lime)
- term.clear()
- paintutils.drawLine(1,1,w,1,colors.gray)
- term.setBackgroundColor(colors.gray)
- term.setCursorPos(1, 1)
- write("RAM Control")
- term.setBackgroundColor(colors.black)
- term.setCursorPos(1,2)
- while true do
- local x, y = term.getCursorPos()
- write("Address :> ")
- local address = tonumber(read())
- if(address > 16)then
- term.setCursorPos(x,y+1)
- write("ERROR: Max RAM address index is 16")
- elseif(address < 0)then
- term.setCursorPos(x,y+1)
- write("ERROR: Cannot Address a negative index!.")
- end
- write("IO (w/r/b): ")
- term.setCursorBlink(true)
- local _, key, h = os.pullEvent("key")
- if(key == keys.w)then
- write("Write")
- readwrite = ramwrite
- elseif(key == keys.r)then
- write("Read")
- readwrite = ramread
- elseif(key == keys.b)then
- write("Both")
- readwrite = ramread + ramwrite
- else
- write("Invalid choice")
- return false
- end
- sleep(0.1)
- if(readwrite == ramwrite or readwrite == ramread + ramwrite)then
- x,y = term.getCursorPos()
- term.setCursorPos(1,y+1)
- y = y + 1
- write("Data :> ")
- data = tonumber(read())
- if(data > 65535)then
- print("ERROR: Max RAM segment is 16bits (65535) Decimal")
- elseif(data < 0)then
- print("ERROR: RAM does not support negative signed Decimal.")
- end
- end
- --]] Attempt RAM poke
- redstone.setBundledOutput(rw, readwrite)
- if(data ~= nil)then
- if(readwrite == ramread + ramwrite)then
- data = data - 1
- end
- redstone.setBundledOutput(dt, tonumber(data))
- end
- redstone.setBundledOutput(add, address)
- print("Poked RAM at: " .. address)
- if(readwrite == ramwrite)then
- print("With Value: " .. data)
- end
- sleep(0)
- end
- end
- while true do
- RAMIO("left","top","back")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement