Xref: utzoo comp.unix.microport:943 comp.unix.xenix:2598
Path: utzoo!attcan!uunet!husc6!mailrus!umix!metavax!oxtrap!b-tech!m2-net!lewis
From: lewis@m2-net.UUCP (Dave Lewis)
Newsgroups: comp.unix.microport,comp.unix.xenix
Subject: Graphics Library (part 2 of 5)
Keywords: Graphics EGA CGA Hercules Printers Microport Xenix 286 386
Message-ID: <1882@m2-net.UUCP>
Date: 1 Jul 88 04:01:41 GMT
References: <1881@m2-net.UUCP>
Reply-To: lewis@m-net.UUCP (Dave Lewis)
Organization: M-NET, Ann Arbor, MI
Lines: 775

------------------------------  cut here  ------------------------------
# To recover, type "sh archive"
echo restoring box.c
sed 's/^X//' > box.c < cellchar.c <= graphics.y_extent)) return(1);
X
X	/* Increment the graphics cursor, check X range.		*/
X	if ((graphics.x_cursor += (int)(NORM_X_RANGE * X_CELL_BITS 
X		/ graphics.x_extent)) < 0)
X		return(1);
X
X	/* Point at the character bit map to print.			*/
X	bits = (char *) &(charcell[asc_char * Y_CELL_BITS]);
X
X	/* Write the character.						*/
X	for (i=y; i < y + Y_CELL_BITS; i++, bits++) {
X		j=x;
X		if (*bits & 0x80) if (write_pix(j,i)) return(1); j++;
X		if (*bits & 0x40) if (write_pix(j,i)) return(1); j++;
X		if (*bits & 0x20) if (write_pix(j,i)) return(1); j++;
X		if (*bits & 0x10) if (write_pix(j,i)) return(1); j++;
X		if (*bits & 0x08) if (write_pix(j,i)) return(1); j++;
X		if (*bits & 0x04) if (write_pix(j,i)) return(1); j++;
X		if (*bits & 0x02) if (write_pix(j,i)) return(1); j++;
X		if (*bits & 0x01) if (write_pix(j,i)) return(1); j++;
X	}
X
X	return(0);
X}
XxX--EOF--XxX
echo restoring cellstr.c
sed 's/^X//' > cellstr.c <
X
Xint cellstr(strng)  
Xchar strng[];
X{
X	int i;
X	int cellchar();
X	for(i=0; strng[i] != NULL; i++)  {
X		if (cellchar(strng[i])) return(1);
X	}
X	return(0);
X}
X
XxX--EOF--XxX
echo restoring clear.c
sed 's/^X//' > clear.c <page1[i][j] = 0x0;
X					(graphics.cgamem)->page2[i][j] = 0x0;
X				}
X			}
X			break;
X
X		case CGA_HI_RES_MODE:
X			for(i=0; i<100; i++)  {
X				for(j=0; j<80; j++)  {
X					(graphics.cgamem)->page1[i][j] = 0x0;
X					(graphics.cgamem)->page2[i][j] = 0x0;
X				}
X			}
X			break;
X
X		case EGA_COLOR_MODE:
X			for (i=0 ; i<350 ; i++) {
X				for (j=0 ; j<80 ; j++) {
X					(graphics.egamem)->mem[i][j] = 0x0;
X				}
X			}
X			break;
X
X		case HERC_GRAF_MODE:
X			for(i=0; i<87; i++)  {
X				for(j=0; j<90; j++)  {
X					(graphics.hercmem)->page1[i][j] = 0x0;
X					(graphics.hercmem)->page2[i][j] = 0x0;
X					(graphics.hercmem)->page3[i][j] = 0x0;
X					(graphics.hercmem)->page4[i][j] = 0x0;
X				}
X			}
X			break;
X
X		case IBM_PRINTER:
X			for(i=0; ibuf[i][j] = 0x0;
X					(graphics.printbuf2)->buf[i][j] = 0x0;
X					(graphics.printbuf3)->buf[i][j] = 0x0;
X				}
X			}
X			break;
X
X		default:
X			return(1);
X
X	}
X	return(0);
X}
XxX--EOF--XxX
echo restoring cursor.c
sed 's/^X//' > cursor.c < graphics.cellfont.chars_per_line) return(1);
X	if (row <= 0 || row > graphics.cellfont.lines_per_screen) return(1);
X
X	/* Move the graphics cursor.  Add a 1/2 pixel offset so we will	*/
X	/* always round down to the correct pixel value.		*/
X
X	xval = (col-1) * graphics.cellfont.xtic;	/* The value...	*/
X	xval += NORM_X_RANGE / graphics.x_extent / 2;	/* Plus 1/2 pix	*/
X
X	yval = (row-1) * graphics.cellfont.ytic;
X	yval += NORM_Y_RANGE / graphics.y_extent / 2;
X
X	if (movepen((int)xval, (int)yval)) return(1);
X
X	return(0);
X}
XxX--EOF--XxX
echo restoring draw.c
sed 's/^X//' > draw.c < y_pixels) {
X                /* Stepwise in x direction. */
X
X                /* Calculate the slope to use (rise over run). */
X                /* Shift left 16 bits for precision. */
X                if (x_dist != 0) slope = (long)y_dist * 0x010000L / 
X                (long)x_dist;
X                else slope = 0x7FFFFFFFL; /* Infinity */
X
X                /* Figure a fudge factor to be used in offsetting the */
X                /* pixels by 1/2 pixel. */
X                if (slope > 0) offset = 1;
X                else if (slope < 0) offset = -1;
X                else offset = 0;
X
X                /* Write the line on the screen. */
X
X                if (x_final - x_start >= 0)  {
X                        if (slope==0)  {
X                                while (x_current <= x_final)
X					if (write_pix(x_current++, 
X						y_current)) return(1);
X                        }
X                        else for (idx=0; idx <= x_pixels; idx++, x_current++)  {
X                                y_current = y_start + (idx*slope/0x08000L 
X                                + offset)/2;
X                                if (write_pix(x_current, y_current))
X					return(1);
X                        }
X                }
X                else  {
X                        if (slope==0)  {
X				while (x_current >= x_final)
X                                        if (write_pix(x_current--, 
X						y_current)) return(1);
X                        }
X                        else for (idx=0; idx <= x_pixels; idx++, x_current--)  {
X                                y_current = y_start - (idx*slope/0x08000L 
X                                + offset)/2;
X                                if (write_pix(x_current, y_current)) 
X					return(1);
X                        }
X                }
X        }
X        else  {
X                /* Stepwise in y direction. */
X
X                /* Calculate the inverse slope to use (run over rise). */
X                /* Shift left 16 bits for precision. */
X                if (y_dist != 0) slope = (long)x_dist * 0x010000L / 
X                (long)y_dist;
X                else slope = 0x7FFFFFFF; /* Infinity */
X
X                /* Figure a fudge factor to be used in offsetting the */
X                /* pixels by 1/2 pixel. */
X                if (slope > 0) offset = 1;
X                else if (slope < 0) offset = -1;
X                else offset = 0;
X
X               /* Write the line on the screen. */
X
X                if (y_final - y_start >= 0)  {
X                        if (slope==0)  {
X                                while (y_current <= y_final)
X                                        if (write_pix(x_current, 
X						y_current++)) return(1);
X                        }
X                        else for (idx=0; idx <= y_pixels; idx++, y_current++)  {
X                                x_current = x_start + (idx*slope/0x08000L 
X                                + offset)/2;
X                                if (write_pix(x_current, y_current))
X					return(1);
X                        }
X                }
X                else  {
X                        if (slope==0)  {
X				while (y_current >= y_final)
X                                        if (write_pix(x_current, 
X						y_current--)) return(1);
X                        }
X                        else for (idx=0; idx <= y_pixels; idx++, y_current--)  {
X                                x_current = x_start - (idx*slope/0x08000L 
X                                + offset)/2;
X                                if (write_pix(x_current, y_current))
X					return(1);
X                        }
X                }
X        }
X        /* Advance the cursor to the new position. */
X        graphics.x_cursor = new_x_cursor;
X        graphics.y_cursor = new_y_cursor;
X	return(0);
X}
XxX--EOF--XxX
echo restoring grafchar.c
sed 's/^X//' > grafchar.c < grafstr.c <
X
Xint grafstr(strng,x,y,vsize,hsize,spacing)  
Xchar strng[];
Xint 	x,		/* X position of upper left corner of character cell */
X	y,		/* Y position of character cell			*/
X	vsize,		/* Vertical size of character cell		*/
X	hsize,		/* Horizontal size of character cell		*/	
X	spacing;	/* Distance between characters			*/
X{
X	int i;
X	int grafchar();
X	for(i=0; strng[i] != NULL; i++)  {
X		if (grafchar(strng[i],x,y,vsize,hsize)) return(1);
X		x += spacing;
X	}
X	return(0);
X}
X
XxX--EOF--XxX
echo restoring init.c
sed 's/^X//' > init.c <
X#include 
X#include 
X#include 
X#include 
X#include "graphics.h"
X
Xstruct SVAT_graphics graphics;
X
Xint init(mode)
Xint mode;
X/* Mode is the video mode that will be used when in graphics mode.	*/
X/* By implication, this gives us the memory location we want to attach	*/
X/* to, as well as the dimensions of the screen.				*/
X
X{
X	char *shmat();
X	int shmid;
X	char *malloc();
X	int clear();
X	extern int errno;
X	static char initialized = 'N';	/* Flag to prevent reinitialization */
X
X	graphics.grafmode = mode;
X
X	/* Attach to the appropriate shared memory segment, and set the	*/
X	/* values of graphics.x_extent and graphics.y_extent, according	*/
X	/* to the video mode requested.					*/
X
X	switch (graphics.grafmode)  {
X	case CGA_COLOR_MODE:
X		graphics.x_extent = 319;
X		graphics.y_extent = 199;
X		graphics.x_window_ll = 0;
X		graphics.y_window_ll = 0;
X		graphics.x_window_ur = 319;
X		graphics.y_window_ur = 199;
X		graphics.aspect_ratio = 0.7;
X		graphics.cellfont.chars_per_line = 40;
X		graphics.cellfont.lines_per_screen = 25;
X		graphics.strokefont.xtic = 800;
X		graphics.strokefont.ytic = 1500;
X		graphics.strokefont.xsize = 100;
X		graphics.strokefont.ysize = 160;
X		if ((shmid = shmget(0xB8000L, 32768, IPC_CREAT)) < 0)
X			return(errno);
X		graphics.cgamem = (CGA_BUF_TYPE *)shmat(shmid, 0L, 0);
X		break;
X	case CGA_HI_RES_MODE:
X		graphics.x_extent = 639;
X		graphics.y_extent = 199;
X		graphics.x_window_ll = 0;
X		graphics.y_window_ll = 0;
X		graphics.x_window_ur = 639;
X		graphics.y_window_ur = 199;
X		graphics.aspect_ratio = 0.7;
X		graphics.cellfont.chars_per_line = 80;
X		graphics.cellfont.lines_per_screen = 25;
X		graphics.strokefont.xtic = 480;
X		graphics.strokefont.ytic = 1500;
X		graphics.strokefont.xsize = 60;
X		graphics.strokefont.ysize = 160;
X		if ((shmid = shmget(0xB8000L, 32768, IPC_CREAT)) < 0)
X			return(errno);
X		graphics.cgamem = (CGA_BUF_TYPE *)shmat(shmid, 0L, 0);
X		break;
X	case HERC_GRAF_MODE:
X		graphics.x_extent = 719;
X		graphics.y_extent = 347;
X		graphics.x_window_ll = 0;
X		graphics.y_window_ll = 0;
X		graphics.x_window_ur = 719;
X		graphics.y_window_ur = 347;
X		graphics.aspect_ratio = 0.7;
X		graphics.cellfont.chars_per_line = 90;
X		graphics.cellfont.lines_per_screen = 43;
X		graphics.strokefont.xtic = 400;
X		graphics.strokefont.ytic = 1500;
X		graphics.strokefont.xsize = 50;
X		graphics.strokefont.ysize = 160;
X		if ((shmid = shmget(0xB0000L, 32768, IPC_CREAT)) < 0)
X			return(errno);
X		graphics.hercmem = (HERC_BUF_TYPE *)shmat(shmid, 0L, 0);
X		break;
X	case EGA_COLOR_MODE:
X		/* (not implemented yet) */
X		graphics.x_extent = 639;
X		graphics.y_extent = 349;
X		graphics.x_window_ll = 0;
X		graphics.y_window_ll = 0;
X		graphics.x_window_ur = 639;
X		graphics.y_window_ur = 349;
X		graphics.aspect_ratio = 0.7;
X		graphics.cellfont.chars_per_line = 80;
X		graphics.cellfont.lines_per_screen = 43;
X		graphics.strokefont.xtic = 480;
X		graphics.strokefont.ytic = 1500;
X		graphics.strokefont.xsize = 60;
X		graphics.strokefont.ysize = 160;
X		if ((shmid = shmget(0xA0000L, 32768, IPC_CREAT)) < 0)
X			return(errno);
X		graphics.egamem = (EGA_BUF_TYPE *)shmat(shmid, 0L, 0);
X		break;
X	case IBM_PRINTER:
X		graphics.x_extent = 719;
X		graphics.y_extent = 959;
X		graphics.x_window_ll = 0;
X		graphics.y_window_ll = 0;
X		graphics.x_window_ur = 719;
X		graphics.y_window_ur = 959;
X		graphics.aspect_ratio = 0.7;
X		graphics.cellfont.chars_per_line = 90;
X		graphics.cellfont.lines_per_screen = 120;
X		graphics.strokefont.xtic = 400;
X		graphics.strokefont.ytic = 1000;
X		graphics.strokefont.xsize = 50;
X		graphics.strokefont.ysize = 100;
X		if ((graphics.printbuf1 = (PR_BUF_TYPE *)malloc
X			(sizeof(PR_BUF_TYPE))) == NULL) return(1);
X		if ((graphics.printbuf2 = (PR_BUF_TYPE *)malloc
X			(sizeof(PR_BUF_TYPE))) == NULL) return(1);
X		if ((graphics.printbuf3 = (PR_BUF_TYPE *)malloc
X			(sizeof(PR_BUF_TYPE))) == NULL) return(1);
X		break;
X
X	default:
X		/* The programmer is probably confused at this point,	*/
X		/* so we may as well exit.				*/
X		printf ("Unable to initialize in routine init().  Mode %d requested.\n",graphics.grafmode);
X		exit (1);
X	}
X
X	/* Set other variables to reasonable values.			*/
X
X	graphics.color = 2;
X	graphics.wrt_mode = OR;
X	graphics.xlate_x = 0;
X	graphics.xlate_y = 0;
X	graphics.xlate_z = 0;
X	graphics.offset_x = 0;
X	graphics.offset_y = 0;
X	graphics.offset_z = 0;
X	graphics.theta_x = 0;
X	graphics.theta_y = 0;
X	graphics.theta_z = 0;
X	graphics.c_tz_c_ty = 1.0;
X	graphics.s_tz = 0.0;
X	graphics.s_ty = 0.0;
X	graphics.c_tz_c_tx = 1.0;
X	graphics.s_tx = 0.0;
X	graphics.scale_factor = 1.0;
X	graphics.perspect_dist = HUGE;
X	graphics.x_vport_ll = NORM_X_MIN;
X	graphics.y_vport_ll = NORM_Y_MAX;
X	graphics.x_vport_ur = NORM_X_MIN;
X	graphics.y_vport_ur = NORM_Y_MAX;
X
X	graphics.strokefont.angle = 0;
X	graphics.strokefont.angle = 0;
X
X	/* Character cell spacing in normalized coordinates.  This is	*/
X	/* the distance in normalized coordinates.  The calculation	*/
X	/* must account for leftover scan lines on the bottom of the	*/
X	/* screen.							*/
X	graphics.cellfont.xtic = 
X		NORM_X_RANGE
X		* (graphics.x_extent 
X		- (graphics.x_extent + 1) % X_CELL_BITS)
X		/ graphics.x_extent
X		/ graphics.cellfont.chars_per_line;
X	/* The (integer) value just got rounded down, but we want to	*/
X	/* round up always, so that we won't lose a pixel.  Therefore	*/
X	/* increment the value by 1.					*/
X	graphics.cellfont.xtic++;
X
X	graphics.cellfont.ytic =
X		NORM_Y_RANGE 
X		* (graphics.y_extent 
X		- (graphics.y_extent + 1) % Y_CELL_BITS)
X		/ graphics.y_extent
X		/ graphics.cellfont.lines_per_screen;
X	graphics.cellfont.ytic++;
X
X	graphics.cellfont.xmult = 1;	/* Cell size multipliers	*/
X	graphics.cellfont.ymult = 1;
X
X	/* Erase graphics memory.					*/
X	if (clear()) return(1);
X
X	return(0);
X}
XxX--EOF--XxX
-- 
Dave Lewis
Ann Arbor, MI
...![ itivax umix ]!m-net!dtlewis!lewis