Example #1
0
u8 Processor::Tick()
{
    m_iCurrentClockCycles = 0;

    if (m_bHalt)
    {
        m_iCurrentClockCycles += (m_bCGBSpeed ? 2 : 4);

        if (m_iUnhaltCycles > 0)
        {
            m_iUnhaltCycles -= m_iCurrentClockCycles;

            if (m_iUnhaltCycles <= 0)
            {
                m_iUnhaltCycles = 0;
                m_bHalt = false;
            }
        }

        if (m_bHalt && (InterruptPending() != None_Interrupt) && (m_iUnhaltCycles == 0))
        {
            m_iUnhaltCycles = (m_bCGBSpeed ? 6 : 12);
        }
    }

    if (!m_bHalt)
    {
        ServeInterrupt(InterruptPending());
        ExecuteOPCode(FetchOPCode());
    }

    UpdateDelayedInterrupts();
    UpdateTimers();
    UpdateSerial();

    if (m_iIMECycles > 0)
    {
        m_iIMECycles -= m_iCurrentClockCycles;

        if (m_iIMECycles <= 0)
        {
            m_iIMECycles = 0;
            m_bIME = true;
        }
    }

    return m_iCurrentClockCycles;
}
Example #2
0
u8 Processor::Tick()
{
    m_iCurrentClockCycles = 0;

    if (m_iAccurateOPCodeState == 0 && m_bHalt)
    {
        m_iCurrentClockCycles += AdjustedCycles(4);

        if (m_iUnhaltCycles > 0)
        {
            m_iUnhaltCycles -= m_iCurrentClockCycles;

            if (m_iUnhaltCycles <= 0)
            {
                m_iUnhaltCycles = 0;
                m_bHalt = false;
            }
        }

        if (m_bHalt && (InterruptPending() != None_Interrupt) && (m_iUnhaltCycles == 0))
        {
            m_iUnhaltCycles = AdjustedCycles(12);
        }
    }

    if (!m_bHalt)
    {
        if (m_iAccurateOPCodeState == 0)
            ServeInterrupt(InterruptPending());

        if (m_bDuringBootROM)
        {
            u16 pc_before = PC.GetValue();
            ExecuteOPCode(FetchOPCode());
            u16 pc_after = PC.GetValue();
            if ((pc_before == 0xFE) && (pc_after == 0x100))
            {
                m_bEndOfBootROM = true;
            }
        }
        else
            ExecuteOPCode(FetchOPCode());
    }

    UpdateDelayedInterrupts();
    UpdateTimers();
    UpdateSerial();

    if (m_iAccurateOPCodeState == 0 && m_iIMECycles > 0)
    {
        m_iIMECycles -= m_iCurrentClockCycles;

        if (m_iIMECycles <= 0)
        {
            m_iIMECycles = 0;
            m_bIME = true;
        }
    }

    return m_iCurrentClockCycles;
}