óÀ ÌÀÀÀÀÀÀÀ ÌÀÌ," ," ," ÀÌ ªª ªª   ª             àîàîîîîàîàîîàîàîààîîîàîàîîîàîîîîàîàîÀÌÌÊ ÌÊ ÀÌ PUPUÐÝÐÐÐÐÐÐÐÝ ÐÝÐÐÝÐÐÝÐÝÐÐÝÐÐÝÐÐÐÐÐÝÐÐÐÝÐÐÝÐÐÝÐÝÐÐÝÐÐÐÝÐÝÐÐÐÐÐÝÐÐÐÝÐÐÐÝÐÝÐÐÐÝÐÐPUÐÝÐÝ03ÐÝÐÝ`fÐÝÐÝ "ÐÝÐÝ`f`f"" "  ª à àîî àî ÐÝ ÐÝ3<PPUP UPPPUP UPPUPPÐÝ ÐÝ0<  "lf,f lf l" " ,, `,`,f,f, l l"l"lf,f,`,`, "l"l l l ``fÌÌ "   "ÌÌ `f`"""ÌÌ ffffffÌÌ """                                                                                                                                                                                                                                                                ÀÌÌÀ Ì Ì ÀÌÌÀÌÌÌÀÌ ÌÌÀ ÀÌÌÌÌ ÌÌ À Ì À ÀÌÌÀÌÌÀÌÌ ÀÌÌ ÌÌÌÀ ÌÌÀÌÌÌÌÌ ÀÌÌÌ À ÌÀ ÌÀÌÌ ÀÌÌ ÀÌÀÌÌ ÀÌ ÀÌÀÌÌ Ì ÌÌ Ì ÌÌÌ ÌÌÌ ÌÌÀÌÌ ÌÌ ÀÌÌÌÌ Ì Ì ÌÌÌÌ ÌÌÌÌÌÌ ÌÌ ÌÌÌÌÌÀÌ ÌÌÀ Ì ÀÌ Ì Ì ÌÌ Ì Ì ÀÌ ÌÌÌÀÌ ÌÌ À À ÌÀ ÀÌÌ ÌÀÌ ÌÀÌ ÌÌÌÌÌÌ ÌÀ ÌÌ ÌÌ Ì Ì ÌÌ ÌÀ Ì ÀÌÌ Ì Ì ÀÌÌÌÌ Ì ÌÌÌÀÌÌ Ì Ì ÀÌ ÌÌÌ Ì ÌÌÌ ÀÌ Ì ÀÌÌ ÌÌÀÌ ÌÌÌÌÌ Ì Ì Ì ÀÌÌ Ì Ì ÀÌ  ÌÌ ÌÌ ÌÀ Ì Ì ÀÌÌ Ì À À ÀÌ ÌÌÌÌ ÌÀ ÌÌÌ ÀÌ À À ÀÌ ÌÌÌÌ Ì ÌÌÀÌ Ì Ì ÀÌ À ÀÌ À À ÀÌ ÀÌÌÀ Ì ÀÌÌ À ÌÌ À À ÀÌ À ÌÌ À ÀÌÌÌÌÌ Ì Ì ÌÌÌÌÀ À À À ÀÌÌÌ ÌÌÌ Ì À À À À Ì ÌÀÌÌ ÌÌÌ Ì Ì ÀÌÌ Ì ÀÌÌÌÌ Ì ÌÌÌÀÌ À À ÀÌ À ÌÌÌ ÌÌÀÌ Ì Ì ÌÌÀ ÌÌ À À Ì Ì Ì Ì ÀÌÌ Ì ÀÌ  ÌÌ ÌÀ ÌÀ ÀÌÀÌÌÀ  À À ÀÌ À ÀÌÌÌ ÌÀ ÌÌ ÀÀÌÌ ÀÀÌÌ ÀÀÀ À Á}ÁþÒñóø÷ïèé÷òóèõäñçÂþÒñóø÷õìêë÷òóèõäñçþÃþÒñóø÷ÁÂÃÄéòõäççöøåðøïçìùþ** !%* 3%!3%!3%!3þ) ) ) ) þþ $! ! 4 !  =Û>ÌÀÀÀÌ À À Ì À À ÀÌÌÌ ÌÌÌÌÌÌ ÌÌ À ÀÌÀ ÌÌ ÀÌÌÌÀÌÌÌÀÌ ÌÌÀÌ ÌÀÀÌÌ Ì Ì À À ÌÀ ÌÌ À Ì Ì ÌÀ Ì À Ì À ÌÌÌ ÌÌ Ì Ì À À Ì À À Ì Ì Ì Ì À Ì À ÀÌ ÀÀÀÌ Ì ÌÌÀÌÌ Ì ÀÌÀ Ì ÀÌÌÌÀÌÌÀÌ Ì ÀÌ ÌÌÌÌÀÀÀÌ À ÌÌÀ À À ÌÌ ÌÌÌÌÌÌ ÌÌ ÌÌÀÌÌÌÌÌ ÀÌÌÌÀÌÌÌÀÌ ÌÌÀÌ ÀÌÀÀÌÌ Ì Ì À Ì Ì À Ì À Ì Ì ÌÀ Ì À Ì À ÌÌÌ ÌÌ Ì Ì À ÌÌÌÌ Ì À Ì Ì Ì Ì À Ì À ÌÌ ÀÀÀÌ Ì ÌÌÀÌÌ ÌÌÀ Ì Ì ÀÌÌÌÀÌÌÀÌ Ì ÀÌ ÌÀÌÌÌÌ ÀÀÀÌ À ÌÌÌÌÌ ÌÀ ÌÌ ÌÌÌÌÌÌ ÌÌ ÀÌÀ À ÀÌÌÀÀÌÌ Ì Ì À ÌÀÌÌÌÀ À ÌÌ ÌÌ Ì Ì À ÌÌ À ÌÌ ÀÌÀÀÀÌ Ì ÌÌÀÌÌ ÀÌ ÌÌ ÀÌÀÌÌ À À ÌÀ À ÌÀ ÀÌÌÌÀÌ ÀÌ ÀÌ ÀÌ Ì ÌÌÌÀÌ À ÀÌ Ì ÌÌ Ì Ì À À À Ì Ì Ì ÌÌ Ì À À ÌÌ À Ì Ì À À À Ì Ì Ì Ì À À ÌÀÌÀ ÀÌÌÀÌ ÀÌ ÀÌ ÌÌÀÌÌÌ ÀÌÌ ÀÌ Ì À ÌÀÀÐÝÐÝîà  îîÀÀ PU PUàî  àîÀÀÐÝÐÝÀ ÌîàÐÝàîî  àîàî ªÐÝPU îîàî  àîÐÝàÀÌ ," lÐÝ ªlÐÝ ªlÐÝ ªl,"    ," ÀÌPUPUPUPU    Pªª ªª  ª UP  P  îîîîîîPîîPîîPîîàîàîUPàîUPàîUPàîàîîîPîîPîîPîîîîîîîîîàÀÀ À ÀÌ  À À À À Ì ÀÌ Ì À À ÀÀÀÌ ÀÌ À À ÀÌÀ ÀÌ À Ì Ì Ì À ÀÀ ÀÌ À À ÀÀÀÀ À À À 0-- title: 2d turing machine ??? -- author: ElNico56 -- desc: Heavily inspired by "Befunge-ish" by "anastasia" -- script: lua local W,H=240,136 local SPRs={ -- sprite ids void=0, -- nothingness head=1, -- program head/cursor halt=2, -- end of program add=3, -- pop top 2 values and push A+B sub=4, -- pop top 2 values and push A-B mul=5, -- pop top 2 values and push A*B div=6, -- pop top 2 values and push A/B mod=7, -- pop top 2 values and push A%B up=8, -- change direction to up dn=9, -- change direction to down lf=10, -- change direction to left rt=11, -- change direction to right rn=12, -- change direction randomly out=13, -- pop top value and show as ASCII psh=14, -- push acc value pop=15, -- pop top value digits=16, -- digits marker srt=26, -- subroutine to popped values as X,Y and push current pos ret=27, -- return to popped values as X,Y save=28, -- pop two values and store V in address A load=29, -- pop top value and push value stored in A ipsh=30, -- push from the other end of the stack ipop=31, -- pop from the other end of the stack clr=32, -- clear stack dup=33, -- pop top value and push it twice swp=34, -- pop top 2 values, swap and push them eq=35, -- pop top, push 0 if A=B, 1 if A>B, -1 A=SPRs.digits and tile0 then head.dir=3 else head.dir=4 end head.state="UzLpRn" end if tile==SPRs.uzrpln then local n=table.remove(head.stack) if n==0 then head.dir=1 elseif n>0 then head.dir=4 else head.dir=3 end head.state="UzRpLn" end if tile==SPRs.dzrpln then local n=table.remove(head.stack) if n==0 then head.dir=2 elseif n>0 then head.dir=4 else head.dir=3 end head.state="DzRpLn" end if tile==SPRs.dzlprn then local n=table.remove(head.stack) if n==0 then head.dir=2 elseif n>0 then head.dir=3 else head.dir=4 end head.state="DzLpRn" end if tile==SPRs.lzupdn then local n=table.remove(head.stack) if n==0 then head.dir=3 elseif n>0 then head.dir=1 else head.dir=2 end head.state="LzUpDn" end if tile==SPRs.lzdpun then local n=table.remove(head.stack) if n==0 then head.dir=3 elseif n>0 then head.dir=2 else head.dir=1 end head.state="LzDpUn" end if tile==SPRs.rzdpun then local n=table.remove(head.stack) if n==0 then head.dir=4 elseif n>0 then head.dir=2 else head.dir=1 end head.state="RzDpUn" end if tile==SPRs.rzdpun then local n=table.remove(head.stack) if n==0 then head.dir=4 elseif n>0 then head.dir=1 else head.dir=2 end head.state="RzDpUn" end ------------------ stack stuff ------------------ if tile==SPRs.psh then table.insert(head.stack,tonumber(head.acc)) head.state="Push "..head.acc head.acc="" end if tile==SPRs.pop then table.remove(head.stack) head.state="Pop" end if tile==SPRs.ipsh then table.insert(head.stack,1,tonumber(head.acc)) head.state="Inverse push "..head.acc head.acc="" end if tile==SPRs.ipop then table.remove(head.stack,1) head.state="Inverse pop" end if tile==SPRs.clr then head.stack={} head.state="Stack clear" end ------------------ stack operators ------------------ if tile==SPRs.add then local B=table.remove(head.stack) local A=table.remove(head.stack) table.insert(head.stack,A+B) head.state="Push "..A.."+"..B end if tile==SPRs.sub then local B=table.remove(head.stack) local A=table.remove(head.stack) table.insert(head.stack,A-B) head.state="Push "..A.."-"..B end if tile==SPRs.mul then local B=table.remove(head.stack) local A=table.remove(head.stack) table.insert(head.stack,A*B) head.state="Push "..A.."*"..B end if tile==SPRs.div then local B=table.remove(head.stack) local A=table.remove(head.stack) table.insert(head.stack,A/B) head.state="Push "..A.."/"..B end if tile==SPRs.mod then local B=table.remove(head.stack) local A=table.remove(head.stack) table.insert(head.stack,A%B) head.state="Push "..A.."%"..B end if tile==SPRs.dup then local n=table.remove(head.stack) table.insert(head.stack,n) table.insert(head.stack,n) head.state="Duplicate "..n end if tile==SPRs.swp then local A=table.remove(head.stack) local B=table.remove(head.stack) table.insert(head.stack,A) table.insert(head.stack,B) head.state="Swapping "..A.." with "..B end if tile==SPRs.eq then local B=table.remove(head.stack) local A=table.remove(head.stack) if A==B then table.insert(head.stack,0) elseif A>B then table.insert(head.stack,1) else table.insert(head.stack,-1) end head.state="Compare "..A.." and "..B end if tile==SPRs.out then local n=table.remove(head.stack) head.output=head.output..string.char(n) head.state="Pop and show as ASCII " end if tile==SPRs.inc then local n=table.remove(head.stack) table.insert(head.stack,n+1) head.state="Increment by 1" end if tile==SPRs.dec then local n=table.remove(head.stack) table.insert(head.stack,n-1) head.state="Decrement by 1" end ------------------ board operators ------------------ if tile==SPRs.srt then local y=table.remove(head.stack) local x=table.remove(head.stack) table.insert(head.stack,head.x) table.insert(head.stack,head.y) head.x = x head.y = y head.state="Subroutine at: "..x..", "..y end if tile==SPRs.ret then local y=table.remove(head.stack) local x=table.remove(head.stack) head.x = x head.y = y head.state="Warping to: "..x..", "..y end if tile==SPRs.coordupe then local y=table.remove(head.stack) local x=table.remove(head.stack) table.insert(head.stack,x) table.insert(head.stack,y) table.insert(head.stack,x) table.insert(head.stack,y) head.state="Duped coord pair" end if tile==SPRs.loc then table.insert(head.stack,head.x) table.insert(head.stack,head.y) head.state="Push current head position" end if tile==SPRs.tget then local y=table.remove(head.stack) local x=table.remove(head.stack) table.insert(head.stack,mget(x,y)) head.state="mget("..x..","..y..")" end if tile==SPRs.tset then local v=table.remove(head.stack) local y=table.remove(head.stack) local x=table.remove(head.stack) mset(x,y,v) head.state="mset("..x..","..y..","..v..")" end ------------------ move ------------------ local jump=1 if not head.req then if tile==SPRs.jump then jump=2 end if head.dir==1 then head.y=head.y-jump end if head.dir==2 then head.y=head.y+jump end if head.dir==3 then head.x=head.x-jump end if head.dir==4 then head.x=head.x+jump end head.x=head.x%240 head.y=head.y%136 end ------------------ input request ------------------ if tile==SPRs.req then head.req=true head.state="Waiting numeric input..." end end local speed=5 local show=true local autostep=false local offx,offy=0,0 function TIC() cls() if btnp(0,15,2) then offy=offy-1 end if btnp(1,15,2) then offy=offy+1 end if btnp(2,15,2) then offx=offx-1 end if btnp(3,15,2) then offx=offx+1 end map(offx,offy) if autostep then step() end if btnp(4) then step() end if btn(5) then step() end if btnp(6) then autostep=not autostep end spr(SPRs.head,((head.x-offx)%240)*8,((head.y-offy)%136)*8,0) if btnp(7) then show = not show end if show then print( "ACC: "..head.acc.. "\nSTATE: "..head.state.. "\nOUTPUT: "..head.output, 0,H-18,12,true,1,true ) local stack={} local j=#head.stack+1 for i,v in ipairs(head.stack) do stack[j-i]=head.stack[i] end print(table.concat(stack,"\n"),0,0,12,true,1,true) end ------------------ input request ------------------ if head.req then for i=1,10 do if keyp(i+26,15,1) then head.acc=head.acc..i-1 end end if keyp(51,15,1) then head.acc=string.sub(head.acc,0,-2) end if keyp(37) then if head.acc=="" then head.acc="0" end head.acc=tostring(0-head.acc) end if keyp(50) then head.req=false if head.acc=="" then head.acc="0" end head.state="Input entered" end end end