Skip to content

Commit

Permalink
cpu: handle all interrupts, added stubs for invalid cop1/3 opcodes
Browse files Browse the repository at this point in the history
  • Loading branch information
JaCzekanski committed Jul 3, 2018
1 parent 5ec994d commit e5a52a9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/cpu/cpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ bool CPU::executeInstructions(int count) {
}

void CPU::checkForInterrupts() {
if ((cop0.cause.interruptPending & 4) && cop0.status.interruptEnable && (cop0.status.interruptMask & 4)) {
if ((cop0.cause.interruptPending & cop0.status.interruptMask) && cop0.status.interruptEnable) {
instructions::exception(this, COP0::CAUSE::Exception::interrupt);
}
}
Expand Down
22 changes: 14 additions & 8 deletions src/cpu/instructions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ std::array<PrimaryInstruction, 64> OpcodeTable = {{
{15, op_lui},

{16, op_cop0},
{17, notImplemented},
{17, invalid_cop},
{18, op_cop2},
{19, notImplemented},
{19, invalid_cop},
{20, invalid},
{21, invalid},
{22, invalid},
Expand Down Expand Up @@ -62,19 +62,19 @@ std::array<PrimaryInstruction, 64> OpcodeTable = {{
{46, op_swr},
{47, invalid},

{48, notImplemented},
{49, notImplemented},
{48, invalid_cop},
{49, invalid_cop},
{50, op_lwc2},
{51, notImplemented},
{51, invalid_cop},
{52, invalid},
{53, invalid},
{54, invalid},
{55, invalid},

{56, notImplemented},
{57, notImplemented},
{56, invalid_cop},
{57, invalid_cop},
{58, op_swc2},
{59, notImplemented},
{59, invalid_cop},
{60, invalid},
{61, invalid},
{62, invalid},
Expand Down Expand Up @@ -808,6 +808,12 @@ void op_swc2(CPU *cpu, Opcode i) {
cpu->sys->writeMemory32(addr, gteRead);
}

// Invalid coprocessor stub
void invalid_cop(CPU *cpu, Opcode i) {
uint32_t addr = cpu->reg[i.rs] + i.offset;
exception(cpu, COP0::CAUSE::Exception::busErrorData);
}

// BREAKPOINT
void op_breakpoint(CPU *cpu, Opcode i) {
cpu->sys->state = System::State::halted;
Expand Down
3 changes: 2 additions & 1 deletion src/cpu/instructions.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once
#include <cstdint>
#include <array>
#include <cstdint>
#include "cpu.h"
#include "opcode.h"

Expand Down Expand Up @@ -81,6 +81,7 @@ void op_sw(CPU* cpu, Opcode i);
void op_swr(CPU* cpu, Opcode i);
void op_lwc2(CPU* cpu, Opcode i);
void op_swc2(CPU* cpu, Opcode i);
void invalid_cop(CPU* cpu, Opcode i);
void op_breakpoint(CPU* cpu, Opcode i);

extern std::array<PrimaryInstruction, 64> OpcodeTable;
Expand Down

0 comments on commit e5a52a9

Please sign in to comment.