Compare commits

..

2 Commits

Author SHA1 Message Date
Rekai Nyangadzayi Musuka 4125ea5c74 fix(instr): fix timing issues with select instructions
instr_timing now runs (and fails on everything)
2021-10-30 14:02:28 +09:00
Rekai Nyangadzayi Musuka b9519d9b7a chore(bus): stub some CGB IO registers 2021-10-30 14:02:05 +09:00
2 changed files with 14 additions and 8 deletions

View File

@ -262,6 +262,7 @@ impl BusIo for Bus {
0x49 => self.ppu.monochrome.obj_palette_1.into(), 0x49 => self.ppu.monochrome.obj_palette_1.into(),
0x4A => self.ppu.pos.window_y, 0x4A => self.ppu.pos.window_y,
0x4B => self.ppu.pos.window_x, 0x4B => self.ppu.pos.window_x,
0x4F => 0xFF, // CGB VRAM Bank Select
_ => { _ => {
warn!("Attempted read from {:#06X} on IO", addr); warn!("Attempted read from {:#06X} on IO", addr);
0xFF 0xFF
@ -372,12 +373,14 @@ impl BusIo for Bus {
0x4A => self.ppu.pos.window_y = byte, 0x4A => self.ppu.pos.window_y = byte,
0x4B => self.ppu.pos.window_x = byte, 0x4B => self.ppu.pos.window_x = byte,
0x4D => {} // CGB Specific Register 0x4D => {} // CGB Specific Register
0x4F => {} // CGB VRAM Bank Select
0x50 => { 0x50 => {
// Disable Boot ROM // Disable Boot ROM
if byte != 0 { if byte != 0 {
self.boot = None; self.boot = None;
} }
} }
0x70 => {} // CGB WRAM Bank Select
_ => warn!("Attempted write of {:#04X} to {:#06X} on IO", byte, addr), _ => warn!("Attempted write of {:#04X} to {:#06X} on IO", byte, addr),
}; };
} }

View File

@ -334,7 +334,6 @@ impl Instruction {
Instruction::ADD(target, src) => match (target, src) { Instruction::ADD(target, src) => match (target, src) {
(AddTarget::HL, AddSource::Group1(pair)) => { (AddTarget::HL, AddSource::Group1(pair)) => {
// ADD HL, r16 | Add 16-bit register to HL // ADD HL, r16 | Add 16-bit register to HL
// FIXME: Memory Timings are not properly emulated for this instruction
use Group1RegisterPair::*; use Group1RegisterPair::*;
let mut flags: Flags = *cpu.flags(); let mut flags: Flags = *cpu.flags();
@ -342,10 +341,11 @@ impl Instruction {
BC | DE | HL | SP => { BC | DE | HL | SP => {
let left = cpu.register_pair(RegisterPair::HL); let left = cpu.register_pair(RegisterPair::HL);
let right = cpu.register_pair(pair.as_register_pair()); let right = cpu.register_pair(pair.as_register_pair());
cpu.set_register_pair( let result = Self::add_u16(left, right, &mut flags);
RegisterPair::HL,
Self::add_u16(left, right, &mut flags), cpu.set_register(CpuRegister::L, result as u8);
); cpu.bus.clock();
cpu.set_register(CpuRegister::H, (result >> 8) as u8);
} }
} }
cpu.set_flags(flags); cpu.set_flags(flags);
@ -376,12 +376,15 @@ impl Instruction {
} }
(AddTarget::SP, AddSource::ImmediateSignedByte) => { (AddTarget::SP, AddSource::ImmediateSignedByte) => {
// ADD SP, i8 | Add i8 to stack pointer // ADD SP, i8 | Add i8 to stack pointer
// FIXME: Memory Timings are not properly emulated for this instruction
let mut flags: Flags = *cpu.flags(); let mut flags: Flags = *cpu.flags();
let left = cpu.register_pair(RegisterPair::SP); let left = cpu.register_pair(RegisterPair::SP);
let sum = Self::add_u16_i8(left, Self::imm_byte(cpu) as i8, &mut flags); let sum = Self::add_u16_i8(left, Self::imm_byte(cpu) as i8, &mut flags);
cpu.bus.clock(); // internal
cpu.set_register_pair(RegisterPair::SP, sum); cpu.set_register_pair(RegisterPair::SP, sum);
cpu.bus.clock();
cpu.set_flags(flags); cpu.set_flags(flags);
16 16
} }
@ -423,7 +426,6 @@ impl Instruction {
AllRegisters::Group1(pair) => { AllRegisters::Group1(pair) => {
// INC r16 | Increment 16-bit register // INC r16 | Increment 16-bit register
// Note: No flags are set with this version of the INC instruction // Note: No flags are set with this version of the INC instruction
// FIXME: Memory Timings are not properly emulated for this instruction
use Group1RegisterPair::*; use Group1RegisterPair::*;
match pair { match pair {
@ -431,6 +433,7 @@ impl Instruction {
let pair = pair.as_register_pair(); let pair = pair.as_register_pair();
let left = cpu.register_pair(pair); let left = cpu.register_pair(pair);
cpu.set_register_pair(pair, left.wrapping_add(1)); cpu.set_register_pair(pair, left.wrapping_add(1));
cpu.bus.clock(); // internal
} }
} }
8 8
@ -462,7 +465,6 @@ impl Instruction {
} }
AllRegisters::Group1(pair) => { AllRegisters::Group1(pair) => {
// DEC r16 | Decrement Register Pair // DEC r16 | Decrement Register Pair
// FIXME: Memory Timings are not properly emulated for this instruction
use Group1RegisterPair::*; use Group1RegisterPair::*;
match pair { match pair {
@ -470,6 +472,7 @@ impl Instruction {
let pair = pair.as_register_pair(); let pair = pair.as_register_pair();
let left = cpu.register_pair(pair); let left = cpu.register_pair(pair);
cpu.set_register_pair(pair, left.wrapping_sub(1)); cpu.set_register_pair(pair, left.wrapping_sub(1));
cpu.bus.clock(); // internal
} }
}; };
8 8