TIP: Click on subject to list as thread! ANSI
echo: os2prog
to: Doug Shields
from: Patrick Haller
date: 1995-10-28 16:53:59
subject: VioGetPhysBuf

Hi Doug!

[..]
 DS> I have been doing some full screen graphics programming lately and can
 DS> not seem to get VioGetPhysBuf to work.  
Here we go:

#include 
#include 
#include 

#define INCL_BASE
#include 

#define SEG16 _far16       /* Borland C and C/Set are different here ! */

#define SCN_W 320
#define SCN_H 200
static VIOMODEINFO vmiOld;
static unsigned char *VGARAMptr;
static int scn_w, scn_h;
static unsigned char palette[0x100][3];
static int npalette;
static int data_depth;

static void setpalette(BYTE *palette, int first, int num)
{
  VIOCOLORREG viocreg;

  viocreg.cb = sizeof(VIOCOLORREG);
  viocreg.type = 3; /* Apparently no #define for this */
  viocreg.firstcolorreg = first;
  viocreg.numcolorregs = num;

  /* Note: viocreg.colorregaddr should be of type CHAR *_Seg16
     But it isn't! Hence if I say viocreg.colorregaddr = buf,
     then the correct thunking will not be applied! */
  memcpy(&viocreg.colorregaddr, palette, 4);

  VioSetState(&viocreg, (HVIO) 0);
}

static void scn_init(void)
{
  VIOMODEINFO vmi;
  VIOPHYSBUF phys;
  VIOOVERSCAN vioos;
  unsigned char SEG16 * ptr1616;
  unsigned char status;

  vmi.cb     = 12;
  vmi.fbType = 3;
  vmi.color  = 8;
  vmi.col    = 40;
  vmi.row    = 25;
  vmi.hres   = SCN_W;
  vmi.vres   = SCN_H;

  VioGetMode(&vmiOld, (HVIO) 0);
  if ( VioSetMode(&vmi, (HVIO) 0) )
  {
          fprintf(stderr, "Unable to enter 320x200 at 8pp graphics
mode\n");
          exit(1);
  }

  phys.cb = 0x10000;
  phys.pBuf = (unsigned char *) 0xa0000;
  if ( VioGetPhysBuf(&phys, 0) )
  {
          fprintf(stderr, "Unable to access to physical graphics
screen\n");
          exit(1);
  }

  ptr1616 = (unsigned char SEG16 *) ( phys.asel[0] << 16 );
  VGARAMptr = (unsigned char *) ptr1616;
  VioScrLock(VP_WAIT, &status, (HVIO) 0);

  /* Set all palette entrys to black */
  //memset(palette, 0, sizeof(palette));

  /* Ensure dish them out from 0 onwards */
  npalette = 0;

  //setpalette((BYTE *) palette, 0, 0x100);

  /* Set screen to colour 255, which will get set to black */
  memset(VGARAMptr, 255, SCN_W*SCN_H);

  /* Set border colour to colour 255 */
  vioos.cb = sizeof(VIOOVERSCAN);
  vioos.type = 1; /* Apparently no #define for this */
  vioos.color = 255;
  VioSetState(&vioos, (HVIO) 0);
}

static void scn_term(void)
{
  VioScrUnLock((HVIO) 0);
  VioSetMode(&vmiOld, (HVIO) 0);
}


void draw ()
{
  USHORT x,y,z;
  ULONG *p;
  register ULONG i;


  i = 0;
  for (z=0;z<10000;z++)
  {
    p = (ULONG *)VGARAMptr;
    i++;

    for (x=0;x<64000;x+=4,p++)
        *p = i;
  }
}

void main (void)
{
  printf ("\nOK, program starts.");

  scn_init ();

  draw ();

  scn_term ();

  printf ("\nEnd.");
}


If you encounter a problem in settings user palettes, then you ran into a
bug in BSESUB.H:

 typedef struct _VIOCOLORREG    /* viocreg */
 {
    USHORT  cb;
    USHORT  type;
    USHORT  firstcolorreg;
    USHORT  numcolorregs;
/*    PCH     colorregaddr; */
    PUCHAR16  colorregaddr;       /* Thunking must explicitly be applied */
 } VIOCOLORREG;
 typedef VIOCOLORREG *PVIOCOLORREG;
     __
     |_)
cu/2 |atrick
[Team  OS/2]

---
* Origin: OS/2 Bodensee ! (2:246/2315.18)
SEEN-BY: 270/101 620/243 711/401 409 410 413 430 807 808 809 934 955 712/407
SEEN-BY: 712/515 628 704 713/888 800/1 7877/2809
@PATH: 246/2315 2300 2340 24/901 240/5500 24/24 396/1 270/101 712/515
@PATH: 711/808 809 934

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.