Finish object view
This commit is contained in:
@@ -28,12 +28,57 @@ pub fn parse_palette(palette: u8, brts: &[u8], color: Color32) -> [Color32; 4] {
|
||||
]
|
||||
}
|
||||
|
||||
pub fn parse_cell(cell: u16) -> (usize, bool, bool, usize) {
|
||||
let char_index = (cell & 0x7ff) as usize;
|
||||
let vflip = cell & 0x1000 != 0;
|
||||
let hflip = cell & 0x2000 != 0;
|
||||
let palette_index = (cell >> 14) as usize;
|
||||
(char_index, vflip, hflip, palette_index)
|
||||
pub struct Object {
|
||||
pub x: i16,
|
||||
pub lon: bool,
|
||||
pub ron: bool,
|
||||
pub parallax: i16,
|
||||
pub y: i16,
|
||||
pub data: CellData,
|
||||
}
|
||||
|
||||
impl Object {
|
||||
pub fn parse(object: [u16; 4]) -> Self {
|
||||
let x = ((object[0] & 0x3ff) << 6 >> 6) as i16;
|
||||
let parallax = ((object[1] & 0x3ff) << 6 >> 6) as i16;
|
||||
let lon = object[1] & 0x8000 != 0;
|
||||
let ron = object[1] & 0x4000 != 0;
|
||||
let y = (object[2] & 0x0ff) as i16;
|
||||
// Y is stored as the bottom 8 bits of an i16,
|
||||
// so only sign extend if it's out of range.
|
||||
let y = if y > 224 { y << 8 >> 8 } else { y };
|
||||
let data = CellData::parse(object[3]);
|
||||
Self {
|
||||
x,
|
||||
lon,
|
||||
ron,
|
||||
parallax,
|
||||
y,
|
||||
data,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct CellData {
|
||||
pub palette_index: usize,
|
||||
pub hflip: bool,
|
||||
pub vflip: bool,
|
||||
pub char_index: usize,
|
||||
}
|
||||
|
||||
impl CellData {
|
||||
pub fn parse(cell: u16) -> Self {
|
||||
let char_index = (cell & 0x7ff) as usize;
|
||||
let vflip = cell & 0x1000 != 0;
|
||||
let hflip = cell & 0x2000 != 0;
|
||||
let palette_index = (cell >> 14) as usize;
|
||||
Self {
|
||||
char_index,
|
||||
vflip,
|
||||
hflip,
|
||||
palette_index,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn read_char_row(
|
||||
|
||||
Reference in New Issue
Block a user