colour update

This commit is contained in:
Alex Janka 2023-05-19 19:15:01 +10:00
parent 335187732a
commit c63cff149d
6 changed files with 34 additions and 14 deletions

6
Cargo.lock generated
View file

@ -1119,7 +1119,7 @@ dependencies = [
[[package]] [[package]]
name = "gb-emu" name = "gb-emu"
version = "0.3.2" version = "0.3.3"
dependencies = [ dependencies = [
"clap", "clap",
"cpal", "cpal",
@ -1136,7 +1136,7 @@ dependencies = [
[[package]] [[package]]
name = "gb-emu-lib" name = "gb-emu-lib"
version = "0.3.2" version = "0.3.3"
dependencies = [ dependencies = [
"async-ringbuf", "async-ringbuf",
"bytemuck", "bytemuck",
@ -2965,7 +2965,7 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
[[package]] [[package]]
name = "vst" name = "vst"
version = "0.3.2" version = "0.3.3"
dependencies = [ dependencies = [
"async-ringbuf", "async-ringbuf",
"baseview", "baseview",

View file

@ -1,6 +1,6 @@
[package] [package]
name = "gb-emu" name = "gb-emu"
version = "0.3.2" version = "0.3.3"
edition = "2021" edition = "2021"
[features] [features]

View file

@ -1,6 +1,6 @@
[package] [package]
name = "vst" name = "vst"
version = "0.3.2" version = "0.3.3"
edition = "2021" edition = "2021"
[lib] [lib]

View file

@ -1,6 +1,6 @@
[package] [package]
name = "gb-emu-lib" name = "gb-emu-lib"
version = "0.3.2" version = "0.3.3"
edition = "2021" edition = "2021"
[features] [features]

View file

@ -1,2 +1,21 @@
use crate::connect::Colour;
// Hz // Hz
pub const CLOCK_SPEED: usize = 4194304; pub const CLOCK_SPEED: usize = 4194304;
pub(crate) const ERROR_COLOUR: Colour = Colour(0xFF, 0x00, 0x00);
pub(crate) mod dmg_colours {
use crate::connect::Colour;
// validation b&w (dmg-acid2 etc.)
// pub(crate) const ZERO: Colour = Colour(0xFF, 0xFF, 0xFF);
// pub(crate) const ONE: Colour = Colour(0xAA, 0xAA, 0xAA);
// pub(crate) const TWO: Colour = Colour(0x55, 0x55, 0x55);
// pub(crate) const THREE: Colour = Colour(0x00, 0x00, 0x00);
// from https://www.designpieces.com/palette/game-boy-original-color-palette-hex-and-rgb/
pub(crate) const ZERO: Colour = Colour(0x9B, 0xBC, 0x0F);
pub(crate) const ONE: Colour = Colour(0x8B, 0xAC, 0x0F);
pub(crate) const TWO: Colour = Colour(0x30, 0x62, 0x30);
pub(crate) const THREE: Colour = Colour(0x0F, 0x38, 0x0F);
}

View file

@ -2,6 +2,7 @@ use bytemuck::from_bytes;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::{ use crate::{
constants::{dmg_colours, ERROR_COLOUR},
processor::memory::addresses::{OamAddress, VramAddress}, processor::memory::addresses::{OamAddress, VramAddress},
util::{as_signed, get_bit, SaturatingCast}, util::{as_signed, get_bit, SaturatingCast},
}; };
@ -100,7 +101,7 @@ pub enum ColourInner {
Error = 255, Error = 255,
} }
pub struct Colour(u8, u8, u8); pub struct Colour(pub u8, pub u8, pub u8);
impl From<Colour> for u32 { impl From<Colour> for u32 {
fn from(value: Colour) -> Self { fn from(value: Colour) -> Self {
@ -145,24 +146,24 @@ impl ColourInner {
) -> Colour { ) -> Colour {
if let Some((cgb_palette, pallete_num)) = cgb_data { if let Some((cgb_palette, pallete_num)) = cgb_data {
if *self == ColourInner::Error { if *self == ColourInner::Error {
return Colour(0xFF, 0, 0); return ERROR_COLOUR;
} }
let offset: usize = (pallete_num as usize * 2 * 4) + (*self as usize * 2); let offset: usize = (pallete_num as usize * 2 * 4) + (*self as usize * 2);
rgb_from_bytes(*from_bytes(&cgb_palette.data[offset..=offset + 1])) rgb_from_bytes(*from_bytes(&cgb_palette.data[offset..=offset + 1]))
} else { } else {
match self { match self {
ColourInner::Zero => Colour(0xFF, 0xFF, 0xFF), ColourInner::Zero => dmg_colours::ZERO,
ColourInner::One => Colour(0xAA, 0xAA, 0xAA), ColourInner::One => dmg_colours::ONE,
ColourInner::Two => Colour(0x55, 0x55, 0x55), ColourInner::Two => dmg_colours::TWO,
ColourInner::Three => Colour(0x00, 0x00, 0x00), ColourInner::Three => dmg_colours::THREE,
ColourInner::Error => { ColourInner::Error => {
if cfg!(debug_assertions) { if cfg!(debug_assertions) {
Colour(0xFF, 0x00, 0x00) ERROR_COLOUR
} else if is_cgb_mode { } else if is_cgb_mode {
rgb_from_bytes(0xFFFF) rgb_from_bytes(0xFFFF)
} else { } else {
Colour(0xFF, 0xFF, 0xFF) dmg_colours::ZERO
} }
} }
} }