import{J,c as Y,d as q,e as I,k as X,q as j}from"./chunk-ULPRULB6.js";import{$ as N,J as C,K as V,T as z,W as a,X as Z,Z as P,aa as _}from"./chunk-RXF2JDJ3.js";import"./chunk-WAARL7ET.js";var o0=P([[a.A,0,16],[a.LEFT,0,4],[a.RIGHT,0,8],[a.P2_A,1,16],[a.P2_LEFT,1,4],[a.P2_RIGHT,1,8],[a.SELECT,0,1],[a.START,1,1],[a.VK_2,1,2]]),h0=P([[a.UP,0,-1],[a.B,0,-2],[a.VK_7,0,-4],[a.A,0,-8],[a.RIGHT,0,-16],[a.LEFT,0,-32],[a.VK_6,0,-64],[a.SELECT,0,-128],[a.START,1,-128],[a.VK_2,1,-64],[a.DOWN,2,-64]]),c0=[33,71,151,8448,18176,38656,5308416,11403264],u0=function(f,t,e,i,h){var G=h.gfxBase||10240;this.missileWidth=h.missileWidth||4,this.missileOffset=h.missileOffset||0,this.showOffscreenObjects=!1,this.frameCounter=0,this.starsEnabled=0;for(var L=[],M=0;M<256;M++)L[M]=V();this.advanceFrame=function(){this.frameCounter=this.frameCounter+1&255},this.drawScanline=function(u,x){var p=x*264;if(!this.showOffscreenObjects&&(x<16||x>=240)){for(var r=0;r<264;r++)u[p+r]=4278190080;return}for(var s=p,S=0;S<32;S++)for(var R=S,a0=e[R*2],s0=e[R*2+1],U=x+a0&255,i0=U>>3<<5,o=U&7,n0=t[i0+R],g=(s0&7)<<2,m=G+(n0<<3)+o,d=f[m],v=f[m+2048],r=0;r<8;r++){var c=128>>r,l=g+(d&c?1:0)+(v&c?2:0);u[s]=i[l],s++}for(var b=7;b>=0;b--){var A=(b<<2)+64,f0=e[A],T=240-(f0-(b<3?1:0)),o=x-T;if(o>=0&&o<16){var w=e[A+3]+1;if(w==0&&!this.showOffscreenObjects)continue;var y=e[A+1],k=y&64;y&128&&(o=15-o),y&=63;var g=(e[A+2]&7)<<2,m=G+(y<<5)+(o<8?o:o+8);s=p+w;for(var d=f[m],v=f[m+2048],r=0;r<8;r++){var c=128>>r,l=(d&c?1:0)+(v&c?2:0);l&&(u[k?s+15-r:s+r]=i[g+l])}for(var d=f[m+8],v=f[m+2056],r=0;r<8;r++){var c=128>>r,l=(d&c?1:0)+(v&c?2:0);l&&(u[k?s+7-r:s+r+8]=i[g+l])}}}for(var D=255,K=255,n=0;n<8;n++){var T=e[96+(n<<2)+1];(T+x-(n<3?1:0)&255)==255&&(n!=7?D=n:K=n)}for(var r=0;r<2;r++)if(n=r?K:D,n!=255)for(var w=255-e[96+(n<<2)+3],s=p+w-this.missileOffset,x0=n==7?4294967040:4294967295,W=0;Wthis.rom?this.rom[t]:null],[16384,18431,1023,t=>this.ram[t]],[20480,22527,1023,t=>this.vram[t]],[22528,24575,255,t=>this.oram[t]],[24576,24576,0,t=>this.inputs[0]],[26624,26624,0,t=>this.inputs[1]],[28672,28672,0,t=>this.inputs[2]],[30720,30720,0,t=>{this.watchdog_counter=E}]]);this.write=_([[16384,18431,1023,(t,e)=>{this.ram[t]=e}],[20480,22527,1023,(t,e)=>{this.vram[t]=e}],[22528,24575,255,(t,e)=>{this.oram[t]=e}],[28673,28673,0,(t,e)=>{this.interruptEnabled=e&1}],[28676,28676,0,(t,e)=>{this.gfx.starsEnabled=e&1}]]);var t=new q;this.psg1=new I(t),this.psg2=new I(t),this.audioadapter=new X([this.psg1.psg,this.psg2.psg],e0,this.sampleRate),this.init()}init(){this.rom=new Uint8Array(this.defaultROMSize),this.palette=new Uint32Array(new ArrayBuffer(32*4)),this.gfx=new u0(this.rom,this.vram,this.oram,this.palette,this.options),this.connectCPUMemoryBus(this),this.connectCPUIOBus(this.newIOBus()),this.inputs.set(this.defaultInputs),this.handler=Z(this.inputs,this.keyMap)}readConst(t){return t<28672?this.read(t):null}newIOBus(){return{read:t=>0,write:(t,e)=>{t&1&&this.psg1.selectRegister(e&15),t&2&&this.psg1.setData(e),t&4&&this.psg2.selectRegister(e&15),t&8&&this.psg2.setData(e)}}}reset(){super.reset(),this.psg1.reset(),this.psg2.reset(),this.watchdog_counter=E}startScanline(){this.audio&&this.audioadapter&&this.audioadapter.generate(this.audio)}drawScanline(){this.gfx.drawScanline(this.pixels,this.scanline)}advanceFrame(t){var e=super.advanceFrame(t);if(this.gfx.advanceFrame(),!this.gfx.showOffscreenObjects)for(var i=0;i<264;i++)this.pixels.fill(4278190080,256+i*264,264+i*264);if(this.watchdog_counter--<=0)throw new z("WATCHDOG FIRED");return this.interruptEnabled&&this.cpu.NMI(),e}loadROM(t){this.rom.set(N(t,this.defaultROMSize));for(var e=0;e<32;e++){var i=this.rom[this.palBase+e];this.palette[e]=4278190080;for(var h=0;h<8;h++)1<this.rom[t]],[16384,18431,2047,t=>this.ram[t]],[18432,20479,1023,t=>this.vram[t]],[20480,24575,255,t=>this.oram[t]],[28672,28672,0,t=>{this.watchdog_counter=E}],[30720,30720,0,t=>{this.watchdog_counter=E}],[33024,33024,0,t=>this.inputs[0]],[33025,33025,0,t=>this.inputs[1]],[33026,33026,0,t=>this.inputs[2]|this.scramble_protection_alt_r()],[33282,33282,0,t=>this.m_protection_result],[37120,37120,0,t=>this.inputs[0]],[37121,37121,0,t=>this.inputs[1]],[37122,37122,0,t=>this.inputs[2]|this.scramble_protection_alt_r()],[37394,37394,0,t=>this.m_protection_result]]);this.write=_([[16384,18431,2047,(t,e)=>{this.ram[t]=e}],[18432,20479,1023,(t,e)=>{this.vram[t]=e}],[20480,24575,255,(t,e)=>{this.oram[t]=e}],[26625,26625,0,(t,e)=>{this.interruptEnabled=e&1}],[26626,26626,0,(t,e)=>{}],[26627,26627,0,(t,e)=>{}],[26628,26628,0,(t,e)=>{this.gfx.starsEnabled=e&1}],[26632,26632,0,(t,e)=>{this.gfx.missileWidth=e}],[26633,26633,0,(t,e)=>{this.gfx.missileOffset=e}],[33282,33282,0,this.scramble_protection_w.bind(this)]]);this.m_protection_state=0;this.m_protection_result=0;this.init()}scramble_protection_w(t,e){switch(this.m_protection_state=this.m_protection_state<<4|e&15,this.m_protection_state&4095){case 3849:this.m_protection_result=255;break;case 2633:this.m_protection_result=191;break;case 793:this.m_protection_result=79;break;case 1481:this.m_protection_result=111;break;case 582:this.m_protection_result^=128;break;case 2911:this.m_protection_result=111;break}}scramble_protection_alt_r(){var t=this.m_protection_result>>7&1;return t<<5|(t^1)<<7}};var v0=[{id:"gfxtest.c",name:"Graphics Test"},{id:"shoot2.c",name:"Solarian Game"}],F=class extends J{constructor(){super(...arguments);this.getMemoryMap=function(){return{main:[{name:"Video RAM",start:20480,size:1024,type:"ram"},{name:"Sprite RAM",start:22528,size:256,type:"ram"},{name:"I/O Registers",start:24576,size:8192,type:"io"}]}}}newMachine(){return new O}getPresets(){return v0}getDefaultExtension(){return".c"}readAddress(t){return this.machine.readConst(t)}readVRAMAddress(t){return t<2048?this.machine.vram[t]:this.machine.oram[t-2048]}showHelp(){return"https://8bitworkshop.com/docs/platforms/arcade/index.html#galaxian-scramble"}},r0=class extends F{newMachine(){return new B}};C.galaxian=F;C["galaxian-scramble"]=r0; //# sourceMappingURL=galaxian-KKUCSTLZ.js.map