Porting MS-DOS Graphics Applications

Are you hesitant about porting your favorite VGA MS-DOS program to Linux? Using this tutorial and SVGALIB, porting will truly become a matter of minutes.
Waiting for the VGA Retrace

By waiting for the VGA retrace, we are telling the program to wait until the monitor's electron beam reaches the bottom of the screen. Since there is a short pause before it jumps back to the top, it is a good moment to switch palettes without seeing “rainbow colors”. Thus, before switching palettes, we should wait for the VGA retrace as follows:

        while (!(inportb(0x3da) & 8));
        while ( (inportb(0x3da) & 8));
Setting the VGA Palette

The following code assumes you have a character array of 768 values, representing the RGB values for 256 colors. For example:

char palette[768];
        where palette[0] = R value of color 0;
        where palette[1] = G value of color 0;
        where palette[2] = B value of color 0;
        for (i = 0; i < 256; i++)
        vga_setpalette(i, palette[i*3],
                palette[i*3+1], palette[i*3+2]);
        for (i = 0; i < 768; i ++)
                outportb(0x3C9, palette[i]);

After adding SVGALIB code to the program, it's time to compile. Simply compile with the -lvga option to link the SVGALIB library. This library is preinstalled on most Linux systems; thus, if you experience problems linking it, you probably don't have it installed and should download it.

jaw3d was programmed by the author and is a Nullsoft Inc. product. Other cross-platform applications may be obtained at http://www.nullsoft.com/.


Jawed Karim is a freshman computer science student at the University of Illinois at Urbana-Champaign and works part-time at the National Center for Supercomputing Applications. His hobbies include programming and bicycle road racing. He can be reached at jkarim@students.uiuc.edu.


White Paper
Linux Management with Red Hat Satellite: Measuring Business Impact and ROI

Linux has become a key foundation for supporting today's rapidly growing IT environments. Linux is being used to deploy business applications and databases, trading on its reputation as a low-cost operating environment. For many IT organizations, Linux is a mainstay for deploying Web servers and has evolved from handling basic file, print, and utility workloads to running mission-critical applications and databases, physically, virtually, and in the cloud. As Linux grows in importance in terms of value to the business, managing Linux environments to high standards of service quality — availability, security, and performance — becomes an essential requirement for business success.

Learn More

Sponsored by Red Hat

White Paper
Private PaaS for the Agile Enterprise

If you already use virtualized infrastructure, you are well on your way to leveraging the power of the cloud. Virtualization offers the promise of limitless resources, but how do you manage that scalability when your DevOps team doesn’t scale? In today’s hypercompetitive markets, fast results can make a difference between leading the pack vs. obsolescence. Organizations need more benefits from cloud computing than just raw resources. They need agility, flexibility, convenience, ROI, and control.

Stackato private Platform-as-a-Service technology from ActiveState extends your private cloud infrastructure by creating a private PaaS to provide on-demand availability, flexibility, control, and ultimately, faster time-to-market for your enterprise.

Learn More

Sponsored by ActiveState