Search code examples
c++turbo-c++bgi

SVGA Programming in Turbo C


I want to do 1024*768 programming in Turbo C++ I am using Turbo C 3.0 where i am using the old VGA method to invoke graphics initgraph( &GraphDriver, &GraphMode, "..\\bgi" );

I want a library which can easily handle the SVGA mode and true colors.


Solution

  • There are several chip manufacturers for SVGA cards, and programming them may require specific code for each of them (unless your graphic board supports VESA, see below). I did that ages ago (in the 90s'), and I used the sources of POVRAY (a raytracer) as a reference.

    Fortunately, POVRAY still exists today: http://www.povray.org/

    You need to grab here http://www.povray.org/ftp/pub/povray/Old-Versions/ the sources of an old 1990's version that still has the routines for SVGA (the authors probably removed them in the recent versions !). You will find in the sources a bunch of inline assembly functions to initialize graphic mode and set a pixel for various graphic boards/manufacturers (S3, ET4000, ...). First unzip POVSRC.ZIP, then MACHINE.ZIP, then IBMPC.ZIP (and it is in IBM.C).

    The code is a bit esoteric: this is because initially the IBM PC was meant to have no more than 64Kb of video ram (at segment A000:0000). To allow having higher resolution, there is a technique that is called "bank switching", that allows changing a "window" in video RAM that is mapped to A000:0000.

    If your SVGA board supports the VESA standard (which is the case for most of them), then things might be easier, there is a standard interrupt for changing the graphic mode and for doing the bank switching (so you probably just need to find in POVRAY the VESA implementation of "set graphic mode" and "set pixel").

    Finally, I mention djgpp (g++ port to MSDOS) that has both a 32 bit DOS extender and a graphic library (grx) that uses the virtual memory in a nifty way to simulate a contiguous graphic memory (it creates virtual addresses for the video RAM and uses page faults interrupts to trigger bank switching automatically). I used it to do 3D graphic programming on a 33Mhz 486.

    Edit: After digging a bit, I found that the latest version that has the routines is the one here: http://www.povray.org/ftp/pub/povray/Old-Versions/Official-3.1g/MS-Dos/

    unzip povmsd_s.zip

    The routines are in SOURCE/MSDOS/VESAVBE.{H,C} (usable if your cards supports the VESA norm). Other cards have their routines in SOURCE/MSDOS/MSDOSVID.C