[net.micro.att] Bitmaps on the 7300, an example

root@bu-cs.UUCP (Barry Shein) (08/23/85)

Ok, maybe I'm dense, but I had quite a bit (no pun intended) of trouble
getting a plain old bitmap out to the screen. Of course, once I got it
right it was 'obvious'. I thought I'd be a nice guy and share my minimal
program from which any other attempt should be easy (I am not completely
altruistic, I will be watching net.sources closely for all the nice
public domain software that now starts to flow :-)

This probably could be brought down a layer lower (ie. eliminate the tam
calls winit(), wcreate() and wexit()) but I don't think that's necessary
and likely in a real application you would be using that library anyhow.
I guess the first thing I would add is a call to iswind() to insure we
are on a bitmapped window at all.

Note that I was able to panic my 7300 with absurd arguments to these
routines, watch out for impossible srcwidth/width combinations.  Someone
at ATTIS development eagerly took the source to a program of mine which
caused a panic so I suspect this problem will be fixed.  One good point:
tho the machine panic'd many times while I played it always came back up
without a peep 3 minutes later, it seems very stable about these things!

	-Barry Shein, Boston University

-----fold and cut----
#include <stdio.h>
#include <sys/window.h>

/*
 *	An absolutely minimal program to fill your AT&T/UNIX/PC/7300
 *	screen with a bunch of vertical lines via use of direct
 *	raster/bitmap operations. It took me quite a few tries to get
 *	this right, maybe I can save you some trouble.
 *
 *	cc this.c -ltam -ltermlib -o whatever
 *
 *	Barry Shein, Boston University
 */
#define XMAX	uw.uw_width			/* in pixels		*/
#define YMAX	uw.uw_height			/* in pixels		*/
#define BPERBY	8				/* bits per byte	*/
#define XMAXB	((XMAX+(BPERBY-1))/BPERBY)	/* in bytes		*/
#define YMAXB	YMAX				/* same as pixels	*/
#define U unsigned short			/* type for args	*/
#define MAXROW	25				/* in 'chars'		*/
#define MAXCOL	80				/* in 'chars'		*/
main(argc,argv) int argc ; char **argv ;
{
	register char *bmap,*cp ;		/* will hold bitmap	*/
	short int wd ;				/* window fd		*/
	register int i ;
	struct uwdata uw ;			/* for ioctl		*/

	winit() ;				/* required !		*/
	/*
	 *	create a new window the size of the whole screen
	 *	with no border (see sys/window.h for other flags
	 */
	if((wd = wcreate(0,0,MAXROW,MAXCOL,NBORDER)) < 0)
	{
		perror("wcreate") ;
		wexit(1) ;
	}
	/*
	 *	get info about the window we just built, esp
	 *	height and width in pixels (XMAX,YMAX)
	 */
	if(ioctl(wd,WIOCGETD,&uw) < 0)
	{
		perror("WIOCGETD") ;
		wexit(1) ;
	}
	/*
	 *	allocate the bitmap for the entire window
	 */
	if((bmap = (char *)malloc(XMAXB*YMAXB)) == NULL)
	{
		perror("malloc") ;
		wexit(1) ;
	}
	/*
	 *	fill the bitmap up with stripes (07's)
	 */
	for(i=0,cp=bmap ; i < (XMAXB*YMAXB) ; i++,cp++)
		*cp = 07 ;
	/*
	 *	Ok, now dump it to the screen.
	 */
	if(wrastop(wd,
		(U *)bmap,		/* the bitmap			*/
		XMAXB,			/* each row in bytes		*/
		(U *)0,0,		/* null: use screen for output	*/
		0,0,			/* start at 0,0 in source	*/
		0,0,			/* start at 0,0 in dst (screen)	*/
		XMAX,YMAX,		/* entire screen		*/
		SRCSRC,DSTSRC,		/* just replace dest with src	*/
		(U *)0)			/* no pattern being used	*/
			< 0) {
			perror("wrastop") ;
			wexit(1) ;
	}
	wexit(0) ;
}