Path: blob/master/libsnes/bsnes/snes/alt/ppu-compatibility/render/cache.cpp
2 views
#ifdef PPU_CPP12#define render_bg_tile_line_2bpp(mask) \3col = !!(d0 & mask) << 0; \4col += !!(d1 & mask) << 1; \5*dest++ = col67#define render_bg_tile_line_4bpp(mask) \8col = !!(d0 & mask) << 0; \9col += !!(d1 & mask) << 1; \10col += !!(d2 & mask) << 2; \11col += !!(d3 & mask) << 3; \12*dest++ = col1314#define render_bg_tile_line_8bpp(mask) \15col = !!(d0 & mask) << 0; \16col += !!(d1 & mask) << 1; \17col += !!(d2 & mask) << 2; \18col += !!(d3 & mask) << 3; \19col += !!(d4 & mask) << 4; \20col += !!(d5 & mask) << 5; \21col += !!(d6 & mask) << 6; \22col += !!(d7 & mask) << 7; \23*dest++ = col2425template<unsigned color_depth>26void PPU::render_bg_tile(uint16 tile_num) {27uint8 col, d0, d1, d2, d3, d4, d5, d6, d7;2829if(color_depth == COLORDEPTH_4) {30uint8 *dest = (uint8*)bg_tiledata[TILE_2BIT] + tile_num * 64;31unsigned pos = tile_num * 16;32unsigned y = 8;33while(y--) {34d0 = vram[pos ];35d1 = vram[pos + 1];36render_bg_tile_line_2bpp(0x80);37render_bg_tile_line_2bpp(0x40);38render_bg_tile_line_2bpp(0x20);39render_bg_tile_line_2bpp(0x10);40render_bg_tile_line_2bpp(0x08);41render_bg_tile_line_2bpp(0x04);42render_bg_tile_line_2bpp(0x02);43render_bg_tile_line_2bpp(0x01);44pos += 2;45}46bg_tiledata_state[TILE_2BIT][tile_num] = 0;47}4849if(color_depth == COLORDEPTH_16) {50uint8 *dest = (uint8*)bg_tiledata[TILE_4BIT] + tile_num * 64;51unsigned pos = tile_num * 32;52unsigned y = 8;53while(y--) {54d0 = vram[pos ];55d1 = vram[pos + 1];56d2 = vram[pos + 16];57d3 = vram[pos + 17];58render_bg_tile_line_4bpp(0x80);59render_bg_tile_line_4bpp(0x40);60render_bg_tile_line_4bpp(0x20);61render_bg_tile_line_4bpp(0x10);62render_bg_tile_line_4bpp(0x08);63render_bg_tile_line_4bpp(0x04);64render_bg_tile_line_4bpp(0x02);65render_bg_tile_line_4bpp(0x01);66pos += 2;67}68bg_tiledata_state[TILE_4BIT][tile_num] = 0;69}7071if(color_depth == COLORDEPTH_256) {72uint8 *dest = (uint8*)bg_tiledata[TILE_8BIT] + tile_num * 64;73unsigned pos = tile_num * 64;74unsigned y = 8;75while(y--) {76d0 = vram[pos ];77d1 = vram[pos + 1];78d2 = vram[pos + 16];79d3 = vram[pos + 17];80d4 = vram[pos + 32];81d5 = vram[pos + 33];82d6 = vram[pos + 48];83d7 = vram[pos + 49];84render_bg_tile_line_8bpp(0x80);85render_bg_tile_line_8bpp(0x40);86render_bg_tile_line_8bpp(0x20);87render_bg_tile_line_8bpp(0x10);88render_bg_tile_line_8bpp(0x08);89render_bg_tile_line_8bpp(0x04);90render_bg_tile_line_8bpp(0x02);91render_bg_tile_line_8bpp(0x01);92pos += 2;93}94bg_tiledata_state[TILE_8BIT][tile_num] = 0;95}96}9798#undef render_bg_tile_line_2bpp99#undef render_bg_tile_line_4bpp100#undef render_bg_tile_line_8bpp101102void PPU::flush_pixel_cache() {103104uint16 main;105106int backdropColor = interface()->getBackdropColor();107if(backdropColor == -1)108main = get_palette(0);109else main = backdropColor;110111uint16 sub = (regs.pseudo_hires || regs.bg_mode == 5 || regs.bg_mode == 6)112? main113: regs.color_rgb;114115unsigned i = 255;116do {117pixel_cache[i].src_main = main;118pixel_cache[i].src_sub = sub;119pixel_cache[i].bg_main = BACK;120pixel_cache[i].bg_sub = BACK;121pixel_cache[i].ce_main = false;122pixel_cache[i].ce_sub = false;123pixel_cache[i].pri_main = 0;124pixel_cache[i].pri_sub = 0;125} while(i--);126}127128void PPU::alloc_tiledata_cache() {129bg_tiledata[TILE_2BIT] = new uint8_t[262144]();130bg_tiledata[TILE_4BIT] = new uint8_t[131072]();131bg_tiledata[TILE_8BIT] = new uint8_t[ 65536]();132bg_tiledata_state[TILE_2BIT] = new uint8_t[ 4096]();133bg_tiledata_state[TILE_4BIT] = new uint8_t[ 2048]();134bg_tiledata_state[TILE_8BIT] = new uint8_t[ 1024]();135}136137//marks all tiledata cache entries as dirty138void PPU::flush_tiledata_cache() {139for(unsigned i = 0; i < 4096; i++) bg_tiledata_state[TILE_2BIT][i] = 1;140for(unsigned i = 0; i < 2048; i++) bg_tiledata_state[TILE_4BIT][i] = 1;141for(unsigned i = 0; i < 1024; i++) bg_tiledata_state[TILE_8BIT][i] = 1;142}143144void PPU::free_tiledata_cache() {145delete[] bg_tiledata[TILE_2BIT];146delete[] bg_tiledata[TILE_4BIT];147delete[] bg_tiledata[TILE_8BIT];148delete[] bg_tiledata_state[TILE_2BIT];149delete[] bg_tiledata_state[TILE_4BIT];150delete[] bg_tiledata_state[TILE_8BIT];151}152153#endif154155156