|
|
DataMuseum.dkPresents historical artifacts from the history of: ICL Comet 32 |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about ICL Comet 32 Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - download
Length: 10253 (0x280d)
Types: TextFile
Notes: UNIX file
Names: »cgraph.c«
└─⟦26887b7e0⟧ Bits:30009717 Comet 32 harddisk image
└─⟦28c352965⟧ »/a« UNIX Filesystem
└─⟦this⟧ »usr/src/gks/comet/cgraph.c«
/*
* 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"
#include <sys/ioctl.h>
#include <stdio.h>
#ifndef FONT
#define FONT typerite_10
#endif
extern font_header FONT;
static int ttyfd;
init_vspy()
{
int i;
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()
{
register unsigned char arg;
#if DBG > 0
printf("initgraph\n");
#endif
ttyfd = open("/dev/bm",0);
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;
arg = 0;
if (ioctl(ttyfd,TIOCSGBUT,&arg) < 0){
perror("ioctl");
exit(1);
}
initcolour();
}
exitgraph()
{
register unsigned char arg;
#if DBG > 0
printf("exitgraph\n");
#endif
lcol = mcol = tcol = GREEN;
cheight = 0;
arg= GREENCURSOR | DISPLAY;
if (ioctl(ttyfd,TIOCSGBCO,&arg) < 0){
perror("ioctl");
exit(1);
}
}
cleardisplay()
{
register unsigned char arg;
arg = HIGHSPEED;
if (ioctl(ttyfd,TIOCSGBCO,&arg) < 0){
perror("ioctl");
exit(1);
}
clearsd(0,YSIZE*LINESIZE);
arg = DISPLAY;
if (ioctl(ttyfd,TIOCSGBCO,&arg) < 0){
perror("ioctl");
exit(1);
}
}
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+1; 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 (p_col == 8) return;
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){
if (p_col == 8){
e = 2*dy - dx;
incr1 = 2*dy;
incr2 = 2*(dy - dx);
dest[offset&(RAMSIZE-1)] = (dest[offset&(RAMSIZE-1)] &
gmask[bit_nr]) | color[p_col][bit_nr];
for (i=0; i<dx+1; i++){
if (e>0){
offset += y_inc;
e += incr2;
dest[offset&(RAMSIZE-1)] = (dest[offset&(RAMSIZE-1)] &
gmask[bit_nr]) | color[p_col][bit_nr];
}
else e += incr1;
if (bit_nr == 7){
bit_nr = 0;
offset++;
}
else bit_nr++;
}
return;
} else {
e = 2*dy - dx;
incr1 = 2*dy;
incr2 = 2*(dy - dx);
for (i=0; i<dx+1; 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+1; 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;
}
fill (ar,n,pa)
rectangle *ar;
int n;
point *pa;
{
bitmap *bp;
register u_int *dest,
offset,
x,
xmin,
y,dx,dy,
k;
u_int ymin,
ymax,
i,j,z,w,
xreal,
polyflag,vertexflag;
point p;
char p_col=(char)fcol;
bp = &display;
p.x = (ar->low.x/8)*8;
p.y = ymax = ar->high.y;
ymin = ar->low.y;
if (( xmin = getaddr(bp, p)) == 0L) return;
offset = (ar->high.x - ar->low.x)/8;
dest = bp->base;
for (y=ymax; y>ymin-1; y--) { /* Scan all x for each y */
xreal = p.x;
polyflag = OUTSIDE;
vertexflag = 0;
for (x=xmin; x<(xmin+offset+2); x++){
if (vertexflag > 0) vertexflag --;
k = dest[x&(RAMSIZE-1)];
if ((k&INF)==0){ /* if not scanline crosses
the polygons sides then: */
if (polyflag){ /* if inside a polygon, fill*/
dest[x&(RAMSIZE-1)] =
(dest[x&(RAMSIZE)] & gmask[ALL] ) |
fullcol[p_col];
}
xreal += 8;
} else { /* else if the scanline crosses
the poygons sides then: */
for (i=0; i<ALL; i++){
/* test if vertex-point*/
if ((k&fmask[i]) == 0) {
if (polyflag)
dest[x&(RAMSIZE-1)] =
(dest[x&(RAMSIZE-1)]&gmask[i]) |
color[p_col][i];
} else {
dest[x&(RAMSIZE-1)] =
(dest[x&(RAMSIZE-1)] & gmask[i]) |
color[p_col][i];
for (j=0; j<n; j++) {
dy = abs((pa+j)->y - y);
dx = abs((pa+j)->x - xreal);
if ((dy<2) && (dx<16)){
if (vertexflag == 0){
vertexflag = 2;
if (j==0) z = n-1;
else z = j-1;
if (j==(n-1)) w = 0;
else w = j+1;
if ((pa+z)->y <= y)
if ((pa+w)->y >= y) goto nlab;
if ((pa+z)->y >= y)
if ((pa+w)->y <= y) goto nlab;
/* We have found a max or min vertexpoint */
if (dy > 0) {
dx = abs((pa+z)->x - (pa+j)->x);
dy = abs((pa+z)->y - (pa+j)->y);
if (dx > 2*dy){
vertexflag = 0;
goto nlab;
}
dx = abs((pa+w)->x - (pa+j)->x);
dy = abs((pa+w)->y - (pa+j)->y);
if (dx > 2*dy){
vertexflag = 0;
goto nlab;
}
}
goto vlab;
nlab: if (polyflag)
polyflag = 0;
else
polyflag = 1;
}
} else continue;
goto vlab;
}
if (polyflag) polyflag = 0;
else polyflag = 1;
vlab: ;
}
xreal += 1;
}
}
}
xmin += LINESIZE;
}
}