home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / sun / volume1 / fastgraph < prev    next >
Encoding:
Internet Message Format  |  1990-02-04  |  26.7 KB

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