[comp.sources.sun] v01i095: Rawgraph - a graphics library for the cg4b

mcgrew@dartagnan.rutgers.edu (Charles Mcgrew) (12/20/89)

Submitted-by: From: hhansen@solan.unit.no
Posting-number: Volume 1, Issue 95
Archive-name: fastgraph

Harald Nordgaard-Hansen ( TeXish : Harald Nordg{\aa}rd-Hansen)
<hhansen@solan.unit.no>

------- Cut here ---------------------------------- Cut here ---------------
#!/bin/sh
# shar:	Shell Archiver  (v1.22)
#
#	Run the following text with /bin/sh to create:
#	  Makefile
#	  README
#	  overview
#	  rawgraph.c
#	  rawgraph.h
#	  sprites.s
#
sed 's/^X//' << 'SHAR_EOF' > Makefile &&
X####################################################################
X#
X# simple makefile for libraw.a, the RAWGRAPH library.
X#
X# Copyright (c) 1989 Upon Software / PVV
X#
X####################################################################
X# CC = gcc
XCC = cc
XAR = ar rc
XAS = as
XRM = rm -f
XRANLIB = ranlib
X
XLOPTS = -O
X# COPTS = -Wall -g
XCOPTS = -O
XLIBS = -lc
X
X# Define SYSTEM to either SUNOS3 or SUNOS4
X# SYSTEM = SUNOS3
XSYSTEM = SUNOS4
X
XJUNKFILES = *.o gmon.out mon.out core *~ #*#
X
XRAWSRC = rawgraph.c rawgraph.h sprites.s
XRAWOBJS = rawgraph.o sprites.o
X
Xall: libraw.a
X
X.c.o:
X	$(CC) $(COPTS) -D$(SYSTEM) -c $*.c
X
X.s.o:
X	$(AS) -o $*.o $*.s
X
Xlibraw.a: $(RAWOBJS)
X	$(AR) $@ $(RAWOBJS)
X	$(RANLIB) $@
X
Xclean: 
X	$(RM) $(JUNKFILES)
X
Xcleanx:
X	$(RM) libraw.a $(JUNKFILES)
X
X# Dependencies
Xrawgraph.o:	rawgraph.h rawgraph.c
X
X#	$(CC) $(COPTS) -D$(SYSTEM) -c rawgraph.c 
X#	$(AS) -o sprites.o sprites.s
SHAR_EOF
chmod 0644 Makefile || echo "restore of Makefile fails"
sed 's/^X//' << 'SHAR_EOF' > README &&
X			 RAWGRAPH ver. 1.0 beta
X			Release date 14.nov. 1989
X			  No previous releases.
X
XFiles in this distribution:
X	rawgraph.h - Header file for rawgraph (include in your programs)
X		     Macros are here.
X	rawgraph.c - The rawgraph functions. All the c functions lies here.
X	sprites.s  - The software sprite assembly routines.
X	Makefile   - A simple makefile to create libraw.a, if you want to
X		     use it as a library.
X	overview   - A small overview of the macros and functions in rawgraph.
X		     This is all the documentation I've had time for. Something
X		     better might come later.
X	README     - This file. Some general info, and documemtation.
X		     Some day I hope to make some man-pages and other
X		     info, but not just now.
X
XPurpose:
X
XRawgraph is a small and fast graphics library for SUN machines with
Xthe cg4b frame buffer. It runs under SunOS4.0, and hopefully also under
XSunOS3.X, although this hasn't been tested too much. It is still under
Xdevelopment, and all comments and enchancements would be helpful.
X
XAnyway, this is just a simple piece of code, and can surely be improved.
XI'd appreciate it if you would let me know if you make any improvements,
Xand I'll try to mail later versions if I get the time. (Life as a student
Xis a little busy these days.. :-)
X
X                                ---
X
XCopyright (c) 1989 Upon Software / PVV
X
XPermission to use, copy, modify, and distribute this software and its
Xdocumentation for any purpose and without fee is hereby granted,
Xprovided that the above copyright notice appear in all copies and that
Xboth that copyright notice and this permission notice appear in
Xsupporting documentation.
X
XThis file is provided AS IS with no warranties of any kind.  The author
Xshall have no liability with respect to the infringement of copyrights,
Xtrade secrets or any patents by this file or any part thereof.  In no
Xevent will the author be liable for any lost revenue or profits or
Xother special, indirect and consequential damages.
X
XComments and additions should be sent to the author:
X
X	<hhansen@solan.unit.no>,
X	<hhansen@idt.unit.no> or
X	<nordgard@norunit.bitnet>
X
X	Harald 'Faramir' Nordgard-Hansen,
X	ProgramVareVerkstedet,
X	Room 246/1, SB2,
X	N-7034 TRONDHEIM - NTH,
X	NORWAY
X
SHAR_EOF
chmod 0644 README || echo "restore of README fails"
sed 's/^X//' << 'SHAR_EOF' > overview &&
X			RAWGRAPH ver. 1.0 beta
X		Copyright (c) 1989 Upon Software / PVV
X	     Simple Overview of the functions in RAWGRAPH.
X
XRawgraph is a small and fast graphics library for SUN machines with
Xthe cg4b frame buffer. It runs under SunOS4.0, and hopefully also under
XSunOS3.X, although this hasn't been tested too much. It is still under
Xdevelopment, and all comments and enchancements would be helpful.
X
XRawgraph is currently made up of three different kinds of "functions".
XThe simple basics is implemented as macros, for speed. Then some more complex 
Xroutines, like initalisation and line drawing routines, are c functions. And
Xfinally there is some software sprite routines, implemented in assembly. The
Xtwo latter is put togetger into libraw.a
X
XThe macros are these:
X
XPlot(x,y)	- Set (black) a pixel on the overlay plane at coords (x,y).
XUnplot(x,y)	- Unset (white) a pixel on the overlay plane at coords (x,y).
XPixel(x,y)	- Returns the value of the overlay plane at coords (x,y).
XEnable(x,y)	- Turn on the overlay plane at coords (x,y).
XDisable(x,y)	- Turn off the overlay plane (and show the color planes) at
X		  coords (x,y).
XEnabled(x,y)	- Returns the value of the enable plane at coords (x,y).
XCplot(x,y,c)	- Set a pixel with color c at coords (x,y) on the color planes.
XCpixel(x,y)	- Returns the value of the color planes at coords (x,y).
X
XCls()		- Set all planes to zero.
XBwCls()		- Set the overlay plane to zero.
XEnblCol()	- Set the enable plane to zero, showing the color planes.
XEnblBw()	- Set the enable plane to 0xff, showing the overlay plane.
XCCls()		- Set the color planes to zero.
X
XThe c functions are these:
X
XInitRawGraph()	- This function must be called before any part of rawgraph is
X		  used. It maps the frame buffer to viritual memory, and sets
X		  up all the global variables.
X
XExitRawGraph()	- This function may be called to close down the rawgraph
X		  system. All it does as of now, is to close the file
X		  descriptor associated with the frame buffer.
X
XCcircle(x,y,r,c) -Draw a circle on the color planes with centre in x,y,
X		  radius r and color c.
X
XCircle(x,y,r)	- Draw a circle on the overlay plane with centre in x,y and
X		  radius r.
X
XCline(x1,y1,x2,y2,c) - Draw a line from (x1,y1) to (x2,y2) on the color
X                       planes, with color c.
X
XLine(x1,y1,x2,y2)    - Draw a line from (x1,y1) to (x2,y2) on the overlay
X                       plane.
X
XPutColors(indent,count,red,green,blue) - Set the palette registers from indent
X		  to indent+count-1 to rgb values from arrays red, green and
X		  blue. See also pixrect's pr_putcolormap.
X
XGetColors(indent,count,red,green,blue) - Like PutColors, but returns the
X		  current values in red, green and blue arrays.
X
XWe also have (color only) soft-sprites, written by Tegge in assembly.
XThe three routines for this are:
X
XPutVarSprite(sprite_data, sprite_mask, x, y, width_int, height) -
X    Put a sprite at position x,y. height is the height of the sprite
X    (in pixels) and width_int is the width of the sprite (in number of
X    32-bit words or 4-pixels). sprite_data is the data to be ored into
X    the screen, and sprite_mask is the data used to test for hitting
X    something. No data is removed from the screen in this process.
X    PutVarSprite returns non-zero if the sprite hit something. In this
X    case, the colors may be wrong on some points.
X
XKillVarSprite(sprite_mask, x, y, width_int, height) -
X    The data in sprite_mask is complemented and anded into the screen
X    at position x,y. This is used for removing a sprite from the screen.
X
XMoveVarSprite(sprite_data, sprite_mask, orig_x, orig_y, dest_x,
X	      dest_y, width_int, height) -
X    This is equivalent with calling KillVarSprite with orig_x and
X    orig_y, and then calling PutVarSprite with dest_x and dest_y, but
X    some optimizing is performed on the way. This is to minimize the
X    "flickering" when moving/animating sprites. MoveVarSprite returns
X    the same as PutVarSprite.
X
XBe aware that the Rawgraph system do not perform clipping. Writing off the
Xscreen will give strange results, or result in segmentation violation if
Xyou move out of the frame buffer. (The different parts of the screen lie
Xsequentially in memory.)
X
XHave fun.
SHAR_EOF
chmod 0644 overview || echo "restore of overview fails"
sed 's/^X//' << 'SHAR_EOF' > rawgraph.c &&
X/**************************************************************\
X*                                                              *
X*     rawgraph.c - raw memory screen library for Sun 3/60's    *
X*                                                              *
X*           Copyright (c) 1989 Upon Software / PVV             *
X*         Written by Harald 'Faramir' Nordgard-Hansen,         *
X*                  <hhansen@solan.unit.no>.                    *
X*             Based on algorithms and code from                *
X*         Roar Andre Lauritsen <roarl@solan.unit.no>,          *
X*             Arne H. Juul <juul@solan.unit.no>,               *
X*             Stig Hemmer <stig@solan.unit.no>,                *
X*                       and above all                          *
X*           Tor 'Tegge' Egge <tegge@solan.unit.no>             *
X*       who discovered how to do it in the first place.        *
X\**************************************************************/
X
X#define RAWLIB
X#include "rawgraph.h"
X
Xbyte *RAWGRAPH_MaskMap,*RAWGRAPH_ColorMap,*RAWGRAPH_BwMap,*RAWGRAPH_Tabell;
Xint RAWGRAPH_BwLinjeAddr[RAWGRAPH_MAXY],RAWGRAPH_CLinjeAddr[RAWGRAPH_MAXY];
Xbyte *RAWGRAPH_screenlefts[RAWGRAPH_MAXY];
X
Xextern void ioctl();
X
X#ifdef SUNOS4
Xextern char *mmap();
X#else
Xextern void mmap();
Xextern byte valloc();
X#endif
X#define MAP_SHARED 1
X
Xstatic int filedesc;
X
X#ifdef ANSI
Xvoid InitRawGraph(void) 
X#else /* ANSI */
Xvoid InitRawGraph()
X#endif /* ANSI */
X{
X  static initialized=0;
X  int line;
X  void exit(), printf() ;
X  int open() ;
X
X  if (initialized) return;
X  initialized=1;
X
X  if ((filedesc=open("/dev/cgfour0",2))<0)
X    {
X      printf("rawgraph: /dev/cgfour0 not available\n"); 
X      exit(4);
X    }
X
X#ifdef SUNOS4
X  RAWGRAPH_Tabell=(byte *) mmap((char *)0,RAWGRAPH_FRAMESIZE,3,
X				MAP_SHARED,filedesc,(long)0);
X#else /* SUNOS4 */
X#  ifdef SUNOS3
X     RAWGRAPH_Tabell=(byte *) valloc(RAWGRAPH_FRAMESIZE);
X     mmap(RAWGRAPH_Tabell,RAWGRAPH_FRAMESIZE,3,MAP_SHARED,filedesc,(long)0);
X#  else /* SUNOS3 */
X     /* This is a bit rotten, but it's the only way to make cpp give a */
X     /* sensible error message... */
X#    include "rawgraph: * Please define either SUNOS3 or SUNOS4 *"
X#  endif /* SUNOS3 */
X#endif /* SUNOS4 */
X
X  RAWGRAPH_ColorMap=&RAWGRAPH_Tabell[262144];
X  RAWGRAPH_MaskMap=&RAWGRAPH_Tabell[131072];
X  RAWGRAPH_BwMap=RAWGRAPH_Tabell;
X
X  for (line=0; line<RAWGRAPH_MAXY; line++)
X    {
X      RAWGRAPH_BwLinjeAddr[line]=((line<<3)+line)<<4;
X      RAWGRAPH_CLinjeAddr[line]=((line<<3)+line)<<7;
X      RAWGRAPH_screenlefts[line]=RAWGRAPH_ColorMap+RAWGRAPH_CLinjeAddr[line];
X    }
X}
X
X#ifdef ANSI
Xvoid ExitRawGraph(void)
X#else
Xvoid ExitRawGraph()
X#endif
X{
X  void close();
X
X  close (filedesc);
X}
X
X#define RAWGRAPH_Cplot4(d1,d2,c) {Cplot(x+d1,y+d2,c); Cplot(x-d1,y-d2,c); Cplot(x+d2,y-d1,c); Cplot(x-d2,y+d1,c);}
X#define RAWGRAPH_BWplot4(d1,d2) {Plot(x+d1,y+d2); Plot(x-d1,y-d2); Plot(x+d2,y-d1); Plot(x-d2,y+d1);}
X
X#ifdef ANSI
Xvoid Ccircle(int x, int y, int r, int c)
X#else
Xvoid Ccircle(x,y,r,c)
X     int x,y,r,c;
X#endif
X{
X  int d1,d2,f;
X  
X  if(r<1)
X    Cplot(x,y,c) ;
X  else
X    {
X      d1=0;d2=f=r;
X      while (d1<d2)
X	{
X	  RAWGRAPH_Cplot4(d1,d2,c);
X	  f-=(d1++)*2+1;
X          if (d1>=d2) break;
X	  if (f<0) f+=(--d2)*2+1;
X	  RAWGRAPH_Cplot4(d2,d1,c);
X	}
X    }
X}
X
X#ifdef ANSI
Xvoid Circle(int x, int y, int r)
X#else
Xvoid Circle(x,y,r)
X     int x,y,r;
X#endif
X{
X  int d1,d2,f;
X  
X  if(r<1)
X    Plot(x,y) ;
X  else
X    {
X      d1=0;d2=f=r;
X      while (d1<d2)
X	{
X	  RAWGRAPH_BWplot4(d1,d2);
X	  f-=(d1++)*2+1;
X          if (d1>=d2) break;
X	  if (f<0) f+=(--d2)*2+1;
X	  RAWGRAPH_BWplot4(d2,d1);
X	}
X    }
X}
X
X#ifdef ANSI
Xvoid Cline(int x1,int y1,int x2,int y2,int c)
X#else
Xvoid Cline(x1,y1,x2,y2,c)
X     int x1,x2,y1,y2,c;
X#endif
X{
X  int dx,dy,x,y,x_end,p,const1,const2;
X
X  if (((x1-x2)*(y1-y2))>0) { 
X    dx = (x1>x2) ? (x1-x2) : (x2-x1);
X    dy = (y1>y2) ? (y1-y2) : (y2-y1);
X    if (dx>dy) { 
X      p = (dy << 1) -dx ;
X      const1 = dy << 1;
X      const2 = (dy - dx) << 1;
X      
X      if(x1>x2) {
X	x = x2;
X	y = y2;
X	x_end = x1;
X      } else {
X	x = x1;
X	y = y1;
X	x_end = x2;
X      }
X      Cplot(x,y,c);
X      while ( x < x_end ) {
X	x++;
X	if (p<0) p += const1;
X	else {
X	  y++;
X	  p += const2;
X	}
X	Cplot(x,y,c);
X      }
X    } else {
X      p = (dx << 1) -dy ;
X      const1 = dx << 1;
X      const2 = (dx - dy) << 1;
X      
X      if(y1>y2) {
X	x = y2;
X	y = x2;
X	x_end = y1;
X      } else {
X	x = y1;
X	y = x1;
X	x_end = y2;
X      }
X      Cplot(y,x,c);
X      while ( x < x_end ) {
X	x++;
X	if (p<0) p += const1;
X	else {
X	  y++;
X	  p += const2;
X	}
X	Cplot(y,x,c);
X      }
X    }
X  } else {
X    dx = (x1>x2) ? (x1-x2) : (x2-x1);
X    dy = (y1>y2) ? (y1-y2) : (y2-y1);
X    if (dx>dy) { 
X      p = (dy << 1) -dx ;
X      const1 = dy << 1;
X      const2 = (dy - dx) << 1;
X      
X      if(x1>x2) {
X	x = x2;
X	y = y2;
X	x_end = x1;
X      } else {
X	x = x1;
X	y = y1;
X	x_end = x2;
X      }
X      Cplot(x,y,c);
X      while ( x < x_end ) {
X	x++;
X	if (p<0) p += const1;
X	else {
X	  y--;
X	  p += const2;
X	}
X	Cplot(x,y,c);
X      }
X    } else {
X      p = (dx << 1) -dy ;
X      const1 = dx << 1;
X      const2 = (dx - dy) << 1;
X      
X      if(y1>y2) {
X	x = y2;
X	y = x2;
X	x_end = y1;
X      } else {
X	x = y1;
X	y = x1;
X	x_end = y2;
X      }
X      Cplot(y,x,c);
X      while ( x < x_end ) {
X	x++;
X	if (p<0) p += const1;
X	else {
X	  y--;
X	  p += const2;
X	}
X	Cplot(y,x,c);
X      }
X    }
X  }
X}
X
X
X#ifdef ANSI
Xvoid Line(int x1,int y1,int x2,int y2)
X#else
Xvoid Line(x1,y1,x2,y2)
X     int x1,x2,y1,y2;
X#endif
X{
X  int dx,dy,x,y,x_end,p,const1,const2;
X
X  if (((x1-x2)*(y1-y2))>0) { 
X    dx = (x1>x2) ? (x1-x2) : (x2-x1);
X    dy = (y1>y2) ? (y1-y2) : (y2-y1);
X    if (dx>dy) { 
X      p = (dy << 1) -dx ;
X      const1 = dy << 1;
X      const2 = (dy - dx) << 1;
X      
X      if(x1>x2) {
X	x = x2;
X	y = y2;
X	x_end = x1;
X      } else {
X	x = x1;
X	y = y1;
X	x_end = x2;
X      }
X      Plot(x,y);
X      while ( x < x_end ) {
X	x++;
X	if (p<0) p += const1;
X	else {
X	  y++;
X	  p += const2;
X	}
X	Plot(x,y);
X      }
X    } else {
X      p = (dx << 1) -dy ;
X      const1 = dx << 1;
X      const2 = (dx - dy) << 1;
X      
X      if(y1>y2) {
X	x = y2;
X	y = x2;
X	x_end = y1;
X      } else {
X	x = y1;
X	y = x1;
X	x_end = y2;
X      }
X      Plot(y,x);
X      while ( x < x_end ) {
X	x++;
X	if (p<0) p += const1;
X	else {
X	  y++;
X	  p += const2;
X	}
X	Plot(y,x);
X      }
X    }
X  } else {
X    dx = (x1>x2) ? (x1-x2) : (x2-x1);
X    dy = (y1>y2) ? (y1-y2) : (y2-y1);
X    if (dx>dy) { 
X      p = (dy << 1) -dx ;
X      const1 = dy << 1;
X      const2 = (dy - dx) << 1;
X      
X      if(x1>x2) {
X	x = x2;
X	y = y2;
X	x_end = x1;
X      } else {
X	x = x1;
X	y = y1;
X	x_end = x2;
X      }
X      Plot(x,y);
X      while ( x < x_end ) {
X	x++;
X	if (p<0) p += const1;
X	else {
X	  y--;
X	  p += const2;
X	}
X	Plot(x,y);
X      }
X    } else {
X      p = (dx << 1) -dy ;
X      const1 = dx << 1;
X      const2 = (dx - dy) << 1;
X      
X      if(y1>y2) {
X	x = y2;
X	y = x2;
X	x_end = y1;
X      } else {
X	x = y1;
X	y = x1;
X	x_end = y2;
X      }
X      Plot(y,x);
X      while ( x < x_end ) {
X	x++;
X	if (p<0) p += const1;
X	else {
X	  y--;
X	  p += const2;
X	}
X	Plot(y,x);
X      }
X    }
X  }
X}
X
X#define MAGIC_PUT 0x80144603
X#define MAGIC_GET 0x80144604
X
Xtypedef struct _colorstruct { 
X  int ind;
X  int cnt;
X  byte *red;
X  byte *grn;
X  byte *blu;
X} Colorstruct;
X
X#ifdef ANSI
Xvoid PutColors(int indent, int count, byte *red, byte *green, byte *blue)
X#else
Xvoid PutColors(indent,count,red,green,blue)
X     int indent,count;
X     byte *red,*green,*blue;
X#endif
X{
X  Colorstruct c;
X
X  c.ind = indent;
X  c.cnt = count;
X  c.red = red;
X  c.grn = green;
X  c.blu = blue;
X
X  ioctl(filedesc,MAGIC_PUT,&c);
X}
X
X#ifdef ANSI
Xvoid GetColors(int indent, int count, byte *red, byte *green, byte *blue)
X#else
Xvoid GetColors(indent,count,red,green,blue)
X     int indent,count;
X     byte *red,*green,*blue;
X#endif
X{
X  Colorstruct c;
X
X  c.ind = indent;
X  c.cnt = count;
X  c.red = red;
X  c.grn = green;
X  c.blu = blue;
X
X  ioctl(filedesc,MAGIC_GET,&c);
X}
SHAR_EOF
chmod 0644 rawgraph.c || echo "restore of rawgraph.c fails"
sed 's/^X//' << 'SHAR_EOF' > rawgraph.h &&
X/**************************************************************\
X*                                                              *
X*      rawgraph.h - raw memory screen utils for Sun 3/60's     *
X*                                                              *
X*           Copyright (c) 1989 Upon Software / PVV             *
X*         Written by Harald 'Faramir' Nordgard-Hansen,         *
X*                  <hhansen@solan.unit.no>.                    *
X*             Based on algorithms and code from                *
X*         Roar Andre Lauritsen <roarl@solan.unit.no>,          *
X*             Arne H. Juul <juul@solan.unit.no>,               *
X*             Stig Hemmer <stig@solan.unit.no>,                *
X*                       and above all                          *
X*           Tor 'Tegge' Egge <tegge@solan.unit.no>             *
X*       who discovered how to do it in the first place.        *
X\**************************************************************/
X
X#ifndef RAWGRAPH_DEFINED
X#define RAWGRAPH_DEFINED
X
X#ifndef byte
X#define byte unsigned char
X#endif
X
Xextern char *memset();
X
X/* First we define the internal constants. */
X#define RAWGRAPH_FRAMESIZE 1302528
X#define RAWGRAPH_COLORSIZE 1036800
X#define RAWGRAPH_BWSIZE    129600
X#define RAWGRAPH_MASKSIZE  129600
X
X#define RAWGRAPH_MAXX 1152
X#define RAWGRAPH_MAXY 900
X
X#define RAWGRAPH_PITCH 1152
X#define RAWGRAPH_BWPITCH 144
X
X/* Then these two, just for convinience. */
X#define MAXX RAWGRAPH_MAXX
X#define MAXY RAWGRAPH_MAXY
X
X/* These are for calculating the offset into the frame buffers. */
X#define RAWGRAPH_CAddr(x,y)  ((x)+RAWGRAPH_CLinjeAddr[y])
X#define RAWGRAPH_BwAddr(x,y) (((x)>>3)+RAWGRAPH_BwLinjeAddr[y])
X
X/* And at last the simple plot/unplot and cls macros. */
X#define Plot(x,y)   (*(RAWGRAPH_BwMap +RAWGRAPH_BwAddr(x,y))|=128>>((x)&7))
X#define Unplot(x,y) (*(RAWGRAPH_BwMap +RAWGRAPH_BwAddr(x,y))&=~(128>>((x)&7)))
X#define Pixel(x,y) ((*(RAWGRAPH_BwMap +RAWGRAPH_BwAddr(x,y))&(128>>((x)&7)))>0)
X#define Enable(x,y)  (*(RAWGRAPH_MaskMap+RAWGRAPH_BwAddr(x,y))|=128>>((x)&7))
X#define Disable(x,y) \
X  (*(RAWGRAPH_MaskMap+RAWGRAPH_BwAddr(x,y))&=~(128>>((x)&7)))
X#define Enabled(x,y) \
X  ((*(RAWGRAPH_MaskMap+RAWGRAPH_BwAddr(x,y))&(128>>((x)&7)))>0)
X#define Cplot(x,y,color) (*(RAWGRAPH_ColorMap+RAWGRAPH_CAddr(x,y))=color)
X#define Cpixel(x,y)      (*(RAWGRAPH_ColorMap+RAWGRAPH_CAddr(x,y)))
X#define Cls()     memset(RAWGRAPH_Tabell  ,0   ,RAWGRAPH_FRAMESIZE)
X#define BwCls()   memset(RAWGRAPH_BwMap   ,0   ,RAWGRAPH_BWSIZE)
X#define EnblCol() memset(RAWGRAPH_MaskMap ,0   ,RAWGRAPH_MASKSIZE)
X#define EnblBw()  memset(RAWGRAPH_MaskMap ,0xff,RAWGRAPH_MASKSIZE)
X#define CCls()    memset(RAWGRAPH_ColorMap,0   ,RAWGRAPH_COLORSIZE)
X
X/* Then the global variables needed. */
Xextern byte *RAWGRAPH_MaskMap,*RAWGRAPH_ColorMap,*RAWGRAPH_BwMap,
X  *RAWGRAPH_Tabell;
Xextern int RAWGRAPH_BwLinjeAddr[], RAWGRAPH_CLinjeAddr[];
X
X/* And finally the various functions in the library. */
X/* first the ansi versions.. */
X#ifdef ANSI
Xvoid InitRawGraph(void);
Xvoid ExitRawGraph(void);
Xvoid CCircle(int x, int y, int r, int c);
Xvoid Circle(int x, int y, int r);
Xvoid Cline(int x1,int y1,int x2,int y2,int c);
Xvoid Line(int x1,int y1,int x2,int y2);
Xvoid PutColors(int indent, int count, byte *red, byte *green, byte *blue);
Xvoid GetColors(int indent, int count, byte *red, byte *green, byte *blue);
Xint PutVarSprite(byte *sprite_data, byte *sprite_mask, int x, int y,
X		 int width_int, int height);
Xint MoveVarSprite(byte *sprite_data, byte *sprite_mask, int orig_x, int orig_y,
X		  int dest_x, int dest_y, int width_int, int height);
Xvoid KillVarSprite(byte *sprite_mask, int x, int y, int width_int, int height);
X
X/* and then the old K&R versions.. */
X#else /* ansi */
Xvoid InitRawGraph();
Xvoid ExitRawGraph();
Xvoid Ccircle();
Xvoid Circle();
Xvoid Cline();
Xvoid Line();
Xvoid PutColors();
Xvoid GetColors();
Xint PutVarSprite();
Xint MoveVarSprite();
Xvoid KillVarSprite();
X#endif /* ansi */
X
X#endif /*RAWGRAPH_DEFINED*/
SHAR_EOF
chmod 0644 rawgraph.h || echo "restore of rawgraph.h fails"
sed 's/^X//' << 'SHAR_EOF' > sprites.s &&
X# Copyright (c) 1989 Upon Software / PVV / Tegge
X.data
X.text
X.proc
X.globl _PutVarSprite
X.globl _KillVarSprite
X.globl _MoveVarSprite
X
X_PutVarSprite:
X	regmask1o=0x04fc		| A7=MSB, D0=LSB
X	moveml #0x3f20,sp@-		| D0=MSB, A7=LSB, D2/D3/D4/D5/D6/A2
X	parms1=4+28
X	movl	a7@(parms1+0),a0	| Upper left corner of sprite
X	movl	a7@(parms1+4),a1	| Upper left corner of sprite mask
X	movl	a7@(parms1+12),d0	| y position
X	asll	#2,d0
X	lea	_RAWGRAPH_screenlefts,a2
X	movl	a2@(d0),a2
X	addl	a7@(parms1+8),a2	| x position
X	moveq	#0,d0			| No collision
X	moveq	#4,d5
X	movel	a7@(parms1+16),d7
X	movel	#288,d6			| integers/rasterline
X	subl	d7,d6			| 
X	lsll	#2,d6			| Convert to bytes
X	movel	a7@(parms1+20),d2	| Number of lines 
X	subql	#1,d2
X	subql	#1,d7	
Xputsprite2:	
X	movel	d7,d1			| (columns / 4) -1
Xputsprite3:
X	movl	a1@+,d3			| Get mask value
X	beq	putsprite5		| Nothing here ?
X	movl	a2@,d4			| Get screen value 
X	andl	d4,d3			| And with mask
X	bne	putsprite4		| No collition ?
X	movl	a0@+,d3
X	orl	d3,d4			| generate new screen value
X	movl	d4,a2@+			| and put it to screen
X
X	dbf	d1,putsprite3		| More on same line ?
X	addl	d6,a2			| Go to next line
X	dbf	d2,putsprite2		| and work more
X	moveml 	sp@+,#regmask1o	
X	rts
Xputsprite4:
X	movel	d5,d0			| Mark collition
X	movl	a0@+,d3
X	orl	d3,d4			| generate new screen value
X	movl	d4,a2@+			| and put it to screen
X
X	dbf	d1,putsprite3		| More on same line ?
X	addl	d6,a2			| Go to next line
X	dbf	d2,putsprite2		| and work more
X	moveml 	sp@+,#regmask1o	
X	rts
X
Xputsprite5:
X	addl	d5,a2
X	addl	d5,a0
X	dbf	d1,putsprite3		| More on same line ?
X	addl	d6,a2			| Go to next line
X	dbf	d2,putsprite2		| and work more
X	moveml 	sp@+,#regmask1o	
X	rts
X
X_KillVarSprite:
X	regmask2o=0x00fc		| a7=MSB,D0=LSB
X	moveml	#0x3f00,sp@-		| D0=MSB,A7=LSB  D2/D3/D4/D5/D6/D7
X	parm2=4+24
X	movel	a7@(parm2+0),a0		| Sprite data 
X	movel	a7@(parm2+8),d0		| Screen y position
X	asll	#2,d0
X	lea	_RAWGRAPH_screenlefts,a1
X	movel	a1@(d0),a1
X	addl	a7@(parm2+4),a1
X	movel	a7@(parm2+16),d0
X	moveq	#-1,d4
X	movel	a7@(parm2+12),d7
X	movel	#288,d5			| integers/rasterline
X	subl	d7,d5			| subtract sprite width 
X	lsll	#2,d5			| Convert to bytes
X	moveq	#4,d6			
X	addl	d4,d7
X	addl	d4,d0
Xkillsprite2:
X	movel	d7,d1
Xkillsprite3:
X	movel	a0@+,d2
X	beq	killsprite4
X	eorl	d4,d2
X	movel	a1@,d3
X	andl	d3,d2
X	movel	d2,a1@+
X	dbf	d1,killsprite3
X	addl	d5,a1
X	dbf	d0,killsprite2
X	moveml	sp@+,#regmask2o		
X	rts
Xkillsprite4:
X	addl	d6,a1
X	dbf	d1,killsprite3
X	addl	d5,a1
X	dbf	d0,killsprite2
X	moveml	sp@+,#regmask2o
X	rts
X
X_MoveVarSprite:
X	regmask3o=0x7cfc		| A7=MSB,D0=LSB
X	moveml	#0x3f3e,sp@-		| D0=MSB,A7=LSB
X	parms3=4+44
X	moveq	#0,d0
X	movel	a7@(parms3+28),d1	| Lines in sprite
X	movel	a7@(parms3+24),a6	| 
X	moveq	#-1,d7
X	addl	d7,d1
X	movel	#4,a5
X	movel	a7@(parms3+0),a0	| Sprite data
X	movel	a7@(parms3+4),a1	| Sprite mask
X	movel	a7@(parms3+12),d2	| Screen Old y
X	lea	_RAWGRAPH_screenlefts,a3		| 
X	asll	#2,d2
X	movel	a3@(d2),a2		
X	addl	a7@(parms3+8),a2	| Screen old x
X	movel	a7@(parms3+20),d2	| Screen new y
X	asll	#2,d2
X	movel	a3@(d2),a3
X	addl	a7@(parms3+16),a3	| screen new x
X	movel	a7@(parms3+8),d2	| Old x
X	cmpl	a7@(parms3+16),d2	| New x
X	bcs	moveright
X| moveleft:
X	movel	a7@(parms3+12),d2	| Old y
X	cmpl	a7@(parms3+20),d2	| New y
X	bcs	moveleftdown
X| moveleftup:
X	movel	#288,d6
X	subl	a6,d6
X	lsll	#2,d6
X	movel	#0,a4
X	addl	d7,a6
Xmoveleftup2:
X	movel	a6,d2
Xmoveleftup3:
X	movel	a1@+,d3			| sprite mask	
X	beq	moveleftup8
X	movel	a0@,d4			| sprite data
X	eorl	d7,d4			| NOT spritedata
X	movel	a2@,d5			| From Screen pos
X	andl	d4,d5			|
X	movel	d5,a2@+			| Removed part
X	movel	a3@,d4			| To Screen pos
X	andl	d4,d3			| Collition ?
X	bne	moveleftColl		| 
Xmoveleftup4:
X	movel	a0@+,d3	
X	orl	d3,d4
X	movel	d4,a3@+
X	dbf	d2,moveleftup3
X	addl	d6,a3
X	addl	d6,a2
X	addl	a4,a0
X	addl	a4,a1
X	dbf	d1,moveleftup2
X	moveml	sp@+,#regmask3o
X	rts
XmoveleftColl:
X	moveq	#1,d0
X	movel	a0@+,d3	
X	orl	d3,d4
X	movel	d4,a3@+
X	dbf	d2,moveleftup3
X	addl	d6,a3
X	addl	d6,a2
X	addl	a4,a0
X	addl	a4,a1
X	dbf	d1,moveleftup2
X	moveml	sp@+,#regmask3o
X	rts
Xmoveleftup8:
X	addl	a5,a0
X	addl	a5,a2
X	addl	a5,a3
X	dbf	d2,moveleftup3
X	addl	d6,a3
X	addl	d6,a2
X	addl	a4,a0
X	addl	a4,a1
X	dbf	d1,moveleftup2
X	moveml	sp@+,#regmask3o
X	rts
X	
Xmoveleftdown:
X	
X	movel	d1,d6		| lines-1
X	lsll	#2,d6		| 
X	lea	_RAWGRAPH_screenlefts,a4
X	movel	a4@(d6),d6	
X	subl	a4@,d6 		| 
X	addl	d6,a2
X	addl	d6,a3
X	movel	a6,d6
X	mulsl	d1,d6
X	lsll	#2,d6
X	addl	d6,a0
X	addl	d6,a1
X	moveq	#0,d6
X	subl	a6,d6
X	lsll	#3,d6
X	movel	d6,a4
X	movel	#-288,d6
X	subl	a6,d6
X	lsll	#2,d6
X	addl	d7,a6
X	jmp	moveleftup2
Xmoveright:
X	movel	a7@(parms3+12),d2	| Old y
X	cmpl	a7@(parms3+20),d2	| New y
X	bcs	moverightdown
X| moverightup:
X	movel	a6,d6
X	lsll	#2,d6
X	addl	d6,a0
X	addl	d6,a1
X	addl	d6,a2
X	addl	d6,a3
X	movel	a6,d6
X	lsll	#3,d6
X	movel	d6,a4
X	movel	#288,d6
X	addl	a6,d6
X	lsll	#2,d6
X	addl	d7,a6
Xmoverightup2:
X	movel	a6,d2
Xmoverightup3:
X	movel	a1@-,d3			| sprite mask	
X	beq	moverightup8
X	movel	a0@-,d4			
X	eorl	d7,d4			| NOT spritemask
X	movel	a2@-,d5		
X	andl	d4,d5			|
X	movel	d5,a2@			| Removed part
X	movel	a3@-,d4
X	andl	d4,d3
X	bne	moverightColl
Xmoverightup4:
X	movel	a0@,d3	
X	orl	d3,d4
X	movel	d4,a3@
X	dbf	d2,moverightup3
X	addl	d6,a3
X	addl	d6,a2
X	addl	a4,a0
X	addl	a4,a1
X	dbf	d1,moverightup2
X	moveml	sp@+,#regmask3o
X	rts
XmoverightColl:
X	moveq	#1,d0
X	movel	a0@,d3	
X	orl	d3,d4
X	movel	d4,a3@
X	dbf	d2,moverightup3
X	addl	d6,a3
X	addl	d6,a2
X	addl	a4,a0
X	addl	a4,a1
X	dbf	d1,moverightup2
X	moveml	sp@+,#regmask3o
X	rts
Xmoverightup8:
X	subl	a5,a0
X	subl	a5,a2
X	subl	a5,a3
X	dbf	d2,moverightup3
X	addl	d6,a3
X	addl	d6,a2
X	addl	a4,a0
X	addl	a4,a1
X	dbf	d1,moverightup2
X	moveml	sp@+,#regmask3o
X	rts
X	
Xmoverightdown:
X	movel	d1,d6
X	lsll	#2,d6
X	lea	_RAWGRAPH_screenlefts,a4
X	movel	a4@(d6),d6
X	subl	a4@,d6
X	lsrl	#2,d6
X	addl	a6,d6
X	lsll	#2,d6
X	addl	d6,a2
X	addl	d6,a3
X	movel	a6,d6
X	mulsl	d1,d6
X	addl	a6,d6
X	lsll	#2,d6
X	addl	d6,a0
X	addl	d6,a1
X	movel	#-288,d6
X	addl	a6,d6
X	lsll	#2,d6
X	movel	#0,a4
X	addl	d7,a6
X	jmp	moverightup2
SHAR_EOF
chmod 0644 sprites.s || echo "restore of sprites.s fails"
exit 0


----- End Forwarded Message -----