Including more test roms and initializing the registers

This commit is contained in:
Franco Colmenarez 2021-10-15 19:49:36 -05:00
parent f9d5cfaa02
commit 9d8d05c660
14 changed files with 25 additions and 14 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -43,7 +43,7 @@ pub struct Bus {
impl Bus { impl Bus {
pub fn new() -> Self { pub fn new() -> Self {
let game_rom = match ROM::load_file("roms/cpu_instrs.gb".to_string()) { let game_rom = match ROM::load_file("roms/cpu_instrs_individual/01-special.gb".to_string()) {
Ok(rom) => rom, Ok(rom) => rom,
_ => ROM::from_bytes(&[0; 0xFFFF]) _ => ROM::from_bytes(&[0; 0xFFFF])
}; };

View File

@ -87,16 +87,16 @@ pub struct Registers {
impl Registers { impl Registers {
pub fn new() -> Self { pub fn new() -> Self {
Self { Self {
a: 0, a: 0x01,
f: 0b00000000, // The first 4 lower bits are always set to 0 f: 0xB0, // The first 4 lower bits are always set to 0
b: 0, b: 0x00,
c: 0, c: 0x00,
d: 0, d: 0x00,
e: 0, e: 0xD8,
h: 0, h: 0x01,
l: 0, l: 0x4D,
sp: 0, sp: 0xFFFE,
pc: 0x100, // On power up, the Gameboy executes the instruction at hex 100 pc: 0x0100, // On power up, the Gameboy executes the instruction at hex 100
} }
} }
@ -275,9 +275,20 @@ impl CPU {
let program_counter = self.registers.get(Register::PC); let program_counter = self.registers.get(Register::PC);
let parameter_bytes = CPU::read_parameter_bytes(program_counter, bus); let parameter_bytes = CPU::read_parameter_bytes(program_counter, bus);
let opcode = CPU::parse_opcode(&parameter_bytes); let opcode = CPU::parse_opcode(&parameter_bytes);
println!("{:?}", opcode); // println!("Opcode: {:02X?} | PC: {:04X?} | Params: {:02X?}", opcode, self.registers.get(Register::PC), &parameter_bytes);
println!("PC: {:04X?}", self.registers.get(Register::PC)); println!("A: {:02X} F: {:02X} B: {:02X} C: {:02X} D: {:02X} E: {:02X} H: {:02X} L: {:02X} SP: {:04X} PC: 00:{:04X} {:02X?}",
println!("{:02X?}", &parameter_bytes); self.registers.get(Register::A),
self.registers.get(Register::F),
self.registers.get(Register::B),
self.registers.get(Register::C),
self.registers.get(Register::D),
self.registers.get(Register::E),
self.registers.get(Register::H),
self.registers.get(Register::L),
self.registers.get(Register::SP),
self.registers.get(Register::PC),
parameter_bytes,
);
self.exec(opcode, bus); self.exec(opcode, bus);
} }