diff --git a/InstructionSets/M68k/Implementation/ExecutorImplementation.hpp b/InstructionSets/M68k/Implementation/ExecutorImplementation.hpp index 6e6e21b57..1d129a354 100644 --- a/InstructionSets/M68k/Implementation/ExecutorImplementation.hpp +++ b/InstructionSets/M68k/Implementation/ExecutorImplementation.hpp @@ -53,7 +53,7 @@ void Executor::signal_bus_error(FunctionCode code, uint32_t a template void Executor::set_interrupt_level(int level) { state_.interrupt_input_ = level; - state_.stopped &= state_.interrupt_input_ <= state_.status.interrupt_level; + state_.stopped &= !state_.status.would_accept_interrupt(level); } template @@ -324,7 +324,7 @@ template void Executor::State::run(int &count) { while(count--) { // Check for a new interrupt. - if(interrupt_input > status.interrupt_level) { + if(status.would_accept_interrupt(interrupt_input)) { const int vector = bus_handler_.acknowlege_interrupt(interrupt_input); if(vector >= 0) { raise_exception(vector); diff --git a/InstructionSets/M68k/Status.hpp b/InstructionSets/M68k/Status.hpp index 7fe42b5f1..583d4fe3b 100644 --- a/InstructionSets/M68k/Status.hpp +++ b/InstructionSets/M68k/Status.hpp @@ -113,7 +113,7 @@ struct Status { } /// Evaluates @c condition. - bool evaluate_condition(Condition condition) { + constexpr bool evaluate_condition(Condition condition) const { switch(condition) { default: case Condition::True: return true; @@ -138,6 +138,13 @@ struct Status { return !zero_result || (negative_flag && !overflow_flag) || (!negative_flag && overflow_flag); } } + + /// @returns @c true if an interrupt at level @c level should be accepted; @c false otherwise. + constexpr bool would_accept_interrupt(int level) const { + // TODO: is level seven really non-maskable? If so then what mechanism prevents + // rapid stack overflow upon a level-seven interrupt? + return level > interrupt_level; + } }; } diff --git a/Processors/68000Mk2/Implementation/68000Mk2Implementation.hpp b/Processors/68000Mk2/Implementation/68000Mk2Implementation.hpp index 9ebf9e40a..ca64c3feb 100644 --- a/Processors/68000Mk2/Implementation/68000Mk2Implementation.hpp +++ b/Processors/68000Mk2/Implementation/68000Mk2Implementation.hpp @@ -354,7 +354,7 @@ void Processor status_.interrupt_level) { + if(status_.would_accept_interrupt(captured_interrupt_level_)) { MoveToStateSpecific(DoInterrupt); } MoveToStateSpecific(STOP); @@ -596,7 +596,7 @@ void Processor status_.interrupt_level) { + if(status_.would_accept_interrupt(captured_interrupt_level_)) { MoveToStateSpecific(DoInterrupt); }