ÎÌÌÌ̈ˆˆ¬ªªª¬ˆˆˆ¬ÌÌ̬ÌÀ̬ÌÀ̬ÌÀÌÌÌìÌÀÀî̬ÀÌÀ¬ÀÀÀ¬ÀÀÀ¬ÀÀÎÌÌÌ̈ˆˆ¬ªªª¬ˆˆˆ¬ÌÌ̬ÌÌ̬ÌÀ̬ÌÀÌÌÌìÌÀÀî̬ÀÌ̬ÀÀÀ¬ÀÀÀ¬ÀÀ¬ÌÌ̬ªªª¬ª¬ª¬ªÊ̬ªªªŒˆˆˆÌÀÌÎÌÌÎ̬̪ªÀ쬪ÀÀÀÌîÀìîÌÌîî¬ÌÌ̬ªªª¬ª¬ª¬ªÊ̬ªªªŒˆˆˆÌÀÌÎÌÌÎ̬̪ªÀ쬪ÀÀÀÌîÀìîÌÌîî >âÌÌ Ì Ì ÀÀÌÀÀÌÀÌÀÌÀ Ì Ì Ì ÌÀ ÌÀ ÌÀ ÌÀ ÀÌÀÌÀÌÀÌ ÀÌ Ì Ì Ì À Ì À Ì À Ì À Ì À Ì À Ì ÌÌ Ì Ì ÀÀÌÀ ÀÌ ÀÌ ÀÌÀ ÀÀÀÀÀÀÀÀÌÀ À Ì Ì ÌÌ ÀÌÀÌÀÌÀÌÀ Ì ÀÌÀ À Ì ÀÌÀÌÀÀ ÌÀ ÌÀ ÌÀ ÌÀ ÌÌÀ À À ÌÌ Ì Ì ÌÌ Ì Ì Ì Ì Ì À À ÌÀ Ì À ÌÀ À Ì Ì Ì Ì ÀÀÌÀÌÌ Ì Ì ÀÌÀ ÀÌ ÀÌÀÌÀÌÀÌÀÌÀÀÌÀ ÀÌÌÀÌÌ ÌÌ ÌÀÀ Ì ÀÌÀÌ ÀÌ Ì Ì ÀÌÀÌÀÀ ÀÌ À ÌÌ À ÌÀ Ì ÌÌ ÌÌÀ Ì Ì À Ì ÌÌÌ ÀÌÌÀ À ÌÌ À ÀÌÀÌÀÌ ÀÌÀÌÀÌÀÌ ÀÌÀÀÀ ÀÀÀÌÀÀ ÀÌÀÀÀÌÀÌÀÌÀÌÀÌÀÌÀÌÀÌ ÀÀÌÀÌÀÌÀÌÀÌÀÌÀÌÀÌ ÀÀÀÌÀÀ ÀÀ ÀÌ À À À À ÀÀÌÀ À ÌÀ À À ÀÌ ÀÌÀ ÀÌÀÌ ÌÌ ÀÌÀÌ À Ì ÀÌ ÀÌ ÀÌÌÌ ÀÌÀÌ ÀÌÀ À ÀÌÌÀ À ÌÀ Ì À ÌÀ À ÀÌ Ì À À ÌÀ Ì Ì ÌÀ À À Ì Ì À Ì Ì À Ì À À ÌÌ À À ÌÀ Ì Ì Ì À À ÌÌÀÌÌ ÀÌÀÌ Ì ÀÌÀÌ À ÀÌ ÀÌ ÀÌ ÀÌ Ì ÀÌÀÌ ÀÌÌ Ì ÀÀÌ À À À ÌÌÀ Ì ÌÌ ÀÌ ÌÌ ÀÌÀ Ì ÀÌ Ì ÀÌ ÀÌÀÌ ÀÌÀ À À ÌÀ Ì À Ì Ì ÌÀ À Ì À À À Ì À ÌÌ À Ì Ì Ì À ÌÌÌ ÀÌ Ì ÀÌÀ ÌÀÌ ÀÌÌÌÀÌÀÌ ÀÌ ÌÌÀ ÀÌÌÀÌ Ì ÀÌ À ÌÀ ÌÌÌ ÌÌÌ Ì ÌÌÌ Ì Ì À Ì ÌÌÀÌ Ì ÌÌÀ ÀÌÀÌÀ À À Ì Ì ÌÌ ÌÌÌ ÌÌ À Ì Ì À Ì Ì À Ì Ì À Ì Ì À À ÀÌÀÌÌ ÌÌÀÌÌ À ÌT-- title: Brainf'd -- author: SirWobb79 (@admiralerkal79 via discord) -- desc: Brainf interpreter in TIC-80 with built in editor -- license: MIT License -- version: 1 -- script: lua select = 1 input = 0 rows = 12 --The limit for on screen appears to be 12 --unless I can make the thing more compact --on screen :p fpi = 1 --Optional to change (makes it slower if bigger) ipf = 1 --Optional to change (makes it faster if bigger) --code = "++++++++++[>++++++++++<-]>[.-]" code = "+>>++++++++[<++++++++>-]<-<[!+>.<]" output = "" chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 .,!?'\"$%^&*()[]{}:;<>-=_+#~/|\\" selectable = "+-><[],.!e" desc = { "Add 1 to cell", "Take 1 from cell", "Move right 1 cell", "Move left 1 cell", "Loop if cell not 0", "End loop if cell is 0", "Input number", "Output char (custom ASCII)", "Output cell value", "End program (optional)" } state = "Paused" --state = "Execute" tapelen = 30000 tape = {"X","X","X"} stack = {} tc = 4 pc = 1 ticks = 0 --tape[1+3] = 10000000000000 for i=1, tapelen do table.insert(tape, 0) end for i=1, 3 do table.insert(tape, "X") end function TIC() cls() selected = selectable:sub(select, select) codef = code if #code >= 25 then --if pc >= #code-10 then codef = "( "..code:sub(pc-10, pc) if pc ~= #code then codef = "( "..code:sub(pc-10, pc+10) end indicator = " ^" if pc > 10 then codef = "( "..code:sub(pc-10, pc+10).." )" else codef = "( "..code:sub(1, 21).." )" indicator = " " for i=1, pc-1 do indicator = indicator.." " end indicator = indicator.."^" end ---indicator = " ^" --end else indicator = "" for i=1, pc-1 do indicator = indicator.." " end indicator = indicator.."^" end outputf = "" if #output > 40*rows then temp = 0 while #output > temp do if temp + 40 > #output then break else temp = temp + 40 end end f = output:sub(temp-(40*rows)+1, #output) --print(temp.."/"..#output, 0, 100) for i=1, #f do outputf = outputf..f:sub(i, i) if i%40 == 0 then outputf = outputf.."\n" end end output = f --this single line makes optimisations else for i=1, #output do outputf = outputf..output:sub(i, i) if i%40 == 0 then outputf = outputf.."\n" end end end view = "["..tape[tc-3].."," ..tape[tc-2].."," ..tape[tc-1].."," ..">"..tape[tc].."<".."," ..tape[tc+1].."," ..tape[tc+2].."," ..tape[tc+3].."]\n(Cell No. "..(tc-3).."/"..#tape-(6)..")".. "\nCode (PC="..pc.."/"..#code.."):\n"..codef.."\n"..indicator .."\nSelected: "..selected.." ("..desc[select]..")".."\nState: "..state.. "\nTicks: "..ticks.."\nOutput:\n"..outputf print(view, 0, 0, 12, true) if state == "Paused" then --[[x, y, pressed = mouse() if not pressed then active = false end if pressed and not active then if x <= 119 then if tc ~= 4 then tc = tc - 1 end else if tc ~= #tape-3 then tc = tc + 1 end end active = true end]] if btnp(0) and select ~= #selectable then select = select + 1 end if btnp(1) and select ~= 1 then select = select - 1 end if btnp(2) and pc ~= 1 then pc = pc - 1 end if btnp(3) and pc ~= #code then pc = pc + 1 end if btnp(4) then code = code..selected pc = #code-1 pc = pc + 1 end if btnp(5) then code = code:sub(1, #code-1) pc = #code+1 pc = pc - 1 end elseif state == "Execute" then for i=1, ipf do --How many iterations per frame ticks = ticks + 1 if ticks%fpi == 0 then --How many frames per iteration command = code:sub(pc, pc) if command == "+" then tape[tc] = tape[tc] + 1 pc = pc + 1 elseif command == "-" then tape[tc] = tape[tc] - 1 pc = pc + 1 elseif command == ">" then if tc ~= tapelen+3 then tc = tc + 1 end pc = pc + 1 elseif command == "<" then if tc ~= 4 then tc = tc - 1 end pc = pc + 1 elseif command == "[" then if tape[tc] == 0 then while code:sub(pc, pc) ~= "]" do pc = pc + 1 end else table.insert(stack, pc) end pc = pc + 1 elseif command == "]" then if tape[tc] ~= 0 then pc = stack[#stack] else table.remove(stack) end pc = pc + 1 elseif command == "." then if tape[tc] >= 1 and tape[tc] <= #chars then output = output..chars:sub(tape[tc], tape[tc]) end pc = pc + 1 elseif command == "!" then output = output..tostring(tape[tc]) pc = pc + 1 elseif command == "," then state = "Input" elseif command == "e" then state = "Paused" else pc = pc + 1 end if pc > #code then state = "Paused" end end end elseif state == "Input" then print("- <"..input.."> +", 78, 36, 12, true) if btnp(2) then input = input - 1 end if btnp(3) then input = input + 1 end if btnp(4) then tape[tc] = input state = "Execute" pc = pc + 1 end end if btnp(6) then if state == "Paused" then state = "Execute" output = "" if pc >= #code then pc = 1 ticks = 0 end else state = "Paused" end end if btnp(7) then --select = 1 --input = 0 state = "Paused" output = "" tape = {"X","X","X"} stack = {} tc = 4 pc = 1 ticks = 0 for i=1, tapelen do table.insert(tape, 0) end for i=1, 3 do table.insert(tape, "X") end end end