www.digitalmars.com         C & C++   DMDScript  

c++.dos.32-bits - 32-bit Video DAC

reply "Imran Haider" <absolute1008 hotmail.com> writes:
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi.  I was wondering that if you set the video mode to a 32-bit mode =
(such as 640x480 in 32-bit color mode), where does the color DAC stay? I =
mean, in 256 color mode, it is reasonable for the video card to store =
768 (256 * 3) byte of color data. In 32-bit mode, there are over a =
billion colors, where do they all stay?
Dec 16 2001
next sibling parent "Walter" <walter digitalmars.com> writes:
The best book I've seen on programming graphics cards is the ZEN book:

    www.digitalmars.com/bibiliography.html



"Imran Haider" <absolute1008 hotmail.com> wrote in message
news:9vjc4d$2ob7$1 digitaldaemon.com...
Hi.  I was wondering that if you set the video mode to a 32-bit mode (such
as 640x480 in 32-bit color mode), where does the color DAC stay? I mean, in
256 color mode, it is reasonable for the video card to store 768 (256 * 3)
byte of color data. In 32-bit mode, there are over a billion colors, where
do they all stay?
Dec 16 2001
prev sibling next sibling parent reply Roland <rv ronetech.com> writes:
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit

Imran Haider a écrit :

 Hi.  I was wondering that if you set the video mode to a 32-bit mode
 (such as 640x480 in 32-bit color mode), where does the color DAC stay?
 I mean, in 256 color mode, it is reasonable for the video card to
 store 768 (256 * 3) byte of color data. In 32-bit mode, there are over
 a billion colors, where do they all stay?

I never tried to program for 32 bit color, even 16 bit. VBE int 10h fc 4f01h can give you informations about video memory organisation. Roland
Dec 18 2001
next sibling parent %u <g_the_best2006 yahoo.com> writes:
please help me
Oct 23 2006
prev sibling next sibling parent %u <g_the_best2006 yahoo.com> writes:
please help me
Oct 23 2006
prev sibling next sibling parent %u <g_the_best2006 yahoo.com> writes:
please help me
Oct 23 2006
prev sibling parent gkk <g_the_best2006 yahoo.com> writes:
please help me
Oct 23 2006
prev sibling next sibling parent Roland <rv ronetech.com> writes:
 Imran Haider a écrit :

 Hi.  I was wondering that if you set the video mode to a 32-bit mode (such as
640x480 in 32-bit color mode), where does the color DAC stay? I mean, in 256
color mode, it is reasonable for the video card to store 768 (256 * 3) byte of
color data. In 32-bit mode, there are over a billion colors, where do they all
stay?

Isn't it 24 bit color ? As told before never programmed for such modes. My bet is: There is 3 planes of 8 bit/pixel, one for red, one for green, one for blue. You switch from one plane to the other the same way as for 16 color ega/vga 1 bit/pixel planes modes. But it is just a bet.. Roland
Dec 18 2001
prev sibling parent Trevor Johns <trevorjohns yahoo.com> writes:
Imran Haider wrote:

 Hi.  I was wondering that if you set the video mode to a 32-bit mode 
 (such as 640x480 in 32-bit color mode), where does the color DAC stay? I 
 mean, in 256 color mode, it is reasonable for the video card to store 
 768 (256 * 3) byte of color data. In 32-bit mode, there are over a 
 billion colors, where do they all stay?
 

