////////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////////// public Z80Cpu(GameBoyTest.MicroTimer.MicroTimer timer) { m_timer = timer; //new GameBoyTest.MicroTimer.MicroTimer();// new System.Timers.Timer(); m_timer.Interval = (long)(GAMEBOY_DEFAULT_CLOCK_SPEED_MS * 1000); //m_timer.AutoReset = false; //m_timer.Elapsed += new ElapsedEventHandler(OnCpuTick); m_timer.MicroTimerElapsed += new GameBoyTest.MicroTimer.MicroTimer.MicroTimerElapsedEventHandler(OnCpuTick); m_decoder = new Z80InstructionDecoder(); m_interruptsMgr = new InterruptsMgr(); m_cpuTimer = new CpuTimer(); m_curInstructionNbCycles = 0; m_curInstructionCurCycle = 0; m_curInstruction = null; m_clockCnt = 0; m_CpuTick = 0; m_controlTimer = new System.Timers.Timer(); m_controlTimer.Interval = 100; m_controlTimer.Elapsed += new ElapsedEventHandler(ControlTimerElapsed); m_controlTimer.Enabled = true; // Enable it m_ImeFlag = false; m_stopWatch = new Stopwatch(); m_timer.Start(); }
public Z80Instruction GetInstructionAt(ushort adr, bool bIsCB) { ushort myPC = adr; if (bIsCB) { //myPC++; byte opcode = GameBoy.Ram.ReadByteAt(myPC); Z80Instruction inst = m_BCInstruction[opcode]; if (inst == null) { int u = 0; u++; } return(inst); } else { byte opcode = GameBoy.Ram.ReadByteAt(myPC); Z80Instruction inst = m_instructions[opcode]; if (inst == null) { int u = 0; u++; } return(inst); } }
////////////////////////////////////////////////////////////////////// // //@return true / if instruction was NOP // ////////////////////////////////////////////////////////////////////// public bool RunOneInstruction(bool bDebugEnabled) { if (m_started || m_runOnce || m_runToStepOver) { bool bCanRun = bDebugEnabled ? DebugFunctions.Z80Form().CanStep() : true; if (bCanRun && (m_curInstruction == null || m_curInstructionCurCycle >= m_curInstructionNbCycles)) { if (m_interruptsMgr.Update()) { return(true); } else { byte opcode = 0; opcode = GameBoy.Ram.ReadByteAt(m_PC); m_curInstruction = m_decoder.GetNextInstruction(); if (m_curInstruction == null) { ThrowNullInstructionException(opcode, m_PC, bDebugEnabled); return(true); } if (m_runOnce) { m_runOnce = false; m_curInstructionCurCycle = m_curInstructionNbCycles; } if (bDebugEnabled) { DebugFunctions.CallStackForm().AddToCallstack(); } ushort oldPc = m_PC; m_PC = m_curInstruction.Exec(m_PC); m_curInstructionNbCycles = m_curInstruction.GetCurNbCycles(oldPc); m_curInstructionCurCycle = 4; GameBoy.Cpu.IncInstructionNumber(); if (m_runToStepOver && opcode == 0xC9) { m_runToStepOver = false; Stop(); } } } else { if (!m_halted) { //on avance 4 cycles par 4 cycles car le timer est a 1Mhz, donc x4 pour les 4Mhz de la GB m_curInstructionCurCycle += 4; } } return(true); } return(false); }
public Z80Instruction GetNextInstruction() { if (GameBoy.Ram.ReadByteAt(GameBoy.Cpu.PC) == 0xCB) { GameBoy.Cpu.PC++; byte opcode = GameBoy.Ram.ReadByteAt(GameBoy.Cpu.PC); Z80Instruction inst = m_BCInstruction[opcode]; return(inst); } else { byte opcode = GameBoy.Ram.ReadByteAt(GameBoy.Cpu.PC); Z80Instruction inst = m_instructions[opcode]; return(inst); } }
private void RegisterInstruction(Z80Instruction inst) { byte[] opcodes = inst.opCodes; if (!inst.isBC) { for (byte i = 0; i < opcodes.Length; i++) { DebugFunctions.ASSERT(m_instructions[opcodes[i]] == null, "Overwriting instruction " + String.Format("{0:x2}", opcodes[i]) + " by " + inst.ToString()); m_instructions[opcodes[i]] = inst; } } else { for (byte i = 0; i < opcodes.Length; i++) { DebugFunctions.ASSERT(m_BCInstruction[opcodes[i]] == null, "Overwriting instruction !"); m_BCInstruction[opcodes[i]] = inst; } } }