aboutsummaryrefslogtreecommitdiff
path: root/src/vga.c
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2023-06-06 22:58:48 +0100
committerJuan J. Martinez <jjm@usebox.net>2023-06-06 22:58:48 +0100
commit1c1e91bd8bf4e9d08cd4d8ee41568e3d25ee8256 (patch)
tree9f556e4cf692f83938ec772342b4cd6bb89323d8 /src/vga.c
parent960db500527928e88bfb3787c9861a8b09f44749 (diff)
downloadgold-mine-run-1c1e91bd8bf4e9d08cd4d8ee41568e3d25ee8256.tar.gz
gold-mine-run-1c1e91bd8bf4e9d08cd4d8ee41568e3d25ee8256.zip
First stab at the sw blitter
Diffstat (limited to 'src/vga.c')
-rw-r--r--src/vga.c42
1 files changed, 39 insertions, 3 deletions
diff --git a/src/vga.c b/src/vga.c
index 981ad6f..e2fb7f9 100644
--- a/src/vga.c
+++ b/src/vga.c
@@ -1,15 +1,22 @@
#include <stdlib.h>
+#include <string.h>
#include <stdint.h>
#include <dpmi.h>
#include <sys/nearptr.h>
#include <pc.h>
-uint8_t *open_framebuffer()
+#include "vga.h"
+
+static uint8_t buffer[320 * 200];
+static uint8_t *screen = NULL;
+
+uint8_t open_framebuffer()
{
if (__djgpp_nearptr_enable() == 0)
- return NULL;
+ return 0;
- return (uint8_t *)(0xa0000 + __djgpp_conventional_base);
+ screen = (uint8_t *)(0xa0000 + __djgpp_conventional_base);
+ return 1;
}
void close_framebuffer()
@@ -36,3 +43,32 @@ void set_palette(const uint8_t *palette)
for (int i = 0; i < 768; i++)
outportb(0x3c9, palette[i] >> 2);
}
+
+void blit(const uint8_t *src, uint16_t x, uint16_t y, uint16_t w, uint16_t h)
+{
+ for (int32_t j = y; j < y + h; j++)
+ for (int32_t i = x; i < x + w; i++)
+ {
+ uint8_t b = *src++;
+
+ /* transparent */
+ if (b == TRANSPARENT)
+ continue;
+
+ /* clipping */
+ if (i < 0 || i >= 320 || j < 0 || j >= 200)
+ continue;
+
+ buffer[i + j * 320] = b;
+ }
+}
+
+void blit_erase(uint8_t c)
+{
+ memset(buffer, c, 320 * 200);
+}
+
+void blit_update()
+{
+ memcpy(screen, buffer, 320 * 200);
+}