Fixed some errors
This commit is contained in:
parent
40e2f45177
commit
80fb089e17
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
||||
cmake-build-debug/
|
||||
.idea/
|
||||
.vs/
|
||||
@ -13,7 +13,7 @@ namespace nes {
|
||||
auto romSize = fs::file_size(path);
|
||||
_romData = std::make_unique<uint8_t[]>(romSize);
|
||||
|
||||
std::ifstream rom(path);
|
||||
std::ifstream rom(path, std::ios::binary);
|
||||
rom.read(reinterpret_cast<char*>(_romData.get()), static_cast<std::streamsize>(romSize));
|
||||
|
||||
// UB here
|
||||
|
||||
19
src/Cpu.cpp
19
src/Cpu.cpp
@ -70,7 +70,7 @@ namespace nes {
|
||||
A = 0;
|
||||
X = 0;
|
||||
Y = 0;
|
||||
SP = 0xFF;
|
||||
SP = 0xFD;
|
||||
flags = 0;
|
||||
|
||||
uint16_t lo = _bus->read(0xFFFC);
|
||||
@ -92,7 +92,11 @@ namespace nes {
|
||||
auto args = (this->*instruction.getAddress)();
|
||||
(this->*instruction.process)(args);
|
||||
|
||||
std::cout << instruction.name << std::hex << ", PC: " << (int)PC << ", A: " << (int)A << ", X: " << (int)X << ", Y: " << (int)Y << std::endl;
|
||||
auto str = std::format("{} ({:02X}), PC: {:X}, SP: {:X}, A: {:02X}, X: {:02X}, Y: {:02X}, [N:{}, V:{}, B{}, D{}, I{}, Z:{}, C:{}]", instruction.name, opcode, PC, SP, A, X, Y,
|
||||
(int)getFlag(Negative), (int)getFlag(Overflow), (int)getFlag(Break), (int)getFlag(DecimalMode), (int)getFlag(InterruptDisable), (int)getFlag(Zero), (int)getFlag(Carry));
|
||||
std::cout << str << std::endl;
|
||||
|
||||
//std::cout << instruction.name << std::hex << ", OpCode: " << (int)opcode << ", PC: " << (int)PC << ", SP: " << (int)SP << ", A: " << (int)A << ", X: " << (int)X << ", Y: " << (int)Y << std::endl;
|
||||
|
||||
_ticks = instruction.cycles;
|
||||
if(instruction.variableCycles) {
|
||||
@ -136,7 +140,7 @@ namespace nes {
|
||||
// Addressing modes
|
||||
|
||||
Cpu::InstructionArgs Cpu::IMM() {
|
||||
return {++PC, 0};
|
||||
return {PC++, 0};
|
||||
}
|
||||
|
||||
Cpu::InstructionArgs Cpu::ABS() {
|
||||
@ -259,7 +263,6 @@ namespace nes {
|
||||
}
|
||||
|
||||
void Cpu::JSR(Cpu::InstructionArgs args) {
|
||||
std::cout << "+++ >>> Jumping from: " << PC << std::endl;
|
||||
PC--;
|
||||
_bus->write(STACK_BASE + SP--, PC >> 8);
|
||||
_bus->write(STACK_BASE + SP--, PC & 0x00FF);
|
||||
@ -313,8 +316,6 @@ namespace nes {
|
||||
|
||||
PC = (hi << 8) | lo;
|
||||
PC++;
|
||||
|
||||
std::cout << "+++ <<< return to: " << PC << std::endl;
|
||||
}
|
||||
|
||||
void Cpu::SED(Cpu::InstructionArgs args) {
|
||||
@ -342,7 +343,7 @@ namespace nes {
|
||||
void Cpu::CMP(Cpu::InstructionArgs args) {
|
||||
uint16_t value = _bus->read(args.address);
|
||||
uint16_t diff = A - value;
|
||||
setFlag(Carry, A > value);
|
||||
setFlag(Carry, A >= value);
|
||||
setFlag(Zero, (diff & 0x00FF) == 0);
|
||||
setFlag(Negative, diff & 0x0080);
|
||||
}
|
||||
@ -381,7 +382,7 @@ namespace nes {
|
||||
void Cpu::CPY(Cpu::InstructionArgs args) {
|
||||
uint16_t value = _bus->read(args.address);
|
||||
uint16_t diff = Y - value;
|
||||
setFlag(Carry, Y > value);
|
||||
setFlag(Carry, Y >= value);
|
||||
setFlag(Zero, (diff & 0x00FF) == 0);
|
||||
setFlag(Negative, diff & 0x0080);
|
||||
}
|
||||
@ -389,7 +390,7 @@ namespace nes {
|
||||
void Cpu::CPX(Cpu::InstructionArgs args) {
|
||||
uint16_t value = _bus->read(args.address);
|
||||
uint16_t diff = X - value;
|
||||
setFlag(Carry, X > value);
|
||||
setFlag(Carry, X >= value);
|
||||
setFlag(Zero, (diff & 0x00FF) == 0);
|
||||
setFlag(Negative, diff & 0x0080);
|
||||
}
|
||||
|
||||
@ -37,7 +37,7 @@ namespace nes {
|
||||
}
|
||||
|
||||
size_t ticks = 0;
|
||||
while (ticks <= 2000) {
|
||||
while (ticks <= 5000) {
|
||||
_cpu->tick();
|
||||
ticks++;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user