1
0
mirror of https://github.com/sehugg/8bitworkshop.git synced 2024-06-01 20:41:36 +00:00
8bitworkshop/gen/atari8-N4PRCBAP.js

11 lines
26 KiB
JavaScript
Raw Normal View History

import{a as xt}from"./chunk-ZE6LZV4I.js";import{B as ft,I as dt,g as nt,k as ht,q as ot,t as ct,y as lt}from"./chunk-ULPRULB6.js";import{J as I,O as T,V as A,W as i,X as it,Z as rt,a as v,aa as C,ea as at,g as f,r as _}from"./chunk-RXF2JDJ3.js";import"./chunk-WAARL7ET.js";var Ut=[0,25,17,9],Yt=[0,25+64,17+80,9+96],E=0,Bt=1,j=2,z=3,Ht=4,Qt=5,jt=7,zt=9,L=10,Xt=11,Gt=12,qt=13,ut=14,Wt=15,K=15;var Zt=17-4,$t=110-4,Jt=105,X=[0,0,8,10,8,16,8,16,8,4,4,2,1,2,1,1],te=[0,0,2,2,2,2,4,4,8,4,4,4,4,2,2,2],ee=[0,0,0,0,0,1,0,1,0,0,2,1,0,0,0,0],mt=[0,0,1,1,2,2,2,2,8,4,4,2,2,2,2,1],V=class{constructor(t,e){this.regs=new Uint8Array(16);this.dma_enabled=!1;this.dliop=0;this.mode=0;this.jmp=!1;this.lms=!1;this.dlarg_lo=0;this.dlarg_hi=0;this.period=0;this.scanaddr=0;this.startaddr=0;this.pfbyte=0;this.ch=0;this.linesleft=0;this.yofs=0;this.isfirstline=!1;this.v=0;this.h=0;this.linebuf=new Uint8Array(48);this.dmaclock=0;this.dmaidx=0;this.output=0;this.dramrefresh=!1;this.in_vscroll=0;this.read=t,this.nmi=e}reset(){this.regs.fill(0),this.regs[ut]=0,this.regs[K]=127,this.regs[Gt]=0,this.regs[qt]=255,this.setReg(E,0),this.h=this.v=0,this.startaddr=this.scanaddr=0,this.dmaclock=0}saveState(){return _(0,{},this)}loadState(t){_(0,this,t),this.setReg(E,t.regs[E])}static stateToLongString(t){let e="";return e+="H: "+v(t.h,3)+" V: "+v(t.v,3)+`
`,e+="DLIOp: "+f(t.dliop,2)+" Lines: "+t.yofs+"/"+t.linesleft,e+=" DMA "+(t.dma_enabled?"ON ":"off"),t.dma_enabled&&(e+=" idx "+t.dmaidx+" clk "+f(t.dmaclock)),e+=`
`,e+="Addr: "+f(t.scanaddr,4)+`
`,e+=A(t.regs,0,16).replace("$00","Regs"),e}setReg(t,e){switch(t){case L:this.regs[L]=255;return;case Wt:this.regs[K]=31;return}this.regs[t]=e}readReg(t){switch(t){case K:return this.regs[t];case Xt:return this.v>>1;default:return 255}}processDLIEntry(){if(this.mode==0)this.linesleft=(this.dliop>>4&7)+1,this.dmaclock=0;else{this.linesleft=X[this.mode],this.period=te[this.mode],this.jmp?(this.regs[j]=this.dlarg_lo,this.regs[z]=this.dlarg_hi,this.mode=this.period=0,this.dliop&64&&(this.linesleft=1,this.dma_enabled=!1),this.dmaclock=0):this.lms&&(this.scanaddr=this.dlarg_lo+(this.dlarg_hi<<8)),this.startaddr=this.scanaddr;let t=this.regs[E]&3,e=this.dliop&16?(this.regs[Ht]&15)>>1:0;this.dliop&16&&t<3&&t++,this.left=Ut[t]+e,this.right=Yt[t]+e;let s=this.regs[Qt]&15;this.dliop&32^this.in_vscroll&&(this.in_vscroll?this.linesleft=s+1:(this.linesleft-=s,this.yofs+=s),this.linesleft&=15,this.in_vscroll^=32)}}nextLine(){this.linesleft>0&&(this.linesleft--,this.yofs++,this.isfirstline=!1,this.mode>=8&&this.linesleft&&(this.scanaddr=this.startaddr))}triggerNMI(t){this.regs[K]=t|31,this.regs[ut]&t&&this.nmi()}getDlistAddr(){return this.regs[j]+(this.regs[z]<<8)}nextInsn(){let t=this.getDlistAddr(),e=this.read(t);return t=t+1&1023|t&~1023,this.regs[j]=t&255,this.regs[z]=t>>8,e}nextScreen(){let t=this.read(this.scanaddr);return this.incScanAddr(),t}incScanAddr(){this.scanaddr=this.scanaddr+1&4095|this.scanaddr&~4095}dlDMAEnabled(){return this.regs[E]&32}isVisibleScanline(){return this.v>=8&&this.v<248}isPlayfieldDMAEnabled(){return this.dma_enabled&&!this.linesleft}isPlayerDMAEnabled(){return this.regs[E]&8}isMissileDMAEnabled(){return this.regs[E]&12}isWSYNC(){return this.regs[L]!=0}clockPulse(){let t=this.isWSYNC();if(!this.isVisibleScanline())this.doVBlank();else{switch(this.h){case 0:this.isMissileDMAEnabled()&&(this.doPlayerMissileDMA(3),t=!0);break;case 1:if(this.isPlayfieldDMAEnabled()){let e=this.nextInsn();this.jmp=(e&~64)==1,this.lms=(e&64)!=0&&(e&15)!=0,this.mode=e&15,this.dliop=e,this.yofs=0,this.isfirstline=!0,t=!0}break;case 2:case 3:case 4:case 5:this.isPlayerDMAEnabled()&&(this.doPlayerMissileDMA(this.h+2),t=!0);break;case 6:case 7:this.isPlayfieldDMAEnabled()&&this.isfirstline&&(this.jmp||this.lms)&&(this.h==6&&(this.dlarg_lo=this.nextInsn()),this.h==7&&(this.dlarg_hi=this.nextInsn()),t=!0);break;case 8:this.isfirstline&&this.processDLIEntry(),this.dliop&128&&this.linesleft==1&&this.triggerNMI(128);break;case 9:break;case 111:this.dma_enabled&&this.nextLine(),++this.v;break}if(this.output=0,this.mode>=2&&this.period){let e=this.h<=Jt;this.dmaclock=this.dmaclock<<1&511,this.dmaclock&1<<this.period&&(this.dmaclock|=1),this.h==this.left&&(this.dmaclock|=1,this.dmaidx=0),this.h==this.right&&(this.dmaclock&=~1,this.dmaidx++),this.dmaclock&1?(this.mode<8&&this.isfirstline&&(e?this.linebuf[this.dmaidx]=this.nextScreen():this.incScanAddr(),t=e),this.dmaidx++):this.dmaclock&8&&(this.ch=this.linebuf[this.dmaidx-4/this.period],e?this.readBitmapData():this.mode>=8&&this.incScanAddr(),t=e),this.output=this.h>=this.left+3&&this.h<=this.right+2?4:0}}return(this.h<Zt||this.h>$t)&&(this.output=2),this.incHorizCounter(),!t&&this.dramrefresh&&(this.read(0),this.dramrefresh=!1,t=!0),t}incHorizCounter(){switch(this.h){case 25:case 25+4*1:case 25+4*2:case 25+4*3:case 25+4*4:case 25+4*5:case 25+4*6:case 25+4*7:case 25+4*8:this.dramrefresh=!0;break;case 102:this.regs[L]=0;break;case 113:this.h=0;return}++this.h}doVBlank(){this.linesleft=this.mode=this.period=0,this.h==111&&this.v++,this.v==248&&this.h==0&&this.triggerNMI(64),this.v==262&&this.h==112&&(this.v=0),this.v==7&&this.h==113&&(this.dma_enabled=this.dlDMAEnabled()!=0),this.output=2,this.dmaclock=0}doPlayerMissileDMA(t){let e=this.regs[E]&16,s=this.regs[jt]<<8;e?(s&=63488,s|=t<<8,s|=this.v&255):(s&=64512,s|=t<<7,s|=this.v>>1),this.read(s)}readBitmapData(){let t=this.mode;if(t<8){let e=this.ch,s=this.yofs>>ee[this.mode],a=s&7,n=this.regs[zt];(t&14)==6?(e&=63,n&=254):(e&=127,n&=252);let h=(e<<3)+(n<<8);if((t&14)==2){let o=this.regs[Bt],l=t==3&&(e&96)==96;o&4?this.pfbyte=this.read(h+(a^7
`,e+=`Write Registers:
`,e+=A(t.regs,0,32),e+=`Read Registers:
`,e+=A(t.readregs,0,32),e}};function At(r){return r=(r|r<<8)&16711935,r=(r|r<<4)&252645135,r=(r|r<<2)&858993459,r=(r|r<<1)&1431655765,r|r<<1}var Et=new Uint32Array(256);for(k=0;k<256;k++)Et[k]=at(k);var k;var c=0;var me=2;var St=4;var Ot=6;var p=8,ge=9,pe=10,be=11,_e=13,q=14,R=15;var ye=8,Ae=9,Ee=10,Se=13,P=14,Y=15;var Rt=128,It=64,Oe=32,Tt=16,Pt=8;var Re=1,Dt=28,Ie=114;var Mt=511,vt=131071,u=0,m=1,b=2,d=3,O=114,Te=15;var Pe=8;var W,B;function De(){W=new Uint8Array(511),B=new Uint8Array(16385);let r=511;for(let t=0;t<511;t++)r=(((r>>5^r)&1)<<8)+(r>>1),W[t]=r;r=131071;for(let t=0;t<16385;t++)r=(((r>>5^r)&255)<<9)+(r>>8),B[t]=r>>1}var H=class{constructor(t,e){this.irq=t;this.antic_xpos=e;this.regs=new Uint8Array(16);this.readregs=new Uint8Array(16);this.divnirq=new Uint32Array(4);this.divnmax=new Uint32Array(4);this.pot_inputs=new Uint8Array(8);this.basemult=0;this.pot_scanline=0;this.random_scanline_counter=0;this.kbcode=0;this.DELAYED_SERIN_IRQ=0;this.DELAYED_SEROUT_IRQ=0;this.DELAYED_XMTDONE_IRQ=0;this.init()}saveState(){return _(0,{},this)}loadState(t){_(0,this,t)}init(){this.readregs.fill(255),this.readregs[Y]=239,this.basemult=Dt,this.pot_inputs.fill(128),De()}read(t){let e=this.readregs[t];switch(t&=15,t){case 0:case 1:case 2:case 3:case 4:case 5:case 6:case 7:return e=this.pot_inputs[t],e<this.pot_scanline?e:this.pot_scanline;case ye:for(let s=0;s<8;s++)this.pot_inputs[s]<=this.pot_scanline&&(e&=~(1<<s));break;case Ae:return this.kbcode;case Y:e=Y+(this.CASSETTE_IOLineStatus()<<4);break;case Ee:if((this.regs[R]&3)!=0){let s=this.random_scanline_counter+this.antic_xpos();if(this.regs[p]&Rt)e=W[s%Mt];else{s%=vt;let a=s>>3;s&=7,e=(B[a]>>s)+(B[a+1]<<8-s)}}break}return e&255}write(t,e){switch(t&=15,this.regs[t]=e,t){case p:e&Re?this.basemult=Ie:this.basemult=Dt,this.update_counter(1<<u|1<<m|1<<b|1<<d);break;case c:this.update_counter(this.regs[p]&Tt?1<<m|1<<u:1<<u);break;case me:this.update_counter(1<<m);break;case St:this.update_counter(this.regs[p]&Pt?1<<d|1<<b:1<<b);break;case Ot:this.update_counter(1<<d);break;case q:this.readregs[P]|=~e&247,~this.readregs[P]&this.regs[q]&&this.generateIRQ(this.readregs[P]);break;case pe:this.readregs[Y]|=224;break;case be:this.regs[R]&4||(this.pot_scanline=0);break;case _e:(this.regs[R]&112)==32&&this.siocheck()&&this.SIO_PutByte(e),(this.regs[R]&8)==0?(this.DELAYED_SEROUT_IRQ=Pe,this.readregs[P]|=8,this.DELAYED_XMTDONE_IRQ=Te):(this.DELAYED_SEROUT_IRQ=312*50*10*(this.regs[St]+this.regs[Ot]*256)/895e3,this.DELAYED_SEROUT_IRQ>=3?(this.readregs[P]|=8,this.DELAYED_XMTDONE_IRQ=2*this.DELAYED_SEROUT_IRQ-2):(this.DELAYED_SEROUT_IRQ=0,this.DELAYED_XMTDONE_IRQ=0));break;case ge:this.divnirq[u]=this.divnmax[u],this.divnirq[m]=this.divnmax[m],this.divnirq[b]=this.divnmax[b],this.divnirq[d]=this.divnmax[d];break;case R:e&4&&(this.pot_scanline=228),(e&3)==0&&(this.DELAYED_SERIN_IRQ=0,this.DELAYED_SEROUT_IRQ=0,this.DELAYED_XMTDONE_IRQ=0);break}this.snd_update(t)}update_counter(t){t&1<<u&&(this.regs[p]&It?this.divnmax[u]=this.regs[c+u]+4:this.divnmax[u]=(this.regs[c+u]+1)*this.basemult,this.divnmax[u]<O&&(this.divnmax[u]=O)),t&1<<m&&(this.regs[p]&Tt?this.regs[p]&It?this.divnmax[m]=this.regs[c+m]*256+this.regs[c+u]+7:this.divnmax[m]=(this.regs[c+m]*256+this.regs[c+u]+1)*this.basemult:this.divnmax[m]=(this.regs[c+m]+1)*this.basemult,this.divnmax[m]<O&&(this.divnmax[m]=O)),t&1<<d&&(this.regs[p]&Pt?this.regs[p]&Oe?this.divnmax[d]=this.regs[c+d]*256+this.regs[c+b]+7:this.divnmax[d]=(this.regs[c+d]*256+this.regs[c+b]+1)*this.basemult:this.divnmax[d]=(this.regs[c+d]+1)*this.basemult,this.divnmax[d]<O&&(this.divnmax[d]=O))}snd_update(t){}advanceScanline(){(this.regs[R]&3)!=0&&(this.pot_scanline<228&&this.pot_scanline++,this.random_scanline_counter+=O,this.random_scanline_counter%=this.regs[p]&Rt?Mt:vt,this.DELAYED_SERIN_IRQ>0&&--this.DELAYED_SERIN_IRQ==0&&(this.readregs[Se]=this.SIO_GetByte(),this.generateIRQ(32)),this.DELAYED_SEROUT_IRQ>0&&--this.DELAYED_SEROUT_IRQ==0&&this.generateIRQ(16),this.DELAYED_XMTDONE_IRQ>0&&--this.DELAYED_XMTDONE_IRQ==0&&this.generateIRQ(8),this.advanceIRQTimer(u,1),this.adv
`,e+=A(t.regs,0,16),e+=`Read Registers:
`,e+=A(t.readregs,0,16),e}CASSETTE_IOLineStatus(){return 0}siocheck(){return((this.regs[c+b]==40||this.regs[c+b]==16||this.regs[c+b]==8||this.regs[c+b]==10)&&this.regs[c+d]==0||(this.regs[R]&120)==40)&&(this.regs[p]&40)==40}SIO_PutByte(t){console.log("SIO put byte",t)}SIO_GetByte(){return 0}};var Me=[i.VK_L,i.VK_J,i.VK_SEMICOLON,i.VK_F4,i.VK_F5,i.VK_K,i.VK_BACK_SLASH,i.VK_TILDE,i.VK_O,null,i.VK_P,i.VK_U,i.VK_ENTER,i.VK_I,i.VK_MINUS2,i.VK_EQUALS2,i.VK_V,i.VK_F7,i.VK_C,i.VK_F6,i.VK_F4,i.VK_B,i.VK_X,i.VK_Z,i.VK_4,null,i.VK_3,i.VK_6,i.VK_ESCAPE,i.VK_5,i.VK_2,i.VK_1,i.VK_COMMA,i.VK_SPACE,i.VK_PERIOD,i.VK_N,null,i.VK_M,i.VK_SLASH,null,i.VK_R,null,i.VK_E,i.VK_Y,i.VK_TAB,i.VK_T,i.VK_W,i.VK_Q,i.VK_9,null,i.VK_0,i.VK_7,i.VK_BACK_SPACE,i.VK_8,null,null,i.VK_F,i.VK_H,i.VK_D,null,i.VK_CAPS_LOCK,i.VK_G,i.VK_S,i.VK_A],ve=rt([[i.UP,0,1],[i.DOWN,0,2],[i.LEFT,0,4],[i.RIGHT,0,8],[{c:16,n:"Shift",plyr:0,button:0},2,1],[i.VK_F1,3,1],[i.VK_F2,3,2],[i.VK_F3,3,4]]),Q=class extends ot{constructor(){super();this.cpuFrequency=1789773;this.numTotalScanlines=262;this.cpuCyclesPerLine=114;this.canvasWidth=336;this.numVisibleScanlines=224;this.aspectRatio=this.canvasWidth/this.numVisibleScanlines*.857;this.firstVisibleScanline=16;this.firstVisibleClock=(44-6)*2;this.defaultROMSize=32768;this.overscan=!0;this.audioOversample=2;this.sampleRate=this.numTotalScanlines*60*this.audioOversample;this.run_address=-1;this.inputs=new Uint8Array(4);this.linergb=new Uint32Array(this.canvasWidth);this.lastdmabyte=0;this.keycode=0;this.cart_80=!1;this.cart_a0=!1;this.xexdata=null;this.keyboard_active=!0;this.d500=new Uint8Array(256);this.cpu=new ct,this.ram=new Uint8Array(65536),this.bios=new Uint8Array(10240),this.bus=this.newBus(),this.connectCPUMemoryBus(this.bus),this.antic=new V(this.readDMA.bind(this),this.antic_nmi.bind(this)),this.gtia=new U,this.irq_pokey=new H(this.pokey_irq.bind(this),()=>this.antic.h),this.audio_pokey=nt(1),this.audioadapter=new ht(this.audio_pokey.pokey1,this.audioOversample,this.sampleRate),this.handler=it(this.inputs,ve,this.getKeyboardFunction(),!0)}newBus(){return{read:C([[0,32767,65535,t=>this.ram[t]],[32768,40959,65535,t=>this.cart_80?this.rom[t-32768]:this.ram[t]],[40960,49151,65535,t=>this.cart_a0?this.rom[t-32768]:this.ram[t]],[53248,53503,31,t=>this.gtia.readReg(t)],[53760,54015,15,t=>this.readPokey(t)],[54016,54271,15,t=>this.readPIA(t)],[54272,54527,15,t=>this.antic.readReg(t)],[54528,54783,255,t=>this.d500[t]],[55296,65535,65535,t=>this.bios[t-55296]]]),write:C([[0,49146,65535,(t,e)=>{this.ram[t]=e}],[49147,49151,65535,(t,e)=>{this.ram[t]=e,this.initCartA()}],[53248,53503,31,(t,e)=>{this.gtia.setReg(t,e)}],[53760,54015,15,(t,e)=>{this.writePokey(t,e)}],[54272,54527,15,(t,e)=>{this.antic.setReg(t,e)}],[54528,54783,255,(t,e)=>{this.writeMapper(t,e)}]])}}loadBIOS(t){this.bios.set(t)}reset(){super.reset(),this.antic.reset(),this.gtia.reset(),this.keycode=0}read(t){return this.bus.read(t)}readDMA(t){let e=this.bus.read(t);return this.probe.logDMARead(t,e),this.lastdmabyte=e,e}readConst(t){return t<53248||t>=54528?this.bus.read(t):255}write(t,e){this.bus.write(t,e)}readPokey(t){switch(t&15){case 9:return this.keycode&255;case 15:return~this.keycode>>6&4|~this.keycode>>3&8|18;default:return this.irq_pokey.read(t)}}readPIA(t){if(t==0||t==1)return~this.inputs[t]}writePokey(t,e){this.audio_pokey.pokey1.setRegister(t,e),this.irq_pokey.write(t,e)}startScanline(){this.gtia.sync();for(let t=0;t<4;t++)this.gtia.readregs[_t+t]=~this.inputs[2]>>t&1;this.gtia.readregs[G]=~this.inputs[3]&7,this.audio&&this.audioadapter.generate(this.audio),this.irq_pokey.advanceScanline()}drawScanline(){let t=this.antic.v-this.firstVisibleScanline;t>=0&&t<this.numVisibleScanlines&&this.pixels.set(this.linergb,t*this.canvasWidth)}advanceCPU(){this.antic.clockPulse()?(this.antic.h<8&&this.gtia.updateGfx(this.antic.h-1,this.antic.v,this.lastdmabyte),this.antic.isWSYNC()&&this.probe.logWait(0),this.probe.logClocks(1)):super.advanceCPU();let t=this.antic.h*4-this.firstVisibleClock,e=()=>{this.gtia.clockPulse1(),this.linergb[t++]=this.gtia.rgb},s=()=>{this.gtia.cl
//# sourceMappingURL=atari8-N4PRCBAP.js.map