From piziali!andy@sulaco.cox.smu.edu  Sun Dec 19 17:12:20 1993
Return-Path: <piziali!andy@sulaco.cox.smu.edu>
Received: from tidmmpl.csc.ti.com by sun_97d1 (4.1/SMI-4.1)
	id AA06337; Sun, 19 Dec 93 17:12:20 CST
Received: by tidmmpl.csc.ti.com ( 5.52 (84)/5.17)
	id AA13956; Sun, 19 Dec 93 17:08:29 CST
Received: from ti.com by tilde.csc.ti.com id AA05775; Sun, 19 Dec 1993 17:10:03 -0600
Received: from sulaco.dia.com (sulaco.cox.smu.edu) by ti.com with SMTP 
	(5.65c/LAI-3.2) id AA13186; Sun, 19 Dec 1993 17:11:22 -0600
Received: from piziali by sulaco.dia.com with uucp
	(Smail3.1.28.1 #1) id m0pBXFh-0001HcC; Sun, 19 Dec 93 17:09 CST
Received: by piziali.lonestar.org (Smail3.1.28.1 #6)
	id m0pBVQP-0005MYC; Sun, 19 Dec 93 15:12 CST
Message-Id: <m0pBVQP-0005MYC@piziali.lonestar.org>
From: andy@piziali.lonestar.org (Andrew J. Piziali)
Subject: /dos/transfer/p9000ch5.txt
To: andy@tidmmpl.csc.ti.com (Andrew J. Piziali)
Date: Sun, 19 Dec 1993 15:12:22 -0600 (CST)
X-Mailer: ELM [version 2.4 PL21]
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Content-Length: 33422     
Status: RO

POWER 9000
USER INTERFACE
CONTROLLER

October 1992

Chapter 5. Sample Programs

5.1. Routines Used throughout the Sample Programs

This section presents an initialization routine (igc_init_sysconfig) that illustrates the initialization required when writing
any Power 9000 application. This section also presents a demo initialization routine (demo_init) and a color setup routine
(color_init). The sample programs in this chapter call all three of these routines.

5.1.1. INITIALIZATION ROUTINE

igc_init_sysconfig (igc_p)
ulong *igc~;
{
      int sysconf;

    bit_count;
int sysconf_shift_count;
int shift_param;

sysconf = Os

/* calculate shift array */
if ( (dim.w & IGM_VALID_SCREENW.MASK) != O)
    printf  ('FATAL ERROR on screen x dirnension\n');
sysconf_shift_count = O;
for (bit_count = 5; bit_count <= 11; bit_count++)
{
  if  (  (dim.w &  (l<<bit_count))  != O)
  {
       /* found a bit in dimension, need to set a bit in sysconfig */
       shift_param = bit_count - 4;
       switch (sysconf_shift_coun~)
       {
           case O:
                 sysconf += Shift_param<<IGM_SYSCONFIG_SHIFTO_SHIFT;
                 break;
           case 1:
                 sysconf += shift_param<<IGM_SYSCONFIG_SHIFTi_SHIFT;
                 break;
           case 2:
                 sysconf += shift_param<<IGM_SYSCONFIG_SHIFT2_SHIFT;
                 break;
           default:
                 printf ('FATAL ERROR on screen x dimension\n");
       }
       sysconf_shift_count++;
  }
}

99


5.1. Routines Used throughout the Sample Programs, continued

/* get swap bits */
if ( (ENDIAN_MACHINE & IGM B SWAP} != O)
          sysconf += IGM_SYSCONFIG_PIX_SWAP_HALF;
if ( (ENDIAN_MACHINE & IGM H SWAP) != O)
          sysconf += IGM_SYSCONFIG_PIX_SWAP_BYTE;
IGC_WRITE_REG (igc_p, IGM_SYSCONFIG, sysconf);

5.1.2. DEMO INITIALIZATION ROUTINE

demo_init(igc, ramdac, clip_min, clip_max)
ulong  **igc,  **ramdac;
struct point_2d *clip_min, *clip_max;
{
  int dev_id;
  int packed_xy;

~ifdef PREDICTOR
    dev_id = O;
#else/* actual chip */
#define IGCNAME "/dev/dfourO~
    dev_id = igc_open(IGCNAME);
~endif PREDICTOR

*igc = igc_connect_regs(dev_id);
*ramdac = igc_connect_ramdac(dev_id);

igc_init_sysconfig (*igc);

packed_xy = IGM_PACK(clip_min->x, clip_min->y);
IGC_WRITE_REG (igc_p, IGM_W_MIN_XY, packed_xy);

  packed_xy = IGM_PACK(clip_max->x,  clip_max->y);
  IGC_WRITE_REG (igc_/o,  IGM_W_MAX_XY, packed_xy);
}

5.1.3. COLOR INITIALIZATION ROUTINE

color_init()
{
  int count, i,  index;
  unsigned char red[256], grn[256], blu[256];

for (i=O;  i<256;  i++)
{
   switch (i%4)
   {
      case O:
         /* green */
         red[i]  = blu[i]  = O;
         grn[i] = 255;
         break;

100


POWER 9000
USER INTERFACE
CONTROLLER

October 1992

5.1. Routines Used throughout the Sample Programs, continued

      case 1:
          /* yellowish */
          red[i] = 240;
          grn[i] = 255;
          blu[i]  = O;
            break;
      case 2:
          /*  red  */
          blu[i]  = grn[i]  = O;
          red[i] = 255;
            break;
      case 3:
          / *  blue  * /
          grn[i] = red[i] = O;
          blu[i] = 255;
          break;
   }
}
/* Pseudo index 0 is white */
red[O] = grn[O] = blu[O] = 255;
/* Pseudo index 255 is black */
red[255]  = grn[255]  = blu[255]  = O;

/* Write the color map */
igc_put_colormap (ramdac_p, O, 256, red, grn, blu);

  /* Set up the foreground and background colors */
  IGC_WRITE_REG (igc_io,  IGM_FGROUND,  RED);
  IGC_WRITE_REG (igc_p, IGM_BGROUND, BLU);
}

10I


5.2. Drawing Quadrilaterals

The following sample program, comprised of C and Q-code, produces the examples in section 4.2.
This program:

1.  Draws a series of points in a rectangular area.
2.  Draws a line.
3.  Draws a second and third line to complete a polyline draw.
4.  Draws a triangle.
5.  Draws two meshed triangles.
6.  Draws a quadrilateral in the shape of an hourglass.

EXAMPLE

#include <stdio.h>
/* toolkit include files */
 include ' igc_gtk. h '
 include ~ igc_macros. h~
 include ~ igc_pr. h~

#define IGC F MASK OxffOO
#define IGC_B_MASK OxfOfO
#define IGC_S_MASK Oxcccc
#define IGC_D_MASK Oxaaaa

#define SCREEN_WIDTH 1152
#define SCREEN_HEIGHT 900

#define OVER_SIZED OxlOOOO

ulong
ulong *ramdac_p;
struct size_2d dim = {1152

    /* Can also use IGM_RASTER_OVERSIZE_MODE */
,900};

main()

int i, minterms, op, packed_xy, raster,
int x, y;
extern ulong ,igc_connect_regs();
extern ulon~ *i~c_connect_ramdac();
struct point_2d clip_min, clip_max;

status;

/, Initialize this demo. */
clip_min.x = clip_min.y = O;
clip_max.x = SCREEN_WIDTH-I;
clip_max.y = SCREEN_HEIGHT-i;
demo_init(&igc_p, &ramdac_p, &clip_min, &clip_max);

102


POWER 9000
USER INTERFACE
CONTROLLER

October 1992

5.2. Drawing Quadrilaterals, continued

/* Initialize the RAMDACs,  foreground and background colors */
color_init ( );

~define GRN 4
~define YEL 5
#define RED 2
#define BLU 3

/* Do a rectangular area of points */
do_points(igc_p, 10, 10, 80, 90, 2);

/*  Line  */
packed_xy = IGM_PACK(10, 120);
IGC_WRITE_2D_META_COORD (igc_.p, IGM_ABS, IGM_XY,
packed_xy = IGM_PACK(100, 120);
IGC_WRITE_2D_META_COORD  (igc_p,   IGM_ABS,  IGM_XY,
do status = IGC_DRAW_QUAD(igc_iD);
while(status & IGM_STATUS_QB_BUSY_MASK);

IGM_LINE, packed_xy);

IGM_LINE, packed_xy);

/* Polyline */
packed_xy = IGM_PACK(200, 20};
IGC_WRITE. 2D .META_COORD (igc_p, IGM_ABS,
do status = IGC_DRAW_QUAD(igc_p);
while (status & IGM_STATUS_QB_BUSY_MASK);
packed_xy = IGM_PACK(200, 100);
IGC_WRITE_2D_META_COORD (igc_p, IGM_ABS,
do status = IGC_DRAW_QUAD(igc_p);
while (status & IGM_STATUS_QB_BUSY_MASK);

IGM_XY. IGM_LINE, packed_xy);

IGM_XY, IGM_LINE, packed_xy);

/* Triangle */
packed_xy = IGM_PACK(270, 20);
IGC_WRITE_2D_META_COORD (igc_p, IGM_ABS, IGM_XY, IGM_TRI
packed_xy = IGM_PACK(340, 40);
IGC_WRITE 2D META_COORD (igc_p, IGM_ABS, IGM_XY, IGM_TRI
packed_xy = IGM_PACK(355,  100);
IGC_WRITE 2D META_COORD (igc_p, IGM_ABS, IGM_XY, IGM_TRI
do status = IGC_DRAW_QUAD(igc_p);
while(status & IGM_STATUS_QB_BUSY_MASK);

packed_xy;
packed_xy);
packed_xy);

/* Meshed Triangles */
packed_xy = IGM_PACK (90,220);
IGC_WRITE  2D  META_COORD  (igc_p,   IGM_ABS,   IGM_XY,
packed_xy = IGM_PACK(223,  184);
IGC_WRITE. 2D META_COORD (igc_p, IGM_ABS, IGM_XY,
packed_xy = IGM_PACK(248,  348);
IGC_WRITE. 2D META_COORD (igc_p, IGM_ABS, IGM_XY,
do status = IGC_DRAW_QUAD(igc_p);
while(status & IGM_STATUS_QB_BUSY_MASK);
packed_xy = IGM_PACK(378, 307);

IGM_TRI  packed_xy);
IGM_TRI, packed_xy);
IGM_TRI, packed_xy);

IGC_WRITE. 2D.META_COORD (igc_p,  IGM_ABS,  IGM_XY,  IGM_TRI, packed_xy);

do status = IGC_D}~W_QUAD(igc__o);
while (status & IGM_STATUS_QB_BUSY_MASK);

103


5.2. Drawing Quadrilaterals, continued

/*  Quad  */
packed_xy = IGM_PACK(400, 130);
IGC_WRITE_2D_META_COORD (igc_p, IGM_ABS,  IGM_XY, IGM_QUAD, packed_xy);
packed_xy = IGM_PACK(470, 130);
IGC_WRITE_2D_META_COORD (igc_p, IGM_ABS, IGM_XY, IGM_QUAD, packed_xy);
packed_xy = IGM_PACK(400, 240);
IGC_WRITE_2D_META_COORD (igc_p,  IGM_ABS,  IGM_XY,  IGM_QUAD, packed_xy);
packed_xy = IGM_PACK(470, 240);
IGC_WRITE 2D .META_COORD (i~c_io,  IGM_ABS,  IGM_XY,  IGM_QUAD, packed_xy);
do status = IGC_DRAW_QUAD(igc_p);
while(status & IGM_STATUS_QB_BUSY_M~SK);

do_points(igc_~o, upper_left_x, upper_left_y, width, height, increment)
ulong *igc_p;
int upper_left_x, upper_left_y, width, height, increment;

  int packed_xy, raster, status, x, y;

do status = IGC_READ_REG ( igc_p, IGM_STATUS);
while(status & IGM_STATUS_BUSY_MASK);

raster = IGC_READ_REG(igc__p,  IGM_~STER);
raster =  (raster & Ox30000)  1  IGC F MASK ~ OVER_SIZED;
IGC_WRITE_REG ( igc_p,  IGM_F~STER,  raster);
IGC_WRITE_REG (igc_p,  IGM_PLANE_MASK,  Oxff);

  /* Points */
  for(y=upper_left_y; y<height; y += increment)
  for(x=upper_left_x; x<width;  x += incremen~)
  {
      packed_xy = IGM_PACK(x, y);
      IGC_WRITE 2D META_COORD (igc~,  IGM_ABS,  IGM_XY,  IGM_POINT, packed_xy);
      do status = IGC_D~W_QUAD(igc__p);
      while(status & IGM_STATUS_QB_BUSY_MASK);

}

104


POWER 9000
USER INTERFACE
CONTROLLER

                                             October 1992
5.3. Defining and Applying a Clipping Window

The following sample program, comprised of C and Q-code, produces the example in section 4.3.
This program.'

1.  Draws a quadrilateral in the shape of an hourglass.
2.  Defines a clipping window.
3.  Draws a quadrilateral exactly like the first quadrilateral, but inside the clipping window so that all
    four edges are clipped.

EXAMPLE

#include <stdio.h>
/* toolkit include files */
#include 'igc_gtk.h~
#include ~igc_macros.h~
#include ~igc_pr.h~

#define IGC_F_MASK OxffOO
#define IGC_B_MASK OxfOfO
#define IGC_S_MASK Oxcccc
#define IGC_D_MASK Oxaaaa

#define SCREEN_WIDTH 1152
#define SCREEN_HEIGHT 900

#define OVER_SIZED OxlOOOO      /* Can also use IGM_RASTER_OVERSIZE_MODE */
ulong *igc_p;
ulong *ramdac_.p;
struct size_2d dim = {1152,900};

main()

int i, minterms, op, packed_xy, raster, status;
int x, y;
extern ulong *igc_connect_regs();
extern ulong *igc_connect_ramdac();
struct point_2d clip_min, clip_max;

/* Initialize this demo. */
clip_min.x = clip_min.y = O;
clip_max.x = SCREEN_WIDTH-I;
clip_max.y = SCREEN_HEIGHT-I;
demo_init(&igc__D, &ramdace, &clip_min, &clip_max);

105


5.3. Defining and Applying a Clipping Window, continued

int packed_xy, raster, status, x, y;

raster = IGC_READ_REG(igc_iD,  IGM_RASTER);
raster =  (raster & Ox30000)  ~  IGC_F_MASK 1 OVER_SIZED;

do status = IGC_READ_REG(igc_p, IGM_STATUS);
while(status & IGM_STATUS_BUSY_MASK);

  IGC_WRITE_REG ( igc_p,  IGM_RASTER,  raster );
  IGC_WRITE_REG (igc~, IGM_PLANE_MASK, Oxff);
}

/* Initialize the RAMDACs,  foreground and background colors */
color_init ();

#define GRN 4
#define YEL 5
#define RED 2
#define BLU 3

/*  Quad  */
packed_xy = IGM_PACK(50, 100);
IGC_WRITE_2D_META_COORD (igc_p, IGM_ABS,
packed_xy = IGM_PACK(150,  100);
IGC_WRITE. 2D.META_COORD (igc_p, IGM_ABS,
packed_xy = IGM_PACK(50, 220);
IGC_WRITE. 2D.META_COORD  (igc~,  IGM_ABS,
packed_xy = IGM_PACK(150, 220);
IGC_WRITE. 2D.META_COORD (igc~,  IGM_ABS,
do status = IGC_DRAW_QUAD(igc_p);
while(status & IGM_STATUS_QB_BUSY_MASK);

IGM_XY, IGM_QUAD, packed_xy;

IGM_XY, IGM_QUAD, packed_xy);

IGM_XY, IGM_QUAD, packed_xy)

IGM_XY, IGM_QUAD, packed_xy);

/* Clipped Quad */
/* Establish clipping area */
    /* Can also use IGM_CLIP_WINDOW */
packed_xy = IGM_PACK(230,  180);

do status = IGC_READ_REG(igc_p, IGM_STATUS);
while(status & IGM_STATUS_BUSY_MASK);

IGC_WRITE_REG (igc_p,  IGM W MIN_XY, packed_xy);

packed_xy = IGM_PACK(270, 240);
IGC_WRITE_REG (igc_p,  IGM W MAX_XY, packed_xy);

106


POWER 9000
USER INTERFACE
CONTROLLER

October 1992

5.3. Defining and Applying a Clipping Window, continued

    /* Draw clipped quad */
packed_xy = IGM_PACK(200,  150);
IGC_WRITE_2D_META_COORD (igc_p,  IGM_ABS,  IGM_XY,
packed_xy  =  IGM_PACK(300,  150);
IGC_WRITE_2D_META_COORD  (igc_p,  IGM_ABS,  IGM_XY,
packed_xy = IGM_PACK(200, 270);
IGC_WRITE_2D_META_COORD  (igc~,   IGM_ABS,  IGM_XY,
packed_xy = IGM_PACK(300, 270);
IGC_WRITE_2D_META_COORD  (igc_p,  IGM_ABS,  IGM_XY,
do status = IGC_DRAW_QUAD(igc__p);
while(status & IGM_STATUS_QB_BUSY_MASK);

IGM_QUAD, packed_xy);
IGM_QUAD, packed_xy);
IGM_QUAD, packed_xy);
IGM_QUAD, packed_xy);

/* Return clip area to whole screen */
    /* Can also use IGM_CLIP_WINDOW */
packed_xy = (0,0);

do status = IGC_READ_REG(igc_p, IGM_STATUS);
while(status & IGM_STATUS_BUSY_MASK);

  IGC_WRITE_REG (igc_p,  IGM_W_MIN_XY, packed_xy);
  packed_xy = IGM_PACK(1151,899);
  IGC_WRITE_REG (igc_~o,  IGM W .MAX_XY, packed_xy);

}

5.4. Performing BitBit Operations

The following sample program, comprised of C and Q-code, produces the example in section 4.4.

This program draws a quadrilateral and then performs a blit of the rectangular area containing the quadrilateral
to another screen location.

EXAMPLE

#include <stdio.h>
/* toolkit include files */
#include ~igc_gtk.h~
#include ~igc_macros.h~
#include ~igc_pr.h~

#define IGC_F_MASK OxffOO
#define IGC B MASK OxfOfO
#define IGC_S_MASK Oxcccc
#define IGC D MASK Oxaaaa

#define SCREEN_WIDTH 1152
#define SCREEN_HEIGHT 900

#define OVER_SIZED OxlOOOO      /* Can also use IGM_RASTER_OVERSIZE_MODE ,/

107


5.4. Performing BitBit Operations, continued

ulong *igc~;
ulong *ramdac_p;
struct size_2d dim = {1152,900};

main()
{
  int i, rainterms, op, packed_xy, raster,
  int x, y;
  extern ulong *igc_connect_regs(};
  extern ulong *igc_connect_ramdac();
  struct point_2d clip_min, clip_max;

status;

/* Initialize this demo. */
clip_min.x = clip_min.y = O;
clip_max.x = SCREEN_WIDTH-l;
clip_max.y = SCREEN_HEIGHT-l;
demo_init(&igc_lo,  &ramdace,

&clip_min, &clip_max);

do status = IGC_READ_REG(igc_p, IGM_STATUS);
while(status & IGM_STATUS_BUSY_MASK);

minterms = IGC F MASK;

raster = IGC_READ_REG(igc_p,  IGM_RASTER);
raster = (raster & Ox30000}  ~ minterms ~ OVER_SIZED;

IGC_WRITE_REG ( igc__p,  IGM_RASTER,  raster);
IGC_WRITE_REG (igc_p, IGM_PLANE_MASK, Oxff);

/* Initialize the RAMDACs, foreground and background colors */
color_init ();

#define GRN 4
#define YEL 5
#define RED 2
#define BLU 3

/* Draw a quad */
    IGC_WRITE 2D META_COORD
    IGC_WRITE 2D .META_COORD
    IGC_WRITE_2D_META_COORD
    IGC_WRITE 2D .META_COORD
    IGC_WRITE 2D .META_COORD
    IGC_WRITE 2D .META_COORD
    IGC_WRITE 2D .META_COORD
    IGC_WRITE 2D .META_COORD

zgc_p, IGM_ABS, IGM_X, IGM_QUAD, 150);
igc_p, IGM_ABS, IGM_Y, IGM_QUAD, 80)
igc~,  IGM_ABS,  IGM_X,  IGM_QUAD,  200;

igc_p, IGM_ABS, IGM_Y, IGM_QUAD, 100;

igC~,  IGM_ABS,   IGM_X,   IGM_QUAD,   180   ;

Igc_p, IGM_ABS,  IGM_Y~  IGM_QUAD,  140  ;
igc~,  IGM_ABS,   IGM_X,   IGM_QUAD,   130

igc_p, IGM_ABS,  IGM_Y,  IGM_QUAD,  120;

do status = IGC_DPjkW_QUAD (igc~);
while (status & IGM_STATUS_QB_BUSY_MASK);

108


POWER 9000
USER INTERFACE
CONTROLLER

October 1992

5.4. Performing BitBlt Operations, continued

/* Blit the area around the quad */
       minterms = IGC_S_MASK;

raster = IGC_READ_REG(igc__p,  IGM_RASTER);
raster = (raster & Ox30000)  i minterms I OVER_SIZED;

     do status = IGC_READ_REG(igc_p,IGM_STATUS);
     while(status & IGM_STATUS_BUSY_MASK);
     IGC_WRITE_REG(igc_p, IGM_RASTER, raster);
     IGC_WRITE 2D .COORD_REG (igc__p, IGM_ABS, IGM_X, O, 130);
     IGC_WRITE_2D_COORD_REG (igc_p,  IGM_ABS, IGM_Y, O, 80);
     IGC_WRITE 2D COORD_REG  (igc_p,  IGM_ABS,  IGM_X,  1,  200);
     IGC_WRITE. 2D COORD_REG (igc_p, IGM_ABS, IGM_Y, 1,140);
     IGC_WRITE 2D COORD_REG  igc_p, IGM_ABS, IGM_X, 2, 350);
     IGC_WRITE 2D COORD_REG  igc_10, IGM_ABS, IGM_Y, 2,320);
     IGC_WRITE_2D_COORD_REG  igc_10, IGM_ABS, IGM_X, 3, 420);
     IGC_WRITE 2D COORD_REG   igc_p,  IGM_ABS,  IGM_Y,  3,  380);
     do status = IGC_DO_BLIT (igc_p);
     while (status & IGM_STATUS_QB_BUSY_MASK);
}

