• C

dvma in 640*480*16m

i am currently involved in a virtual reality project and i need to know how do i directly access the video memory in 640*480*16million color mode? i also need to know how the pallete registers can be arranged conveniently.
i am developing it in dos using turbo c compiler.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

There are no pallete registers in a 16 bit colour mode.
Which compiler?
can you tell us what OS are you using
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

Sanjeev070898Author Commented:
Edited text of question.
Sanjeev070898Author Commented:
Edited text of question.
As i know. you can't make it. Maximum you can use 256 colors.
nils pipenbrinckCommented:
you can't use the palette registers.
maybe your graphic card will allow you to modify them (to load different color ramps.. you could do a gamma correction that way) but it's not supported.

if you want do do truecolor under dos you have to use the vesa interface.

you can get infos about that everywhere (search for vesa vbe).. note, that you can't use vbe2.0 and linear frame buffer with turbo c (since you're doing realmode code, and the linear framebuffer only work in protected mode enviroments).

it needs a lot of dirty dos-coding to get it working (bios-interrupt calls and such stuff), but it's possible.

I think, you need this:
Here are two files: vesa.h and vesa.cpp

File vesa.h

typedef struct VbeInfoBlock {
             char VbeSignature[4];                 // VBE Signature = "VESA"
             unsigned int VbeVersion;              // VBE Version
             unsigned char far *OemStringPtr;      // Pointer to OEM String
             unsigned long Capabilities;           // Capabilities of graphics controller
             unsigned int far *VideoModePtr;       // Pointer to Video Mode List
             unsigned int TotalMemory;             // Number of 64kb memory blocks
             unsigned int OemSoftwareRev;          // VBE implementation Software revision
             unsigned char far *OemVendorNamePtr;  // Pointer to Vendor Name String
             unsigned char far *OemProductNamePtr; // Pointer to Product Name String
             unsigned char far *OemProductRevPtr;  // Pointer to Product Revision String
             unsigned int AccelVbeVersion;         // Vbe/AF Version
             unsigned int far *AccelVideoModePtr;  // Pointer to Accelerated Mode List
             unsigned char Reserved[216];          // Reserved for VBE implementation
             unsigned char OemData[256];           // Data Area for OEM Strings

 typedef struct ModeInfoBlock {
             // Mandatory information for all VBE revisions
             unsigned int ModeAttributes;         // Mode attributes
             unsigned char WinAAttributes;        // Window A attributes
             unsigned char WinBAttributes;        // Window B attributes
             unsigned int WinGranularity;         // Window granularity
             unsigned int WinSize;                // Window size
             unsigned int WinASegment;            // Window A start segment
             unsigned int WinBSegment;            // Window B start segment
             void (far *WinFuncPtr)();            // Pointer to window function
             unsigned int BytesPerScanLine;       // Bytes per scan line

             // Mandatory information for VBE 1.2 and above
             unsigned int XResolution;            // Horizontal resolution in pixels or chars
             unsigned int YResolution;            // Vertical resolution in pixels or chars
             unsigned char XCharSize;             // Character cell width in pixels
             unsigned char YCharSize;             // Character cell height in pixels
             unsigned char NumberOfPlanes;        // Number of memory planes
             unsigned char BitsPerPixel;          // Bits per pixel
             unsigned char NumberOfBanks;         // Number of banks
             unsigned char MemoryModel;           // Memory model type
             unsigned char BankSize;              // Bank size in KB
             unsigned char NumberOfImagePages;    // Number of images
             unsigned char Reserved1;             // Reserved for page function

             // Direct Color fields (required for direct(6) and YUV(7) memory models)
             unsigned char RedMaskSize;           // Size of direct color red mask in bits
             unsigned char RedFieldPosition;      // bit position of lsb of red mask
             unsigned char GreenMaskSize;         // size of direct color green mask in bits
             unsigned char GreenFieldPosition;    // bit position of lsb of green mask
             unsigned char BlueMaskSize;          // size of direct color blue mask in bits
             unsigned char BlueFieldPosition;     // bit position of lsb of blue mask
             unsigned char RsvdMaskSize;          // size of direct color reserved mask in bits
             unsigned char RsvdFieldPosition;     // bit position of lsb of reserved mask
             unsigned char DirectColorModeInfo;   // direct color mode attributes

             // Mandatory information for VBE 2.0 and above
             unsigned long PhysBasePtr;           // Physical address for flat frame buffer
             unsigned long Reserved2;             // Reserved - always set to 0
             unsigned int Reserved22;             // Reserved - always set to 0

             // Mandatory information for VBE 3.0 and above
             unsigned int LinBytesPerScanLine;    // Bytes per scan line for linear modes
             unsigned char BnkNumberOfImagePages; // Number of images for banked modes
             unsigned char LinNumberOfImagePages; // Number of images for linear modes
             unsigned char LinRedMaskSize;        // Size of direct color red mask (linear modes)
             unsigned char LinRedFieldPosition;   // Bit position of lsb of red mask (linear modes)
             unsigned char LinGreenMaskSize;      // Size of direct color green mask (linear modes)
             unsigned char LinGreenFieldPosition; // Bit position of lsb of green mask (linear modes)
             unsigned char LinBlueMaskSize;       // Size of direct color blue mask (linear modes)
             unsigned char LinBlueFieldPosition;  // Bit position of lsb of blue mask (linear modes)
             unsigned char LinRsvdMaskSize;       // Size of direct color rsvd mask (linear modes)
             unsigned char LinRsvdFieldPosition;  // Bit position of lsb of rsvd mask (linear modes)
             unsigned long MaxPixelClock;         // Maximum pixel clock (in Hz) for graphics modes
             unsigned char Reserved3[190];        // Remainder for ModeInfoBlock

File vesa.cpp

 #include <conio.h>
 #include <dos.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include "vesa.h"

 #define loword(l) ((int)(l))
 #define hiword(l) ((int)((l)>>16))

 VbeInfoBlock vi;
 ModeInfoBlock mi;
 int curent_bank=0;
 int granularity;
 unsigned char far *screen; // pointer to screen memory ( usually = 0xA000 )

 // Gets VESA information
 int GetVbeInfoBlock(VbeInfoBlock &vib) {
       asm {
             mov ax,0x4f00
             mov bx,ds
             mov es,bx
             mov di,word ptr vib
             int 0x10
       return _AX==0x4f00;

 // Gets video mode information
 int GetModeInfoBlock(ModeInfoBlock &mib,int mode) {
       asm {
             mov ax,0x4f01
             mov cx,ds
             mov es,cx
             mov di,word ptr mib
             mov cx,mode
             int 0x10
       return _AX==0x4f00;

 // Turns on video mode
 int SetVesaMode(int mode) {
       asm {
             mov ax,0x4f02
             mov bx,mode
             int 0x10
       return _AX==0x4f00;

 // Returns curent video mode
 int GetVesaMode() {
       asm {
             mov ax,0x4f03
             int 0x10
       return _AX==0x4f00;

 // Changes windows/banks
 void SetCurBank(int position,char window) {
        asm {
              mov ax,0x4f05
              mov bh,0
              mov bl,window
              mov dx,position
              int 0x10

 // Changes windows/banks ( Should be some faster )
 void _SetCurBank(int position,char window) {
        asm {
              mov bh,0
              mov bl,window
              mov dx,position

 // Finds a video mode
 void set_gfx_mode(int x_res,int y_res,int bits) {
        unsigned int mode[100],exit_f=0,n;
        unsigned int far *temp_ptr=vi.VideoModePtr;


        if (strcmp(vi.VbeSignature,"VESA")) exit(0);

        do { mode[n]=*temp_ptr++; } while ((mode[n++]!=0xffff));

        for (n=0;!exit_f;n++) {
              if ((mi.XResolution==x_res) && (mi.YResolution==y_res) && (mi.BitsPerPixel==bits))
                   if (mi.ModeAttributes & 1) exit_f=1;
                   else { printf("\n Mode does not supported in this hardware"); exit(0); }

        if (mode[n-1]==0xffff) { printf("\n Mode not found\n"); exit(0); }

        screen=(unsigned char far *)MK_FP(mi.WinASegment,0);

 // Draw a pixel on the screen
 void putpixel(int x,int y,unsigned char red,unsigned char green,unsigned char blue) {
        unsigned long addr=(unsigned long)mi.BytesPerScanLine*(long)y+
        (long)(x*3); // 3 becouse there are 3 bytes per pixel in 24 bits
        if (curent_bank!=hiword(addr)) _SetCurBank(hiword(addr),0);

 void main() {

        for (int j=0;j<600;j++)
              for (int i=0;i<800;i++)


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial

// Finds a video mode
 void set_gfx_mode(int x_res,int y_res,int bits) {
  unsigned int mode[100],exit_f=0,n;

n is not defined before it's first use!

should read:
  unsigned int mode[100],exit_f=0,n=0;

Also the Mode searcher algorithem's a bit dodgy, kamarey if you get a minite, can you rewrite it so an invalid mode doesn't hang your machine?
Thank. I forgot to do this, but it will be done by compiler. And the main idia here is how to write a pixel in 24-bit mode.
I know, I'm just lazy :)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.