Remove single-instruction helper func

This commit is contained in:
Kevin Hamacher 2020-02-21 18:28:05 +01:00
parent 1cc839c911
commit 1890dd2d3a
2 changed files with 12 additions and 38 deletions

View File

@ -334,31 +334,6 @@ impl Display {
} }
} }
fn get_background_attribute(
&self,
//tile_index_x: usize,
//tile_index_y: usize,
vram_offset: usize,
) -> BgMapAttributes {
/*
let background_map = if self.control & CTRL_BG_TILE_MAP_SELECT != 0 {
0x1C00
} else {
0x1800
};
let vram_offset: usize =
background_map + ((tile_index_y as usize) * 32) + tile_index_x as usize;
*/
// Background attributes are only in this memory range.
assert!(
vram_offset >= 0x1800 && vram_offset < 0x2000,
format!("offset: {:04X}", vram_offset)
);
BgMapAttributes(self.vram1[vram_offset])
}
pub fn tick(&mut self, ticks: u16) { pub fn tick(&mut self, ticks: u16) {
self.status &= 0xFC; self.status &= 0xFC;
if self.control & CTRL_LCD_DISPLAY_ENABLE == 0 { if self.control & CTRL_LCD_DISPLAY_ENABLE == 0 {
@ -621,7 +596,7 @@ impl Display {
// GBC stuff // GBC stuff
// Get BG map attributes // Get BG map attributes
let bg_attribs = self.get_background_attribute(vram_offset); let bg_attribs = BgMapAttributes(self.vram1[vram_offset]);
let vram = [&*self.vram0, &*self.vram1][bg_attribs.vram_bank_number()]; let vram = [&*self.vram0, &*self.vram1][bg_attribs.vram_bank_number()];
// TODO: Priority // TODO: Priority
@ -687,11 +662,7 @@ impl Display {
// Obtain tile ID in this area // Obtain tile ID in this area
let tile_id = self.vram0[vram_offset]; let tile_id = self.vram0[vram_offset];
let bg_attribs = BgMapAttributes(self.vram1[vram_offset]);
let bg_attribs = self.get_background_attribute(
//tile_index_x as usize, tile_index_y as usize
vram_offset,
);
// Get BG map attributes // Get BG map attributes
let vram = if bg_attribs.vram_bank_number() == 0 { let vram = if bg_attribs.vram_bank_number() == 0 {
@ -700,13 +671,12 @@ impl Display {
&*self.vram1 &*self.vram1
}; };
// TODO: Priority let tile_offset_x = if bg_attribs.horizontal_flip() {
let tile_offset_x = if bg_attribs.vertical_flip() {
7 ^ tile_offset_x 7 ^ tile_offset_x
} else { } else {
tile_offset_x tile_offset_x
}; };
let tile_offset_y = if bg_attribs.horizontal_flip() { let tile_offset_y = if bg_attribs.vertical_flip() {
7 ^ tile_offset_y 7 ^ tile_offset_y
} else { } else {
tile_offset_y tile_offset_y

View File

@ -11,15 +11,19 @@ impl BgMapAttributes {
} }
pub fn horizontal_flip(&self) -> bool { pub fn horizontal_flip(&self) -> bool {
(self.0 >> 5) != 0 ((self.0 >> 5) & 1) == 1
} }
pub fn vertical_flip(&self) -> bool { pub fn vertical_flip(&self) -> bool {
(self.0 >> 6) != 0 ((self.0 >> 6) & 1) == 1
}
pub fn has_priority(&self) -> bool {
(self.0 >> 7) != 0
} }
} }
#[derive(Debug, Copy, Clone)] #[derive(Copy, Clone, Debug, PartialEq)]
pub enum PixelOrigin { pub enum PixelOrigin {
Empty, Empty,
Background(usize), Background(usize),
@ -36,7 +40,7 @@ pub struct Sprite {
impl Sprite { impl Sprite {
pub fn load(buf: &[u8]) -> Self { pub fn load(buf: &[u8]) -> Self {
assert!(buf.len() > 4); assert!(buf.len() >= 4);
Self { Self {
x: buf[0], x: buf[0],
y: buf[1], y: buf[1],