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
d07e7f09
Verified
Commit
d07e7f09
authored
1 year ago
by
João Magalhães
Browse files
Options
Downloads
Patches
Plain Diff
chore: better structure for boot loading of CGB
parent
a914056c
No related branches found
No related tags found
1 merge request
!16
Support for Game Boy Color (CGB) 😎🖍️
Pipeline
#2554
failed
1 year ago
Stage: build
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
frontends/sdl/src/main.rs
+5
-5
5 additions, 5 deletions
frontends/sdl/src/main.rs
src/gb.rs
+21
-6
21 additions, 6 deletions
src/gb.rs
with
26 additions
and
11 deletions
frontends/sdl/src/main.rs
+
5
−
5
View file @
d07e7f09
...
@@ -7,7 +7,7 @@ pub mod graphics;
...
@@ -7,7 +7,7 @@ pub mod graphics;
use
audio
::
Audio
;
use
audio
::
Audio
;
use
boytacean
::{
use
boytacean
::{
devices
::
printer
::
PrinterDevice
,
devices
::
printer
::
PrinterDevice
,
gb
::{
AudioProvider
,
GameBoy
},
gb
::{
AudioProvider
,
GBMode
,
GameBoy
},
pad
::
PadKey
,
pad
::
PadKey
,
ppu
::{
PaletteInfo
,
PpuMode
,
DISPLAY_HEIGHT
,
DISPLAY_WIDTH
},
ppu
::{
PaletteInfo
,
PpuMode
,
DISPLAY_HEIGHT
,
DISPLAY_WIDTH
},
};
};
...
@@ -186,7 +186,7 @@ impl Emulator {
...
@@ -186,7 +186,7 @@ impl Emulator {
pub
fn
reset
(
&
mut
self
)
{
pub
fn
reset
(
&
mut
self
)
{
self
.system
.reset
();
self
.system
.reset
();
self
.system
.load
_boot_default
(
);
self
.system
.load
(
true
);
self
.load_rom
(
None
);
self
.load_rom
(
None
);
}
}
...
@@ -317,7 +317,7 @@ impl Emulator {
...
@@ -317,7 +317,7 @@ impl Emulator {
}
}
Event
::
DropFile
{
filename
,
..
}
=>
{
Event
::
DropFile
{
filename
,
..
}
=>
{
self
.system
.reset
();
self
.system
.reset
();
self
.system
.load
_boot_cgb
(
);
self
.system
.load
(
true
);
self
.load_rom
(
Some
(
&
filename
));
self
.load_rom
(
Some
(
&
filename
));
}
}
_
=>
(),
_
=>
(),
...
@@ -446,7 +446,7 @@ impl Emulator {
...
@@ -446,7 +446,7 @@ impl Emulator {
fn
main
()
{
fn
main
()
{
// creates a new Game Boy instance and loads both the boot ROM
// creates a new Game Boy instance and loads both the boot ROM
// and the initial game ROM to "start the engine"
// and the initial game ROM to "start the engine"
let
mut
game_boy
=
GameBoy
::
new
();
let
mut
game_boy
=
GameBoy
::
new
(
GBMode
::
Cgb
);
let
mut
printer
=
Box
::
<
PrinterDevice
>
::
default
();
let
mut
printer
=
Box
::
<
PrinterDevice
>
::
default
();
printer
.set_callback
(|
image_buffer
|
{
printer
.set_callback
(|
image_buffer
|
{
let
file_name
=
format!
(
"printer-{}.png"
,
Utc
::
now
()
.format
(
"%Y%m%d-%H%M%S"
));
let
file_name
=
format!
(
"printer-{}.png"
,
Utc
::
now
()
.format
(
"%Y%m%d-%H%M%S"
));
...
@@ -460,7 +460,7 @@ fn main() {
...
@@ -460,7 +460,7 @@ fn main() {
.unwrap
();
.unwrap
();
});
});
game_boy
.attach_serial
(
printer
);
game_boy
.attach_serial
(
printer
);
game_boy
.load
_boot_cgb
(
);
game_boy
.load
(
true
);
// creates a new generic emulator structure then starts
// creates a new generic emulator structure then starts
// both the video and audio sub-systems, loads default
// both the video and audio sub-systems, loads default
...
...
This diff is collapsed.
Click to expand it.
src/gb.rs
+
21
−
6
View file @
d07e7f09
...
@@ -30,11 +30,24 @@ use std::{
...
@@ -30,11 +30,24 @@ use std::{
panic
::{
set_hook
,
take_hook
,
PanicInfo
},
panic
::{
set_hook
,
take_hook
,
PanicInfo
},
};
};
/// Enumeration that describes the multiple running
// modes of the Game Boy emulator.
pub
enum
GBMode
{
Dmg
=
1
,
Cgb
=
2
,
Sgb
=
3
,
}
/// Top level structure that abstracts the usage of the
/// Top level structure that abstracts the usage of the
/// Game Boy system under the Boytacean emulator.
/// Game Boy system under the Boytacean emulator.
/// 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
:
GBMode
,
/// 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
...
@@ -90,7 +103,7 @@ pub trait AudioProvider {
...
@@ -90,7 +103,7 @@ pub trait AudioProvider {
#[cfg_attr(feature
=
"wasm"
,
wasm_bindgen)]
#[cfg_attr(feature
=
"wasm"
,
wasm_bindgen)]
impl
GameBoy
{
impl
GameBoy
{
#[cfg_attr(feature
=
"wasm"
,
wasm_bindgen(constructor))]
#[cfg_attr(feature
=
"wasm"
,
wasm_bindgen(constructor))]
pub
fn
new
()
->
Self
{
pub
fn
new
(
mode
:
GBMode
)
->
Self
{
let
ppu
=
Ppu
::
default
();
let
ppu
=
Ppu
::
default
();
let
apu
=
Apu
::
default
();
let
apu
=
Apu
::
default
();
let
pad
=
Pad
::
default
();
let
pad
=
Pad
::
default
();
...
@@ -99,6 +112,7 @@ impl GameBoy {
...
@@ -99,6 +112,7 @@ impl GameBoy {
let
mmu
=
Mmu
::
new
(
ppu
,
apu
,
pad
,
timer
,
serial
);
let
mmu
=
Mmu
::
new
(
ppu
,
apu
,
pad
,
timer
,
serial
);
let
cpu
=
Cpu
::
new
(
mmu
);
let
cpu
=
Cpu
::
new
(
mmu
);
Self
{
Self
{
mode
,
cpu
,
cpu
,
ppu_enabled
:
true
,
ppu_enabled
:
true
,
apu_enabled
:
true
,
apu_enabled
:
true
,
...
@@ -178,10 +192,11 @@ impl GameBoy {
...
@@ -178,10 +192,11 @@ impl GameBoy {
self
.cpu
.boot
();
self
.cpu
.boot
();
}
}
pub
fn
load_default
(
&
mut
self
,
boot
:
bool
)
{
pub
fn
load
(
&
mut
self
,
boot
:
bool
)
{
self
.mmu
()
.allocate_default
();
match
self
.mode
{
if
boot
{
GBMode
::
Dmg
=>
self
.load_dmg
(
boot
),
self
.load_boot_default
();
GBMode
::
Cgb
=>
self
.load_cgb
(
boot
),
GBMode
::
Sgb
=>
todo!
(),
}
}
}
}
...
@@ -601,6 +616,6 @@ impl AudioProvider for GameBoy {
...
@@ -601,6 +616,6 @@ impl AudioProvider for GameBoy {
impl
Default
for
GameBoy
{
impl
Default
for
GameBoy
{
fn
default
()
->
Self
{
fn
default
()
->
Self
{
Self
::
new
()
Self
::
new
(
GBMode
::
Dmg
)
}
}
}
}
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