Path: blob/master/libsnes/bsnes/snes/alt/ppu-performance/background/mode7.cpp
2 views
#ifdef PPU_CPP12#define Clip(x) (((x) & 0x2000) ? ((x) | ~0x03ff) : ((x) & 0x03ff))34void PPU::Background::render_mode7() {5signed px, py;6signed tx, ty, tile, palette;78signed a = sclip<16>(self.regs.m7a);9signed b = sclip<16>(self.regs.m7b);10signed c = sclip<16>(self.regs.m7c);11signed d = sclip<16>(self.regs.m7d);1213signed cx = sclip<13>(self.regs.m7x);14signed cy = sclip<13>(self.regs.m7y);15signed hofs = sclip<13>(self.regs.mode7_hoffset);16signed vofs = sclip<13>(self.regs.mode7_voffset);1718signed y = (self.regs.mode7_vflip == false ? self.vcounter() : 255 - self.vcounter());1920uint16 *mosaic_x, *mosaic_y;21if(id == ID::BG1) {22mosaic_x = mosaic_table[self.bg1.regs.mosaic];23mosaic_y = mosaic_table[self.bg1.regs.mosaic];24} else {25mosaic_x = mosaic_table[self.bg2.regs.mosaic];26mosaic_y = mosaic_table[self.bg1.regs.mosaic];27}2829unsigned priority0 = (priority0_enable ? regs.priority0 : 0);30unsigned priority1 = (priority1_enable ? regs.priority1 : 0);31if(priority0 + priority1 == 0) return;3233signed psx = ((a * Clip(hofs - cx)) & ~63) + ((b * Clip(vofs - cy)) & ~63) + ((b * mosaic_y[y]) & ~63) + (cx << 8);34signed psy = ((c * Clip(hofs - cx)) & ~63) + ((d * Clip(vofs - cy)) & ~63) + ((d * mosaic_y[y]) & ~63) + (cy << 8);35for(signed x = 0; x < 256; x++) {36px = (psx + (a * mosaic_x[x])) >> 8;37py = (psy + (c * mosaic_x[x])) >> 8;3839switch(self.regs.mode7_repeat) {40case 0: case 1: {41px &= 1023;42py &= 1023;43tx = ((px >> 3) & 127);44ty = ((py >> 3) & 127);45tile = ppu.vram[(ty * 128 + tx) << 1];46palette = ppu.vram[(((tile << 6) + ((py & 7) << 3) + (px & 7)) << 1) + 1];47break;48}4950case 2: {51if((px | py) & ~1023) {52palette = 0;53} else {54px &= 1023;55py &= 1023;56tx = ((px >> 3) & 127);57ty = ((py >> 3) & 127);58tile = ppu.vram[(ty * 128 + tx) << 1];59palette = ppu.vram[(((tile << 6) + ((py & 7) << 3) + (px & 7)) << 1) + 1];60}61break;62}6364case 3: {65if((px | py) & ~1023) {66tile = 0;67} else {68px &= 1023;69py &= 1023;70tx = ((px >> 3) & 127);71ty = ((py >> 3) & 127);72tile = ppu.vram[(ty * 128 + tx) << 1];73}74palette = ppu.vram[(((tile << 6) + ((py & 7) << 3) + (px & 7)) << 1) + 1];75break;76}77}7879unsigned priority;80if(id == ID::BG1) {81priority = priority0;82} else {83priority = (palette & 0x80 ? priority1 : priority0);84palette &= 0x7f;85}8687if(palette == 0) continue;88unsigned plot_x = (self.regs.mode7_hflip == false ? x : 255 - x);8990unsigned color;91if(self.screen.regs.direct_color && id == ID::BG1) {92color = self.screen.get_direct_color(0, palette);93} else {94color = self.screen.get_palette(palette);95}9697if(regs.main_enable && !window.main[plot_x]) self.screen.output.plot_main(plot_x, color, priority, id);98if(regs.sub_enable && !window.sub[plot_x]) self.screen.output.plot_sub(plot_x, color, priority, id);99}100}101102#undef Clip103104#endif105106107