-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented sprite
OBP0
and OBP1
palette support
- Loading branch information
Showing
6 changed files
with
67 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
pub(crate) mod oam_parser; | ||
pub(crate) mod palette; | ||
pub(crate) mod states; | ||
pub mod tile_parser; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use crate::{ | ||
common::Bit, | ||
consts::gpu::{OBP0, OBP1}, | ||
GameBoy, | ||
}; | ||
|
||
use super::{oam_parser::Palette, tile_parser::Line, Color}; | ||
|
||
pub(crate) fn bools_to_color(bool1: bool, bool2: bool) -> Color { | ||
match (bool1, bool2) { | ||
(false, false) => Color::Light, | ||
(false, true) => Color::MediumlyLight, | ||
(true, false) => Color::MediumlyDark, | ||
(true, true) => Color::Dark, | ||
} | ||
} | ||
|
||
impl GameBoy { | ||
pub(crate) fn apply_palette_to_sprite(&self, line: &mut Line, palette: &Palette) { | ||
let palette = match palette { | ||
Palette::OBP0 => self.bus[OBP0], | ||
Palette::OBP1 => self.bus[OBP1], | ||
}; | ||
|
||
let id_1 = bools_to_color(palette.get_bit(3), palette.get_bit(2)); | ||
let id_2 = bools_to_color(palette.get_bit(5), palette.get_bit(4)); | ||
let id_3 = bools_to_color(palette.get_bit(7), palette.get_bit(6)); | ||
|
||
for pixel in line.colors.iter_mut() { | ||
*pixel = match pixel { | ||
Color::MediumlyLight => id_1, | ||
Color::MediumlyDark => id_2, | ||
Color::Dark => id_3, | ||
|
||
// Light will not change because light just means transparent in a sprite | ||
Color::Light => Color::Light, | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters