Skip to content

Commit dee01e6

Browse files
author
anton
committed
link cable: add catch up cycles to master gameboy for real time gameplay
1 parent 8f23ba7 commit dee01e6

4 files changed

Lines changed: 19 additions & 4 deletions

File tree

README.de.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Cross-Plattform Emulator-Produktlinie in C++ (NES, DMG, CGB, GBA)
1616
- Die meisten Mapper sind implementiert (MBC1, MBC2, MBC3, MBC5)
1717
- Die Echtzeituhr von entsprechenden Cartridges ist aktuell noch nicht implementiert
1818
- Einige wenige Spiele funktionieren aufgrund von obskuren DMA Timings nicht korrekt
19-
- Link Cable Emulation via TCP, das Master-Gerät läuft je nach Latenz langsamer
19+
- Link Cable Emulation via TCP, das Master-Gerät hat aufgrund von Latenz Audio Glitches
2020
### Nintendo Gameboy Advance (in Arbeit)
2121
- Funktionierende CPU und Bus
2222
- Besteht ARMWrestler, arm.gba und thumb.gba von jsmolka, die meisten SingleStepTests

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Cross-Plattform emulator product line in C++ (NES, DMG, CGB, GBA)
1616
- Most mappers implemented (MBC1, MBC2, MBC3, MBC5)
1717
- RTC is missing
1818
- Some games require very strict DMA timing and don't work correctly because of it
19-
- Link Cable Implementation over TCP, Master Gameboy experiences Slowdown while waiting for packets
19+
- Link Cable Implementation over TCP, Master Gameboy experiences audio glitches because of latency
2020
### Nintendo Gameboy Advance (incomplete)
2121
- Working CPU and Bus
2222
- Passes ARMWrestler, arm.gba and thumb.gba by jsmolka, most SingleStepTests

src/cgb/src/gbc.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ pub(crate) mod gbc{
111111
pub fn clock_until_sample_ready(&mut self){
112112
while !self.audio_sample_ready(){
113113
self.clock();
114+
while self.bus.borrow().enable_catch_up{
115+
self.bus.borrow_mut().clock();
116+
}
114117
if self.bus.borrow().is_halted(){
115118
break;
116119
}

src/cgb/src/gbc/bus.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ pub struct Bus{
6363
awaiting_serial: bool,
6464
serial_count: usize,
6565
serial_min: usize,
66+
pub catch_up_cycles: usize,
67+
pub enable_catch_up: bool,
6668
net_state: Option<cxx::WeakPtr<NetworkState>>,
6769

6870
// mbc3
@@ -98,7 +100,8 @@ impl Bus{
98100
cgb_mode: false, wram_bank: 1, hdma1: 0, hdma2: 0, hdma3: 0, hdma4: 0, hdma5: 0, vram_dma_active: DmaMode::Finished, vram_dma_bytes_remaining: 0,
99101
vram_dma_pointer: 0, br: false, palette_address: 0, palette_address_obj: 0, ff72: 0, ff73: 0, ff74: 0, ff75: 0, mbc1_bank_mode: false, mbc1_magic_register: 0,
100102
sb: 0, sc: 0, hdma_initiated_now: false, cpu_advanced: false, apu: None, watch_breakpoints: false, breakpoints: Vec::new(), breakpoints_op: Vec::new(),
101-
test_mode: false, test_output: None, out_buffer: 0, is_master: false, net_state: None, received: false, sent: false, serial_count: 0, serial_min: 0, awaiting_serial: false
103+
test_mode: false, test_output: None, out_buffer: 0, is_master: false, net_state: None, received: false, sent: false, serial_count: 0, serial_min: 0,
104+
awaiting_serial: false, catch_up_cycles: 0, enable_catch_up: false
102105
}
103106
}
104107

@@ -658,6 +661,13 @@ impl Bus{
658661
}
659662
pub fn clock(&mut self){
660663

664+
if self.catch_up_cycles > 0 && self.enable_catch_up{
665+
self.catch_up_cycles = self.catch_up_cycles.saturating_sub(1);
666+
}
667+
if self.enable_catch_up && self.catch_up_cycles == 0{
668+
self.enable_catch_up = false;
669+
}
670+
661671
if self.watch_breakpoints && self.cpu.as_mut().unwrap().remaining_steps == 0{
662672
let pc_val = self.cpu.as_mut().unwrap().reg_pc;
663673
if self.breakpoints.contains(&pc_val){
@@ -674,7 +684,7 @@ impl Bus{
674684
let dual_speed = self.cpu.as_mut().unwrap().dual_speed_mode;
675685

676686

677-
if (self.sc & 128) > 0{ // Übertragung aktiv
687+
if !self.enable_catch_up && (self.sc & 128) > 0{ // Übertragung aktiv, nicht dabei, aufzuholen
678688
if self.is_master{
679689
self.serial_count = self.serial_count.saturating_add(1);
680690
if self.serial_count >= self.serial_min{
@@ -684,9 +694,11 @@ impl Bus{
684694
self.serial_min = 0;
685695
self.sc = self.sc & !(1 << 7);
686696
self.request_serial();
697+
self.enable_catch_up = true;
687698
}
688699
else{
689700
// Gameboy pausieren
701+
self.catch_up_cycles = self.catch_up_cycles.saturating_add(1);
690702
return;
691703
}
692704
}

0 commit comments

Comments
 (0)