0,]']±>Sï}WÿÍu§ðp8·d%qy)6o;]ÉA¦ösï÷ôôô”°ÂVl†3!°à        à   Àk­°Õm«°Ôp�-oprruuôÐkkkppÏpt²oðàimipdhdkkokrà‡�������������������7= F   À?`fffff`fÝÝÝÝ ÝÝ UUUUUUPUPUPUUUU```f`f`f````Ý ÝÝUUUUUPUP```f``f``f```fÝ ÝÝÝÝUUUUUUUUUPU`f``````````Ý ÝÝUUUUUUUPPU``ffff`fÝÝÝÝUUUUPUUPUUUUÐÝ Ð Ý ÐÝ Ý ÐÝÝÝÝÝÝ Ý`f`f`f`f`ffÐ ÐÝ Ð ÝÝÐ ÝÝÝ ÝÐÝffff``Ð ÐÐ ÐÝÐÝ ÐÝÐÐ Ý ÝÝÝffff`fÐÝ Ð Ð ÐÐ Ð ÐÐÝÝ ÝÝfffff`fÐ ÐÝÝÝ ÐÝÝÝ Ý ÝÝÝÐÝ `f`fff`ffÐÝ ÐÝ Ý ÐÝÝÐÝÝÐÝÝÝ ÐÝwpwwpwpwwÐ ÐÝÐ ÝÝÐ Ð Ý ÝÐ wwwwpwÐ ÐÝ ÐÝÐÐ ÐÝ ÐÝ ÐÝÝ wwwwwwÐÝ Ð Ð ÐÝÐ Ð Ý Ý pwwwwwppÐ ÐÐÝÝÝ Ð Ð Ð Ý ÐÝpwwwwpwwÐÝ ÐÝÝÝ Ð Ý Ð ÝÝÐÝ»» »»»» °»»»° »»»Ð ÐÝÐ ÝÝ Ð ÝÝ Ý ÝÐ »» »» » ° » °»Ð ÐÐ ÐÝÐÐ ÐÝÐÐ Ý Ý »»» »»» »»» »ÐÝ ÐÝÐ ÐÐ Ð ÐÐ ÝÝÝ »»»»» » ° » »Ð ÐÝ Ý ÝÝÝ ÝÝÝÐÝ»» »» °»»»° »»°» ÐÝ Ð Ý Ð ÐÝÝÐÝ ÐÝ ÐÝÐÝ ª ª ª ªª  ªÐ ÐÝ Ð ÝÝ ÝÝÝÝÐ ÝÐ ª ª ªª    ªÐ ÐÐ ÐÝÐÐ Ð Ý ÝÝ Ý ª ªªªªªÐÝ ÐÝÝÐ ÐÐ ÐÝÐ ÝÝ Ý ª ª ªª   ªÐ Ð Ý ÝÝÝ ÐÝÝÝÐÝÐÝ ª ªªªª   ª ÐÝ ÐÝÝÝ ÐÝ ÐÝÝÝ ÐÝÝ™ �™™™™� �™Ð ÐÐ Ð ÝÝÐ Ð ÐÝ ÐÝ™ ™ ™™ � ™Ð ÐÐÝ ÐÝÐÝ ÐÝ Ð Ý Ý™ ™ ™™™™™ÐÝ ÝÐ ÐÐ Ð Ð ÐÝ Ý�™™ ™™ � ™ Ð ÐÐÝ Ý ÐÝÝÐÝÝÝ ÐÝÐÝ �™™™ ™™� �™ ÐÝ Ý Ý ÐÝÝÝ ÐÝÝÝÐ ÐÝ ÝÝ Ý033033303333Ð ÐÐ Ð ÝÝÐ ÐÐ ÝÝ ÝÝÐÝ3330003Ð ÐÐÝ ÐÝÐÐ Ý ÐÝ ÝÝ ÝÝÝÝ333333ÐÝ Ð ÐÐ ÐÐÝÐ ÐÝ ÝÝÝ3330003Ð ÐÝ Ý Ý Ý ÐÝ ÐÝ ÝÝ ÐÝ 030330300333ÐÝ ÐÝÝÝ ÐÝÝÝ Ý """" Ð ÐÝÐ ÝÐ Ð ÝÐ Ð"""Ð ÐÐ ÐÝÐÐÝ ÐÝÐÝ """ÐÝ ÝÐ ÐÝÐ ÐÐ Ð"""Ð ÐÐ Ý ÐÝ Ý Ý """"" ÐÝ Ý ÐÝ Ð ÐÝ Ð Ð ÐÐ ÐÐ ÐÝ Ð ÐÝ Ð ÐÝ Ð ÐÐ Ð ÐÐ ÐÝ Ð ÐÐ ÐÐ Ð ÐÐ Ð ÐÝ ÐÝ ÝÝÐÝ ÝÝÐÝ Ý ÐÝÝÐÝÝÝ ÐÝ Ð ÐÐ ÐÐ Ð Ð ÝÝÐ ÐÝÝÐÝ ÐÝ ÐÝÐÝ ÐÝ ÐÐ Ð Ð ÐÐ Ð ÐÝ Ð Ð Ý ÐÝÝÐÝ Ý Ý Ý Ý ÐÝÝÐ ÐÐ ÐÐ ÝÐ Ð ÝÐ Ð ÐÐ ÐÐÝÐÐÝ ÐÝÐÐÝ ÐÝ ÐÝÝÐ ÐÐ ÐÐ ÐÝÐ ÐÐ ÐÝ Ý Ý ÐÝ ÐÝ ÐÝ Ý Ý Ý ÐÝÝÐ ÐÐ ÐÐ ÝÐ Ð ÐÐ Ð ÐÐÝ ÐÝÐÐÝ Ý ÐÝ ÐÝ Ð ÐÐ ÐÐ ÐÐ ÐÝÐ ÐÐÝ Ý Ý Ý ÐÝ ÐÝ Ý ÐÝÝÐÝ ÐÝÝÐÝ Ð ÐÐ ÐÝÐ ÐÝÝÐ ÐÐ Ð Ð ÐÐ Ý ÐÝ Ð ÐÐÝÐ ÐÐÝÐ Ð ÐÝ Ý ÐÝ Ý ÐÝÝÐÝ ÐÝ Ý Ý ÐÝÝÐÝ Ð ÐÐ ÐÐ ÝÐ ÝÝÐ ÐÐ ÐÐÝÐÐÝ Ð Ý ÐÝ Ð ÐÐ ÐÐ ÐÝÐ Ð ÐÐÝ Ý Ý Ð ÐÝÝÐÝ ÐÝÝÝ ÐÝÝÐ Ý Ð ÐÐ Ð ÝÝÝ Ð ÝÐ ÐÐÝ ÐÝÐÐ Ð ÐÝÐÐÝ Ð Ð ÐÝÐ Ð ÐÐ ÐÐÝÝÝ Ð ÝÝÝ ÐÝ ÐÝÝÝ Ý ÐÝ Ý Ð ÐÐ Ð ÐÐ ÝÝÐ ÝÐ ÐÐÝ Ý ÐÝÐÝ ÐÝÐÐÝ Ð Ð ÐÐ ÐÐ Ð ÐÐ ÐÐ Ý Ý ÐÝÝÝ îàîîîîÐÝ Ð ÐÝ Ý Ý ÐÝÝÝ ÐÝÝÝ Ð Ý Ý ÐÝÝÐÝ ÐÝÝÐÝ àîîàîàîÝÝ Ð ÐÐ ÝÐ ÝÝÐ ÝÐ Ð ÝÝ Ð ÝÐ ÐÝÝÐ ÝàîàààîààîàÝ Ð ÐÝ ÐÝÐÐÝÐÐ ÐÝÐÐÝ ÐÝÐÐ ÐÝÐÐ ÐÐ Ý ÐÝ Ý ààîààààÐ Ð Ð ÐÐ ÐÐ ÐÐÝÐ ÐÝÐ ÐÐÝÝÐ ÐÐÝÝÐÝÐ ÝÐ îàîîÐÝÝÝÝÐÝ Ý Ý Ý Ý ÐÝ Ý Ý Ð ÐÝ ÐÝÝÐÝ ÐÝÝîàîîîîÝ Ð Ý ÐÝÝÝ Ý Ý Ý Ý Ý Ý Ý Ý Ý Ý Ý àîîàîààÐ ÝÝ Ð ÝÝÐ ÝÐ ÝÐ ÝÐ ÝÐ ÝÐ ÝÐ ÝÐ ÝÐ ÝÐ ÝÐ ÝÐ ÝàîàààîàîÐÝÐÐ ÐÝÐÐ ÐÝÐÐÝÐÐÝÐÐÝÐÐÝÐÐÝÐÐÝÐÐÝÐÐÝÐÐÝÐÐÝÐÐÝÐààîààààÐ ÐÐÝÝÐ ÐÐÝÐ ÐÐ ÐÐ ÐÐ ÐÐ ÐÐ ÐÐ ÐÐ ÐÐ ÐÐ ÐÐ ÐÐ ÐîàîîÝ Ý Ý Ý Ý Ý Ý Ý Ý Ý Ý Ý Ý Ý Ý îàîîàîÝ Ð ÐÝÝÝ Ý ÐÝÝÝ ÐÝÝÝ ÐÝÝÝ Ý ÐÝÝÐÝ ÐÝ Ð àîîîàîÐ ÝÝ Ð Ð ÝÐ ÝÝÐ ÐÐ Ð ÝÐ Ð ÝÐ ÐÝÝÐ ÐÝ àîààààîàÐÝÐÐ ÐÝ ÐÝÐÐÝÐÐ Ý ÐÝ ÐÝÐÐÝ ÐÝÐÝ Ð Ý Ð ÐÐ ààîàààÐ ÐÐ Ð Ð ÐÐ ÐÐÝÐ ÐÝÐ ÐÝÐ ÐÐ ÐÐÝÐ Ð ÐÐ îàîîîÝ ÝÝÐÝÝÝ Ý Ý Ý ÐÝ Ý ÐÝ Ý Ý Ý ÐÝÝÐÝ ÝÝîàîîàîÝ ÐÝ Ý Ý Ý Ý Ý Ý Ý Ý Ý Ý Ý Ý Ý Ý àîîîààÐ ÝÝÐ ÝÐ ÐÐ ÝÐ ÝÐ ÝÐ ÝÐ ÝÐ ÝÐ ÝÐ ÝÐ ÝÐ ÝÐ ÝÐ ÝàîàààîÐÝÐÝ ÐÝÐÐ ÐÝÐÐÝÐÐÝÐÐÝÐÐÝÐÐÝÐÐÝÐÐÝÐÐÝÐÐÝÐÐÝÐÐÝÐààîàààÐ ÐÐ Ð ÐÐ ÐÐ ÐÐ ÐÐ ÐÐ ÐÐ ÐÐ ÐÐ ÐÐ ÐÐ ÐÐ ÐÐ ÐÐ ÐîàîîîÝ ÐÝÝÝ Ý Ý Ý Ý Ý Ý Ý Ý Ý Ý Ý Ý Ý îàîîàîîÝ ÐÝ ÐÝÝÝ Ý Ý Ý Ý Ý Ý Ý Ý Ý Ý Ý Ý àîîîàîÐ ÝÝÝÐ Ð ÝÐ ÝÐ ÝÐ ÝÐ ÝÐ ÝÐ ÝÐ ÝÐ ÝÐ ÝÐ ÝÐ ÝàîààîàîàÐÝÐÝ Ð ÐÝ ÐÝÐÐÝÐÐÝÐÐÝÐÐÝÐÐÝÐÐÝÐÐÝÐÐÝÐÐÝÐÐÝÐÐÝÐààîàààÐ ÐÐ ÝÐ ÐÐ ÐÐ ÐÐ ÐÐ ÐÐ ÐÐ ÐÐ ÐÐ ÐÐ ÐÐ ÐÐ ÐÐ ÐîààîîîÝ ÐÝÝÐ Ý Ý Ý Ý Ý Ý Ý Ý Ý Ý Ý Ý Ý ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÌüÿÌüÿÌüÏÌüÿÌÿÿÿÿÿÌÌÏÌüÏüÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÏüÌÏüÌÏüÏÏüÏÿÌÿÿÿÿÿÏüÏüÏÏüÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÏÌÏÏÌÏÏüÿÏÌüÿÿÿÿÿÿÿÏüÏüÏÏüÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÏüÏÏüÏÏüÏÏüÏÿÌÿÿÿÿÿÏüÏüÏÏüÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÌüÿÌüÿÌüÏÌüÿÌÿÿÿÿÿÌÌÏÌüÏÌÌÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ»1-- title: COSMAC VIP PIN-8 Player -- author: The Beesh-Spweesh! -- desc: RCA 1802 emulation experiment -- Emulator options CLOCKRATE=600 -- CPU instructions per tempo-frame SPEEDMULT=3 -- Tempo multiplier -- CPU registers init local R={[0]=0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} local X,P=0,0 local D=0x00 local DF=false local T=0x00 local Q=false local MIE=true local IDL=false local FREQA,FREQB,VOLA,VOLB=0xFF,0xFF,0,0 local OCTA,OCTB local INTEN=false local OUT3=0x00 local drumch=2 local function read(a) if a<0x4000 then return peek(0x8000+a) else return 0 end end local function write(a,v) if a<0x4000 then poke(0x8000+a,v) else if a==0x8001 then FREQA=v elseif a==0x8002 then FREQB=v elseif a==0x8003 then if v&0x04==0 then if v&0x10>0 then OCTA=v&3 else OCTA=nil end else if v&0x10>0 then OCTB=v&3 else OCTB=nil end end elseif a==0x8010 then VOLA=v&0xF elseif a==0x8020 then VOLB=v&0xF elseif a==0x8030 then INTEN=v&1>0 end --trace(x16(a).." = "..x8(v)) end end local function nextbyte() local b=read(R[P]) R[P]=R[P]+1&0xFFFF return b end local function EF1() return true end local EF2,EF3,EF4=EF1,EF1,EF1 local function input(n) local v=0 --trace("Input "..x8(v).." from port "..n) return v end local function output(n,v) if n==3 then local old=OUT3 OUT3=v if old~=v and Q then if v&1==0 then sfx(1,nil,-1,drumch,11) drumch=drumch~1 end if v&2==0 then sfx(2,nil,-1,drumch,11) drumch=drumch~1 end if v&4==0 then sfx(3,nil,-1,drumch,11) drumch=drumch~1 end if v&8==0 then sfx(4,nil,-1,drumch,11) drumch=drumch~1 end end end --trace("Output "..x8(v).." to port "..n) end local instrSet={ [0x00]=function() IDL=true R[P]=R[P]-1&0xFFFF end, [0x30]=function() R[P]=nextbyte()|R[P]&0xFF00 end, [0x31]=function() local b=nextbyte() if Q then R[P]=R[P]&0xFF00|b end end, [0x32]=function() local b=nextbyte() if D==0 then R[P]=R[P]&0xFF00|b end end, [0x33]=function() local b=nextbyte() if DF then R[P]=R[P]&0xFF00|b end end, [0x34]=function() local b=nextbyte() if EF1() then R[P]=R[P]&0xFF00|b end end, [0x35]=function() local b=nextbyte() if EF2() then R[P]=R[P]&0xFF00|b end end, [0x36]=function() local b=nextbyte() if EF3() then R[P]=R[P]&0xFF00|b end end, [0x37]=function() local b=nextbyte() if EF4() then R[P]=R[P]&0xFF00|b end end, [0x38]=function() R[P]=R[P]+1&0xFFFF end, [0x39]=function() local b=nextbyte() if not Q then R[P]=R[P]&0xFF00|b end end, [0x3A]=function() local b=nextbyte() if D>0 then R[P]=R[P]&0xFF00|b end end, [0x3B]=function() local b=nextbyte() if not DF then R[P]=R[P]&0xFF00|b end end, [0x3C]=function() local b=nextbyte() if not EF1() then R[P]=R[P]&0xFF00|b end end, [0x3D]=function() local b=nextbyte() if not EF2() then R[P]=R[P]&0xFF00|b end end, [0x3E]=function() local b=nextbyte() if not EF3() then R[P]=R[P]&0xFF00|b end end, [0x3F]=function() local b=nextbyte() if not EF4() then R[P]=R[P]&0xFF00|b end end, [0x60]=function() R[X]=R[X]+1&0xFFFF end, [0x68]=function() error("Illegal opcode 0x68") end, [0x70]=function() local t=read(R[X]) R[X]=R[X]+1&0xFFFF X,P,MIE=t>>4,t&0xF,true end, [0x71]=function() local t=read(R[X]) R[X]=R[X]+1&0xFFFF X,P,MIE=t>>4,t&0xF,false end, [0x72]=function() D=read(R[X]) R[X]=R[X]+1&0xFFFF end, [0x73]=function() write(R[X],D) R[X]=R[X]-1&0xFFFF end, [0x74]=function() D=D+read(R[X])+(DF and 1 or 0) DF=D>0xFF D=D&0xFF end, [0x75]=function() D=read(R[X])-D-(DF and 0 or 1) DF=D>=0 D=D&0xFF end, [0x76]=function() D=D|(DF and 0x100 or 0) DF=D&1>0 D=D>>1 end, [0x77]=function() D=D-read(R[X])-(DF and 0 or 1) DF=D>=0 D=D&0xFF end, [0x78]=function() write(R[X],T) end, [0x79]=function() T=X<<4|P write(R[2],T) X=P R[2]=R[2]-1&0xFFFF end, [0x7A]=function() Q=false end, [0x7B]=function() Q=true end, [0x7C]=function() D=D+nextbyte()+(DF and 1 or 0) DF=D>0xFF D=D&0xFF end, [0x7D]=function() D=nextbyte()-D-(DF and 0 or 1) DF=D>=0 D=D&0xFF end, [0x7E]=function() D=D<<1|(DF and 1 or 0) DF=D>0xFF D=D&0xFF end, [0x7F]=function() D=D-nextbyte()-(DF and 0 or 1) DF=D>=0 D=D&0xFF end, [0xC0]=function() R[P]=nextbyte()<<8|nextbyte() end, [0xC1]=function() local w=nextbyte()<<8|nextbyte() if Q then R[P]=w end end, [0xC2]=function() local w=nextbyte()<<8|nextbyte() if D==0 then R[P]=w end end, [0xC3]=function() local w=nextbyte()<<8|nextbyte() if DF then R[P]=w end end, [0xC4]=function() end, [0xC5]=function() if not Q then R[P]=R[P]+2&0xFFFF end end, [0xC6]=function() if D>0 then R[P]=R[P]+2&0xFFFF end end, [0xC7]=function() if not DF then R[P]=R[P]+2&0xFFFF end end, [0xC8]=function() R[P]=R[P]+2&0xFFFF end, [0xC9]=function() local w=nextbyte()<<8|nextbyte() if not Q then R[P]=w end end, [0xCA]=function() local w=nextbyte()<<8|nextbyte() if D>0 then R[P]=w end end, [0xCB]=function() local w=nextbyte()<<8|nextbyte() if not DF then R[P]=w end end, [0xCC]=function() if MIE then R[P]=R[P]+2&0xFFFF end end, [0xCD]=function() if Q then R[P]=R[P]+2&0xFFFF end end, [0xCE]=function() if D==0 then R[P]=R[P]+2&0xFFFF end end, [0xCF]=function() if DF then R[P]=R[P]+2&0xFFFF end end, [0xF0]=function() D=read(R[X]) end, [0xF1]=function() D=D|read(R[X]) end, [0xF2]=function() D=D&read(R[X]) end, [0xF3]=function() D=D~read(R[X]) end, [0xF4]=function() D=D+read(R[X]) DF=D>0xFF D=D&0xFF end, [0xF5]=function() D=read(R[X])-D DF=D>=0 D=D&0xFF end, [0xF6]=function() DF=D&1>0 D=D>>1 end, [0xF7]=function() D=D-read(R[X]) DF=D>=0 D=D&0xFF end, [0xF8]=function() D=nextbyte() end, [0xF9]=function() D=D|nextbyte() end, [0xFA]=function() D=D&nextbyte() end, [0xFB]=function() D=D~nextbyte() end, [0xFC]=function() D=D+nextbyte() DF=D>0xFF D=D&0xFF end, [0xFD]=function() D=nextbyte()-D DF=D>=0 D=D&0xFF end, [0xFE]=function() DF=D>0x7F D=D<<1&0xFF end, [0xFF]=function() D=D-nextbyte() DF=D>=0 D=D&0xFF end } for num=0,15 do if num>0 then instrSet[num]=function() D=read(R[num]) end end instrSet[0x10+num]=function() R[num]=R[num]+1&0xFFFF end instrSet[0x20+num]=function() R[num]=R[num]-1&0xFFFF end instrSet[0x40+num]=function() D=read(R[num]) R[num]=R[num]+1&0xFFFF end instrSet[0x50+num]=function() write(R[num],D) end instrSet[0x80+num]=function() D=R[num]&0xFF end instrSet[0x90+num]=function() D=R[num]>>8 end instrSet[0xA0+num]=function() R[num]=R[num]&0xFF00|D end instrSet[0xB0+num]=function() R[num]=R[num]&0xFF|D<<8 end instrSet[0xD0+num]=function() P=num end instrSet[0xE0+num]=function() X=num end end for num=1,7 do instrSet[0x60+num]=function() output(num,read(R[X])) R[X]=R[X]+1&0xFFFF end instrSet[0x68+num]=function() D=input(num) write(R[X],D) end end function x4(v) return ("%1X"):format(v) end function x8(v) return ("%02X"):format(v) end function x16(v) return ("%04X"):format(v) end function dis(op,h,l) local i,n=op>>4,op&0xF if i==0x0 then if n==0 then return "IDL" end return "LDN R"..x4(n) elseif i==0x1 then return "INC R"..x4(n) elseif i==0x2 then return "DEC R"..x4(n) elseif i==0x3 then if n==0x0 then return "BR "..x8(h) elseif n==0x1 then return "BQ "..x8(h) elseif n==0x2 then return "BZ "..x8(h) elseif n==0x3 then return "BDF "..x8(h) elseif n==0x4 then return "B1 "..x8(h) elseif n==0x5 then return "B2 "..x8(h) elseif n==0x6 then return "B3 "..x8(h) elseif n==0x7 then return "B4 "..x8(h) elseif n==0x8 then return "SKP" elseif n==0x9 then return "BNQ "..x8(h) elseif n==0xA then return "BNZ "..x8(h) elseif n==0xB then return "BNF "..x8(h) elseif n==0xC then return "BN1 "..x8(h) elseif n==0xD then return "BN2 "..x8(h) elseif n==0xE then return "BN3 "..x8(h) else return "BN4 "..x8(h) end elseif i==0x4 then return "LDA R"..x4(n) elseif i==0x5 then return "STR R"..x4(n) elseif i==0x6 then if n==0x0 then return "IRX" elseif n==0x8 then return "ILLEGAL" elseif n<0x8 then return "OUT "..n else return "INP "..n-8 end elseif i==0x7 then if n==0x0 then return "RET" elseif n==0x1 then return "DIS" elseif n==0x2 then return "LDXA" elseif n==0x3 then return "STXD" elseif n==0x4 then return "ADC" elseif n==0x5 then return "SDB" elseif n==0x6 then return "SHRC" elseif n==0x7 then return "SMB" elseif n==0x8 then return "SAV" elseif n==0x9 then return "MARK" elseif n==0xA then return "REQ" elseif n==0xB then return "SEQ" elseif n==0xC then return "ADCI "..x8(h) elseif n==0xD then return "SDBI "..x8(h) elseif n==0xE then return "SHLC" else return "SMBI "..x8(h) end elseif i==0x8 then return "GLO R"..x4(n) elseif i==0x9 then return "GHI R"..x4(n) elseif i==0xA then return "PLO R"..x4(n) elseif i==0xB then return "PHI R"..x4(n) elseif i==0xC then if n==0x0 then return "LBR "..x16(h<<8|l) elseif n==0x1 then return "LBQ "..x16(h<<8|l) elseif n==0x2 then return "LBZ "..x16(h<<8|l) elseif n==0x3 then return "LBDF "..x16(h<<8|l) elseif n==0x4 then return "NOP" elseif n==0x5 then return "LSNQ" elseif n==0x6 then return "LSNZ" elseif n==0x7 then return "LSNF" elseif n==0x8 then return "LSKP" elseif n==0x9 then return "LBNQ "..x16(h<<8|l) elseif n==0xA then return "LBNZ "..x16(h<<8|l) elseif n==0xB then return "LBNF "..x16(h<<8|l) elseif n==0xC then return "LSIE" elseif n==0xD then return "LSQ" elseif n==0xE then return "LSZ" else return "LSDF" end elseif i==0xD then return "SEP R"..x4(n) elseif i==0xE then return "SEX R"..x4(n) else if n==0x0 then return "LDX" elseif n==0x1 then return "OR" elseif n==0x2 then return "AND" elseif n==0x3 then return "XOR" elseif n==0x4 then return "ADD" elseif n==0x5 then return "SD" elseif n==0x6 then return "SHR" elseif n==0x7 then return "SM" elseif n==0x8 then return "LDI "..x8(h) elseif n==0x9 then return "ORI "..x8(h) elseif n==0xA then return "ANI "..x8(h) elseif n==0xB then return "XRI "..x8(h) elseif n==0xC then return "ADI "..x8(h) elseif n==0xD then return "SDI "..x8(h) elseif n==0xE then return "SHL" else return "SMI "..x8(h) end end end local tempoacc=0 function mainloop() --local lasttime=time() local oldPC=R[P] local o1=read(oldPC) local o2=read(oldPC+1&0xFFFF) local o3=read(oldPC+2&0xFFFF) --trace("FRAME BEGIN",3) tempoacc=tempoacc+SPEEDMULT for i=1,btn(5) and 0 or tempoacc do if MIE and INTEN then if IDL then R[P]=R[P]+1&0xFFFF IDL=false end T=X<<4|P X,P,MIE=2,1,false end for i=1,CLOCKRATE do local b=read(R[P]) R[P]=R[P]+1&0xFFFF instrSet[b]() end end tempoacc=tempoacc%1 cls() for i=0,15 do local xp=X==i and P==i print("R"..x4(i).." "..x16(R[i]),1,1+i*6, xp and 6 or X==i and 9 or P==i and 4 or 13,true) end print("D "..x8(D),52,1,13,true) print("DF "..(DF and 1 or 0),52,7,13,true) print("X "..x4(X),52,13,13,true) print("P "..x4(P),52,19,13,true) print("T "..x8(T),52,25,13,true) print("Q "..(Q and 1 or 0),52,31,13,true) print("MIE "..(MIE and 1 or 0),52,37,13,true) if IDL then print("(IDL)",52,43,2,true) end rect(0,128,240,8,15) print(x16(oldPC)..": "..dis(o1,o2,o3),1,129,12,true) for i=0,4 do local base=0x0700+i*8 print(x16(base),1,98+i*6,14,true) for j=0,7 do print(x8(read(base+j)),29+j*14,98+i*6,13,true) end end print("FREQA: "..x8(FREQA),186,1,5,true) print("OCTA: "..(OCTA or "-"),186,7,6,true) print("VOLA: "..x4(VOLA),186,13,7,true) print("FREQB: "..x8(FREQB),186,19,11,true) print("OCTB: "..(OCTB or "-"),186,25,10,true) print("VOLB: "..x4(VOLB),186,31,9,true) print("OUT3: "..x8(OUT3),186,37,3,true) if Q then if OCTA then local f=math.min((13757<>8) poke4(0xFF9D*2+1,VOLA) memcpy(0xFF9E,0xFFE4,16) end if OCTB then local f=math.min((13757<>8) poke4(0xFFAF*2+1,VOLB) memcpy(0xFFB0,0xFFE4,16) end end --print(time()-lasttime,160,129,12) end local mvbase=0 function memviewer() cls() for i=0,15 do local base=mvbase+i*8 print(x16(base),1,1+i*6,14,true) for j=0,7 do print(x8(read(base+j)),29+j*14,1+i*6,13,true) end end if btnp(0,30,6) then mvbase=mvbase+0x80&0x3FFF end if btnp(1,30,6) then mvbase=mvbase-0x80&0x3FFF end if btnp(4) then TIC=mainloop end end function TIC() cls() print("Press (A)/[Z] to run emulator",1,1,12) print("Press (B)/[X] to view binary (max 16 KB)",1,8,12) if btnp(4) then TIC=mainloop end if btnp(5) then TIC=memviewer end end --[[ for i=0x8270,0x82AE do poke(i,math.random(0,255)) end for i=0x8300,0x86FF do poke(i,math.random(0,255)) end --]]