Message-ID: <3842DB84.46B6E87D@interlog.com> From: Alan Illeman X-Mailer: Mozilla 4.04 [en] (Win95; U) MIME-Version: 1.0 Newsgroups: comp.os.msdos.djgpp Subject: Re: Newbie tries to plot a pixel and fails :) References: Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 291 Date: Mon, 29 Nov 1999 15:01:08 -0500 NNTP-Posting-Host: 154.5.74.15 X-Trace: cac1.rdr.news.psi.ca 943905251 154.5.74.15 (Mon, 29 Nov 1999 14:54:11 EST) NNTP-Posting-Date: Mon, 29 Nov 1999 14:54:11 EST To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com James Migel wrote: > > Hi all, I'm trying to work my way through the DJGPP tutorial on the game > programming megasite http://perplexed.com/GPMega/ and am having trouble > plotting a pixel. I have my code right I think... mode 13 starts and then it > is supposed to plot at x=25 y=25 color=25 but I see nothing... I thought > that maybe my color (25) was black but it doesn't matter what I use I still > get a blank screen. Is it possible that I have to load a color palette > before it knows any colors? code as follows: [snip] I've replied to this already, suggesting that perhaps you use Allegro but on second thoughts, as I was new to djgpp but not to vesa, share this snippet with you.. ------------------- file: vesa.h ------------------- #ifndef VESA__H #define VESA__H typedef struct VESAINFO { unsigned char VESASignature[4] __attribute__ ((packed)); unsigned short VESAVersion __attribute__ ((packed)); unsigned long OEMStringPtr __attribute__ ((packed)); unsigned long Capabilities __attribute__ ((packed)); unsigned long VideoModePtr __attribute__ ((packed)); unsigned short TotalMemory __attribute__ ((packed)); unsigned char Reserved[236] __attribute__ ((packed)); } VESAINFO; typedef struct MODEINFO { unsigned short ModeAttributes __attribute__ ((packed)); unsigned char WinAAttributes __attribute__ ((packed)); unsigned char WinBAttributes __attribute__ ((packed)); unsigned short WinGranularity __attribute__ ((packed)); unsigned short WinSize __attribute__ ((packed)); unsigned short WinASegment __attribute__ ((packed)); unsigned short WinBSegment __attribute__ ((packed)); unsigned long WinFuncPtr __attribute__ ((packed)); unsigned short BytesPerScanLine __attribute__ ((packed)); unsigned short XResolution __attribute__ ((packed)); unsigned short YResolution __attribute__ ((packed)); unsigned char XCharSize __attribute__ ((packed)); unsigned char YCharSize __attribute__ ((packed)); unsigned char NumberOfPlanes __attribute__ ((packed)); unsigned char BitsPerPixel __attribute__ ((packed)); unsigned char NumberOfBanks __attribute__ ((packed)); unsigned char MemoryModel __attribute__ ((packed)); unsigned char BankSize __attribute__ ((packed)); unsigned char NumberOfImagePages __attribute__ ((packed)); unsigned char Reserved_page __attribute__ ((packed)); unsigned char RedMaskSize __attribute__ ((packed)); unsigned char RedMaskPos __attribute__ ((packed)); unsigned char GreenMaskSize __attribute__ ((packed)); unsigned char GreenMaskPos __attribute__ ((packed)); unsigned char BlueMaskSize __attribute__ ((packed)); unsigned char BlueMaskPos __attribute__ ((packed)); unsigned char ReservedMaskSize __attribute__ ((packed)); unsigned char ReservedMaskPos __attribute__ ((packed)); unsigned char DirectColorModeInfo __attribute__ ((packed)); unsigned long PhysBasePtr __attribute__ ((packed)); unsigned long OffScreenMemOffset __attribute__ ((packed)); unsigned short OffScreenMemSize __attribute__ ((packed)); unsigned char Reserved[206] __attribute__ ((packed)); } MODEINFO; /* VESA 1.2 functions */ #define GET_VESA_VGA_INFO 0x4F00 #define GET_VESA_MODE_INFO 0x4F01 #define SET_VESA_MODE 0x4F02 #define GET_VESA_MODE 0x4F03 /* not used 0x4F04 Save/Restore Super VGA state */ /* not used 0x4F05 CPU Video Memory Window Control */ /* not used 0x4F06 Get/Set Logical Scan Line Length */ #define SET_VESA_START 0x4F07 #define SET_VESA_DACS 0x4F08 /* VESA 2.0 functions */ #define GET_VESA_PALETTE 0x4F09 /* Get/Set Palette Data */ #define GET_VESA_PM 0x4F0A /* Return VBE Protected Mode Interface */ #define SET_VESA_LINEAR 0x4000 /* OR with MODE in SET_VESA_MODE */ /* errors */ #define VESA_SUCCESS 0 #define VESA_ERROR -1 #define VESA_SIGNATURE_ERROR -2 #define VESA_VERSION_ERROR -3 #define VESA_MODE_ERROR -4 #define VESA_LINEAR_ERROR -5 #define VESA_MAPPING_ERROR -6 extern unsigned char *video; extern int xres; extern int yres; int SetVesaMode(unsigned short); void ResetMode(void); #endif ------------------ file: vesa.c ---------------------- #include #include #include #include #include "vesa.h" static VESAINFO vesainfo; static MODEINFO modeinfo; static char oldmode; unsigned char *video; int xres; int yres; static int GetVESAINFO(void) { __dpmi_regs r; long dosbuf; int i; /* use the memory transfer buffer */ dosbuf = __tb & 0xFFFFF; /* initialize the buffer to zero */ for (i=0; i>4) & 0xFFFF; __dpmi_int(0x10, &r); if (r.d.eax == -1) return VESA_ERROR; /* copy data into structure */ dosmemget(dosbuf, sizeof(VESAINFO), &vesainfo); if (strncmp(vesainfo.VESASignature, "VESA", 4) != 0) return VESA_SIGNATURE_ERROR; if(vesainfo.VESAVersion < 0x200) return VESA_VERSION_ERROR; return VESA_SUCCESS; } static int GetMODEINFO(unsigned short mode) { __dpmi_regs r; long dosbuf; int i; /* use the memory transfer buffer */ dosbuf = __tb & 0xFFFFF; /* initialize the buffer to zero */ for (i=0; i>4) & 0xFFFF; __dpmi_int(0x10, &r); if (r.d.eax == -1) return VESA_ERROR; /* copy data into structure */ dosmemget(dosbuf, sizeof(MODEINFO), &modeinfo); return VESA_SUCCESS; } static int GetModeInfo(unsigned short mode) { long modeptr; int i, error; __dpmi_meminfo mapping; if((error=GetVESAINFO()) != VESA_SUCCESS) return error; /* convert the mode list pointer from seg:offset to a linear address */ modeptr = ((vesainfo.VideoModePtr & 0xFFFF0000) >> 12) + (vesainfo.VideoModePtr & 0xFFFF); for(i=0; ;i++) { if(_farpeekw(_dos_ds, modeptr) == 0xFFFF) return VESA_MODE_ERROR; if(_farpeekw(_dos_ds, modeptr) == mode) break; modeptr += 2; /* next WORD */ } if((error=GetMODEINFO(mode)) != VESA_SUCCESS) return error; /* check for linear frame buffer capability */ if(!(modeinfo.ModeAttributes & 0x0080)) return VESA_LINEAR_ERROR; /* create direct pointer to video memory */ if (!__djgpp_nearptr_enable()) return VESA_MAPPING_ERROR; /* not really */ /* map into linear memory */ mapping.address = modeinfo.PhysBasePtr; mapping.size = vesainfo.TotalMemory << 16; if (__dpmi_physical_address_mapping(&mapping) != 0) return VESA_MAPPING_ERROR; video = (unsigned char *)(mapping.address + __djgpp_conventional_base); xres = modeinfo.XResolution; yres = modeinfo.YResolution; return VESA_SUCCESS; } int SetVesaMode(unsigned short mode) { __dpmi_regs r; int error; if((error=GetModeInfo(mode)) != VESA_SUCCESS) return error; /* get current video mode */ oldmode = _farpeekb(_dos_ds, 0x449); /* byte at 40:49h */ /* call the VESA function */ r.x.ax = SET_VESA_MODE; r.x.bx = mode | SET_VESA_LINEAR; __dpmi_int(0x10, &r); if (r.d.eax == -1) return VESA_ERROR; return VESA_SUCCESS; } void ResetMode(void) { __dpmi_regs r; if(oldmode != _farpeekb(_dos_ds, 0x449)) { r.h.ah = 0; r.h.al = oldmode; __dpmi_int(0x10, &r); } } ----------------- file: vesa1.c -------------------------- #include #include "vesa.h" int main(void) { int i, j, error; unsigned short mode; /*-------------------------------------------- Test VESA mode 0x105 1024x768, 256 colors for Matrox Mystique 2Mb video card --------------------------------------------*/ mode = 0x105; if((error=SetVesaMode(mode)) != VESA_SUCCESS) return -error; /* clear video memory */ memset(video, 0x3F, xres*yres); /* sort of pink color */ for(i=0,j=0; i