@@ -320,19 +320,19 @@ pub struct Ppu {
320320 pub state : u8 ,
321321 /// When making the LY==LYC comparison, uses this value instead of ly to control the comparison
322322 /// timing. This is 0xFF if this will not update the stat.
323- ly_for_compare : u8 ,
323+ pub ly_for_compare : u8 ,
324324
325325 /// A rising edge on this signal causes a STAT interrupt.
326- stat_signal : bool ,
327- ly_compare_signal : bool ,
326+ pub stat_signal : bool ,
327+ pub ly_compare_signal : bool ,
328328 /// use this value instead of the current stat mode when controlling the stat interrupt signal,
329329 /// to control the timing. 0xff means that this will not trigger a interrupt.
330330 ///
331331 /// Mode 0 - Horizontal Blank
332332 /// Mode 1 - Vertical Blank
333333 /// Mode 2 - OAM Search
334334 /// Mode 3 - Drawing pixels
335- stat_mode_for_interrupt : u8 ,
335+ pub stat_mode_for_interrupt : u8 ,
336336
337337 /// Which clock cycle the PPU where last updated
338338 pub last_clock_count : u64 ,
@@ -374,7 +374,7 @@ pub struct Ppu {
374374 /// The x position in the current scanline, from -(8 + scx%8) to 160. Negative values
375375 /// (represented by positives between 241 and 255) are use for detecting sprites that starts
376376 /// to the left of the screen, and for discarding pixels for scrolling.
377- scanline_x : u8 ,
377+ pub scanline_x : u8 ,
378378}
379379
380380fn dbg_fmt_hash < T : std:: hash:: Hash > ( value : & T ) -> impl std:: fmt:: Debug {
@@ -942,6 +942,9 @@ impl Ppu {
942942 // Writing to wx do some time traveling shenanigans. Make sure they are not observable.
943943 debug_assert ! ( ppu. last_clock_count <= gb. clock_count) ;
944944
945+ #[ cfg( feature = "wave_trace" ) ]
946+ gb. vcd_writer . trace_ppu ( ppu. last_clock_count , ppu) . unwrap ( ) ;
947+
945948 ppu. last_clock_count = gb. clock_count ;
946949
947950 if ppu. lcdc & 0x80 == 0 {
@@ -959,9 +962,15 @@ impl Ppu {
959962
960963 if ppu. next_clock_count >= gb. clock_count {
961964 Self :: update_dma ( gb, ppu, gb. clock_count ) ;
965+
966+ #[ cfg( feature = "wave_trace" ) ]
967+ gb. vcd_writer . trace_ppu ( gb. clock_count , ppu) . unwrap ( ) ;
962968 }
963969
964970 while ppu. next_clock_count < gb. clock_count {
971+ #[ cfg( feature = "wave_trace" ) ]
972+ let curr_ppu_clock_count = ppu. next_clock_count ;
973+
965974 Self :: update_dma ( gb, ppu, ppu. next_clock_count ) ;
966975 // println!("state: {}", state);
967976 match ppu. state {
@@ -1026,7 +1035,10 @@ impl Ppu {
10261035 6 => {
10271036 ppu. line_start_clock_count = ppu. next_clock_count ;
10281037 ppu. screen_x = 0 ;
1029- if gb. clock_count > ppu. next_clock_count + 456 {
1038+
1039+ let use_optimization = !cfg ! ( feature = "wave_trace" ) ;
1040+
1041+ if use_optimization && gb. clock_count > ppu. next_clock_count + 456 {
10301042 if ppu. wy == ppu. ly {
10311043 ppu. reach_window = true ;
10321044 }
@@ -1518,6 +1530,9 @@ impl Ppu {
15181530 }
15191531 _ => unreachable ! ( ) ,
15201532 }
1533+
1534+ #[ cfg( feature = "wave_trace" ) ]
1535+ gb. vcd_writer . trace_ppu ( curr_ppu_clock_count, ppu) . unwrap ( ) ;
15211536 }
15221537
15231538 Self :: update_dma ( gb, ppu, gb. clock_count ) ;
0 commit comments