1
0
mirror of https://github.com/sehugg/8bitworkshop.git synced 2024-11-15 14:07:16 +00:00
8bitworkshop/gen/williams-6FMADIXT.js

4 lines
13 KiB
JavaScript

import{D as _0,F as P0,K as y0,d as N,i as V,q as b0,s as w0}from"./chunk-TV4YGKI4.js";import{$ as l,J as D,P as l0,R as k,T as d0,V as f,W as p0,X as v0,Y as A,_ as g,g as b}from"./chunk-Z5CU44VP.js";import"./chunk-5XVCUSSZ.js";var j=8,W0=304,Z=class extends b0{constructor(t){super();this.isDefender=t;this.xtal=12e6;this.cpuFrequency=this.xtal/3/4;this.cpuCyclesPerLine=54;this.canvasWidth=256;this.numTotalScanlines=304;this.numVisibleScanlines=304;this.defaultROMSize=49152;this.rotate=-90;this.sampleRate=1;this.ram=new Uint8Array(49152);this.nvram=new Uint8Array(1024);this.rom=new Uint8Array(49152);this.portsel=0;this.banksel=0;this.watchdog_counter=0;this.watchdog_enabled=!1;this.pia6821=new Uint8Array(8);this.blitregs=new Uint8Array(8);this.palette=new Uint32Array(16);this.screenNeedsRefresh=!1;this.cpuScale=1;this.waitCycles=0;this.palette.fill(4278190080),this.initBus(t),this.initInputs(t),this.initAudio(),this.initCPU()}initInputs(t){var n=A([[f.A,4,1],[f.RIGHT,4,2],[f.B,4,4],[f.VK_X,4,8],[f.P2_START,4,16],[f.START,4,32],[f.LEFT,4,64],[f.DOWN,4,128],[f.UP,6,1],[f.SELECT,0,4],[f.VK_7,0,1],[f.VK_8,0,2],[f.VK_9,0,8]]),s=A([[f.P2_UP,0,1],[f.P2_DOWN,0,2],[f.P2_LEFT,0,4],[f.P2_RIGHT,0,8],[f.START,0,16],[f.P2_START,0,32],[f.UP,0,64],[f.DOWN,0,128],[f.LEFT,2,1],[f.RIGHT,2,2],[f.VK_7,4,1],[f.VK_8,4,2],[f.VK_6,4,4],[f.VK_9,4,8],[f.SELECT,4,16]]),o=t?n:s;this.handler=p0(this.pia6821,o)}initBus(t){var n=l([[1024,1535,511,r=>this.nvram[r]],[2048,2048,0,r=>this.scanline],[3072,3079,7,r=>this.pia6821[r]],[0,4095,0,r=>{}]]),s=l([[0,15,15,this.setPalette.bind(this)],[1020,1023,0,(r,a)=>{a==56&&(this.watchdog_counter=j),this.watchdog_enabled=!0}],[1024,1535,511,(r,a)=>{this.nvram[r]=a}],[3074,3074,1,(r,a)=>{this.worker&&this.worker.postMessage({command:a&63})}],[3072,3079,7,(r,a)=>{this.pia6821[r]=a}],[0,4095,0,(r,a)=>{}]]),o=l([[0,49151,65535,r=>this.ram[r]],[49152,53247,4095,r=>{switch(this.banksel){case 0:return n(r);case 1:return this.rom[r+12288];case 2:return this.rom[r+16384];case 3:return this.rom[r+20480];case 7:return this.rom[r+24576];default:return 0}}],[53248,65535,65535,r=>this.rom?this.rom[r-53248]:0]]),v=l([[0,38911,0,this.write_display_byte.bind(this)],[38912,49151,0,(r,a)=>{this.ram[r]=a}],[49152,53247,4095,s.bind(this)],[53248,57343,0,(r,a)=>{this.banksel=a&7}],[0,65535,0,(r,a)=>{}]]),m=l([[2052,2055,3,r=>this.pia6821[r]],[2060,2063,3,r=>this.pia6821[r+4]],[2816,3071,0,r=>this.scanline],[3072,4095,1023,r=>this.nvram[r]],[0,4095,0,r=>{}]]),h=l([[0,15,15,this.setPalette.bind(this)],[2060,2060,15,(r,a)=>{this.worker&&this.worker.postMessage({command:a})}],[2304,2559,0,(r,a)=>{this.banksel=a&1}],[2560,2567,7,this.setBlitter.bind(this)],[3071,3071,0,(r,a)=>{a==57&&(this.watchdog_counter=j,this.watchdog_enabled=!0)}],[3072,4095,1023,(r,a)=>{this.nvram[r]=a}]]),p=l([[0,36863,65535,r=>this.banksel?this.rom[r]:this.ram[r]],[36864,49151,65535,r=>this.ram[r]],[49152,53247,4095,m],[53248,65535,65535,r=>this.rom?this.rom[r-16384]:0]]),u=l([[0,38911,0,this.write_display_byte.bind(this)],[38912,49151,0,(r,a)=>{this.ram[r]=a}],[49152,53247,4095,h.bind(this)]]),y=t?o:p,C=t?v:u;this.membus={read:y,write:C},this.membus=this.probeMemoryBus(this.membus),this.readAddress=this.membus.read}initAudio(){this.master=new N,this.worker=new Worker("./src/common/audio/z80worker.js");let t=new V(this.worker);this.master.master.addChannel(t)}initCPU(){this.rom=new Uint8Array(this.defaultROMSize),this.cpu=this.newCPU(this.membus)}newCPU(t){var n=Object.create(w0());return n.init(t.write,t.read,0),n}setPalette(t,n){var s=4278190080|(n&7)<<5|(n>>3&7)<<13|n>>6<<22;s!=this.palette[t]&&(this.palette[t]=s,this.screenNeedsRefresh=!0)}write_display_byte(t,n){this.ram[t]=n,this.drawDisplayByte(t,n),this.displayPCs&&(this.displayPCs[t]=this.cpu.getPC())}drawDisplayByte(t,n){var s=(t&65280)<<1|t&255^255;this.pixels[s]=this.palette[n>>4],this.pixels[s+256]=this.palette[n&15]}setBlitter(t,n){if(t)this.blitregs[t]=n;else{var s=this.doBlit(n);this.waitCycles-=s*this.cpuScale}}doBlit(t){t&=255;var n=W0-this.blitregs[7],s=(this.blitregs[2]<<8)+this.blitregs[3],o=(this.blitregs[4]<<8)+this.blitregs[5],v=this.blitregs[6]^4,m=this.blitregs[7]^4;v==0&&v++,m==0&&m++,m==255&&m++;for(var h=t&1?256:1,p=t&1?1:v,u=t&2?256:1,y=t&2?1:v,C=0,r=0;r<m;r++){for(var a=s&65535,S=o&65535,_=0;_<v;_++){var w=this.membus.read(a);t&32?(C=C<<8|w,this.blit_pixel(S,C>>4&255,t)):this.blit_pixel(S,w,t),a+=h,a&=65535,S+=u,S&=65535}t&2?o=o&65280|o+y&255:o+=y,t&1?s=s&65280|s+p&255:s+=p}return v*m*(2+((t&4)>>2))}blit_pixel(t,n,s){var o=t<49152?this.ram[t]:this.membus.read(t),v=this.blitregs[1],m=255;s&8&&!(n&240)?s&128&&(m&=15):s&128||(m&=15),s&8&&!(n&15)?s&64&&(m&=240):s&64||(m&=240),o&=m,s&16?o|=v&~m:o|=n&~m,t<38912&&this.membus.write(t,o)}startScanline(){if(this.audio&&this.audioadapter&&this.audioadapter.generate(this.audio),this.screenNeedsRefresh&&this.scanline==0){for(var t=0;t<38912;t++)this.drawDisplayByte(t,this.ram[t]);this.screenNeedsRefresh=!1}this.scanline==0&&this.watchdog_enabled&&this.watchdog_counter--<=0&&(console.log("WATCHDOG FIRED, PC =",this.cpu.getPC().toString(16)),this.reset())}drawScanline(){let t=this.scanline;(t==0||t==60||t==188||t==252)&&(!this.isDefender||this.pia6821[7]==60)&&(this.cpu.interrupt&&this.cpu.interrupt(),this.cpu.requestInterrupt&&this.cpu.requestInterrupt())}read(t){return this.membus.read(t)}write(t,n){this.membus.write(t,n)}readConst(t){return t>=49152&&t<=52223?255:this.membus.read(t)}reset(){super.reset(),this.watchdog_counter=j,this.watchdog_enabled=!1,this.banksel=1}loadSoundROM(t){console.log("loading sound ROM "+t.length+" bytes");var n=g(t,16384);this.worker.postMessage({rom:n})}loadROM(t){t.length>2&&(this.isDefender?(this.loadSoundROM(t.slice(26624)),t=this.rom.slice(0,26624)):t.length>49152?(this.loadSoundROM(t.slice(49152)),t=this.rom.slice(0,49152)):t.length>36864&&t[36864]&&this.loadSoundROM(t.slice(36864)),t=g(t,49152)),super.loadROM(t)}loadState(t){this.cpu.loadState(t.c),this.ram.set(t.ram),this.nvram.set(t.nvram),this.pia6821.set(t.inputs),this.blitregs.set(t.blt),this.watchdog_counter=t.wdc,this.banksel=t.bs,this.portsel=t.ps}saveState(){return{c:this.cpu.saveState(),ram:this.ram.slice(0),nvram:this.nvram.slice(0),inputs:this.pia6821.slice(0),blt:this.blitregs.slice(0),wdc:this.watchdog_counter,bs:this.banksel,ps:this.portsel}}loadControlsState(t){this.pia6821.set(t.inputs)}saveControlsState(){return{inputs:this.pia6821.slice(0)}}};var R0=[{id:"gfxtest.c",name:"Graphics Test"},{id:"sprites.c",name:"Sprite Test"},{id:"game1.c",name:"Raster Paranoia Game"},{id:"bitmap_rle.c",name:"RLE Bitmap"}],J=function(M,t,n){var s=this;this.__proto__=new(t||P0),n=n||{};for(var o=n==null?void 0:n.isDefender,v=304,m=256,h,p,u,y,C=0,r=0,a,S=!1,_=new k(8).mem,w=new k(8).mem,R,E,L,I,H=!1,B,K,U,T,Q,S0=12e6,e0=S0/3/4,t0=e0/60,r0=1,z=8,H0=4293848814,z0=4278190080,C0=A([[f.A,4,1],[f.RIGHT,4,2],[f.B,4,4],[f.VK_X,4,8],[f.P2_START,4,16],[f.START,4,32],[f.LEFT,4,64],[f.DOWN,4,128],[f.UP,6,1],[f.SELECT,0,4],[f.VK_7,0,1],[f.VK_8,0,2],[f.VK_9,0,8]]),T0=A([[f.P2_UP,0,1],[f.P2_DOWN,0,2],[f.P2_LEFT,0,4],[f.P2_RIGHT,0,8],[f.START,0,16],[f.P2_START,0,32],[f.UP,0,64],[f.DOWN,0,128],[f.LEFT,2,1],[f.RIGHT,2,2],[f.VK_7,4,1],[f.VK_8,4,2],[f.VK_6,4,4],[f.VK_9,4,8],[f.SELECT,4,16]]),A0=o?C0:T0,O=[],G=0;G<16;G++)O[G]=4278190080;this.getPresets=function(){return R0};var g0=l([[1024,1535,511,function(e){return y.mem[e]}],[2048,2048,0,function(e){return K}],[3072,3079,7,function(e){return _[e]}],[0,4095,0,function(e){}]]),E0=l([[0,15,15,s0],[1020,1023,0,function(e,i){i==56&&(a=z),S=!0}],[1024,1535,511,function(e,i){y.mem[e]=i}],[3074,3074,1,function(e,i){T&&T.postMessage({command:i&63})}],[3072,3079,7,function(e,i){_[e]=i}],[0,4095,0,function(e,i){console.log("iowrite",b(e),b(i))}]]),i0=l([[0,49151,65535,function(e){return p.mem[e]}],[49152,53247,4095,function(e){switch(r){case 0:return g0(e);case 1:return u[e+12288];case 2:return u[e+16384];case 3:return u[e+20480];case 7:return u[e+24576];default:return 0}}],[53248,65535,65535,function(e){return u?u[e-53248]:0}]]),O0=l([[0,38911,0,n0],[38912,49151,0,function(e,i){p.mem[e]=i}],[49152,53247,4095,E0],[53248,57343,0,function(e,i){r=i&7}],[0,65535,0,function(e,i){console.log(b(e),b(i))}]]),D0=l([[2052,2055,3,function(e){return _[e]}],[2060,2063,3,function(e){return _[e+4]}],[2816,3071,0,function(e){return K}],[3072,4095,1023,function(e){return y.mem[e]}],[0,4095,0,function(e){}]]),k0=l([[0,15,15,s0],[2060,2060,15,function(e,i){T&&T.postMessage({command:i})}],[2304,2559,0,function(e,i){r=i&1}],[2560,2567,7,K0],[3071,3071,0,function(e,i){i==57&&(a=z,S=!0)}],[3072,4095,1023,function(e,i){y.mem[e]=i}]]),I0=l([[0,36863,65535,function(e){return r?u[e]:p.mem[e]}],[36864,49151,65535,function(e){return p.mem[e]}],[49152,53247,4095,D0],[53248,65535,65535,function(e){return u?u[e-16384]:0}]]),B0=l([[0,38911,0,n0],[38912,49151,0,function(e,i){p.mem[e]=i}],[49152,53247,4095,k0]]),q=o?i0:I0,f0=o?O0:B0;function s0(e,i){var x=4278190080|(i&7)<<5|(i>>3&7)<<13|i>>6<<22;x!=O[e]&&(O[e]=x,H=!0)}function n0(e,i){p.mem[e]=i,a0(e,i),I&&(I[e]=h.getPC())}function a0(e,i){var x=(e&65280)<<1|e&255^255;L[x]=O[i>>4],L[x+256]=O[i&15]}function K0(e,i){if(e)w[e]=i;else{var x=U0(i);this.waitCycles-=x*r0}}function U0(e){e&=255;var i=v-w[7],x=(w[2]<<8)+w[3],c=(w[4]<<8)+w[5],P=w[6]^4,d=w[7]^4;P==0&&P++,d==0&&d++,d==255&&d++;for(var F=e&1?256:1,o0=e&1?1:P,F0=e&2?256:1,c0=e&2?1:P,Y=0,m0=0;m0<d;m0++){for(var X=x&65535,W=c&65535,u0=0;u0<P;u0++){var h0=q(X);e&32?(Y=Y<<8|h0,x0(W,Y>>4&255,e)):x0(W,h0,e),X+=F,X&=65535,W+=F0,W&=65535}e&2?c=c&65280|c+c0&255:c+=c0,e&1?x=x&65280|x+o0&255:x+=o0}return P*d*(2+((e&4)>>2))}function x0(e,i,x){var c=e<49152?p.mem[e]:q(e),P=w[1],d=255;x&8&&!(i&240)?x&128&&(d&=15):x&128||(d&=15),x&8&&!(i&15)?x&64&&(d&=240):x&64||(d&=240),c&=d,x&16?c|=P&~d:c|=i&~d,e<38912&&f0(e,c)}this.start=function(){p=new k(49152),y=new k(1024),u=new Uint8Array(49152),B={read:q,write:f0},this.readAddress=B.read;var e={read:function(c){return 0},write:function(c,P){console.log(b(c),b(P))}};h=s.newCPU(B,e),U=new N,T=new Worker("./src/common/audio/z80worker.js"),Q=new V(T),U.master.addChannel(Q);let i=(n==null?void 0:n.rotate)==null?-90:parseFloat(n.rotate);R=new l0(M,m,v,{rotate:i}),R.create(),$(R.canvas).click(function(c){var P=Math.floor(c.offsetX*R.canvas.width/$(R.canvas).width()),d=Math.floor(c.offsetY*R.canvas.height/$(R.canvas).height()),F=(P>>3)+d*32+1024;I&&console.log(P,d,b(F,4),"PC",b(I[F],4))});var x=R.getFrameData();v0(R,_,A0),L=R.getFrameData(),E=new d0(60,this.nextFrame.bind(this))},this.getRasterScanline=function(){return K},this.advance=function(e){for(var i=Math.round(t0/65),x=0;x<256;x+=4)K=x,(x==0||x==60||x==188||x==252)&&(B.read!=i0||_[7]==60)&&(h.interrupt&&h.interrupt(),h.requestInterrupt&&h.requestInterrupt()),this.runCPU(h,i),x<256&&R.updateFrame(0,0,256-4-x,0,4,304);if(this.runCPU(h,i*2),H&&!e){for(var c=0;c<38912;c++)a0(c,p.mem[c]);H=!1}S&&a--<=0&&(console.log("WATCHDOG FIRED, PC =",h.getPC().toString(16)),this.reset())},this.loadSoundROM=function(e){console.log("loading sound ROM "+e.length+" bytes");var i=g(e,16384);T.postMessage({rom:i})},this.loadROM=function(e,i){i.length>2&&(o?(s.loadSoundROM(i.slice(26624)),u=u.slice(0,26624)):i.length>49152?(s.loadSoundROM(i.slice(49152)),u=u.slice(0,49152)):i.length>36864&&i[36864]&&s.loadSoundROM(i.slice(36864)),u=g(i,49152)),s.reset()},this.loadState=function(e){h.loadState(e.c),p.mem.set(e.b),y.mem.set(e.nvram),_.set(e.pia),w.set(e.blt),a=e.wdc,r=e.bs,C=e.ps},this.saveState=function(){return{c:s.getCPUState(),b:p.mem.slice(0),nvram:y.mem.slice(0),pia:_.slice(0),blt:w.slice(0),wdc:a,bs:r,ps:C}},this.loadControlsState=function(e){_.set(e.pia)},this.saveControlsState=function(){return{pia:_.slice(0)}},this.getCPUState=function(){return h.saveState()},this.isRunning=function(){return E&&E.isRunning()},this.pause=function(){E.stop(),U.stop()},this.resume=function(){E.start(),U.start()},this.reset=function(){h.reset(),a=z,S=!1,r=1},this.scaleCPUFrequency=function(e){r0=e,e0*=e,t0*=e},this.getMemoryMap=function(){return{main:[{name:"Video RAM",start:0,size:49152,type:"ram"},{name:"I/O Registers",start:49152,size:4096,type:"io"}]}},this.showHelp=function(){return"https://8bitworkshop.com/docs/platforms/arcade/#williams-hardware"}},N0=function(M,t){this.__proto__=new J(M,null,t)},V0=function(M,t){this.__proto__=new J(M,_0,t),this.scaleCPUFrequency(4),this.ramStateToLongString=function(n){var s=n.blt,o=(s[2]<<8)+s[3],v=(s[4]<<8)+s[5],m=s[6]^4,h=s[7]^4;return`
BLIT `+b(o,4)+" "+b(v,4)+" w:"+b(m)+" h:"+b(h)+" f:"+b(s[0])+" s:"+b(s[1])}},L0=function(M,t){this.__proto__=new J(M,null,{isDefender:!0}),this.getMemoryMap=function(){return{main:[{name:"NVRAM",start:1024,size:512,type:"ram"},{name:"Video RAM",start:0,size:49152,type:"ram"},{name:"I/O Registers",start:49152,size:4096,type:"io"},{name:"ROM",start:53248,size:12288,type:"rom"}]}}},M0=class extends y0{newMachine(){return new Z(!1)}getPresets(){return R0}getDefaultExtension(){return".c"}readAddress(t){return this.machine.readConst(t)}getMemoryMap(){return{main:[{name:"Video RAM",start:0,size:49152,type:"ram"},{name:"I/O Registers",start:49152,size:3072,type:"io"},{name:"NVRAM",start:52224,size:1024,type:"ram"},{name:"ROM",start:53248,size:12288,type:"rom"}]}}};D.williams=M0;D["williams.old"]=N0;D["williams-defender"]=L0;D["williams-z80"]=V0;
//# sourceMappingURL=williams-6FMADIXT.js.map