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
e2389ecf
Verified
Commit
e2389ecf
authored
2 years ago
by
João Magalhães
Browse files
Options
Downloads
Patches
Plain Diff
feat: WASM palette colors
parent
d8bc788e
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
CHANGELOG.md
+1
-0
1 addition, 0 deletions
CHANGELOG.md
examples/web/index.ts
+8
-0
8 additions, 0 deletions
examples/web/index.ts
src/gb.rs
+27
-0
27 additions, 0 deletions
src/gb.rs
src/ppu.rs
+10
-6
10 additions, 6 deletions
src/ppu.rs
with
46 additions
and
6 deletions
CHANGELOG.md
+
1
−
0
View file @
e2389ecf
...
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
...
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
*
Support for true fullscreen at a browser level
*
Support for true fullscreen at a browser level
*
Support for more flexible palette colors
*
Support for more flexible palette colors
*
Support for setting palette colors using WASM
### Changed
### Changed
...
...
This diff is collapsed.
Click to expand it.
examples/web/index.ts
+
8
−
0
View file @
e2389ecf
...
@@ -286,6 +286,14 @@ class GameboyEmulator extends EmulatorBase implements Emulator {
...
@@ -286,6 +286,14 @@ class GameboyEmulator extends EmulatorBase implements Emulator {
break
;
break
;
}
}
// @todo replace this with somethign more flexible
this
.
gameBoy
.
set_palette_colors_ws
([
"
b6a571
"
,
"
8b7e56
"
,
"
554d35
"
,
"
201d13
"
]);
// resets the Game Boy engine to restore it into
// resets the Game Boy engine to restore it into
// a valid state ready to be used
// a valid state ready to be used
this
.
gameBoy
.
reset
();
this
.
gameBoy
.
reset
();
...
...
This diff is collapsed.
Click to expand it.
src/gb.rs
+
27
−
0
View file @
e2389ecf
...
@@ -10,6 +10,8 @@ use crate::{
...
@@ -10,6 +10,8 @@ use crate::{
};
};
#[cfg(feature
=
"wasm"
)]
#[cfg(feature
=
"wasm"
)]
use
crate
::
ppu
::
Palette
;
use
std
::
convert
::
TryInto
;
use
wasm_bindgen
::
prelude
::
*
;
use
wasm_bindgen
::
prelude
::
*
;
#[cfg(feature
=
"wasm"
)]
#[cfg(feature
=
"wasm"
)]
...
@@ -244,9 +246,34 @@ impl GameBoy {
...
@@ -244,9 +246,34 @@ impl GameBoy {
prev
(
info
);
prev
(
info
);
}));
}));
}
}
pub
fn
load_rom_ws
(
&
mut
self
,
data
:
&
[
u8
])
->
Cartridge
{
pub
fn
load_rom_ws
(
&
mut
self
,
data
:
&
[
u8
])
->
Cartridge
{
self
.load_rom
(
data
)
.clone
()
self
.load_rom
(
data
)
.clone
()
}
}
pub
fn
set_palette_colors_ws
(
&
mut
self
,
value
:
Vec
<
JsValue
>
)
{
let
palette
:
Palette
=
value
.into_iter
()
.map
(|
v
|
self
.convert_value
(
&
v
))
.collect
::
<
Vec
<
[
u8
;
3
]
>>
()
.try_into
()
.unwrap
();
self
.ppu
()
.set_palette_colors
(
&
palette
);
}
fn
convert_value
(
&
self
,
value
:
&
JsValue
)
->
[
u8
;
3
]
{
value
.as_string
()
.unwrap
()
.chars
()
.collect
::
<
Vec
<
char
>>
()
.chunks
(
2
)
.map
(|
s
|
s
.iter
()
.collect
::
<
String
>
())
.map
(|
s
|
u8
::
from_str_radix
(
&
s
,
16
)
.unwrap
())
.collect
::
<
Vec
<
u8
>>
()
.try_into
()
.unwrap
()
}
}
}
#[cfg(feature
=
"wasm"
)]
#[cfg(feature
=
"wasm"
)]
...
...
This diff is collapsed.
Click to expand it.
src/ppu.rs
+
10
−
6
View file @
e2389ecf
...
@@ -178,8 +178,8 @@ pub struct Ppu {
...
@@ -178,8 +178,8 @@ pub struct Ppu {
/// The base colors that are going to be used in the registration
/// The base colors that are going to be used in the registration
/// of the concrete palettes, this value basically controls the
/// of the concrete palettes, this value basically controls the
/// colors that are going to be shown for each of the four base
/// colors that are going to be shown for each of the four base
/// values - 0x00, 0x01, 0x02, and 0x03
/// values - 0x00, 0x01, 0x02, and 0x03
.
pal
l
ette_colors
:
Palette
,
palette_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).
...
@@ -308,7 +308,7 @@ impl Ppu {
...
@@ -308,7 +308,7 @@ impl Ppu {
priority
:
false
,
priority
:
false
,
index
:
0
,
index
:
0
,
};
OBJ_COUNT
],
};
OBJ_COUNT
],
pal
l
ette_colors
:
PALETTE_COLORS
,
palette_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
],
...
@@ -518,7 +518,7 @@ impl Ppu {
...
@@ -518,7 +518,7 @@ impl Ppu {
for
index
in
0
..
PALETTE_SIZE
{
for
index
in
0
..
PALETTE_SIZE
{
let
color_index
:
usize
=
(
value
as
usize
>>
(
index
*
2
))
&
3
;
let
color_index
:
usize
=
(
value
as
usize
>>
(
index
*
2
))
&
3
;
match
color_index
{
match
color_index
{
0
..=
3
=>
self
.palette
[
index
]
=
self
.pal
l
ette_colors
[
color_index
],
0
..=
3
=>
self
.palette
[
index
]
=
self
.palette_colors
[
color_index
],
color_index
=>
panic!
(
"Invalid palette color index {:04x}"
,
color_index
),
color_index
=>
panic!
(
"Invalid palette color index {:04x}"
,
color_index
),
}
}
}
}
...
@@ -528,7 +528,7 @@ impl Ppu {
...
@@ -528,7 +528,7 @@ impl Ppu {
for
index
in
0
..
PALETTE_SIZE
{
for
index
in
0
..
PALETTE_SIZE
{
let
color_index
:
usize
=
(
value
as
usize
>>
(
index
*
2
))
&
3
;
let
color_index
:
usize
=
(
value
as
usize
>>
(
index
*
2
))
&
3
;
match
color_index
{
match
color_index
{
0
..=
3
=>
self
.palette_obj_0
[
index
]
=
self
.pal
l
ette_colors
[
color_index
],
0
..=
3
=>
self
.palette_obj_0
[
index
]
=
self
.palette_colors
[
color_index
],
color_index
=>
panic!
(
"Invalid palette color index {:04x}"
,
color_index
),
color_index
=>
panic!
(
"Invalid palette color index {:04x}"
,
color_index
),
}
}
}
}
...
@@ -538,7 +538,7 @@ impl Ppu {
...
@@ -538,7 +538,7 @@ impl Ppu {
for
index
in
0
..
PALETTE_SIZE
{
for
index
in
0
..
PALETTE_SIZE
{
let
color_index
:
usize
=
(
value
as
usize
>>
(
index
*
2
))
&
3
;
let
color_index
:
usize
=
(
value
as
usize
>>
(
index
*
2
))
&
3
;
match
color_index
{
match
color_index
{
0
..=
3
=>
self
.palette_obj_1
[
index
]
=
self
.pal
l
ette_colors
[
color_index
],
0
..=
3
=>
self
.palette_obj_1
[
index
]
=
self
.palette_colors
[
color_index
],
color_index
=>
panic!
(
"Invalid palette color index {:04x}"
,
color_index
),
color_index
=>
panic!
(
"Invalid palette color index {:04x}"
,
color_index
),
}
}
}
}
...
@@ -565,6 +565,10 @@ impl Ppu {
...
@@ -565,6 +565,10 @@ impl Ppu {
&
self
.tiles
&
self
.tiles
}
}
pub
fn
set_palette_colors
(
&
mut
self
,
value
:
&
Palette
)
{
self
.palette_colors
=
*
value
;
}
pub
fn
palette
(
&
self
)
->
Palette
{
pub
fn
palette
(
&
self
)
->
Palette
{
self
.palette
self
.palette
}
}
...
...
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