snes: fix bugs in SGB CDL
This commit is contained in:
parent
cafe1581ac
commit
d796af3a9d
|
@ -3,13 +3,18 @@
|
||||||
#include "table.cpp"
|
#include "table.cpp"
|
||||||
#include "disassembler.cpp"
|
#include "disassembler.cpp"
|
||||||
|
|
||||||
|
uint8 CPU::op_fetch() {
|
||||||
|
cdlInfo.currFlags = eCDLog_Flags_ExecOperand;
|
||||||
|
uint8 opcode = op_read(r[PC]++);
|
||||||
|
cdlInfo.currFlags = eCDLog_Flags_CPUData;
|
||||||
|
return opcode;
|
||||||
|
}
|
||||||
|
|
||||||
void CPU::op_xx() {
|
void CPU::op_xx() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void CPU::op_cb() {
|
void CPU::op_cb() {
|
||||||
cdlInfo.currFlags = eCDLog_Flags_ExecOperand;
|
uint8 opcode = op_fetch();
|
||||||
uint8 opcode = op_read(r[PC]++);
|
|
||||||
cdlInfo.currFlags = eCDLog_Flags_CPUData;
|
|
||||||
(this->*opcode_table_cb[opcode])();
|
(this->*opcode_table_cb[opcode])();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +25,7 @@ template<unsigned x, unsigned y> void CPU::op_ld_r_r() {
|
||||||
}
|
}
|
||||||
|
|
||||||
template<unsigned x> void CPU::op_ld_r_n() {
|
template<unsigned x> void CPU::op_ld_r_n() {
|
||||||
r[x] = op_read(r[PC]++);
|
r[x] = op_fetch();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<unsigned x> void CPU::op_ld_r_hl() {
|
template<unsigned x> void CPU::op_ld_r_hl() {
|
||||||
|
@ -32,7 +37,7 @@ template<unsigned x> void CPU::op_ld_hl_r() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void CPU::op_ld_hl_n() {
|
void CPU::op_ld_hl_n() {
|
||||||
op_write(r[HL], op_read(r[PC]++));
|
op_write(r[HL], op_fetch());
|
||||||
}
|
}
|
||||||
|
|
||||||
template<unsigned x> void CPU::op_ld_a_rr() {
|
template<unsigned x> void CPU::op_ld_a_rr() {
|
||||||
|
@ -40,8 +45,8 @@ template<unsigned x> void CPU::op_ld_a_rr() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void CPU::op_ld_a_nn() {
|
void CPU::op_ld_a_nn() {
|
||||||
uint8 lo = op_read(r[PC]++);
|
uint8 lo = op_fetch();
|
||||||
uint8 hi = op_read(r[PC]++);
|
uint8 hi = op_fetch();
|
||||||
r[A] = op_read((hi << 8) | (lo << 0));
|
r[A] = op_read((hi << 8) | (lo << 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,17 +55,17 @@ template<unsigned x> void CPU::op_ld_rr_a() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void CPU::op_ld_nn_a() {
|
void CPU::op_ld_nn_a() {
|
||||||
uint8 lo = op_read(r[PC]++);
|
uint8 lo = op_fetch();
|
||||||
uint8 hi = op_read(r[PC]++);
|
uint8 hi = op_fetch();
|
||||||
op_write((hi << 8) | (lo << 0), r[A]);
|
op_write((hi << 8) | (lo << 0), r[A]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CPU::op_ld_a_ffn() {
|
void CPU::op_ld_a_ffn() {
|
||||||
r[A] = op_read(0xff00 + op_read(r[PC]++));
|
r[A] = op_read(0xff00 + op_fetch());
|
||||||
}
|
}
|
||||||
|
|
||||||
void CPU::op_ld_ffn_a() {
|
void CPU::op_ld_ffn_a() {
|
||||||
op_write(0xff00 + op_read(r[PC]++), r[A]);
|
op_write(0xff00 + op_fetch(), r[A]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CPU::op_ld_a_ffc() {
|
void CPU::op_ld_a_ffc() {
|
||||||
|
@ -94,13 +99,13 @@ void CPU::op_ldd_a_hl() {
|
||||||
//16-bit load commands
|
//16-bit load commands
|
||||||
|
|
||||||
template<unsigned x> void CPU::op_ld_rr_nn() {
|
template<unsigned x> void CPU::op_ld_rr_nn() {
|
||||||
r[x] = op_read(r[PC]++) << 0;
|
r[x] = op_fetch() << 0;
|
||||||
r[x] |= op_read(r[PC]++) << 8;
|
r[x] |= op_fetch() << 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CPU::op_ld_nn_sp() {
|
void CPU::op_ld_nn_sp() {
|
||||||
uint16 addr = op_read(r[PC]++) << 0;
|
uint16 addr = op_fetch() << 0;
|
||||||
addr |= op_read(r[PC]++) << 8;
|
addr |= op_fetch() << 8;
|
||||||
op_write(addr + 0, r[SP] >> 0);
|
op_write(addr + 0, r[SP] >> 0);
|
||||||
op_write(addr + 1, r[SP] >> 8);
|
op_write(addr + 1, r[SP] >> 8);
|
||||||
}
|
}
|
||||||
|
@ -134,7 +139,7 @@ void CPU::opi_add_a(uint8 x) {
|
||||||
}
|
}
|
||||||
|
|
||||||
template<unsigned x> void CPU::op_add_a_r() { opi_add_a(r[x]); }
|
template<unsigned x> void CPU::op_add_a_r() { opi_add_a(r[x]); }
|
||||||
void CPU::op_add_a_n() { opi_add_a(op_read(r[PC]++)); }
|
void CPU::op_add_a_n() { opi_add_a(op_fetch()); }
|
||||||
void CPU::op_add_a_hl() { opi_add_a(op_read(r[HL])); }
|
void CPU::op_add_a_hl() { opi_add_a(op_read(r[HL])); }
|
||||||
|
|
||||||
void CPU::opi_adc_a(uint8 x) {
|
void CPU::opi_adc_a(uint8 x) {
|
||||||
|
@ -148,7 +153,7 @@ void CPU::opi_adc_a(uint8 x) {
|
||||||
}
|
}
|
||||||
|
|
||||||
template<unsigned x> void CPU::op_adc_a_r() { opi_adc_a(r[x]); }
|
template<unsigned x> void CPU::op_adc_a_r() { opi_adc_a(r[x]); }
|
||||||
void CPU::op_adc_a_n() { opi_adc_a(op_read(r[PC]++)); }
|
void CPU::op_adc_a_n() { opi_adc_a(op_fetch()); }
|
||||||
void CPU::op_adc_a_hl() { opi_adc_a(op_read(r[HL])); }
|
void CPU::op_adc_a_hl() { opi_adc_a(op_read(r[HL])); }
|
||||||
|
|
||||||
void CPU::opi_sub_a(uint8 x) {
|
void CPU::opi_sub_a(uint8 x) {
|
||||||
|
@ -162,7 +167,7 @@ void CPU::opi_sub_a(uint8 x) {
|
||||||
}
|
}
|
||||||
|
|
||||||
template<unsigned x> void CPU::op_sub_a_r() { opi_sub_a(r[x]); }
|
template<unsigned x> void CPU::op_sub_a_r() { opi_sub_a(r[x]); }
|
||||||
void CPU::op_sub_a_n() { opi_sub_a(op_read(r[PC]++)); }
|
void CPU::op_sub_a_n() { opi_sub_a(op_fetch()); }
|
||||||
void CPU::op_sub_a_hl() { opi_sub_a(op_read(r[HL])); }
|
void CPU::op_sub_a_hl() { opi_sub_a(op_read(r[HL])); }
|
||||||
|
|
||||||
void CPU::opi_sbc_a(uint8 x) {
|
void CPU::opi_sbc_a(uint8 x) {
|
||||||
|
@ -176,7 +181,7 @@ void CPU::opi_sbc_a(uint8 x) {
|
||||||
}
|
}
|
||||||
|
|
||||||
template<unsigned x> void CPU::op_sbc_a_r() { opi_sbc_a(r[x]); }
|
template<unsigned x> void CPU::op_sbc_a_r() { opi_sbc_a(r[x]); }
|
||||||
void CPU::op_sbc_a_n() { opi_sbc_a(op_read(r[PC]++)); }
|
void CPU::op_sbc_a_n() { opi_sbc_a(op_fetch()); }
|
||||||
void CPU::op_sbc_a_hl() { opi_sbc_a(op_read(r[HL])); }
|
void CPU::op_sbc_a_hl() { opi_sbc_a(op_read(r[HL])); }
|
||||||
|
|
||||||
void CPU::opi_and_a(uint8 x) {
|
void CPU::opi_and_a(uint8 x) {
|
||||||
|
@ -188,7 +193,7 @@ void CPU::opi_and_a(uint8 x) {
|
||||||
}
|
}
|
||||||
|
|
||||||
template<unsigned x> void CPU::op_and_a_r() { opi_and_a(r[x]); }
|
template<unsigned x> void CPU::op_and_a_r() { opi_and_a(r[x]); }
|
||||||
void CPU::op_and_a_n() { opi_and_a(op_read(r[PC]++)); }
|
void CPU::op_and_a_n() { opi_and_a(op_fetch()); }
|
||||||
void CPU::op_and_a_hl() { opi_and_a(op_read(r[HL])); }
|
void CPU::op_and_a_hl() { opi_and_a(op_read(r[HL])); }
|
||||||
|
|
||||||
void CPU::opi_xor_a(uint8 x) {
|
void CPU::opi_xor_a(uint8 x) {
|
||||||
|
@ -200,7 +205,7 @@ void CPU::opi_xor_a(uint8 x) {
|
||||||
}
|
}
|
||||||
|
|
||||||
template<unsigned x> void CPU::op_xor_a_r() { opi_xor_a(r[x]); }
|
template<unsigned x> void CPU::op_xor_a_r() { opi_xor_a(r[x]); }
|
||||||
void CPU::op_xor_a_n() { opi_xor_a(op_read(r[PC]++)); }
|
void CPU::op_xor_a_n() { opi_xor_a(op_fetch()); }
|
||||||
void CPU::op_xor_a_hl() { opi_xor_a(op_read(r[HL])); }
|
void CPU::op_xor_a_hl() { opi_xor_a(op_read(r[HL])); }
|
||||||
|
|
||||||
void CPU::opi_or_a(uint8 x) {
|
void CPU::opi_or_a(uint8 x) {
|
||||||
|
@ -212,7 +217,7 @@ void CPU::opi_or_a(uint8 x) {
|
||||||
}
|
}
|
||||||
|
|
||||||
template<unsigned x> void CPU::op_or_a_r() { opi_or_a(r[x]); }
|
template<unsigned x> void CPU::op_or_a_r() { opi_or_a(r[x]); }
|
||||||
void CPU::op_or_a_n() { opi_or_a(op_read(r[PC]++)); }
|
void CPU::op_or_a_n() { opi_or_a(op_fetch()); }
|
||||||
void CPU::op_or_a_hl() { opi_or_a(op_read(r[HL])); }
|
void CPU::op_or_a_hl() { opi_or_a(op_read(r[HL])); }
|
||||||
|
|
||||||
void CPU::opi_cp_a(uint8 x) {
|
void CPU::opi_cp_a(uint8 x) {
|
||||||
|
@ -225,7 +230,7 @@ void CPU::opi_cp_a(uint8 x) {
|
||||||
}
|
}
|
||||||
|
|
||||||
template<unsigned x> void CPU::op_cp_a_r() { opi_cp_a(r[x]); }
|
template<unsigned x> void CPU::op_cp_a_r() { opi_cp_a(r[x]); }
|
||||||
void CPU::op_cp_a_n() { opi_cp_a(op_read(r[PC]++)); }
|
void CPU::op_cp_a_n() { opi_cp_a(op_fetch()); }
|
||||||
void CPU::op_cp_a_hl() { opi_cp_a(op_read(r[HL])); }
|
void CPU::op_cp_a_hl() { opi_cp_a(op_read(r[HL])); }
|
||||||
|
|
||||||
template<unsigned x> void CPU::op_inc_r() {
|
template<unsigned x> void CPU::op_inc_r() {
|
||||||
|
@ -307,7 +312,7 @@ template<unsigned x> void CPU::op_dec_rr() {
|
||||||
void CPU::op_add_sp_n() {
|
void CPU::op_add_sp_n() {
|
||||||
op_io();
|
op_io();
|
||||||
op_io();
|
op_io();
|
||||||
signed n = (int8)op_read(r[PC]++);
|
signed n = (int8)op_fetch();
|
||||||
r.f.z = 0;
|
r.f.z = 0;
|
||||||
r.f.n = 0;
|
r.f.n = 0;
|
||||||
r.f.h = ((r[SP] & 0x0f) + (n & 0x0f)) > 0x0f;
|
r.f.h = ((r[SP] & 0x0f) + (n & 0x0f)) > 0x0f;
|
||||||
|
@ -317,7 +322,7 @@ void CPU::op_add_sp_n() {
|
||||||
|
|
||||||
void CPU::op_ld_hl_sp_n() {
|
void CPU::op_ld_hl_sp_n() {
|
||||||
op_io();
|
op_io();
|
||||||
signed n = (int8)op_read(r[PC]++);
|
signed n = (int8)op_fetch();
|
||||||
r.f.z = 0;
|
r.f.z = 0;
|
||||||
r.f.n = 0;
|
r.f.n = 0;
|
||||||
r.f.h = ((r[SP] & 0x0f) + (n & 0x0f)) > 0x0f;
|
r.f.h = ((r[SP] & 0x0f) + (n & 0x0f)) > 0x0f;
|
||||||
|
@ -596,8 +601,8 @@ void CPU::op_ei() {
|
||||||
//jump commands
|
//jump commands
|
||||||
|
|
||||||
void CPU::op_jp_nn() {
|
void CPU::op_jp_nn() {
|
||||||
uint8 lo = op_read(r[PC]++);
|
uint8 lo = op_fetch();
|
||||||
uint8 hi = op_read(r[PC]++);
|
uint8 hi = op_fetch();
|
||||||
r[PC] = (hi << 8) | (lo << 0);
|
r[PC] = (hi << 8) | (lo << 0);
|
||||||
op_io();
|
op_io();
|
||||||
}
|
}
|
||||||
|
@ -607,8 +612,8 @@ void CPU::op_jp_hl() {
|
||||||
}
|
}
|
||||||
|
|
||||||
template<unsigned x, bool y> void CPU::op_jp_f_nn() {
|
template<unsigned x, bool y> void CPU::op_jp_f_nn() {
|
||||||
uint8 lo = op_read(r[PC]++);
|
uint8 lo = op_fetch();
|
||||||
uint8 hi = op_read(r[PC]++);
|
uint8 hi = op_fetch();
|
||||||
if(r.f[x] == y) {
|
if(r.f[x] == y) {
|
||||||
r[PC] = (hi << 8) | (lo << 0);
|
r[PC] = (hi << 8) | (lo << 0);
|
||||||
op_io();
|
op_io();
|
||||||
|
@ -616,13 +621,13 @@ template<unsigned x, bool y> void CPU::op_jp_f_nn() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void CPU::op_jr_n() {
|
void CPU::op_jr_n() {
|
||||||
int8 n = op_read(r[PC]++);
|
int8 n = op_fetch();
|
||||||
r[PC] += n;
|
r[PC] += n;
|
||||||
op_io();
|
op_io();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<unsigned x, bool y> void CPU::op_jr_f_n() {
|
template<unsigned x, bool y> void CPU::op_jr_f_n() {
|
||||||
int8 n = op_read(r[PC]++);
|
int8 n = op_fetch();
|
||||||
if(r.f[x] == y) {
|
if(r.f[x] == y) {
|
||||||
r[PC] += n;
|
r[PC] += n;
|
||||||
op_io();
|
op_io();
|
||||||
|
@ -630,8 +635,8 @@ template<unsigned x, bool y> void CPU::op_jr_f_n() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void CPU::op_call_nn() {
|
void CPU::op_call_nn() {
|
||||||
uint8 lo = op_read(r[PC]++);
|
uint8 lo = op_fetch();
|
||||||
uint8 hi = op_read(r[PC]++);
|
uint8 hi = op_fetch();
|
||||||
op_write(--r[SP], r[PC] >> 8);
|
op_write(--r[SP], r[PC] >> 8);
|
||||||
op_write(--r[SP], r[PC] >> 0);
|
op_write(--r[SP], r[PC] >> 0);
|
||||||
r[PC] = (hi << 8) | (lo << 0);
|
r[PC] = (hi << 8) | (lo << 0);
|
||||||
|
@ -639,8 +644,8 @@ void CPU::op_call_nn() {
|
||||||
}
|
}
|
||||||
|
|
||||||
template<unsigned x, bool y> void CPU::op_call_f_nn() {
|
template<unsigned x, bool y> void CPU::op_call_f_nn() {
|
||||||
uint8 lo = op_read(r[PC]++);
|
uint8 lo = op_fetch();
|
||||||
uint8 hi = op_read(r[PC]++);
|
uint8 hi = op_fetch();
|
||||||
if(r.f[x] == y) {
|
if(r.f[x] == y) {
|
||||||
op_write(--r[SP], r[PC] >> 8);
|
op_write(--r[SP], r[PC] >> 8);
|
||||||
op_write(--r[SP], r[PC] >> 0);
|
op_write(--r[SP], r[PC] >> 0);
|
||||||
|
|
|
@ -1,145 +1,146 @@
|
||||||
#include "registers.hpp"
|
#include "registers.hpp"
|
||||||
void (CPU::*opcode_table[256])();
|
void (CPU::*opcode_table[256])();
|
||||||
void (CPU::*opcode_table_cb[256])();
|
void (CPU::*opcode_table_cb[256])();
|
||||||
void initialize_opcode_table();
|
void initialize_opcode_table();
|
||||||
|
|
||||||
void op_xx();
|
void op_xx();
|
||||||
void op_cb();
|
void op_cb();
|
||||||
|
uint8 op_fetch();
|
||||||
//8-bit load commands
|
|
||||||
template<unsigned x, unsigned y> void op_ld_r_r();
|
//8-bit load commands
|
||||||
template<unsigned x> void op_ld_r_n();
|
template<unsigned x, unsigned y> void op_ld_r_r();
|
||||||
template<unsigned x> void op_ld_r_hl();
|
template<unsigned x> void op_ld_r_n();
|
||||||
template<unsigned x> void op_ld_hl_r();
|
template<unsigned x> void op_ld_r_hl();
|
||||||
void op_ld_hl_n();
|
template<unsigned x> void op_ld_hl_r();
|
||||||
template<unsigned x> void op_ld_a_rr();
|
void op_ld_hl_n();
|
||||||
void op_ld_a_nn();
|
template<unsigned x> void op_ld_a_rr();
|
||||||
template<unsigned x> void op_ld_rr_a();
|
void op_ld_a_nn();
|
||||||
void op_ld_nn_a();
|
template<unsigned x> void op_ld_rr_a();
|
||||||
void op_ld_a_ffn();
|
void op_ld_nn_a();
|
||||||
void op_ld_ffn_a();
|
void op_ld_a_ffn();
|
||||||
void op_ld_a_ffc();
|
void op_ld_ffn_a();
|
||||||
void op_ld_ffc_a();
|
void op_ld_a_ffc();
|
||||||
void op_ldi_hl_a();
|
void op_ld_ffc_a();
|
||||||
void op_ldi_a_hl();
|
void op_ldi_hl_a();
|
||||||
void op_ldd_hl_a();
|
void op_ldi_a_hl();
|
||||||
void op_ldd_a_hl();
|
void op_ldd_hl_a();
|
||||||
|
void op_ldd_a_hl();
|
||||||
//16-bit load commands
|
|
||||||
template<unsigned x> void op_ld_rr_nn();
|
//16-bit load commands
|
||||||
void op_ld_nn_sp();
|
template<unsigned x> void op_ld_rr_nn();
|
||||||
void op_ld_sp_hl();
|
void op_ld_nn_sp();
|
||||||
template<unsigned x> void op_push_rr();
|
void op_ld_sp_hl();
|
||||||
template<unsigned x> void op_pop_rr();
|
template<unsigned x> void op_push_rr();
|
||||||
|
template<unsigned x> void op_pop_rr();
|
||||||
//8-bit arithmetic commands
|
|
||||||
void opi_add_a(uint8 x);
|
//8-bit arithmetic commands
|
||||||
template<unsigned x> void op_add_a_r();
|
void opi_add_a(uint8 x);
|
||||||
void op_add_a_n();
|
template<unsigned x> void op_add_a_r();
|
||||||
void op_add_a_hl();
|
void op_add_a_n();
|
||||||
|
void op_add_a_hl();
|
||||||
void opi_adc_a(uint8 x);
|
|
||||||
template<unsigned x> void op_adc_a_r();
|
void opi_adc_a(uint8 x);
|
||||||
void op_adc_a_n();
|
template<unsigned x> void op_adc_a_r();
|
||||||
void op_adc_a_hl();
|
void op_adc_a_n();
|
||||||
|
void op_adc_a_hl();
|
||||||
void opi_sub_a(uint8 x);
|
|
||||||
template<unsigned x> void op_sub_a_r();
|
void opi_sub_a(uint8 x);
|
||||||
void op_sub_a_n();
|
template<unsigned x> void op_sub_a_r();
|
||||||
void op_sub_a_hl();
|
void op_sub_a_n();
|
||||||
|
void op_sub_a_hl();
|
||||||
void opi_sbc_a(uint8 x);
|
|
||||||
template<unsigned x> void op_sbc_a_r();
|
void opi_sbc_a(uint8 x);
|
||||||
void op_sbc_a_n();
|
template<unsigned x> void op_sbc_a_r();
|
||||||
void op_sbc_a_hl();
|
void op_sbc_a_n();
|
||||||
|
void op_sbc_a_hl();
|
||||||
void opi_and_a(uint8 x);
|
|
||||||
template<unsigned x> void op_and_a_r();
|
void opi_and_a(uint8 x);
|
||||||
void op_and_a_n();
|
template<unsigned x> void op_and_a_r();
|
||||||
void op_and_a_hl();
|
void op_and_a_n();
|
||||||
|
void op_and_a_hl();
|
||||||
void opi_xor_a(uint8 x);
|
|
||||||
template<unsigned x> void op_xor_a_r();
|
void opi_xor_a(uint8 x);
|
||||||
void op_xor_a_n();
|
template<unsigned x> void op_xor_a_r();
|
||||||
void op_xor_a_hl();
|
void op_xor_a_n();
|
||||||
|
void op_xor_a_hl();
|
||||||
void opi_or_a(uint8 x);
|
|
||||||
template<unsigned x> void op_or_a_r();
|
void opi_or_a(uint8 x);
|
||||||
void op_or_a_n();
|
template<unsigned x> void op_or_a_r();
|
||||||
void op_or_a_hl();
|
void op_or_a_n();
|
||||||
|
void op_or_a_hl();
|
||||||
void opi_cp_a(uint8 x);
|
|
||||||
template<unsigned x> void op_cp_a_r();
|
void opi_cp_a(uint8 x);
|
||||||
void op_cp_a_n();
|
template<unsigned x> void op_cp_a_r();
|
||||||
void op_cp_a_hl();
|
void op_cp_a_n();
|
||||||
|
void op_cp_a_hl();
|
||||||
template<unsigned x> void op_inc_r();
|
|
||||||
void op_inc_hl();
|
template<unsigned x> void op_inc_r();
|
||||||
template<unsigned x> void op_dec_r();
|
void op_inc_hl();
|
||||||
void op_dec_hl();
|
template<unsigned x> void op_dec_r();
|
||||||
void op_daa();
|
void op_dec_hl();
|
||||||
void op_cpl();
|
void op_daa();
|
||||||
|
void op_cpl();
|
||||||
//16-bit arithmetic commands
|
|
||||||
template<unsigned x> void op_add_hl_rr();
|
//16-bit arithmetic commands
|
||||||
template<unsigned x> void op_inc_rr();
|
template<unsigned x> void op_add_hl_rr();
|
||||||
template<unsigned x> void op_dec_rr();
|
template<unsigned x> void op_inc_rr();
|
||||||
void op_add_sp_n();
|
template<unsigned x> void op_dec_rr();
|
||||||
void op_ld_hl_sp_n();
|
void op_add_sp_n();
|
||||||
|
void op_ld_hl_sp_n();
|
||||||
//rotate/shift commands
|
|
||||||
void op_rlca();
|
//rotate/shift commands
|
||||||
void op_rla();
|
void op_rlca();
|
||||||
void op_rrca();
|
void op_rla();
|
||||||
void op_rra();
|
void op_rrca();
|
||||||
template<unsigned x> void op_rlc_r();
|
void op_rra();
|
||||||
void op_rlc_hl();
|
template<unsigned x> void op_rlc_r();
|
||||||
template<unsigned x> void op_rl_r();
|
void op_rlc_hl();
|
||||||
void op_rl_hl();
|
template<unsigned x> void op_rl_r();
|
||||||
template<unsigned x> void op_rrc_r();
|
void op_rl_hl();
|
||||||
void op_rrc_hl();
|
template<unsigned x> void op_rrc_r();
|
||||||
template<unsigned x> void op_rr_r();
|
void op_rrc_hl();
|
||||||
void op_rr_hl();
|
template<unsigned x> void op_rr_r();
|
||||||
template<unsigned x> void op_sla_r();
|
void op_rr_hl();
|
||||||
void op_sla_hl();
|
template<unsigned x> void op_sla_r();
|
||||||
template<unsigned x> void op_swap_r();
|
void op_sla_hl();
|
||||||
void op_swap_hl();
|
template<unsigned x> void op_swap_r();
|
||||||
template<unsigned x> void op_sra_r();
|
void op_swap_hl();
|
||||||
void op_sra_hl();
|
template<unsigned x> void op_sra_r();
|
||||||
template<unsigned x> void op_srl_r();
|
void op_sra_hl();
|
||||||
void op_srl_hl();
|
template<unsigned x> void op_srl_r();
|
||||||
|
void op_srl_hl();
|
||||||
//single-bit commands
|
|
||||||
template<unsigned b, unsigned x> void op_bit_n_r();
|
//single-bit commands
|
||||||
template<unsigned b> void op_bit_n_hl();
|
template<unsigned b, unsigned x> void op_bit_n_r();
|
||||||
template<unsigned b, unsigned x> void op_set_n_r();
|
template<unsigned b> void op_bit_n_hl();
|
||||||
template<unsigned b> void op_set_n_hl();
|
template<unsigned b, unsigned x> void op_set_n_r();
|
||||||
template<unsigned b, unsigned x> void op_res_n_r();
|
template<unsigned b> void op_set_n_hl();
|
||||||
template<unsigned b> void op_res_n_hl();
|
template<unsigned b, unsigned x> void op_res_n_r();
|
||||||
|
template<unsigned b> void op_res_n_hl();
|
||||||
//control commands
|
|
||||||
void op_ccf();
|
//control commands
|
||||||
void op_scf();
|
void op_ccf();
|
||||||
void op_nop();
|
void op_scf();
|
||||||
void op_halt();
|
void op_nop();
|
||||||
void op_stop();
|
void op_halt();
|
||||||
void op_di();
|
void op_stop();
|
||||||
void op_ei();
|
void op_di();
|
||||||
|
void op_ei();
|
||||||
//jump commands
|
|
||||||
void op_jp_nn();
|
//jump commands
|
||||||
void op_jp_hl();
|
void op_jp_nn();
|
||||||
template<unsigned x, bool y> void op_jp_f_nn();
|
void op_jp_hl();
|
||||||
void op_jr_n();
|
template<unsigned x, bool y> void op_jp_f_nn();
|
||||||
template<unsigned x, bool y> void op_jr_f_n();
|
void op_jr_n();
|
||||||
void op_call_nn();
|
template<unsigned x, bool y> void op_jr_f_n();
|
||||||
template<unsigned x, bool y> void op_call_f_nn();
|
void op_call_nn();
|
||||||
void op_ret();
|
template<unsigned x, bool y> void op_call_f_nn();
|
||||||
template<unsigned x, bool y> void op_ret_f();
|
void op_ret();
|
||||||
void op_reti();
|
template<unsigned x, bool y> void op_ret_f();
|
||||||
template<unsigned n> void op_rst_n();
|
void op_reti();
|
||||||
|
template<unsigned n> void op_rst_n();
|
||||||
//disassembler.cpp
|
|
||||||
string disassemble(uint16 pc);
|
//disassembler.cpp
|
||||||
string disassemble_opcode(uint16 pc);
|
string disassemble(uint16 pc);
|
||||||
string disassemble_opcode_cb(uint16 pc);
|
string disassemble_opcode(uint16 pc);
|
||||||
|
string disassemble_opcode_cb(uint16 pc);
|
||||||
|
|
|
@ -1,90 +1,96 @@
|
||||||
//70224 clocks/frame
|
//70224 clocks/frame
|
||||||
// 456 clocks/scanline
|
// 456 clocks/scanline
|
||||||
// 154 scanlines/frame
|
// 154 scanlines/frame
|
||||||
|
|
||||||
#ifdef CPU_CPP
|
#ifdef CPU_CPP
|
||||||
|
|
||||||
#include "opcode.cpp"
|
#include "opcode.cpp"
|
||||||
|
|
||||||
void CPU::add_clocks(unsigned clocks) {
|
void CPU::add_clocks(unsigned clocks) {
|
||||||
system.clocks_executed += clocks;
|
system.clocks_executed += clocks;
|
||||||
if(system.sgb()) scheduler.exit(Scheduler::ExitReason::StepEvent);
|
|
||||||
|
auto flags = cdlInfo.currFlags;
|
||||||
status.clock += clocks;
|
|
||||||
if(status.clock >= 4 * 1024 * 1024) {
|
if(system.sgb()) scheduler.exit(Scheduler::ExitReason::StepEvent);
|
||||||
status.clock -= 4 * 1024 * 1024;
|
cdlInfo.currFlags = flags;
|
||||||
cartridge.mbc3.second();
|
|
||||||
}
|
status.clock += clocks;
|
||||||
|
if(status.clock >= 4 * 1024 * 1024) {
|
||||||
//4MHz / N(hz) - 1 = mask
|
status.clock -= 4 * 1024 * 1024;
|
||||||
if((status.clock & 15) == 0) timer_262144hz();
|
cartridge.mbc3.second();
|
||||||
if((status.clock & 63) == 0) timer_65536hz();
|
}
|
||||||
if((status.clock & 255) == 0) timer_16384hz();
|
|
||||||
if((status.clock & 511) == 0) timer_8192hz();
|
//4MHz / N(hz) - 1 = mask
|
||||||
if((status.clock & 1023) == 0) timer_4096hz();
|
if((status.clock & 15) == 0) timer_262144hz();
|
||||||
|
if((status.clock & 63) == 0) timer_65536hz();
|
||||||
lcd.clock -= clocks * lcd.frequency;
|
if((status.clock & 255) == 0) timer_16384hz();
|
||||||
if(lcd.clock <= 0) co_switch(scheduler.active_thread = lcd.thread);
|
if((status.clock & 511) == 0) timer_8192hz();
|
||||||
|
if((status.clock & 1023) == 0) timer_4096hz();
|
||||||
apu.clock -= clocks * apu.frequency;
|
|
||||||
if(apu.clock <= 0) co_switch(scheduler.active_thread = apu.thread);
|
lcd.clock -= clocks * lcd.frequency;
|
||||||
}
|
if(lcd.clock <= 0) co_switch(scheduler.active_thread = lcd.thread);
|
||||||
|
cdlInfo.currFlags = flags;
|
||||||
void CPU::timer_262144hz() {
|
|
||||||
if(status.timer_enable && status.timer_clock == 1) {
|
apu.clock -= clocks * apu.frequency;
|
||||||
if(++status.tima == 0) {
|
if(apu.clock <= 0) co_switch(scheduler.active_thread = apu.thread);
|
||||||
status.tima = status.tma;
|
cdlInfo.currFlags = flags;
|
||||||
interrupt_raise(Interrupt::Timer);
|
}
|
||||||
}
|
|
||||||
}
|
void CPU::timer_262144hz() {
|
||||||
}
|
if(status.timer_enable && status.timer_clock == 1) {
|
||||||
|
if(++status.tima == 0) {
|
||||||
void CPU::timer_65536hz() {
|
status.tima = status.tma;
|
||||||
if(status.timer_enable && status.timer_clock == 2) {
|
interrupt_raise(Interrupt::Timer);
|
||||||
if(++status.tima == 0) {
|
}
|
||||||
status.tima = status.tma;
|
}
|
||||||
interrupt_raise(Interrupt::Timer);
|
}
|
||||||
}
|
|
||||||
}
|
void CPU::timer_65536hz() {
|
||||||
}
|
if(status.timer_enable && status.timer_clock == 2) {
|
||||||
|
if(++status.tima == 0) {
|
||||||
void CPU::timer_16384hz() {
|
status.tima = status.tma;
|
||||||
if(status.timer_enable && status.timer_clock == 3) {
|
interrupt_raise(Interrupt::Timer);
|
||||||
if(++status.tima == 0) {
|
}
|
||||||
status.tima = status.tma;
|
}
|
||||||
interrupt_raise(Interrupt::Timer);
|
}
|
||||||
}
|
|
||||||
}
|
void CPU::timer_16384hz() {
|
||||||
|
if(status.timer_enable && status.timer_clock == 3) {
|
||||||
status.div++;
|
if(++status.tima == 0) {
|
||||||
}
|
status.tima = status.tma;
|
||||||
|
interrupt_raise(Interrupt::Timer);
|
||||||
void CPU::timer_8192hz() {
|
}
|
||||||
if(status.serial_transfer && status.serial_clock) {
|
}
|
||||||
if(--status.serial_bits == 0) {
|
|
||||||
status.serial_transfer = 0;
|
status.div++;
|
||||||
interrupt_raise(Interrupt::Serial);
|
}
|
||||||
}
|
|
||||||
}
|
void CPU::timer_8192hz() {
|
||||||
}
|
if(status.serial_transfer && status.serial_clock) {
|
||||||
|
if(--status.serial_bits == 0) {
|
||||||
void CPU::timer_4096hz() {
|
status.serial_transfer = 0;
|
||||||
if(status.timer_enable && status.timer_clock == 0) {
|
interrupt_raise(Interrupt::Serial);
|
||||||
if(++status.tima == 0) {
|
}
|
||||||
status.tima = status.tma;
|
}
|
||||||
interrupt_raise(Interrupt::Timer);
|
}
|
||||||
}
|
|
||||||
}
|
void CPU::timer_4096hz() {
|
||||||
}
|
if(status.timer_enable && status.timer_clock == 0) {
|
||||||
|
if(++status.tima == 0) {
|
||||||
void CPU::hblank() {
|
status.tima = status.tma;
|
||||||
if(status.dma_mode == 1 && status.dma_length) {
|
interrupt_raise(Interrupt::Timer);
|
||||||
for(unsigned n = 0; n < 16; n++) {
|
}
|
||||||
bus.write(status.dma_target++, bus.read(status.dma_source++));
|
}
|
||||||
add_clocks(4);
|
}
|
||||||
}
|
|
||||||
status.dma_length -= 16;
|
void CPU::hblank() {
|
||||||
}
|
if(status.dma_mode == 1 && status.dma_length) {
|
||||||
}
|
for(unsigned n = 0; n < 16; n++) {
|
||||||
|
bus.write(status.dma_target++, bus.read(status.dma_source++));
|
||||||
#endif
|
add_clocks(4);
|
||||||
|
}
|
||||||
|
status.dma_length -= 16;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue