DataMuseum.dk

Presents historical artifacts from the history of:

ICL Comet 32

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about ICL Comet 32

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - metrics - download

⟦f64764dcf⟧ TextFile

    Length: 10558 (0x293e)
    Types: TextFile
    Notes: UNIX file
    Names: »cgraph.old0«

Derivation

└─⟦26887b7e0⟧ Bits:30009717 Comet 32 harddisk image
    └─⟦28c352965⟧ »/a« UNIX Filesystem
        └─⟦this⟧ »usr/src/gks/comet/cgraph.old0« 

TextFile

/*
 *  graph.c
 *
 *  Fonts are assumed to be 8 pixels wide and a bitmap row is
 *  written into one double word of the graphics ram.  All the
 *  "form" stuff has been deleted from the original.
 *  	
 */

#include "../h/graph.h"

#ifndef FONT
#define FONT typerite_10
#endif

extern font_header FONT;
init_vspy()
{
	int i;

	if (vspy(MPS_PAGE, Phys_MPS, 1) < 0) {
		perror("vspy");
		fprintf(stderr, "on control page\n");
		exit(1);
	}

	for (i=0; i<512; i++) {
		if (vspy(GB_VideoRAM+i*BLKSIZE, Phys_RAM+i*BLKSIZE, 1) < 0) {
			perror("vspy");
			fprintf(stderr, "on page #%d\n", i);
			exit(1);
		}
	}
}


initgraph()
{
#if DBG > 0
	printf("initgraph\n");
#endif

	init_vspy();

	finfo = (chardes *)(&FONT + 1) - FONT.first_ch;
	fbase = (unsigned char *)(finfo + FONT.last_ch + 1);

	blp = &finfo[BIGBLOB];
	Fh = blp->up + blp->down;

	gramstart = RAMSTART;
	vram = GB_VideoRAM;
	display.base = GB_VideoRAM;
	*GB_Utility = 0;
	initcolour();
}

exitgraph()
{
#if DBG > 0
	printf("exitgraph\n");
#endif
	lcol = mcol = tcol = GREEN;
	cheight = 0;
	*GB_Control = GREENCURSOR | DISPLAY;
}
cleardisplay()
{
	*GB_Control = HIGHSPEED;
	clearsd(0,YSIZE*LINESIZE);
	*GB_Control = DISPLAY;
}

clearsd(coff, cnt)
int coff, cnt;
{
	asm("	movd	16(fp),r0	");
	asm("	subd	1,r0		");
	asm("	movd	12(fp),r1	");
	asm("	ashd	2,r1		");
	asm("	addd	_vram,r1	");
	asm("	addr	4(r1),r2	");
	asm("	movqd	0,0(r1)		");
	asm("	movsd			");
}

initcolour()
{
	register int i,k;
	
	for (k=0; k<8; k++) {
		for (i=0; i<8; i++) {
			if (4 & k) color[k][i] |= (1 << (i+24));	
			if (2 & k) color[k][i] |= (1 << (i+16));	
			if (1 & k) color[k][i] |= (1 << (i+8));	
		}
	}
	for (i=0; i<8; i++) color[8][i] |= (1<<i);
}

