www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/11/25/02:46:48

From: Aleksander Simon Kenton <ask1701 AT dcs DOT qmw DOT ac DOT uk>
Newsgroups: comp.os.msdos.djgpp
Subject: Help VBE2 example source code reboots my machine !!!!!
Date: Sun, 23 Nov 1997 15:37:12 +0000
Organization: Queen Mary And Westfield College, University of London
Lines: 271
Message-ID: <34784DA8.F95@dcs.qmw.ac.uk>
NNTP-Posting-Host: it191.dcs.qmw.ac.uk
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Hi guys,
		I'm trying to compile and run some vbe2 source code I found on the
web, it seems to compile fine but reboots my machine... I don't know if
anyone has tried this source code...or not anyway here it is....
	/*
 * Written by Steve Marton (12/19/96)
 * istvan AT outer-net DOT com - use this for pointing out my mistakes :-)
 *
 * This program is supposed to demonstrate the way to use the linear
frame
 * buffer feature of VBE 2.0. A 24bit putpixel() is also thrown in for
fun.
 */

#include <stdio.h>
#include <stdlib.h>
#include <pc.h>
#include <dpmi.h>
#include <go32.h>
#include <dos.h>
#include <math.h>
#include <sys/nearptr.h>
#include <crt0.h>
int _crt0_startup_flags = _CRT0_FLAG_NEARPTR | _CRT0_FLAG_NONMOVE_SBRK;

#define PACKED __attribute__((packed))
#pragma pack(1) 

typedef struct {
  short   ModeAttributes PACKED;         /* Mode
attributes                  */
  char    WinAAttributes PACKED;         /* Window A
attributes              */
  char    WinBAttributes PACKED;         /* Window B
attributes              */
  short   WinGranularity PACKED;         /* Window granularity in
k          */
  short   WinSize PACKED;                /* Window size in
k                 */
  short   WinASegment PACKED;            /* Window A
segment                 */
  short   WinBSegment PACKED;            /* Window B
segment                 */
  void    *WinFuncPtr PACKED;            /* Pointer to window
function       */
  short   BytesPerScanLine PACKED;       /* Bytes per
scanline               */
  short   XResolution PACKED;            /* Horizontal
resolution            */
  short   YResolution PACKED;            /* Vertical
resolution              */
  char    XCharSize PACKED;              /* Character cell
width             */
  char    YCharSize PACKED;              /* Character cell
height            */
  char    NumberOfPlanes PACKED;         /* Number of memory
planes          */
  char    BitsPerPixel PACKED;           /* Bits per
pixel                   */
  char    NumberOfBanks PACKED;          /* Number of CGA style
banks        */
  char    MemoryModel PACKED;            /* Memory model
type                */
  char    BankSize PACKED;               /* Size of CGA style
banks          */
  char    NumberOfImagePages PACKED;     /* Number of images
pages           */
  char    res1 PACKED;                   /*
Reserved                         */
  char    RedMaskSize PACKED;            /* Size of direct color red
mask    */
  char    RedFieldPosition PACKED;       /* Bit posn of lsb of red
mask      */
  char    GreenMaskSize PACKED;          /* Size of direct color green
mask  */
  char    GreenFieldPosition PACKED;     /* Bit posn of lsb of green
mask    */
  char    BlueMaskSize PACKED;           /* Size of direct color blue
mask   */
  char    BlueFieldPosition PACKED;      /* Bit posn of lsb of blue
mask     */
  char    RsvdMaskSize PACKED;           /* Size of direct color res
mask    */
  char    RsvdFieldPosition PACKED;      /* Bit posn of lsb of res
mask      */
  char    DirectColorModeInfo PACKED;    /* Direct color mode
attributes     */

  /* VESA 2.0 variables */
  long    PhysBasePtr;           /* physical address for flat frame
buffer */
  long    OffScreenMemOffset;            /* pointer to start of off
screen memory */
  short   OffScreenMemSize;      /* amount of off screen memory in 1k
units */
  char    res2[206] PACKED;              /* Pad to 256 byte block
size       */
}VBE_ModeInfo;
#pragma pack(4)

unsigned int addr;               // Address of the linear frame buffer
unsigned char *video_pointer;    // 8 bit pointer to the video memory
unsigned short *vid_point;       // 16 bit pointer
int xres,yres;                   // maximum x and y resolutions
int shorts_per_row=640*3/2+64;   // self explanatory quantities needed
for
int chars_per_row=640*3+128;     // the 24 bit putpixel (note the 128
bytes 
                                 // added to the end of the line - this
is
                                 // required by this video mode)

VBE_ModeInfo *get_mode_info(int mode)
{
   static VBE_ModeInfo modeinfo;
        __dpmi_regs r;

        r.x.ax = 0x4F01;
        r.x.cx = mode;
        r.x.es = __tb / 16;
        r.x.di = 0;
        __dpmi_int(0x10, &r);
        if(r.h.ah) return 0;
   dosmemget(__tb, sizeof(VBE_ModeInfo), &modeinfo);
   return &modeinfo;
}

