@@ -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