1
0
mirror of https://github.com/sehugg/8bitworkshop.git synced 2024-10-18 00:24:04 +00:00
8bitworkshop/gen/chunk-4UOPFAU7.js

12 lines
15 KiB
JavaScript
Raw Normal View History

import{c as ae,k as he,l as ne,o as be}from"./chunk-2T5IQXGX.js";import{V as ie,a as I,g as w,t as u}from"./chunk-VOKPYVET.js";var l;(function(i){i[i.GRAPHICS=0]="GRAPHICS",i[i.TEXT=1]="TEXT",i[i.BITMAP=2]="BITMAP",i[i.MULTICOLOR=3]="MULTICOLOR",i[i.MODE4=4]="MODE4",i[i.BITMAP_TEXT=5]="BITMAP_TEXT",i[i.BITMAP_MULTICOLOR=6]="BITMAP_MULTICOLOR",i[i.ILLEGAL=7]="ILLEGAL"})(l||(l={}));var O=class{constructor(e,t,r){this.probe=new ne;this.ram=new Uint8Array(16384);this.registers=new Uint8Array(8);this.spriteBuffer=new Uint8Array(256);this.displayOn=!1;this.interruptsOn=!1;this.fb32=e,this.cru=t,this.enableFlicker=r,this.palette=[u(0,0,0),u(0,0,0),u(33,200,66),u(94,220,120),u(84,85,237),u(125,118,252),u(212,82,77),u(66,235,245),u(252,85,84),u(255,121,120),u(212,193,84),u(230,206,128),u(33,176,59),u(201,91,186),u(204,204,204),u(255,255,255)]}reset(){var e;this.ram.fill(0),this.registers.fill(0),this.addressRegister=0,this.statusRegister=0,this.prefetchByte=0,this.latch=!1,this.displayOn=!1,this.interruptsOn=!1,this.screenMode=0,this.bitmapMode=!1,this.textMode=!1,this.colorTable=0,this.nameTable=0,this.charPatternTable=0,this.spriteAttributeTable=0,this.spritePatternTable=0,this.colorTableMask=16383,this.patternTableMask=16383,this.ramMask=16383,this.fgColor=0,this.bgColor=0,this.flicker=this.enableFlicker,this.redrawRequired=!0,this.width=304,this.height=240}drawScanline(e){var t=this.fb32,r=this.width,a=e*r,h=this.screenMode,s=this.textMode,b=this.bitmapMode,i=s?240:256,n=192,d=r-i>>1,m=this.height-n>>1,M=this.fgColor,g=this.bgColor,o=this.ram,x=this.nameTable,V=this.colorTable,C=this.charPatternTable,D=this.colorTableMask,H=this.patternTableMask,oe=this.spriteAttributeTable,ue=this.spritePatternTable,$=(this.registers[1]&2)!=0,q=this.registers[1]&1,y=($?16:8)<<(q?1:0),j=this.flicker?4:32,J=this.palette,N=!1,Q=!1,Y=31,k,v,W,f,F,B,p;if(e>=m&&e<m+n&&this.displayOn){var c=e-m;if(!s){var z=this.spriteBuffer;z.fill(0);var E=0,ee=!1,S=oe,L;for(L=0;L<32&&E<=j&&!ee;L++){var R=o[S];if(R!==208){R>208&&(R-=256),R++;var X=R+y,U=-1;if(L<8||!b)c>=R&&c<X&&(U=c);else{var K=c&((this.registers[4]&3)<<6|63);K>=R&&K<X?U=K:c>=64&&c<128&&c>=R&&c<X&&(U=c)}if(U!==-1){if(E<j){var te=o[S+1],ce=o[S+2]&($?252:255),de=o[S+3]&15;(o[S+3]&128)!=0&&(te-=32);for(var me=U-R>>q,ge=ue+(ce<<3)+me,_=0;_<y;_++){var G=te+_;if(G>=0&&G<i){var re=_>>q,pe=o[ge+(re>=8?16:0)];(pe&128>>(re&7))!=0&&(z[G]===0?z[G]=de+1:N=!0)}}}E++}S+=4}else ee=!0}E>4&&(Q=!0,Y=L)}var A=s?(c>>3)*40:c>>3<<5,P=c&7;for(k=0;k<r;k++){if(k>=d&&k<d+i){var T=k-d;switch(h){case 0:f=o[x+A+(T>>3)],B=o[V+(f>>3)],p=o[C+(f<<3)+P],v=(p&128>>(T&7))!=0?(B&240)>>4:B&15;break;case 2:f=o[x+A+(T>>3)],F=((c&192)<<5)+(f<<3),B=o[V+(F&D)+P],p=o[C+(F&H)+P],v=(p&128>>(T&7))!=0?(B&240)>>4:B&15;break;case 3:f=o[x+A+(T>>3)],P=(c&28)>>2,p=o[C+(f<<3)+P],v=(T&4)==0?(p&240)>>4:p&15;break;case 1:f=o[x+A+Math.floor(T/6)],p=o[C+(f<<3)+P],v=(p&128>>T%6)!=0?M:g;break;case 5:f=o[x+A+Math.floor(T/6)],F=((c&192)<<5)+(f<<3),p=o[C+(F&H)+P],v=(p&128>>T%6)!=0?M:g;break;case 6:f=o[x+A+(T>>3)],P=(c&28)>>2,F=((c&192)<<5)+(f<<3),p=o[C+(F&H)+P],v=(T&4)==0?(p&240)>>4:p&15;break;case 7:v=(T&4)==0?M:g;break}if(v===0&&(v=g),!s){var se=z[T]-1;se>0&&(v=se)}}else v=g;W=J[v],t[a++]=W}}else for(W=J[g],k=0;k<r;k++)t[a++]=W;e===m+n&&(this.statusRegister|=128,this.interruptsOn&&this.cru.setVDPInterrupt(!0)),N&&(this.statusRegister|=32),(this.statusRegister&64)==0&&(this.statusRegister|=Y),Q&&(this.statusRegister|=64)}setReadAddress(e){this.addressRegister=(e&63)<<8|this.addressRegister&255,this.prefetchByte=this.ram[this.addressRegister++],this.addressRegister&=16383}setWriteAddress(e){this.addressRegister=(e&63)<<8|this.addressRegister&255}setVDPWriteRegister(e){var t=this.registers.length-1;switch(this.registers[e&t]=this.addressRegister&255,e&t){case 0:this.updateMode(this.registers[0],this.registers[1]);break;case 1:this.ramMask=(this.registers[1]&128)!=0?16383:8191,this.displayOn=(this.registers[1]&64)!=0,this.interruptsOn=(this.registers[1]&32)!=0,this.updateMode(this.registers[0],this.registers[1]);break;case 2:this.nameTable=(this.registers[2]&15)
`;var a=this.getDebugTables();for(var h of a)h[2]>0&&(t+=I(h[0],e)+": $"+w(h[1],4)+" - $"+w(h[1]+h[2]-1,4)+`
`);return t+=I("Address Register",e)+": $"+w(this.addressRegister,4)+`
`,t+=I("Status Register",e)+": $"+w(this.statusRegister,2)+`
`,t+=I("Screen Mode",e)+": "+this.screenMode+`
`,t+=I("Display On",e)+": "+this.displayOn+`
`,this.ramMask!=16383&&(t+=I("RAM Mask",e)+": $"+w(this.ramMask)+`
`),t}hexView(e,t,r){for(var a="",h=null,s=e,b=0,i=0;i<t&&s<16384;s++,i++){(i&15)==0&&(a+=`
`+w(s,4)+":",b++),a+=" ",r&&r===s&&(h=b);var n=this.ram[s].toString(16).toUpperCase();n.length===1&&(a+="0"),a+=n}return{text:a.substr(1),lineCount:b,anchorLine:h-1}}getWord(e){return e<16384?this.ram[e]<<8|this.ram[e+1]:0}getCharAt(e,t){return e-=24,t-=24,this.textMode?this.ram[this.nameTable+Math.floor((e-8)/6)+Math.floor(t/8)*40]:this.ram[this.nameTable+Math.floor(e/8)+Math.floor(t/8)*32]}setFlicker(e){this.flicker=e,this.enableFlicker=e}getState(){return{ram:this.ram.slice(0),registers:this.registers.slice(0),addressRegister:this.addressRegister,statusRegister:this.statusRegister,latch:this.latch,prefetchByte:this.prefetchByte,displayOn:this.displayOn,interruptsOn:this.interruptsOn,screenMode:this.screenMode,bitmapMode:this.bitmapMode,textMode:this.textMode,colorTable:this.colorTable,nameTable:this.nameTable,charPatternTable:this.charPatternTable,spriteAttributeTable:this.spriteAttributeTable,spritePatternTable:this.spritePatternTable,colorTableMask:this.colorTableMask,patternTableMask:this.patternTableMask,ramMask:this.ramMask,fgColor:this.fgColor,bgColor:this.bgColor,flicker:this.flicker}}restoreState(e){this.ram.set(e.ram),this.registers.set(e.registers),this.addressRegister=e.addressRegister,this.statusRegister=e.statusRegister,this.latch=e.latch,this.prefetchByte=e.prefetchByte,this.displayOn=e.displayOn,this.interruptsOn=e.interruptsOn,this.screenMode=e.screenMode,this.bitmapMode=e.bitmapMode,this.textMode=e.textMode,this.colorTable=e.colorTable,this.nameTable=e.nameTable,this.charPatternTable=e.charPatternTable,this.spriteAttributeTable=e.spriteAttributeTable,this.spritePatternTable=e.spritePatternTable,this.colorTableMask=e.colorTableMask,this.patternTableMask=e.patternTableMask,this.ramMask=e.ramMask,this.fgColor=e.fgColor,this.bgColor=e.bgColor,this.flicker=e.flicker,this.redrawRequired=!0}},Te=class extends O{constructor(){super(...arguments);this.cram=new Uint8Array(32);this.cpalette=new Uint32Array(32);this.registers=new Uint8Array(16);this.vramUntwiddled=new Uint8Array(32768);this.numVisibleLines=192;this.lineCounter=0;this.lineInterruptPending=!1}reset(){super.reset(),this.writeToCRAM=!1,this.cram.fill(0),this.cpalette.fill(0),this.vramUntwiddled.fill(0)}readStatus(){return this.lineInterruptPending=!1,super.readStatus()}updateMode(e,t){e&4?(this.screenMode=4,this.nameTable=(this.registers[2]&15)<<10&14336,this.spriteAttributeTable=(this.registers[5]&126)<<7):super.updateMode(e,t)}setReadAddress(e){super.setReadAddress(e),this.writeToCRAM=!1}setWriteAddress(e){super.setWriteAddress(e),this.writeToCRAM=!1}setVDPWriteRegister(e){super.setVDPWriteRegister(e),this.ramMask=16383}setVDPWriteCommand3(e){this.writeToCRAM=!0}writeData(e){if(this.writeToCRAM){var t=this.addressRegister++&this.cram.length-1;this.cram[t]=e,this.cpalette[t]=u((e&3)*85,(e>>2&3)*85,(e>>4&3)*85),this.prefetchByte=e,this.addressRegister&=this.ramMask,this.redrawRequired=!0}else{var r=this.addressRegister;super.writeData(e),this.writeTwiddled(r,e)}this.latch=!1}writeTwiddled(e,t){for(var r=e&16380,a=r*2,h=this.ram[r],s=this.ram[r+1],b=this.ram[r+2],i=this.ram[r+3],n=0;n<8;++n){var d=7-n,m=h>>>d&1|(s>>>d&1)<<1|(b>>>d&1)<<2|(i>>>d&1)<<3;this.vramUntwiddled[a+n]=m}}getState(){var e=super.getState();return e.cram=this.cram.slice(0),e}restoreState(e){super.restoreState(e),this.cram.set(e.cram)}drawScanline(e){this.screenMode==4?this.rasterize_line(e):super.drawScanline(e)}findSprites(e){var t=this.spriteAttributeTable,r=[],a=8,h;for(this.registers[1]&2&&(a=16),h=0;h<64;h++){var s=this.ram[t+h];if(s===208)break;if(s>=240&&(s-=256),e>=s&&e<s+a){if(r.length===8){this.statusRegister|=64;break}r.push([this.ram[t+128+h*2],this.ram[t+128+h*2+1],s])}}return r}rasterize_background(e,t,r,a,h){e=e|0,t=t|0,r=r|0,a=(a|0)*2;var s,b;r&1<<9?(b=-1,a+=7):b=1;let i=r&1<<11?16:0;var n;if(h&&i===0)for(s=0;s<8;s++)n=this.vramUntwiddled[a],a+=b,n!==0&&(this.fb32[e+t]=this.cpalette[n]),t=t+1&255;else for(s=0;s<8;s++)n=this.vramUntwiddled[a]+i,a+=b,this.fb32[e+t]=this.cpalette[n],t=t+1&255}clear_background(e,t){e=e|0,t=t|0;var r;let a=this.cpalette[0];for(r=0;r<8;+
//# sourceMappingURL=chunk-4UOPFAU7.js.map