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
440b038b
Verified
Commit
440b038b
authored
1 year ago
by
João Magalhães
Browse files
Options
Downloads
Patches
Plain Diff
chore: initial PoC of Game Genie usage
parent
3983c13f
No related branches found
No related tags found
1 merge request
!25
Game Genie support
Pipeline
#2866
failed
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
-1
4 additions, 1 deletion
src/gb.rs
src/rom.rs
+45
-0
45 additions, 0 deletions
src/rom.rs
with
49 additions
and
1 deletion
src/gb.rs
+
4
−
1
View file @
440b038b
...
...
@@ -969,7 +969,10 @@ impl GameBoy {
}
pub
fn
load_rom
(
&
mut
self
,
data
:
&
[
u8
])
->
&
Cartridge
{
let
rom
=
Cartridge
::
from_data
(
data
);
let
mut
rom
=
Cartridge
::
from_data
(
data
);
//rom.add_genie_code("00A-17B-C49").unwrap(); // SML
//rom.add_genie_code("008-60A-E6E").unwrap(); // SML
rom
.add_genie_code
(
"001-40C-E6E"
)
.unwrap
();
self
.mmu
()
.set_rom
(
rom
);
self
.mmu
()
.rom
()
}
...
...
This diff is collapsed.
Click to expand it.
src/rom.rs
+
45
−
0
View file @
440b038b
use
core
::
fmt
;
use
std
::{
cmp
::
max
,
collections
::
HashMap
,
fmt
::{
Display
,
Formatter
},
};
...
...
@@ -208,6 +209,14 @@ impl Display for CgbMode {
}
}
#[derive(Clone)]
pub
struct
GameGenieCode
{
code
:
String
,
address
:
u16
,
new_data
:
u8
,
old_data
:
u8
,
}
/// Structure that defines the ROM and ROM contents
/// of a Game Boy cartridge. Should correctly address
/// the specifics of all the major MBCs (Memory Bank
...
...
@@ -227,6 +236,8 @@ pub struct Cartridge {
/// RAM and ROM access on the current cartridge.
mbc
:
&
'static
Mbc
,
genie_codes
:
HashMap
<
u16
,
GameGenieCode
>
,
/// The number of ROM banks (of 8KB) that are available
/// to the current cartridge, this is a computed value
/// to allow improved performance.
...
...
@@ -261,6 +272,7 @@ impl Cartridge {
rom_data
:
vec!
[],
ram_data
:
vec!
[],
mbc
:
&
NO_MBC
,
genie_codes
:
HashMap
::
new
(),
rom_bank_count
:
0
,
ram_bank_count
:
0
,
rom_offset
:
0x4000
,
...
...
@@ -282,6 +294,16 @@ impl Cartridge {
}
pub
fn
read
(
&
self
,
addr
:
u16
)
->
u8
{
//if addr == 0x4A17 {
// println!("cenas");
// return 0x00;
//} // @todo hack for gamegenie
if
self
.genie_codes
.contains_key
(
&
addr
)
{
let
game_genie_code
=
self
.genie_codes
.get
(
&
addr
)
.unwrap
();
return
game_genie_code
.new_data
;
}
match
addr
&
0xf000
{
0x0000
|
0x1000
|
0x2000
|
0x3000
|
0x4000
|
0x5000
|
0x6000
|
0x7000
=>
{
(
self
.mbc.read_rom
)(
self
,
addr
)
...
...
@@ -389,6 +411,29 @@ impl Cartridge {
let
ram_banks
=
max
(
self
.ram_size
()
.ram_banks
(),
1
);
self
.ram_data
=
vec!
[
0u8
;
ram_banks
as
usize
*
RAM_BANK_SIZE
];
}
pub
fn
add_genie_code
(
&
mut
self
,
code
:
&
str
)
->
Result
<&
GameGenieCode
,
&
str
>
{
if
code
.len
()
!=
11
{
return
Err
(
"Invalid Game Genie code length"
);
}
let
new_data_slice
=
&
code
[
0
..=
1
];
let
new_data
=
u8
::
from_str_radix
(
new_data_slice
,
16
)
.unwrap
();
let
address_slice
=
format!
(
"{}{}{}"
,
&
code
[
6
..=
6
],
&
code
[
2
..=
2
],
&
code
[
4
..=
5
]);
let
address
=
u16
::
from_str_radix
(
address_slice
.as_str
(),
16
)
.unwrap
()
^
0xf000
;
let
game_genie_code
=
GameGenieCode
{
code
:
String
::
from
(
code
),
address
:
address
,
new_data
:
new_data
,
old_data
:
new_data
,
};
self
.genie_codes
.insert
(
address
,
game_genie_code
);
Ok
(
self
.genie_codes
.get
(
&
address
)
.unwrap
())
}
}
#[cfg_attr(feature
=
"wasm"
,
wasm_bindgen)]
...
...
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