cvs.gedasymbols.org/archives/browse.cgi   search  
Mail Archives: djgpp/1998/03/30/08:00:41

From: Nicolas Blais <eletech AT netrover DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: **HELP!** can someone modify my sub-routine to make it better? (vesa.cpp)
Date: Mon, 30 Mar 1998 07:48:31 -0500
Organization: Elemental Technologies
Lines: 204
Message-ID: <351F949E.D7B85E7F@netrover.com>
NNTP-Posting-Host: 198.168.87.54
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

This is a multi-part message in MIME format.
--------------CF95929C9287BD6F402B6108
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Hi, I don't know how many times I asked this but, please, can you make
my code better?  Especially that put_char() that I got from someone
else, it's effecient, but it's 2 lines of code that I know you can turn
into 1.  Also, make my putpixel() better, I heard it was slow and
awkward.

Feel free to keep it too.
Nicolas Blais

--------------CF95929C9287BD6F402B6108
Content-Type: text/plain; charset=us-ascii; name="Vesa.cpp"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="Vesa.cpp"

#include <dpmi.h>
#include <go32.h>
#include <sys/farptr.h>
#include <iostream.h>
#include <string.h>

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<sizeof(VESA_INFO); c++)
_farpokeb(_dos_ds, dosbuf+c, 0);
dosmemput("VBE2", 4, dosbuf);
r.x.ax = 0x4F00;
r.x.di = dosbuf & 0xF;
r.x.es = (dosbuf>>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<sizeof(MODE_INFO); c++)
_farpokeb(_dos_ds, dosbuf+c, 0);
r.x.ax = 0x4F01;
r.x.di = dosbuf & 0xF;
r.x.es = (dosbuf>>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 depth, int mm)
{
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<number_of_modes; c++) {
if (get_mode_info(mode_list[c]) != 0) continue;
if ((mode_info.ModeAttributes & 0x19) != 0x19) continue;
if ((mode_info.XResolution != w) || (mode_info.YResolution != h)) continue;
if (mode_info.NumberOfPlanes != 1) continue;
if (mode_info.MemoryModel != mm) continue;
if (mode_info.BitsPerPixel != depth) continue;
return mode_list[c];
}
return 0;
}

int set_vesa_mode(int w, int h, int depth, int mm)
{
 __dpmi_regs r;
 int mode_number;
 mode_number = find_vesa_mode(w, h, depth, mm);
 if (!mode_number)
 return -1;
 r.x.ax = 0x4F02;
 r.x.bx = mode_number;
 __dpmi_int(0x10, &r);
 if (r.h.ah) return -1;
 return 0;
}

void set_vesa_bank(int bank_number)
{
 __dpmi_regs r;
 r.x.ax = 0x4F05;
 r.x.bx = 0;
 r.x.dx = bank_number;
 __dpmi_int(0x10, &r);
}

void putpixel(int x, int y, int color)
{
 int address = y*640+x;
 int bank_size = mode_info.WinGranularity*1024;
 int bank_number = address/bank_size;
 int bank_offset = address%bank_size;
 set_vesa_bank(bank_number);
_farpokeb(_dos_ds, 0xA0000+bank_offset, color);
}

void set_mode(int m)
{
  __dpmi_regs r;
  r.h.ah = 0;
  r.h.al = m;
  __dpmi_int(0x10, &r);
}

void put_char(int ch, int color)
{
  __dpmi_regs r;
  r.h.ah = 0x0e;
  r.h.al = ch;
  r.h.bh = 0;
  r.h.bl = color;
  __dpmi_int(0x10, &r);
}

--------------CF95929C9287BD6F402B6108--

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019