Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
boytacean
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
João Magalhães
boytacean
Commits
c368556c
Verified
Commit
c368556c
authored
1 year ago
by
João Magalhães
Browse files
Options
Downloads
Patches
Plain Diff
chore: stricter loading of state files
parent
75a1e293
No related branches found
No related tags found
1 merge request
!31
System state save
Pipeline
#3234
passed
1 year ago
Stage: build
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/gb.rs
+4
-0
4 additions, 0 deletions
src/gb.rs
src/state.rs
+37
-14
37 additions, 14 deletions
src/state.rs
with
41 additions
and
14 deletions
src/gb.rs
+
4
−
0
View file @
c368556c
...
...
@@ -945,6 +945,10 @@ impl GameBoy {
self
.mmu
()
.rom
()
}
pub
fn
rom_i
(
&
self
)
->
&
Cartridge
{
self
.mmu_i
()
.rom_i
()
}
pub
fn
frame_buffer
(
&
mut
self
)
->
&
[
u8
;
FRAME_BUFFER_SIZE
]
{
&
(
self
.ppu
()
.frame_buffer
)
}
...
...
This diff is collapsed.
Click to expand it.
src/state.rs
+
37
−
14
View file @
c368556c
...
...
@@ -15,7 +15,7 @@ pub trait Serialize {
pub
trait
State
{
fn
from_gb
(
gb
:
&
GameBoy
)
->
Self
;
fn
to_gb
(
&
self
,
gb
:
&
mut
GameBoy
);
fn
to_gb
(
&
self
,
gb
:
&
mut
GameBoy
)
->
Result
<
(),
String
>
;
}
#[derive(Default)]
...
...
@@ -94,11 +94,12 @@ impl State for BeesState {
}
}
fn
to_gb
(
&
self
,
gb
:
&
mut
GameBoy
)
{
self
.verify
()
.unwrap
();
self
.name
.to_gb
(
gb
);
self
.info
.to_gb
(
gb
);
self
.core
.to_gb
(
gb
);
fn
to_gb
(
&
self
,
gb
:
&
mut
GameBoy
)
->
Result
<
(),
String
>
{
self
.verify
()
?
;
self
.name
.to_gb
(
gb
)
?
;
self
.info
.to_gb
(
gb
)
?
;
self
.core
.to_gb
(
gb
)
?
;
Ok
(())
}
}
...
...
@@ -268,7 +269,9 @@ impl State for BeesName {
Self
::
new
(
format!
(
"{} v{}"
,
Info
::
name
(),
Info
::
version
()))
}
fn
to_gb
(
&
self
,
_gb
:
&
mut
GameBoy
)
{}
fn
to_gb
(
&
self
,
_gb
:
&
mut
GameBoy
)
->
Result
<
(),
String
>
{
Ok
(())
}
}
impl
Default
for
BeesName
{
...
...
@@ -296,7 +299,12 @@ impl BeesInfo {
}
pub
fn
title
(
&
self
)
->
String
{
String
::
from_utf8
(
Vec
::
from
(
&
self
.title
[
..
]))
.unwrap
()
String
::
from
(
String
::
from_utf8
(
Vec
::
from
(
&
self
.title
[
..
]))
.unwrap
()
.trim_matches
(
char
::
from
(
0
))
.trim
(),
)
}
}
...
...
@@ -322,7 +330,18 @@ impl State for BeesInfo {
)
}
fn
to_gb
(
&
self
,
_gb
:
&
mut
GameBoy
)
{}
fn
to_gb
(
&
self
,
gb
:
&
mut
GameBoy
)
->
Result
<
(),
String
>
{
if
self
.title
()
!=
gb
.rom_i
()
.title
()
{
return
Err
(
format!
(
"Invalid ROM loaded, expected '{}' (len {}) got '{}' (len {})"
,
self
.title
(),
self
.title
()
.len
(),
gb
.rom_i
()
.title
(),
gb
.rom_i
()
.title
()
.len
(),
));
}
Ok
(())
}
}
impl
Default
for
BeesInfo
{
...
...
@@ -519,7 +538,7 @@ impl State for BeesCore {
)
}
fn
to_gb
(
&
self
,
gb
:
&
mut
GameBoy
)
{
fn
to_gb
(
&
self
,
gb
:
&
mut
GameBoy
)
->
Result
<
(),
String
>
{
gb
.cpu
()
.set_pc
(
self
.pc
);
gb
.cpu
()
.set_af
(
self
.af
);
gb
.cpu
()
.set_bc
(
self
.bc
);
...
...
@@ -539,6 +558,8 @@ impl State for BeesCore {
gb
.mmu
()
.write_many
(
0xff80
,
&
self
.hram.buffer
);
//@TODO the background palettes are missing - CGB only
//@TODO the object palettes are missing - CGB only
Ok
(())
}
}
...
...
@@ -568,16 +589,18 @@ pub fn save_state(gb: &GameBoy) -> Vec<u8> {
data
}
pub
fn
load_state_file
(
file_path
:
&
str
,
gb
:
&
mut
GameBoy
)
{
pub
fn
load_state_file
(
file_path
:
&
str
,
gb
:
&
mut
GameBoy
)
->
Result
<
(),
String
>
{
let
mut
file
=
File
::
open
(
file_path
)
.unwrap
();
let
mut
data
=
vec!
[];
file
.read_to_end
(
&
mut
data
)
.unwrap
();
load_state
(
&
data
,
gb
);
load_state
(
&
data
,
gb
)
?
;
Ok
(())
}
pub
fn
load_state
(
data
:
&
[
u8
],
gb
:
&
mut
GameBoy
)
{
pub
fn
load_state
(
data
:
&
[
u8
],
gb
:
&
mut
GameBoy
)
->
Result
<
(),
String
>
{
let
mut
state
=
BeesState
::
default
();
state
.load
(
&
mut
Cursor
::
new
(
data
.to_vec
()));
state
.to_gb
(
gb
);
state
.to_gb
(
gb
)
?
;
print!
(
"{}"
,
state
);
Ok
(())
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment