pretends to go double speed

This commit is contained in:
Alex Janka 2023-04-22 19:09:33 +10:00
parent f1ce5cfc9f
commit ec6a7d02b2
4 changed files with 17 additions and 16 deletions

View file

@ -521,7 +521,7 @@ where
R: Renderer<ColourFormat>, R: Renderer<ColourFormat>,
C: PocketCamera + Send + 'static, C: PocketCamera + Send + 'static,
{ {
pub fn increment_timers(&mut self, machine_cycles: u8) { pub fn increment_timers(&mut self, machine_cycles: usize) {
let steps = (machine_cycles as usize) * 4; let steps = (machine_cycles as usize) * 4;
self.cycle_count += steps; self.cycle_count += steps;

View file

@ -32,14 +32,16 @@ where
.map_or(false, |v| v.double_speed.current) .map_or(false, |v| v.double_speed.current)
} }
pub(crate) fn should_switch_speed(&mut self) -> bool { pub(crate) fn try_switch_speed(&mut self) -> bool {
if let Some(cgb_peripherals) = &mut self.cgb_peripherals { if let Some(cgb_peripherals) = &mut self.cgb_peripherals {
if cgb_peripherals.double_speed.prepared && !cgb_peripherals.double_speed.current { if cgb_peripherals.double_speed.prepared && !cgb_peripherals.double_speed.current {
println!("switching to double speed");
cgb_peripherals.double_speed.current = true; cgb_peripherals.double_speed.current = true;
cgb_peripherals.double_speed.prepared = false; cgb_peripherals.double_speed.prepared = false;
return true; return true;
} else if cgb_peripherals.double_speed.prepared && cgb_peripherals.double_speed.current } else if cgb_peripherals.double_speed.prepared && cgb_peripherals.double_speed.current
{ {
println!("switching to normal speed");
cgb_peripherals.double_speed.current = false; cgb_peripherals.double_speed.current = false;
cgb_peripherals.double_speed.prepared = false; cgb_peripherals.double_speed.prepared = false;
return true; return true;

View file

@ -98,15 +98,9 @@ where
} }
// double this if in double speed mode // double this if in double speed mode
let mut vram_dma_cycles = self.memory.vram_dma_tick(); let vram_dma_cycles = self.memory.vram_dma_tick();
while vram_dma_cycles > 0 { if vram_dma_cycles > 0 {
let cycles = if vram_dma_cycles > 0xFF { self.increment_timers(vram_dma_cycles);
0xFF
} else {
vram_dma_cycles as u8
};
vram_dma_cycles -= cycles as usize;
self.increment_timers(cycles);
let interrupt_cycles = self.handle_interrupts(); let interrupt_cycles = self.handle_interrupts();
self.increment_timers(interrupt_cycles); self.increment_timers(interrupt_cycles);
} }
@ -152,7 +146,7 @@ where
} }
} }
fn handle_interrupts(&mut self) -> u8 { fn handle_interrupts(&mut self) -> usize {
if self.memory.ime { if self.memory.ime {
if let Some(interrupt) = self.memory.interrupts.get_next_interrupt() { if let Some(interrupt) = self.memory.interrupts.get_next_interrupt() {
// if interrupt != Interrupt::Vblank { // if interrupt != Interrupt::Vblank {

View file

@ -15,7 +15,7 @@ where
R: Renderer<ColourFormat>, R: Renderer<ColourFormat>,
C: PocketCamera + Send + 'static, C: PocketCamera + Send + 'static,
{ {
pub fn run_opcode(&mut self, opcode: u8) -> u8 { pub fn run_opcode(&mut self, opcode: u8) -> usize {
match opcode { match opcode {
0x00 => { 0x00 => {
// noop // noop
@ -93,7 +93,12 @@ where
0x10 => { 0x10 => {
// stop // stop
// 1 cycle long // 1 cycle long
panic!("stop instruction"); if self.memory.try_switch_speed() {
2050
} else {
0
}
// panic!("stop instruction");
} }
0x11 => { 0x11 => {
self.reg.de = self.ld_immediate_word(); self.reg.de = self.ld_immediate_word();
@ -1231,7 +1236,7 @@ where
} }
} }
fn cb_subop(&mut self, subop: u8) -> u8 { fn cb_subop(&mut self, subop: u8) -> usize {
match subop { match subop {
0x00 => { 0x00 => {
let val = self.rlc(self.reg.get_8(Reg8::B)); let val = self.rlc(self.reg.get_8(Reg8::B));
@ -2453,6 +2458,6 @@ where
} }
} }
fn undefined(opcode: u8) -> u8 { fn undefined(opcode: u8) -> usize {
panic!("Undefined behaviour: opcode {opcode:#X}"); panic!("Undefined behaviour: opcode {opcode:#X}");
} }