Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Inputs
- -- b1 = add > +
- -- b2 = sub > -
- -- b3 = nxt > >
- -- b4 = lst > <
- -- b5 = stb > [
- -- b6 = enb > ]
- -- b7 = set > .
- -- b8 = nop > do nothing
- -- n1 = pos > instruction possition
- -- n2 = svl > value to use with set
- -- Outputs
- -- n1 = tape[index] > tape value at index
- -- n2 = rpos > Requested next instruction possition
- -- Others
- -- tape = memory
- -- index = memory possition
- -- stbs = pos when all stb calls was made
- -- wab = do not execute anything untill next enb
- tape = {}
- index = 1
- stbs = {}
- wab = false
- function onTick()
- add = input.getBool(1)
- sub = input.getBool(2)
- nxt = input.getBool(3)
- lst = input.getBool(4)
- stb = input.getBool(5)
- enb = input.getBool(6)
- set = input.getBool(7)
- nop = input.getBool(8)
- pos = input.getNumber(1)
- svl = input.getNumber(2)
- if tape[index] == nil then
- tape[index] = 0
- end
- if add and not wab then
- tape[index] = tape[index] + 1
- rpos = pos + 1
- elseif sub and not wab then
- tape[index] = tape[index] - 1
- rpos = pos + 1
- elseif nxt and not wab then
- index = index + 1
- rpos = pos + 1
- elseif lst and not wab then
- index = index - 1
- rpos = pos + 1
- elseif stb and not wab then
- if tape[index] == 0 then
- wab = true
- else
- stbs[#stbs+1] = pos
- end
- rpos = pos + 1
- elseif enb then
- rpos = pos + 1
- if wab == false then
- if tape[index] == 0 then
- stbs[#stbs] = nil
- else
- rpos = stbs[#stbs]
- stbs[#stbs] = nil
- end
- else
- wab = false
- end
- elseif set and not wab then
- rpos = pos + 1
- tape[index] = svl
- elseif nop and not wab then
- rpos = pos + 1
- end
- output.setNumber(2,rpos)
- output.setNumber(1,tape[index])
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement