home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / compsrcs / sun / volume01 / fastgr.aph < prev    next >
Encoding:
Internet Message Format  |  1991-08-27  |  27.1 KB

  1. From decwrl!sun-barr!cs.utexas.edu!rutgers!aramis.rutgers.edu!dartagnan.rutgers.edu!mcgrew Wed Dec 20 08:05:24 PST 1989
  2. Article 98 of comp.sources.sun:
  3. Path: decwrl!sun-barr!cs.utexas.edu!rutgers!aramis.rutgers.edu!dartagnan.rutgers.edu!mcgrew
  4. From: mcgrew@dartagnan.rutgers.edu (Charles Mcgrew)
  5. Newsgroups: comp.sources.sun
  6. Subject: v01i095:  Rawgraph - a graphics library for the cg4b (Sun 3/60)
  7. Message-ID: <Dec.19.23.56.26.1989.28257@dartagnan.rutgers.edu>
  8. Date: 20 Dec 89 04:56:30 GMT
  9. Organization: Rutgers Univ., New Brunswick, N.J.
  10. Lines: 1075
  11. Approved: mcgrew@aramis.rutgers.edu
  12.  
  13. Submitted-by: From: hhansen@solan.unit.no
  14. Posting-number: Volume 1, Issue 95
  15. Archive-name: fastgraph
  16.  
  17. Harald Nordgaard-Hansen ( TeXish : Harald Nordg{\aa}rd-Hansen)
  18. <hhansen@solan.unit.no>
  19.  
  20. ------- Cut here ---------------------------------- Cut here ---------------
  21. #!/bin/sh
  22. # shar:    Shell Archiver  (v1.22)
  23. #
  24. #    Run the following text with /bin/sh to create:
  25. #      Makefile
  26. #      README
  27. #      overview
  28. #      rawgraph.c
  29. #      rawgraph.h
  30. #      sprites.s
  31. #
  32. sed 's/^X//' << 'SHAR_EOF' > Makefile &&
  33. X####################################################################
  34. X#
  35. X# simple makefile for libraw.a, the RAWGRAPH library.
  36. X#
  37. X# Copyright (c) 1989 Upon Software / PVV
  38. X#
  39. X####################################################################
  40. X# CC = gcc
  41. XCC = cc
  42. XAR = ar rc
  43. XAS = as
  44. XRM = rm -f
  45. XRANLIB = ranlib
  46. X
  47. XLOPTS = -O
  48. X# COPTS = -Wall -g
  49. XCOPTS = -O
  50. XLIBS = -lc
  51. X
  52. X# Define SYSTEM to either SUNOS3 or SUNOS4
  53. X# SYSTEM = SUNOS3
  54. XSYSTEM = SUNOS4
  55. X
  56. XJUNKFILES = *.o gmon.out mon.out core *~ #*#
  57. X
  58. XRAWSRC = rawgraph.c rawgraph.h sprites.s
  59. XRAWOBJS = rawgraph.o sprites.o
  60. X
  61. Xall: libraw.a
  62. X
  63. X.c.o:
  64. X    $(CC) $(COPTS) -D$(SYSTEM) -c $*.c
  65. X
  66. X.s.o:
  67. X    $(AS) -o $*.o $*.s
  68. X
  69. Xlibraw.a: $(RAWOBJS)
  70. X    $(AR) $@ $(RAWOBJS)
  71. X    $(RANLIB) $@
  72. X
  73. Xclean: 
  74. X    $(RM) $(JUNKFILES)
  75. X
  76. Xcleanx:
  77. X    $(RM) libraw.a $(JUNKFILES)
  78. X
  79. X# Dependencies
  80. Xrawgraph.o:    rawgraph.h rawgraph.c
  81. X
  82. X#    $(CC) $(COPTS) -D$(SYSTEM) -c rawgraph.c 
  83. X#    $(AS) -o sprites.o sprites.s
  84. SHAR_EOF
  85. chmod 0644 Makefile || echo "restore of Makefile fails"
  86. sed 's/^X//' << 'SHAR_EOF' > README &&
  87. X             RAWGRAPH ver. 1.0 beta
  88. X            Release date 14.nov. 1989
  89. X              No previous releases.
  90. X
  91. XFiles in this distribution:
  92. X    rawgraph.h - Header file for rawgraph (include in your programs)
  93. X             Macros are here.
  94. X    rawgraph.c - The rawgraph functions. All the c functions lies here.
  95. X    sprites.s  - The software sprite assembly routines.
  96. X    Makefile   - A simple makefile to create libraw.a, if you want to
  97. X             use it as a library.
  98. X    overview   - A small overview of the macros and functions in rawgraph.
  99. X             This is all the documentation I've had time for. Something
  100. X             better might come later.
  101. X    README     - This file. Some general info, and documemtation.
  102. X             Some day I hope to make some man-pages and other
  103. X             info, but not just now.
  104. X
  105. XPurpose:
  106. X
  107. XRawgraph is a small and fast graphics library for SUN machines with
  108. Xthe cg4b frame buffer. It runs under SunOS4.0, and hopefully also under
  109. XSunOS3.X, although this hasn't been tested too much. It is still under
  110. Xdevelopment, and all comments and enchancements would be helpful.
  111. X
  112. XAnyway, this is just a simple piece of code, and can surely be improved.
  113. XI'd appreciate it if you would let me know if you make any improvements,
  114. Xand I'll try to mail later versions if I get the time. (Life as a student
  115. Xis a little busy these days.. :-)
  116. X
  117. X                                ---
  118. X
  119. XCopyright (c) 1989 Upon Software / PVV
  120. X
  121. XPermission to use, copy, modify, and distribute this software and its
  122. Xdocumentation for any purpose and without fee is hereby granted,
  123. Xprovided that the above copyright notice appear in all copies and that
  124. Xboth that copyright notice and this permission notice appear in
  125. Xsupporting documentation.
  126. X
  127. XThis file is provided AS IS with no warranties of any kind.  The author
  128. Xshall have no liability with respect to the infringement of copyrights,
  129. Xtrade secrets or any patents by this file or any part thereof.  In no
  130. Xevent will the author be liable for any lost revenue or profits or
  131. Xother special, indirect and consequential damages.
  132. X
  133. XComments and additions should be sent to the author:
  134. X
  135. X    <hhansen@solan.unit.no>,
  136. X    <hhansen@idt.unit.no> or
  137. X    <nordgard@norunit.bitnet>
  138. X
  139. X    Harald 'Faramir' Nordgard-Hansen,
  140. X    ProgramVareVerkstedet,
  141. X    Room 246/1, SB2,
  142. X    N-7034 TRONDHEIM - NTH,
  143. X    NORWAY
  144. X
  145. SHAR_EOF
  146. chmod 0644 README || echo "restore of README fails"
  147. sed 's/^X//' << 'SHAR_EOF' > overview &&
  148. X            RAWGRAPH ver. 1.0 beta
  149. X        Copyright (c) 1989 Upon Software / PVV
  150. X         Simple Overview of the functions in RAWGRAPH.
  151. X
  152. XRawgraph is a small and fast graphics library for SUN machines with
  153. Xthe cg4b frame buffer. It runs under SunOS4.0, and hopefully also under
  154. XSunOS3.X, although this hasn't been tested too much. It is still under
  155. Xdevelopment, and all comments and enchancements would be helpful.
  156. X
  157. XRawgraph is currently made up of three different kinds of "functions".
  158. XThe simple basics is implemented as macros, for speed. Then some more complex 
  159. Xroutines, like initalisation and line drawing routines, are c functions. And
  160. Xfinally there is some software sprite routines, implemented in assembly. The
  161. Xtwo latter is put togetger into libraw.a
  162. X
  163. XThe macros are these:
  164. X
  165. XPlot(x,y)    - Set (black) a pixel on the overlay plane at coords (x,y).
  166. XUnplot(x,y)    - Unset (white) a pixel on the overlay plane at coords (x,y).
  167. XPixel(x,y)    - Returns the value of the overlay plane at coords (x,y).
  168. XEnable(x,y)    - Turn on the overlay plane at coords (x,y).
  169. XDisable(x,y)    - Turn off the overlay plane (and show the color planes) at
  170. X          coords (x,y).
  171. XEnabled(x,y)    - Returns the value of the enable plane at coords (x,y).
  172. XCplot(x,y,c)    - Set a pixel with color c at coords (x,y) on the color planes.
  173. XCpixel(x,y)    - Returns the value of the color planes at coords (x,y).
  174. X
  175. XCls()        - Set all planes to zero.
  176. XBwCls()        - Set the overlay plane to zero.
  177. XEnblCol()    - Set the enable plane to zero, showing the color planes.
  178. XEnblBw()    - Set the enable plane to 0xff, showing the overlay plane.
  179. XCCls()        - Set the color planes to zero.
  180. X
  181. XThe c functions are these:
  182. X
  183. XInitRawGraph()    - This function must be called before any part of rawgraph is
  184. X          used. It maps the frame buffer to viritual memory, and sets
  185. X          up all the global variables.
  186. X
  187. XExitRawGraph()    - This function may be called to close down the rawgraph
  188. X          system. All it does as of now, is to close the file
  189. X          descriptor associated with the frame buffer.
  190. X
  191. XCcircle(x,y,r,c) -Draw a circle on the color planes with centre in x,y,
  192. X          radius r and color c.
  193. X
  194. XCircle(x,y,r)    - Draw a circle on the overlay plane with centre in x,y and
  195. X          radius r.
  196. X
  197. XCline(x1,y1,x2,y2,c) - Draw a line from (x1,y1) to (x2,y2) on the color
  198. X                       planes, with color c.
  199. X
  200. XLine(x1,y1,x2,y2)    - Draw a line from (x1,y1) to (x2,y2) on the overlay
  201. X                       plane.
  202. X
  203. XPutColors(indent,count,red,green,blue) - Set the palette registers from indent
  204. X          to indent+count-1 to rgb values from arrays red, green and
  205. X          blue. See also pixrect's pr_putcolormap.
  206. X
  207. XGetColors(indent,count,red,green,blue) - Like PutColors, but returns the
  208. X          current values in red, green and blue arrays.
  209. X
  210. XWe also have (color only) soft-sprites, written by Tegge in assembly.
  211. XThe three routines for this are:
  212. X
  213. XPutVarSprite(sprite_data, sprite_mask, x, y, width_int, height) -
  214. X    Put a sprite at position x,y. height is the height of the sprite
  215. X    (in pixels) and width_int is the width of the sprite (in number of
  216. X    32-bit words or 4-pixels). sprite_data is the data to be ored into
  217. X    the screen, and sprite_mask is the data used to test for hitting
  218. X    something. No data is removed from the screen in this process.
  219. X    PutVarSprite returns non-zero if the sprite hit something. In this
  220. X    case, the colors may be wrong on some points.
  221. X
  222. XKillVarSprite(sprite_mask, x, y, width_int, height) -
  223. X    The data in sprite_mask is complemented and anded into the screen
  224. X    at position x,y. This is used for removing a sprite from the screen.
  225. X
  226. XMoveVarSprite(sprite_data, sprite_mask, orig_x, orig_y, dest_x,
  227. X          dest_y, width_int, height) -
  228. X    This is equivalent with calling KillVarSprite with orig_x and
  229. X    orig_y, and then calling PutVarSprite with dest_x and dest_y, but
  230. X    some optimizing is performed on the way. This is to minimize the
  231. X    "flickering" when moving/animating sprites. MoveVarSprite returns
  232. X    the same as PutVarSprite.
  233. X
  234. XBe aware that the Rawgraph system do not perform clipping. Writing off the
  235. Xscreen will give strange results, or result in segmentation violation if
  236. Xyou move out of the frame buffer. (The different parts of the screen lie
  237. Xsequentially in memory.)
  238. X
  239. XHave fun.
  240. SHAR_EOF
  241. chmod 0644 overview || echo "restore of overview fails"
  242. sed 's/^X//' << 'SHAR_EOF' > rawgraph.c &&
  243. X/**************************************************************\
  244. X*                                                              *
  245. X*     rawgraph.c - raw memory screen library for Sun 3/60's    *
  246. X*                                                              *
  247. X*           Copyright (c) 1989 Upon Software / PVV             *
  248. X*         Written by Harald 'Faramir' Nordgard-Hansen,         *
  249. X*                  <hhansen@solan.unit.no>.                    *
  250. X*             Based on algorithms and code from                *
  251. X*         Roar Andre Lauritsen <roarl@solan.unit.no>,          *
  252. X*             Arne H. Juul <juul@solan.unit.no>,               *
  253. X*             Stig Hemmer <stig@solan.unit.no>,                *
  254. X*                       and above all                          *
  255. X*           Tor 'Tegge' Egge <tegge@solan.unit.no>             *
  256. X*       who discovered how to do it in the first place.        *
  257. X\**************************************************************/
  258. X
  259. X#define RAWLIB
  260. X#include "rawgraph.h"
  261. X
  262. Xbyte *RAWGRAPH_MaskMap,*RAWGRAPH_ColorMap,*RAWGRAPH_BwMap,*RAWGRAPH_Tabell;
  263. Xint RAWGRAPH_BwLinjeAddr[RAWGRAPH_MAXY],RAWGRAPH_CLinjeAddr[RAWGRAPH_MAXY];
  264. Xbyte *RAWGRAPH_screenlefts[RAWGRAPH_MAXY];
  265. X
  266. Xextern void ioctl();
  267. X
  268. X#ifdef SUNOS4
  269. Xextern char *mmap();
  270. X#else
  271. Xextern void mmap();
  272. Xextern byte valloc();
  273. X#endif
  274. X#define MAP_SHARED 1
  275. X
  276. Xstatic int filedesc;
  277. X
  278. X#ifdef ANSI
  279. Xvoid InitRawGraph(void) 
  280. X#else /* ANSI */
  281. Xvoid InitRawGraph()
  282. X#endif /* ANSI */
  283. X{
  284. X  static initialized=0;
  285. X  int line;
  286. X  void exit(), printf() ;
  287. X  int open() ;
  288. X
  289. X  if (initialized) return;
  290. X  initialized=1;
  291. X
  292. X  if ((filedesc=open("/dev/cgfour0",2))<0)
  293. X    {
  294. X      printf("rawgraph: /dev/cgfour0 not available\n"); 
  295. X      exit(4);
  296. X    }
  297. X
  298. X#ifdef SUNOS4
  299. X  RAWGRAPH_Tabell=(byte *) mmap((char *)0,RAWGRAPH_FRAMESIZE,3,
  300. X                MAP_SHARED,filedesc,(long)0);
  301. X#else /* SUNOS4 */
  302. X#  ifdef SUNOS3
  303. X     RAWGRAPH_Tabell=(byte *) valloc(RAWGRAPH_FRAMESIZE);
  304. X     mmap(RAWGRAPH_Tabell,RAWGRAPH_FRAMESIZE,3,MAP_SHARED,filedesc,(long)0);
  305. X#  else /* SUNOS3 */
  306. X     /* This is a bit rotten, but it's the only way to make cpp give a */
  307. X     /* sensible error message... */
  308. X#    include "rawgraph: * Please define either SUNOS3 or SUNOS4 *"
  309. X#  endif /* SUNOS3 */
  310. X#endif /* SUNOS4 */
  311. X
  312. X  RAWGRAPH_ColorMap=&RAWGRAPH_Tabell[262144];
  313. X  RAWGRAPH_MaskMap=&RAWGRAPH_Tabell[131072];
  314. X  RAWGRAPH_BwMap=RAWGRAPH_Tabell;
  315. X
  316. X  for (line=0; line<RAWGRAPH_MAXY; line++)
  317. X    {
  318. X      RAWGRAPH_BwLinjeAddr[line]=((line<<3)+line)<<4;
  319. X      RAWGRAPH_CLinjeAddr[line]=((line<<3)+line)<<7;
  320. X      RAWGRAPH_screenlefts[line]=RAWGRAPH_ColorMap+RAWGRAPH_CLinjeAddr[line];
  321. X    }
  322. X}
  323. X
  324. X#ifdef ANSI
  325. Xvoid ExitRawGraph(void)
  326. X#else
  327. Xvoid ExitRawGraph()
  328. X#endif
  329. X{
  330. X  void close();
  331. X
  332. X  close (filedesc);
  333. X}
  334. X
  335. 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);}
  336. 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);}
  337. X
  338. X#ifdef ANSI
  339. Xvoid Ccircle(int x, int y, int r, int c)
  340. X#else
  341. Xvoid Ccircle(x,y,r,c)
  342. X     int x,y,r,c;
  343. X#endif
  344. X{
  345. X  int d1,d2,f;
  346. X  
  347. X  if(r<1)
  348. X    Cplot(x,y,c) ;
  349. X  else
  350. X    {
  351. X      d1=0;d2=f=r;
  352. X      while (d1<d2)
  353. X    {
  354. X      RAWGRAPH_Cplot4(d1,d2,c);
  355. X      f-=(d1++)*2+1;
  356. X          if (d1>=d2) break;
  357. X      if (f<0) f+=(--d2)*2+1;
  358. X      RAWGRAPH_Cplot4(d2,d1,c);
  359. X    }
  360. X    }
  361. X}
  362. X
  363. X#ifdef ANSI
  364. Xvoid Circle(int x, int y, int r)
  365. X#else
  366. Xvoid Circle(x,y,r)
  367. X     int x,y,r;
  368. X#endif
  369. X{
  370. X  int d1,d2,f;
  371. X  
  372. X  if(r<1)
  373. X    Plot(x,y) ;
  374. X  else
  375. X    {
  376. X      d1=0;d2=f=r;
  377. X      while (d1<d2)
  378. X    {
  379. X      RAWGRAPH_BWplot4(d1,d2);
  380. X      f-=(d1++)*2+1;
  381. X          if (d1>=d2) break;
  382. X      if (f<0) f+=(--d2)*2+1;
  383. X      RAWGRAPH_BWplot4(d2,d1);
  384. X    }
  385. X    }
  386. X}
  387. X
  388. X#ifdef ANSI
  389. Xvoid Cline(int x1,int y1,int x2,int y2,int c)
  390. X#else
  391. Xvoid Cline(x1,y1,x2,y2,c)
  392. X     int x1,x2,y1,y2,c;
  393. X#endif
  394. X{
  395. X  int dx,dy,x,y,x_end,p,const1,const2;
  396. X
  397. X  if (((x1-x2)*(y1-y2))>0) { 
  398. X    dx = (x1>x2) ? (x1-x2) : (x2-x1);
  399. X    dy = (y1>y2) ? (y1-y2) : (y2-y1);
  400. X    if (dx>dy) { 
  401. X      p = (dy << 1) -dx ;
  402. X      const1 = dy << 1;
  403. X      const2 = (dy - dx) << 1;
  404. X      
  405. X      if(x1>x2) {
  406. X    x = x2;
  407. X    y = y2;
  408. X    x_end = x1;
  409. X      } else {
  410. X    x = x1;
  411. X    y = y1;
  412. X    x_end = x2;
  413. X      }
  414. X      Cplot(x,y,c);
  415. X      while ( x < x_end ) {
  416. X    x++;
  417. X    if (p<0) p += const1;
  418. X    else {
  419. X      y++;
  420. X      p += const2;
  421. X    }
  422. X    Cplot(x,y,c);
  423. X      }
  424. X    } else {
  425. X      p = (dx << 1) -dy ;
  426. X      const1 = dx << 1;
  427. X      const2 = (dx - dy) << 1;
  428. X      
  429. X      if(y1>y2) {
  430. X    x = y2;
  431. X    y = x2;
  432. X    x_end = y1;
  433. X      } else {
  434. X    x = y1;
  435. X    y = x1;
  436. X    x_end = y2;
  437. X      }
  438. X      Cplot(y,x,c);
  439. X      while ( x < x_end ) {
  440. X    x++;
  441. X    if (p<0) p += const1;
  442. X    else {
  443. X      y++;
  444. X      p += const2;
  445. X    }
  446. X    Cplot(y,x,c);
  447. X      }
  448. X    }
  449. X  } else {
  450. X    dx = (x1>x2) ? (x1-x2) : (x2-x1);
  451. X    dy = (y1>y2) ? (y1-y2) : (y2-y1);
  452. X    if (dx>dy) { 
  453. X      p = (dy << 1) -dx ;
  454. X      const1 = dy << 1;
  455. X      const2 = (dy - dx) << 1;
  456. X      
  457. X      if(x1>x2) {
  458. X    x = x2;
  459. X    y = y2;
  460. X    x_end = x1;
  461. X      } else {
  462. X    x = x1;
  463. X    y = y1;
  464. X    x_end = x2;
  465. X      }
  466. X      Cplot(x,y,c);
  467. X      while ( x < x_end ) {
  468. X    x++;
  469. X    if (p<0) p += const1;
  470. X    else {
  471. X      y--;
  472. X      p += const2;
  473. X    }
  474. X    Cplot(x,y,c);
  475. X      }
  476. X    } else {
  477. X      p = (dx << 1) -dy ;
  478. X      const1 = dx << 1;
  479. X      const2 = (dx - dy) << 1;
  480. X      
  481. X      if(y1>y2) {
  482. X    x = y2;
  483. X    y = x2;
  484. X    x_end = y1;
  485. X      } else {
  486. X    x = y1;
  487. X    y = x1;
  488. X    x_end = y2;
  489. X      }
  490. X      Cplot(y,x,c);
  491. X      while ( x < x_end ) {
  492. X    x++;
  493. X    if (p<0) p += const1;
  494. X    else {
  495. X      y--;
  496. X      p += const2;
  497. X    }
  498. X    Cplot(y,x,c);
  499. X      }
  500. X    }
  501. X  }
  502. X}
  503. X
  504. X
  505. X#ifdef ANSI
  506. Xvoid Line(int x1,int y1,int x2,int y2)
  507. X#else
  508. Xvoid Line(x1,y1,x2,y2)
  509. X     int x1,x2,y1,y2;
  510. X#endif
  511. X{
  512. X  int dx,dy,x,y,x_end,p,const1,const2;
  513. X
  514. X  if (((x1-x2)*(y1-y2))>0) { 
  515. X    dx = (x1>x2) ? (x1-x2) : (x2-x1);
  516. X    dy = (y1>y2) ? (y1-y2) : (y2-y1);
  517. X    if (dx>dy) { 
  518. X      p = (dy << 1) -dx ;
  519. X      const1 = dy << 1;
  520. X      const2 = (dy - dx) << 1;
  521. X      
  522. X      if(x1>x2) {
  523. X    x = x2;
  524. X    y = y2;
  525. X    x_end = x1;
  526. X      } else {
  527. X    x = x1;
  528. X    y = y1;
  529. X    x_end = x2;
  530. X      }
  531. X      Plot(x,y);
  532. X      while ( x < x_end ) {
  533. X    x++;
  534. X    if (p<0) p += const1;
  535. X    else {
  536. X      y++;
  537. X      p += const2;
  538. X    }
  539. X    Plot(x,y);
  540. X      }
  541. X    } else {
  542. X      p = (dx << 1) -dy ;
  543. X      const1 = dx << 1;
  544. X      const2 = (dx - dy) << 1;
  545. X      
  546. X      if(y1>y2) {
  547. X    x = y2;
  548. X    y = x2;
  549. X    x_end = y1;
  550. X      } else {
  551. X    x = y1;
  552. X    y = x1;
  553. X    x_end = y2;
  554. X      }
  555. X      Plot(y,x);
  556. X      while ( x < x_end ) {
  557. X    x++;
  558. X    if (p<0) p += const1;
  559. X    else {
  560. X      y++;
  561. X      p += const2;
  562. X    }
  563. X    Plot(y,x);
  564. X      }
  565. X    }
  566. X  } else {
  567. X    dx = (x1>x2) ? (x1-x2) : (x2-x1);
  568. X    dy = (y1>y2) ? (y1-y2) : (y2-y1);
  569. X    if (dx>dy) { 
  570. X      p = (dy << 1) -dx ;
  571. X      const1 = dy << 1;
  572. X      const2 = (dy - dx) << 1;
  573. X      
  574. X      if(x1>x2) {
  575. X    x = x2;
  576. X    y = y2;
  577. X    x_end = x1;
  578. X      } else {
  579. X    x = x1;
  580. X    y = y1;
  581. X    x_end = x2;
  582. X      }
  583. X      Plot(x,y);
  584. X      while ( x < x_end ) {
  585. X    x++;
  586. X    if (p<0) p += const1;
  587. X    else {
  588. X      y--;
  589. X      p += const2;
  590. X    }
  591. X    Plot(x,y);
  592. X      }
  593. X    } else {
  594. X      p = (dx << 1) -dy ;
  595. X      const1 = dx << 1;
  596. X      const2 = (dx - dy) << 1;
  597. X      
  598. X      if(y1>y2) {
  599. X    x = y2;
  600. X    y = x2;
  601. X    x_end = y1;
  602. X      } else {
  603. X    x = y1;
  604. X    y = x1;
  605. X    x_end = y2;
  606. X      }
  607. X      Plot(y,x);
  608. X      while ( x < x_end ) {
  609. X    x++;
  610. X    if (p<0) p += const1;
  611. X    else {
  612. X      y--;
  613. X      p += const2;
  614. X    }
  615. X    Plot(y,x);
  616. X      }
  617. X    }
  618. X  }
  619. X}
  620. X
  621. X#define MAGIC_PUT 0x80144603
  622. X#define MAGIC_GET 0x80144604
  623. X
  624. Xtypedef struct _colorstruct { 
  625. X  int ind;
  626. X  int cnt;
  627. X  byte *red;
  628. X  byte *grn;
  629. X  byte *blu;
  630. X} Colorstruct;
  631. X
  632. X#ifdef ANSI
  633. Xvoid PutColors(int indent, int count, byte *red, byte *green, byte *blue)
  634. X#else
  635. Xvoid PutColors(indent,count,red,green,blue)
  636. X     int indent,count;
  637. X     byte *red,*green,*blue;
  638. X#endif
  639. X{
  640. X  Colorstruct c;
  641. X
  642. X  c.ind = indent;
  643. X  c.cnt = count;
  644. X  c.red = red;
  645. X  c.grn = green;
  646. X  c.blu = blue;
  647. X
  648. X  ioctl(filedesc,MAGIC_PUT,&c);
  649. X}
  650. X
  651. X#ifdef ANSI
  652. Xvoid GetColors(int indent, int count, byte *red, byte *green, byte *blue)
  653. X#else
  654. Xvoid GetColors(indent,count,red,green,blue)
  655. X     int indent,count;
  656. X     byte *red,*green,*blue;
  657. X#endif
  658. X{
  659. X  Colorstruct c;
  660. X
  661. X  c.ind = indent;
  662. X  c.cnt = count;
  663. X  c.red = red;
  664. X  c.grn = green;
  665. X  c.blu = blue;
  666. X
  667. X  ioctl(filedesc,MAGIC_GET,&c);
  668. X}
  669. SHAR_EOF
  670. chmod 0644 rawgraph.c || echo "restore of rawgraph.c fails"
  671. sed 's/^X//' << 'SHAR_EOF' > rawgraph.h &&
  672. X/**************************************************************\
  673. X*                                                              *
  674. X*      rawgraph.h - raw memory screen utils for Sun 3/60's     *
  675. X*                                                              *
  676. X*           Copyright (c) 1989 Upon Software / PVV             *
  677. X*         Written by Harald 'Faramir' Nordgard-Hansen,         *
  678. X*                  <hhansen@solan.unit.no>.                    *
  679. X*             Based on algorithms and code from                *
  680. X*         Roar Andre Lauritsen <roarl@solan.unit.no>,          *
  681. X*             Arne H. Juul <juul@solan.unit.no>,               *
  682. X*             Stig Hemmer <stig@solan.unit.no>,                *
  683. X*                       and above all                          *
  684. X*           Tor 'Tegge' Egge <tegge@solan.unit.no>             *
  685. X*       who discovered how to do it in the first place.        *
  686. X\**************************************************************/
  687. X
  688. X#ifndef RAWGRAPH_DEFINED
  689. X#define RAWGRAPH_DEFINED
  690. X
  691. X#ifndef byte
  692. X#define byte unsigned char
  693. X#endif
  694. X
  695. Xextern char *memset();
  696. X
  697. X/* First we define the internal constants. */
  698. X#define RAWGRAPH_FRAMESIZE 1302528
  699. X#define RAWGRAPH_COLORSIZE 1036800
  700. X#define RAWGRAPH_BWSIZE    129600
  701. X#define RAWGRAPH_MASKSIZE  129600
  702. X
  703. X#define RAWGRAPH_MAXX 1152
  704. X#define RAWGRAPH_MAXY 900
  705. X
  706. X#define RAWGRAPH_PITCH 1152
  707. X#define RAWGRAPH_BWPITCH 144
  708. X
  709. X/* Then these two, just for convinience. */
  710. X#define MAXX RAWGRAPH_MAXX
  711. X#define MAXY RAWGRAPH_MAXY
  712. X
  713. X/* These are for calculating the offset into the frame buffers. */
  714. X#define RAWGRAPH_CAddr(x,y)  ((x)+RAWGRAPH_CLinjeAddr[y])
  715. X#define RAWGRAPH_BwAddr(x,y) (((x)>>3)+RAWGRAPH_BwLinjeAddr[y])
  716. X
  717. X/* And at last the simple plot/unplot and cls macros. */
  718. X#define Plot(x,y)   (*(RAWGRAPH_BwMap +RAWGRAPH_BwAddr(x,y))|=128>>((x)&7))
  719. X#define Unplot(x,y) (*(RAWGRAPH_BwMap +RAWGRAPH_BwAddr(x,y))&=~(128>>((x)&7)))
  720. X#define Pixel(x,y) ((*(RAWGRAPH_BwMap +RAWGRAPH_BwAddr(x,y))&(128>>((x)&7)))>0)
  721. X#define Enable(x,y)  (*(RAWGRAPH_MaskMap+RAWGRAPH_BwAddr(x,y))|=128>>((x)&7))
  722. X#define Disable(x,y) \
  723. X  (*(RAWGRAPH_MaskMap+RAWGRAPH_BwAddr(x,y))&=~(128>>((x)&7)))
  724. X#define Enabled(x,y) \
  725. X  ((*(RAWGRAPH_MaskMap+RAWGRAPH_BwAddr(x,y))&(128>>((x)&7)))>0)
  726. X#define Cplot(x,y,color) (*(RAWGRAPH_ColorMap+RAWGRAPH_CAddr(x,y))=color)
  727. X#define Cpixel(x,y)      (*(RAWGRAPH_ColorMap+RAWGRAPH_CAddr(x,y)))
  728. X#define Cls()     memset(RAWGRAPH_Tabell  ,0   ,RAWGRAPH_FRAMESIZE)
  729. X#define BwCls()   memset(RAWGRAPH_BwMap   ,0   ,RAWGRAPH_BWSIZE)
  730. X#define EnblCol() memset(RAWGRAPH_MaskMap ,0   ,RAWGRAPH_MASKSIZE)
  731. X#define EnblBw()  memset(RAWGRAPH_MaskMap ,0xff,RAWGRAPH_MASKSIZE)
  732. X#define CCls()    memset(RAWGRAPH_ColorMap,0   ,RAWGRAPH_COLORSIZE)
  733. X
  734. X/* Then the global variables needed. */
  735. Xextern byte *RAWGRAPH_MaskMap,*RAWGRAPH_ColorMap,*RAWGRAPH_BwMap,
  736. X  *RAWGRAPH_Tabell;
  737. Xextern int RAWGRAPH_BwLinjeAddr[], RAWGRAPH_CLinjeAddr[];
  738. X
  739. X/* And finally the various functions in the library. */
  740. X/* first the ansi versions.. */
  741. X#ifdef ANSI
  742. Xvoid InitRawGraph(void);
  743. Xvoid ExitRawGraph(void);
  744. Xvoid CCircle(int x, int y, int r, int c);
  745. Xvoid Circle(int x, int y, int r);
  746. Xvoid Cline(int x1,int y1,int x2,int y2,int c);
  747. Xvoid Line(int x1,int y1,int x2,int y2);
  748. Xvoid PutColors(int indent, int count, byte *red, byte *green, byte *blue);
  749. Xvoid GetColors(int indent, int count, byte *red, byte *green, byte *blue);
  750. Xint PutVarSprite(byte *sprite_data, byte *sprite_mask, int x, int y,
  751. X         int width_int, int height);
  752. Xint MoveVarSprite(byte *sprite_data, byte *sprite_mask, int orig_x, int orig_y,
  753. X          int dest_x, int dest_y, int width_int, int height);
  754. Xvoid KillVarSprite(byte *sprite_mask, int x, int y, int width_int, int height);
  755. X
  756. X/* and then the old K&R versions.. */
  757. X#else /* ansi */
  758. Xvoid InitRawGraph();
  759. Xvoid ExitRawGraph();
  760. Xvoid Ccircle();
  761. Xvoid Circle();
  762. Xvoid Cline();
  763. Xvoid Line();
  764. Xvoid PutColors();
  765. Xvoid GetColors();
  766. Xint PutVarSprite();
  767. Xint MoveVarSprite();
  768. Xvoid KillVarSprite();
  769. X#endif /* ansi */
  770. X
  771. X#endif /*RAWGRAPH_DEFINED*/
  772. SHAR_EOF
  773. chmod 0644 rawgraph.h || echo "restore of rawgraph.h fails"
  774. sed 's/^X//' << 'SHAR_EOF' > sprites.s &&
  775. X# Copyright (c) 1989 Upon Software / PVV / Tegge
  776. X.data
  777. X.text
  778. X.proc
  779. X.globl _PutVarSprite
  780. X.globl _KillVarSprite
  781. X.globl _MoveVarSprite
  782. X
  783. X_PutVarSprite:
  784. X    regmask1o=0x04fc        | A7=MSB, D0=LSB
  785. X    moveml #0x3f20,sp@-        | D0=MSB, A7=LSB, D2/D3/D4/D5/D6/A2
  786. X    parms1=4+28
  787. X    movl    a7@(parms1+0),a0    | Upper left corner of sprite
  788. X    movl    a7@(parms1+4),a1    | Upper left corner of sprite mask
  789. X    movl    a7@(parms1+12),d0    | y position
  790. X    asll    #2,d0
  791. X    lea    _RAWGRAPH_screenlefts,a2
  792. X    movl    a2@(d0),a2
  793. X    addl    a7@(parms1+8),a2    | x position
  794. X    moveq    #0,d0            | No collision
  795. X    moveq    #4,d5
  796. X    movel    a7@(parms1+16),d7
  797. X    movel    #288,d6            | integers/rasterline
  798. X    subl    d7,d6            | 
  799. X    lsll    #2,d6            | Convert to bytes
  800. X    movel    a7@(parms1+20),d2    | Number of lines 
  801. X    subql    #1,d2
  802. X    subql    #1,d7    
  803. Xputsprite2:    
  804. X    movel    d7,d1            | (columns / 4) -1
  805. Xputsprite3:
  806. X    movl    a1@+,d3            | Get mask value
  807. X    beq    putsprite5        | Nothing here ?
  808. X    movl    a2@,d4            | Get screen value 
  809. X    andl    d4,d3            | And with mask
  810. X    bne    putsprite4        | No collition ?
  811. X    movl    a0@+,d3
  812. X    orl    d3,d4            | generate new screen value
  813. X    movl    d4,a2@+            | and put it to screen
  814. X
  815. X    dbf    d1,putsprite3        | More on same line ?
  816. X    addl    d6,a2            | Go to next line
  817. X    dbf    d2,putsprite2        | and work more
  818. X    moveml     sp@+,#regmask1o    
  819. X    rts
  820. Xputsprite4:
  821. X    movel    d5,d0            | Mark collition
  822. X    movl    a0@+,d3
  823. X    orl    d3,d4            | generate new screen value
  824. X    movl    d4,a2@+            | and put it to screen
  825. X
  826. X    dbf    d1,putsprite3        | More on same line ?
  827. X    addl    d6,a2            | Go to next line
  828. X    dbf    d2,putsprite2        | and work more
  829. X    moveml     sp@+,#regmask1o    
  830. X    rts
  831. X
  832. Xputsprite5:
  833. X    addl    d5,a2
  834. X    addl    d5,a0
  835. X    dbf    d1,putsprite3        | More on same line ?
  836. X    addl    d6,a2            | Go to next line
  837. X    dbf    d2,putsprite2        | and work more
  838. X    moveml     sp@+,#regmask1o    
  839. X    rts
  840. X
  841. X_KillVarSprite:
  842. X    regmask2o=0x00fc        | a7=MSB,D0=LSB
  843. X    moveml    #0x3f00,sp@-        | D0=MSB,A7=LSB  D2/D3/D4/D5/D6/D7
  844. X    parm2=4+24
  845. X    movel    a7@(parm2+0),a0        | Sprite data 
  846. X    movel    a7@(parm2+8),d0        | Screen y position
  847. X    asll    #2,d0
  848. X    lea    _RAWGRAPH_screenlefts,a1
  849. X    movel    a1@(d0),a1
  850. X    addl    a7@(parm2+4),a1
  851. X    movel    a7@(parm2+16),d0
  852. X    moveq    #-1,d4
  853. X    movel    a7@(parm2+12),d7
  854. X    movel    #288,d5            | integers/rasterline
  855. X    subl    d7,d5            | subtract sprite width 
  856. X    lsll    #2,d5            | Convert to bytes
  857. X    moveq    #4,d6            
  858. X    addl    d4,d7
  859. X    addl    d4,d0
  860. Xkillsprite2:
  861. X    movel    d7,d1
  862. Xkillsprite3:
  863. X    movel    a0@+,d2
  864. X    beq    killsprite4
  865. X    eorl    d4,d2
  866. X    movel    a1@,d3
  867. X    andl    d3,d2
  868. X    movel    d2,a1@+
  869. X    dbf    d1,killsprite3
  870. X    addl    d5,a1
  871. X    dbf    d0,killsprite2
  872. X    moveml    sp@+,#regmask2o        
  873. X    rts
  874. Xkillsprite4:
  875. X    addl    d6,a1
  876. X    dbf    d1,killsprite3
  877. X    addl    d5,a1
  878. X    dbf    d0,killsprite2
  879. X    moveml    sp@+,#regmask2o
  880. X    rts
  881. X
  882. X_MoveVarSprite:
  883. X    regmask3o=0x7cfc        | A7=MSB,D0=LSB
  884. X    moveml    #0x3f3e,sp@-        | D0=MSB,A7=LSB
  885. X    parms3=4+44
  886. X    moveq    #0,d0
  887. X    movel    a7@(parms3+28),d1    | Lines in sprite
  888. X    movel    a7@(parms3+24),a6    | 
  889. X    moveq    #-1,d7
  890. X    addl    d7,d1
  891. X    movel    #4,a5
  892. X    movel    a7@(parms3+0),a0    | Sprite data
  893. X    movel    a7@(parms3+4),a1    | Sprite mask
  894. X    movel    a7@(parms3+12),d2    | Screen Old y
  895. X    lea    _RAWGRAPH_screenlefts,a3        | 
  896. X    asll    #2,d2
  897. X    movel    a3@(d2),a2        
  898. X    addl    a7@(parms3+8),a2    | Screen old x
  899. X    movel    a7@(parms3+20),d2    | Screen new y
  900. X    asll    #2,d2
  901. X    movel    a3@(d2),a3
  902. X    addl    a7@(parms3+16),a3    | screen new x
  903. X    movel    a7@(parms3+8),d2    | Old x
  904. X    cmpl    a7@(parms3+16),d2    | New x
  905. X    bcs    moveright
  906. X| moveleft:
  907. X    movel    a7@(parms3+12),d2    | Old y
  908. X    cmpl    a7@(parms3+20),d2    | New y
  909. X    bcs    moveleftdown
  910. X| moveleftup:
  911. X    movel    #288,d6
  912. X    subl    a6,d6
  913. X    lsll    #2,d6
  914. X    movel    #0,a4
  915. X    addl    d7,a6
  916. Xmoveleftup2:
  917. X    movel    a6,d2
  918. Xmoveleftup3:
  919. X    movel    a1@+,d3            | sprite mask    
  920. X    beq    moveleftup8
  921. X    movel    a0@,d4            | sprite data
  922. X    eorl    d7,d4            | NOT spritedata
  923. X    movel    a2@,d5            | From Screen pos
  924. X    andl    d4,d5            |
  925. X    movel    d5,a2@+            | Removed part
  926. X    movel    a3@,d4            | To Screen pos
  927. X    andl    d4,d3            | Collition ?
  928. X    bne    moveleftColl        | 
  929. Xmoveleftup4:
  930. X    movel    a0@+,d3    
  931. X    orl    d3,d4
  932. X    movel    d4,a3@+
  933. X    dbf    d2,moveleftup3
  934. X    addl    d6,a3
  935. X    addl    d6,a2
  936. X    addl    a4,a0
  937. X    addl    a4,a1
  938. X    dbf    d1,moveleftup2
  939. X    moveml    sp@+,#regmask3o
  940. X    rts
  941. XmoveleftColl:
  942. X    moveq    #1,d0
  943. X    movel    a0@+,d3    
  944. X    orl    d3,d4
  945. X    movel    d4,a3@+
  946. X    dbf    d2,moveleftup3
  947. X    addl    d6,a3
  948. X    addl    d6,a2
  949. X    addl    a4,a0
  950. X    addl    a4,a1
  951. X    dbf    d1,moveleftup2
  952. X    moveml    sp@+,#regmask3o
  953. X    rts
  954. Xmoveleftup8:
  955. X    addl    a5,a0
  956. X    addl    a5,a2
  957. X    addl    a5,a3
  958. X    dbf    d2,moveleftup3
  959. X    addl    d6,a3
  960. X    addl    d6,a2
  961. X    addl    a4,a0
  962. X    addl    a4,a1
  963. X    dbf    d1,moveleftup2
  964. X    moveml    sp@+,#regmask3o
  965. X    rts
  966. X    
  967. Xmoveleftdown:
  968. X    
  969. X    movel    d1,d6        | lines-1
  970. X    lsll    #2,d6        | 
  971. X    lea    _RAWGRAPH_screenlefts,a4
  972. X    movel    a4@(d6),d6    
  973. X    subl    a4@,d6         | 
  974. X    addl    d6,a2
  975. X    addl    d6,a3
  976. X    movel    a6,d6
  977. X    mulsl    d1,d6
  978. X    lsll    #2,d6
  979. X    addl    d6,a0
  980. X    addl    d6,a1
  981. X    moveq    #0,d6
  982. X    subl    a6,d6
  983. X    lsll    #3,d6
  984. X    movel    d6,a4
  985. X    movel    #-288,d6
  986. X    subl    a6,d6
  987. X    lsll    #2,d6
  988. X    addl    d7,a6
  989. X    jmp    moveleftup2
  990. Xmoveright:
  991. X    movel    a7@(parms3+12),d2    | Old y
  992. X    cmpl    a7@(parms3+20),d2    | New y
  993. X    bcs    moverightdown
  994. X| moverightup:
  995. X    movel    a6,d6
  996. X    lsll    #2,d6
  997. X    addl    d6,a0
  998. X    addl    d6,a1
  999. X    addl    d6,a2
  1000. X    addl    d6,a3
  1001. X    movel    a6,d6
  1002. X    lsll    #3,d6
  1003. X    movel    d6,a4
  1004. X    movel    #288,d6
  1005. X    addl    a6,d6
  1006. X    lsll    #2,d6
  1007. X    addl    d7,a6
  1008. Xmoverightup2:
  1009. X    movel    a6,d2
  1010. Xmoverightup3:
  1011. X    movel    a1@-,d3            | sprite mask    
  1012. X    beq    moverightup8
  1013. X    movel    a0@-,d4            
  1014. X    eorl    d7,d4            | NOT spritemask
  1015. X    movel    a2@-,d5        
  1016. X    andl    d4,d5            |
  1017. X    movel    d5,a2@            | Removed part
  1018. X    movel    a3@-,d4
  1019. X    andl    d4,d3
  1020. X    bne    moverightColl
  1021. Xmoverightup4:
  1022. X    movel    a0@,d3    
  1023. X    orl    d3,d4
  1024. X    movel    d4,a3@
  1025. X    dbf    d2,moverightup3
  1026. X    addl    d6,a3
  1027. X    addl    d6,a2
  1028. X    addl    a4,a0
  1029. X    addl    a4,a1
  1030. X    dbf    d1,moverightup2
  1031. X    moveml    sp@+,#regmask3o
  1032. X    rts
  1033. XmoverightColl:
  1034. X    moveq    #1,d0
  1035. X    movel    a0@,d3    
  1036. X    orl    d3,d4
  1037. X    movel    d4,a3@
  1038. X    dbf    d2,moverightup3
  1039. X    addl    d6,a3
  1040. X    addl    d6,a2
  1041. X    addl    a4,a0
  1042. X    addl    a4,a1
  1043. X    dbf    d1,moverightup2
  1044. X    moveml    sp@+,#regmask3o
  1045. X    rts
  1046. Xmoverightup8:
  1047. X    subl    a5,a0
  1048. X    subl    a5,a2
  1049. X    subl    a5,a3
  1050. X    dbf    d2,moverightup3
  1051. X    addl    d6,a3
  1052. X    addl    d6,a2
  1053. X    addl    a4,a0
  1054. X    addl    a4,a1
  1055. X    dbf    d1,moverightup2
  1056. X    moveml    sp@+,#regmask3o
  1057. X    rts
  1058. X    
  1059. Xmoverightdown:
  1060. X    movel    d1,d6
  1061. X    lsll    #2,d6
  1062. X    lea    _RAWGRAPH_screenlefts,a4
  1063. X    movel    a4@(d6),d6
  1064. X    subl    a4@,d6
  1065. X    lsrl    #2,d6
  1066. X    addl    a6,d6
  1067. X    lsll    #2,d6
  1068. X    addl    d6,a2
  1069. X    addl    d6,a3
  1070. X    movel    a6,d6
  1071. X    mulsl    d1,d6
  1072. X    addl    a6,d6
  1073. X    lsll    #2,d6
  1074. X    addl    d6,a0
  1075. X    addl    d6,a1
  1076. X    movel    #-288,d6
  1077. X    addl    a6,d6
  1078. X    lsll    #2,d6
  1079. X    movel    #0,a4
  1080. X    addl    d7,a6
  1081. X    jmp    moverightup2
  1082. SHAR_EOF
  1083. chmod 0644 sprites.s || echo "restore of sprites.s fails"
  1084. exit 0
  1085.  
  1086.  
  1087. ----- End Forwarded Message -----
  1088.  
  1089.  
  1090.