(Screen) Cached row only written when visible

This commit is contained in:
neauoire 2023-11-12 16:53:55 -08:00
parent 0536b821dc
commit ee7a69c8b4
1 changed files with 9 additions and 9 deletions

View File

@ -49,28 +49,28 @@ screen_fill(Uint8 *layer, int color)
void void
screen_rect(Uint8 *layer, Uint16 x1, Uint16 y1, Uint16 x2, Uint16 y2, int color) screen_rect(Uint8 *layer, Uint16 x1, Uint16 y1, Uint16 x2, Uint16 y2, int color)
{ {
int x, y, w, h; int row, x, y, w, h;
if(!x1 && !y1) { if(!x1 && !y1) {
screen_fill(layer, color); screen_fill(layer, color);
return; return;
} }
w = uxn_screen.width, h = uxn_screen.height; w = uxn_screen.width, h = uxn_screen.height;
for(y = y1; y < y2 && y < h; y++) for(y = y1; y < y2 && y < h; y++)
for(x = x1; x < x2 && x < w; x++) for(x = x1, row = y * w; x < x2 && x < w; x++)
layer[x + y * w] = color; layer[x + row] = color;
} }
static void static void
screen_2bpp(Uint8 *layer, Uint8 *ram, Uint16 addr, Uint16 x1, Uint16 y1, Uint16 color, int fx, int fy) screen_2bpp(Uint8 *layer, Uint8 *ram, Uint16 addr, Uint16 x1, Uint16 y1, Uint16 color, int fx, int fy)
{ {
int w = uxn_screen.width, h = uxn_screen.height, opaque = (color % 5); int row, w = uxn_screen.width, h = uxn_screen.height, opaque = (color % 5);
Uint8 *ch1 = &ram[addr], *ch2 = ch1 + 8; Uint8 *ch1 = &ram[addr], *ch2 = ch1 + 8;
Uint16 y, ymod = (fy < 0 ? 7 : 0), ymax = y1 + ymod + fy * 8; Uint16 y, ymod = (fy < 0 ? 7 : 0), ymax = y1 + ymod + fy * 8;
Uint16 x, xmod = (fx > 0 ? 7 : 0), xmax = x1 + xmod - fx * 8; Uint16 x, xmod = (fx > 0 ? 7 : 0), xmax = x1 + xmod - fx * 8;
for(y = y1 + ymod; y != ymax; y += fy) { for(y = y1 + ymod; y != ymax; y += fy) {
int row = y * w, c = *ch1++ | (*ch2++ << 8); int c = *ch1++ | (*ch2++ << 8);
if(y < h) if(y < h)
for(x = x1 + xmod; x != xmax; x -= fx, c >>= 1) { for(x = x1 + xmod, row = y * w; x != xmax; x -= fx, c >>= 1) {
Uint8 ch = (c & 1) | ((c >> 7) & 2); Uint8 ch = (c & 1) | ((c >> 7) & 2);
if((opaque || ch) && x < w) if((opaque || ch) && x < w)
layer[x + row] = blending[ch][color]; layer[x + row] = blending[ch][color];
@ -81,14 +81,14 @@ screen_2bpp(Uint8 *layer, Uint8 *ram, Uint16 addr, Uint16 x1, Uint16 y1, Uint16
static void static void
screen_1bpp(Uint8 *layer, Uint8 *ram, Uint16 addr, Uint16 x1, Uint16 y1, Uint16 color, int fx, int fy) screen_1bpp(Uint8 *layer, Uint8 *ram, Uint16 addr, Uint16 x1, Uint16 y1, Uint16 color, int fx, int fy)
{ {
int w = uxn_screen.width, h = uxn_screen.height, opaque = (color % 5); int row, w = uxn_screen.width, h = uxn_screen.height, opaque = (color % 5);
Uint8 *ch1 = &ram[addr]; Uint8 *ch1 = &ram[addr];
Uint16 y, ymod = (fy < 0 ? 7 : 0), ymax = y1 + ymod + fy * 8; Uint16 y, ymod = (fy < 0 ? 7 : 0), ymax = y1 + ymod + fy * 8;
Uint16 x, xmod = (fx > 0 ? 7 : 0), xmax = x1 + xmod - fx * 8; Uint16 x, xmod = (fx > 0 ? 7 : 0), xmax = x1 + xmod - fx * 8;
for(y = y1 + ymod; y != ymax; y += fy) { for(y = y1 + ymod; y != ymax; y += fy) {
int row = y * w, c = *ch1++; int c = *ch1++;
if(y < h) if(y < h)
for(x = x1 + xmod; x != xmax; x -= fx, c >>= 1) { for(x = x1 + xmod, row = y * w; x != xmax; x -= fx, c >>= 1) {
Uint8 ch = c & 1; Uint8 ch = c & 1;
if((opaque || ch) && x < w) if((opaque || ch) && x < w)
layer[x + row] = blending[ch][color]; layer[x + row] = blending[ch][color];