-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8983a4c
commit 9982f86
Showing
8 changed files
with
143 additions
and
17 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
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
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,14 +1,44 @@ | ||
use super::Layer; | ||
use crate::cpu::hardware::lcd::memory::Memory; | ||
use crate::cpu::hardware::lcd::registers::Registers; | ||
use crate::cpu::hardware::lcd::{Color, PixelInfo, LCD_WIDTH}; | ||
use serde::Deserialize; | ||
use serde::Serialize; | ||
use serde_with::serde_as; | ||
|
||
#[derive(Default, Serialize, Deserialize)] | ||
pub struct Layer2; | ||
#[serde_as] | ||
#[derive(Serialize, Deserialize)] | ||
pub struct Layer2 { | ||
#[serde_as(as = "[_; 240]")] | ||
bg_pixels_scanline: [Option<PixelInfo>; LCD_WIDTH], | ||
} | ||
|
||
impl Default for Layer2 { | ||
fn default() -> Self { | ||
Self { | ||
bg_pixels_scanline: [None; LCD_WIDTH], | ||
} | ||
} | ||
} | ||
|
||
impl Layer for Layer2 { | ||
#[allow(unused_variables)] | ||
fn render(&self, x: usize, y: usize) -> Option<crate::cpu::hardware::lcd::Color> { | ||
// TODO: To implement | ||
None | ||
fn render( | ||
&self, | ||
x: usize, | ||
y: usize, | ||
memory: &Memory, | ||
registers: &Registers, | ||
) -> Option<PixelInfo> { | ||
let idx: usize = y * LCD_WIDTH + x; | ||
|
||
let color_idx = memory.video_ram[idx] as usize; | ||
let low_nibble = memory.bg_palette_ram[color_idx * 2] as u16; | ||
let high_nibble = memory.bg_palette_ram[color_idx * 2 + 1] as u16; | ||
|
||
Some(PixelInfo { | ||
color: Color::from_palette_color((high_nibble << 8) | low_nibble), | ||
priority: 0, | ||
}) | ||
} | ||
} |
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
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