public void frame(int throttle, int frameSkip, int stage) { fclock = z80._clock.m + 17556; //Echo every 100 frames // if(stage % 100 == 0) Echo("Stepping Gameboy (PC = " + z80.r.pc + ")"); //var brk = document.getElementById('breakpoint').value; if ((stage % frameSkip) == 0) { gPU.drawNow(); } currentTime = System.DateTime.Now.Ticks; mMU._timer [0] = (int)((currentTime - startTime) / 610.3515625); switch (mMU._timer[3] & 0x3) { case 0: mMU._timer [1] += (int)(((currentTime - lastTime) / 610.3515625) / 1024); break; case 1: mMU._timer [1] += (int)(((currentTime - lastTime) / 610.3515625) / 16); break; case 2: mMU._timer [1] += (int)(((currentTime - lastTime) / 610.3515625) / 64); break; case 3: mMU._timer [1] += (int)(((currentTime - lastTime) / 610.3515625) / 256); break; } if (mMU._timer [1] > 255) { mMU._if |= 0x04; lastTime = currentTime; } if (currentTime - hblankTime > 283813) //handle hblank { mMU._if |= 0x01; hblankTime = currentTime; vblanks++; // Echo("vblank " + vblanks); } lastTime = currentTime; for (; z80._clock.m < fclock && throttle > 0; throttle--) { //if(z80._halt!=0) z80.r.m=1; //else //{ // z80.r.r = (z80.r.r+1) & 127; z80._map[mMU.rb(z80.r.pc++)](); z80.r.pc &= 65535; //} if (z80.r.ime != 0 && mMU._ie != 0 && mMU._if != 0) { z80._halt = 0; z80.r.ime = 0; ifired = mMU._ie & mMU._if; if ((ifired & 1) != 0) { mMU._if &= 0xFE; z80.RST40(); } else if ((ifired & 2) != 0) { mMU._if &= 0xFD; z80.RST48(); } else if ((ifired & 4) != 0) { mMU._if &= 0xFB; z80.RST50(); } else if ((ifired & 8) != 0) { mMU._if &= 0xF7; z80.RST58(); } else if ((ifired & 16) != 0) { mMU._if &= 0xEF; z80.RST60(); } else { z80.r.ime = 1; } } z80._clock.m += z80.r.m; gPU.checkline(); // tIMER.inc(); } }