diff options
author | Juan J. Martinez <jjm@usebox.net> | 2023-06-08 22:27:52 +0100 |
---|---|---|
committer | Juan J. Martinez <jjm@usebox.net> | 2023-06-08 22:27:52 +0100 |
commit | 71fba1c1de9509ed8e7a4db712f6b535fa1f1514 (patch) | |
tree | f5ae9c4f8b9feb46e1b20af45e84184a41a7d8c8 | |
parent | cb6d24b838632e1269a5e4bb4e83425061f5d853 (diff) | |
download | gold-mine-run-71fba1c1de9509ed8e7a4db712f6b535fa1f1514.tar.gz gold-mine-run-71fba1c1de9509ed8e7a4db712f6b535fa1f1514.zip |
Add blit rectangle
Allows blitting a section of a larger sprite.
-rw-r--r-- | src/vga.c | 19 | ||||
-rw-r--r-- | src/vga.h | 2 |
2 files changed, 21 insertions, 0 deletions
@@ -101,6 +101,25 @@ void blit(const uint8_t *sprite, const Rect *dst) } } +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 b = sprite[sx + sy]; + + /* transparent */ + if (b == TRANSPARENT) + continue; + + /* clipping */ + if (i < 0 || i >= 320 || j < 0 || j >= 200 * 320) + continue; + + buffer[i + j] = b; + } +} + void blit_erase(uint8_t c) { memset(buffer, c, 320 * 200); @@ -21,6 +21,8 @@ void wait_vsync(); void set_palette(const uint8_t *palette); void blit(const uint8_t *sprite, const Rect *dst); +/* in src w is sprite width, h is sprite height */ +void blitrc(const uint8_t *sprite, const Rect *src, const Rect *dst); void blit_erase(uint8_t c); void blit_update(); |