diff options
author | Juan J. Martinez <jjm@usebox.net> | 2023-07-08 12:38:13 +0100 |
---|---|---|
committer | Juan J. Martinez <jjm@usebox.net> | 2023-07-08 12:38:13 +0100 |
commit | f515c558088a232e0796bfb3e46b6d969f5f204a (patch) | |
tree | 1bc61eec33716ef496977d6fe3f4efe6d544a186 /src/vga.c | |
parent | 445d861069fde835b1207c046594c3c39437b1d3 (diff) | |
download | gold-mine-run-f515c558088a232e0796bfb3e46b6d969f5f204a.tar.gz gold-mine-run-f515c558088a232e0796bfb3e46b6d969f5f204a.zip |
Remove clipping and make the loops more efficient
Diffstat (limited to 'src/vga.c')
-rw-r--r-- | src/vga.c | 58 |
1 files changed, 36 insertions, 22 deletions
@@ -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) |