Implementing vertical sync MS DOS C++

133 Views Asked by At

I'm right now developing a game for ms dos in C++ (compiler: DJGPP) and need to test if the VGA card is currently in the vertical blanking interval. Is there a memory address I can just read? How can I check for this?

1

There are 1 best solutions below

0
Count_MHM On

What you're looking for is the port 0x03DA. (0x03BA if using MDA)

//0x03DA:
//      Read:  status bits are same as MDA (port 3baH) or CGA (port 3daH)
//      ╓7┬6┬5┬4┬3┬2┬1┬0╖
//      ║       │ │ │ │ ║
//      ╙─┴─┴─┴─┴╥┴╥┴╥┴╥╜ bit
//               ║ ║ ║ ╚═► 0: retrace.  1=display is in vert or horiz retrace.
//               ║ ║ ╚═══► 1: 1=light pen is triggered; 0=armed
//               ║ ╚═════► 2: 1=light pen switch is open; 0=closed
//               ╚═══════► 3: 1=vertical sync pulse is occurring.

// header that includes inp()
#include <conio.h> // for OpenWatcom
#include <pc.h>    // for DJGPP

bool isVsync()
{
    return (inp(0x03DA) & 0x08);
}