Skip to content

Commit

Permalink
Implement HLT/KIL Opcodes (#399)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChessMan14 authored May 11, 2024
1 parent 5448b15 commit eab01be
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
32 changes: 20 additions & 12 deletions src/core/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,11 @@ void cpu_exe_op(BYTE nidx) {
nes[nidx].c.cpu.base_opcode_cycles = table_opcode_cycles[(BYTE)nes[nidx].c.cpu.opcode];
mod_cycles_op(+=, nes[nidx].c.cpu.base_opcode_cycles);

//Jam the cpu if necessary
if (nes[nidx].c.cpu.jammed) {
return;
}

// ... e la eseguo
switch (nes[nidx].c.cpu.opcode) {

Expand Down Expand Up @@ -957,24 +962,26 @@ void cpu_exe_op(BYTE nidx) {
case 0xBB: ABX(RD_OP, _CYW(LAS), nes[nidx].c.cpu.YR) break; // LAS $ABS,Y
case 0x9B: ABX(WR_OP, XAS, nes[nidx].c.cpu.YR) break; // XAS $ABS,Y

case 0x02: // JAM
case 0x12: // JAM
case 0x22: // JAM
case 0x32: // JAM
case 0x42: // JAM
case 0x52: // JAM
case 0x62: // JAM
case 0x72: // JAM
case 0x92: // JAM
case 0xB2: // JAM
case 0xD2: // JAM
case 0xF2: // JAM
//KIL/HLT instructions. Set the cpu to be jammed
case 0x02:
case 0x12:
case 0x22:
case 0x32:
case 0x42:
case 0x52:
case 0x62:
case 0x72:
case 0x92:
case 0xB2:
case 0xD2:
case 0xF2:
default:
if (!info.no_rom && !info.first_illegal_opcode) {
log_warning(uL("cpu;alert PC = 0x%04X, CODEOP = 0x%02X"), (nes[nidx].c.cpu.PC.w - 1), nes[nidx].c.cpu.opcode);
gui_overlay_info_append_msg_precompiled(4, NULL);
info.first_illegal_opcode = TRUE;
}
nes[nidx].c.cpu.jammed = 1;
nes[nidx].c.cpu.cycles = 0;
break;
case OP_NMI: IMP(RD_OP, NMI) break; // NMI
Expand Down Expand Up @@ -1061,6 +1068,7 @@ void cpu_turn_on(BYTE nidx) {
nes[nidx].c.cpu.opcode_cycle = 0;
nes[nidx].c.cpu.double_wr = 0;
nes[nidx].c.cpu.double_rd = 0;
nes[nidx].c.cpu.jammed = 0;
}
memset(&nes[nidx].c.nmi, 0x00, sizeof(_nmi));
memset(&nes[nidx].c.irq, 0x00, sizeof(_irq));
Expand Down
2 changes: 2 additions & 0 deletions src/core/cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ typedef struct _cpu {
WORD base_opcode_cycles;
// buffer di lettura
BYTE openbus;
//Set to true by KIL/HLT instruction
BYTE jammed;
} _cpu;
typedef struct _irq {
BYTE high;
Expand Down

0 comments on commit eab01be

Please sign in to comment.