From 4c1f33184f1cba5006b4da8bbe2a161cd971aabc Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Sat, 17 Jun 2023 22:19:40 +0100 Subject: Function to read from the back buffer --- src/vga.c | 17 +++++++++++++++++ src/vga.h | 2 ++ 2 files changed, 19 insertions(+) (limited to 'src') diff --git a/src/vga.c b/src/vga.c index 0df25f8..cb2c5a8 100644 --- a/src/vga.c +++ b/src/vga.c @@ -129,3 +129,20 @@ void blit_update() { memcpy(screen, buffer, 320 * 200); } + +void read_buffer(uint8_t *dst, const Rect *src) +{ + for (int32_t j = src->y * 320; j < (src->y + src->h) * 320; j += 320) + for (int16_t i = src->x; i < src->x + src->w; i++) + { + uint8_t b; + + /* clipping */ + if (i < 0 || i >= 320 || j < 0 || j >= 200 * 320) + b = TRANSPARENT; + else + b = buffer[i + j]; + + *dst++ = b; + } +} diff --git a/src/vga.h b/src/vga.h index 40dbcdf..e6642f7 100644 --- a/src/vga.h +++ b/src/vga.h @@ -26,4 +26,6 @@ void blitrc(const uint8_t *sprite, const Rect *src, const Rect *dst); void blit_erase(uint8_t c); void blit_update(); +/* read from back buffer into memory */ +void read_buffer(uint8_t *dst, const Rect *src); #endif /* _VGA_H */ -- cgit v1.2.3