aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2023-06-08 21:49:39 +0100
committerJuan J. Martinez <jjm@usebox.net>2023-06-08 21:49:39 +0100
commitc5e314048afd1ba3f87204b0655af70f95ae7ab1 (patch)
treea6865eff98ff79293b7f88679e46c22b17b1f32a
parent3e77771703d1be4d6ef363267caa15535ec333af (diff)
downloadgold-mine-run-c5e314048afd1ba3f87204b0655af70f95ae7ab1.tar.gz
gold-mine-run-c5e314048afd1ba3f87204b0655af70f95ae7ab1.zip
Set VGA 320x200 256 col at 60Hz
-rw-r--r--TODO.md3
-rw-r--r--src/vga.c28
2 files changed, 29 insertions, 2 deletions
diff --git a/TODO.md b/TODO.md
index 090b178..a3e7d49 100644
--- a/TODO.md
+++ b/TODO.md
@@ -1,6 +1,7 @@
# TODO
- drawing
+ - detect VGA
- sw blitter
- input
- joystick?
@@ -19,6 +20,4 @@
# REVIEW
-- review use of the timer
- - tick frequency is 18.2 times per second
- use dosemu instead of dosbox?
diff --git a/src/vga.c b/src/vga.c
index 6665c79..e90ebba 100644
--- a/src/vga.c
+++ b/src/vga.c
@@ -4,6 +4,7 @@
#include <dpmi.h>
#include <sys/nearptr.h>
#include <pc.h>
+#include <dos.h>
#include "vga.h"
@@ -29,6 +30,33 @@ void set_mode(uint8_t mode)
__dpmi_regs regs = { 0 };
regs.x.ax = mode;
__dpmi_int(0x10, &regs);
+
+ if (mode == 0x13)
+ {
+ /* setup the VGA: 320x200 @ 60Hz */
+ /* from: https://gist.github.com/juj/34306e6da02a8a7043e393f01e013f24 */
+ disable();
+
+ /* XXX: probably not neeed */
+ wait_vsync();
+
+ outportw(0x3d4, 0x0011); /* Turn off write protect to CRTC registers */
+ outportw(0x3d4, 0x0b06); /* New vertical total=525 lines, bits 0-7 */
+ outportw(0x3d4, 0x3e07); /* New vertical total=525 lines, bits 8-9 */
+
+ outportw(0x3d4, 0xb910); /* Vsync start=scanline 185 */
+ outportw(0x3d4, 0x8f12); /* Vertical display end=scanline 399, bits 0-7 */
+ outportw(0x3d4, 0xb815); /* Vertical blanking start=scanline 440, bits 0-7 */
+ outportw(0x3d4, 0xe216); /* Adjust vblank end position */
+ outportw(0x3d4, 0x8511); /* Vsync length=2 lines + turn write protect back on */
+
+ /* XXX: probably not neeed */
+ wait_vsync();
+
+ outportw(0x3d4, 0x2813); /* 8 pixel chars */
+ outportw(0x3d4, 0x8e11); /* restore retrace */
+ enable();
+ }
}
void wait_vsync()