@@ -12,6 +12,7 @@ pub use crate::io::{
12
12
pub struct GBA {
13
13
cpu : CPU ,
14
14
io : IO ,
15
+ next_frame_cycle : usize ,
15
16
}
16
17
17
18
impl GBA {
@@ -23,14 +24,19 @@ impl GBA {
23
24
( GBA {
24
25
cpu : CPU :: new ( false , & mut io) ,
25
26
io,
27
+ next_frame_cycle : 0 ,
26
28
} , pixels, debug_windows_spec)
27
29
}
28
30
29
- pub fn emulate ( & mut self ) {
31
+ pub fn emulate_frame ( & mut self ) {
30
32
self . io . poll_keypad_updates ( ) ;
31
- self . io . run_dma ( ) ;
32
- self . cpu . handle_irq ( & mut self . io ) ;
33
- self . cpu . emulate_instr ( & mut self . io ) ;
33
+ // TODO: This will overflow on 32-bit systems
34
+ self . next_frame_cycle += CLOCKS_PER_FRAME ;
35
+ while self . io . cycle < self . next_frame_cycle {
36
+ self . io . run_dma ( ) ;
37
+ self . cpu . handle_irq ( & mut self . io ) ;
38
+ self . cpu . emulate_instr ( & mut self . io ) ;
39
+ }
34
40
}
35
41
36
42
pub fn peek_mem ( & self , region : VisibleMemoryRegion , addr : usize ) -> u8 {
@@ -45,7 +51,10 @@ pub const SCALE: usize = 2;
45
51
pub const AUDIO_SAMPLE_RATE : usize = 0x8000 ;
46
52
pub const AUDIO_BUFFER_LEN : usize = 4096 ;
47
53
pub const CLOCK_FREQ : usize = 1 << 24 ;
48
- pub const FRAME_PERIOD : std:: time:: Duration = std:: time:: Duration :: from_nanos ( 1e9 as u64 * 280896 / CLOCK_FREQ as u64 ) ;
54
+ pub const CLOCKS_PER_FRAME : usize = 280896 ;
55
+ pub const FRAME_PERIOD : std:: time:: Duration = std:: time:: Duration :: from_nanos (
56
+ 1e9 as u64 * CLOCKS_PER_FRAME as u64 / CLOCK_FREQ as u64
57
+ ) ;
49
58
50
59
#[ derive( Clone , Copy ) ]
51
60
pub enum VisibleMemoryRegion {
0 commit comments