Compare commits
5 Commits
1cc839c911
...
cd2f9ddfd8
| Author | SHA1 | Date | |
|---|---|---|---|
| cd2f9ddfd8 | |||
| 65e65be0eb | |||
| 52c73538cb | |||
| 515321110b | |||
| 1890dd2d3a |
@ -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 {
|
||||||
@ -474,7 +449,6 @@ 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;
|
||||||
|
|
||||||
@ -482,13 +456,14 @@ 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: usize = render_y as usize - y as usize;
|
let tile_offset_y = if sprite.is_y_flipped() {
|
||||||
|
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;
|
||||||
@ -516,6 +491,10 @@ 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;
|
||||||
@ -621,10 +600,9 @@ 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
|
|
||||||
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 {
|
||||||
@ -656,9 +634,13 @@ 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::BackgroundPriority);
|
||||||
|
} else {
|
||||||
self.set_pixel(render_x, render_y, color, PixelOrigin::Background(c));
|
self.set_pixel(render_x, render_y, color, PixelOrigin::Background(c));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (self.control & CTRL_WND_DISPLAY_ENABLE) == CTRL_WND_DISPLAY_ENABLE {
|
if (self.control & CTRL_WND_DISPLAY_ENABLE) == CTRL_WND_DISPLAY_ENABLE {
|
||||||
// Draw 'window' over the background.
|
// Draw 'window' over the background.
|
||||||
@ -687,11 +669,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 +678,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
|
||||||
|
|||||||
@ -11,18 +11,23 @@ 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),
|
||||||
|
BackgroundPriority,
|
||||||
Window,
|
Window,
|
||||||
Sprite,
|
Sprite,
|
||||||
}
|
}
|
||||||
@ -36,10 +41,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[0],
|
x: buf[1],
|
||||||
y: buf[1],
|
y: buf[0],
|
||||||
tile: buf[2],
|
tile: buf[2],
|
||||||
flags: buf[3],
|
flags: buf[3],
|
||||||
}
|
}
|
||||||
|
|||||||
@ -368,9 +368,8 @@ 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!("R u sure this is correct?");
|
panic!("Trying to switch to wram bank {} which is non-existing", val);
|
||||||
}
|
}
|
||||||
if val == 0 {
|
if val == 0 {
|
||||||
self.wram_bank = 1;
|
self.wram_bank = 1;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user