[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 232
  • Last Modified:

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.
0
Sanjeev070898
Asked:
Sanjeev070898
  • 3
  • 3
  • 2
  • +3
1 Solution
 
Lab_RatCommented:
There are no pallete registers in a 16 bit colour mode.
0
 
kamareyCommented:
Which compiler?
0
 
kamenimCommented:
Hi
can you tell us what OS are you using
0
Live webcast with Pinal Dave

Pinal Dave will teach you tricks to help identify the real root cause of database problems rather than red herrings. Attendees will learn scripts that they can use in their environment to immediately figure out their performance Blame Shifters and fix them quickly.

 
Sanjeev070898Author Commented:
Edited text of question.
0
 
Sanjeev070898Author Commented:
Edited text of question.
0
 
AlexVirochovskyCommented:
As i know. you can't make it. Maximum you can use 256 colors.
 
0
 
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.

nils
0
 
kamareyCommented:
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) {
       strcpy(vib.VbeSignature,"VBE2");
       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) {
        curent_bank=position;
        position*=granularity;
        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) {
        curent_bank=position;
        position*=granularity;
        asm {
              mov bh,0
              mov bl,window
              mov dx,position
        }
        mi.WinFuncPtr();
 }

 // 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;

        GetVbeInfoBlock(vi);

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

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

        for (n=0;!exit_f;n++) {
              GetModeInfoBlock(mi,mode[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); }

        SetVesaMode(mode[n-1]);
        SetCurBank(0,0);
        SetCurBank(0,1);
        granularity=mi.WinGranularity/64;
        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);
        screen[loword(addr)]=blue;
        screen[loword(addr)+1]=green;
        screen[loword(addr)+2]=red;
 }


 void main() {
        set_gfx_mode(800,600,24);

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

        getch();
        SetVesaMode(3);
 }
0
 
Lab_RatCommented:
Errata:

// 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?
0
 
kamareyCommented:
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.
0
 
Lab_RatCommented:
I know, I'm just lazy :)
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

  • 3
  • 3
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now