What are you meant to do when you wake up on a Saturday morning without a clear idea of what to do that day? Get back into DOS programming of course.

First up I decided that I couldn’t be bothered with boring old 16 bit code as I like being able to have more than 64k of things, so I downloaded watcom C++ 1.9. It’s freely available now, which is nice as I could never afford it in the day and DOS/4GW is going to make a lot of future things easier (and make a lot of things harder too. Swings and roundabouts and all that). There’s a version 2 on github but I went with the original open source release for the first pass. I didn’t have a good reason to, I just did for nostalgia reasons.

So I wrote my first DOS program in, um, nearly 30 years probably?

#include <stdio.h>
#include <dos.h>

void set_graphics_mode(unsigned char mode)
{
    union REGS regs;
    regs.h.ah = 0x00;
    regs.h.al = mode;

    int386(0x10, &regs, &regs);
}

int main(int argc, char* argv[])
{
    unsigned char *vga=(unsigned char*)0xA0000L;
    set_graphics_mode(0x13);

    for(int x=0; x < 200; x++)
    {
        for(int y = 0; y < 320; y++)
        {
            unsigned short offset = 320*x + y;
            vga[offset] = y < 256 ? y : 255;
        }
    }

    getchar();
    set_graphics_mode(0x03);
    return 0;
}

I called that file test.cpp and then after installing watcom into dosbox. It’s easy enough to do, but you will need to look at the mount command in dosbox first and run something like: mount c c:\dosbox

After that you just need to run: wcl386 test.cpp

Once it’s compiled you can run it and get the oh so pretty VGA graphics out. VGA Graphics

Now to do something useful with this. Where’s my copy of Abrash’s black book?

There’s some handy links I’ve found (or rediscovered) already as well.