Add interrupt handling with vector constants and documentation#122
Add interrupt handling with vector constants and documentation#122
Conversation
|
I ran into Klaus2m5/6502_65C02_functional_tests#23 while testing. Commented out that part. It seems to be an issue with the test code. |
|
Do you know what should happen when both interrupts (or one or two interrupts plus a reset) happen at once? How accurate does this emulator need to be in this area? |
|
Yeah, that's the tricky bit. Essentially, that's the test I commented out. When BRK (software), IRQ, and NMI are triggered simultaneously, the behavior depends on instruction-cycle-level interrupt sampling, which according to the issue isn't even fully documented for real hardware (there's actually a hardware bug on real NMOS 6502 where concurrent BRK+NMI can corrupt the B flag). For now we skip that specific concurrent BRK+IRQ+NMI test, but the Klaus interrupt test suite validates all other interrupt handling: individual BRK/IRQ/NMI, interrupt nesting, NMI priority, I flag masking for IRQ, edge detection, etc. |
fe04447 to
7dbdede
Compare
e695763 to
2a80766
Compare
|
I made a bunch of changes. Should be ready for another round of reviews. 😅 |
|
Sorry for the delay around Christmas and New Year, I'll get on it hopefully in the coming days! |
|
There is no rush at all. |
a1cd8cd to
fdd93e1
Compare
removed that note, thanks @omarandlorraine. |
Implements hardware interrupt support following the W65C02S datasheet: Interrupt handling: - Add nmi_pending() and irq_pending() to Bus trait - NMI: edge-triggered (falling edge detection) - IRQ: level-triggered, maskable by I flag - service_interrupt() pushes PC/status, sets I flag, jumps to vector Wait states: - Replace `halted: bool` with WaitState enum (Running, WaitingForInterrupt, WaitingForReset) - WAI instruction waits for interrupt, resumes on IRQ or NMI - STP instruction waits for reset Helper methods: - Add push_address() for pushing 16-bit addresses to stack - Add set_word() to Bus trait for writing 16-bit values Testing: - Integrate Klaus2m5 interrupt test suite - Add unit tests for IRQ, NMI, and WAI behavior - Concurrent BRK+IRQ+NMI test disabled (hardware timing edge case) References: - W65C02S Datasheet, Section 3.4 (IRQB) and 3.6 (NMIB) - Klaus2m5/6502_65C02_functional_tests Closes #64
631ff37 to
4135b00
Compare
This is a follow-up to #121 and implements #64.
I tried to follow the instructions from the W65C02S Datasheet, Section 3.4 (IRQB) and 3.6 (NMIB), which I referenced in a few places.
Basically:
WaitStateenum (Running,WaitingForInterrupt,WaitingForReset) as suggested by the awesome @omarandlorraine