Compare commits
No commits in common. "cd2f9ddfd8157a520adc2e02b6ad66bd57bc9f79" and "1cc839c911796a34a69f427fe700d8a47d63a507" have entirely different histories.
cd2f9ddfd8
...
1cc839c911
@ -334,6 +334,31 @@ 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 {
|
||||||
@ -449,6 +474,7 @@ impl Display {
|
|||||||
|
|
||||||
// Calculate correct coords
|
// Calculate correct coords
|
||||||
let x: u8 = sprite.x.wrapping_sub(8);
|
let x: u8 = sprite.x.wrapping_sub(8);
|
||||||
|
// Flip sprite, TODO: What does this do in WIDE mode?
|
||||||
let y: u8 = sprite.y.wrapping_sub(16);
|
let y: u8 = sprite.y.wrapping_sub(16);
|
||||||
let render_y = self.curline;
|
let render_y = self.curline;
|
||||||
|
|
||||||
@ -456,14 +482,13 @@ impl Display {
|
|||||||
let wide_mode = self.control & CTRL_BG_SPRITE_SIZE > 0;
|
let wide_mode = self.control & CTRL_BG_SPRITE_SIZE > 0;
|
||||||
let actual_h = if wide_mode { 16 } else { 8 };
|
let actual_h = if wide_mode { 16 } else { 8 };
|
||||||
|
|
||||||
|
if sprite.is_y_flipped() {
|
||||||
|
eprintln!("Sorry, no y flip support yet, rendering as-is");
|
||||||
|
}
|
||||||
|
|
||||||
if y.wrapping_add(actual_h) > render_y && y <= render_y {
|
if y.wrapping_add(actual_h) > render_y && y <= render_y {
|
||||||
num_rendered += 1;
|
num_rendered += 1;
|
||||||
let tile_offset_y = if sprite.is_y_flipped() {
|
let tile_offset_y: usize = render_y as usize - y as usize;
|
||||||
render_y as usize - (y as usize) ^ (actual_h as usize - 1)
|
|
||||||
} else {
|
|
||||||
render_y as usize - y as usize
|
|
||||||
};
|
|
||||||
|
|
||||||
let tile_base_addr: usize = sprite.tile as usize * 16;
|
let tile_base_addr: usize = sprite.tile as usize * 16;
|
||||||
|
|
||||||
let tile_addr = tile_base_addr + tile_offset_y * 2;
|
let tile_addr = tile_base_addr + tile_offset_y * 2;
|
||||||
@ -491,10 +516,6 @@ impl Display {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if pixel_origin == PixelOrigin::BackgroundPriority {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
let x_maybe_flipped: u8 = if sprite.is_x_flipped() { x_o ^ 7 } else { x_o };
|
let x_maybe_flipped: u8 = if sprite.is_x_flipped() { x_o ^ 7 } else { x_o };
|
||||||
b1 = (tile_line_1 & 1 << (7 - x_o)) > 0;
|
b1 = (tile_line_1 & 1 << (7 - x_o)) > 0;
|
||||||
b2 = (tile_line_2 & 1 << (7 - x_o)) > 0;
|
b2 = (tile_line_2 & 1 << (7 - x_o)) > 0;
|
||||||
@ -600,9 +621,10 @@ impl Display {
|
|||||||
|
|
||||||
// GBC stuff
|
// GBC stuff
|
||||||
// Get BG map attributes
|
// Get BG map attributes
|
||||||
let bg_attribs = BgMapAttributes(self.vram1[vram_offset]);
|
let bg_attribs = self.get_background_attribute(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
|
||||||
let tile_offset_y = if bg_attribs.vertical_flip() {
|
let tile_offset_y = if bg_attribs.vertical_flip() {
|
||||||
7 ^ tile_offset_y
|
7 ^ tile_offset_y
|
||||||
} else {
|
} else {
|
||||||
@ -634,11 +656,7 @@ impl Display {
|
|||||||
let c = ((b2 as u8) * 2 + b1 as u8) as usize;
|
let c = ((b2 as u8) * 2 + b1 as u8) as usize;
|
||||||
// let color = self.background_palette.get_color(c);
|
// let color = self.background_palette.get_color(c);
|
||||||
let color = self.background_palette_cgb[bg_attribs.palette_number()].get_color(c);
|
let color = self.background_palette_cgb[bg_attribs.palette_number()].get_color(c);
|
||||||
if bg_attribs.has_priority() && (self.control & 1) == 1 {
|
self.set_pixel(render_x, render_y, color, PixelOrigin::Background(c));
|
||||||
self.set_pixel(render_x, render_y, color, PixelOrigin::BackgroundPriority);
|
|
||||||
} else {
|
|
||||||
self.set_pixel(render_x, render_y, color, PixelOrigin::Background(c));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -669,7 +687,11 @@ 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 {
|
||||||
@ -678,12 +700,13 @@ impl Display {
|
|||||||
&*self.vram1
|
&*self.vram1
|
||||||
};
|
};
|
||||||
|
|
||||||
let tile_offset_x = if bg_attribs.horizontal_flip() {
|
// TODO: Priority
|
||||||
|
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.vertical_flip() {
|
let tile_offset_y = if bg_attribs.horizontal_flip() {
|
||||||
7 ^ tile_offset_y
|
7 ^ tile_offset_y
|
||||||
} else {
|
} else {
|
||||||
tile_offset_y
|
tile_offset_y
|
||||||
|
|||||||
@ -11,23 +11,18 @@ impl BgMapAttributes {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn horizontal_flip(&self) -> bool {
|
pub fn horizontal_flip(&self) -> bool {
|
||||||
((self.0 >> 5) & 1) == 1
|
(self.0 >> 5) != 0
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn vertical_flip(&self) -> bool {
|
pub fn vertical_flip(&self) -> bool {
|
||||||
((self.0 >> 6) & 1) == 1
|
(self.0 >> 6) != 0
|
||||||
}
|
|
||||||
|
|
||||||
pub fn has_priority(&self) -> bool {
|
|
||||||
(self.0 >> 7) != 0
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, PartialEq)]
|
#[derive(Debug, Copy, Clone)]
|
||||||
pub enum PixelOrigin {
|
pub enum PixelOrigin {
|
||||||
Empty,
|
Empty,
|
||||||
Background(usize),
|
Background(usize),
|
||||||
BackgroundPriority,
|
|
||||||
Window,
|
Window,
|
||||||
Sprite,
|
Sprite,
|
||||||
}
|
}
|
||||||
@ -41,10 +36,10 @@ 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[1],
|
x: buf[0],
|
||||||
y: buf[0],
|
y: buf[1],
|
||||||
tile: buf[2],
|
tile: buf[2],
|
||||||
flags: buf[3],
|
flags: buf[3],
|
||||||
}
|
}
|
||||||
|
|||||||
@ -368,8 +368,9 @@ impl Interconnect {
|
|||||||
}
|
}
|
||||||
0xFF70 => {
|
0xFF70 => {
|
||||||
if self.wram_bank != val {
|
if self.wram_bank != val {
|
||||||
|
println!("Switching wram bank to {:02X}", val);
|
||||||
if val > 7 {
|
if val > 7 {
|
||||||
panic!("Trying to switch to wram bank {} which is non-existing", val);
|
panic!("R u sure this is correct?");
|
||||||
}
|
}
|
||||||
if val == 0 {
|
if val == 0 {
|
||||||
self.wram_bank = 1;
|
self.wram_bank = 1;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user