In HiColor & TrueColor modes each and every pixel holds it's own RGB value (3*5 bits per channel+spare bit=15-bit HiColor or use 6 bits for Green [the eye is more sensitive to green] for 16-bit HiColor; 8 bits per channel giving 24-bit color, then add a spare byte for 32-bit color [fits better into registers is all]). Since each pixel determines it's own exact color, you don't need any DAC to do color conversion as in palettized modes (what shade of purple is color number 7???) Here's some sample DOS code I wrote a while ago that should give you a start (requires a VESA driver - most video cards now come with it built into the BIOS or as a DOS TRS driver to load) VESA.H ====== /* * VESA.H - SuperVGA VESA Interface Routines */ #if !defined(VESA_H) #define VESA_H struct VESAInfo { char VESASignature[4]; /* "VESA" */ unsigned VESAVersion; char far * OEMString; unsigned char VESACapabilities[4]; unsigned far * VESAModePtr; /* ptr to mode numbers, -1 terminated */ unsigned MemorySize; /* # of 64K pages (VESA 1.2) */ char reserved[236]; }; struct VESAMode { unsigned ModeAttributes; /* 0000 0001 mode supported in hardware 0000 0010 Extended mode information available 0000 0100 Output functions supported by BIOS 0000 1000 Color mode (0=mono) 0001 0000 Graphics mode (0=text mode) */ unsigned char WinAAttributes; unsigned char WinBAttributes; /* 0000 0001 Window is supported 0000 0010 Window is readable 0000 0100 Window is writable */ unsigned WinGranularity; /* in K bytes */ unsigned WinSize; /* in K bytes */ unsigned WinASegment; /* window A segment address */ unsigned WinBSegment; /* window A segment address */ void (far * WinFuncPtr)(void); unsigned BytesPerLine; /* logical scanline length */ /* optional extended info */ unsigned XResolution; unsigned YResolution; unsigned char XCharSize; unsigned char YCharSize; unsigned char Planes; unsigned char BitsPerPixel; unsigned char Banks; unsigned char MemoryModel; /* 00h = Text mode 01h = CGA graphics 02h = Hercules graphics 03h = 4-plane planar (EGA) 04h = Packed pixel 05h = Non-chain 4, 256 color 06h = Direct Color (HiColor [15/16 bit] or TrueColor [24/32 bit]) 07h = YUV (Luminance/Chrominance) 08h-0Fh = Reserved, to be defined by VESA 10h-FFh = To be defined by OEM */ unsigned char BankSize; /* bank size in K */ unsigned char NumPages; unsigned char Reserved; unsigned char RedMask; unsigned char RedShift; unsigned char GreenMask; unsigned char GreenShift; unsigned char BlueMask; unsigned char BlueShift; unsigned char ReservedMask; unsigned char ReservedShift; unsigned char DirectColorInfo; char reserved[217]; }; int isVESA(void); int VESAMode(unsigned mode); void VESAPoint(unsigned x, unsigned y, long color); long VESARGB(unsigned char r, unsigned char g, unsigned char b); void VESAPallette(unsigned char *pal); enum VESAModes { V640x400x256 = 0x100, V640x480x256, V800x600x16, V800x600x256, V1024x768x16, V1024x768x256, V1280x1024x16, V1280x1024x256, V80x60, V132x25, V132x43, V132x50, V132x60, V320x200x32K, V320x200x64K, V320x200x16M, V640x480x32K, V640x480x64K, V640x480x16M, V800x600x32K, V800x600x64K, V800x600x16M, V1024x768x32K, V1024x768x64K, V1024x768x16M, V1280x1024x32K, V1280x1024x64K, V1280x1024x16M }; #endif VESA.C ====== /* * VESA.C - SuperVGA VESA Interface Routines */ #include "vesa.h" #include <dos.h> #include <limits.h> struct VESAInfo vinfo; struct VESAMode vmode; static unsigned vesapage; int isVESA(void) { struct VESAInfo far *fp = &vinfo; union REGS reg; struct SREGS sreg; reg.x.ax = 0x4f00; sreg.es = FP_SEG(fp); reg.x.di = FP_OFF(fp); return (int86x(0x10, &reg, &reg, &sreg) == 0x004f); } int VESAMode(unsigned mode) { union REGS reg; struct SREGS sreg; struct VESAMode far *fp = &vmode; vesapage = 0xffff; if (mode < 0x100) { reg.x.ax = mode; int86(0x10, &reg, &reg); if (mode == 0x13) { /* MCGA graphics */ vmode.ModeAttributes = 0x1f; vmode.WinAAttributes = 0x07; vmode.WinBAttributes = 0x00; vmode.WinGranularity = 64; vmode.WinSize = 64; vmode.WinASegment = 0xa000; vmode.WinBSegment = 0; vmode.BytesPerLine = 320; vmode.XResolution = 320; vmode.YResolution = 200; vmode.XCharSize = 8; vmode.YCharSize = 8; vmode.Planes = 1; vmode.BitsPerPixel = 8; vmode.Banks = 1; vmode.MemoryModel = 4; vmode.BankSize = 0; vesapage = 0; } return (1); } else { reg.x.ax = 0x4f01; /* get VESA mode info */ reg.x.cx = mode; sreg.es = FP_SEG(fp); reg.x.di = FP_OFF(fp); if (int86x(0x10, &reg, &reg, &sreg) != 0x004f || (vmode.ModeAttributes & 0x0001) == 0) /* mode not supported */ return (0); reg.x.ax = 0x4f02; reg.x.bx = mode; return (int86x(0x10, &reg, &reg, &sreg) == 0x004f); } } /* * Note: VESAPoint should work in all 256/32K/64K/16M color modes */ void VESAPoint(unsigned x, unsigned y, long color) { union REGS reg; struct SREGS sreg; unsigned long addr; unsigned char far *fp; unsigned pageno, offset; addr = (long)y * vmode.BytesPerLine + x * (vmode.BitsPerPixel/9+1); pageno = (unsigned)(addr / ((long)vmode.WinGranularity << 10)); offset = (unsigned)(addr % ((long)vmode.WinGranularity << 10)); if (pageno != vesapage) { reg.x.ax = 0x4f05; reg.x.bx = 0x0000; /* select bank, window A */ reg.x.dx = vesapage = pageno; int86x(0x10, &reg, &reg, &sreg); } fp = (unsigned char far *)(((long)vmode.WinASegment << 16) + offset); if (vmode.BitsPerPixel == 8) *fp = (unsigned char)color; else if (vmode.BitsPerPixel == 15 || vmode.BitsPerPixel == 16) *((unsigned far *)fp) = (unsigned) color; else if (vmode.BitsPerPixel == 24 || vmode.BitsPerPixel == 32) { *fp++ = (unsigned char) (color & 0xff); /* red */ *fp++ = (unsigned char) ((color >> 8) & 0xff); /* green */ *fp = (unsigned char) ((color >> 16) & 0xff); /* blue */ } } long VESARGB(unsigned char r, unsigned char g, unsigned char b) { long rl, gl, bl; rl = r >> (CHAR_BIT - vmode.RedMask); gl = g >> (CHAR_BIT - vmode.GreenMask); bl = b >> (CHAR_BIT - vmode.BlueMask); return (rl << vmode.RedShift) | (gl << vmode.GreenShift) | (bl << vmode.BlueShift); } void VESAPallette(unsigned char *pal) { union REGS reg; struct SREGS sreg; char far *fp = (char far *) pal; reg.x.ax = 0x1012; reg.x.bx = 0; /* starting pallette entry */ reg.x.cx = 256; sreg.es = FP_SEG(fp); reg.x.dx = FP_OFF(fp); int86x(0x10, &reg, &reg, &sreg); } ZZ3.C ===== /* * VESA graphics */ #include <stdio.h> #include <stdlib.h> #include <conio.h> #include <string.h> #include <dos.h> #include <limits.h> #include "vesa.h" extern struct VESAInfo vinfo; extern struct VESAMode vmode; void main(int argc, char *argv[]) { int x, y; if (!isVESA()) { fprintf(stderr, "VESA not installed\n"); exit(1); } if (!VESAMode(V800x600x32K)) { fprintf(stderr, "Mode not supported\n"); exit(1); } for (y = 172; y < 428; y++) { /* left */ for (x = 0; x < 256; x++) VESAPoint(x, y, VESARGB(x, y-172, 0)); /* RED-GREEN */ /* middle */ for (x = 272; x < 528; x++) VESAPoint(x, y, VESARGB(0, x-272, y-172)); /* GREEN-BLUE */ /* right */ for (x = 544; x < 800; x++) VESAPoint(x, y, VESARGB(y-172, 0, x-544)); /* BLUE-RED */ } cprintf("\a"); getch(); VESAMode(3); exit(0); }
Feb 20 2002