diff --git a/src/devices/ppu.c b/src/devices/ppu.c index a4b5d18..2850edc 100644 --- a/src/devices/ppu.c +++ b/src/devices/ppu.c @@ -50,23 +50,24 @@ ppu_palette(Ppu *p, Uint8 *addr) } for(i = 4; i < 16; ++i) p->palette[i] = p->palette[i / 4]; - p->fg.reqdraw = p->bg.reqdraw = 1; + p->fg.changed = p->bg.changed = 1; } void ppu_resize(Ppu *p, Uint16 width, Uint16 height) { - Uint8 - *bg = realloc(p->bg.p, width * height), - *fg = realloc(p->fg.p, width * height); + Uint8 + *bg = realloc(p->bg.pixels, width * height), + *fg = realloc(p->fg.pixels, width * height); if(!bg || !fg) return; - p->bg.p = bg; - p->fg.p = fg; + p->bg.pixels = bg; + p->fg.pixels = fg; p->width = width; p->height = height; ppu_clear(p, &p->bg); ppu_clear(p, &p->fg); + p->fg.changed = p->bg.changed = 1; } void @@ -74,7 +75,8 @@ ppu_clear(Ppu *p, Layer *layer) { Uint32 i, size = p->width * p->height; for(i = 0; i < size; ++i) - layer->p[i] = 0x00; + layer->pixels[i] = 0x00; + p->fg.changed = p->bg.changed = 1; } void @@ -82,8 +84,8 @@ ppu_redraw(Ppu *p, Uint32 *screen) { Uint32 i, size = p->width * p->height; for(i = 0; i < size; ++i) - screen[i] = p->palette[p->fg.p[i] ? p->fg.p[i] : p->bg.p[i]]; - p->fg.reqdraw = p->bg.reqdraw = 0; + screen[i] = p->palette[p->fg.pixels[i] ? p->fg.pixels[i] : p->bg.pixels[i]]; + p->fg.changed = p->bg.changed = 0; } void @@ -91,10 +93,10 @@ ppu_write(Ppu *p, Layer *layer, Uint16 x, Uint16 y, Uint8 color) { if(x < p->width && y < p->height) { Uint32 i = (x + y * p->width); - Uint8 prev = layer->p[i]; + Uint8 prev = layer->pixels[i]; if(color != prev) { - layer->p[i] = color; - layer->reqdraw = 1; + layer->pixels[i] = color; + layer->changed = 1; } } } diff --git a/src/devices/ppu.h b/src/devices/ppu.h index c6a16a0..75711f0 100644 --- a/src/devices/ppu.h +++ b/src/devices/ppu.h @@ -21,14 +21,14 @@ typedef unsigned short Uint16; typedef unsigned int Uint32; typedef struct Layer { - Uint8 *p; - Uint8 reqdraw; + Uint8 *pixels; + Uint8 changed; } Layer; typedef struct Ppu { - Layer fg, bg; Uint16 width, height; Uint32 palette[16]; + Layer fg, bg; } Ppu; void ppu_palette(Ppu *p, Uint8 *addr); diff --git a/src/uxnemu.c b/src/uxnemu.c index 46b9690..0d200b9 100644 --- a/src/uxnemu.c +++ b/src/uxnemu.c @@ -105,7 +105,6 @@ set_zoom(Uint8 scale) if(!gWindow) return; set_window_size(gWindow, (ppu.width + PAD * 2) * zoom, (ppu.height + PAD * 2) * zoom); - ppu.fg.reqdraw = ppu.bg.reqdraw = 1; } static int @@ -128,7 +127,6 @@ set_size(Uint16 width, Uint16 height, int is_resize) return error("SDL_UpdateTexture", SDL_GetError()); if(is_resize) set_window_size(gWindow, (ppu.width + PAD * 2) * zoom, (ppu.height + PAD * 2) * zoom); - ppu.fg.reqdraw = ppu.bg.reqdraw = 1; return 1; } @@ -550,7 +548,7 @@ run(Uxn *u) } breakout: uxn_eval(u, devscreen->vector); - if(ppu.fg.reqdraw || ppu.bg.reqdraw || devsystem->dat[0xe]) + if(ppu.fg.changed || ppu.bg.changed || devsystem->dat[0xe]) redraw(u); if(!BENCH) { elapsed = (SDL_GetPerformanceCounter() - begin) / (double)SDL_GetPerformanceFrequency() * 1000.0f;