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
328c167d
Verified
Commit
328c167d
authored
1 year ago
by
João Magalhães
Browse files
Options
Downloads
Patches
Plain Diff
feat: new redundant code added
parent
3055417e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!16
Support for Game Boy Color (CGB) 😎🖍️
Pipeline
#2564
failed
1 year ago
Stage: build
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/gb.rs
+51
-17
51 additions, 17 deletions
src/gb.rs
with
51 additions
and
17 deletions
src/gb.rs
+
51
−
17
View file @
328c167d
...
@@ -155,6 +155,31 @@ impl GameBoyConfig {
...
@@ -155,6 +155,31 @@ impl GameBoyConfig {
/// Should serve as the main entry-point API.
/// Should serve as the main entry-point API.
#[cfg_attr(feature
=
"wasm"
,
wasm_bindgen)]
#[cfg_attr(feature
=
"wasm"
,
wasm_bindgen)]
pub
struct
GameBoy
{
pub
struct
GameBoy
{
/// The current running mode of the emulator, this
/// may affect many aspects of the emulation, like
/// CPU frequency, PPU frequency, Boot rome size, etc.
mode
:
GameBoyMode
,
/// If the PPU is enabled, it will be clocked.
ppu_enabled
:
bool
,
/// If the APU is enabled, it will be clocked.
apu_enabled
:
bool
,
/// If the timer is enabled, it will be clocked.
timer_enabled
:
bool
,
/// If the serial is enabled, it will be clocked.
serial_enabled
:
bool
,
/// The current frequency at which the Game Boy
/// emulator is being handled. This is a "hint" that
/// may help components to adjust their internal
/// logic to match the current frequency. For example
/// the APU will adjust its internal clock to match
/// this hint.
clock_freq
:
u32
,
/// Reference to the Game Boy CPU component to be
/// Reference to the Game Boy CPU component to be
/// used as the main element of the system, when
/// used as the main element of the system, when
/// clocked, the amount of ticks from it will be
/// clocked, the amount of ticks from it will be
...
@@ -210,7 +235,16 @@ impl GameBoy {
...
@@ -210,7 +235,16 @@ impl GameBoy {
let
mmu
=
Mmu
::
new
(
ppu
,
apu
,
pad
,
timer
,
serial
,
gbc
.clone
());
let
mmu
=
Mmu
::
new
(
ppu
,
apu
,
pad
,
timer
,
serial
,
gbc
.clone
());
let
cpu
=
Cpu
::
new
(
mmu
,
gbc
.clone
());
let
cpu
=
Cpu
::
new
(
mmu
,
gbc
.clone
());
Self
{
cpu
,
gbc
}
Self
{
mode
,
ppu_enabled
:
true
,
apu_enabled
:
true
,
timer_enabled
:
true
,
serial_enabled
:
true
,
clock_freq
:
GameBoy
::
CPU_FREQ
,
cpu
,
gbc
,
}
}
}
pub
fn
reset
(
&
mut
self
)
{
pub
fn
reset
(
&
mut
self
)
{
...
@@ -224,16 +258,16 @@ impl GameBoy {
...
@@ -224,16 +258,16 @@ impl GameBoy {
pub
fn
clock
(
&
mut
self
)
->
u8
{
pub
fn
clock
(
&
mut
self
)
->
u8
{
let
cycles
=
self
.cpu_clock
();
let
cycles
=
self
.cpu_clock
();
if
self
.ppu_enabled
()
{
if
self
.ppu_enabled
{
self
.ppu_clock
(
cycles
);
self
.ppu_clock
(
cycles
);
}
}
if
self
.apu_enabled
()
{
if
self
.apu_enabled
{
self
.apu_clock
(
cycles
);
self
.apu_clock
(
cycles
);
}
}
if
self
.timer_enabled
()
{
if
self
.timer_enabled
{
self
.timer_clock
(
cycles
);
self
.timer_clock
(
cycles
);
}
}
if
self
.serial_enabled
()
{
if
self
.serial_enabled
{
self
.serial_clock
(
cycles
);
self
.serial_clock
(
cycles
);
}
}
cycles
cycles
...
@@ -448,57 +482,57 @@ impl GameBoy {
...
@@ -448,57 +482,57 @@ impl GameBoy {
String
::
from
(
COMPILATION_TIME
)
String
::
from
(
COMPILATION_TIME
)
}
}
#[inline(always)]
pub
fn
mode
(
&
self
)
->
GameBoyMode
{
pub
fn
mode
(
&
self
)
->
GameBoyMode
{
(
*
self
.
gbc
)
.borrow
()
.
mode
()
self
.mode
}
}
pub
fn
set_mode
(
&
mut
self
,
value
:
GameBoyMode
)
{
pub
fn
set_mode
(
&
mut
self
,
value
:
GameBoyMode
)
{
self
.mode
=
value
;
(
*
self
.gbc
)
.borrow_mut
()
.set_mode
(
value
);
(
*
self
.gbc
)
.borrow_mut
()
.set_mode
(
value
);
}
}
#[inline(always)]
pub
fn
ppu_enabled
(
&
self
)
->
bool
{
pub
fn
ppu_enabled
(
&
self
)
->
bool
{
(
*
self
.
gbc
)
.borrow
()
.
ppu_enabled
()
self
.ppu_enabled
}
}
pub
fn
set_ppu_enabled
(
&
mut
self
,
value
:
bool
)
{
pub
fn
set_ppu_enabled
(
&
mut
self
,
value
:
bool
)
{
self
.ppu_enabled
=
value
;
(
*
self
.gbc
)
.borrow_mut
()
.set_ppu_enabled
(
value
);
(
*
self
.gbc
)
.borrow_mut
()
.set_ppu_enabled
(
value
);
}
}
#[inline(always)]
pub
fn
apu_enabled
(
&
self
)
->
bool
{
pub
fn
apu_enabled
(
&
self
)
->
bool
{
(
*
self
.
gbc
)
.borrow
()
.
apu_enabled
self
.apu_enabled
}
}
pub
fn
set_apu_enabled
(
&
mut
self
,
value
:
bool
)
{
pub
fn
set_apu_enabled
(
&
mut
self
,
value
:
bool
)
{
self
.apu_enabled
=
value
;
(
*
self
.gbc
)
.borrow_mut
()
.set_apu_enabled
(
value
);
(
*
self
.gbc
)
.borrow_mut
()
.set_apu_enabled
(
value
);
}
}
#[inline(always)]
pub
fn
timer_enabled
(
&
self
)
->
bool
{
pub
fn
timer_enabled
(
&
self
)
->
bool
{
(
*
self
.
gbc
)
.borrow
()
.
timer_enabled
()
self
.timer_enabled
}
}
pub
fn
set_timer_enabled
(
&
mut
self
,
value
:
bool
)
{
pub
fn
set_timer_enabled
(
&
mut
self
,
value
:
bool
)
{
self
.timer_enabled
=
value
;
(
*
self
.gbc
)
.borrow_mut
()
.set_timer_enabled
(
value
);
(
*
self
.gbc
)
.borrow_mut
()
.set_timer_enabled
(
value
);
}
}
#[inline(always)]
pub
fn
serial_enabled
(
&
self
)
->
bool
{
pub
fn
serial_enabled
(
&
self
)
->
bool
{
(
*
self
.
gbc
)
.borrow
()
.
serial_enabled
()
self
.serial_enabled
}
}
pub
fn
set_serial_enabled
(
&
mut
self
,
value
:
bool
)
{
pub
fn
set_serial_enabled
(
&
mut
self
,
value
:
bool
)
{
self
.serial_enabled
=
value
;
(
*
self
.gbc
)
.borrow_mut
()
.set_serial_enabled
(
value
);
(
*
self
.gbc
)
.borrow_mut
()
.set_serial_enabled
(
value
);
}
}
#[inline(always)]
pub
fn
clock_freq
(
&
self
)
->
u32
{
pub
fn
clock_freq
(
&
self
)
->
u32
{
(
*
self
.
gbc
)
.borrow
()
.
clock_freq
()
self
.clock_freq
}
}
pub
fn
set_clock_freq
(
&
mut
self
,
value
:
u32
)
{
pub
fn
set_clock_freq
(
&
mut
self
,
value
:
u32
)
{
self
.clock_freq
=
value
;
(
*
self
.gbc
)
.borrow_mut
()
.set_clock_freq
(
value
);
(
*
self
.gbc
)
.borrow_mut
()
.set_clock_freq
(
value
);
self
.apu
()
.set_clock_freq
(
value
);
self
.apu
()
.set_clock_freq
(
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