ableos_userland/libraries/able_graphics_library/src/ptmode/true_nes/mod.rs

100 lines
2.0 KiB
Rust

/// Nes colors
pub enum TrueNesColor {
Gray = 0x00,
}
#[derive(Clone, Copy)]
pub struct Tile;
impl Tile {
pub fn blank() -> Self {
Self {}
}
}
/// Nintendo is wrong and this is the closest approximation I will make to the scrolling logic for the NES.
#[allow(non_camel_case_types)]
#[derive(Clone, Copy)]
pub struct u9 {
pub upper_bit: bool,
pub lower_byte: u8,
}
//TODO impl a new() that takes various types
impl u9 {
pub fn new(id: u16) -> Self {
let high_byte: u8 = ((id >> 8) << 7) as u8;
let lower_byte: u8 = (id >> 8) as u8;
let high_bit = match high_byte {
0 => false,
_ => true,
};
Self {
upper_bit: high_bit,
lower_byte,
}
}
}
pub type TileID = u9;
/// An NES accurate tilemap.
pub type TileMap = [[TileID; 64]; 60];
pub struct PatternTable {
tile_data: [Tile; 256],
}
impl PatternTable {
pub fn blank() -> Self {
Self {
tile_data: [Tile; 256],
}
}
}
pub struct BackgroundMap {
tilemap: TileMap,
// scroll_offsets: [u9; 2],
}
impl BackgroundMap {
pub fn new() -> Self {
Self {
tilemap: [[u9::new(0); 64]; 60],
}
}
}
#[derive(Clone, Copy)]
pub struct Sprite {
x: u8,
y: u8,
tile_id_a: TileID,
/// Used to make 8x16 sprites
tile_id_b: Option<TileID>,
}
impl Sprite {
pub fn new() -> Self {
Self {
x: 0,
y: 0,
tile_id_a: TileID::new(0),
tile_id_b: None,
}
}
}
pub struct NesData {
sprites: [Sprite; 64],
background_map: BackgroundMap,
pattern_table_a: PatternTable,
pattern_table_b: PatternTable,
}
impl NesData {
pub fn new() -> Self {
NesData {
sprites: [Sprite::new(); 64],
background_map: BackgroundMap::new(),
pattern_table_a: PatternTable::blank(),
pattern_table_b: PatternTable::blank(),
}
}
}