public void InterruptServiceRoutine() { byte bIF = Memory.DirectRead(IF); byte bIE = Memory.DirectRead(IE); int f = IRQLookup[bIF & bIE & 0x1F]; //-1 means no interrupt if (IME) { if (f != -1) { //2 Internal delays Board.AdvanceSystemTime(); //4 Board.AdvanceSystemTime(); //8 //PUSH PC Board.AdvanceSystemTime(); //12 Memory.Write((byte)(Registers.PC >> 8), --Registers.SP); Board.AdvanceSystemTime(); //16 Memory.Write((byte)Registers.PC, --Registers.SP); //SERVE bIF = ServeIRQ(f, bIF); Board.AdvanceSystemTime(); //20 Memory.DirectWrite(bIF, IF); if (GetCPU().Halt) { Board.AdvanceSystemTime(); //24 GetCPU().Halt = false; } SetIME(false); } } else { if (f != -1) { if (GetCPU().Halt) { Board.AdvanceSystemTime(); //4 GetCPU().Halt = false; GetCPU().DoubleInstructionExecutionBug = DoubleInstructionEnable; DoubleInstructionEnable = true; } } else { DoubleInstructionEnable = false; } } if (Schedule) { IME = true; Schedule = false; } }
public void WriteByte(long address, byte b) { mmu.Write(b, (ushort)address); }