aboutsummaryrefslogtreecommitdiff
path: root/src/vga.c
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2023-07-08 22:35:16 +0100
committerJuan J. Martinez <jjm@usebox.net>2023-07-08 22:35:16 +0100
commit8871729a65615df0eab213bbbf942abe75771704 (patch)
tree34a4ab0f412c34383799e14816d1dfe288705085 /src/vga.c
parent5ae0b6490f5fd138f4cbf5c084680bb03b2fff05 (diff)
downloadgold-mine-run-8871729a65615df0eab213bbbf942abe75771704.tar.gz
gold-mine-run-8871729a65615df0eab213bbbf942abe75771704.zip
Avoid drawing the whole screen on each frame
This allows supporting 386DX "just about" (there will be flickering).
Diffstat (limited to 'src/vga.c')
-rw-r--r--src/vga.c59
1 files changed, 34 insertions, 25 deletions
diff --git a/src/vga.c b/src/vga.c
index ec56b60..13013b2 100644
--- a/src/vga.c
+++ b/src/vga.c
@@ -10,16 +10,22 @@
static uint8_t buffer[320 * 200];
static uint8_t *screen = NULL;
+static uint8_t *target = NULL;
uint8_t open_framebuffer()
{
if (__djgpp_nearptr_enable() == 0)
return 0;
- screen = (uint8_t *)(0xa0000 + __djgpp_conventional_base);
+ target = screen = (uint8_t *)(0xa0000 + __djgpp_conventional_base);
return 1;
}
+void blit_target(uint8_t t)
+{
+ target = t ? buffer : screen;
+}
+
void close_framebuffer()
{
__djgpp_nearptr_disable();
@@ -91,94 +97,97 @@ void set_palette(const uint8_t *palette)
void blit(const uint8_t *sprite, const Rect *dst)
{
- uint8_t *dbuffer = buffer + dst->x + dst->y * 320;
+ uint8_t b;
+ uint8_t *dtarget = target + dst->x + dst->y * 320;
for (uint16_t j = dst->h; j > 0; j--)
{
for (uint16_t i = dst->w; i > 0; i--)
{
- uint8_t b = *sprite++;
+ b = *sprite++;
/* transparent */
if (b == TRANSPARENT)
{
- dbuffer++;
+ dtarget++;
continue;
}
- *dbuffer++ = b;
+ *dtarget++ = b;
}
- dbuffer += 320 - dst->w;
+ dtarget += 320 - dst->w;
}
}
void blit_c(const uint8_t *sprite, const Rect *dst, uint8_t c)
{
- uint8_t *dbuffer = buffer + dst->x + dst->y * 320;
+ uint8_t b;
+ uint8_t *dtarget = target + dst->x + dst->y * 320;
for (uint16_t j = dst->h; j > 0; j--)
{
for (uint16_t i = dst->w; i > 0; i--)
{
- uint8_t b = *sprite++;
+ b = *sprite++;
/* transparent */
if (b == TRANSPARENT)
{
- dbuffer++;
+ dtarget++;
continue;
}
- *dbuffer++ = b ? c : b;
+ *dtarget++ = b ? c : b;
}
- dbuffer += 320 - dst->w;
+ dtarget += 320 - dst->w;
}
}
void blitrc(const uint8_t *sprite, const Rect *src, const Rect *dst)
{
- uint8_t *dbuffer = buffer + dst->x + dst->y * 320;
+ uint8_t b;
+ uint8_t *dtarget = target + dst->x + dst->y * 320;
sprite += src->x + src->y * src->w;
for (uint16_t j = dst->h; j > 0; j--)
{
for (uint16_t i = dst->w; i > 0; i--)
{
- uint8_t b = *sprite++;
+ b = *sprite++;
/* transparent */
if (b == TRANSPARENT)
{
- dbuffer++;
+ dtarget++;
continue;
}
- *dbuffer++ = b;
+ *dtarget++ = b;
}
sprite += src->w - dst->w;
- dbuffer += 320 - dst->w;
+ dtarget += 320 - dst->w;
}
}
void blit_erase(uint8_t c)
{
- memset(buffer, c, 320 * 200);
+ memset(target, c, 320 * 200);
}
-void blit_update()
+void blit_copy_all()
{
memcpy(screen, buffer, 320 * 200);
}
-void read_buffer(uint8_t *dst, const Rect *src)
+void blit_copy(const Rect *dst)
{
- uint8_t *s = buffer + src->y * 320 + src->x;
+ uint8_t *src = buffer + dst->x + dst->y * 320;
+ uint8_t *dtarget = screen + dst->x + dst->y * 320;
- for (uint16_t j = src->h; j > 0; j--)
+ for (uint16_t j = dst->h; j > 0; j--)
{
- for (uint16_t i = src->w; i > 0; i--)
- *dst++ = *s++;
-
- s += 320 - src->w;
+ memcpy(dtarget, src, dst->w);
+ src += 320;
+ dtarget += 320;
}
}