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
67d95c93
Verified
Commit
67d95c93
authored
1 year ago
by
João Magalhães
Browse files
Options
Downloads
Patches
Plain Diff
chore: initial support for loading sav files
parent
fbe1e0ca
No related branches found
No related tags found
1 merge request
!28
Support for .sav RAM files loading in SDL
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
frontends/sdl/src/main.rs
+10
-4
10 additions, 4 deletions
frontends/sdl/src/main.rs
src/util.rs
+51
-1
51 additions, 1 deletion
src/util.rs
with
61 additions
and
5 deletions
frontends/sdl/src/main.rs
+
10
−
4
View file @
67d95c93
...
...
@@ -13,6 +13,7 @@ use boytacean::{
ppu
::{
PaletteInfo
,
PpuMode
},
rom
::
Cartridge
,
serial
::{
NullDevice
,
SerialDevice
},
util
::
replace_ext
,
};
use
chrono
::
Utc
;
use
clap
::
Parser
;
...
...
@@ -202,10 +203,15 @@ impl Emulator {
}
pub
fn
load_rom
(
&
mut
self
,
path
:
Option
<&
str
>
)
{
let
path_res
=
path
.unwrap_or
(
&
self
.rom_path
);
let
rom_path
:
&
str
=
path
.unwrap_or
(
&
self
.rom_path
);
let
ram_path
=
replace_ext
(
rom_path
,
"sav"
)
.unwrap_or
(
""
.to_string
());
let
rom
=
self
.system
.load_rom_file
(
path_res
,
Some
(
"C:/repo.other/boytacean/res/roms.prop/super_mario_2.sav"
),
rom_path
,
if
Path
::
new
(
&
ram_path
)
.exists
()
{
Some
(
&
ram_path
)
}
else
{
None
},
);
println!
(
"========= Cartridge =========
\n
{}
\n
============================="
,
...
...
@@ -216,7 +222,7 @@ impl Emulator {
.set_title
(
format!
(
"{} [{}]"
,
self
.title
,
rom
.title
())
.as_str
())
.unwrap
();
}
self
.rom_path
=
String
::
from
(
path
_res
);
self
.rom_path
=
String
::
from
(
rom_
path
);
}
pub
fn
reset
(
&
mut
self
)
{
...
...
This diff is collapsed.
Click to expand it.
src/util.rs
+
51
−
1
View file @
67d95c93
use
std
::{
cell
::
RefCell
,
fs
::
File
,
io
::
Read
,
rc
::
Rc
};
use
std
::{
cell
::
RefCell
,
fs
::
File
,
io
::
Read
,
path
::
Path
,
rc
::
Rc
};
pub
type
SharedMut
<
T
>
=
Rc
<
RefCell
<
T
>>
;
...
...
@@ -11,3 +11,53 @@ pub fn read_file(path: &str) -> Vec<u8> {
file
.read_to_end
(
&
mut
data
)
.unwrap
();
data
}
/// Replaces the extension in the given path with the provided extension.
/// This function allows for simple associated file discovery.
pub
fn
replace_ext
(
path
:
&
str
,
new_extension
:
&
str
)
->
Option
<
String
>
{
let
file_path
=
Path
::
new
(
path
);
let
parent_dir
=
file_path
.parent
()
?
;
let
file_stem
=
file_path
.file_stem
()
?
;
let
file_extension
=
file_path
.extension
()
?
;
if
file_stem
==
file_extension
{
return
None
;
}
let
new_file_name
=
format!
(
"{}.{}"
,
file_stem
.to_str
()
?
,
new_extension
);
let
new_file_path
=
parent_dir
.join
(
new_file_name
);
Some
(
String
::
from
(
new_file_path
.to_str
()
?
))
}
#[cfg(test)]
mod
tests
{
use
super
::
*
;
#[test]
fn
test_change_extension
()
{
let
new_path
=
replace_ext
(
"/path/to/file.txt"
,
"dat"
)
.unwrap
();
assert_eq!
(
new_path
,
Path
::
new
(
"/path/to"
)
.join
(
"file.dat"
)
.to_str
()
.unwrap
()
);
let
new_path
=
replace_ext
(
"/path/to/file.with.multiple.dots.txt"
,
"dat"
)
.unwrap
();
assert_eq!
(
new_path
,
Path
::
new
(
"/path/to"
)
.join
(
"file.with.multiple.dots.dat"
)
.to_str
()
.unwrap
()
);
let
new_path
=
replace_ext
(
"/path/to/file.without.extension"
,
"dat"
)
.unwrap
();
assert_eq!
(
new_path
,
Path
::
new
(
"/path/to"
)
.join
(
"file.without.dat"
)
.to_str
()
.unwrap
()
);
let
new_path
=
replace_ext
(
"/path/to/directory/"
,
"dat"
);
assert_eq!
(
new_path
,
None
);
}
}
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