5.5. Applying a Pattern

The following sample program, comprised of C and Q-code, produces the example in section 4.5.
This program draws a quad with a defined pattern applied.

EXAMPLE

#include <stdio.h>
/* toolkit include files */
#include ~igc_gtk.h~
#include ~igc_macros.h~
#include ~igc_pr.h~

#define IGC_F_MASK OxffOO
#define IGC_B_MASK OxfOfO
#define IGC_S_MASK Oxcccc
#define IGC D MASK Oxaaaa

#define SCREEN_WIDTH 1152
#define SCREEN_HEIGHT 900

#define OVER_SIZED OxlOOOO      /* Can also use IGM_RASTER_OVERSIZE_MODE */

ulong *igc__p;
ulong *ramdac_p;
struct size_2d dim = {1152,900}';

109


5.5. Applying a Pattern, continued

/* Data for the pattern */
static ulong pattern[8] = {
    Oxdeadbeef, Oxdeadbeef,
    Oxdeadbeef, Oxdeadbeef,
    Oxdeadbeef, Oxdeadbeef,
    Oxdeadbeef, Oxdeadbeef};

main()
{

int i, minterms, op, packed_xy, raster,
int x, y;
extern ulong *igc_connect_regs();
extern ulong *igc_connect_ramdac();
struct point_2d clip_rain, clip_max;

status;

/* Initialize this demo. */
clip_min.x = clip_min.y = O;
clip_max.x = SCREEN_WIDTH-I;
clip_max.y = SCREEN_HEIGHT-I;
demo_init(&igc__p, &ramdac_p, &clip_min,

&clip_max);

/* Initialize the RAMDACs,  foreground and background colors */
color_init();

#define GRN 4
#define YEL 5
#define RED 2
#define BLU 3

{
  int packed_xy, raster, status, x, y;

raster = IGC_READ_REG(igc_P,  IGM_RASTER);
raster =  (raster & Ox30000)  ~  IGC_F_MASK I OVER_SIZED;

    Wait to load the pixel processing registers. */
do status = IGC_READ_REG(igc_p,  IGM_STATUS);
while(status & IGM_STATUS_BUSY_MASK);

/* Load the registers. */
IGC_WRITE_REG(igc_P,  IGM_RASTER,  raster);
IGC_WRITE_REG (igc_p, IGM_PLANE_MASK, Oxff);

110


POWER 9000
USER INTERFACE
CONTROLLER

October1992

5.5. Applying a Pattern, continued

/*Quad with a pattern */
/* Load the parameter engine */
 packed_xy = IGM_PACK(390-200, 220);
 IGC_WRITE_2D_META_COORD  ( igc_p,   IGM_ABS,
 packed_xy = IGM_PACK(440-200, 220);
 IGC_WRITE_2D_META_COORD  ( igc_p,  IGM_ABS,
 packed_xy = IGM_PACK(390-200, 420);
 IGC_WRITE_2D_META_COORD (igc_p, IGM_ABS,
 packed_xy = IGM_PACK(440-200, 420);
 IGC_WRITE 2D META_COORD (igc_p, IGM_ABS,

IGM_XY, IGM_QUAD, packed_xy);
IGM_XY, IGM_QUAD, packed_xy);
IGM_XY,  IGM_QUAD, packed_xy),
IGM_XY,  IGM_QUAD, packed_xy);

/* Load the pattern. */
/* The pattern is a 16x16 array of bits.   Load 2 rows at a time.  */
for(i=O; i<8; i++)
  IGC_WRITE_REG(igc_p,  IGM_PATTERNO+i, pattern[i] );

  /* Turn pattern use ON.  It's a read/modify/write to preserve the current
   * contents of the raster reg. */
#define IGM_USE_PATTERN Ox20000            /* Also defined in Toolkit */
   raster = IGC_READ_REG(igc_p,  IGM_RASTER);
   minterms =  (IGC_S_MASK & IGC F MASK);
    IGC_WRITE_REG(igc_p, IGM_RASTER,  (raster & Ox30000)  I minterms I
IGM_USE_PATTERN);

IGC_WRITE_REG ( igc_p, IGM_PAT_ORIGINX, 0 );
IGC_WRITE_REG ( igc_p, IGM_PAT_ORIGINY, O);

/* Draw the quad. */
do status = IGC_DRAW_QUAD(igc_p);
while (status & IGM_STATUS_QB_BUSY_MASK);

/* Wait to load the pixel processing registers. */
do status = IGC_READ_REG(igc_p,  IGM_STATUS),
while(status & IGM_STATUS_BUSY_MASK);

 /* Turn pattern use OFF. */
  IGC_WRITE_REG ( igc_p,  IGM_RASTER,  raster);
}

111


5.6. Drawing with Pixell

The following sample program, comprised of C and Q-code, produces the example in section 4.6.
This program performs a pixell operation.

EXAMPLE

#include <stdio.h>
/* toolkit include files */
#include ~igc_gtk.h~
#include ~igc_macros.h~
#include ~igc_pr.h~

#define IGC_F_MASK OxffOO
#define IGC_B_MASK OxfOfO
#define IGC_S_MASK Oxcccc
#define IGC_D_MASK Oxaaaa

#define SCREEN_WIDTH 1152
#define SCREEN_HEIGHT 900

#define OVER_SIZED OxlOOOO     /* Can also use IGM_RASTER_OVERSIZE_MODE */
ulong *igc_p;
ulong *ramdac_p;
struct size_2d dim = {1152,900};

/* Data for the pixell examples */
static ulong rune[] = {
        OxfOfOfOfO,  OxfOfOfOfO
        OxOfOfOfOf,  OxOfOfOfOf
        OxfOfOfOfO,  OxfOfOfOfO
        OxOfOfOfOf,  OxOfOfOfOf
        OxfOfOfOfO,  OxfOfOfOfO
        OxOfOfOfOf,  OxOfOfOfOf
        OxfOfOfOfO,  OxfOfOfOfO
        OxOfOfOfOf,  OxOfOfOfOf
        };

OxfOfOfOfO,  OxfOfOfOfO,
OxOfOfOfOf,  OxOfOfOfOf
OxfOfOfOfO,  OxfOfOfOfO
OxOfOfOfOf,  OxOfOfOfOf
OxfOfOfOfO,  OxfOfOfOfO
OxOfOfOfOf,  OxOfOfOfOf
OxfOfOfOfO,  OxfOfOfOfO,
OxOfOfOfOf,  OxOfOfOfOf,

main()
{

int i, minterms, op, packed_xy, raster, status;
int x, y;
extern ulong *igc_connect_regs();
extern ulong *igc_connect_ramdac();
struct point_2d clip_min, clip_max;

/* Initialize this demo. */
clip_min.x = clip_min.y = O;
clip_max.x = SCREEN_WIDTH-i;
clip_max.y = SCREEN_HEIGHT-i;
demo_init(&igc_p, &ramdac_p, &clip_min,

&clip_max);

112


POWER 9000
USER INTERFACE
CONTROLLER

October 1992

5.6. Drawing with Pixell, continued

/* Initialize the RAMDACs,  foreground and background colors */
color_init ( );

#define GRN 4
#define YEL 5
#define RED 2
#define BLU 3

int packed_xy, raster, status, x, y;

raster = IGC_READ_REG(igc~,  IGM_RASTER);
raster = (raster & Ox30000) I IGC F MASKlOVER_SIZED;

/* We must wait here because we can't be sure the chip is ready.  */
do status = IGC_READ_REG(igc~,  IGM_STATUS);
while(status & IGM_STATUS_BUSY_MASK);

  IGC_WRITE_REG(igc_p,  IGM_RASTER. raster);
  IGC_WRITE_REG  (igc_p,  IGM_PLANE_MASK,  Oxff);
}

/* pixell example */
/* Definitions used for the pixell register values */
define XO  500 ,/* Left edge of block. */
define Xi  500/* Current point for transfer. */
define YI  250
define X2  532/* Right hand edge of block.  */
define Y3  1    /* Increment */

/* Set up a foreground and background pseudo-color index.  */
IGC_WRITE_REG (igc~, IGM_FGROUND, RED);
IGC_WRITE_REG (igc_/o, IGM_BGROUND, GRN);

/* Set up the parameter engine for the pixell operation.    */
IGC_WRITE. 2D COORD_REG(igc~, IGM_ABS, IGM_X, O, XO);
packed_xy = IGM_PACK(Xi,Yi);
IGC_WRITE_2D_COORD_REG(igc_p,  IGM_ABS,  IGM_XY,  1, packed_xy);
IGC_WRITE_2D_COORD_REG(igc~, IGM_ABS, IGM_X, 2, X2);
IGC_WRITE. 2D.COORD_REG(igc_p, IGM_ABS, IGM_Y, 3, Y3);

/* Set up the minterms to write foreground when source is 1 and
    * background when source is O. */
minterms = (IGC_S_MASK & IGC F MASK) I (~IGC S MASK & IGC B _MASK);
raster = IGC_READ_REG(igc_p,  IGM_RASTER);
raster = (raster & Ox30000)  I minterms I OVER_SIZED;
IGC_WRITE_REG(igc~,  IGM_R_ASTER, raster);

  /* A pixell will wait for the Power 9000 to finish the current operation,
      * its up to you to make sure its waiting for another pixell. */
  for (i=O; i<sizeof(rune)/4; i++)
      IGC_WRITE_PIXELI (igc~, 31, rune [ i] );

}

