rustyboy/src/display/structs.rs

86 lines
1.6 KiB
Rust

use super::*;
// Display color
pub struct BgMapAttributes(pub u8);
impl BgMapAttributes {
pub fn palette_number(&self) -> usize {
(self.0 & 0b111) as usize
}
pub fn vram_bank_number(&self) -> usize {
((self.0 >> 3) & 1) as usize
}
pub fn horizontal_flip(&self) -> bool {
(self.0 >> 5) != 0
}
pub fn vertical_flip(&self) -> bool {
(self.0 >> 6) != 0
}
}
#[derive(Debug, Copy, Clone)]
pub enum PixelOrigin {
Empty,
Background(usize),
Window,
Sprite,
}
pub struct Sprite {
pub x: u8,
pub y: u8,
pub tile: u8,
flags: u8,
}
impl Sprite {
pub fn load(buf: &[u8]) -> Self {
assert!(buf.len() > 4);
Self {
x: buf[0],
y: buf[1],
tile: buf[2],
flags: buf[3],
}
}
pub fn is_hidden(&self) -> bool {
self.x == 0 || self.y == 0
}
pub fn is_foreground(&self) -> bool {
(self.flags & SPRITE_OBJ_BG_PRIORITY) == 0
}
pub fn is_x_flipped(&self) -> bool {
(self.flags & SPRITE_X_FLIP) == SPRITE_X_FLIP
}
pub fn is_y_flipped(&self) -> bool {
(self.flags & SPRITE_Y_FLIP) == SPRITE_Y_FLIP
}
pub fn palette(&self) -> u8 {
// GB
/*
if (self.flags & SPRITE_PALETTE_NO) == 0 {
0
} else {
1
}
*/
// GBC
self.flags & 0b111
}
// GBC only
pub fn vram_bank(&self) -> u8 {
if (self.flags & SPRITE_TILE_VRAM_BANK) == 0 {
0
} else {
1
}
}
}