Move gameboy doctor code to misc/
This commit is contained in:
parent
7bc272afb6
commit
cc6cb865bc
2 changed files with 5 additions and 1 deletions
misc
99
misc/gbdif.cpp
Normal file
99
misc/gbdif.cpp
Normal file
|
@ -0,0 +1,99 @@
|
|||
#include <cpu/cpu.h>
|
||||
#include <cartridge/cartridge.h>
|
||||
#include <cartridge/mbc/mbc1.h>
|
||||
#include <memory/ram.h>
|
||||
#include <memory/bus.h>
|
||||
#include <memory/register.h>
|
||||
#include <fstream>
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
if(argc < 2)
|
||||
return 1;
|
||||
|
||||
std::ifstream file(argv[1]);
|
||||
Cartridge cart(file);
|
||||
|
||||
if(cart.type() != CT_MBC1)
|
||||
return 2;
|
||||
|
||||
RAM wram1(0x1000);
|
||||
RAM wram2(0x1000);
|
||||
RAM hram(0x100);
|
||||
RAM oam(0x100);
|
||||
|
||||
MBC1 mbc1(cart);
|
||||
|
||||
ConstRegister ly_reg(0x90);
|
||||
|
||||
Bus b;
|
||||
b.map_device(0x0000, 0x7FFF, &mbc1);
|
||||
b.map_device(0xA000, 0xBFFF, &mbc1, 0xA000);
|
||||
b.map_device(0xC000, 0xCFFF, &wram1);
|
||||
b.map_device(0xD000, 0xDFFF, &wram2);
|
||||
b.map_device(0xE000, 0xFDFF, &wram1);
|
||||
b.map_device(0xFE00, 0xFE9F, &oam);
|
||||
b.map_device(0xFF44, 0xFF44, &ly_reg);
|
||||
b.map_device(0xFF80, 0xFFFE, &hram);
|
||||
|
||||
Cpu cpu(&b);
|
||||
|
||||
BoundRegister ie_mapped(cpu.state.IE);
|
||||
BoundRegister if_mapped(cpu.state.IF);
|
||||
b.map_device(0xFFFF, 0xFFFF, &ie_mapped);
|
||||
b.map_device(0xFF0F, 0xFF0F, &ie_mapped);
|
||||
|
||||
cpu.state.A = 0x1;
|
||||
cpu.state.carry = true;
|
||||
cpu.state.halfcarry = true;
|
||||
cpu.state.subtract = false;
|
||||
cpu.state.zero = true;
|
||||
|
||||
cpu.state.B = 0x00;
|
||||
cpu.state.C = 0x13;
|
||||
cpu.state.D = 0x00;
|
||||
cpu.state.E = 0xD8;
|
||||
cpu.state.H = 0x01;
|
||||
cpu.state.L = 0x4D;
|
||||
|
||||
cpu.state.SP = 0xFFFE;
|
||||
cpu.state.PC = 0x100;
|
||||
|
||||
const std::chrono::milliseconds delay(10);
|
||||
|
||||
try {
|
||||
while(!cpu.state.stopped)
|
||||
{
|
||||
std::cout
|
||||
<< "A:" << std::setfill('0') << std::setw(2) << std::hex << std::uppercase << (unsigned)cpu.state.A
|
||||
<< " F:" << std::setfill('0') << std::setw(2) << std::hex << std::uppercase << (unsigned)cpu.state.getF()
|
||||
<< " B:" << std::setfill('0') << std::setw(2) << std::hex << std::uppercase << (unsigned)cpu.state.B
|
||||
<< " C:" << std::setfill('0') << std::setw(2) << std::hex << std::uppercase << (unsigned)cpu.state.C
|
||||
<< " D:" << std::setfill('0') << std::setw(2) << std::hex << std::uppercase << (unsigned)cpu.state.D
|
||||
<< " E:" << std::setfill('0') << std::setw(2) << std::hex << std::uppercase << (unsigned)cpu.state.E
|
||||
<< " H:" << std::setfill('0') << std::setw(2) << std::hex << std::uppercase << (unsigned)cpu.state.H
|
||||
<< " L:" << std::setfill('0') << std::setw(2) << std::hex << std::uppercase << (unsigned)cpu.state.L
|
||||
<< " SP:" << std::setfill('0') << std::setw(4) << std::hex << std::uppercase << (unsigned)cpu.state.SP
|
||||
<< " PC:" << std::setfill('0') << std::setw(4) << std::hex << std::uppercase << (unsigned)cpu.state.PC
|
||||
<< " PCMEM:"
|
||||
<< std::setw(2) << std::hex << std::uppercase << (unsigned)b.read8(cpu.state.PC) << ","
|
||||
<< std::setw(2) << std::hex << std::uppercase << (unsigned)b.read8(cpu.state.PC+1) << ","
|
||||
<< std::setw(2) << std::hex << std::uppercase << (unsigned)b.read8(cpu.state.PC+2) << ","
|
||||
<< std::setw(2) << std::hex << std::uppercase << (unsigned)b.read8(cpu.state.PC+3) << std::endl;
|
||||
|
||||
cpu.step();
|
||||
|
||||
|
||||
if(cpu.state.halted)
|
||||
std::this_thread::sleep_for(delay);
|
||||
}
|
||||
} catch(CpuException& e) {
|
||||
std::cerr << e.what() << std::endl;
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue