From: Nicolas Blais Newsgroups: comp.os.msdos.djgpp Subject: PRO: Plz check my code for some errors/optimization. (VESA.CPP) Date: Tue, 24 Mar 1998 20:38:55 -0500 Organization: Elemental Technologies Lines: 205 Message-ID: <3518602E.15E3A2C4@netrover.com> NNTP-Posting-Host: 198.168.87.132 Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------CEB05B56DAE19F42DDC63E3C" To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk This is a multi-part message in MIME format. --------------CEB05B56DAE19F42DDC63E3C Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Attached is my VESA sub routine that I use to create most of my programs. Are there anything I don't need or I need? Or anything I can do better? For example, when I want to output text on my screen, I use put_char, ex: for (p = "Hello World!"; *p;p++) put_char(*p, 7); You see, that's 2 lines of code for just 2 words. Can I simplify this? Also, how do I set it to 640x480x16bit? Thanks, Nicolas Blais //----------------------------------------------------------------------------------------- --------------CEB05B56DAE19F42DDC63E3C Content-Type: text/plain; charset=us-ascii; name="Vesa.cpp" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="Vesa.cpp" #include #include #include #include typedef struct VESA_INFO { unsigned char VESASignature[4] __attribute__ ((packed)); unsigned short VESAVersion __attribute__ ((packed)); unsigned long OEMStringPtr __attribute__ ((packed)); unsigned char Capabilities[4] __attribute__ ((packed)); unsigned long VideoModePtr __attribute__ ((packed)); unsigned short TotalMemory __attribute__ ((packed)); unsigned short OemSoftwareRev __attribute__ ((packed)); unsigned long OemVendorNamePtr __attribute__ ((packed)); unsigned long OemProductNamePtr __attribute__ ((packed)); unsigned long OemProductRevPtr __attribute__ ((packed)); unsigned char Reserved[222] __attribute__ ((packed)); unsigned char OemData[256] __attribute__ ((packed)); } VESA_INFO; VESA_INFO vesa_info; int get_vesa_info() { __dpmi_regs r; long dosbuf; int c; dosbuf = __tb & 0xFFFFF; for (c=0; c>4) & 0xFFFF; __dpmi_int(0x10, &r); if (r.h.ah) return -1; dosmemget(dosbuf, sizeof(VESA_INFO), &vesa_info); if (strncmp(vesa_info.VESASignature, "VESA", 4) != 0) return -1; return 0; } typedef struct MODE_INFO { 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)); } MODE_INFO; MODE_INFO mode_info; int get_mode_info(int mode) { __dpmi_regs r; long dosbuf; int c; dosbuf = __tb & 0xFFFFF; for (c=0; c>4) & 0xFFFF; r.x.cx = mode; __dpmi_int(0x10, &r); if (r.h.ah) return -1; dosmemget(dosbuf, sizeof(MODE_INFO), &mode_info); return 0; } int find_vesa_mode(int w, int h) { int mode_list[256]; int number_of_modes; long mode_ptr; int c; if (get_vesa_info() != 0) return 0; mode_ptr = ((vesa_info.VideoModePtr & 0xFFFF0000) >> 12) + (vesa_info.VideoModePtr & 0xFFFF); number_of_modes = 0; while (_farpeekw(_dos_ds, mode_ptr) != 0xFFFF) { mode_list[number_of_modes] = _farpeekw(_dos_ds, mode_ptr); number_of_modes++; mode_ptr += 2; } for (c=0; c