From f515c558088a232e0796bfb3e46b6d969f5f204a Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Sat, 8 Jul 2023 12:38:13 +0100 Subject: Remove clipping and make the loops more efficient --- src/vga.c | 58 ++++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/vga.c b/src/vga.c index df79c7c..98cb404 100644 --- a/src/vga.c +++ b/src/vga.c @@ -91,59 +91,73 @@ void set_palette(const uint8_t *palette) void blit(const uint8_t *sprite, const Rect *dst) { - for (int32_t j = dst->y * 320; j < (dst->y + dst->h) * 320; j += 320) - for (int16_t i = dst->x; i < dst->x + dst->w; i++) + uint8_t *dbuffer = buffer + dst->x + dst->y * 320; + + for (int16_t j = 0; j < dst->h; j++) + { + for (int16_t i = 0; i < dst->w; i++) { uint8_t b = *sprite++; /* transparent */ if (b == TRANSPARENT) + { + dbuffer++; continue; + } - /* clipping */ - if (i < 0 || i >= 320 || j < 0 || j >= 200 * 320) - continue; - - buffer[i + j] = b; + *dbuffer++ = b; } + dbuffer += 320 - dst->w; + } } void blit_c(const uint8_t *sprite, const Rect *dst, uint8_t c) { - for (int32_t j = dst->y * 320; j < (dst->y + dst->h) * 320; j += 320) - for (int16_t i = dst->x; i < dst->x + dst->w; i++) + uint8_t *dbuffer = buffer + dst->x + dst->y * 320; + + for (int16_t j = 0; j < dst->h; j++) + { + for (int16_t i = 0; i < dst->w; i++) { uint8_t b = *sprite++; /* transparent */ if (b == TRANSPARENT) + { + dbuffer++; continue; + } - /* clipping */ - if (i < 0 || i >= 320 || j < 0 || j >= 200 * 320) - continue; - - buffer[i + j] = b ? c : b; + *dbuffer++ = b ? c : b; } + dbuffer += 320 - dst->w; + } } void blitrc(const uint8_t *sprite, const Rect *src, const Rect *dst) { - for (int32_t j = dst->y * 320, sy = src->y * src->w; j < (dst->y + dst->h) * 320; j += 320, sy += src->w) - for (int16_t i = dst->x, sx = src->x; i < dst->x + dst->w; i++, sx++) + uint8_t *dbuffer = buffer + dst->x + dst->y * 320; + sprite += src->x + src->y * src->w; + + for (int16_t j = 0; j < dst->h; j++) + { + for (int16_t i = 0; i < dst->w; i++) { - uint8_t b = sprite[sx + sy]; + uint8_t b = *sprite++; /* transparent */ if (b == TRANSPARENT) + { + dbuffer++; continue; + } - /* clipping */ - if (i < 0 || i >= 320 || j < 0 || j >= 200 * 320) - continue; - - buffer[i + j] = b; + *dbuffer++ = b; } + sprite += src->w - dst->w; + dbuffer += 320 - dst->w; + } } void blit_erase(uint8_t c) -- cgit v1.2.3