8bitworkshop/gen/pce-QQSEYHLV.js

3 lines
49 KiB
JavaScript

import{y as m}from"./chunk-ULPRULB6.js";import{J as R,P as T,W as u}from"./chunk-RXF2JDJ3.js";import"./chunk-WAARL7ET.js";var M=[{id:"test_conio.c",name:"Hello World (conio)"},{id:"siegegame.c",name:"Siege Game (conio)"},{id:"hello.wiz",name:"Hello World (Wiz)"}],G=class{constructor(t){this.mainElement=t}start(){this.pce=new y,this.video=new T(this.mainElement,684,262,{overscan:!0,aspect:4/3}),this.video.create(),this.pce.SetCanvas(this.video.canvas)}reset(){this.pce.Reset()}isRunning(){return this.pce.TimerID!=null}pause(){this.pce.Pause()}resume(){this.pce.CreateAudioContext(),this.pce.Start()}getPresets(){return M}loadROM(t,e){this.pce.Pause(),this.pce.Init(),this.pce.SetROM(e)}getPlatformName(){return"PC Engine"}getToolForFilename(t){return m(t)}getDefaultExtension(){return".pce"}readAddress(t){return this.pce.Get(t)}writeAddress(t,e){this.pce.Set(t,e)}readVRAMAddress(t){return this.pce.VDC[0].VRAM[t]}};R.pce=G;var y=class{constructor(){this.MainCanvas=null;this.Ctx=null;this.ImageData=null;this.MapperBase=class{constructor(t,e){this.ROM=t,this.Core=e}Init(){}Read(t){return 255}Write(t,e){}};this.VDCSelect=0;this.ScreenWidthMAX=0;this.ScreenHeightMAX=0;this.SuperGrafx=!1,this.CountryTypePCE=64,this.CountryTypeTG16=0,this.CountryType=this.CountryTypePCE,this.GamePadButton6=!1,this.MultiTap=!1,this.EtcConstruct(),this.CPUConstruct(),this.StorageConstruct(),this.VCEConstruct(),this.VPCConstruct(),this.VDCConstruct(),this.SoundConstruct(),this.PSGConstruct(),this.TimerConstruct(),this.JoystickConstruct()}EtcConstruct(){this.TimerID=null,this.MainCanvas=null,this.Ctx=null,this.ImageData=null}UpdateAnimationFrame(){this.TimerID=window.requestAnimationFrame(this.UpdateAnimationFrame.bind(this)),this.Run()}CancelAnimationFrame(){window.cancelAnimationFrame(this.TimerID),this.TimerID=null}Pause(){this.TimerID!=null&&(this.JoystickEventRelease(),this.CancelAnimationFrame())}Start(){this.TimerID==null&&(this.JoystickEventInit(),this.UpdateAnimationFrame())}Run(){for(this.CheckGamePad(),this.DrawFlag=!1;!this.DrawFlag;)this.CPURun(),this.VDCRun(),this.TimerRun(),this.PSGRun()}Reset(){this.StorageReset(),this.Mapper.Init(),this.CPUInit(),this.VCEInit(),this.VPCInit(),this.VDCInit(),this.TimerInit(),this.JoystickInit(),this.PSGInit(),this.CPUReset()}Init(){this.StorageInit(),this.CPUInit(),this.VCEInit(),this.VPCInit(),this.VDCInit(),this.TimerInit(),this.JoystickInit(),this.PSGInit()}SetCanvas(t){if(this.MainCanvas=t,!this.MainCanvas.getContext)return!1;this.Ctx=this.MainCanvas.getContext("2d"),this.ImageData=this.Ctx.createImageData(this.MainCanvas.width,this.MainCanvas.height);for(let e=0;e<this.MainCanvas.width*this.MainCanvas.height*4;e+=4)this.ImageData.data[e]=0,this.ImageData.data[e+1]=0,this.ImageData.data[e+2]=0,this.ImageData.data[e+3]=255;return this.Ctx.putImageData(this.ImageData,0,0),!0}CPUConstruct(){this.OpCycles=[8,7,3,4,6,4,6,7,3,2,2,2,7,5,7,6,2,7,7,4,6,4,6,7,2,5,2,2,7,5,7,6,7,7,3,4,4,4,6,7,3,2,2,2,5,5,7,6,2,7,7,2,4,4,6,7,2,5,2,2,5,5,7,6,7,7,3,4,8,4,6,7,3,2,2,2,4,5,7,6,2,7,7,5,2,4,6,7,2,5,3,2,2,5,7,6,7,7,2,2,4,4,6,7,3,2,2,2,7,5,7,6,2,7,7,0,4,4,6,7,2,5,3,2,7,5,7,6,4,7,2,7,4,4,4,7,2,2,2,2,5,5,5,6,2,7,7,8,4,4,4,7,2,5,2,2,5,5,5,6,2,7,2,7,4,4,4,7,2,2,2,2,5,5,5,6,2,7,7,8,4,4,4,7,2,5,2,2,5,5,5,6,2,7,2,0,4,4,6,7,2,2,2,2,5,5,7,6,2,7,7,0,2,4,6,7,2,5,3,2,2,5,7,6,2,7,2,0,4,4,6,7,2,2,2,2,5,5,7,6,2,7,7,0,2,4,6,7,2,5,3,2,2,5,7,6],this.OpBytes=[0,2,1,2,2,2,2,2,1,2,1,1,3,3,3,0,0,2,2,2,2,2,2,2,1,3,1,1,3,3,3,0,0,2,1,2,2,2,2,2,1,2,1,1,3,3,3,0,0,2,2,1,2,2,2,2,1,3,1,1,3,3,3,0,0,2,1,2,0,2,2,2,1,2,1,1,0,3,3,0,0,2,2,2,1,2,2,2,1,3,1,1,1,3,3,0,0,2,1,1,2,2,2,2,1,2,1,1,0,3,3,0,0,2,2,0,2,2,2,2,1,3,1,1,0,3,3,0,0,2,1,3,2,2,2,2,1,2,1,1,3,3,3,0,0,2,2,4,2,2,2,2,1,3,1,1,3,3,3,0,2,2,2,3,2,2,2,2,1,2,1,1,3,3,3,0,0,2,2,4,2,2,2,2,1,3,1,1,3,3,3,0,2,2,1,0,2,2,2,2,1,2,1,1,3,3,3,0,0,2,2,0,1,2,2,2,1,3,1,1,1,3,3,0,2,2,1,0,2,2,2,2,1,2,1,1,3,3,3,0,0,2,2,0,1,2,2,2,1,3,1,1,1,3,3,0],this.A=0,this.X=0,this.Y=0,this.PC=0,this.S=0,this.P=0,this.NZCacheTable=new Uint8Array(256),this.NZCacheTable=this.NZCacheTable.map((t,e)=>e&128),this.NZCacheTable[0]=2,this.NFlag=128,this.VFlag=64,this.TFlag=32,this.BFlag=16,this.DFlag=8,this.IFlag=4,this.ZFlag=2,this.CFlag=1,this.TIQFlag=4,this.IRQ1Flag=2,this.IRQ2Flag=1,this.ProgressClock=0,this.CPUBaseClock=0,this.BaseClock1=12,this.BaseClock3=6,this.BaseClock5=4,this.BaseClock7=3,this.BaseClock10=2,this.TransferSrc=0,this.TransferDist=0,this.TransferLen=0,this.TransferAlt=0}CPUReset(){this.TransferSrc=0,this.TransferDist=0,this.TransferLen=0,this.TransferAlt=0,this.CPUBaseClock=this.BaseClock1,this.SetIFlag(),this.PC=this.Get16(65534)}CPUInit(){this.A=0,this.X=0,this.Y=0,this.PC=0,this.S=0,this.P=0,this.ProgressClock=0,this.CPUBaseClock=this.BaseClock1,this.TransferSrc=0,this.TransferDist=0,this.TransferLen=0,this.TransferAlt=0,this.LastInt=0}CPURun(){this.ProgressClock=0;let t=this.LastInt;this.LastInt=(this.P&this.IFlag)==0?this.GetIntStatus():0,t!=0&&this.TransferLen==0?(this.LastInt=0,(t&this.TIQFlag)==this.TIQFlag?(this.Push(this.PCH()),this.Push(this.PCL()),this.Push(this.P),this.P=4,this.PC=this.Get16(65530)):(t&this.IRQ1Flag)==this.IRQ1Flag?(this.Push(this.PCH()),this.Push(this.PCL()),this.Push(this.P),this.P=4,this.PC=this.Get16(65528)):(t&this.IRQ2Flag)==this.IRQ2Flag&&(this.Push(this.PCH()),this.Push(this.PCL()),this.Push(this.P),this.SetIFlag(),this.PC=this.Get16(65526)),this.ProgressClock=8*this.CPUBaseClock):this.OpExec()}OpExec(){let t,e,s,i,a,h=this.Get(this.PC);switch(h){case 105:this.ADC(this.PC+1);break;case 101:this.ADC(this.ZP());break;case 117:this.ADC(this.ZP_X());break;case 114:this.ADC(this.IND());break;case 97:this.ADC(this.IND_X());break;case 113:this.ADC(this.IND_Y());break;case 109:this.ADC(this.ABS());break;case 125:this.ADC(this.ABS_X());break;case 121:this.ADC(this.ABS_Y());break;case 233:this.SBC(this.PC+1);break;case 229:this.SBC(this.ZP());break;case 245:this.SBC(this.ZP_X());break;case 242:this.SBC(this.IND());break;case 225:this.SBC(this.IND_X());break;case 241:this.SBC(this.IND_Y());break;case 237:this.SBC(this.ABS());break;case 253:this.SBC(this.ABS_X());break;case 249:this.SBC(this.ABS_Y());break;case 41:this.AND(this.PC+1);break;case 37:this.AND(this.ZP());break;case 53:this.AND(this.ZP_X());break;case 50:this.AND(this.IND());break;case 33:this.AND(this.IND_X());break;case 49:this.AND(this.IND_Y());break;case 45:this.AND(this.ABS());break;case 61:this.AND(this.ABS_X());break;case 57:this.AND(this.ABS_Y());break;case 73:this.EOR(this.PC+1);break;case 69:this.EOR(this.ZP());break;case 85:this.EOR(this.ZP_X());break;case 82:this.EOR(this.IND());break;case 65:this.EOR(this.IND_X());break;case 81:this.EOR(this.IND_Y());break;case 77:this.EOR(this.ABS());break;case 93:this.EOR(this.ABS_X());break;case 89:this.EOR(this.ABS_Y());break;case 9:this.ORA(this.PC+1);break;case 5:this.ORA(this.ZP());break;case 21:this.ORA(this.ZP_X());break;case 18:this.ORA(this.IND());break;case 1:this.ORA(this.IND_X());break;case 17:this.ORA(this.IND_Y());break;case 13:this.ORA(this.ABS());break;case 29:this.ORA(this.ABS_X());break;case 25:this.ORA(this.ABS_Y());break;case 6:t=this.ZP(),this.Set(t,this.ASL(this.Get(t)));break;case 22:t=this.ZP_X(),this.Set(t,this.ASL(this.Get(t)));break;case 14:t=this.ABS(),this.Set(t,this.ASL(this.Get(t)));break;case 30:t=this.ABS_X(),this.Set(t,this.ASL(this.Get(t)));break;case 10:this.A=this.ASL(this.A);break;case 70:t=this.ZP(),this.Set(t,this.LSR(this.Get(t)));break;case 86:t=this.ZP_X(),this.Set(t,this.LSR(this.Get(t)));break;case 78:t=this.ABS(),this.Set(t,this.LSR(this.Get(t)));break;case 94:t=this.ABS_X(),this.Set(t,this.LSR(this.Get(t)));break;case 74:this.A=this.LSR(this.A);break;case 38:t=this.ZP(),this.Set(t,this.ROL(this.Get(t)));break;case 54:t=this.ZP_X(),this.Set(t,this.ROL(this.Get(t)));break;case 46:t=this.ABS(),this.Set(t,this.ROL(this.Get(t)));break;case 62:t=this.ABS_X(),this.Set(t,this.ROL(this.Get(t)));break;case 42:this.A=this.ROL(this.A);break;case 102:t=this.ZP(),this.Set(t,this.ROR(this.Get(t)));break;case 118:t=this.ZP_X(),this.Set(t,this.ROR(this.Get(t)));break;case 110:t=this.ABS(),this.Set(t,this.ROR(this.Get(t)));break;case 126:t=this.ABS_X(),this.Set(t,this.ROR(this.Get(t)));break;case 106:this.A=this.ROR(this.A);break;case 15:this.BBRi(0);break;case 31:this.BBRi(1);break;case 47:this.BBRi(2);break;case 63:this.BBRi(3);break;case 79:this.BBRi(4);break;case 95:this.BBRi(5);break;case 111:this.BBRi(6);break;case 127:this.BBRi(7);break;case 143:this.BBSi(0);break;case 159:this.BBSi(1);break;case 175:this.BBSi(2);break;case 191:this.BBSi(3);break;case 207:this.BBSi(4);break;case 223:this.BBSi(5);break;case 239:this.BBSi(6);break;case 255:this.BBSi(7);break;case 144:this.Branch((this.P&this.CFlag)==0,1);break;case 176:this.Branch((this.P&this.CFlag)==this.CFlag,1);break;case 208:this.Branch((this.P&this.ZFlag)==0,1);break;case 240:this.Branch((this.P&this.ZFlag)==this.ZFlag,1);break;case 16:this.Branch((this.P&this.NFlag)==0,1);break;case 48:this.Branch((this.P&this.NFlag)==this.NFlag,1);break;case 80:this.Branch((this.P&this.VFlag)==0,1);break;case 112:this.Branch((this.P&this.VFlag)==this.VFlag,1);break;case 128:this.Branch(!0,1);break;case 68:this.PC++,this.Push(this.PCH()),this.Push(this.PCL()),this.Branch(!0,0);break;case 32:e=this.ABS(),this.PC+=2,this.Push(this.PCH()),this.Push(this.PCL()),this.PC=e,this.ClearTFlag();break;case 64:this.P=this.Pull(),this.toPCL(this.Pull()),this.toPCH(this.Pull());break;case 96:this.ClearTFlag(),this.toPCL(this.Pull()),this.toPCH(this.Pull()),this.PC++;break;case 76:this.PC=this.ABS(),this.ClearTFlag();break;case 108:this.PC=this.ABS_IND(),this.ClearTFlag();break;case 124:this.PC=this.ABS_X_IND(),this.ClearTFlag();break;case 0:this.PC+=2,this.Push(this.PCH()),this.Push(this.PCL()),this.SetBFlag(),this.Push(this.P),this.ClearDFlag(),this.ClearTFlag(),this.SetIFlag(),this.PC=this.Get16(65526);break;case 98:this.A=0,this.ClearTFlag();break;case 130:this.X=0,this.ClearTFlag();break;case 194:this.Y=0,this.ClearTFlag();break;case 24:this.ClearCFlag(),this.ClearTFlag();break;case 216:this.ClearDFlag(),this.ClearTFlag();break;case 88:this.ClearIFlag(),this.ClearTFlag();break;case 184:this.ClearVFlag(),this.ClearTFlag();break;case 56:this.SetCFlag(),this.ClearTFlag();break;case 248:this.SetDFlag(),this.ClearTFlag();break;case 120:this.SetIFlag(),this.ClearTFlag();break;case 244:this.SetTFlag();break;case 201:this.Compare(this.A,this.PC+1);break;case 197:this.Compare(this.A,this.ZP());break;case 213:this.Compare(this.A,this.ZP_X());break;case 210:this.Compare(this.A,this.IND());break;case 193:this.Compare(this.A,this.IND_X());break;case 209:this.Compare(this.A,this.IND_Y());break;case 205:this.Compare(this.A,this.ABS());break;case 221:this.Compare(this.A,this.ABS_X());break;case 217:this.Compare(this.A,this.ABS_Y());break;case 224:this.Compare(this.X,this.PC+1);break;case 228:this.Compare(this.X,this.ZP());break;case 236:this.Compare(this.X,this.ABS());break;case 192:this.Compare(this.Y,this.PC+1);break;case 196:this.Compare(this.Y,this.ZP());break;case 204:this.Compare(this.Y,this.ABS());break;case 198:t=this.ZP(),this.Set(t,this.Decrement(this.Get(t)));break;case 214:t=this.ZP_X(),this.Set(t,this.Decrement(this.Get(t)));break;case 206:t=this.ABS(),this.Set(t,this.Decrement(this.Get(t)));break;case 222:t=this.ABS_X(),this.Set(t,this.Decrement(this.Get(t)));break;case 58:this.A=this.Decrement(this.A);break;case 202:this.X=this.Decrement(this.X);break;case 136:this.Y=this.Decrement(this.Y);break;case 230:t=this.ZP(),this.Set(t,this.Increment(this.Get(t)));break;case 246:t=this.ZP_X(),this.Set(t,this.Increment(this.Get(t)));break;case 238:t=this.ABS(),this.Set(t,this.Increment(this.Get(t)));break;case 254:t=this.ABS_X(),this.Set(t,this.Increment(this.Get(t)));break;case 26:this.A=this.Increment(this.A);break;case 232:this.X=this.Increment(this.X);break;case 200:this.Y=this.Increment(this.Y);break;case 72:this.Push(this.A),this.ClearTFlag();break;case 8:this.Push(this.P),this.ClearTFlag();break;case 218:this.Push(this.X),this.ClearTFlag();break;case 90:this.Push(this.Y),this.ClearTFlag();break;case 104:this.A=this.Pull(),this.SetNZFlag(this.A),this.ClearTFlag();break;case 40:this.P=this.Pull();break;case 250:this.X=this.Pull(),this.SetNZFlag(this.X),this.ClearTFlag();break;case 122:this.Y=this.Pull(),this.SetNZFlag(this.Y),this.ClearTFlag();break;case 7:this.RMBi(0);break;case 23:this.RMBi(1);break;case 39:this.RMBi(2);break;case 55:this.RMBi(3);break;case 71:this.RMBi(4);break;case 87:this.RMBi(5);break;case 103:this.RMBi(6);break;case 119:this.RMBi(7);break;case 135:this.SMBi(0);break;case 151:this.SMBi(1);break;case 167:this.SMBi(2);break;case 183:this.SMBi(3);break;case 199:this.SMBi(4);break;case 215:this.SMBi(5);break;case 231:this.SMBi(6);break;case 247:this.SMBi(7);break;case 34:e=this.A,this.A=this.X,this.X=e,this.ClearTFlag();break;case 66:e=this.A,this.A=this.Y,this.Y=e,this.ClearTFlag();break;case 2:e=this.X,this.X=this.Y,this.Y=e,this.ClearTFlag();break;case 170:this.X=this.A,this.SetNZFlag(this.X),this.ClearTFlag();break;case 168:this.Y=this.A,this.SetNZFlag(this.Y),this.ClearTFlag();break;case 186:this.X=this.S,this.SetNZFlag(this.X),this.ClearTFlag();break;case 138:this.A=this.X,this.SetNZFlag(this.A),this.ClearTFlag();break;case 154:this.S=this.X,this.ClearTFlag();break;case 152:this.A=this.Y,this.SetNZFlag(this.A),this.ClearTFlag();break;case 137:this.BIT(this.PC+1);break;case 36:this.BIT(this.ZP());break;case 52:this.BIT(this.ZP_X());break;case 44:this.BIT(this.ABS());break;case 60:this.BIT(this.ABS_X());break;case 131:this.TST(this.PC+1,8192|this.Get(this.PC+2));break;case 163:this.TST(this.PC+1,8192|this.Get(this.PC+2)+this.X&255);break;case 147:this.TST(this.PC+1,this.Get16(this.PC+2));break;case 179:this.TST(this.PC+1,this.Get16(this.PC+2)+this.X&65535);break;case 20:this.TRB(this.ZP());break;case 28:this.TRB(this.ABS());break;case 4:this.TSB(this.ZP());break;case 12:this.TSB(this.ABS());break;case 169:this.A=this.Load(this.PC+1);break;case 165:this.A=this.Load(this.ZP());break;case 181:this.A=this.Load(this.ZP_X());break;case 178:this.A=this.Load(this.IND());break;case 161:this.A=this.Load(this.IND_X());break;case 177:this.A=this.Load(this.IND_Y());break;case 173:this.A=this.Load(this.ABS());break;case 189:this.A=this.Load(this.ABS_X());break;case 185:this.A=this.Load(this.ABS_Y());break;case 162:this.X=this.Load(this.PC+1);break;case 166:this.X=this.Load(this.ZP());break;case 182:this.X=this.Load(this.ZP_Y());break;case 174:this.X=this.Load(this.ABS());break;case 190:this.X=this.Load(this.ABS_Y());break;case 160:this.Y=this.Load(this.PC+1);break;case 164:this.Y=this.Load(this.ZP());break;case 180:this.Y=this.Load(this.ZP_X());break;case 172:this.Y=this.Load(this.ABS());break;case 188:this.Y=this.Load(this.ABS_X());break;case 133:this.Store(this.ZP(),this.A);break;case 149:this.Store(this.ZP_X(),this.A);break;case 146:this.Store(this.IND(),this.A);break;case 129:this.Store(this.IND_X(),this.A);break;case 145:this.Store(this.IND_Y(),this.A);break;case 141:this.Store(this.ABS(),this.A);break;case 157:this.Store(this.ABS_X(),this.A);break;case 153:this.Store(this.ABS_Y(),this.A);break;case 134:this.Store(this.ZP(),this.X);break;case 150:this.Store(this.ZP_Y(),this.X);break;case 142:this.Store(this.ABS(),this.X);break;case 132:this.Store(this.ZP(),this.Y);break;case 148:this.Store(this.ZP_X(),this.Y);break;case 140:this.Store(this.ABS(),this.Y);break;case 100:this.Store(this.ZP(),0);break;case 116:this.Store(this.ZP_X(),0);break;case 156:this.Store(this.ABS(),0);break;case 158:this.Store(this.ABS_X(),0);break;case 234:this.ClearTFlag();break;case 3:this.SetVDCRegister(this.Get(this.PC+1),this.VDCSelect),this.ClearTFlag();break;case 19:this.SetVDCLow(this.Get(this.PC+1),this.VDCSelect),this.ClearTFlag();break;case 35:this.SetVDCHigh(this.Get(this.PC+1),this.VDCSelect),this.ClearTFlag();break;case 83:for(s=this.Get(this.PC+1),i=1,s==0?s=this.MPRSelect:this.MPRSelect=s,a=0;a<8;a++)(s&i<<a)!=0&&(this.MPR[a]=this.A<<13);break;case 67:for(s=this.Get(this.PC+1),i=1,s==0?s=this.MPRSelect:this.MPRSelect=s,a=0;a<8;a++)(s&i<<a)!=0&&(this.A=this.MPR[a]>>>13);break;case 243:this.TransferLen==0&&(this.TransferSrc=this.Get16(this.PC+1),this.TransferDist=this.Get16(this.PC+3),this.TransferLen=this.Get16(this.PC+5),this.TransferAlt=1,this.ProgressClock=17),this.Set(this.TransferDist,this.Get(this.TransferSrc)),this.TransferSrc=this.TransferSrc+this.TransferAlt&65535,this.TransferDist=this.TransferDist+1&65535,this.TransferLen=this.TransferLen-1&65535,this.TransferAlt=this.TransferAlt==1?-1:1,this.ProgressClock+=6,this.TransferLen==0&&(this.ClearTFlag(),this.PC+=7);break;case 195:this.TransferLen==0&&(this.TransferSrc=this.Get16(this.PC+1),this.TransferDist=this.Get16(this.PC+3),this.TransferLen=this.Get16(this.PC+5),this.ProgressClock=17),this.Set(this.TransferDist,this.Get(this.TransferSrc)),this.TransferSrc=this.TransferSrc-1&65535,this.TransferDist=this.TransferDist-1&65535,this.TransferLen=this.TransferLen-1&65535,this.ProgressClock+=6,this.TransferLen==0&&(this.ClearTFlag(),this.PC+=7);break;case 227:this.TransferLen==0&&(this.TransferSrc=this.Get16(this.PC+1),this.TransferDist=this.Get16(this.PC+3),this.TransferLen=this.Get16(this.PC+5),this.TransferAlt=1,this.ProgressClock=17),this.Set(this.TransferDist,this.Get(this.TransferSrc)),this.TransferSrc=this.TransferSrc+1&65535,this.TransferDist=this.TransferDist+this.TransferAlt&65535,this.TransferLen=this.TransferLen-1&65535,this.TransferAlt=this.TransferAlt==1?-1:1,this.ProgressClock+=6,this.TransferLen==0&&(this.ClearTFlag(),this.PC+=7);break;case 115:this.TransferLen==0&&(this.TransferSrc=this.Get16(this.PC+1),this.TransferDist=this.Get16(this.PC+3),this.TransferLen=this.Get16(this.PC+5),this.ProgressClock=17),this.Set(this.TransferDist,this.Get(this.TransferSrc)),this.TransferSrc=this.TransferSrc+1&65535,this.TransferDist=this.TransferDist+1&65535,this.TransferLen=this.TransferLen-1&65535,this.ProgressClock+=6,this.TransferLen==0&&(this.ClearTFlag(),this.PC+=7);break;case 211:this.TransferLen==0&&(this.TransferSrc=this.Get16(this.PC+1),this.TransferDist=this.Get16(this.PC+3),this.TransferLen=this.Get16(this.PC+5),this.ProgressClock=17),this.Set(this.TransferDist,this.Get(this.TransferSrc)),this.TransferSrc=this.TransferSrc+1&65535,this.TransferLen=this.TransferLen-1&65535,this.ProgressClock+=6,this.TransferLen==0&&(this.ClearTFlag(),this.PC+=7);break;case 212:this.ClearTFlag(),this.CPUBaseClock=this.BaseClock7;break;case 84:this.ClearTFlag(),this.CPUBaseClock=this.BaseClock1;break;default:this.ClearTFlag();break}this.PC+=this.OpBytes[h],this.ProgressClock=(this.ProgressClock+this.OpCycles[h])*this.CPUBaseClock}Adder(t,e){let s,i=this.Get(t);!e&&(this.P&this.TFlag)==this.TFlag?(this.ProgressClock=3,s=this.Get(8192|this.X)):s=this.A,e&&(i=~i&255);let a=this.P&1,h=s+i+a;(this.P&this.DFlag)==0?((~s&~i&h|s&i&~h)&128)==128?this.SetVFlag():this.ClearVFlag():(this.ProgressClock+=1,e?((h&15)>9&&(h-=6),(h&240)>144&&(h-=96)):((s&15)+(i&15)+a>9&&(h+=6),(h&496)>144&&(h+=96))),h>255?this.SetCFlag():this.ClearCFlag(),h&=255,this.SetNZFlag(h),!e&&(this.P&this.TFlag)==this.TFlag?this.Set(8192|this.X,h):this.A=h,this.ClearTFlag()}ADC(t){this.Adder(t,!1)}SBC(t){this.Adder(t,!0)}AND(t){let e,s=this.Get(t);(this.P&this.TFlag)==0?e=this.A:(this.ProgressClock=3,e=this.Get(8192|this.X));let i=e&s;this.SetNZFlag(i),(this.P&this.TFlag)==0?this.A=i:this.Set(8192|this.X,i),this.ClearTFlag()}EOR(t){let e,s=this.Get(t);(this.P&this.TFlag)==0?e=this.A:(this.ProgressClock=3,e=this.Get(8192|this.X));let i=e^s;this.SetNZFlag(i),(this.P&this.TFlag)==0?this.A=i:this.Set(8192|this.X,i),this.ClearTFlag()}ORA(t){let e,s=this.Get(t);(this.P&this.TFlag)==0?e=this.A:(this.ProgressClock=3,e=this.Get(8192|this.X));let i=e|s;this.SetNZFlag(i),(this.P&this.TFlag)==0?this.A=i:this.Set(8192|this.X,i),this.ClearTFlag()}ASL(t){return t<<=1,t>255?this.SetCFlag():this.ClearCFlag(),t&=255,this.SetNZFlag(t),this.ClearTFlag(),t}LSR(t){return(t&1)==1?this.SetCFlag():this.ClearCFlag(),t>>=1,this.SetNZFlag(t),this.ClearTFlag(),t}ROL(t){return t=t<<1|this.P&1,t>255?this.SetCFlag():this.ClearCFlag(),t&=255,this.SetNZFlag(t),this.ClearTFlag(),t}ROR(t){let e=this.P&this.CFlag;return(t&1)==1?this.SetCFlag():this.ClearCFlag(),t=t>>1|e<<7,this.SetNZFlag(t),this.ClearTFlag(),t}BBRi(t){let e=this.Get(this.ZP());e=e>>t&1,this.Branch(e==0,2)}BBSi(t){let e=this.Get(this.ZP());e=e>>t&1,this.Branch(e==1,2)}Branch(t,e){if(this.ClearTFlag(),t){let s=this.Get(this.PC+e);s>=128&&(s|=65280),this.PC=this.PC+e+1+s&65535,this.ProgressClock=2}else this.PC+=e+1}Compare(t,e){t-=this.Get(e),t<0?this.ClearCFlag():this.SetCFlag(),this.ClearTFlag(),this.SetNZFlag(t&255)}Decrement(t){return t=t-1&255,this.SetNZFlag(t),this.ClearTFlag(),t}Increment(t){return t=t+1&255,this.SetNZFlag(t),this.ClearTFlag(),t}Push(t){this.Set(8448|this.S,t),this.S=this.S-1&255}Pull(){return this.S=this.S+1&255,this.Get(8448|this.S)}RMBi(t){let e=this.ZP();this.Set(e,this.Get(e)&~(1<<t)),this.ClearTFlag()}SMBi(t){let e=this.ZP();this.Set(e,this.Get(e)|1<<t),this.ClearTFlag()}BIT(t){let e=this.Get(t);this.SetNZFlag(this.A&e),this.P=this.P&~(this.NFlag|this.VFlag)|e&(this.NFlag|this.VFlag),this.ClearTFlag()}TST(t,e){let s=this.Get(t),i=this.Get(e);this.SetNZFlag(s&i),this.P=this.P&~(this.NFlag|this.VFlag)|i&(this.NFlag|this.VFlag),this.ClearTFlag()}TRB(t){let e=this.Get(t),s=~this.A&e;this.Set(t,s),this.SetNZFlag(s),this.P=this.P&~(this.NFlag|this.VFlag)|e&(this.NFlag|this.VFlag),this.ClearTFlag()}TSB(t){let e=this.Get(t),s=this.A|e;this.Set(t,s),this.SetNZFlag(s),this.P=this.P&~(this.NFlag|this.VFlag)|e&(this.NFlag|this.VFlag),this.ClearTFlag()}Load(t){let e=this.Get(t);return this.SetNZFlag(e),this.ClearTFlag(),e}Store(t,e){this.Set(t,e),this.ClearTFlag()}ZP(){return 8192|this.Get(this.PC+1)}ZP_X(){return 8192|this.Get(this.PC+1)+this.X&255}ZP_Y(){return 8192|this.Get(this.PC+1)+this.Y&255}IND(){return this.Get16(8192|this.Get(this.PC+1))}IND_X(){return this.Get16(8192|this.Get(this.PC+1)+this.X&255)}IND_Y(){return this.Get16(8192|this.Get(this.PC+1))+this.Y&65535}ABS(){return this.Get16(this.PC+1)}ABS_X(){return this.Get16(this.PC+1)+this.X&65535}ABS_Y(){return this.Get16(this.PC+1)+this.Y&65535}ABS_IND(){return this.Get16(this.Get16(this.PC+1))}ABS_X_IND(){return this.Get16(this.Get16(this.PC+1)+this.X&65535)}SetNZFlag(t){this.P=this.P&~(this.NFlag|this.ZFlag)|this.NZCacheTable[t]}SetVFlag(){this.P|=this.VFlag}ClearVFlag(){this.P&=~this.VFlag}SetTFlag(){this.P|=this.TFlag}ClearTFlag(){this.P&=~this.TFlag}SetBFlag(){this.P|=this.BFlag}ClearBFlag(){this.P&=~this.BFlag}SetDFlag(){this.P|=this.DFlag}ClearDFlag(){this.P&=~this.DFlag}SetIFlag(){this.P|=this.IFlag}ClearIFlag(){this.P&=~this.IFlag}SetCFlag(){this.P|=this.CFlag}ClearCFlag(){this.P&=~this.CFlag}PCH(){return this.PC>>8}PCL(){return this.PC&255}toPCH(t){this.PC=this.PC&255|t<<8}toPCL(t){this.PC=this.PC&65280|t}StorageConstruct(){this.MPR=new Array(8),this.MPRSelect=0,this.RAM=new Uint8Array(32768),this.RAMMask=8191,this.BRAM=new Uint8Array(8192).fill(0),this.BRAMUse=!1,this.INTIRQ2=0,this.IntDisableRegister=0,this.Mapper=null,this.Mapper0=class extends this.MapperBase{constructor(t,e){super(t,e);let s=this.ROM.length-1;for(this.Address=524288;this.Address>0&&(this.Address&s)==0;)this.Address>>>=1}Read(t){return t>=this.ROM.length?this.ROM[t&this.Address-1|this.Address]:this.ROM[t]}},this.Mapper1=class extends this.MapperBase{constructor(t,e){super(t,e);this.Address=0}Init(){this.Address=0}Read(t){return t<524288?this.ROM[t]:this.ROM[this.Address|t&524287]}Write(t,e){this.Address=(t&15)+1<<19}},this.Mapper2=class extends this.MapperBase{constructor(t,e){super(t,e);this.ROM=t}Read(t){return this.ROM[t]||0}Write(t,e){t>=524288&&(this.ROM[t]=e)}}}GetIntStatus(){return~this.IntDisableRegister&this.GetIntReqest()}GetIntDisable(){return this.IntDisableRegister}SetIntDisable(t){this.IntDisableRegister=t,this.TimerAcknowledge()}GetIntReqest(){return(((this.VDC[0].VDCStatus|this.VDC[1].VDCStatus)&63)!=0?this.IRQ1Flag:0)|this.INTIRQ2|this.INTTIQ}SetIntReqest(t){this.TimerAcknowledge()}SetROM(t){this.Init();let e=t.slice(t.length%8192);this.Mapper=new this.Mapper0(e,this),this.CPUReset()}StorageInit(){this.RAM.fill(0),this.RAMMask=this.SuperGrafx?32767:8191,this.StorageReset()}StorageReset(){this.IntDisableRegister=0;for(let t=0;t<7;t++)this.MPR[t]=255<<13;this.MPR[7]=0,this.MPRSelect=1}Get16(t){return this.Get(t+1)<<8|this.Get(t)}Get(t){if(t=this.MPR[t>>13]|t&8191,t<1048576)return this.Mapper.Read(t);if(t<2023424)return 255;if(t<2031616)return this.BRAMUse?this.BRAM[t&8191]:255;if(t<2064384)return this.RAM[t&this.RAMMask];if(t<2088960)return 255;if(t<2089984)if(this.SuperGrafx){let e=t&31;if(e<8)switch(t&3){case 0:return this.GetVDCStatus(0);case 1:return 0;case 2:return this.GetVDCLow(0);case 3:return this.GetVDCHigh(0)}else{if(e<16)return this.GetVPC(e&7);if(e<24)switch(t&3){case 0:return this.GetVDCStatus(1);case 1:return 0;case 2:return this.GetVDCLow(1);case 3:return this.GetVDCHigh(1)}else return 255}}else switch(t&3){case 0:return this.GetVDCStatus(0);case 1:return 0;case 2:return this.GetVDCLow(0);case 3:return this.GetVDCHigh(0)}if(t<2091008)switch(t&7){case 4:return this.GetVCEDataLow();case 5:return this.GetVCEDataHigh();default:return 0}if(t<2092032)return this.GetPSG(t&15);if(t<2093056)return this.ReadTimerCounter();if(t<2094080)return this.GetJoystick();if(t<2095104)switch(t&3){case 2:return this.GetIntDisable();case 3:return this.GetIntReqest();default:return 0}return 255}Set(t,e){if(t=this.MPR[t>>13]|t&8191,t<1048576){this.Mapper.Write(t,e);return}if(!(t<2023424)){if(t<2031616){this.BRAMUse&&(this.BRAM[t&8191]=e);return}if(t<2064384){this.RAM[t&this.RAMMask]=e;return}if(!(t<2088960)){if(t<2089984){if(this.SuperGrafx){let s=t&31;if(s<8)switch(t&3){case 0:this.SetVDCRegister(e,0);break;case 2:this.SetVDCLow(e,0);break;case 3:this.SetVDCHigh(e,0);break}else if(s<16)this.SetVPC(s&7,e);else if(s<24)switch(t&3){case 0:this.SetVDCRegister(e,1);break;case 2:this.SetVDCLow(e,1);break;case 3:this.SetVDCHigh(e,1);break}}else switch(t&3){case 0:this.SetVDCRegister(e,0);break;case 1:break;case 2:this.SetVDCLow(e,0);break;case 3:this.SetVDCHigh(e,0);break}return}if(t<2091008){switch(t&7){case 0:this.SetVCEControl(e);break;case 2:this.SetVCEAddressLow(e);break;case 3:this.SetVCEAddressHigh(e);break;case 4:this.SetVCEDataLow(e);break;case 5:this.SetVCEDataHigh(e);break}return}if(t<2092032){this.SetPSG(t&15,e);return}if(t<2093056){switch(t&1){case 0:this.WirteTimerReload(e);break;case 1:this.WirteTimerControl(e);break}return}if(t<2094080){this.SetJoystick(e);return}if(t<2095104){switch(t&3){case 2:this.SetIntDisable(e);break;case 3:this.SetIntReqest(e);break}return}}}}VCEConstruct(){this.Palette=new Array(512),this.PaletteData=new Array(512),this.MonoPaletteData=new Array(512),this.VCEBaseClock=0,this.VCEControl=0,this.VCEAddress=0,this.VCEData=0}VCEInit(){this.Palette.fill(0);for(let t=0;t<512;t++)this.PaletteData[t]={r:0,g:0,b:0},this.MonoPaletteData[t]={r:0,g:0,b:0};this.VCEBaseClock=this.BaseClock5,this.VCEControl=0,this.VCEAddress=0,this.VCEData=0}SetVCEControl(t){switch(this.VCEControl=t,t&3){case 0:this.VCEBaseClock=this.BaseClock5;break;case 1:this.VCEBaseClock=this.BaseClock7;break;case 2:case 3:this.VCEBaseClock=this.BaseClock10;break}}SetVCEAddressLow(t){this.VCEAddress=this.VCEAddress&65280|t}SetVCEAddressHigh(t){this.VCEAddress=(this.VCEAddress&255|t<<8)&511}GetVCEDataLow(){return this.Palette[this.VCEAddress]&255}GetVCEDataHigh(){let t=(this.Palette[this.VCEAddress]&65280)>>8;return this.VCEAddress=this.VCEAddress+1&511,t}SetVCEDataLow(t){this.Palette[this.VCEAddress]=this.Palette[this.VCEAddress]&65280|t,this.ToPalettes()}SetVCEDataHigh(t){this.Palette[this.VCEAddress]=this.Palette[this.VCEAddress]&255|t<<8,this.ToPalettes(),this.VCEAddress=this.VCEAddress+1&511}ToPalettes(){let t=this.Palette[this.VCEAddress],e=this.PaletteData[this.VCEAddress];e.r=(t>>3&7)*36,e.g=(t>>6&7)*36,e.b=(t&7)*36;let s=e.r*.299+e.g*.587+e.b*.114;this.MonoPaletteData[this.VCEAddress].r=s,this.MonoPaletteData[this.VCEAddress].g=s,this.MonoPaletteData[this.VCEAddress].b=s}VPCConstruct(){this.VPCRegister=new Uint8Array(8),this.VDCSelect=0,this.VPCWindow1=0,this.VPCWindow2=0,this.VPCPriority=new Uint8Array(4)}VPCInit(){this.VPCRegister.fill(0),this.VPCRegister[0]=17,this.VPCRegister[1]=17,this.VPCRegister[7]=255,this.VDCSelect=0,this.VPCWindow1=0,this.VPCWindow2=0,this.VPCPriority.fill(1)}SetVPC(t,e){t!=7&&(this.VPCRegister[t]=e,t==6&&(this.VDCSelect=e&1),(t==2||t==3)&&(this.VPCWindow1=(this.VPCRegister[2]|(this.VPCRegister[3]&3)<<8)-64,this.VPCWindow1<0&&(this.VPCWindow1=1024)),(t==4||t==5)&&(this.VPCWindow2=(this.VPCRegister[4]|(this.VPCRegister[5]&3)<<8)-64,this.VPCWindow2<0&&(this.VPCWindow2=-1)),t==0&&(this.VPCPriority[2]=this.VPCRegister[0]>>4,this.VPCPriority[3]=this.VPCRegister[0]&15),t==1&&(this.VPCPriority[0]=this.VPCRegister[1]>>4,this.VPCPriority[1]=this.VPCRegister[1]&15))}GetVPC(t){return this.VPCRegister[t]}VDCConstruct(){this.DrawFlag=!1,this.VDCPutLineProgressClock=0,this.VDCPutLine=0,this.VDC=new Array(2),this.VDCLineClock=1368,this.ScreenSize=[],this.ScreenSize[this.BaseClock5]=342,this.ScreenSize[this.BaseClock7]=456,this.ScreenSize[this.BaseClock10]=684,this.PutScreenSize=[],this.PutScreenSize[this.BaseClock5]=320,this.PutScreenSize[this.BaseClock7]=428,this.PutScreenSize[this.BaseClock10]=640,this.ScreenHeightMAX=262,this.ScreenWidthMAX=684,this.VScreenWidthArray=[],this.VScreenWidthArray[0]=32,this.VScreenWidthArray[16]=64,this.VScreenWidthArray[32]=128,this.VScreenWidthArray[48]=128,this.ReverseBit=new Uint8Array(256),this.ReverseBit=this.ReverseBit.map((t,e)=>(e&128)>>7|(e&64)>>5|(e&32)>>3|(e&16)>>1|(e&8)<<1|(e&4)<<3|(e&2)<<5|(e&1)<<7),this.ReverseBit16=new Uint16Array(65536).fill(0),this.ReverseBit16=this.ReverseBit16.map((t,e)=>this.ReverseBit[e&255]<<8|this.ReverseBit[(e&65280)>>8]),this.ReverseBit256=new Uint32Array(256).fill(0),this.ReverseBit256=this.ReverseBit256.map((t,e)=>{let s=this.ReverseBit[e];return(s&128)<<28-7|(s&64)<<24-6|(s&32)<<20-5|(s&16)<<16-4|(s&8)<<12-3|(s&4)<<8-2|(s&2)<<4-1|(s&1)<<0-0}),this.SPAddressMask=[],this.SPAddressMask[16]=[],this.SPAddressMask[32]=[],this.SPAddressMask[16][16]=2046,this.SPAddressMask[16][32]=2046&2042,this.SPAddressMask[16][64]=2046&2034,this.SPAddressMask[32][16]=2044,this.SPAddressMask[32][32]=2044&2042,this.SPAddressMask[32][64]=2044&2034}MakeSpriteLine(t){let e=this.VDC[t],s=e.SPLine;for(let c=0;c<e.ScreenWidth;c++){let S=s[c];S.data=0,S.palette=0,S.no=255,S.priority=0}if((e.VDCRegister[5]&64)==0)return;let i=0,a=e.DrawBGYLine-(e.VDS+e.VSW)+64,h=e.VRAM,r=e.SATB,n=this.ReverseBit16;for(let c=0,S=0;c<64;c++,S+=4){let P=r[S]&1023,F=r[S+3],x=((F&12288)>>8)+16;if(x=x>32?64:x,a<P||a>P+x-1)continue;let l=(r[S+1]&1023)-32,C=((F&256)>>4)+16;if(l+C<=0)continue;let A=a-P;(F&32768)==32768&&(A=x-1-A);let o=(r[S+2]&this.SPAddressMask[C][x])<<5|((A&48)<<3|A&15),k,b,g,D;(F&2048)==0?(k=n[h[o]],b=n[h[o+16]],g=n[h[o+32]],D=n[h[o+48]],C==32&&(k|=n[h[o|64]]<<16,b|=n[h[(o|64)+16]]<<16,g|=n[h[(o|64)+32]]<<16,D|=n[h[(o|64)+48]]<<16)):(k=h[o],b=h[o+16],g=h[o+32],D=h[o+48],C==32&&(k=k<<16|h[o|64],b=b<<16|h[(o|64)+16],g=g<<16|h[(o|64)+32],D=D<<16|h[(o|64)+48]));let d=(F&15)<<4|256,L=F&128,B=0;for(l<0&&(B-=l,l=0);B<C&&l<e.ScreenWidth;B++,l++){let f=s[l];if(f.data==0){let V=k>>>B&1|b>>>B<<1&2|g>>>B<<2&4|D>>>B<<3&8;V!=0&&(f.data=V,f.palette=d,f.priority=L)}if(f.no==255&&(f.no=c),c!=0&&f.no==0&&(e.VDCStatus|=e.VDCRegister[5]&1),++i==256&&(e.VDCStatus|=e.VDCRegister[5]&2,e.SpriteLimit))return}}}MakeBGLine(t){let e=this.VDC[t],s=e.SPLine,i=e.BGLine,a=e.ScreenWidth,h=(e.HDS+e.HSW<<3)+e.DrawBGIndex;if((e.VDCRegister[5]&128)==128){let r=e.VScreenWidth-1,n=e.VDCRegister[7],c=n>>3&r;n=(n&7)<<2;let S=e.DrawBGLine,P=(S>>3&e.VScreenHeight-1)*e.VScreenWidth;S=S&7;let F=e.VRAM,x=0,l=this.ReverseBit256;for(;x<a;){let C=F[c+P],A=((C&4095)<<4)+S,o=(C&61440)>>8,k=F[A],b=F[A+8],g=l[k&255]|l[(k&65280)>>8]<<1|l[b&255]<<2|l[(b&65280)>>8]<<3;for(;n<32&&x<a;n+=4,x++){let D=g>>>n&15,d=s[x];i[x+h]=d.data!=0&&(D==0||d.priority==128)?d.data|d.palette:D|(D==0?0:o)}n=0,c=c+1&r}}else for(let r=0;r<a;r++)i[r+h]=s[r].data|s[r].palette}MakeBGColorLineVDC(t){this.VDC[t].BGLine.fill(256)}VDCProcessDMA(t){let e=this.VDC[t];e.VRAMtoSATBCount>0&&(e.VRAMtoSATBCount-=this.ProgressClock,e.VRAMtoSATBCount<=0&&(e.VDCStatus=e.VDCStatus&191|(e.VDCRegister[15]&1)<<3)),e.VRAMtoVRAMCount>0&&(e.VRAMtoVRAMCount-=this.ProgressClock,e.VRAMtoVRAMCount<=0&&(e.VDCStatus=e.VDCStatus&191|(e.VDCRegister[15]&2)<<3))}VDCProcess(t){let e=this.VDC[t];e.VDCProgressClock-=this.VDCLineClock,e.DrawBGIndex=0,e.BGLine.fill(256);for(let s=0;s<e.ScreenSize;s+=e.DrawLineWidth){e.DrawBGYLine++,e.DrawBGYLine==this.ScreenHeightMAX&&(e.DrawBGYLine=0),e.DrawBGYLine<e.VDS+e.VSW?this.MakeBGColorLineVDC(t):e.DrawBGYLine<=e.VDS+e.VSW+e.VDW?(e.DrawBGLine=(e.DrawBGYLine==e.VDS+e.VSW?e.VDCRegister[8]:e.DrawBGLine+1)&e.VScreenHeightMask,e.VDCBurst?this.MakeBGColorLineVDC(t):(this.MakeSpriteLine(t),this.MakeBGLine(t))):this.MakeBGColorLineVDC(t);let i=e.VDS+e.VSW+e.VDW+1;if(i>261&&(i-=261),e.DrawBGYLine==i&&(e.VDCStatus|=(e.VDCRegister[5]&8)<<2,e.VRAMtoSATBStartFlag)){for(let a=0,h=e.VDCRegister[19];a<256;a++,h++)e.SATB[a]=e.VRAM[h];e.VRAMtoSATBCount=256*this.VCEBaseClock,e.VDCStatus|=64,e.VRAMtoSATBStartFlag=(e.VDCRegister[15]&16)==16}e.RasterCount++,e.DrawBGYLine==e.VDS+e.VSW-1&&(e.RasterCount=64),e.RasterCount==e.VDCRegister[6]&&(e.VDCStatus&32)==0&&(e.VDCStatus|=e.VDCRegister[5]&4),e.DrawBGIndex+=e.DrawLineWidth}}VDCRun(){for(this.VDCProcessDMA(0),this.VDC[0].VDCProgressClock+=this.ProgressClock,this.SuperGrafx&&(this.VDCProcessDMA(1),this.VDC[1].VDCProgressClock+=this.ProgressClock);this.VDC[0].VDCProgressClock>=this.VDCLineClock;)this.VDCProcess(0),this.SuperGrafx&&this.VDCProcess(1);if(this.VDCPutLineProgressClock+=this.ProgressClock,this.VDCPutLineProgressClock>=this.VDCLineClock){this.VDCPutLineProgressClock-=this.VDCLineClock,this.VDCPutLine++,this.VDCPutLine==this.ScreenHeightMAX&&(this.VDCPutLine=0,this.GetScreenSize(0),this.VDC[0].DrawBGYLine=0,this.SuperGrafx&&(this.GetScreenSize(1),this.VDC[1].DrawBGYLine=0),this.DrawFlag=!0,this.Ctx.putImageData(this.ImageData,0,0));let t=(this.VCEControl&128)==0?this.PaletteData:this.MonoPaletteData,e=this.ImageData.data,s=this.VDCPutLine*this.ScreenWidthMAX*4,i=t[256],a=this.ScreenSize[this.VCEBaseClock],h=this.VDC[0].BGLine;if(this.SuperGrafx){let r=this.VPCWindow1,n=this.VPCWindow2,c=this.VPCPriority,S=this.VDC[1].BGLine;for(let P=0;P<a;P++,s+=4){let F=0;P>=r&&(F|=1),P<=n&&(F|=2);let x=h[P],l=S[P],C;switch(c[F]){case 4|3:x>256||l>256?C=t[x>256?x:l]:C=t[(x&255)!=0?x:l];break;case 8|3:x<256&&x!=0?C=t[x]:C=t[(l&255)!=0?l:x];break;case 0|3:case 12|3:C=t[(x&255)!=0?x:l];break;case 0|1:case 4|1:case 8|1:case 12|1:C=t[x];break;case 0|2:case 4|2:case 8|2:case 12|2:C=t[l];break;default:C=i;break}e[s]=C.r,e[s+1]=C.g,e[s+2]=C.b}}else for(let r=0;r<a;r++,s+=4){let n=t[h[r]];e[s]=n.r,e[s+1]=n.g,e[s+2]=n.b}}}GetScreenSize(t){let e=this.VDC[t],s=e.VDCRegister;e.VScreenWidth=this.VScreenWidthArray[s[9]&48],e.VScreenHeight=(s[9]&64)==0?32:64,e.VScreenHeightMask=e.VScreenHeight*8-1,e.ScreenWidth=((s[11]&127)+1)*8,e.ScreenWidth>this.ScreenWidthMAX&&(e.ScreenWidth=this.ScreenWidthMAX),e.HDS=(s[10]&32512)>>8,e.HSW=s[10]&31,e.HDE=(s[11]&32512)>>8,e.HDW=s[11]&127,e.VDS=(s[12]&65280)>>8,e.VSW=s[12]&31,e.VDW=s[13]&511,e.VCR=s[14]&255,e.ScreenSize=this.ScreenSize[this.VCEBaseClock],this.MainCanvas.width!=e.ScreenSize&&(this.MainCanvas.width=this.PutScreenSize[this.VCEBaseClock]),e.DrawLineWidth=e.HDS+e.HSW+e.HDE+e.HDW+1<<3,e.DrawLineWidth<=this.ScreenSize[this.BaseClock5]?e.DrawLineWidth=this.ScreenSize[this.BaseClock5]:e.DrawLineWidth<=this.ScreenSize[this.BaseClock7]?e.DrawLineWidth=this.ScreenSize[this.BaseClock7]:e.DrawLineWidth=this.ScreenSize[this.BaseClock10],e.VDCBurst=(s[5]&192)==0}VDCInit(){this.VDCPutLineProgressClock=0,this.VDCPutLine=0,this.DrawFlag=!1;for(let t=0;t<2;t++){this.VDC[t]={VDCRegister:new Uint16Array(20).fill(0),VRAM:new Uint16Array(65536).fill(0),SATB:new Uint16Array(256).fill(0),VDCBurst:!1,SpriteLimit:!1,SPLine:new Array(this.ScreenWidthMAX),BGLine:new Array(this.ScreenWidthMAX).fill(0),VDCStatus:0,VDCRegisterSelect:0,WriteVRAMData:0,VRAMtoSATBStartFlag:!1,VRAMtoSATBCount:0,VRAMtoVRAMCount:0,RasterCount:64,VDCProgressClock:0,DrawBGYLine:0,DrawBGLine:0,VScreenWidth:0,VScreenHeight:0,VScreenHeightMask:0,ScreenWidth:0,ScreenSize:0,DrawLineWidth:0,DrawBGIndex:0,HDS:0,HSW:0,HDE:0,HDW:0,VDS:0,VSW:0,VDW:0,VCR:0};for(let e=0;e<this.VDC[t].SPLine.length;e++)this.VDC[t].SPLine[e]={data:0,no:255,priority:0};this.VDC[t].VDCRegister[9]=16,this.VDC[t].VDCRegister[10]=514,this.VDC[t].VDCRegister[11]=799,this.VDC[t].VDCRegister[12]=3842,this.VDC[t].VDCRegister[13]=239,this.VDC[t].VDCRegister[14]=3}this.GetScreenSize(0),this.GetScreenSize(1)}SetVDCRegister(t,e){this.VDC[e].VDCRegisterSelect=t&31}SetVDCLow(t,e){let s=this.VDC[e];if(s.VDCRegisterSelect==2?s.WriteVRAMData=t:s.VDCRegister[s.VDCRegisterSelect]=s.VDCRegister[s.VDCRegisterSelect]&65280|t,s.VDCRegisterSelect==1){s.VDCRegister[2]=s.VRAM[s.VDCRegister[1]];return}if(s.VDCRegisterSelect==8){s.DrawBGLine=s.VDCRegister[8];return}s.VDCRegisterSelect==15&&(s.VRAMtoSATBStartFlag=(s.VDCRegister[15]&16)==16)}SetVDCHigh(t,e){let s=this.VDC[e];if(s.VDCRegisterSelect==2){s.VRAM[s.VDCRegister[0]]=s.WriteVRAMData|t<<8,s.VDCRegister[0]=s.VDCRegister[0]+this.GetVRAMIncrement(e)&65535;return}if(s.VDCRegister[s.VDCRegisterSelect]=s.VDCRegister[s.VDCRegisterSelect]&255|t<<8,s.VDCRegisterSelect==1){s.VDCRegister[2]=s.VRAM[s.VDCRegister[1]],s.VDCRegister[3]=s.VDCRegister[2],s.VDCRegister[1]=s.VDCRegister[1]+this.GetVRAMIncrement(e)&65535;return}if(s.VDCRegisterSelect==8){s.DrawBGLine=s.VDCRegister[8];return}if(s.VDCRegisterSelect==18){let i=(s.VDCRegister[15]&4)==0?1:-1,a=(s.VDCRegister[15]&8)==0?1:-1,h=s.VDCRegister[16],r=s.VDCRegister[17],n=s.VDCRegister[18]+1;s.VRAMtoVRAMCount=n*this.VCEBaseClock,s.VDCStatus|=64;let c=s.VRAM;for(;n>0;n--)c[r]=c[h],h=h+i&65535,r=r+a&65535;return}s.VDCRegisterSelect==19&&(s.VRAMtoSATBStartFlag=!0)}GetVRAMIncrement(t){switch(this.VDC[t].VDCRegister[5]&6144){case 0:return 1;case 2048:return 32;case 4096:return 64;case 6144:return 128}}GetVDCStatus(t){let e=this.VDC[t].VDCStatus;return this.VDC[t].VDCStatus&=64,e}GetVDCLow(t){return this.VDC[t].VDCRegister[this.VDC[t].VDCRegisterSelect]&255}GetVDCHigh(t){let e=this.VDC[t];if(e.VDCRegisterSelect==2||e.VDCRegisterSelect==3){let s=(e.VDCRegister[2]&65280)>>8;return e.VDCRegister[2]=e.VRAM[e.VDCRegister[1]],e.VDCRegister[3]=e.VDCRegister[2],e.VDCRegister[1]=e.VDCRegister[1]+this.GetVRAMIncrement(t)&65535,s}return(e.VDCRegister[e.VDCRegisterSelect]&65280)>>8}SoundConstruct(){this.WaveDataArray=[],this.WaveClockCounter=0,this.WaveVolume=1,this.WebAudioCtx=null,this.WebAudioJsNode=null,this.WebAudioGainNode=null,this.WebAudioBufferSize=2048,this.PSGClock=3579545}WebAudioFunction(t){let e=[],s=[];for(let i=0;i<2;i++){if(e[i]=t.outputBuffer.getChannelData(i),s[i]=new Float32Array(this.WebAudioBufferSize),this.WaveDataArray[i].length<this.WebAudioBufferSize)s[i].fill(0);else{for(let a=0;a<s[i].length;a++)s[i][a]=this.WaveDataArray[i].shift()/(32*16*32*8*16);this.WaveDataArray[i].length>this.WebAudioBufferSize*2&&(this.WaveDataArray[i]=this.WaveDataArray[i].slice(this.WebAudioBufferSize))}e[i].set(s[i])}}SoundInit(){this.WaveClockCounter=0,this.WaveDataArray=[],this.WaveDataArray[0]=[],this.WaveDataArray[1]=[],typeof AudioContext!="undefined"&&this.WebAudioCtx==null&&this.CreateAudioContext()}CreateAudioContext(){this.WebAudioCtx=new window.AudioContext,this.WebAudioJsNode=this.WebAudioCtx.createScriptProcessor(this.WebAudioBufferSize,0,2),this.WebAudioJsNode.onaudioprocess=this.WebAudioFunction.bind(this),this.WebAudioGainNode=this.WebAudioCtx.createGain(),this.WebAudioJsNode.connect(this.WebAudioGainNode),this.WebAudioGainNode.connect(this.WebAudioCtx.destination)}SoundSet(){let t,e,s,i,a,h;if(this.WaveClockCounter+=this.WebAudioCtx.sampleRate,this.WaveClockCounter>=this.PSGClock){for(this.WaveClockCounter-=this.PSGClock,t=0,e=0,a=0;a<6;a++)(a!=1||!this.WaveLfoOn)&&(s=this.PSGChannel[a],a<4||!s.noiseon?h=s.keyon?s.dda?s.R[6]&31:s.wave[s.index]:0:h=(s.noise&1)==1?15:0,t+=h*s.leftvol,e+=h*s.rightvol);this.WaveDataArray[0].push(t*this.WaveVolumeLeft),this.WaveDataArray[1].push(e*this.WaveVolumeRight),this.WebAudioGainNode.gain.value=this.WaveVolume}}PSGConstruct(){this.PSGChannel=new Array(6),this.PSGBaseClock=this.BaseClock3,this.PSGProgressClock=0,this.WaveVolumeLeft=0,this.WaveVolumeRight=0,this.WaveLfoOn=!1,this.WaveLfoControl=0,this.WaveLfoFreqency=0}PSGInit(){this.SoundInit();for(let t=0;t<this.PSGChannel.length;t++)this.PSGChannel[t]={R:new Array(10).fill(0),keyon:!1,dda:!1,freq:0,count:0,vol:0,leftvol:0,rightvol:0,noiseon:!1,noisefreq:0,noise:32768,noisestate:0,index:0,wave:new Uint8Array(32)}}PSGRun(){if(this.WebAudioCtx==null)return;let t,e,s,i,a,h;for(this.PSGProgressClock+=this.ProgressClock,e=this.PSGProgressClock/this.PSGBaseClock|0,this.PSGProgressClock%=this.PSGBaseClock;e>0;){for(e--,s=0,this.WaveLfoOn&&(i=this.PSGChannel[0],a=this.PSGChannel[1],i.keyon&&(i.count==0?(i.index=i.index+1&31,h=0,this.WaveLfoControl!=0&&(h=a.wave[a.index],h=h>15?h-32:h&15,h<<=4*(this.WaveLfoControl-1)),h=i.freq+h,h<0&&(h=0),i.count=h):i.count--,a.count==0?(a.index=a.index+1&31,a.count=a.freq*this.WaveLfoFreqency):a.count--),s=2);s<6;s++)t=this.PSGChannel[s],s<4||!t.noiseon?t.keyon&&!t.dda&&(t.count==0?(t.index=t.index+1&31,t.count=t.freq):t.count--):t.keyon&&!t.dda&&(t.count==0?(t.index=t.index+1&31,t.index==0&&(t.noise=t.noise>>1|(t.noise<<12^t.noise<<15)&32768),t.count=t.noisefreq):t.count--);this.SoundSet()}}SetPSG(t,e){if(t==0){this.PSGChannel[0].R[0]=e&7;return}if(this.PSGChannel[0].R[0]>5)return;let s=this.PSGChannel[this.PSGChannel[0].R[0]];switch(s.R[t]=e,t){case 1:this.PSGChannel[0].R[1]=e,this.WaveVolumeLeft=(e&240)>>4,this.WaveVolumeRight=e&15;return;case 2:case 3:s.freq=(s.R[3]<<8|s.R[2])&4095;return;case 4:s.keyon=(e&128)==128,s.dda=(e&64)==64,(e&64)==64&&(s.index=0),s.vol=e&31;case 5:let i=s.R[4]&31;s.leftvol=((s.R[5]&240)>>4)*i,s.rightvol=(s.R[5]&15)*i;return;case 6:s.dda||(s.wave[s.index]=e&31,s.index=s.index+1&31);return;case 7:s.noiseon=(e&128)==128,s.noisefreq=e&31^31;return;case 8:this.PSGChannel[0].R[8]=e,this.WaveLfoFreqency=e;return;case 9:this.PSGChannel[0].R[9]=e,this.WaveLfoOn=(e&128)==128,this.WaveLfoControl=e&3;return}}GetPSG(t){return t>9?255:t==0||t==1||t==8||t==9?this.PSGChannel[0].R[t]:this.PSGChannel[0].R[0]>5?255:this.PSGChannel[this.PSGChannel[0].R[0]].R[t]}TimerConstruct(){this.TimerBaseClock=this.BaseClock7,this.TimerReload=0,this.TimerFlag=!1,this.TimerCounter=0,this.TimerPrescaler=0,this.INTTIQ=0}TimerInit(){this.TimerReload=0,this.TimerFlag=!1,this.TimerCounter=0,this.TimerPrescaler=0,this.INTTIQ=0}ReadTimerCounter(){return this.TimerCounter}TimerAcknowledge(){this.INTTIQ=0}WirteTimerReload(t){this.TimerReload=t&127}WirteTimerControl(t){!this.TimerFlag&&(t&1)==1&&(this.TimerCounter=this.TimerReload,this.TimerPrescaler=0),this.TimerFlag=(t&1)==1}TimerRun(){if(this.TimerFlag)for(this.TimerPrescaler+=this.ProgressClock;this.TimerPrescaler>=1024*this.TimerBaseClock;)this.TimerPrescaler-=1024*this.TimerBaseClock,this.TimerCounter--,this.TimerCounter<0&&(this.TimerCounter=this.TimerReload,this.INTTIQ=this.TIQFlag)}JoystickConstruct(){this.JoystickSEL=0,this.JoystickCLR=0,this.KeyUpFunction=null,this.KeyDownFunction=null,this.Keybord=new Array(5).fill([]),this.Keybord=this.Keybord.map(t=>new Array(4)),this.GamePad=new Array(5).fill([]),this.GamePad=this.Keybord.map(t=>new Array(4)),this.GamePadSelect=0,this.GamePadButtonSelect=0,this.GamePadBuffer=0,this.GamePadData=[],this.GamePadData["STANDARD PAD"]=[[[{type:"B",index:1}],[{type:"B",index:0}],[{type:"B",index:8}],[{type:"B",index:9},{type:"B",index:2}],[{type:"B",index:12}],[{type:"B",index:13}],[{type:"B",index:14}],[{type:"B",index:15}]],[[{type:"B",index:1}],[{type:"B",index:0}],[{type:"B",index:8}],[{type:"B",index:9}],[{type:"B",index:12}],[{type:"B",index:13}],[{type:"B",index:14}],[{type:"B",index:15}],[{type:"B",index:7}],[{type:"B",index:5}],[{type:"B",index:2}],[{type:"B",index:3}]]],this.GamePadData["HORI PAD 3 TURBO (Vendor: 0f0d Product: 0009)"]=[[[{type:"B",index:2}],[{type:"B",index:1}],[{type:"B",index:8}],[{type:"B",index:9},{type:"B",index:0}],[{type:"P",index:9}],[{type:"N",index:0}],[{type:"N",index:0}],[{type:"N",index:0}]],[[{type:"B",index:2}],[{type:"B",index:1}],[{type:"B",index:8}],[{type:"B",index:9}],[{type:"P",index:9}],[{type:"N",index:0}],[{type:"N",index:0}],[{type:"N",index:0}],[{type:"B",index:7}],[{type:"B",index:5}],[{type:"B",index:0}],[{type:"B",index:3}]]],this.GamePadData["0f0d-0009-HORI PAD 3 TURBO"]=this.GamePadData["HORI PAD 3 TURBO (Vendor: 0f0d Product: 0009)"],this.GamePadData["UNKNOWN PAD"]=this.GamePadData["HORI PAD 3 TURBO (Vendor: 0f0d Product: 0009)"],this.GamePadKeyData=[{index:0,data:1},{index:0,data:2},{index:0,data:4},{index:0,data:8},{index:1,data:1},{index:1,data:4},{index:1,data:8},{index:1,data:2},{index:2,data:1},{index:2,data:2},{index:2,data:4},{index:2,data:8}],this.GamePadPovData=[1,1|2,2,2|4,4,4|8,8,1|8]}JoystickInit(){this.JoystickSEL=0,this.JoystickCLR=0;for(let t=0;t<this.Keybord.length;t++)this.Keybord[t][0]=191,this.Keybord[t][1]=191,this.Keybord[t][2]=191,this.Keybord[t][3]=176;this.GamePadSelect=0,this.GamePadButtonSelect=0,this.GamePadBuffer=0}SetJoystick(t){let e=t&1,s=(t&2)>>1;if(this.JoystickSEL==1&&this.JoystickCLR==0&&e==1&&s==1){this.JoystickSEL=0,this.JoystickCLR=0,this.GamePadSelect=0,this.GamePadButton6&&(this.GamePadButtonSelect=this.GamePadButtonSelect^2),this.GamePadBuffer=176|this.CountryType;return}this.JoystickSEL==0&&this.JoystickCLR==0&&e==1&&s==0&&this.GamePadSelect++,this.JoystickSEL=e,this.JoystickCLR=s;let i=this.MultiTap?this.GamePadSelect-1:0;if(i<5){let a=this.GamePadButtonSelect|this.JoystickSEL;this.GamePadBuffer=this.Keybord[i][a]&this.GamePad[i][a]|this.CountryType}else this.GamePadBuffer=176|this.CountryType}GetJoystick(){return this.GamePadBuffer}UnsetButtonRUN(t){this.Keybord[t][0]|=8}UnsetButtonSELECT(t){this.Keybord[t][0]|=4}UnsetButtonSHOT2(t){this.Keybord[t][0]|=2}UnsetButtonSHOT1(t){this.Keybord[t][0]|=1}UnsetButtonLEFT(t){this.Keybord[t][1]|=8}UnsetButtonDOWN(t){this.Keybord[t][1]|=4}UnsetButtonRIGHT(t){this.Keybord[t][1]|=2}UnsetButtonUP(t){this.Keybord[t][1]|=1}UnsetButtonSHOT6(t){this.Keybord[t][2]|=8}UnsetButtonSHOT5(t){this.Keybord[t][2]|=4}UnsetButtonSHOT4(t){this.Keybord[t][2]|=2}UnsetButtonSHOT3(t){this.Keybord[t][2]|=1}SetButtonRUN(t){this.Keybord[t][0]&=~8}SetButtonSELECT(t){this.Keybord[t][0]&=~4}SetButtonSHOT2(t){this.Keybord[t][0]&=~2}SetButtonSHOT1(t){this.Keybord[t][0]&=~1}SetButtonLEFT(t){this.Keybord[t][1]&=~8}SetButtonDOWN(t){this.Keybord[t][1]&=~4}SetButtonRIGHT(t){this.Keybord[t][1]&=~2}SetButtonUP(t){this.Keybord[t][1]&=~1}SetButtonSHOT6(t){this.Keybord[t][2]&=~8}SetButtonSHOT5(t){this.Keybord[t][2]&=~4}SetButtonSHOT4(t){this.Keybord[t][2]&=~2}SetButtonSHOT3(t){this.Keybord[t][2]&=~1}CheckKeyUpFunction(t){switch(t.keyCode){case u.START.c:this.UnsetButtonRUN(0);break;case u.SELECT.c:this.UnsetButtonSELECT(0);break;case u.A.c:case u.GP_A.c:this.UnsetButtonSHOT2(0);break;case u.B.c:case u.GP_B.c:this.UnsetButtonSHOT1(0);break;case 86:this.UnsetButtonSHOT2(0);break;case 66:this.UnsetButtonSHOT1(0);break;case 37:this.UnsetButtonLEFT(0);break;case 39:this.UnsetButtonRIGHT(0);break;case 40:this.UnsetButtonDOWN(0);break;case 38:this.UnsetButtonUP(0);break;case 71:this.UnsetButtonSHOT6(0);break;case 70:this.UnsetButtonSHOT5(0);break;case 68:this.UnsetButtonSHOT4(0);break;case 67:this.UnsetButtonSHOT3(0);break}}CheckKeyDownFunction(t){switch(t.keyCode){case u.START.c:this.SetButtonRUN(0);break;case u.SELECT.c:this.SetButtonSELECT(0);break;case u.A.c:case u.GP_A.c:this.SetButtonSHOT2(0);break;case u.B.c:case u.GP_B.c:this.SetButtonSHOT1(0);break;case 86:this.SetButtonSHOT2(0);break;case 66:this.SetButtonSHOT1(0);break;case 37:this.SetButtonLEFT(0);break;case 39:this.SetButtonRIGHT(0);break;case 40:this.SetButtonDOWN(0);break;case 38:this.SetButtonUP(0);break;case 71:this.SetButtonSHOT6(0);break;case 70:this.SetButtonSHOT5(0);break;case 68:this.SetButtonSHOT4(0);break;case 67:this.SetButtonSHOT3(0);break}}JoystickEventInit(){this.KeyUpFunction=this.CheckKeyUpFunction.bind(this),this.KeyDownFunction=this.CheckKeyDownFunction.bind(this),this.MainCanvas.addEventListener("keyup",this.KeyUpFunction,!0),this.MainCanvas.addEventListener("keydown",this.KeyDownFunction,!0)}JoystickEventRelease(){this.MainCanvas.removeEventListener("keyup",this.KeyUpFunction,!0),this.MainCanvas.removeEventListener("keydown",this.KeyDownFunction,!0)}CheckGamePad(){for(let e=0;e<this.GamePad.length;e++)this.GamePad[e][0]=191,this.GamePad[e][1]=191,this.GamePad[e][2]=191,this.GamePad[e][3]=176;if(typeof navigator.getGamepads=="undefined")return;let t=navigator.getGamepads();for(let e=0;e<5;e++){let s=t[e];if(typeof s!="undefined"&&s!==null){let i;s.mapping==="standard"?i=this.GamePadData["STANDARD PAD"]:(i=this.GamePadData[s.id],typeof i=="undefined"&&(i=this.GamePadData["UNKNOWN PAD"])),i=this.GamePadButton6?i[1]:i[0];let a=0;for(let h of i){for(let r of h)switch(r.type){case"B":s.buttons[r.index].pressed&&(this.GamePad[e][this.GamePadKeyData[a].index]&=~this.GamePadKeyData[a].data);break;case"A-":s.axes[r.index]<-.5&&(this.GamePad[e][this.GamePadKeyData[a].index]&=~this.GamePadKeyData[a].data);break;case"A+":s.axes[r.index]>.5&&(this.GamePad[e][this.GamePadKeyData[a].index]&=~this.GamePadKeyData[a].data);break;case"AB":s.axes[r.index]>-.75&&(this.GamePad[e][this.GamePadKeyData[a].index]&=~this.GamePadKeyData[a].data);break;case"P":let n=(s.axes[r.index]+1)*7/2+.5|0;this.GamePad[e][1]&=~(n<=7?this.GamePadPovData[n]:0);break}a++}}}}};
//# sourceMappingURL=pce-QQSEYHLV.js.map