core/gpu: Optimize VRAM accesses all over the place

Former-commit-id: a14fc75968c5ce6016acc88fe2cc24eaac8b305b
Former-commit-id: 41f3142ea586c981cd5ccc7eb5a69f49bdcc591d
This commit is contained in:
Michel Heily 2020-05-30 13:13:25 +03:00
parent 71074c9c87
commit dc59d7f71f
4 changed files with 12 additions and 9 deletions

View file

@ -263,7 +263,7 @@ impl Gpu {
#[inline]
pub fn read_pixel_index_bpp4(&self, addr: u32, x: u32, y: u32) -> usize {
let ofs = addr - VRAM_ADDR + index2d!(u32, x / 2, y, 4);
let ofs = addr + index2d!(u32, x / 2, y, 4);
let ofs = ofs as usize;
let byte = self.vram.read_8(ofs as u32);
if x & 1 != 0 {
@ -275,7 +275,7 @@ impl Gpu {
#[inline]
pub fn read_pixel_index_bpp8(&self, addr: u32, x: u32, y: u32) -> usize {
let ofs = addr - VRAM_ADDR;
let ofs = addr;
self.vram.read_8(ofs + index2d!(u32, x, y, 8)) as usize
}
@ -312,7 +312,10 @@ impl Gpu {
pub fn render_scanline(&mut self) {
if self.dispcnt.force_blank() {
for x in self.frame_buffer[self.vcount * DISPLAY_WIDTH..].iter_mut().take(DISPLAY_WIDTH) {
for x in self.frame_buffer[self.vcount * DISPLAY_WIDTH..]
.iter_mut()
.take(DISPLAY_WIDTH)
{
*x = 0xf8f8f8;
}
return;

View file

@ -31,11 +31,11 @@ impl DisplayControl {
impl BgControl {
pub fn char_block(&self) -> u32 {
VRAM_ADDR + (self.character_base_block() as u32) * 0x4000
(self.character_base_block() as u32) * 0x4000
}
pub fn screen_block(&self) -> u32 {
VRAM_ADDR + (self.screen_base_block() as u32) * SCREEN_BLOCK_SIZE
(self.screen_base_block() as u32) * SCREEN_BLOCK_SIZE
}
pub fn size_regular(&self) -> (u32, u32) {

View file

@ -97,7 +97,7 @@ impl Gpu {
return;
}
let tile_base = OVRAM + 0x20 * (attrs.2.tile() as u32);
let tile_base = OVRAM - VRAM_ADDR + 0x20 * (attrs.2.tile() as u32);
let (tile_size, pixel_format) = attrs.tile_format();
let palette_bank = match pixel_format {
@ -190,7 +190,7 @@ impl Gpu {
return;
}
let tile_base = OVRAM + 0x20 * (attrs.2.tile() as u32);
let tile_base = OVRAM - VRAM_ADDR + 0x20 * (attrs.2.tile() as u32);
let (tile_size, pixel_format) = attrs.tile_format();
let palette_bank = match pixel_format {

View file

@ -56,7 +56,7 @@ impl Gpu {
+ SCREEN_BLOCK_SIZE * sbb
+ 2 * index2d!(u32, se_row, se_column, 32);
for _ in se_row..32 {
let entry = TileMapEntry(self.vram.read_16(map_addr - VRAM_ADDR));
let entry = TileMapEntry(self.vram.read_16(map_addr));
let tile_addr = tileset_base + entry.tile_index() * tile_size;
for tile_px in start_tile_x..8 {
@ -121,7 +121,7 @@ impl Gpu {
}
}
let map_addr = screen_block + index2d!(u32, t.0 / 8, t.1 / 8, texture_size / 8);
let tile_index = self.vram.read_8(map_addr - VRAM_ADDR) as u32;
let tile_index = self.vram.read_8(map_addr) as u32;
let tile_addr = char_block + tile_index * 0x40;
let color = self.get_palette_color(