aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2023-05-29 23:32:41 +0100
committerJuan J. Martinez <jjm@usebox.net>2023-05-29 23:32:41 +0100
commit2941ac6b8ecc1fd96b886219795f5d7e55bb85d8 (patch)
tree9786ef28b990199e353bea285d6d5ecdb0a45e31 /src
downloadgold-mine-run-2941ac6b8ecc1fd96b886219795f5d7e55bb85d8.tar.gz
gold-mine-run-2941ac6b8ecc1fd96b886219795f5d7e55bb85d8.zip
Initial import
Diffstat (limited to 'src')
-rw-r--r--src/Makefile25
-rw-r--r--src/main.c33
-rw-r--r--src/vga.c24
-rw-r--r--src/vga.h9
4 files changed, 91 insertions, 0 deletions
diff --git a/src/Makefile b/src/Makefile
new file mode 100644
index 0000000..94b83eb
--- /dev/null
+++ b/src/Makefile
@@ -0,0 +1,25 @@
+BIN := ../game.exe
+CC := i586-pc-msdosdjgpp-gcc
+CFLAGS := -I. -c -Wall -pedantic -O2 -march=i386
+LDFLAGS := -s
+
+SRCS := $(wildcard *.c)
+OBJS := $(SRCS:.c=.o)
+
+all: $(BIN)
+
+$(BIN): $(OBJS)
+ $(CC) $(LDFLAGS) $(OBJS) $(LIBS) -o $@
+
+.c.o:
+ $(CC) $(CFLAGS) $< -o $@
+
+clean:
+ rm -f $(BIN) *.o Makefile.deps
+
+Makefile.deps: $(SRCS)
+ $(CC) $(CFLAGS) -MM *.[ch] > Makefile.deps
+
+.PHONY: all clean
+
+include Makefile.deps
diff --git a/src/main.c b/src/main.c
new file mode 100644
index 0000000..5b315df
--- /dev/null
+++ b/src/main.c
@@ -0,0 +1,33 @@
+#include <stdint.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include <conio.h>
+
+#include "vga.h"
+
+int main(int argc, char *argv[])
+{
+ /* set VGA 320x200, 256 col */
+ set_mode(0x13);
+
+ uint8_t *screen = open_framebuffer();
+ if (!screen)
+ {
+ fprintf(stderr, "ERROR: failed to open the framebuffer\n");
+ return 1;
+ }
+
+ for (int i = 0; i < 320 * 200 * 10; i++)
+ screen[rand() % (320 * 200)] = rand() % 255;
+
+ printf("Hello DOS!\n");
+
+ getch();
+
+ set_mode(3);
+ close_framebuffer();
+
+ return 0;
+}
diff --git a/src/vga.c b/src/vga.c
new file mode 100644
index 0000000..5badd82
--- /dev/null
+++ b/src/vga.c
@@ -0,0 +1,24 @@
+#include <stdlib.h>
+#include <stdint.h>
+#include <dpmi.h>
+#include <sys/nearptr.h>
+
+uint8_t *open_framebuffer()
+{
+ if (__djgpp_nearptr_enable() == 0)
+ return NULL;
+
+ return (uint8_t *)(0xa0000 + __djgpp_conventional_base);
+}
+
+void close_framebuffer()
+{
+ __djgpp_nearptr_disable();
+}
+
+void set_mode(uint8_t mode)
+{
+ __dpmi_regs regs = { 0 };
+ regs.x.ax = mode;
+ __dpmi_int(0x10, &regs);
+}
diff --git a/src/vga.h b/src/vga.h
new file mode 100644
index 0000000..f35e6dd
--- /dev/null
+++ b/src/vga.h
@@ -0,0 +1,9 @@
+#ifndef _VGA_H
+#define _VGA_H
+
+uint8_t *open_framebuffer();
+void close_framebuffer();
+
+void set_mode(uint8_t mode);
+
+#endif // _VGA_H