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
d8bc788e
Verified
Commit
d8bc788e
authored
2 years ago
by
João Magalhães
Browse files
Options
Downloads
Patches
Plain Diff
feat: flexible palette colors
parent
83e51486
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
CHANGELOG.md
+1
-0
1 addition, 0 deletions
CHANGELOG.md
src/ppu.rs
+21
-16
21 additions, 16 deletions
src/ppu.rs
with
22 additions
and
16 deletions
CHANGELOG.md
+
1
−
0
View file @
d8bc788e
...
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
...
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
### Added
*
Support for true fullscreen at a browser level
*
Support for true fullscreen at a browser level
*
Support for more flexible palette colors
### Changed
### Changed
...
...
This diff is collapsed.
Click to expand it.
src/ppu.rs
+
21
−
16
View file @
d8bc788e
...
@@ -40,6 +40,10 @@ pub const COLOR_BUFFER_SIZE: usize = DISPLAY_WIDTH * DISPLAY_HEIGHT;
...
@@ -40,6 +40,10 @@ pub const COLOR_BUFFER_SIZE: usize = DISPLAY_WIDTH * DISPLAY_HEIGHT;
/// The size of the RGB frame buffer in bytes.
/// The size of the RGB frame buffer in bytes.
pub
const
FRAME_BUFFER_SIZE
:
usize
=
DISPLAY_WIDTH
*
DISPLAY_HEIGHT
*
RGB_SIZE
;
pub
const
FRAME_BUFFER_SIZE
:
usize
=
DISPLAY_WIDTH
*
DISPLAY_HEIGHT
*
RGB_SIZE
;
/// The base colors to be used to populate the
/// custom palettes of the Game Boy.
pub
const
PALETTE_COLORS
:
Palette
=
[[
255
,
255
,
255
],
[
192
,
192
,
192
],
[
96
,
96
,
96
],
[
0
,
0
,
0
]];
/// Defines the Game Boy pixel type as a buffer
/// Defines the Game Boy pixel type as a buffer
/// with the size of RGB (3 bytes).
/// with the size of RGB (3 bytes).
pub
type
Pixel
=
[
u8
;
RGB_SIZE
];
pub
type
Pixel
=
[
u8
;
RGB_SIZE
];
...
@@ -171,6 +175,12 @@ pub struct Ppu {
...
@@ -171,6 +175,12 @@ pub struct Ppu {
/// to be drawn to the screen,
/// to be drawn to the screen,
obj_data
:
[
ObjectData
;
OBJ_COUNT
],
obj_data
:
[
ObjectData
;
OBJ_COUNT
],
/// The base colors that are going to be used in the registration
/// of the concrete palettes, this value basically controls the
/// colors that are going to be shown for each of the four base
/// values - 0x00, 0x01, 0x02, and 0x03
pallette_colors
:
Palette
,
/// The palette of colors that is currently loaded in Game Boy
/// The palette of colors that is currently loaded in Game Boy
/// and used for background (tiles).
/// and used for background (tiles).
palette
:
Palette
,
palette
:
Palette
,
...
@@ -182,7 +192,7 @@ pub struct Ppu {
...
@@ -182,7 +192,7 @@ pub struct Ppu {
palette_obj_1
:
Palette
,
palette_obj_1
:
Palette
,
/// The complete set of palettes in binary data so that they can
/// The complete set of palettes in binary data so that they can
/// b
r
e read if required by the system.
/// be
re-
read if required by the system.
palettes
:
[
u8
;
3
],
palettes
:
[
u8
;
3
],
/// The scroll Y register that controls the Y offset
/// The scroll Y register that controls the Y offset
...
@@ -298,6 +308,7 @@ impl Ppu {
...
@@ -298,6 +308,7 @@ impl Ppu {
priority
:
false
,
priority
:
false
,
index
:
0
,
index
:
0
,
};
OBJ_COUNT
],
};
OBJ_COUNT
],
pallette_colors
:
PALETTE_COLORS
,
palette
:
[[
0u8
;
RGB_SIZE
];
PALETTE_SIZE
],
palette
:
[[
0u8
;
RGB_SIZE
];
PALETTE_SIZE
],
palette_obj_0
:
[[
0u8
;
RGB_SIZE
];
PALETTE_SIZE
],
palette_obj_0
:
[[
0u8
;
RGB_SIZE
];
PALETTE_SIZE
],
palette_obj_1
:
[[
0u8
;
RGB_SIZE
];
PALETTE_SIZE
],
palette_obj_1
:
[[
0u8
;
RGB_SIZE
];
PALETTE_SIZE
],
...
@@ -505,11 +516,9 @@ impl Ppu {
...
@@ -505,11 +516,9 @@ impl Ppu {
0x0045
=>
self
.lyc
=
value
,
0x0045
=>
self
.lyc
=
value
,
0x0047
=>
{
0x0047
=>
{
for
index
in
0
..
PALETTE_SIZE
{
for
index
in
0
..
PALETTE_SIZE
{
match
(
value
>>
(
index
*
2
))
&
3
{
let
color_index
:
usize
=
(
value
as
usize
>>
(
index
*
2
))
&
3
;
0
=>
self
.palette
[
index
]
=
[
255
,
255
,
255
],
match
color_index
{
1
=>
self
.palette
[
index
]
=
[
192
,
192
,
192
],
0
..=
3
=>
self
.palette
[
index
]
=
self
.pallette_colors
[
color_index
],
2
=>
self
.palette
[
index
]
=
[
96
,
96
,
96
],
3
=>
self
.palette
[
index
]
=
[
0
,
0
,
0
],
color_index
=>
panic!
(
"Invalid palette color index {:04x}"
,
color_index
),
color_index
=>
panic!
(
"Invalid palette color index {:04x}"
,
color_index
),
}
}
}
}
...
@@ -517,11 +526,9 @@ impl Ppu {
...
@@ -517,11 +526,9 @@ impl Ppu {
}
}
0x0048
=>
{
0x0048
=>
{
for
index
in
0
..
PALETTE_SIZE
{
for
index
in
0
..
PALETTE_SIZE
{
match
(
value
>>
(
index
*
2
))
&
3
{
let
color_index
:
usize
=
(
value
as
usize
>>
(
index
*
2
))
&
3
;
0
=>
self
.palette_obj_0
[
index
]
=
[
255
,
255
,
255
],
match
color_index
{
1
=>
self
.palette_obj_0
[
index
]
=
[
192
,
192
,
192
],
0
..=
3
=>
self
.palette_obj_0
[
index
]
=
self
.pallette_colors
[
color_index
],
2
=>
self
.palette_obj_0
[
index
]
=
[
96
,
96
,
96
],
3
=>
self
.palette_obj_0
[
index
]
=
[
0
,
0
,
0
],
color_index
=>
panic!
(
"Invalid palette color index {:04x}"
,
color_index
),
color_index
=>
panic!
(
"Invalid palette color index {:04x}"
,
color_index
),
}
}
}
}
...
@@ -529,11 +536,9 @@ impl Ppu {
...
@@ -529,11 +536,9 @@ impl Ppu {
}
}
0x0049
=>
{
0x0049
=>
{
for
index
in
0
..
PALETTE_SIZE
{
for
index
in
0
..
PALETTE_SIZE
{
match
(
value
>>
(
index
*
2
))
&
3
{
let
color_index
:
usize
=
(
value
as
usize
>>
(
index
*
2
))
&
3
;
0
=>
self
.palette_obj_1
[
index
]
=
[
255
,
255
,
255
],
match
color_index
{
1
=>
self
.palette_obj_1
[
index
]
=
[
192
,
192
,
192
],
0
..=
3
=>
self
.palette_obj_1
[
index
]
=
self
.pallette_colors
[
color_index
],
2
=>
self
.palette_obj_1
[
index
]
=
[
96
,
96
,
96
],
3
=>
self
.palette_obj_1
[
index
]
=
[
0
,
0
,
0
],
color_index
=>
panic!
(
"Invalid palette color index {:04x}"
,
color_index
),
color_index
=>
panic!
(
"Invalid palette color index {:04x}"
,
color_index
),
}
}
}
}
...
...
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