void init(int mode)
{
   int bpp;
   VBE_ModeInfo *modeinfo;
   __dpmi_meminfo mem;
        __dpmi_regs reg;

   modeinfo=get_mode_info(mode);
   xres=modeinfo->XResolution;
   yres=modeinfo->YResolution;
   bpp=modeinfo->BitsPerPixel/8;
   mem.size=yres*xres*(bpp+1);   // make it a little bigger so that if
you 
                                 // get off the screen it won't cause a
gpf 
   mem.address=modeinfo->PhysBasePtr;
   __dpmi_physical_address_mapping(&mem);
   addr=mem.address;   
   video_pointer = (unsigned char *)(addr + __djgpp_conventional_base);
   vid_point = (unsigned short *)video_pointer;  // set up pointers
pointing
                                                 // to the same place
   printf("Vesa mode %x: %d x %d, %d colors\n", mode, xres, yres,
(int)pow(2,bpp*8)); // colors=2^BitsPerPixel
   getkey();

   reg.x.ax=0x4f02;        // bios modeset function
   reg.x.bx=0x4000+mode;   // vesa mode plus linear frame buffer
identifier
   __dpmi_int(0x10,&reg);
}

/*
Simple putpixel for 8 or 16 bit modes (some 32 bit cards support this
method
if you change the color variable to ulong; it's also faster than the
next one, so try it)
\*
void putpixel(int x, int y, unsigned short c)
   {
      vid_point[y*xres+x]=c;  \* same as *vid_point+y*xres+x = c
   }                          \* note: change to *video_pointer for 8bit
modes

\*
16 bit putpixel with separate control over rgb values
\*
void putpixel(int x, int y, unsigned short r, unsigned short g, unsigned
short b)
   {
      vid_point[y*xres+x]=b+(g<<5)+(r<<10);  \* the shifts are for
placing the
   }                                         \* colors in their right
places
   \* change them depending on the bits per pixel of your video mode
   \* you might have to switch b and r in some modes
*/

/*
24 bit putpixel - 16.7M colors
this one's really wierd because the colors are described by three bytes
the explanation would be too long, but mail me if you really need it
*/
void putpixel(int x, int y, unsigned char red, unsigned char green,
unsigned char blue)
{
   if ((x & 1)==0) {            // it's an even pixel
      vid_point[y*shorts_per_row + (x*3)/2]=blue+(green<<8);
      video_pointer[y*chars_per_row + x*3+2]=red;
   } else {             // it's an odd pixel
      video_pointer[y*chars_per_row + x*3]=blue;
      vid_point[y*shorts_per_row + (x*3+1)/2]=green+(red<<8);
   }
}

/*
Palette setting only works in 8 bit modes
*/
void set_palette(unsigned char entry, unsigned char r, unsigned char g,
unsigned char b)
{
   outportb(0x3c8, entry);
   outportb(0x3c9, r);
   outportb(0x3c9, g);
   outportb(0x3c9, b);
}

/*
normal setmode
*/
void sm(unsigned char mode)
{
   union REGS in;
   union REGS out;
   in.h.ah=0;
   in.h.al=mode;
   int86(0x10, &in, &out);
}

void rect(short x1, short y1, short x2, short y2, unsigned char r,
unsigned char g, unsigned char b);
void line(short x, short y, short x2, short y2, unsigned char r,
unsigned char g, unsigned char b);
void circle(short xc, short yc, float rad, unsigned char r, unsigned
char g, unsigned char b);
void moire(void);

void main(void)
{
   int x, y;
   float t;
   int mode=0x112;  // 640x480x16M

   init(mode);

   for (y=0; y < yres; y++)
     {
     for (x=0; x < xres; x++) putpixel(x, y, y, y/2, x);      
     }
   
   for (t=0; t<10; t++)
   {
      for (x=0; x<640; x++) putpixel(x, 400+t, t*5, x/3, x/6);
      for (y=0; y<480; y++) putpixel(80+t, y, t*5, y/2, y/8);
   }
   
   for (t=0; t<16; t++) rect(t, t, xres-t, yres-t, 0, 0, t*10);

   moire();

   for(t=0; t<50; t+=.005) circle(xres/2, yres/2, t, 255-t*3, 0, 0);
   
   for (t=0; t<50; t++) rect(550-t, 90-t, 550+t, 90+t, t*5, t*5, t*5);
   
   getkey();
   sm(0x3);
}

Not all the source code is included....
	Another related question..can anyone tell me how to use the GRX
graphics library..just show me some simple code to get me up and
started...much appreciated.
Cheers.
	Alek Kenton.

- Raw text -


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