fix error colour being dmg zero in cgb mode
This commit is contained in:
parent
c63cff149d
commit
cd7a686e0d
3 changed files with 32 additions and 28 deletions
|
@ -3,8 +3,8 @@ use self::{
|
|||
cgb::CgbData,
|
||||
tile_window::TileWindow,
|
||||
types::{
|
||||
BgAttributes, ColourInner, GpuInterrupts, Lcdc, Oam, ObjPalette, ObjSize, Object,
|
||||
ObjectFlags, Palette, Stat, TiledataArea, TilemapArea, Vram, VramBank,
|
||||
rgb_from_bytes, BgAttributes, ColourInner, GpuInterrupts, Lcdc, Oam, ObjPalette, ObjSize,
|
||||
Object, ObjectFlags, Palette, Stat, TiledataArea, TilemapArea, Vram, VramBank,
|
||||
},
|
||||
};
|
||||
use crate::{
|
||||
|
@ -61,7 +61,14 @@ where
|
|||
pub fn new(cgb: bool, window: R, tile_window_renderer: Option<R>) -> Self {
|
||||
let tile_window = tile_window_renderer
|
||||
.map(|tile_window_renderer| TileWindow::new(tile_window_renderer, cgb));
|
||||
let buffer = vec![ColourInner::Error.rgb_bytes(None, false).into(); WIDTH * HEIGHT];
|
||||
let buffer = vec![
|
||||
if cgb {
|
||||
rgb_from_bytes(0xFFFF).into()
|
||||
} else {
|
||||
ColourInner::Error.rgb_bytes(None).into()
|
||||
};
|
||||
WIDTH * HEIGHT
|
||||
];
|
||||
|
||||
Self {
|
||||
buffer,
|
||||
|
@ -217,7 +224,7 @@ where
|
|||
} else {
|
||||
for x in 0..WIDTH {
|
||||
self.buffer[(scanline as usize * WIDTH) + x] = ColourInner::Error
|
||||
.rgb_bytes(None, self.cgb_data.is_some())
|
||||
.rgb_bytes(self.cgb_data.as_ref().map(|d| (&d.palettes.bg, 0_u8)))
|
||||
.into();
|
||||
}
|
||||
}
|
||||
|
@ -362,7 +369,7 @@ where
|
|||
{
|
||||
let cgb_data = self.cgb_data.as_ref().map(|v| {
|
||||
(
|
||||
v.palettes.obj,
|
||||
&v.palettes.obj,
|
||||
if self.is_cgb_mode() {
|
||||
object.flags.cgb_palette
|
||||
} else {
|
||||
|
@ -371,8 +378,7 @@ where
|
|||
)
|
||||
});
|
||||
|
||||
self.buffer[buffer_index] =
|
||||
colour.rgb_bytes(cgb_data, self.cgb_data.is_some()).into();
|
||||
self.buffer[buffer_index] = colour.rgb_bytes(cgb_data).into();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -451,10 +457,9 @@ where
|
|||
let cgb_data = self
|
||||
.cgb_data
|
||||
.as_ref()
|
||||
.map(|v| (v.palettes.bg, attributes.palette));
|
||||
.map(|v| (&v.palettes.bg, attributes.palette));
|
||||
|
||||
self.buffer[(scanline as usize * WIDTH) + x] =
|
||||
colour.rgb_bytes(cgb_data, self.cgb_data.is_some()).into();
|
||||
self.buffer[(scanline as usize * WIDTH) + x] = colour.rgb_bytes(cgb_data).into();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ where
|
|||
window.prepare(current_width, TILE_WINDOW_HEIGHT);
|
||||
Self {
|
||||
sprite_buffer: vec![
|
||||
ColourInner::Error.rgb_bytes(None, false).into();
|
||||
ColourInner::Error.rgb_bytes(None).into();
|
||||
current_width * TILE_WINDOW_HEIGHT
|
||||
],
|
||||
sprite_renderer: window,
|
||||
|
@ -56,10 +56,8 @@ where
|
|||
};
|
||||
self.sprite_renderer
|
||||
.resize(current_width, TILE_WINDOW_HEIGHT);
|
||||
self.sprite_buffer = vec![
|
||||
ColourInner::Error.rgb_bytes(None, false).into();
|
||||
current_width * TILE_WINDOW_HEIGHT
|
||||
];
|
||||
self.sprite_buffer =
|
||||
vec![ColourInner::Error.rgb_bytes(None).into(); current_width * TILE_WINDOW_HEIGHT];
|
||||
}
|
||||
for (tile_y, data_begin) in (0x8000..0xA000).step_by(0x10 * 16).enumerate() {
|
||||
self.draw_row(tile_y, data_begin, palette, memory, is_cgb_mode);
|
||||
|
@ -150,7 +148,7 @@ where
|
|||
|
||||
let addr = offset + real_px_x + (real_px_y * line_width);
|
||||
if addr < self.sprite_buffer.len() {
|
||||
self.sprite_buffer[addr] = colour.rgb_bytes(None, is_cgb_mode).into();
|
||||
self.sprite_buffer[addr] = colour.rgb_bytes(None).into();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -117,7 +117,7 @@ impl From<Colour> for [u8; 4] {
|
|||
}
|
||||
}
|
||||
|
||||
fn rgb_from_bytes(bytes: u16) -> Colour {
|
||||
pub(super) fn rgb_from_bytes(bytes: u16) -> Colour {
|
||||
let b = (bytes & (0b11111 << 10)) >> 10;
|
||||
let g = (bytes & (0b11111 << 5)) >> 5;
|
||||
let r = bytes & 0b11111;
|
||||
|
@ -139,16 +139,19 @@ fn rgb_from_bytes(bytes: u16) -> Colour {
|
|||
}
|
||||
|
||||
impl ColourInner {
|
||||
pub(super) fn rgb_bytes(
|
||||
&self,
|
||||
cgb_data: Option<(CgbPalette, u8)>,
|
||||
is_cgb_mode: bool,
|
||||
) -> Colour {
|
||||
pub(super) fn rgb_bytes(&self, cgb_data: Option<(&CgbPalette, u8)>) -> Colour {
|
||||
if let Some((cgb_palette, pallete_num)) = cgb_data {
|
||||
if *self == ColourInner::Error {
|
||||
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)
|
||||
+ (if *self == ColourInner::Error {
|
||||
if cfg!(debug_assertions) {
|
||||
return ERROR_COLOUR;
|
||||
} else {
|
||||
ColourInner::Zero
|
||||
}
|
||||
} else {
|
||||
*self
|
||||
} as usize
|
||||
* 2);
|
||||
|
||||
rgb_from_bytes(*from_bytes(&cgb_palette.data[offset..=offset + 1]))
|
||||
} else {
|
||||
|
@ -160,8 +163,6 @@ impl ColourInner {
|
|||
ColourInner::Error => {
|
||||
if cfg!(debug_assertions) {
|
||||
ERROR_COLOUR
|
||||
} else if is_cgb_mode {
|
||||
rgb_from_bytes(0xFFFF)
|
||||
} else {
|
||||
dmg_colours::ZERO
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue