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
2aecc268
Verified
Commit
2aecc268
authored
1 year ago
by
João Magalhães
Browse files
Options
Downloads
Patches
Plain Diff
chore: better state manager naming
parent
f5e7a17c
No related branches found
No related tags found
1 merge request
!31
System state save
Pipeline
#3265
passed
1 year ago
Stage: build
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
frontends/sdl/src/main.rs
+3
-3
3 additions, 3 deletions
frontends/sdl/src/main.rs
src/state.rs
+37
-33
37 additions, 33 deletions
src/state.rs
with
40 additions
and
36 deletions
frontends/sdl/src/main.rs
+
3
−
3
View file @
2aecc268
...
@@ -14,7 +14,7 @@ use boytacean::{
...
@@ -14,7 +14,7 @@ use boytacean::{
ppu
::
PaletteInfo
,
ppu
::
PaletteInfo
,
rom
::
Cartridge
,
rom
::
Cartridge
,
serial
::{
NullDevice
,
SerialDevice
},
serial
::{
NullDevice
,
SerialDevice
},
state
::
{
load_state_file
,
save_state_file
}
,
state
::
StateManager
,
util
::{
replace_ext
,
write_file
},
util
::{
replace_ext
,
write_file
},
};
};
use
chrono
::
Utc
;
use
chrono
::
Utc
;
...
@@ -286,7 +286,7 @@ impl Emulator {
...
@@ -286,7 +286,7 @@ impl Emulator {
}
}
fn
save_state
(
&
mut
self
,
file_path
:
&
str
)
{
fn
save_state
(
&
mut
self
,
file_path
:
&
str
)
{
if
let
Err
(
message
)
=
save_stat
e_file
(
file_path
,
&
mut
self
.system
)
{
if
let
Err
(
message
)
=
StateManager
::
sav
e_file
(
file_path
,
&
mut
self
.system
)
{
println!
(
"Error saving state: {}"
,
message
)
println!
(
"Error saving state: {}"
,
message
)
}
else
{
}
else
{
println!
(
"Saved state into: {}"
,
file_path
)
println!
(
"Saved state into: {}"
,
file_path
)
...
@@ -294,7 +294,7 @@ impl Emulator {
...
@@ -294,7 +294,7 @@ impl Emulator {
}
}
fn
load_state
(
&
mut
self
,
file_path
:
&
str
)
{
fn
load_state
(
&
mut
self
,
file_path
:
&
str
)
{
if
let
Err
(
message
)
=
load_state
_file
(
file_path
,
&
mut
self
.system
)
{
if
let
Err
(
message
)
=
StateManager
::
load
_file
(
file_path
,
&
mut
self
.system
)
{
println!
(
"Error loading state: {}"
,
message
)
println!
(
"Error loading state: {}"
,
message
)
}
else
{
}
else
{
println!
(
"Loaded state from: {}"
,
file_path
)
println!
(
"Loaded state from: {}"
,
file_path
)
...
...
This diff is collapsed.
Click to expand it.
src/state.rs
+
37
−
33
View file @
2aecc268
...
@@ -966,37 +966,41 @@ impl Default for BeesMbc {
...
@@ -966,37 +966,41 @@ impl Default for BeesMbc {
}
}
}
}
pub
fn
save_state_file
(
file_path
:
&
str
,
gb
:
&
mut
GameBoy
)
->
Result
<
(),
String
>
{
pub
struct
StateManager
;
let
mut
file
=
match
File
::
create
(
file_path
)
{
Ok
(
file
)
=>
file
,
impl
StateManager
{
Err
(
_
)
=>
return
Err
(
format!
(
"Failed to open file: {}"
,
file_path
)),
pub
fn
save_file
(
file_path
:
&
str
,
gb
:
&
mut
GameBoy
)
->
Result
<
(),
String
>
{
};
let
mut
file
=
match
File
::
create
(
file_path
)
{
let
data
=
save_state
(
gb
)
?
;
Ok
(
file
)
=>
file
,
file
.write_all
(
&
data
)
.unwrap
();
Err
(
_
)
=>
return
Err
(
format!
(
"Failed to open file: {}"
,
file_path
)),
Ok
(())
};
}
let
data
=
Self
::
save
(
gb
)
?
;
file
.write_all
(
&
data
)
.unwrap
();
pub
fn
save_state
(
gb
:
&
mut
GameBoy
)
->
Result
<
Vec
<
u8
>
,
String
>
{
Ok
(())
let
mut
data
:
Vec
<
u8
>
=
vec!
[];
}
BeesState
::
from_gb
(
gb
)
.write
(
&
mut
data
);
Ok
(
data
)
pub
fn
save
(
gb
:
&
mut
GameBoy
)
->
Result
<
Vec
<
u8
>
,
String
>
{
}
let
mut
data
:
Vec
<
u8
>
=
vec!
[];
BeesState
::
from_gb
(
gb
)
.write
(
&
mut
data
);
pub
fn
load_state_file
(
file_path
:
&
str
,
gb
:
&
mut
GameBoy
)
->
Result
<
(),
String
>
{
Ok
(
data
)
let
mut
file
=
match
File
::
open
(
file_path
)
{
}
Ok
(
file
)
=>
file
,
Err
(
_
)
=>
return
Err
(
format!
(
"Failed to open file: {}"
,
file_path
)),
pub
fn
load_file
(
file_path
:
&
str
,
gb
:
&
mut
GameBoy
)
->
Result
<
(),
String
>
{
};
let
mut
file
=
match
File
::
open
(
file_path
)
{
let
mut
data
=
vec!
[];
Ok
(
file
)
=>
file
,
file
.read_to_end
(
&
mut
data
)
.unwrap
();
Err
(
_
)
=>
return
Err
(
format!
(
"Failed to open file: {}"
,
file_path
)),
load_state
(
&
data
,
gb
)
?
;
};
Ok
(())
let
mut
data
=
vec!
[];
}
file
.read_to_end
(
&
mut
data
)
.unwrap
();
Self
::
load
(
&
data
,
gb
)
?
;
pub
fn
load_state
(
data
:
&
[
u8
],
gb
:
&
mut
GameBoy
)
->
Result
<
(),
String
>
{
Ok
(())
let
mut
state
=
BeesState
::
default
();
}
state
.read
(
&
mut
Cursor
::
new
(
data
.to_vec
()));
state
.to_gb
(
gb
)
?
;
pub
fn
load
(
data
:
&
[
u8
],
gb
:
&
mut
GameBoy
)
->
Result
<
(),
String
>
{
print!
(
"{}"
,
state
);
let
mut
state
=
BeesState
::
default
();
Ok
(())
state
.read
(
&
mut
Cursor
::
new
(
data
.to_vec
()));
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