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
214ea837
Verified
Commit
214ea837
authored
2 years ago
by
João Magalhães
Browse files
Options
Downloads
Patches
Plain Diff
fix: title offset calculation
To avoid 0x0 characters in ROM title.
parent
fbeb1b02
No related branches found
Branches containing commit
Tags
0.8.0
Tags containing commit
No related merge requests found
Pipeline
#2177
passed
2 years ago
Stage: build
Stage: test
Stage: deploy
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
CHANGELOG.md
+1
-1
1 addition, 1 deletion
CHANGELOG.md
frontends/sdl/src/main.rs
+6
-0
6 additions, 0 deletions
frontends/sdl/src/main.rs
frontends/sdl/src/util.rs
+3
-1
3 additions, 1 deletion
frontends/sdl/src/util.rs
src/rom.rs
+20
-1
20 additions, 1 deletion
src/rom.rs
with
30 additions
and
3 deletions
CHANGELOG.md
+
1
−
1
View file @
214ea837
...
...
@@ -17,7 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
*
*
Bug with ROM title that included 0x0 characters in it
## [0.6.7] - 2023-02-13
...
...
This diff is collapsed.
Click to expand it.
frontends/sdl/src/main.rs
+
6
−
0
View file @
214ea837
...
...
@@ -57,6 +57,10 @@ impl Emulator {
"========= Cartridge =========
\n
{}
\n
=============================
\n
"
,
rom
);
self
.graphics
.window_mut
()
.set_title
(
format!
(
"{} - {}"
,
TITLE
,
rom
.title
())
.as_str
())
.unwrap
();
}
pub
fn
run
(
&
mut
self
)
{
...
...
@@ -189,6 +193,8 @@ fn main() {
let
mut
game_boy
=
GameBoy
::
new
();
game_boy
.load_boot_default
();
// creates a new generic emulator structure loads the default
// ROM file and starts running it
let
mut
emulator
=
Emulator
::
new
(
game_boy
,
SCREEN_SCALE
);
emulator
.load_rom
(
"../../res/roms/pocket.gb"
);
emulator
.run
();
...
...
This diff is collapsed.
Click to expand it.
frontends/sdl/src/util.rs
+
3
−
1
View file @
214ea837
...
...
@@ -3,7 +3,7 @@ use sdl2::{
AudioSubsystem
,
EventPump
,
TimerSubsystem
,
VideoSubsystem
,
};
/// Structure that provide the complete set of Graphics
/// Structure that provide
s
the complete set of Graphics
/// and Sound syb-system ready to be used by the overall
/// emulator infrastructure.
pub
struct
Graphics
{
...
...
@@ -67,6 +67,8 @@ impl Graphics {
}
}
/// Creates an SDL2 Surface structure from the provided
/// bytes that represent an image (eg: an PNG image buffer).
pub
fn
surface_from_bytes
(
bytes
:
&
[
u8
])
->
Surface
{
unsafe
{
let
rw_ops
=
RWops
::
from_bytes
(
bytes
)
.unwrap
();
...
...
This diff is collapsed.
Click to expand it.
src/rom.rs
+
20
−
1
View file @
214ea837
...
...
@@ -222,6 +222,11 @@ pub struct Cartridge {
/// If the RAM access ia enabled, this flag allows
/// control of memory access to avoid corruption.
ram_enabled
:
bool
,
// The final offset of the last character of the title
// that is considered to be non zero (0x0) so that a
// proper safe conversion to UTF-8 string can be done.
title_offset
:
usize
,
}
impl
Cartridge
{
...
...
@@ -235,6 +240,7 @@ impl Cartridge {
rom_offset
:
0x4000
,
ram_offset
:
0x0000
,
ram_enabled
:
false
,
title_offset
:
0x0143
,
}
}
...
...
@@ -312,6 +318,7 @@ impl Cartridge {
self
.ram_offset
=
0x0000
;
self
.set_mbc
();
self
.set_computed
();
self
.set_title_offset
();
self
.allocate_ram
();
self
.set_rom_bank
(
1
);
self
.set_ram_bank
(
0
);
...
...
@@ -326,6 +333,18 @@ impl Cartridge {
self
.ram_bank_count
=
self
.ram_size
()
.ram_banks
();
}
pub
fn
set_title_offset
(
&
mut
self
)
{
let
mut
offset
:
usize
=
0
;
for
byte
in
&
self
.rom_data
[
0x0134
..
0x0143
]
{
if
*
byte
!=
0u8
{
offset
+=
1
;
continue
;
}
break
;
}
self
.title_offset
=
0x0134
+
offset
;
}
fn
allocate_ram
(
&
mut
self
)
{
let
ram_banks
=
max
(
self
.ram_size
()
.ram_banks
(),
1
);
self
.ram_data
=
vec!
[
0u8
;
ram_banks
as
usize
*
RAM_BANK_SIZE
];
...
...
@@ -335,7 +354,7 @@ impl Cartridge {
#[cfg_attr(feature
=
"wasm"
,
wasm_bindgen)]
impl
Cartridge
{
pub
fn
title
(
&
self
)
->
String
{
String
::
from
(
std
::
str
::
from_utf8
(
&
self
.rom_data
[
0x0134
..
0x0143
])
.unwrap
())
String
::
from
(
std
::
str
::
from_utf8
(
&
self
.rom_data
[
0x0134
..
self
.title_offset
])
.unwrap
())
}
pub
fn
rom_type
(
&
self
)
->
RomType
{
...
...
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