From 496f63acdc6b7183562ed5dc14efa2b070dd201b Mon Sep 17 00:00:00 2001 From: infiton Date: Wed, 13 Jul 2022 12:27:10 -0400 Subject: [PATCH] allow for interrupts --- ext/ruby6502/fake6502.c | 10 ++++++---- ext/ruby6502/fake6502.h | 2 ++ ext/ruby6502/ruby6502.c | 14 ++++++++++++++ 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/ext/ruby6502/fake6502.c b/ext/ruby6502/fake6502.c index dd0170e..b2bea6a 100644 --- a/ext/ruby6502/fake6502.c +++ b/ext/ruby6502/fake6502.c @@ -960,10 +960,12 @@ void nmi6502() { } void irq6502() { - push16(pc); - push8(status); - status |= FLAG_INTERRUPT; - pc = (uint16_t)read6502(0xFFFE) | ((uint16_t)read6502(0xFFFF) << 8); + if (! (status & FLAG_INTERRUPT) ) { + push16(pc); + push8(status); + status |= FLAG_INTERRUPT; + pc = (uint16_t)read6502(0xFFFE) | ((uint16_t)read6502(0xFFFF) << 8); + } } uint8_t callexternal = 0; diff --git a/ext/ruby6502/fake6502.h b/ext/ruby6502/fake6502.h index 1c4c8cd..54a1c19 100644 --- a/ext/ruby6502/fake6502.h +++ b/ext/ruby6502/fake6502.h @@ -4,6 +4,8 @@ void reset6502(); void step6502(); void exec6502(uint32_t tickcount); +void nmi6502(); +void irq6502(); void hookexternal(void *funcptr); uint16_t getPC(); diff --git a/ext/ruby6502/ruby6502.c b/ext/ruby6502/ruby6502.c index 85eeb6c..6127732 100644 --- a/ext/ruby6502/ruby6502.c +++ b/ext/ruby6502/ruby6502.c @@ -46,6 +46,18 @@ static VALUE reset(VALUE self) return Qtrue; } +static VALUE interrupt_request(VALUE self) +{ + irq6502(); + return Qtrue; +} + +static VALUE non_maskable_interrupt(VALUE self) +{ + nmi6502(); + return Qtrue; +} + static VALUE step(VALUE self) { step6502(); @@ -117,6 +129,8 @@ void Init_ruby6502() rb_define_singleton_method(mRuby6502, "hooks?", get_has_hooks, 0); rb_define_singleton_method(mRuby6502, "reset", reset, 0); + rb_define_singleton_method(mRuby6502, "interrupt_request", interrupt_request, 0); + rb_define_singleton_method(mRuby6502, "non_maskable_interrupt", non_maskable_interrupt, 0); rb_define_singleton_method(mRuby6502, "step", step, 0); rb_define_singleton_method(mRuby6502, "exec", exec, 1);