From 2941ac6b8ecc1fd96b886219795f5d7e55bb85d8 Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Mon, 29 May 2023 23:32:41 +0100 Subject: Initial import --- src/Makefile | 25 +++++++++++++++++++++++++ src/main.c | 33 +++++++++++++++++++++++++++++++++ src/vga.c | 24 ++++++++++++++++++++++++ src/vga.h | 9 +++++++++ 4 files changed, 91 insertions(+) create mode 100644 src/Makefile create mode 100644 src/main.c create mode 100644 src/vga.c create mode 100644 src/vga.h (limited to 'src') 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 +#include +#include +#include + +#include + +#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 +#include +#include +#include + +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, ®s); +} 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 -- cgit v1.2.3