Skip to content

Commit

Permalink
allow for interrupts
Browse files Browse the repository at this point in the history
  • Loading branch information
infiton committed Jul 13, 2022
1 parent d8f7d7f commit 496f63a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
10 changes: 6 additions & 4 deletions ext/ruby6502/fake6502.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions ext/ruby6502/fake6502.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
void reset6502();
void step6502();
void exec6502(uint32_t tickcount);
void nmi6502();
void irq6502();
void hookexternal(void *funcptr);

uint16_t getPC();
Expand Down
14 changes: 14 additions & 0 deletions ext/ruby6502/ruby6502.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 496f63a

Please sign in to comment.