1
0
mirror of https://github.com/sehugg/8bitworkshop.git synced 2024-06-02 12:41:30 +00:00
8bitworkshop/gen/vectrex-F4KLHI2D.js

5 lines
20 KiB
JavaScript
Raw Normal View History

import{F as Q,d as B,e as w,m as E,n as y}from"./chunk-TIPL7ZBK.js";import{$ as g,I,P as n,T as u,V as r,X as b,Y as l,_ as a,g as o,l as C,m as f,r as c}from"./chunk-BHN4Q7CX.js";import"./chunk-RQFURXHW.js";var p=[{id:"hello.xasm",name:"Hello World (ASM)"},{id:"hello.c",name:"Hello World (CMOC)"},{id:"joystick.c",name:"Joystick Test (CMOC)"},{id:"threed.c",name:"3D Transformations (CMOC)"}],d=l([[r.LEFT,0,1],[r.RIGHT,0,2],[r.DOWN,0,4],[r.UP,0,8],[r.GP_B,2,1],[r.GP_A,2,2],[r.GP_D,2,4],[r.GP_C,2,8],[r.P2_LEFT,1,1],[r.P2_RIGHT,1,2],[r.P2_DOWN,1,4],[r.P2_UP,1,8],[r.P2_GP_B,2,16],[r.P2_GP_A,2,32],[r.P2_GP_D,2,64],[r.P2_GP_C,2,128]]),D=class{constructor(t){this.ora=0;this.orb=0;this.ddra=0;this.ddrb=0;this.t1on=0;this.t1int=0;this.t1c=0;this.t1ll=0;this.t1lh=0;this.t1pb7=0;this.t2on=0;this.t2int=0;this.t2c=0;this.t2ll=0;this.sr=0;this.srb=0;this.src=0;this.srclk=0;this.acr=0;this.pcr=0;this.ifr=0;this.ier=0;this.ca2=0;this.cb2h=0;this.cb2s=0;this.vectrex=t}reset(){this.ora=0,this.orb=0,this.ddra=0,this.ddrb=0,this.t1on=0,this.t1int=0,this.t1c=0,this.t1ll=0,this.t1lh=0,this.t1pb7=128,this.t2on=0,this.t2int=0,this.t2c=0,this.t2ll=0,this.sr=0,this.srb=8,this.src=0,this.srclk=0,this.acr=0,this.pcr=0,this.ifr=0,this.ier=0,this.ca2=1,this.cb2h=1,this.cb2s=0}int_update(){this.ifr&127&(this.ier&127)?this.ifr|=128:this.ifr&=127}step0(){var t=0;if(this.t1on&&(this.t1c=this.t1c>0?this.t1c-1:65535,(this.t1c&65535)==65535&&(this.acr&64?(this.ifr|=64,this.int_update(),this.t1pb7^=128,this.t1c=this.t1lh<<8|this.t1ll):this.t1int&&(this.ifr|=64,this.int_update(),this.t1pb7=128,this.t1int=0))),this.t2on&&(this.acr&32)==0&&(this.t2c=this.t2c>0?this.t2c-1:65535,(this.t2c&65535)==65535&&this.t2int&&(this.ifr|=32,this.int_update(),this.t2int=0)),this.src=this.src>0?this.src-1:255,(this.src&255)==255?(this.src=this.t2ll,this.srclk?(t=1,this.srclk=0):(t=0,this.srclk=1)):t=0,this.srb<8){switch(this.acr&28){case 0:break;case 4:t&&(this.sr<<=1,this.srb++);break;case 8:this.sr<<=1,this.srb++;break;case 12:break;case 16:t&&(this.cb2s=this.sr>>7&1,this.sr<<=1,this.sr|=this.cb2s);break;case 20:t&&(this.cb2s=this.sr>>7&1,this.sr<<=1,this.sr|=this.cb2s,this.srb++);break;case 24:this.cb2s=this.sr>>7&1,this.sr<<=1,this.sr|=this.cb2s,this.srb++;break;case 28:break}this.srb==8&&(this.ifr|=4,this.int_update())}}step1(){(this.pcr&14)==10&&(this.ca2=1),(this.pcr&224)==160&&(this.cb2h=1)}read(t){var s;switch(t&15){case 0:return this.acr&128?s=this.orb&95|this.t1pb7|this.vectrex.alg.compare:s=this.orb&223|this.vectrex.alg.compare,s&255;case 1:(this.pcr&14)==8&&(this.ca2=0);case 15:return(this.orb&24)==8?s=this.vectrex.psg.readData():s=this.ora,s&255;case 2:return this.ddrb&255;case 3:return this.ddra&255;case 4:return s=this.t1c,this.ifr&=191,this.t1on=0,this.t1int=0,this.t1pb7=128,this.int_update(),s&255;case 5:return this.t1c>>8&255;case 6:return this.t1ll&255;case 7:return this.t1lh&255;case 8:return s=this.t2c,this.ifr&=223,this.t2on=0,this.t2int=0,this.int_update(),s&255;case 9:return this.t2c>>8;case 10:return s=this.sr,this.ifr&=251,this.srb=0,this.srclk=1,this.int_update(),s&255;case 11:return this.acr&255;case 12:return this.pcr&255;case 13:return this.ifr&255;case 14:return(this.ier|128)&255}}write(t,s){switch(t&15){case 0:this.orb=s,this.vectrex.snd_update(),this.vectrex.alg.update(),(this.pcr&224)==128&&(this.cb2h=0);break;case 1:(this.pcr&14)==8&&(this.ca2=0);case 15:this.ora=s,this.vectrex.snd_update(),this.vectrex.alg.xsh=s^128,this.vectrex.alg.update();break;case 2:this.ddrb=s;break;case 3:this.ddra=s;break;case 4:this.t1ll=s;break;case 5:this.t1lh=s,this.t1c=this.t1lh<<8|this.t1ll,this.ifr&=191,this.t1on=1,this.t1int=1,this.t1pb7=0,this.int_update();break;case 6:this.t1ll=s;break;case 7:this.t1lh=s;break;case 8:this.t2ll=s;break;case 9:this.t2c=s<<8|this.t2ll,this.ifr&=223,this.t2on=1,this.t2int=1,this.int_update();break;case 10:this.sr=s,this.ifr&=251,this.srb=0,this.srclk=1,this.int_update();break;case 11:this.acr=s;break;case 12:this.pcr=s,(this.pcr&14)==12?this.ca2=0:this.ca2=1,(this.pcr&224)==192?this.cb2h=0:this.cb2h=1;break;case 13:this.ifr&=
`;return s}},A={VECTREX_MHZ:15e5,VECTREX_COLORS:128,ALG_MAX_X:33e3,ALG_MAX_Y:41e3,SCREEN_X_DEFAULT:900,SCREEN_Y_DEFAULT:1100,BOUNDS_MIN_X:0,BOUNDS_MAX_X:3e4,BOUNDS_MIN_Y:41e3,BOUNDS_MAX_Y:0},m=class{constructor(t){this.videoEnabled=!0;this.rsh=0;this.xsh=0;this.ysh=0;this.zsh=0;this.jch0=0;this.jch1=0;this.jch2=0;this.jch3=0;this.jsh=0;this.compare=0;this.dx=0;this.dy=0;this.curr_x=0;this.curr_y=0;this.max_x=A.ALG_MAX_X>>1;this.max_y=A.ALG_MAX_Y>>1;this.vectoring=!1;this.vector_x0=0;this.vector_y0=0;this.vector_x1=0;this.vector_y1=0;this.vector_dx=0;this.vector_dy=0;this.vector_color=0;this.vectrex=t}reset(){this.rsh=128,this.xsh=128,this.ysh=128,this.zsh=0,this.jch0=128,this.jch1=128,this.jch2=128,this.jch3=128,this.jsh=128,this.compare=0,this.dx=0,this.dy=0,this.curr_x=A.ALG_MAX_X>>1,this.curr_y=A.ALG_MAX_Y>>1,this.vectoring=!1}update(){var t=this.vectrex.via;switch(t.orb&6){case 0:this.jsh=this.jch0,(t.orb&1)==0&&(this.ysh=this.xsh);break;case 2:this.jsh=this.jch1,(t.orb&1)==0&&(this.rsh=this.xsh);break;case 4:this.jsh=this.jch2,(t.orb&1)==0&&(this.xsh>128?this.zsh=this.xsh-128:this.zsh=0);break;case 6:this.jsh=this.jch3;break}this.jsh>this.xsh?this.compare=32:this.compare=0,this.dx=this.xsh-this.rsh,this.dy=this.rsh-this.ysh}step(){var t=this.vectrex.via,s=0,i=0,h=0,e=0;t.acr&16?e=t.cb2s:e=t.cb2h,t.ca2==0?(s=this.max_x-this.curr_x,i=this.max_y-this.curr_y):(t.acr&128?h=t.t1pb7:h=t.orb&128,h==0?(s=this.dx,i=this.dy):(s=0,i=0)),this.vectoring?e==0?(this.vectoring=!1,this.addline(this.vector_x0,this.vector_y0,this.vector_x1,this.vector_y1,this.vector_color)):(s!=this.vector_dx||i!=this.vector_dy||(this.zsh&255)!=this.vector_color)&&(this.addline(this.vector_x0,this.vector_y0,this.vector_x1,this.vector_y1,this.vector_color),this.curr_x>=0&&this.curr_x<A.ALG_MAX_X&&this.curr_y>=0&&this.curr_y<A.ALG_MAX_Y?(this.vector_x0=this.curr_x,this.vector_y0=this.curr_y,this.vector_x1=this.curr_x,this.vector_y1=this.curr_y,this.vector_dx=s,this.vector_dy=i,this.vector_color=this.zsh&255):this.vectoring=!1):e==1&&this.curr_x>=0&&this.curr_x<A.ALG_MAX_X&&this.curr_y>=0&&this.curr_y<A.ALG_MAX_Y&&(this.vectoring=!0,this.vector_x0=this.curr_x,this.vector_y0=this.curr_y,this.vector_x1=this.curr_x,this.vector_y1=this.curr_y,this.vector_dx=s,this.vector_dy=i,this.vector_color=this.zsh&255),this.curr_x+=s,this.curr_y+=i,this.vectoring&&this.curr_x>=0&&this.curr_x<A.ALG_MAX_X&&this.curr_y>=0&&this.curr_y<A.ALG_MAX_Y&&(this.vector_x1=this.curr_x,this.vector_y1=this.curr_y)}addline(t,s,i,h,e){!this.videoEnabled||(t=(t-A.BOUNDS_MIN_X)/(A.BOUNDS_MAX_X-A.BOUNDS_MIN_X)*A.SCREEN_X_DEFAULT,i=(i-A.BOUNDS_MIN_X)/(A.BOUNDS_MAX_X-A.BOUNDS_MIN_X)*A.SCREEN_X_DEFAULT,s=(s-A.BOUNDS_MIN_Y)/(A.BOUNDS_MAX_Y-A.BOUNDS_MIN_Y)*A.SCREEN_Y_DEFAULT,h=(h-A.BOUNDS_MIN_Y)/(A.BOUNDS_MAX_Y-A.BOUNDS_MIN_Y)*A.SCREEN_Y_DEFAULT,this.vectrex.video.drawLine(t,s,i,h,e,7))}saveState(){return c(null,{},this)}loadState(t){c(null,this,t)}toLongString(t){var s="";for(var i in t)s+=i+": "+t[i]+`
`;return s}},v=class extends Q{constructor(t){super();this.nullProbe=new y;this.probe=this.nullProbe;this.mainElement=t}getPresets(){return p}start(){this.via=new D(this),this.alg=new m(this),this.bios=a(new C().decode(f(atob(G))),8192),this.ram=new Uint8Array(1024),this.inputs=new Uint8Array(4);var t={read:g([[0,32767,0,s=>this.rom&&this.rom[s]],[51200,53247,1023,s=>this.ram[s]],[53248,57343,15,s=>this.via.read(s)],[57344,65535,8191,s=>this.bios&&this.bios[s]]]),write:g([[51200,53247,1023,(s,i)=>{this.ram[s]=i}],[53248,55295,1023,(s,i)=>{this.via.write(s&15,i)}],[55296,57343,1023,(s,i)=>{this.ram[s]=i,this.via.write(s&15,i)}]])};this.bus={read:s=>{var i=t.read(s);return this.probe.logRead(s,i),i},write:(s,i)=>{this.probe.logWrite(s,i),t.write(s,i)}},this._cpu=this.newCPU(this.bus),this.video=new n(this.mainElement,A.SCREEN_X_DEFAULT,A.SCREEN_Y_DEFAULT),this.video.persistenceAlpha=.2,this.audio=new B,this.psg=new w(this.audio),this.video.create(),this.timer=new u(60,this.nextFrame.bind(this)),b(this.video,this.inputs,d)}updateControls(){this.alg.jch0=this.inputs[0]&1?0:this.inputs[0]&2?255:128,this.alg.jch1=this.inputs[0]&4?0:this.inputs[0]&8?255:128,this.alg.jch2=this.inputs[1]&1?0:this.inputs[1]&2?255:128,this.alg.jch3=this.inputs[1]&4?0:this.inputs[1]&8?255:128,this.psg.psg.register[14]=~this.inputs[2]}advance(t){t||this.video.clear(),this.alg.videoEnabled=!t,this.updateControls(),this.probe.logNewFrame();for(var s=15e5/60,i=0;i<s;)i+=this.nextCycle();return i}nextCycle(){this.probe.logExecute(this.getPC(),this.getSP()),this.via.ifr&128&&this._cpu.interrupt();var t=this.runCPU(this._cpu,1);t==0&&(t=1),this.probe.logClocks(t);for(var s=0;s<t;s++)this.via.step0(),this.alg.step(),this.via.step1();return t}snd_update(){switch(this.via.orb&24){case 0:break;case 8:break;case 16:this.psg.curreg!=14&&this.psg.setData(this.via.ora);break;case 24:(this.via.ora&240)==0&&this.psg.selectRegister(this.via.ora&15);break}}getCPUState(){return this._cpu.saveState()}loadROM(t,s){this.rom=a(s,32768),this.reset()}loadBIOS(t,s){this.bios=a(s,8192),this.reset()}isRunning(){return this.timer.isRunning()}pause(){this.timer.stop(),this.audio.stop()}resume(){this.timer.start(),this.audio.start()}reset(){this._cpu.reset(),this.via.reset(),this.alg.reset()}readAddress(t){return(t&61440)!=53248?this.bus.read(t):null}loadState(t){this._cpu.loadState(t.c),this.ram.set(t.b),this.via.loadState(t.via),this.alg.loadState(t.alg),this.loadControlsState(t)}saveState(){return{c:this.getCPUState(),b:this.ram.slice(0),via:this.via.saveState(),alg:this.alg.saveState(),in:this.inputs.slice(0)}}loadControlsState(t){this.inputs.set(t.in)}saveControlsState(){return{in:this.inputs.slice(0)}}getMemoryMap(){return{main:[{name:"Cartridge ROM",start:0,size:32768,type:"rom"},{name:"RAM",start:51200,size:1024,type:"ram"},{name:"I/O Registers",start:53248,size:128,type:"io"},{name:"BIOS",start:57344,size:8192,type:"rom"}]}}getDebugCategories(){return super.getDebugCategories().concat(["VIA6522","ANALOG"])}getDebugInfo(t,s){switch(t){case"VIA6522":return this.via.toLongString(s.via);case"ANALOG":return this.alg.toLongString(s.alg);default:return super.getDebugInfo(t,s)}}startProbing(){var t=new E(this);return this.connectProbe(t),t}stopProbing(){this.connectProbe(null)}connectProbe(t){this.probe=t||this.nullProbe}};I.vectrex=v;var G="TFpHAAAgAAAAG/A3SzUgAXSsbrHtd/hQMOhNSU5FgPhQAN5TVE9STYAAjsiDb4CMy8Um+b3o43zIJIa7t8iAjgEBv8iBrAUTcCb5IAC98a/MAgC996kKeQ9WD5uOyKi9+E+OyK+xo/mxocwAAb34fI7JAKwIBO2rn8SfxoYFl9mX2pfbICS96GYQjsjElpuupjAEr6aO7aduA4amBYQDJgIM2W7tvefkbtuGpoQrBb3hKSBB3PCDAAHd8CcUNAi98aq96s/O7i+96p01CJYPJySOyKjOy+u9+NiOyK9uwdzwECb/RL3xiw87EM7L6n7wHG4w6vC95R694mK95Li941M1CL3rQ73sRr3slb3mRyXflr0QJ/9hlr5uMZJ+4KWfwsx/AN3cl7eGIJecjuHnn52OyTOfuYYdl7gPVs7td732jTQIvecRvfaHliaFASYCCresAlnqz73yiawCX/Kl9si3JxyO7yYQvsjcvep/ju9dsaOUsaE1CArcIMA1CA+chgSXt4Z/l7iWtydK1rgnBAq4IBLWJsQfJgxKl7eewqaGxgO96aGsBLXyqc7uIL3qnRCO4PjO7ae2yJvuxr3qqKwHzawEyuZHILI5CrgnTgztvfUXhAeLBJec3rmGgKfE3NyLCKdEb0XnRm9HbhNNKwyBECwCiwyBYC8OIO6B8C8CgAyBoCwCIOKnyBEfiR2KAafIEG9CMcgSEJ+5OQACBxAAIBgQAQAFAAMlB1AAAAEAADU
//# sourceMappingURL=vectrex-F4KLHI2D.js.map