u_int getaddr(bp,p)
bitmap *bp;
point p;
/* Answer adress of point p in bitmap *bp
 * Return zero if p not in bp.
 */
{
	register u_int offset;
	rectangle r;

	/* Inside test */
	r = bp->rect;
	if (( p.x >= r.low.x) && ( p.x <= r.high.x ) &&
		( p.y >= r.low.y) && ( p.y <= r.high.y) ) {
		
		offset = ((bp->width)*(bp->rect.high.y-p.y)) +
			( p.x )/PIXEL_SIZE - (bp->rect.low.x)/PIXEL_SIZE +
			gramstart;	
		return (offset);
	}
	else
	return(0L);
}
line (p1,p2)
point *p1,*p2;
{
/* Draw a line from point a to b using colour col */

	bitmap *bp;
	register short incr1, incr2, y_inc;
	unsigned register char bit_nr;
	register u_int *dest;
	short int e, i;
	short dx, dy;
	point p,a,b;
	char p_col=(char)lcol;
	u_int offset;

#if DBG > 0
	printf("line\n");
#endif

	a.x = p1->x;
	a.y = p1->y;
	b.x = p2->x;
	b.y = p2->y;
	bp = &display;
	dx = abs(b.x-a.x);
	dy = abs(b.y-a.y);
	p = ((a.x > b.x) ? b:a);
	y_inc = (p.y > min(a.y,b.y) ? bp->width : -(bp->width));
	if ((offset = getaddr(bp, p)) == 0L){
/*		error...  */
#if DBG > 0
		printf("Illegal address\n");
#endif
	return;
	}
	dest = bp->base;
	bit_nr = p.x % 8;

/* vertical line */
	if (dx == 0)
		for (i=0; i<=dy; i++){
		   dest[offset&(RAMSIZE-1)] = (dest[offset&(RAMSIZE-1)] & 
	           gmask[bit_nr]) | color[p_col][bit_nr];
			offset += y_inc;
		}
	else
/* horizontal line */
	if (dy == 0) {
		if (bit_nr > 0){
		   for (i=bit_nr; i<ALL; i++){
		       dest[offset&(RAMSIZE-1)] = (dest[offset&(RAMSIZE-1)] & 
	               gmask[i]) | color[p_col][i];
			dx = dx - 1;
			if (dx < 0) return;
		   }
		   offset++;
		}			
		incr1 = dx / 8;
		incr2 = dx % 8;
		for (i=0; i<incr1; i++){
		       dest[offset&(RAMSIZE-1)] = (dest[offset&(RAMSIZE-1)] & 
	               gmask[ALL]) | fullcol[p_col];
		       offset++;
		}
		for (i=0; i<=incr2; i++)
		       dest[offset&(RAMSIZE-1)] = (dest[offset&(RAMSIZE-1)] & 
	               gmask[i]) | color[p_col][i];
	}
	else
/* more horizontal */
	if (dx >= dy){
		e = 2*dy - dx;
		incr1 = 2*dy;
		incr2 = 2*(dy - dx);
		for (i=0; i<=dx; i++){

		       dest[offset&(RAMSIZE-1)] = (dest[offset&(RAMSIZE-1)] & 
	               gmask[bit_nr]) | color[p_col][bit_nr];

			if (e>0){
				offset += y_inc;
				e += incr2;
			}
			else e += incr1;
			if (bit_nr == 7){
				bit_nr = 0;
				offset++;
			}
			else bit_nr++;
		}
	}
	else
/* more vertical */
	{
		e = 2*dx - dy;
		incr1 = 2*dx;
		incr2 = 2*(dx - dy);
		for (i=0; i<=dy; i++){
		       dest[offset&(RAMSIZE-1)] = (dest[offset&(RAMSIZE-1)] & 
	               gmask[bit_nr]) | color[p_col][bit_nr];

			if (e>0){
				if (bit_nr == 7){
					bit_nr = 0;
					offset++;
				}
				else bit_nr++;
				e+=incr2;
			}
			else e += incr1;
			offset + = y_inc;
		}
	}
	return;
}

plott (p1)
point *p1;
{
	point p;
	unsigned register char bit_nr = p1->x % PIXEL_SIZE;
	register u_int *dest;
	char p_col=(char)mcol;
	u_int offset;
	bitmap *bp;

	p.x = p1->x;
	p.y = p1->y;

	bp = &display;
	dest = bp->base;
	offset = getaddr(bp,p);
	if (offset != 0L) 
		   dest[offset&(RAMSIZE-1)] = (dest[offset&(RAMSIZE-1)] & 
	           gmask[bit_nr]) | color[p_col][bit_nr];

	return;
}

