Friday, January 31, 2020

Wait for VSYNC in DOS (inline assembly)

#define VID_STATUS 03dah      
#define VSYNC_MASK 00001000b  

int main()
{
    while(1)         // forever loop
    {
        DrawWait:
        asm
        {
            mov dx, VID_STATUS
            in al, dx
            test al, VSYNC_MASK 
            jz DrawWait     
        }
        draw(); 
    }
    return 0;
}

This method is mostly elegant, but depending on your game and environment, you may need a second wait for the z flag to be set to ensure the draw routine only runs once. 

There IS another method (thanks: michaelangel007), perhaps not as great for games, but could be used for a variety of other purposes, and that is to reprogram the timer for a value other than 18.2/s. 
Reference link

No comments:

Post a Comment