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
f4982fb7
Verified
Commit
f4982fb7
authored
1 year ago
by
João Magalhães
Browse files
Options
Downloads
Patches
Plain Diff
fix: BESS loading issue
parent
9928b893
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Pipeline
#3352
passed
1 year ago
Stage: build
Stage: test
Stage: deploy
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
CHANGELOG.md
+1
-0
1 addition, 0 deletions
CHANGELOG.md
src/state.rs
+33
-6
33 additions, 6 deletions
src/state.rs
src/util.rs
+19
-1
19 additions, 1 deletion
src/util.rs
with
53 additions
and
7 deletions
CHANGELOG.md
+
1
−
0
View file @
f4982fb7
...
...
@@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
*
Breaking issue with Libretro frontend and Linux
*
Fix
`window_counter`
issue in PPU
*
Issue with BESS header testing
## [0.9.13] - 2023-08-01
...
...
This diff is collapsed.
Click to expand it.
src/state.rs
+
33
−
6
View file @
f4982fb7
...
...
@@ -6,6 +6,7 @@ use std::{
fs
::
File
,
io
::{
Cursor
,
Read
,
Seek
,
SeekFrom
,
Write
},
mem
::
size_of
,
vec
,
};
use
crate
::{
...
...
@@ -460,7 +461,7 @@ impl BessState {
/// buffer represents a valid BESS (Best Effort Save State)
/// file structure, thought magic string validation.
pub
fn
is_bess
(
data
:
&
mut
Cursor
<
Vec
<
u8
>>
)
->
bool
{
data
.seek
(
SeekFrom
::
End
(
-
8
))
.unwrap
();
data
.seek
(
SeekFrom
::
End
(
-
4
))
.unwrap
();
let
mut
buffer
=
[
0x00
;
4
];
data
.read_exact
(
&
mut
buffer
)
.unwrap
();
let
magic
=
u32
::
from_le_bytes
(
buffer
);
...
...
@@ -911,8 +912,8 @@ impl Serialize for BessInfo {
impl
State
for
BessInfo
{
fn
from_gb
(
gb
:
&
mut
GameBoy
)
->
Result
<
Self
,
String
>
{
Ok
(
Self
::
new
(
&
gb
.cartridge_i
()
.rom_data
()[
0x134
..=
0x143
],
&
gb
.cartridge_i
()
.rom_data
()[
0x14e
..=
0x14f
],
&
gb
.cartridge_i
()
.rom_data
()[
0x
0
134
..=
0x
0
143
],
&
gb
.cartridge_i
()
.rom_data
()[
0x
0
14e
..=
0x
0
14f
],
))
}
...
...
@@ -1495,7 +1496,7 @@ impl StateManager {
}
else
if
BessState
::
is_bess
(
data
)
{
SaveStateFormat
::
Bess
}
else
{
return
Err
(
String
::
from
(
"Unknown state file"
));
return
Err
(
String
::
from
(
"Unknown
save
state file
format
"
));
}
}
};
...
...
@@ -1528,7 +1529,7 @@ impl StateManager {
Ok
(
state
)
}
/// Obtains the thumbnail of the state file, this thumbnail is
/// Obtains the thumbnail of the
save
state file, this thumbnail is
/// stored in raw RGB format.
/// This operation is currently only supported for the BOS format.
pub
fn
thumbnail
(
data
:
&
[
u8
],
format
:
Option
<
SaveStateFormat
>
)
->
Result
<
Vec
<
u8
>
,
String
>
{
...
...
@@ -1541,7 +1542,7 @@ impl StateManager {
}
else
if
BessState
::
is_bess
(
data
)
{
SaveStateFormat
::
Bess
}
else
{
return
Err
(
String
::
from
(
"Unknown state file"
));
return
Err
(
String
::
from
(
"Unknown
save
state file
format
"
));
}
}
};
...
...
@@ -1555,3 +1556,29 @@ impl StateManager {
}
}
}
#[cfg(test)]
mod
tests
{
use
super
::
*
;
use
crate
::
gb
::
GameBoy
;
#[test]
fn
test_load_bos
()
{
let
mut
gb
=
GameBoy
::
default
();
gb
.load
(
true
);
gb
.load_rom_file
(
"res/roms/test/firstwhite.gb"
,
None
);
let
data
=
StateManager
::
save
(
&
mut
gb
,
Some
(
SaveStateFormat
::
Bos
))
.unwrap
();
StateManager
::
load
(
&
data
,
&
mut
gb
,
Some
(
SaveStateFormat
::
Bos
))
.unwrap
();
StateManager
::
load
(
&
data
,
&
mut
gb
,
None
)
.unwrap
();
}
#[test]
fn
test_load_bess
()
{
let
mut
gb
=
GameBoy
::
default
();
gb
.load
(
true
);
gb
.load_rom_file
(
"res/roms/test/firstwhite.gb"
,
None
);
let
data
=
StateManager
::
save
(
&
mut
gb
,
Some
(
SaveStateFormat
::
Bess
))
.unwrap
();
StateManager
::
load
(
&
data
,
&
mut
gb
,
Some
(
SaveStateFormat
::
Bess
))
.unwrap
();
StateManager
::
load
(
&
data
,
&
mut
gb
,
None
)
.unwrap
();
}
}
This diff is collapsed.
Click to expand it.
src/util.rs
+
19
−
1
View file @
f4982fb7
...
...
@@ -125,7 +125,7 @@ pub fn get_timestamp() -> u64 {
mod
tests
{
use
std
::
path
::
Path
;
use
super
::
replace_ext
;
use
super
::
{
capitalize
,
replace_ext
}
;
#[test]
fn
test_change_extension
()
{
...
...
@@ -156,4 +156,22 @@ mod tests {
let
new_path
=
replace_ext
(
"/path/to/directory/"
,
"dat"
);
assert_eq!
(
new_path
,
None
);
}
#[test]
fn
test_capitalize_empty_string
()
{
let
result
=
capitalize
(
""
);
assert_eq!
(
result
,
""
);
}
#[test]
fn
test_capitalize_single_character
()
{
let
result
=
capitalize
(
"a"
);
assert_eq!
(
result
,
"A"
);
}
#[test]
fn
test_capitalize_multiple_characters
()
{
let
result
=
capitalize
(
"hello, world!"
);
assert_eq!
(
result
,
"Hello, world!"
);
}
}
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