paintchar(p1,c)
char c;
point *p1;
{
	register u_int  *dest;
	register chardes *cdp;
	register u_int  shift, offset;
	register u_int shift0;
	u_char *bmap;
	u_char tbmap, tbmap0;
	u_char *bend;
	int i;
	bitmap *bp;
	point p;
	char p_col=(char)tcol;
	u_char bit_nr = p1->x%PIXEL_SIZE;

	bp = &display;
	dest = bp->base;
	cdp = &finfo[c];
	p.x = p1->x;
	p.y = p1->y;
	if ( cdp->nbytes == 0 ) return;
	if (( offset = getaddr(bp,p) ) == 0L ) return;
	bmap = fbase + cdp->offset;
	bend = bmap + cdp->up + cdp->down;
	offset += (blp->up - cdp->up -Fh)*LINESIZE;

	if (cheight == 0){
	do {
		 tbmap = *bmap>>(8 - bit_nr);
		tbmap0 = *bmap<<(bit_nr);
		shift = tbmap0;
		shift = ( (shift<<8) | (shift<<16) | (shift<<24) );
		dest[offset&(RAMSIZE-1)] = (dest[offset&(RAMSIZE-1)] | 
	        shift ) & fullcol[p_col];
		if(bit_nr > 0){
			shift = tbmap;
			offset ++;
			shift = ((shift<<8) | (shift<<16) | (shift<<24));
			dest[offset&(RAMSIZE-1)] = (dest[offset&(RAMSIZE-1)] |
			shift) & fullcol[p_col];
			offset --;
		}



		offset += LINESIZE;
	}
	while ( ++bmap < bend );
	} else {
	offset += (blp->up - cdp->up -Fh)*LINESIZE;
	do {
		shift = shift0 = 0L;
		tbmap = *bmap;
		tbmap0 = tbmap>>4;
		for (i=0; i<4; i++){
			shift |= ( 3 * (tbmap & tmask[i] )) << i;
			shift0 |= ( 3 * (tbmap0 & tmask[i] )) << i;
		}

		shift = ( (shift<<8) | (shift<<16) | (shift<<24) );
		dest[offset&(RAMSIZE-1)] = (dest[offset&(RAMSIZE-1)] | 
	        shift ) & fullcol[p_col];

		offset++;

		shift0 = ( (shift0<<8) | (shift0<<16) | (shift0<<24) );
		dest[offset&(RAMSIZE-1)] = (dest[offset&(RAMSIZE-1)] | 
	        shift0 ) & fullcol[p_col];

		offset += (LINESIZE - 1);

		dest[offset&(RAMSIZE-1)] = (dest[offset&(RAMSIZE-1)] | 
	        shift ) & fullcol[p_col];

		offset++;

		dest[offset&(RAMSIZE-1)] = (dest[offset&(RAMSIZE-1)] | 
	        shift0 ) & fullcol[p_col];

		offset += (LINESIZE - 1);
	}
	while ( ++bmap < bend );
	}
}
putcharsize(i)
int i;
{
	cheight = i;
}
putpcindex(i)
int i;
{
	lcol = i;
}

