minor optimizations

This commit is contained in:
Yanyan Jiang 2017-07-28 09:17:21 -04:00
parent 3b2a74d9c3
commit 8aaaa602ae
2 changed files with 33 additions and 24 deletions

View File

@ -142,11 +142,12 @@ void fce_update_screen()
int h = _screen.height;
frame ++;
// if (frame % 10 == 0) printf("Frame %d (%d FPS)\n", frame, frame * 1000 / _uptime());
if (frame % 2 != 0) return;
int pad = (w - h) / 2;
for (int y = 0; y < h; y ++) {
if ( (y & 1) != (frame & 1) ) continue;
int y1 = y * H / h;
int y1 = y * (H - 1) / h + 1;
for (int x = pad; x < w - pad; x ++) {
row[x] = palette[canvas[y1][xmap[x] + 0xff]];
}

View File

@ -16,10 +16,16 @@ byte ppu_latch;
bool ppu_sprite_hit_occured = false;
byte ppu_screen_background[264][248];
// preprocess tables
static byte XHL[8][256][256];
static word ppu_ram_map[0x4000];
static inline void draw(int col, int row, int idx) {
canvas[row & 0xff][(col + 0xff) & 0x1ff] = idx;
}
// PPUCTRL Functions
inline word ppu_base_nametable_address() { return ppu_base_nametable_addresses[ppu.PPUCTRL & 0x3]; }
@ -66,6 +72,7 @@ inline void ppu_set_in_vblank(bool yesno) { common_mod
// RAM
inline word ppu_get_real_ram_address(word address)
{
if (address < 0x2000) {
@ -91,12 +98,12 @@ inline word ppu_get_real_ram_address(word address)
inline byte ppu_ram_read(word address)
{
return PPU_RAM[ppu_get_real_ram_address(address)];
return PPU_RAM[ppu_ram_map[address]];
}
inline void ppu_ram_write(word address, byte data)
{
PPU_RAM[ppu_get_real_ram_address(address)] = data;
PPU_RAM[ppu_ram_map[address]] = data;
}
// 3F01 = 0F (00001111)
@ -133,16 +140,17 @@ inline void ppu_ram_write(word address, byte data)
// Rendering
static void table_init() {
for (int x = 0; x < 8; x ++)
for (int h = 0; h < 256; h ++)
for (int l = 0; l < 256; l ++) {
XHL[x][h][l] = (((h >> (7 - x)) & 1) << 1) | ((l >> (7 - x)) & 1);
}
#define LOOP(x) \
{ \
byte color = (((h >> (7 - x)) & 1) << 1) | ((l >> (7 - x)) & 1); \
if (color != 0) { \
int idx = ppu_ram_read(palette_address + color); \
ppu_screen_background[(tile_x << 3) + x][ppu.scanline] = color; \
draw(scroll_base + x, ppu.scanline + 1, idx); \
} \
}
for (int x = 0; x < 0x4000; x ++) {
ppu_ram_map[x] = ppu_get_real_ram_address(x);
}
}
void ppu_draw_background_scanline(bool mirror)
{
@ -176,14 +184,15 @@ void ppu_draw_background_scanline(bool mirror)
palette_attribute &= 3;
word palette_address = 0x3F00 + (palette_attribute << 2);
LOOP(0)
LOOP(1)
LOOP(2)
LOOP(3)
LOOP(4)
LOOP(5)
LOOP(6)
LOOP(7)
for (int x = 0; x < 8; x ++) {
byte color = XHL[x][h][l];
// byte color = (((h >> (7 - x)) & 1) << 1) | ((l >> (7 - x)) & 1);
if (color != 0) {
int idx = ppu_ram_read(palette_address + color);
ppu_screen_background[(tile_x << 3) + x][ppu.scanline] = color;
draw(scroll_base + x, ppu.scanline + 1, idx);
}
}
taddr ++;
scroll_base += 8;
@ -222,9 +231,7 @@ void ppu_draw_sprite_scanline()
word palette_address = 0x3F10 + (palette_attribute << 2);
int x;
for (x = 0; x < 8; x++) {
int color = hflip ?
((((h >> x) & 1) << 1) | ((l >> x) & 1)):
((((h >> (7 - x)) & 1) << 1) | ((l >> (7 - x)) & 1));
int color = hflip ? XHL[7 - x][h][l] : XHL[x][h][l];
// Color 0 is transparent
if (color != 0) {
@ -387,6 +394,7 @@ void ppu_init()
ppu.PPUSTATUS |= 0xA0;
ppu.PPUDATA = 0;
ppu_2007_first_read = true;
table_init();
}
void ppu_sprram_write(byte data)