aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2023-05-30 23:32:52 +0100
committerJuan J. Martinez <jjm@usebox.net>2023-05-30 23:32:52 +0100
commitcbeff523d3c01471fcddfbf713b5d8d9e36dc1a9 (patch)
treeea96fc1371df2abae24b09954997277f762cad57 /src
parentd6cce83a4c5a6540f0b32e3bca9fb56c1f8855d1 (diff)
downloadgold-mine-run-cbeff523d3c01471fcddfbf713b5d8d9e36dc1a9.tar.gz
gold-mine-run-cbeff523d3c01471fcddfbf713b5d8d9e36dc1a9.zip
pngpal tool and first stab at embedding data on the EXE
WIP; the embedded data has an "environ" symbol that will cause issues when we embed more than one piece of data.
Diffstat (limited to 'src')
-rw-r--r--src/Makefile5
-rw-r--r--src/main.c12
-rw-r--r--src/vga.c8
-rw-r--r--src/vga.h3
4 files changed, 25 insertions, 3 deletions
diff --git a/src/Makefile b/src/Makefile
index 94b83eb..a53c697 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -4,7 +4,7 @@ CFLAGS := -I. -c -Wall -pedantic -O2 -march=i386
LDFLAGS := -s
SRCS := $(wildcard *.c)
-OBJS := $(SRCS:.c=.o)
+OBJS := $(SRCS:.c=.o) palette.o
all: $(BIN)
@@ -14,6 +14,9 @@ $(BIN): $(OBJS)
.c.o:
$(CC) $(CFLAGS) $< -o $@
+palette.o: ../data/sprites.png
+ ../tools/pngpal.py $< $@
+
clean:
rm -f $(BIN) *.o Makefile.deps
diff --git a/src/main.c b/src/main.c
index 5b315df..dd3cffa 100644
--- a/src/main.c
+++ b/src/main.c
@@ -7,11 +7,16 @@
#include "vga.h"
+/* embedded data */
+extern const uint8_t binary_palette_start[];
+
int main(int argc, char *argv[])
{
/* set VGA 320x200, 256 col */
set_mode(0x13);
+ set_palette(binary_palette_start);
+
uint8_t *screen = open_framebuffer();
if (!screen)
{
@@ -19,8 +24,11 @@ int main(int argc, char *argv[])
return 1;
}
- for (int i = 0; i < 320 * 200 * 10; i++)
- screen[rand() % (320 * 200)] = rand() % 255;
+ for (int i = 0; i < 16; i++)
+ {
+ memset(screen, i, 320 * 200);
+ getch();
+ }
printf("Hello DOS!\n");
diff --git a/src/vga.c b/src/vga.c
index 5badd82..b3ee0a2 100644
--- a/src/vga.c
+++ b/src/vga.c
@@ -2,6 +2,7 @@
#include <stdint.h>
#include <dpmi.h>
#include <sys/nearptr.h>
+#include <pc.h>
uint8_t *open_framebuffer()
{
@@ -22,3 +23,10 @@ void set_mode(uint8_t mode)
regs.x.ax = mode;
__dpmi_int(0x10, &regs);
}
+
+void set_palette(const uint8_t *palette)
+{
+ outportb(0x3c8, 0);
+ for (int i = 0; i < 768; i++)
+ outportb(0x3c9, (palette[i] * 63) / 255);
+}
diff --git a/src/vga.h b/src/vga.h
index f35e6dd..a9c46c6 100644
--- a/src/vga.h
+++ b/src/vga.h
@@ -6,4 +6,7 @@ void close_framebuffer();
void set_mode(uint8_t mode);
+/* the palette is expected to be 8 bit per color, and will be converted to VGA's 6 bit per color */
+void set_palette(const uint8_t *palette);
+
#endif // _VGA_H