putmcindex(i)
int i;
{
	mcol = i;
}
puttcindex(i)
int i;
{
	tcol = i;
}
putfcindex(i)
int i;
{
	fcol = i;
}
#define	MASK	0xffffff00
fill (ar)
rectangle *ar;
{
	bitmap *bp;
	register u_int *dest, offset, x, k;
	u_int	incrx,oldx;
	short y, ymin, ymax, i, j;
	point p;
	int inc,oldinc;
	u_char bit;
	char p_col=(char)fcol;

	bp = &display;
	p.x = ar->low.x;
	p.y = ymax = ar->high.y;
	ymin = ar->low.y;

	if ((offset = getaddr(bp, p)) == 0L) return;
	incrx = (ar->high.x - ar->low.x)/8 + 2;
	dest = bp->base;

	for (y=ymin; y<ymax+1; y++) {

/*						Get first x-coordinate	*/

		x = offset;
		inc = incrx;
	      	k = dest[x&(RAMSIZE-1)];
		while ((k&INF)==0){
	     		x++;
			inc--;
			if(inc<0) goto  end;
	   		k = dest[x&(RAMSIZE-1)];		
	        }
		while (k&INF){

	        	for (bit=0; bit<ALL; bit++){
	  			if (k&fmask[bit]) goto cont1;
cont1:			j = bit + 1;
			for (i=bit; i<ALL; i++)
				if(k&fmask[i]) j=i+1;
			for (i=bit; i<j; i++)
			dest[x&(RAMSIZE-1)] = (dest[x&(RAMSIZE)]&gmask[i] ) |
					color[p_col][i];
			bit = j;
			if (j > 7) {
				bit = 0;
				x++;
				inc--;
				if(inc<0) goto end;
			} 
		k = dest[x&(RAMSIZE-1)];
		}

/*						Fill until next x-coordinate*/
		oldx = x;
		oldinc = inc;
		while ((k&INF)==0){
			x++;
			inc--;
			if(inc<0) goto end;
			k = dest[x&(RAMSIZE-1)];
		}
		x = oldx;
		inc = oldinc;
		k = 0;

	   	while ((k&INF)==0){
		if (y > (ymax-1)) goto end;
		if (y < (ymin+1)) goto end; 
		if (bit>0){
			for (i=bit; i<ALL; i++){
			   dest[x&(RAMSIZE-1)] = 
			  (dest[x&(RAMSIZE-1)]) | color[p_col][i];
			}
			bit = 0;
	     		x++;
			inc--;
			if(inc<0) goto  end;
		} else {
		     dest[x&(RAMSIZE-1)] = (dest[x&(RAMSIZE-1)]&gmask[ALL]) 
						 | fullcol[p_col];
	     	     x++;
		     inc--;
		     if(inc<0) goto  end;
		}
		     k = dest[x&(RAMSIZE-1)];
		}

/*                                                Got next x-coord   */

		j=0;
	   	for (i=bit; i<ALL; i++)
	  		if (k&fmask[i])
                           j=i+1;
		for (i=bit; i<j; i++)
			   dest[x&(RAMSIZE-1)] = 
			  (dest[x&(RAMSIZE-1)]&gmask[i])  | color[p_col][i];
			
		if (j>7){
			x++;	
			inc--;
			if (inc<0) goto end;
		     	k = dest[x&(RAMSIZE-1)];

   			while ((k&INF) == ALLBITS){
		
		     dest[x&(RAMSIZE-1)] = (dest[x&(RAMSIZE-1)]&gmask[ALL]) 
						 | fullcol[p_col];
	     	        x++;
			inc--;
		        if(inc<0) goto  end;
		        k = dest[x&(RAMSIZE-1)];
	       		} 

			if ( k&INF > 0){
			for (i=0; i<ALL; i++)
				if (k&fmask[i])
                                       j=i+1;
			for (i=0; i<j; i++)
			   dest[x&(RAMSIZE-1)] = 
			  (dest[x&(RAMSIZE-1)] & gmask[i]) | color[p_col][i];
	    		}
		}	

end:	  	offset += LINESIZE;
	  }
}
rectang (ar)
rectangle *ar;
{

	register short incr1, incr2, y;
	register u_int *dest;
	register short int  i;
	bitmap *bp;
	point p;
	int dx;
	int xmax, ymin, ymax;
	unsigned char bit_nr ;
	char p_col=(char)fcol;
	u_int offset,x;

	bp = &display;
	p.x = ar->low.x;
	bit_nr = p.x%8;
	p.y = ymax = ar->high.y;
	ymin = ar->low.y;
	xmax = ar->high.x - ar->low.x;

	if ((offset = getaddr(bp, p)) == 0L) return;

	dest = bp->base;

	for (y=ymin; y< ymax+1; y++){

/* horizontal line */
		dx = xmax;
		x = offset;
		if (bit_nr > 0){
		   for (i=bit_nr; i<ALL; i++){
		       dest[x&(RAMSIZE-1)] = (dest[x&(RAMSIZE-1)] & 
	               gmask[i]) | color[p_col][i];
			dx = dx - 1;
			if (dx < 0) goto cont;
		   }
		   x++;
		}			
		incr1 = dx / 8;
		incr2 = dx % 8;

		for (i=0; i<incr1; i++){
		       dest[x&(RAMSIZE-1)] = (dest[x&(RAMSIZE-1)] & 
	               gmask[ALL]) | fullcol[p_col];
		       x++;
		}
		for (i=0; i<=incr2; i++)
		       dest[x&(RAMSIZE-1)] = (dest[x&(RAMSIZE-1)] & 
	               gmask[i]) | color[p_col][i];

cont:		offset += LINESIZE;
	}
}