www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/03/28/21:02:13

From: Nicolas Blais <eletech AT netrover DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: HELP!!: Can anyone optimize my code here? (vesa.cpp)
Date: Sat, 28 Mar 1998 20:51:31 -0500
Organization: Elemental Technologies
Lines: 225
Message-ID: <351DA923.7E2A8732@netrover.com>
NNTP-Posting-Host: 198.168.87.18
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.
--------------522A660E1EEFE22AFAF23509
Content-Type: multipart/alternative; boundary="------------B9D95652519785CB5F740CEC"


--------------B9D95652519785CB5F740CEC
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

I need a pro who can optimize my code and send it back to me.  This is a
kind of a VESA sub-routine.  My main problem with it is that to show
text on the screen, I have to use 2 lines of codes for just one line of
text.  (Put_char)
Also, how do I set the VESA mode to 640x480x16k?

Thanks, Nicolas Blais



--------------B9D95652519785CB5F740CEC
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<HTML>
<B>I need a pro who can optimize my code</B> and <B>send it back to me</B>.&nbsp;
This is a kind of a VESA sub-routine.&nbsp; My main problem with it is
that to show text on the screen, I have to use 2 lines of codes for just
one line of text.&nbsp; (Put_char)
<BR>Also, how do I set the VESA mode to 640x480x16k?

<P>Thanks, Nicolas Blais
<BR>&nbsp;
<BR>&nbsp;</HTML>

--------------B9D95652519785CB5F740CEC--

--------------522A660E1EEFE22AFAF23509
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>

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 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 != 4) continue;
if (mode_info.BitsPerPixel != 8) continue;
return mode_list[c];
}
return 0;
}

int set_vesa_mode(int w, int h)
{
 __dpmi_regs r;
 int mode_number;
 mode_number = find_vesa_mode(w, h);
 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_vesa_640x480(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);
}

--------------522A660E1EEFE22AFAF23509--

- Raw text -


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