using System; using System.Collections.Generic; using System.Text; using dotnes.Core; namespace dotnes { namespace Nes { struct Constants { public const float ClockDivider = 12; public const int CyclesPerScanline = (int)(1364 / ClockDivider); } } class Machine : IMachine { private CPU cpu; private Cartridge image; bool vblanking; private int currentCycles; public Machine() { cpu = new CPU(this); vblanking = false; currentCycles = Nes.Constants.CyclesPerScanline; } void LoadImage(Cartridge img) { image = img; } void DoFrame() { // do each visible scanline (hblank), vblank, and then non-visible for (int line = 0; line < 262; line++) { switch (line) { case 241: { vblanking = true; currentCycles -= cpu.Execute(7); cpu.Interrupt(InterruptType.NMI); break; } case 261: vblanking = false; break; } if (currentCycles > 0) currentCycles -= cpu.Execute(currentCycles); currentCycles += Nes.Constants.CyclesPerScanline; } } //-------------------------------------------------------------------- // IMachine implementation //-------------------------------------------------------------------- byte IMachine.Read(UInt16 address) { return 0; } void IMachine.Write(UInt16 address, byte value) { } void IMachine.BadOp(byte op) { } InterruptType IMachine.CheckInterrupt() { return InterruptType.None; } void IMachine.Debug() { } } }