Introduction

Here are some tidbits about a few compilers and some solutions to common VGA programming problems. Some of this information is from my experiences, other information is from people e-mailing me about their experiences. If anyone has any information about getting the code at this site to work with a particular compiler, let me know.

How do I compile the source code using DJGPP 2.0?

Well, the good news is that DJGPP source is now included on the site. In case you are wondering, here are the changes.

DJGPP creates protected mode programs, so you can't access the video segment directly without some trickery. You can use the __djgpp_nearptr_enable() function to get access to the first 640K of memory. So, in main() add these lines at the beggining:

if (__djgpp_nearptr_enable() == 0)
  exit(-1);
  
VGA=(byte *)(0xa0000 + __djgpp_conventional_base);
my_clock=(word *)(0x0046c + __djgpp_conventional_base);

At the end of the program, use __djgpp_nearptr_disable(); to get the program back to regular protected mode. Also, don't forget to #include <sys/nearptr.h>.

This should get all of the programs to work except mouse.c.

How do I compile the source code using Watcom C/C++ 10.6?

Like DJGPP, Watcom C/C++ creates protected-mode programs, but the first megabyte or memory can be access directly by your program without any changes. Memory is linear instead of based on segments and offsets. So, change this

byte *VGA=(byte*)0xA0000000L;

to this:

byte *VGA=(byte*)0xA0000L;

Also, chage all int86(); functions to int386(); and make sure you #include <i86.h>.

In the plot_pixel_slow(); function in pixel.c, change this

regs.x.cx = x;
regs.x.dx = y;

to this:

regs.w.cx = x;
regs.w.dx = y;

That should do it! All the programs should work except mouse.c.

How do I compile the source code using Turbo C 2.01?

Compiling the code at this site with Turbo C 2.01 (a free compiler from Borland) is fairly straightforward. In modes.c and unchain.c, change every instance of outpw to outport. Be sure to compile in the large memory model, like so:

tcc -ml -N filename.c

How do I compile the source code using an older version of Turbo C or Borland C?

Some people have told me the Turbo C compiler does not accept direct pointers. For those of you with Turbo C, every section of code that looks like this:

byte *VGA=(byte *)0xA0000000L;
word *my_clock=(word *)0x0000046C;

Should be changed to:

byte *VGA=(byte *)MK_FP(0xA000,0);
word *my_clock=(word *)MK_FP(0,0x046C);

Also, make sure to include <dos.h>.

How do I compile the source code using Quick C?

For users of Quick C, change #include <mem.h> to #include <memory.h>

How do I compile the source code using GCC?

You can't. The code is DOS-mode only, so you'll need a DOS compiler. GCC on Linux or other operating systems won't work, and the Windows port of GCC (Cygwin) won't work either. Try DJGPP, which is a DOS port of GCC.

How do I compile the source code using Visual C++?

You'll need Visual C++ 1.42, which isn't available anymore. Visual C++ 2.0 and above are for Windows only.

The code compiles fine, but I run the program the screen goes black and/or Windows locks up.

For Turbo C, Borland C, and a few others, the programs must be compiled in the LARGE memory model. Otherwise, the programs will crash when they try to access the video memory area.

When I compile, I get the error “Code has no effect in function” and it points to the outp() function.

I've heard about this happening in Turbo C 3.0, and Borland C 4.5. At the top of the program, insert the code #undef outp.

When I run the program, I get the error “Not enough memory for double buffer”.

I thinks this only happens in older versions of Borland C/Turbo C. If you are running the program from the IDE, there is not enough conventional memory to run both the IDE and the program at the same time. After you compile, either exit Borland C to run the program or go to a dos shell to run the program.

Some people wrote in and said this: Change the debugger memory. Go to the options menu, then debugger. Change the program heap size to around 350K or so.

I have Borland C++ 5.0 for Windows 95 and I can't get the programs to compile. It says undefined structure 'REGS'.

Make sure you compile the programs for DOS, not Windows.

The programs only seem to work with the bitmaps that come with each program (i.e. rocket.bmp and mset.bmp).

Here are four reasons your bitmaps may not be working:

  1. Make sure the bitmap's width is divisible by 4 (for example, a width of 24 is okay but a width of 25 is not)
  2. In your paint program, do not save your bitmaps as compressed or RLE bitmaps. The code can only handle uncompressed format BMP files.
  3. In your paint program, make sure you save in 256-color (8 bit) format.
  4. Use the code from palette.c (rather than bitmap.c) if your bitmap uses a non-standard palette.

If you've done these four things and you are still having a problem, email me the bitmap and I will try to figure it out.

How do you display text in mode 0x13?

You can use the BIOS fonts, but it's best to write your own font routines. You can easily create a bitmap for the ASCII characters in a paint program, and then write the code to read the bitmaps and display a string. Plus, bitmap fonts look a lot better than the BIOS fonts.

What is a good graphics program?

Paint Shop Pro is a great graphics program for Windows, and I use it all the time. Download the shareware version at www.corel.com. You could use Microsoft Paint that comes with Windows, but you'll be better off with a more powerful graphics program.

Could you please send me information on 640x480 or 800x600 or [enter your favorite video mode here]?

Sorry, I really don't have any VESA SVGA code to give out. Check out Steel's page and look at the “VESA” programming information.

ARGH! Help me! I've got an assignment due tomorrow, could you please modify your code to my assignment's specifications and send it to me?

This always makes me laugh. The funny thing is, this question gets asked quite often. Short answer: No. Long answer: Do your own work.