113


5.7. Applying Transparency

The following sample program, comprised of C and Q-code, produces the example in section 4.7.

This program repeats the previous pixell, applies transparency, and then performs a second pixell.

EXAMPLE

#include <stdio.h>
/* toolkit include files */
#include 'igc_gtk.h~
#include 'igc_macros.h~
#include ~igc_pr.h~

#define IGC F MASK OxffOO
#define IGC_B_MASK OxfOfO
#define IGC S MASK Oxcccc
#define IGC_D_MASK Oxaaaa

#define SCREEN_WIDTH 1152
#define SCREEN_HEIGHT 900

#define OVER_SIZED OxlOOOO      /* Can also use IGM_RASTER_OVERSIZE_MODE */

ulong *igc_p;
ulong *ramdace;
struct size_2d dim = {1152,900};

/* Data for the pixell examples */
static ulong rune[] = {
        OxfOfOfOfO,  OxfOfOfOfO,  OxfOfOfOfO,  OxfOfOfOfO,
        OxOfOfOfOf,  OxOfOfOfOf,  OxOfOfOfOf,  OxOfOfOfOf,
        OxfOfOfOfO,  OxfOfOfOfO,  OxfOfOfOfO,  OxfOfOfOfO,
        OxOfOfOfOf, OxOfOfOfOf, OxOfOfOfOf, OxOfOfOfOf,
        OxfOfOfOfO,  OxfOfOfOfO,  OxfOfOfOfO,  OxfOfOfOfO,
        OxOfOfOfOf, OxOfOfOfOf, OxOfOfOfOf, OxOfOfOfOf,
        OxfOfOfOfO,  OxfOfOfOfO,  OxfOfOfOfO,  OxfOfOfOfO,
        OxOfOfOfOf,  OxOfOfOfOf,  OxOfOfOfOf,  OxOfOfOfOf,
        };

