Skip to content

Commit bab8e45

Browse files
committed
Upgraded dependencies and cleaned up
1 parent 36977f1 commit bab8e45

File tree

9 files changed

+192
-189
lines changed

9 files changed

+192
-189
lines changed

Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[workspace]
22
members = [
33
"spirit",
4-
"appirition",
54
"tombstone",
65
"ghast",
76
]

spirit/Cargo.toml

+1-3
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@ name = "spirit"
33
version = "0.1.0"
44
edition = "2021"
55

6-
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7-
86
[dependencies]
97
# serde_json = { version = "1.0" }
108
# hex = { version = "0.4", features = ["serde"] }
11-
derive_more = "1.0"
9+
derive_more = { version = "1.0", features = ["full"] }
1210
array-concat = "0.5.2"
1311
# once_cell = "1.19"
1412
tracing = "0.1.40"

spirit/src/cpu.rs

+16-9
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use std::{
88
sync::{Mutex, OnceLock},
99
};
1010

11+
use serde::{Deserialize, Serialize};
1112
use tracing::{info, info_span, trace};
1213

1314
use crate::{
@@ -19,9 +20,11 @@ use crate::{
1920
mem::MemoryMap,
2021
};
2122

22-
#[derive(Debug, Default, Hash, Clone, PartialEq, Eq, derive_more::Display)]
23+
#[derive(
24+
Debug, Default, Hash, Clone, PartialEq, Eq, derive_more::Display, Serialize, Deserialize,
25+
)]
2326
#[display(
24-
fmt = "CPU {{ A=0x{:0>2X} F={} B=0x{:0>2X} C=0x{:0>2X} D=0x{:0>2X} E=0x{:0>2X} H=0x{:0>2X} L=0x{:0>2X} SP=0x{:0>2X} PC=0x{:0>2X} IME={} Done={} }}",
27+
"CPU {{ A=0x{:0>2X} F={} B=0x{:0>2X} C=0x{:0>2X} D=0x{:0>2X} E=0x{:0>2X} H=0x{:0>2X} L=0x{:0>2X} SP=0x{:0>2X} PC=0x{:0>2X} IME={} Done={} }}",
2528
a,
2629
f,
2730
b,
@@ -54,7 +57,9 @@ pub struct Cpu {
5457
pub state: CpuState,
5558
}
5659

57-
#[derive(Debug, Default, Hash, Clone, Copy, PartialEq, Eq, derive_more::Display)]
60+
#[derive(
61+
Debug, Default, Hash, Clone, Copy, PartialEq, Eq, derive_more::Display, Serialize, Deserialize,
62+
)]
5863
#[repr(u8)]
5964
pub enum CpuState {
6065
#[default]
@@ -81,13 +86,15 @@ pub enum RegisterFlags {
8186
C,
8287
}
8388

84-
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Hash, derive_more::Display)]
89+
#[derive(
90+
Debug, Clone, Copy, PartialEq, Eq, Default, Hash, derive_more::Display, Serialize, Deserialize,
91+
)]
8592
#[display(
86-
fmt = "Flags(Z={} N={} H={} C={})",
87-
"*z as u8",
88-
"*n as u8",
89-
"*h as u8",
90-
"*c as u8"
93+
"Flags(Z={} N={} H={} C={})",
94+
*z as u8,
95+
*n as u8,
96+
*h as u8,
97+
*c as u8
9198
)]
9299
pub struct Flags {
93100
/// The zero flag

spirit/src/lib.rs

+32-32
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
clippy::all
1515
)]
1616

17-
use std::borrow::Cow;
17+
use std::{borrow::Cow, ops::{Deref, DerefMut}};
18+
19+
use serde::{Deserialize, Serialize};
1820

1921
use cpu::{check_bit_const, Cpu, CpuState};
2022
use lookup::Instruction;
@@ -31,21 +33,31 @@ pub mod rom;
3133
pub(crate) mod utils;
3234

3335
/// Represents a Gameboy color with a cartridge inserted.
34-
#[derive(Debug, Hash)]
36+
#[derive(Debug, Hash, Serialize, Deserialize)]
3537
pub struct Gameboy {
3638
pub mem: MemoryMap,
3739
pub ppu: Ppu,
3840
cpu: Cpu,
3941
}
4042

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+
4153
impl Gameboy {
4254
/// 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 {
4557
mem: MemoryMap::new(cart),
4658
cpu: Cpu::new(),
4759
ppu: Ppu::new(),
48-
}
60+
})
4961
}
5062

5163
pub fn next_frame(&mut self) -> FrameSequence<'_> {
@@ -109,12 +121,6 @@ impl Gameboy {
109121
})
110122
}
111123

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-
118124
/// This returns a state that will track the number of required clock ticks it takes to
119125
/// complete the next operation. If the state is dropped before the required number of ticks,
120126
/// the intruction is automatically ran.
@@ -232,16 +238,6 @@ impl Drop for StepProcess<'_> {
232238
}
233239
}
234240

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-
245241
impl StartUpSequence {
246242
pub fn frame_step(&mut self) -> StartUpFrame<'_> {
247243
StartUpFrame::new(self)
@@ -252,6 +248,20 @@ impl StartUpSequence {
252248
}
253249
}
254250

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+
255265
impl StartUpSequence {
256266
fn new(mut gb: Gameboy) -> Self {
257267
let remap_mem = gb.mem.start_up_remap();
@@ -409,16 +419,6 @@ mod tests {
409419

410420
#[test_log::test]
411421
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();
423423
}
424424
}

0 commit comments

Comments
 (0)