delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/03/09/17:34:49

From: Niklas <d95-nlu AT nada DOT kth DOT se>
Newsgroups: comp.os.msdos.djgpp,comp.graphics.algorithms
Subject: VESA 2.0 and NEAR PTR
Date: Sun, 09 Mar 1997 22:30:15 +0100
Organization: Solace Computer Society
Lines: 202
Message-ID: <33232BE7.2F3D@nada.kth.se>
Reply-To: d95-nlu AT nada DOT kth DOT se
NNTP-Posting-Host: sl52.modempool.kth.se
Mime-Version: 1.0
CC: pweeks AT execulink DOT com, d95-nlu AT nada DOT kth DOT se
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

The following program doesn't work, and so doesn't the wide-spread
vbetest.zip. but vbetest.zip used to work for me, but not any longer.
is there some update problem? I use djgpp2, sdd53 and win95.
I copied pweeks AT execulink DOT com code and put the following together.
please reply to newsgroup and mail...
d95-nlu AT nada DOT kth DOT se

#include <stdio.h>
#include <assert.h>
#include <string.h>
#include <iostream.h>
#include <dpmi.h>
#include <go32.h>                       // for the declaration of
_dos_ds
#include <sys/nearptr.h>

#define PACKED __attribute__ ((packed))

#pragma pack(1)
                                        // SuperVGA information block
typedef struct {
  char    VESASignature[4] PACKED;      // 'VESA' 4 byte signature
  short   VESAVersion PACKED;           // VBE version number
  char    *OEMStringPtr PACKED;         // Pointer to OEM string
  long    Capabilities PACKED;          // Capabilities of video card
  short   *VideoModePtr PACKED;         // Pointer to supported modes
  short   TotalMemory PACKED;           // Number of 64kb memory blocks
  char    reserved[236] PACKED;         // Pad to 256 byte block size
} VBE_VgaInfo;

                                         // SuperVGA mode information
block
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()


int VBE_detect(VBE_VgaInfo *vbeinfo) {
  __dpmi_regs regs;
  
  assert(sizeof(*vbeinfo) < _go32_info_block.size_of_transfer_buffer);
  regs.x.ax = 0x4F00;
  regs.x.di = __tb & 0x0F;
  regs.x.es = (__tb >> 4) & 0xFFFF;
  dosmemput(vbeinfo,sizeof(*vbeinfo),__tb);
  __dpmi_int(0x10, &regs);
  dosmemget(__tb, sizeof(*vbeinfo), vbeinfo);
  if(strncmp(vbeinfo->VESASignature,"VESA",4) != 0) return 0;
  else return vbeinfo->VESAVersion;
}





void VBE_getmodeinfo(unsigned short mode, VBE_ModeInfo *modeinfo) {
  __dpmi_regs regs;
  
  assert(sizeof(*modeinfo) < _go32_info_block.size_of_transfer_buffer);
  regs.x.ax = 0x4F01;
  regs.x.cx = mode;
  regs.x.di = __tb & 0x0F;
  regs.x.es = (__tb >> 4) & 0xFFFF;
  __dpmi_int(0x10, &regs);
  dosmemget(__tb, sizeof(*modeinfo), modeinfo);
  return;
}


/*
#define SUPPORTED 1
#define NOT_SUPPORTED	0

int check_640x480x256(void) {
  __dpmi_regs regs;
  regs.x.ax = 0x4F02;
  regs.x.bx = 0x4101;
  __dpmi_int(0x10, &regs);
  if(regs.x.ax == 0x4F) return SUPPORTED;
  else return NOT_SUPPORTED;
}
*/


unsigned int linear_address;

void VBE_get_linear_address(int mode) {
  VBE_ModeInfo modeinfo;
  __dpmi_meminfo mem;
  
  VBE_getmodeinfo(mode, &modeinfo);
  mem.size = (unsigned long)(modeinfo.XResolution * modeinfo.YResolution
* modeinfo.BitsPerPixel/8);
  mem.address = modeinfo.PhysBasePtr;
  __dpmi_physical_address_mapping(&mem);
  linear_address = mem.address;
  return;
}


VBE_ModeInfo modeinfo;


void VBE_setmode(int mode) {
  __dpmi_regs regs;
  regs.x.ax = 0x4f02;
  regs.x.bx = mode | 0x8000;
  __dpmi_int(0x10, &regs);
  return;
}

void settext() {
  __dpmi_regs regs;
  regs.x.ax = 3;
  __dpmi_int(0x10, &regs);
  return;
}


int main(void) {
  /*if(VBE_detect(&vbeinfo) < 0x200) {
    printf("Your card does not support VESA 2.0\n");
    exit(1);
  }*/

  int mode = 0x4101;

  VBE_getmodeinfo(mode, &modeinfo);
  if(modeinfo.ModeAttributes & 0x8)
    printf("Linear frame buffer found\n");
  else {
    printf("Linear frame buffer not found\n");
    exit(1);
  }

  VBE_get_linear_address(mode);
  char* video = (char*)linear_address;
  VBE_setmode(mode);                                    // 640x480x256

  getch();

  __djgpp_nearptr_enable();
  video += __djgpp_conventional_base;
  for(int i=0;i<640*480;i++)
    video[ i ] = (unsigned char)(i&255);
  __djgpp_nearptr_disable();

  getch();
  settext();
  cout << modeinfo.PhysBasePtr << endl;
  cout << int(video) << endl;
  return 0;
}

------------------------------
please reply to newsgroup and mail...
d95-nlu AT nada DOT kth DOT se
------------------------------

- Raw text -


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