main()
{

int i, minterms, op, packed_xy, raster, status;
int x, y;
extern ulong *igc_connect_regs();
extern ulong *igc_connect_ramdac();
struct point_2d clip_rain, clip_max;

/* Initialize this demo.  */
clip_min.x = clip_min.y = O;
clip_max.x = SCREEN_WIDTH-I;
clip_max.y = SCREEN_HEIGHT-i;
demo_init(&igc_p, &ramdac_p, &clip_min, &clip_max);

114


POWER 9000
USER INTERFACE
CONTROLLER

October 1992

5.7. Applying Transparency, continued

  /* Initialize the RAMDACs,  foreground and background colors */
  color_init();

#define GRN 4
#define YEL 5
#define RED 2
#define BLU 3

{
  int packed_xy, raster, status, x, y;

raster = IGC_READ_REG(igc_/o,  IGM_RASTER);
raster = (raster & Ox30000) I IGC F MASK ~ OVER_SIZED;

/* We must wait here because we can't be sure the chip is ready.  */
do status = IGC_READ_REG(igc_/D,  IGM_STATUS);
while(status & IGM_STATUS_BUSY_MASK);

  IGC_WRITE_REG(igc_p,  IGM_RASTER,  raster);
  IGC_WRITE_REG (igc_p, IGM_PLANE_MASK, Oxff);
}

/* pixell example */
/* Definitions used for the pixell register values */
define XO  500/* Left edge of block. */
define XI  500/* Current point for transfer. */
define Yi  250
define X2  532/* Right hand edge of block.  */
define Y3  1    /* Increment */

/* Set up a foreground and background pseudo-color index.  */
IGC_WRITE_REG (igc_p, IGM_FGROUND, RED);
IGC_WRITE_REG (igc_/o, IGM_BGROUND, GRN);

/* Set up the parameter engine for the iDixell operation.   */
IGC_WRITE. 2D COORD_REG(igc_p, IGM_ABS, IGM_X, O, XO);
packed_xy = IGM_PACK(XI,Yi),
IGC_WRITE. 2D COORD_REG(igc_p,  IGM_ABS,  IGM_XY,  1, packed_xy);
IGC_WRITE. 2D COORD_REG(igc_/o, IGM_ABS, IGM_X, 2, X2);
IGC_WRITE_2D_COORD_REG(igc_p, IGM_ABS, IGM_Y, 3, Y3);

/* Set up the minterms to write foreground when source is 1 and
    * background when source is O. */
rainterms = (IGC_ S MASK & IGC_F_MASK)  I  (~IGC S MASK & IGC B MASK);
raster = IGC_READ_REG(igc_p,  IGM_RASTER);
raster = (raster & Ox30000)  I minterms I OVER_SIZED;
IGC_WRITE_REG(igc_13,  IGM_P~ASTER,  raster);

/* A pixell will wait for the Power 9000 to finish the current operation,
    * its up to you to make sure its waiting for another pixell.  */
for (i=O; i<sizeof(rune)/4; i++)
   IGC_WRITE_PIXELI(igc_p,31,rune[i]);

115


POWER 9000
USER INTERFACE
CONTROLLER

October 1992

5.7. Applying Transparency, continued

/* Initialize the RAMDACs,  foreground and background colors */
color_init ( );

#define GRN 4
#define YEL 5
#define RED 2
#define BLU 3

{
  int packed_xy, raster, status, x, y;

raster = IGC_READ_REG(igc_p,  IGM_RASTER);
raster =  (raster & Ox30000)  I  IGC F MASK I OVER_SIZED;

/* We must wait here because we can't be sure the chip is ready.  */
do status = IGC_READ_REG(igc_p,  IGM_STATUS);
while(status & IGM_STATUS_BUSY_MASK);

  IGC_WRITE_REG(igc_p,  IGM_RASTER,  raster);
  IGC_WRITE_REG (igc_p, IGM_PLANE_MASK, Oxff);
}

/* pixell example */
/* Definitions used for the pixell register values */
define XO  500/* Left edge of block. */
define XI  500/* Current point for transfer.  */
define Yi  250
define X2  532/* Right hand edge of block.  */
define Y3  1    /* Increment */

/* Set up a foreground and background pseudo-color index.  */
IGC_WRITE_REG (igc_p, IGM_FGROUND, RED);
IGC_WRITE_REG (igc_io, IGM_BGROUND, GRN);

/* Set up the parameter engine for the pixell operation.    */
IGC_WRITE_2D_COORD_REG(igc_p, IGM_ABS, IGM_X, O, XO);
packed_xy = IGM_PACK(Xi,YI);
IGC_WRITE_2D_COORD_REG(igc_p,   IGM_ABS,  IGM_XY,  1, packed_xy);
IGC_WRITE_2D_COORD_REG(igc_p,   IGM_ABS,   IGM_X,   2,   X2);
IGC_WRITE_2D_COORD_REG(igc_p,   IGM_ABS,  IGM_Y,  3, Y3);

/* Set up the minterms to write foreground when source is 1 and
    * background when source is O.  */
minterms = (IGC_S_MASK & IGC F MASK)  ~  (-IGC_S_MASK & IGC B MASK);
raster = IGC_READ_REG(igc_10,  IGM_RASTER);
raster = (raster & Ox30000)  I minterms I OVER_SIZED;
IGC_WRITE_REG(igc_p,  IGM_RASTER,  raster);

/* A pixell will wait for the Power 9000 to finish the current operation,
    * its up to you to make sure its waiting for another pixell. */
for (i=O; i<sizeof(rune)/4; i++)
   IGC_WRITE_PIXELi(igc_p,31,rune[i]);

115


POWER 9000
USER INTERFACE
CONTROLLER

October 1992

5.8. Drawing Characters with Pixell, continued

/* Data for the pixell character example */
~define N_CHARS 6
static int weitek[N_CHARS] [2] = {
{0x92929254,0x7C444444},
{0x00003844,0x7C404438},
{OxlOO07010,0x1010107C},
{0x20207C20,0x20202418},
{0x00003844,0x7C404438},
{ 0xC0404C50, Ox705048EC} };

main()
{
  int i, minterms, op, packed_xy, raster, status;
  int x, y;
  extern ulong *igc_connect_regs();
  extern ulong *igc_connect_ramdac();
  struct point_2d clip_min, clip_max;
      int xO;  /* Left edge of block. */
      int xl;  /* Current point for transfer.  */
      int yl;
      int x2;/* Right hand edge of block. */
      int y3;   /* Increment */

    /* Initialize this demo.  */
clip_min.x = clip_min.y = O;
clip_max.x = SCREEN_WIDTH-I;
clip_max.y = SCREEN_HEIGHT-i;
demo_init(&igc_p, &ramdac_p, &clip_min, &clip_max);

/* Initialize the RAMDACs, foreground and background colors */
color_init();

#define GRN 4
#define YEL 5
#define RED 2
#define BLU 3
{
  int packed_xy,

raster, status, x, y;

raster = IGC_READ_REG(igc_p,  IGM_RASTER);
raster =  (raster & Ox30000)  I  IGC F MASK I OVER_SIZED;

/* Wait to load the pixel processing registers. */
do  status  =  IGC_READ_REG(igc_p,   IGM_STATUS);
while(status & IGM_STATUS_BUSY_MASK);

IGC_WRITE_REG(igc__p,  IGM_RASTER,  raster);
IGC_WRITE_REG (igc_p, IGM_PLANE_MASK, Oxff);

/* Turn pattern use OFF.  */
IGC_WRITE_REG(igc_p,  IGM_RASTER,  raster);

117


5.8. Drawing Characters with Pixell, continued

    /* pixell example */
/* Definitions used for the pixell register values */
   xO =   500;/* Left edge of block. */
   xl =   500;/* Current point for transfer. */
   =      250;
   x2 =   508;/* Right hand edge of block. */
   y3 =   1;    /~* Increment */

/* Set up a foreground and background pseudo-color index. */
IGC_WRITE_REG (igc__p, IGM_FGROUND, RED);
IGC_WRITE_REG (igc_p, IGM_BGROUND, GP~N);

/* Set up the parameter engine for the pixell operation.     */
IGC_WRITE_2D_COORD_REG(igc~,  IGM_ABS,  IGM_X,  O,  xO);
packed_xy = IGM_PACK(xl,yl);
IGC_WRITE_2D_COORD_REG(igc_iD,  IGM_ABS,  IGM_XY,  1, packed_xy);
IGC_WRITE_2D_COORD_REG(igc__p,  IGM_ABS,  IGM_X,  2, x2);
IGC_WRITE_2D_COORD_REG(igc~,    IGM_ABS,   IGM_Y,   3,  y3);

/* Set up the minterms to write foreground when source is 1 and
    * background when source is O. */
minterms =  (IGC_S_MASK & IGC_F_MASK);
raster = IGC_READ_REG(igc_p,  IGM_RASTER);
raster = (raster & Ox30000)  1 minterms ~ OVER_SIZED;
IGC_WRITE_REG(igc_p,  IGM_RASTER,  raster);

/* We must wait here because we can't be sure the chip is ready. */
do status = IGC_READ_REG(igc_p,  IGM_STATUS);
while (status & IGM_STATUS_BUSY_MASK);

/* A pixell will wait for the Power 9000 to finish ~he current operation,
    * its up to you to make sure its waiting for another pixell. */
for (i=O; i<6; i++)

  IGC_WRITE_PIXELI (igc_p, 31,weitek[i] [0]);
  IGC_WRITE_PIXELi (igc_p, 31,weitek[i] [1]);
    xO += 8;
    xl  += 8;
    yl = 250;
    x2   +=  8;

/* Set up the parameter engine for ~he pixell operation.   */
    IGC_WRITE_2D_COORD_REG(igc_P, IGM_ABS, IGM_X, O, xO);
    packed_xy = IGM_PACK(xl,yl);
  IGC_WRITE. 2D COORD_REG(igc_p,  IGM_ABS,  IGM_XY,  1, packed_xy);
  IGC_WRITE_2D_COORD_REG(igc_P,  IGM_ABS,  IGM_X,  2, x2);

 /* We must wait here because we can't be sure the chip is ready. */
     do status = IGC_READ_REG(igc_p,  IGM_STATUS);
     while ( status & IGM_STATUS_BUSY_MASK);

}

118


POWER 9000
USER INTERFACE
CONTROLLER

                                             October 1992
  Drawing with Pixe18

The following sample program, comprised of C and Q-code, produces the example in section 4.9.
This program draws two WEITEK logos in different colors.

EXAMPLE

#include <stdio.h>
/* toolkit include files */
#include 'igc_gtk.h'
#include 'igc_macros.h'
#include 'igc_pr.h'

#define IGC_F_MASK OxffOO
#define IGC_B_MASK OxfOfO
#define IGC S MASK Oxcccc
#define IGC D MASK Oxaaaa

#define SCREEN_WIDTH 1152
#define SCREEN_HEIGHT 900

#define OVER_SIZED OxlOOOO

ulong *igc_p;
ulong *ramdac_p;
struct size_2d dim = {1152,900};

main ( )
{

int i, minterms, op, packed_xy, raster,
int x, y;
extern ulong *igc_connect_regs();
extern ulong *igc_connect_ramdac();
struct point_2d clip_rain, clip_max;

status;

/* Initialize this demo. */
clip_min.x = clip_min.y = O;
clip_max.x = SCREEN_WIDTH-i;
clip_max.y = SCREEN_HEIGHT-i;
demo_init(&igc_p, &ramdac_p, &clip_min, &clip_max);

/* Initialize the RAMDACs,  foreground and background colors */
color_init();

#define GRN 4
#define YEL 5
#define RED 2
#define BLU 3

119


5.9. Drawing with Pixe18, continued

  /* With a 'mask nothing' plane mask, draw a 1ogo */

 /* Wait to write registers */
 do  status  =  IGC_READ_REG ( igc_p, IGM_STATUS );
  while (status & IGM_STATUS_BUSY_MASK);

IGC_WRITE_REG  (igc_io,  IGM_PLANE_MASK,  Oxff);
do_logo(igc_p, 100, 100, YEL, BLU, 0);

/* With a 'mask bit O' plane mask, draw a 1ogo of a different color */
IGC_WRITE_REG (igc_p, IGM_PLANE_MASK, Oxfe);
do_logo(igc_p, 200,  100, YEL, BLU, 0);

/* Back to 'mask nothing'. */
IGC_WRITE_REG (igc_p, IGM_PLANE_MASK, Oxff);

#define XDIM 100
#define YDIM 100
#define HOR 31
#define VRT 69

unsigned char 1Ogo[YDIM][XDIM];

do_logo(igc_p, x_off, y_off, upper_color,
ulong *igc_p;
int x_off, y_off;
int upper_color, lower_color, background;
{
  int dO;
  int x, y, val;
  int minterms;
  int packed_xy;
  int raster, run;
  int status;
  ulong *wptr;

lower_color, background)

minterms = IGC S_MASK;
raster = IGC_READ_REG(igC_p,  IGM_RASTER);
raster = (raster & Ox30000)  ~ minterms ~ OVER_SIZED;
IGC_WRITE_REG(igc_P,  IGM_RASTER, raster);

120


POWER 9000
USER INTERFACE
CONTROLLER

October 1992

5.9. Drawing with Pixe18, continued

/* Draw a 1ogo and thank goodness you don't work for the Stones.
for(y=O; y<YDIM; y++)
   for(x=O; x<XDIM; x++)
   {
      int val;
      if  (XDIM > x + y)
      val = background;
      else if  (x> VRT && y > HOR)
            val = background;
      else if (y <= HOR)
            val = upper_color;
      else val = lower_color;
      logo[y] [x] = val;
   }

/* Left hand edge of block */
IGC_WRITE_2D_COORD_REG(igc_p,  IGM_ABS,  IGM_X ,  O. x_off);

/* Current point for transfer */
packed_xy = IGM_PACK(x_off, y_off);
IGC_WRITE_2D_COORD_REG(igc_iD,  IGM_ABS,  IGM_XY,  1,  packed_xy);

/* Right hand edge to transfer [xl,x2)  */
IGC_WRITE_2D_COORD_REG(igc..p,   IGM_ABS,   IGM_X  ,   2,   x_off  +  XDIM);

/* Y increment */
IGC_WRITE 2D .COORD_REG(igc_p,  IGM_ABS,  IGM_Y , 3, 1);

run  =  XDIM  *  YDIM;
wptr = (ulong *)&logo[O] [0];

  while(run > O)
  {
      dO =  *wptr++;
      IGC_WRITE_PIXEL8 ( igc_p, dO );
      run  -=  4;
  }
}

*/

121



