Skip to content

Commit

Permalink
Better irq timing
Browse files Browse the repository at this point in the history
  • Loading branch information
drhelius committed Sep 11, 2024
1 parent 39050eb commit 8e49f07
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
13 changes: 12 additions & 1 deletion src/huc6280.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ void HuC6280::Reset()
m_clock = 0;
m_clock_cycles = 0;
m_last_instruction_cycles = 0;
m_checking_irqs = false;
m_irq1_asserted = false;
m_irq2_asserted = false;
m_nmi_requested = false;
Expand All @@ -102,7 +103,7 @@ void HuC6280::Reset()
ClearDisassemblerCallStack();
}

unsigned int HuC6280::Tick()
unsigned int HuC6280::TickOPCode()
{
m_memory_breakpoint_hit = false;
m_skip_flag_transfer_clear = false;
Expand All @@ -126,6 +127,14 @@ unsigned int HuC6280::Tick()

m_last_instruction_cycles = m_cycles;

m_checking_irqs = true;

return m_cycles;
}

unsigned int HuC6280::TickIRQ()
{
m_cycles = 0;
bool irq_pending = false;
u16 irq_pending_low = 0;
u16 irq_pending_high = 0;
Expand Down Expand Up @@ -194,6 +203,8 @@ unsigned int HuC6280::Tick()
SetFlag(FLAG_INTERRUPT);
}

m_checking_irqs = false;

return m_cycles;
}

Expand Down
6 changes: 4 additions & 2 deletions src/huc6280.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ class HuC6280
void Init(Memory* memory, HuC6270* huc6270);
void Reset();
bool Clock();
unsigned int Tick();
unsigned int TickOPCode();
unsigned int TickIRQ();
void AssertIRQ1(bool asserted);
void AssertIRQ2(bool asserted);
void RequestNMI();
Expand Down Expand Up @@ -134,8 +135,9 @@ class HuC6280
u8 m_zn_flags_lut[256];
unsigned int m_cycles;
unsigned int m_clock;
unsigned int m_clock_cycles;
int m_clock_cycles;
unsigned int m_last_instruction_cycles;
bool m_checking_irqs;
bool m_irq1_asserted;
bool m_irq2_asserted;
bool m_nmi_requested;
Expand Down
11 changes: 8 additions & 3 deletions src/huc6280_inline.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,14 @@ inline bool HuC6280::Clock()

if (m_clock % k_huc6280_speed_divisor[m_speed] == 0)
{
if (m_clock_cycles == 0)
m_clock_cycles = Tick();
if (m_clock_cycles <= 0)
{
if (m_checking_irqs)
m_clock_cycles += TickIRQ();
else
m_clock_cycles += TickOPCode();
}

m_clock_cycles--;
instruction_completed = (m_clock_cycles == 0);
}
Expand All @@ -44,7 +50,6 @@ inline bool HuC6280::Clock()

inline void HuC6280::AssertIRQ1(bool asserted)
{
// Debug("IRQ1 asserted: %s", asserted ? "true" : "false");
m_irq1_asserted = asserted;
if (m_irq1_asserted)
SetBit(m_interrupt_request_register, 1);
Expand Down

0 comments on commit 8e49f07

Please sign in to comment.