ppu: Fix window
This commit is contained in:
parent
bdf51448f7
commit
b7c1d9b8a0
150
src/display.rs
150
src/display.rs
@ -843,87 +843,95 @@ impl Display {
|
|||||||
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.
|
||||||
// Screen coordinates of the top left corner are WX-7, WY
|
// Screen coordinates of the top left corner are WX-7, WY
|
||||||
|
// Quick check if the window is visible at all.
|
||||||
if self.windowx < 167 && self.windowy < 144 {
|
if self.windowx < 167 && self.windowy < 144 {
|
||||||
//let rx = self.windowx.wrapping_add(7);
|
let window_y_offset = render_y as i16 - self.windowy as i16;
|
||||||
let rx = 7u8.wrapping_sub(self.windowx);
|
if self.windowx < 7 {
|
||||||
let ry = render_y.wrapping_add(self.windowy);
|
eprintln!("Window X position < 7, bailing out");
|
||||||
for r_x in 0..160u8 {
|
} else if window_y_offset >= 144 || window_y_offset < 0 {
|
||||||
let render_x = r_x.wrapping_add(rx);
|
// Not visible
|
||||||
// Absolute render coordinates
|
} else {
|
||||||
let tile_index_x: u8 = render_x >> 3;
|
let window_y_offset = window_y_offset as u8;
|
||||||
let tile_index_y: u8 = ry >> 3;
|
let window_x_offset = self.windowx - 7;
|
||||||
let tile_offset_x: u8 = render_x & 7;
|
|
||||||
let tile_offset_y: u8 = ry & 7;
|
|
||||||
|
|
||||||
let vram_offset: usize =
|
for r_x in 0..(160u8 - window_x_offset) {
|
||||||
window_map + (tile_index_y as usize) * 32 + tile_index_x as usize;
|
let render_x = r_x.wrapping_add(window_x_offset);
|
||||||
|
// Absolute render coordinates
|
||||||
|
let tile_index_x: u8 = render_x >> 3;
|
||||||
|
let tile_index_y: u8 = window_y_offset >> 3;
|
||||||
|
let tile_offset_x: u8 = render_x & 7;
|
||||||
|
let tile_offset_y: u8 = window_y_offset & 7;
|
||||||
|
|
||||||
// Obtain tile ID in this area
|
let vram_offset: usize =
|
||||||
let tile_id = self.vram0[vram_offset];
|
window_map + (tile_index_y as usize) * 32 + tile_index_x as usize;
|
||||||
|
|
||||||
let bg_attribs = self.get_background_attribute(
|
// Obtain tile ID in this area
|
||||||
//tile_index_x as usize, tile_index_y as usize
|
let tile_id = self.vram0[vram_offset];
|
||||||
vram_offset,
|
|
||||||
);
|
|
||||||
|
|
||||||
// Get BG map attributes
|
let bg_attribs = self.get_background_attribute(
|
||||||
let vram = if bg_attribs.vram_bank_number() == 0 {
|
//tile_index_x as usize, tile_index_y as usize
|
||||||
&*self.vram0
|
vram_offset,
|
||||||
} else {
|
);
|
||||||
&*self.vram1
|
|
||||||
};
|
|
||||||
|
|
||||||
// TODO: Priority
|
// Get BG map attributes
|
||||||
let tile_offset_x = if bg_attribs.vertical_flip() {
|
let vram = if bg_attribs.vram_bank_number() == 0 {
|
||||||
7 ^ tile_offset_x
|
&*self.vram0
|
||||||
} else {
|
} else {
|
||||||
tile_offset_x
|
&*self.vram1
|
||||||
};
|
};
|
||||||
let tile_offset_y = if bg_attribs.horizontal_flip() {
|
|
||||||
7 ^ tile_offset_y
|
|
||||||
} else {
|
|
||||||
tile_offset_y
|
|
||||||
};
|
|
||||||
|
|
||||||
// Obtain tile information
|
// TODO: Priority
|
||||||
let tile_base_addr: usize = self.get_bg_window_tile_addr(tile_id);
|
let tile_offset_x = if bg_attribs.vertical_flip() {
|
||||||
let tile_addr = tile_base_addr + (tile_offset_y as usize) * 2;
|
7 ^ tile_offset_x
|
||||||
let tile_line_1 = vram[tile_addr];
|
} else {
|
||||||
let tile_line_2 = vram[tile_addr + 1];
|
tile_offset_x
|
||||||
|
};
|
||||||
|
let tile_offset_y = if bg_attribs.horizontal_flip() {
|
||||||
|
7 ^ tile_offset_y
|
||||||
|
} else {
|
||||||
|
tile_offset_y
|
||||||
|
};
|
||||||
|
|
||||||
// Get the correct bit
|
// Obtain tile information
|
||||||
let b1: bool = (tile_line_1 & 1 << (7 - tile_offset_x)) > 0;
|
let tile_base_addr: usize = self.get_bg_window_tile_addr(tile_id);
|
||||||
let b2: bool = (tile_line_2 & 1 << (7 - tile_offset_x)) > 0;
|
let tile_addr = tile_base_addr + (tile_offset_y as usize) * 2;
|
||||||
|
let tile_line_1 = vram[tile_addr];
|
||||||
|
let tile_line_2 = vram[tile_addr + 1];
|
||||||
|
|
||||||
let c = (b2 as u8) * 2 + b1 as u8;
|
// Get the correct bit
|
||||||
let origin = match c {
|
let b1: bool = (tile_line_1 & 1 << (7 - tile_offset_x)) > 0;
|
||||||
0 => PixelOrigin::Empty, // Hack so that objects will be in front of it.
|
let b2: bool = (tile_line_2 & 1 << (7 - tile_offset_x)) > 0;
|
||||||
_ => PixelOrigin::Window,
|
|
||||||
};
|
|
||||||
let c = self.background_palette_cgb[bg_attribs.palette_number()]
|
|
||||||
.get_color(c as usize);
|
|
||||||
self.set_pixel(render_x, render_y, c, origin);
|
|
||||||
/*
|
|
||||||
let lookup: [u8; 4] = [
|
|
||||||
self.background_palette & 3,
|
|
||||||
(self.background_palette >> 2) & 3,
|
|
||||||
(self.background_palette >> 4) & 3,
|
|
||||||
(self.background_palette >> 6) & 3,
|
|
||||||
];
|
|
||||||
let entry = MONOCHROME_PALETTE[lookup[c as usize] as usize];
|
|
||||||
|
|
||||||
// Draw stuff. We're currently only in monochrome mode
|
let c = (b2 as u8) * 2 + b1 as u8;
|
||||||
let origin = match c {
|
let origin = match c {
|
||||||
0 => PixelOrigin::Empty, // Hack so that objects will be in front of it.
|
0 => PixelOrigin::Empty, // Hack so that objects will be in front of it.
|
||||||
_ => PixelOrigin::Window,
|
_ => PixelOrigin::Window,
|
||||||
};
|
};
|
||||||
self.set_pixel(
|
let c = self.background_palette_cgb[bg_attribs.palette_number()]
|
||||||
render_x,
|
.get_color(c as usize);
|
||||||
render_y,
|
self.set_pixel(render_x, render_y, c, origin);
|
||||||
sdl2::pixels::Color::RGB(entry[0], entry[1], entry[2]),
|
/*
|
||||||
origin,
|
let lookup: [u8; 4] = [
|
||||||
);
|
self.background_palette & 3,
|
||||||
*/
|
(self.background_palette >> 2) & 3,
|
||||||
|
(self.background_palette >> 4) & 3,
|
||||||
|
(self.background_palette >> 6) & 3,
|
||||||
|
];
|
||||||
|
let entry = MONOCHROME_PALETTE[lookup[c as usize] as usize];
|
||||||
|
|
||||||
|
// Draw stuff. We're currently only in monochrome mode
|
||||||
|
let origin = match c {
|
||||||
|
0 => PixelOrigin::Empty, // Hack so that objects will be in front of it.
|
||||||
|
_ => PixelOrigin::Window,
|
||||||
|
};
|
||||||
|
self.set_pixel(
|
||||||
|
render_x,
|
||||||
|
render_y,
|
||||||
|
sdl2::pixels::Color::RGB(entry[0], entry[1], entry[2]),
|
||||||
|
origin,
|
||||||
|
);
|
||||||
|
*/
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user