fix(ppu): improve accuracy of timer
This commit is contained in:
		
							
								
								
									
										31
									
								
								src/timer.rs
									
									
									
									
									
								
							
							
						
						
									
										31
									
								
								src/timer.rs
									
									
									
									
									
								
							@@ -21,17 +21,6 @@ impl Timer {
 | 
				
			|||||||
        use State::*;
 | 
					        use State::*;
 | 
				
			||||||
        use TimerSpeed::*;
 | 
					        use TimerSpeed::*;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        match self.state {
 | 
					 | 
				
			||||||
            TIMAOverflow(_) | AbortedTIMAOverflow(_) => self.next(),
 | 
					 | 
				
			||||||
            LoadTMA => {
 | 
					 | 
				
			||||||
                self.counter = self.modulo;
 | 
					 | 
				
			||||||
                self.interrupt = true;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                self.next();
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            Normal => {}
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        self.divider = self.divider.wrapping_add(1);
 | 
					        self.divider = self.divider.wrapping_add(1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Get Bit Position
 | 
					        // Get Bit Position
 | 
				
			||||||
@@ -53,6 +42,17 @@ impl Timer {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        self.and_result = Some(new_result);
 | 
					        self.and_result = Some(new_result);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        match self.state {
 | 
				
			||||||
 | 
					            TIMAOverflow(_) | AbortedTIMAOverflow(_) => self.next(),
 | 
				
			||||||
 | 
					            LoadTIMA => {
 | 
				
			||||||
 | 
					                self.counter = self.modulo;
 | 
				
			||||||
 | 
					                self.interrupt = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                self.next();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            Normal => {}
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /// 0xFF05 | TIMA - Timer Counter
 | 
					    /// 0xFF05 | TIMA - Timer Counter
 | 
				
			||||||
@@ -70,7 +70,7 @@ impl Timer {
 | 
				
			|||||||
                self.counter = byte;
 | 
					                self.counter = byte;
 | 
				
			||||||
                self.state = AbortedTIMAOverflow(step);
 | 
					                self.state = AbortedTIMAOverflow(step);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            LoadTMA => {}
 | 
					            LoadTIMA => { /* Ignored */ }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -95,9 +95,8 @@ impl Timer {
 | 
				
			|||||||
        use State::*;
 | 
					        use State::*;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        self.state = match self.state {
 | 
					        self.state = match self.state {
 | 
				
			||||||
            Normal | LoadTMA => Normal,
 | 
					            Normal | LoadTIMA | AbortedTIMAOverflow(3) => Normal,
 | 
				
			||||||
            AbortedTIMAOverflow(4) => Normal,
 | 
					            TIMAOverflow(3) => LoadTIMA,
 | 
				
			||||||
            TIMAOverflow(4) => LoadTMA,
 | 
					 | 
				
			||||||
            AbortedTIMAOverflow(step) => AbortedTIMAOverflow(step + 1),
 | 
					            AbortedTIMAOverflow(step) => AbortedTIMAOverflow(step + 1),
 | 
				
			||||||
            TIMAOverflow(step) => TIMAOverflow(step + 1),
 | 
					            TIMAOverflow(step) => TIMAOverflow(step + 1),
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@@ -181,5 +180,5 @@ enum State {
 | 
				
			|||||||
    TIMAOverflow(u8),
 | 
					    TIMAOverflow(u8),
 | 
				
			||||||
    AbortedTIMAOverflow(u8),
 | 
					    AbortedTIMAOverflow(u8),
 | 
				
			||||||
    Normal,
 | 
					    Normal,
 | 
				
			||||||
    LoadTMA,
 | 
					    LoadTIMA,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user