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
4160fe52
Verified
Commit
4160fe52
authored
2 years ago
by
João Magalhães
Browse files
Options
Downloads
Patches
Plain Diff
feat: for RAM access control
parent
b2b5bdbe
No related branches found
No related tags found
No related merge requests found
Pipeline
#977
passed
2 years ago
Stage: build
Changes
1
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/rom.rs
+18
-3
18 additions, 3 deletions
src/rom.rs
with
18 additions
and
3 deletions
src/rom.rs
+
18
−
3
View file @
4160fe52
...
...
@@ -149,6 +149,10 @@ pub struct Cartridge {
/// The offset address to the ERAM bank that is
/// currently in use by the ROM cartridge.
ram_offset
:
usize
,
/// If the RAM access ia enabled, this flag allows
/// control of memory access to avoid corruption.
ram_enabled
:
bool
,
}
impl
Cartridge
{
...
...
@@ -159,6 +163,7 @@ impl Cartridge {
mbc
:
&
NO_MBC
,
rom_offset
:
0x4000
,
ram_offset
:
0x0000
,
ram_enabled
:
false
,
}
}
...
...
@@ -317,9 +322,9 @@ pub static NO_MBC: Mbc = Mbc {
_
=>
panic!
(
"Writing to unknown Cartridge ROM location 0x{:04x}"
,
addr
),
};
},
read_ram
:
|
rom
:
&
Cartridge
,
addr
:
u16
|
->
u8
{
rom
.ram_data
[(
addr
&
0x
1fff
)
as
usize
]
},
read_ram
:
|
rom
:
&
Cartridge
,
addr
:
u16
|
->
u8
{
rom
.ram_data
[(
addr
-
0x
a000
)
as
usize
]
},
write_ram
:
|
rom
:
&
mut
Cartridge
,
addr
:
u16
,
value
:
u8
|
{
rom
.ram_data
[(
addr
&
0x
1fff
)
as
usize
]
=
value
;
rom
.ram_data
[(
addr
-
0x
a000
)
as
usize
]
=
value
;
},
};
...
...
@@ -336,9 +341,11 @@ pub static MBC1: Mbc = Mbc {
},
write_rom
:
|
rom
:
&
mut
Cartridge
,
addr
:
u16
,
value
:
u8
|
{
match
addr
&
0xf000
{
// RAM enabled flag
0x0000
|
0x1000
=>
{
println!
(
"RAM
enable =
> {}"
,
value
)
;
rom
.ram_
enable
d
=
(
value
&
0x0f
)
==
0x0a
;
}
// ROM bank selection 5 lower bits
0x2000
|
0x3000
=>
{
let
mut
rom_bank
=
value
&
0x1f
;
// @todo this is slow and must be pre-computed in cartridge
...
...
@@ -348,6 +355,7 @@ pub static MBC1: Mbc = Mbc {
}
rom
.set_rom_bank
(
rom_bank
);
}
// RAM bank selection and ROM bank selection upper bits
0x4000
|
0x5000
=>
{
let
ram_bank
=
value
&
0x03
;
rom
.set_ram_bank
(
ram_bank
);
...
...
@@ -360,9 +368,16 @@ pub static MBC1: Mbc = Mbc {
}
},
read_ram
:
|
rom
:
&
Cartridge
,
addr
:
u16
|
->
u8
{
if
!
rom
.ram_enabled
{
return
0xff
;
}
rom
.ram_data
[
rom
.ram_offset
+
(
addr
-
0xa000
)
as
usize
]
},
write_ram
:
|
rom
:
&
mut
Cartridge
,
addr
:
u16
,
value
:
u8
|
{
if
!
rom
.ram_enabled
{
debugln!
(
"Attempt to write to ERAM while write protect is active"
);
return
;
}
rom
.ram_data
[
rom
.ram_offset
+
(
addr
-
0xa000
)
as
usize
]
=
value
;
},
};
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