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
354fe6f0
Verified
Commit
354fe6f0
authored
2 years ago
by
João Magalhães
Browse files
Options
Downloads
Patches
Plain Diff
feat: better PPU implementation
parent
89fe647f
No related branches found
No related tags found
No related merge requests found
Pipeline
#853
passed
2 years ago
Stage: build
Stage: deploy
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/cpu.rs
+2
-0
2 additions, 0 deletions
src/cpu.rs
src/ppu.rs
+26
-7
26 additions, 7 deletions
src/ppu.rs
with
28 additions
and
7 deletions
src/cpu.rs
+
2
−
0
View file @
354fe6f0
...
@@ -80,6 +80,8 @@ impl Cpu {
...
@@ -80,6 +80,8 @@ impl Cpu {
let
pc
=
self
.pc
;
let
pc
=
self
.pc
;
//@todo maybe remove this option as it may
// spend valuable resources
if
pc
>=
0x8000
&&
pc
<
0x9fff
{
if
pc
>=
0x8000
&&
pc
<
0x9fff
{
panic!
(
"Invalid PC area at 0x{:04x}"
,
pc
);
panic!
(
"Invalid PC area at 0x{:04x}"
,
pc
);
}
}
...
...
This diff is collapsed.
Click to expand it.
src/ppu.rs
+
26
−
7
View file @
354fe6f0
...
@@ -25,7 +25,7 @@ pub const FRAME_BUFFER_SIZE: usize = DISPLAY_WIDTH * DISPLAY_HEIGHT * RGB_SIZE;
...
@@ -25,7 +25,7 @@ pub const FRAME_BUFFER_SIZE: usize = DISPLAY_WIDTH * DISPLAY_HEIGHT * RGB_SIZE;
/// # Basic usage
/// # Basic usage
/// ```rust
/// ```rust
/// let ppu = Ppu::new();
/// let ppu = Ppu::new();
/// ppu.
ti
ck();
/// ppu.
clo
ck();
/// ```
/// ```
pub
struct
Ppu
{
pub
struct
Ppu
{
/// The 8 bit based RGB frame buffer with the
/// The 8 bit based RGB frame buffer with the
...
@@ -82,11 +82,12 @@ pub struct Ppu {
...
@@ -82,11 +82,12 @@ pub struct Ppu {
stat_lyc
:
bool
,
stat_lyc
:
bool
,
}
}
#[derive(Clone,
Copy)]
pub
enum
PpuMode
{
pub
enum
PpuMode
{
OamRead
,
Hblank
=
0
,
V
ramRead
,
V
Blank
=
1
,
Hblank
,
OamRead
=
2
,
V
Blank
,
V
ramRead
=
3
,
}
}
impl
Ppu
{
impl
Ppu
{
...
@@ -117,7 +118,14 @@ impl Ppu {
...
@@ -117,7 +118,14 @@ impl Ppu {
}
}
pub
fn
clock
(
&
mut
self
,
cycles
:
u8
)
{
pub
fn
clock
(
&
mut
self
,
cycles
:
u8
)
{
if
!
self
.switch_lcd
{
return
;
}
// increments the current mode clock by the provided amount
// of CPU cycles (probably coming from a previous CPU clock)
self
.mode_clock
+=
cycles
as
u16
;
self
.mode_clock
+=
cycles
as
u16
;
match
self
.mode
{
match
self
.mode
{
PpuMode
::
OamRead
=>
{
PpuMode
::
OamRead
=>
{
if
self
.mode_clock
>=
80
{
if
self
.mode_clock
>=
80
{
...
@@ -127,7 +135,9 @@ impl Ppu {
...
@@ -127,7 +135,9 @@ impl Ppu {
}
}
PpuMode
::
VramRead
=>
{
PpuMode
::
VramRead
=>
{
if
self
.mode_clock
>=
172
{
if
self
.mode_clock
>=
172
{
self
.render_line
();
if
self
.switch_bg
{
self
.render_line
();
}
self
.mode_clock
=
0
;
self
.mode_clock
=
0
;
self
.mode
=
PpuMode
::
Hblank
;
self
.mode
=
PpuMode
::
Hblank
;
...
@@ -182,7 +192,8 @@ impl Ppu {
...
@@ -182,7 +192,8 @@ impl Ppu {
let
value
=
if
self
.stat_hblank
{
0x04
}
else
{
0x00
}
let
value
=
if
self
.stat_hblank
{
0x04
}
else
{
0x00
}
|
if
self
.stat_vblank
{
0x08
}
else
{
0x00
}
|
if
self
.stat_vblank
{
0x08
}
else
{
0x00
}
|
if
self
.stat_oam
{
0x10
}
else
{
0x00
}
|
if
self
.stat_oam
{
0x10
}
else
{
0x00
}
|
if
self
.stat_lyc
{
0x20
}
else
{
0x00
};
|
if
self
.stat_lyc
{
0x20
}
else
{
0x00
}
|
self
.mode
as
u8
;
value
value
}
}
0x0042
=>
self
.scy
,
0x0042
=>
self
.scy
,
...
@@ -342,6 +353,14 @@ impl Ppu {
...
@@ -342,6 +353,14 @@ impl Ppu {
}
}
}
}
pub
fn
fill_frame_buffer
(
&
mut
self
,
color
:
[
u8
;
RGB_SIZE
])
{
for
index
in
(
0
..
self
.frame_buffer
.len
())
.step_by
(
RGB_SIZE
)
{
self
.frame_buffer
[
index
]
=
color
[
0
];
self
.frame_buffer
[
index
+
1
]
=
color
[
1
];
self
.frame_buffer
[
index
+
2
]
=
color
[
2
];
}
}
/// Prints the tile data information to the stdout, this is
/// Prints the tile data information to the stdout, this is
/// useful for debugging purposes.
/// useful for debugging purposes.
pub
fn
draw_tile_stdout
(
&
self
,
tile_index
:
usize
)
{
pub
fn
draw_tile_stdout
(
&
self
,
tile_index
:
usize
)
{
...
...
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