14
14
clippy:: all
15
15
) ]
16
16
17
- use std:: borrow:: Cow ;
17
+ use std:: { borrow:: Cow , ops:: { Deref , DerefMut } } ;
18
+
19
+ use serde:: { Deserialize , Serialize } ;
18
20
19
21
use cpu:: { check_bit_const, Cpu , CpuState } ;
20
22
use lookup:: Instruction ;
@@ -31,21 +33,31 @@ pub mod rom;
31
33
pub ( crate ) mod utils;
32
34
33
35
/// Represents a Gameboy color with a cartridge inserted.
34
- #[ derive( Debug , Hash ) ]
36
+ #[ derive( Debug , Hash , Serialize , Deserialize ) ]
35
37
pub struct Gameboy {
36
38
pub mem : MemoryMap ,
37
39
pub ppu : Ppu ,
38
40
cpu : Cpu ,
39
41
}
40
42
43
+ #[ must_use = "Start up sequence is lazy and should be ticked. Dropping this object to complete the startup sequence instantly." ]
44
+ pub struct StartUpSequence {
45
+ gb : Gameboy ,
46
+ op : Instruction ,
47
+ counter : u8 ,
48
+ done : bool ,
49
+ /// The memory that the ROM contains that get mapped over during the startup process.
50
+ remap_mem : StartUpHeaders ,
51
+ }
52
+
41
53
impl Gameboy {
42
54
/// Takes data that represents the data stored on a game cartridge and uses it to construct the
43
- pub fn new < ' a , C : Into < Cow < ' a , [ u8 ] > > > ( cart : C ) -> Self {
44
- Self {
55
+ pub fn new < ' a , C : Into < Cow < ' a , [ u8 ] > > > ( cart : C ) -> StartUpSequence {
56
+ StartUpSequence :: new ( Self {
45
57
mem : MemoryMap :: new ( cart) ,
46
58
cpu : Cpu :: new ( ) ,
47
59
ppu : Ppu :: new ( ) ,
48
- }
60
+ } )
49
61
}
50
62
51
63
pub fn next_frame ( & mut self ) -> FrameSequence < ' _ > {
@@ -109,12 +121,6 @@ impl Gameboy {
109
121
} )
110
122
}
111
123
112
- /// Runs the power-up sequence for the gameboy. During this time, the Gameboy remaps part of
113
- /// the memory to read from the start up sequence.
114
- pub fn start_up ( self ) -> StartUpSequence {
115
- StartUpSequence :: new ( self )
116
- }
117
-
118
124
/// This returns a state that will track the number of required clock ticks it takes to
119
125
/// complete the next operation. If the state is dropped before the required number of ticks,
120
126
/// the intruction is automatically ran.
@@ -232,16 +238,6 @@ impl Drop for StepProcess<'_> {
232
238
}
233
239
}
234
240
235
- #[ must_use = "Start up sequence is lazy and should be ticked. Dropping this object to complete the startup sequence instantly." ]
236
- pub struct StartUpSequence {
237
- gb : Gameboy ,
238
- op : Instruction ,
239
- counter : u8 ,
240
- done : bool ,
241
- /// The memory that the ROM contains that get mapped over during the startup process.
242
- remap_mem : StartUpHeaders ,
243
- }
244
-
245
241
impl StartUpSequence {
246
242
pub fn frame_step ( & mut self ) -> StartUpFrame < ' _ > {
247
243
StartUpFrame :: new ( self )
@@ -252,6 +248,20 @@ impl StartUpSequence {
252
248
}
253
249
}
254
250
251
+ impl Deref for StartUpSequence {
252
+ type Target = Gameboy ;
253
+
254
+ fn deref ( & self ) -> & Self :: Target {
255
+ self . gb ( )
256
+ }
257
+ }
258
+
259
+ impl DerefMut for StartUpSequence {
260
+ fn deref_mut ( & mut self ) -> & mut Self :: Target {
261
+ & mut self . gb
262
+ }
263
+ }
264
+
255
265
impl StartUpSequence {
256
266
fn new ( mut gb : Gameboy ) -> Self {
257
267
let remap_mem = gb. mem . start_up_remap ( ) ;
@@ -409,16 +419,6 @@ mod tests {
409
419
410
420
#[ test_log:: test]
411
421
fn start_up_completion ( ) {
412
- let mut gb = Gameboy :: new ( include_bytes ! ( "../tests/roms/acid/which.gb" ) ) ;
413
- gb. start_up ( ) . complete ( ) ;
414
- }
415
-
416
- #[ test]
417
- fn frame_by_frame_start_up ( ) {
418
- let mut gb = Gameboy :: new ( include_bytes ! ( "../tests/roms/acid/which.gb" ) ) ;
419
- let mut seq = gb. start_up ( ) ;
420
- while !seq. is_complete ( ) {
421
- seq. frame_step ( ) . complete ( ) ;
422
- }
422
+ Gameboy :: new ( include_bytes ! ( "../tests/roms/acid/which.gb" ) ) . complete ( ) ;
423
423
}
424
424
}
0 commit comments