aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2023-06-08 22:27:52 +0100
committerJuan J. Martinez <jjm@usebox.net>2023-06-08 22:27:52 +0100
commit71fba1c1de9509ed8e7a4db712f6b535fa1f1514 (patch)
treef5ae9c4f8b9feb46e1b20af45e84184a41a7d8c8 /src
parentcb6d24b838632e1269a5e4bb4e83425061f5d853 (diff)
downloadgold-mine-run-71fba1c1de9509ed8e7a4db712f6b535fa1f1514.tar.gz
gold-mine-run-71fba1c1de9509ed8e7a4db712f6b535fa1f1514.zip
Add blit rectangle
Allows blitting a section of a larger sprite.
Diffstat (limited to 'src')
-rw-r--r--src/vga.c19
-rw-r--r--src/vga.h2
2 files changed, 21 insertions, 0 deletions
diff --git a/src/vga.c b/src/vga.c
index 6b093c0..0df25f8 100644
--- a/src/vga.c
+++ b/src/vga.c
@@ -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);
diff --git a/src/vga.h b/src/vga.h
index 8dae83d..40dbcdf 100644
--- a/src/vga.h
+++ b/src/vga.h
@@ -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();