diff --git a/.gitignore b/.gitignore index 1c828c4..8b7d20d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ cmake-build-debug/ .idea/ +.vs/ \ No newline at end of file diff --git a/src/Cartridge.cpp b/src/Cartridge.cpp index fb787b2..aa94dc3 100644 --- a/src/Cartridge.cpp +++ b/src/Cartridge.cpp @@ -13,7 +13,7 @@ namespace nes { auto romSize = fs::file_size(path); _romData = std::make_unique(romSize); - std::ifstream rom(path); + std::ifstream rom(path, std::ios::binary); rom.read(reinterpret_cast(_romData.get()), static_cast(romSize)); // UB here diff --git a/src/Cpu.cpp b/src/Cpu.cpp index 00aa1b3..fb34685 100644 --- a/src/Cpu.cpp +++ b/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); } diff --git a/src/Nes.cpp b/src/Nes.cpp index de14263..366d699 100644 --- a/src/Nes.cpp +++ b/src/Nes.cpp @@ -37,7 +37,7 @@ namespace nes { } size_t ticks = 0; - while (ticks <= 2000) { + while (ticks <= 5000) { _cpu->tick(); ticks++; }