home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / games / volume1 / sidtool / part01 next >
Internet Message Format  |  1987-05-15  |  59KB

  1. Path: seismo!husc6!mit-eddie!uw-beaver!tektronix!tekgen!tekred!games-request
  2. From: games-request@tekred.TEK.COM
  3. Newsgroups: comp.sources.games
  4. Subject: v01i018:  sidtool - pacman game for Suns, Part01/05
  5. Message-ID: <1216@tekred.TEK.COM>
  6. Date: 15 May 87 23:39:07 GMT
  7. Sender: billr@tekred.TEK.COM
  8. Lines: 2042
  9. Approved: billr@tekred.TEK.COM
  10.  
  11. Submitted by: Rich Burridge <munnari!sunk.oz!richb@seismo.css.gov>
  12. Comp.sources.games: Volume 1, Issue 18
  13. Archive-name: sidtool/Part01
  14.  
  15.     [I've actually tried this on our Sun50.  It's pretty neat.
  16.      This version *includes* the first official patch for the
  17.      game.  Note that the default is for the support files to
  18.      be in the same directory as the game.  Edit "sidtool.h"
  19.      if you want to change this.  Note also that the mouse
  20.      cursor has to be inside the sidtool window for it to
  21.      recognize the DEL key.   -br]
  22.  
  23. #! /bin/sh
  24. # This is a shell archive.  Remove anything before this line, then unpack
  25. # it by saving it into a file and typing "sh file".  To overwrite existing
  26. # files, type "sh file -c".  You can also feed this as standard input via
  27. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  28. # will see the following message at the end:
  29. #        "End of archive 1 (of 5)."
  30. # Contents:  README MANIFEST images images/animate.c release sid_blt.c
  31. #   sid_main.c
  32. # Wrapped by billr@tekred on Tue May 12 09:16:27 1987
  33. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  34. if test -f README -a "${1}" != "-c" ; then 
  35.   echo shar: Will not over-write existing file \"README\"
  36. else
  37. echo shar: Extracting \"README\" \(1865 characters\)
  38. sed "s/^X//" >README <<'END_OF_README'
  39. X
  40. X  Welcome to sidtool version 2.1.  -  April 1987.
  41. X
  42. XThis software is the second major release of the Sun Interactive
  43. XDebugger program, better known as sidtool. It probably still
  44. Xcontains bugs (and features). Should you find any of these, I
  45. Xwould be pleased to hear about them, and try to remove them.
  46. X
  47. XThis software will only work correctly with SunOS v3.2 or later.
  48. XWith a small effort, it could probably be made to run under v3.0,
  49. Xbut this is not supported.
  50. X
  51. XSETUP.
  52. XNote there is a #define in sidtool.h called SPEED. Experimentation
  53. Xwith this should give a better timing for other machines such as 
  54. XSun2s and the 3/260s.
  55. X
  56. XUnpack these files into a directory, alter the BINDIR line in
  57. Xthe top level Makefile to be where you want the sidtool release
  58. Xto be put, and type "make install".
  59. X
  60. XDISCLAIMER.
  61. XThis software was developed and tested on a 3/50. It is recognised
  62. Xthat this software runs slowly on Sun2s, and that there are
  63. Xprobably timing problems on other Sun3s. If you find a good pause
  64. Xfactor, please let me know.
  65. X
  66. XOPTIONS.
  67. XThere are a few command line options for alternately specifying
  68. Xwhere some of the files used by sidtool can be found. These are:
  69. X
  70. X -afilename   -  New animate filename.
  71. X -cspeed      -  New class (speed) of machine.
  72. X -d           -  Run in self demonstration mode.
  73. X -hfilename   -  New help filename.
  74. X -mfilename   -  New maze filename.
  75. X -sfilename   -  New high score filename.
  76. X
  77. XThe replacement filenames can also be specified by environment
  78. Xvariables. These are:
  79. X
  80. X SID_MAZE    -  New maze filename.
  81. X SID_ANIMATE -  New animate filename.
  82. X SID_SCORE   -  New high score filename.
  83. X SID_HELP    -  New help filename.
  84. X
  85. XKNOWN BUGS AND FEATURES:    None known.
  86. X
  87. XHave fun,
  88. X
  89. X  Rich Burridge,         SUN Microsystems Australia (Melbourne).
  90. X  Tel:  +61 59 962672.   UUCP:  sun!sunaus!sunk!richb
  91. X                         ACSnet:  richb@sunk.oz
  92. END_OF_README
  93. if test 1865 -ne `wc -c <README`; then
  94.     echo shar: \"README\" unpacked with wrong size!
  95. fi
  96. # end of overwriting check
  97. fi
  98. if test -f MANIFEST -a "${1}" != "-c" ; then 
  99.   echo shar: Will not over-write existing file \"MANIFEST\"
  100. else
  101. echo shar: Extracting \"MANIFEST\" \(2394 characters\)
  102. sed "s/^X//" >MANIFEST <<'END_OF_MANIFEST'
  103. X   File Name        Archive #    Description
  104. X-----------------------------------------------------------
  105. X INTRO                     4    
  106. X MANIFEST                  1    This shipping list
  107. X Makefile                  4    
  108. X README                    1    
  109. X README_v30                4    
  110. X TO_DO                     5    
  111. X bltstuff.h                4    
  112. X images                    1    
  113. X images/BASHFUL0.pic       3    
  114. X images/BASHFUL1.pic       3    
  115. X images/Makefile           2    
  116. X images/POKEY0.pic         4    
  117. X images/POKEY1.pic         4    
  118. X images/SHADOW0.pic        4    
  119. X images/SHADOW1.pic        4    
  120. X images/SPEEDY0.pic        4    
  121. X images/SPEEDY1.pic        4    
  122. X images/animate.c          1    
  123. X images/blueghost0.pic     3    
  124. X images/blueghost1.pic     2    
  125. X images/bluepics0.pic      3    
  126. X images/bluepics1.pic      3    
  127. X images/cirDOWN0.pic       3    
  128. X images/cirDOWN1.pic       3    
  129. X images/cirDOWN2.pic       3    
  130. X images/cirDOWN3.pic       3    
  131. X images/cirLEFT0.pic       3    
  132. X images/cirLEFT1.pic       3    
  133. X images/cirLEFT2.pic       3    
  134. X images/cirLEFT3.pic       3    
  135. X images/cirRIGHT0.pic      3    
  136. X images/cirRIGHT1.pic      3    
  137. X images/cirRIGHT2.pic      3    
  138. X images/cirRIGHT3.pic      3    
  139. X images/cirUP0.pic         4    
  140. X images/cirUP1.pic         4    
  141. X images/cirUP2.pic         4    
  142. X images/cirUP3.pic         4    
  143. X images/circleexplode0.pic 2    
  144. X images/circleexplode1.pic 2    
  145. X images/circleexplode2.pic 2    
  146. X images/circleexplode3.pic 2    
  147. X images/circleexplode4.pic 2    
  148. X images/circleexplode5.pic 2    
  149. X images/circleexplode6.pic 2    
  150. X images/circleexplode7.pic 2    
  151. X images/circleexplode8.pic 2    
  152. X images/cornerDL.pic       4    
  153. X images/cornerLU.pic       3    
  154. X images/cornerRD.pic       3    
  155. X images/cornerUR.pic       3    
  156. X images/eyesDOWN.pic       3    
  157. X images/eyesLEFT.pic       3    
  158. X images/eyesRIGHT.pic      3    
  159. X images/eyesUP.pic         4    
  160. X images/fruit1.pic         4    
  161. X images/fruit2.pic         4    
  162. X images/fruit3.pic         4    
  163. X images/fruit4.pic         4    
  164. X images/fruit5.pic         4    
  165. X images/fruit6.pic         4    
  166. X images/fruit7.pic         4    
  167. X images/fruit8.pic         4    
  168. X images/picbigdot.pic      3    
  169. X images/picsmalldot.pic    2    
  170. X main.cursor               5    
  171. X patchlevel.h              4    
  172. X release                   1    
  173. X sid_blt.c                 1    
  174. X sid_main.c                1    
  175. X sid_stuff.c               2    
  176. X sid_sun.c                 2    
  177. X sidtool.h                 2    
  178. X sidtool.help              4    
  179. X sidtool.icon              4    
  180. X sidtool.maze              2    
  181. END_OF_MANIFEST
  182. if test 2394 -ne `wc -c <MANIFEST`; then
  183.     echo shar: \"MANIFEST\" unpacked with wrong size!
  184. fi
  185. # end of overwriting check
  186. fi
  187. if test ! -d images ; then
  188.     echo shar: Creating directory \"images\"
  189.     mkdir images
  190. fi
  191. if test -f images/animate.c -a "${1}" != "-c" ; then 
  192.   echo shar: Will not over-write existing file \"images/animate.c\"
  193. else
  194. echo shar: Extracting \"images/animate.c\" \(4180 characters\)
  195. sed "s/^X//" >images/animate.c <<'END_OF_images/animate.c'
  196. X
  197. X/*  animate.c
  198. X *
  199. X *  Make the debugger.animate file from the individual icons.
  200. X *  Written by Rich Burridge - Sun Microsystems Australia (Melbourne).
  201. X *
  202. X *  Version 2.1.  -  April 1987.
  203. X *
  204. X *  No responsibility is taken for any errors or inaccuracies inherent
  205. X *  either to the comments or the code of this program, but if reported
  206. X *  to me, then an attempt will be made to fix them.
  207. X */
  208. X
  209. X#include <stdio.h>
  210. X#include <strings.h>
  211. X#include <errno.h>
  212. X
  213. X#define  CLOSE    (void) close      /* To make lint happy. */
  214. X#define  FCLOSE   (void) fclose
  215. X#define  FPRINTF  (void) fprintf
  216. X#define  SSCANF   (void) sscanf
  217. X#define  STRCPY   (void) strcpy
  218. X#define  STRNCPY  (void) strncpy
  219. X#define  WRITE    (void) write
  220. X
  221. X#define  BUFSIZE  512               /* Output buffer size in characters. */
  222. X#define  MAXLINE  256               /* Maximum length of character string. */
  223. X
  224. Xextern int errno ;
  225. X
  226. Xchar progname[MAXLINE] ;            /* Name of this program. */
  227. Xchar filename[MAXLINE] ;            /* Name of the sidtool animate file. */
  228. X
  229. Xint fd ;                            /* File descriptor for animate data. */
  230. X
  231. X
  232. Xgetline(fd,s)      /* Checks each character, and ignore's it if its NULL. */
  233. XFILE *fd ;
  234. Xchar s[MAXLINE] ;
  235. X
  236. X{
  237. X  int c,i ;
  238. X
  239. X  i = 0 ;
  240. X  while (i < MAXLINE-1 && (c = getc(fd)) != EOF && c != '\n')
  241. X  if (c != '\0') s[i++] = c ;
  242. X
  243. X  if (c == EOF) return ;
  244. X  if (c == '\n') s[i++] = c ;
  245. X  s[i] = '\0' ;
  246. X}
  247. X
  248. X
  249. Xload_cursor(name)
  250. Xchar name[MAXLINE] ;
  251. X
  252. X{
  253. X  unsigned short buf[BUFSIZE/2] ;
  254. X  int i,j,temp ;
  255. X  char arg[MAXLINE],line[MAXLINE] ;
  256. X  FILE *fin,*fopen() ;
  257. X
  258. X  if ((fin = fopen(name,"r")) == NULL)
  259. X    {
  260. X      FPRINTF(stderr,"%s: can't open %s.\n",progname,name) ;
  261. X      exit(1) ;
  262. X    }
  263. X  getline(fin,line) ;
  264. X  getline(fin,line) ;
  265. X  for (i = 0; i < 32; i++)
  266. X    {
  267. X      getline(fin,line) ;
  268. X      for (j = 0; j < 8; j++)
  269. X        {
  270. X          STRNCPY(&arg[0],&line[j*7+3],4) ;
  271. X          arg[4] = '\0' ;
  272. X          SSCANF(arg,"%X",&temp) ;
  273. X          buf[i*8+j] = (short) temp ;
  274. X        }
  275. X    }
  276. X  WRITE(fd,(char *) buf,BUFSIZE) ;
  277. X  FCLOSE(fin) ;
  278. X}
  279. X
  280. X
  281. X/*ARGSUSED*/
  282. Xmain(argc,argv)
  283. Xint argc ;
  284. Xchar *argv[] ;
  285. X
  286. X{
  287. X  STRCPY(progname,argv[0]) ;
  288. X  STRCPY(filename,"sidtool.animate") ;
  289. X  if ((fd = open(filename,2)) == -1)
  290. X    if ((fd = creat(filename,0777)) == -1)
  291. X      {
  292. X        FPRINTF(stderr,"\n%s: unable to create %s.\n",progname,filename) ;
  293. X        exit(1) ;
  294. X      }
  295. X
  296. X  load_cursor("cornerUR.pic") ;
  297. X  load_cursor("cornerRD.pic") ;
  298. X  load_cursor("cornerDL.pic") ;
  299. X  load_cursor("cornerLU.pic") ;
  300. X
  301. X  load_cursor("picbigdot.pic") ;
  302. X  load_cursor("picsmalldot.pic") ;
  303. X
  304. X  load_cursor("cirRIGHT0.pic") ;
  305. X  load_cursor("cirRIGHT1.pic") ;
  306. X  load_cursor("cirRIGHT2.pic") ;
  307. X  load_cursor("cirRIGHT3.pic") ;
  308. X
  309. X  load_cursor("cirUP0.pic") ;
  310. X  load_cursor("cirUP1.pic") ;
  311. X  load_cursor("cirUP2.pic") ;
  312. X  load_cursor("cirUP3.pic") ;
  313. X
  314. X  load_cursor("cirLEFT0.pic") ;
  315. X  load_cursor("cirLEFT1.pic") ;
  316. X  load_cursor("cirLEFT2.pic") ;
  317. X  load_cursor("cirLEFT3.pic") ;
  318. X
  319. X  load_cursor("cirDOWN0.pic") ;
  320. X  load_cursor("cirDOWN1.pic") ;
  321. X  load_cursor("cirDOWN2.pic") ;
  322. X  load_cursor("cirDOWN3.pic") ;
  323. X
  324. X  load_cursor("POKEY0.pic") ;
  325. X  load_cursor("POKEY1.pic") ;
  326. X
  327. X  load_cursor("BASHFUL0.pic") ;
  328. X  load_cursor("BASHFUL1.pic") ;
  329. X
  330. X  load_cursor("SPEEDY0.pic") ;
  331. X  load_cursor("SPEEDY1.pic") ;
  332. X
  333. X  load_cursor("SHADOW0.pic") ;
  334. X  load_cursor("SHADOW1.pic") ;
  335. X
  336. X  load_cursor("blueghost0.pic") ;
  337. X  load_cursor("blueghost1.pic") ;
  338. X
  339. X  load_cursor("bluepics0.pic") ;
  340. X  load_cursor("bluepics1.pic") ;
  341. X
  342. X  load_cursor("eyesRIGHT.pic") ;
  343. X  load_cursor("eyesUP.pic") ;
  344. X  load_cursor("eyesLEFT.pic") ;
  345. X  load_cursor("eyesDOWN.pic") ;
  346. X
  347. X  load_cursor("circleexplode0.pic") ;
  348. X  load_cursor("circleexplode1.pic") ;
  349. X  load_cursor("circleexplode2.pic") ;
  350. X  load_cursor("circleexplode3.pic") ;
  351. X  load_cursor("circleexplode4.pic") ;
  352. X  load_cursor("circleexplode5.pic") ;
  353. X  load_cursor("circleexplode6.pic") ;
  354. X  load_cursor("circleexplode7.pic") ;
  355. X  load_cursor("circleexplode8.pic") ;
  356. X
  357. X  load_cursor("fruit1.pic") ;
  358. X  load_cursor("fruit2.pic") ;
  359. X  load_cursor("fruit3.pic") ;
  360. X  load_cursor("fruit4.pic") ;
  361. X  load_cursor("fruit5.pic") ;
  362. X  load_cursor("fruit6.pic") ;
  363. X  load_cursor("fruit7.pic") ;
  364. X  load_cursor("fruit8.pic") ;
  365. X  CLOSE(fd) ;
  366. X}
  367. END_OF_images/animate.c
  368. if test 4180 -ne `wc -c <images/animate.c`; then
  369.     echo shar: \"images/animate.c\" unpacked with wrong size!
  370. fi
  371. # end of overwriting check
  372. fi
  373. if test ! -d release ; then
  374.     echo shar: Creating directory \"release\"
  375.     mkdir release
  376. fi
  377. if test -f sid_blt.c -a "${1}" != "-c" ; then 
  378.   echo shar: Will not over-write existing file \"sid_blt.c\"
  379. else
  380. echo shar: Extracting \"sid_blt.c\" \(21194 characters\)
  381. sed "s/^X//" >sid_blt.c <<'END_OF_sid_blt.c'
  382. X
  383. X/*  sid_blt.c
  384. X *
  385. X *  Various routines that do "rasterop" type graphics used by sidtool.
  386. X *
  387. X *  Written by Rich Burridge - SUN Microsystems Australia (Melbourne).
  388. X *
  389. X *  Version 2.1.  -  April 1987.
  390. X *
  391. X *  No responsibility is taken for any errors inherent either to the code
  392. X *  or the comments of this program, but if reported to me then an attempt
  393. X *  will be made to fix them.
  394. X */
  395. X
  396. X#include <stdio.h>
  397. X#include <strings.h>
  398. X#include <setjmp.h>
  399. X#include "bltstuff.h"
  400. X#include "sidtool.h"
  401. X#include <sys/types.h>
  402. X#include <sys/timeb.h>
  403. X#include <suntool/sunview.h>
  404. X#include <suntool/canvas.h>
  405. X
  406. Xextern jmp_buf exception ;
  407. Xextern int val ;
  408. X
  409. Xextern Pixfont *pf ;
  410. Xextern Pixwin *pw ;
  411. X
  412. X/* For descriptions of these variables, see sid_main.c */
  413. X
  414. Xextern BOOLEAN autoplay,demomode,remove ;
  415. X
  416. Xextern char a_name[MAXLINE],buffer[MAXLINE],but_names[7][8],h_name[MAXLINE] ;
  417. Xextern char m_name[MAXLINE],maze[XSIZE+2][YSIZE+2],names[4][MAXLINE],sc ;
  418. Xextern char titlestring[MAXLINE] ;
  419. X
  420. Xextern int autoscore,blueblink,blueincblink,boxx,boxy,button,c,circatchup ;
  421. Xextern int cirmx,cirmy,cirx,ciry,count,credits,curbluetime[MAXNUMPLAYERS+1] ;
  422. Xextern int curdir,dots[MAXNUMPLAYERS+1][XSIZE+4][YSIZE+2],dotx,doty ;
  423. Xextern int fruitchances[MAXNUMPLAYERS+1],fruiton,fruittime,fruitx,fruity ;
  424. Xextern int fruitmaze[MAXNUMPLAYERS+1],g,gamestate,height,highplayer ;
  425. Xextern int highscore,inc,movei,movej,movex,newdir,numcir[MAXNUMPLAYERS+1] ;
  426. Xextern int numdots[MAXNUMPLAYERS+1],nx,ny,oldcurdir,oldcx,oldcy,orgx,orgy ;
  427. Xextern int pausetime,player,posx,posy,progstate,score[MAXNUMPLAYERS+1] ;
  428. Xextern int sfunc,skilllevel,speed,tunnel[XSIZE+4][YSIZE+2],walls[XSIZE+6][YSIZE+1] ;
  429. Xextern int width,x,y ;
  430. X
  431. Xextern Pixrect *load_picture() ;
  432. Xextern long random() ;
  433. X
  434. Xextern Pixrect *bigdot,*bluebug[2],*bluepics[2],*bugpics[4][2],*circleexplode[9] ;
  435. Xextern Pixrect *circles[4][4],*corner[4],*curcircle,*eyes[4],*fruitpics[9] ;
  436. Xextern Pixrect *smalldot ;
  437. X
  438. Xextern struct bugrec  bugs[4] ;         /* The bad guys. */
  439. Xextern struct scorerec allhighscores[11] ;
  440. Xextern struct startrec startpos[4] ;
  441. X
  442. X
  443. Xclear_screen()
  444. X
  445. X{
  446. X  BLT_SCRN(orgx,orgy,width,height,RCLR) ;
  447. X
  448. X/*  To get over displaying the last cursor incorrectly after a cleared screen,
  449. X *  the old cursor position is forced off the screen.
  450. X */
  451. X
  452. X  oldcx = 1000 ;
  453. X  oldcy = 1000 ;
  454. X}
  455. X
  456. X
  457. Xddrawline(mx,my,dir)
  458. Xint mx,my,dir ;
  459. X
  460. X/*  Draw a maze line from mx,my in the direction dir.
  461. X *  Parameters: dir should be d,u,l,r, (or R for a thin line).
  462. X */
  463. X
  464. X{
  465. X  int x,y ;
  466. X
  467. X  TRANSPT(mx,my,x,y) ;
  468. X  switch (dir)
  469. X    {
  470. X      case 'd' :
  471. X      case 'u' : BLT_SCRN(x+SQUARE/2,y,2,SQUARE,RSET) ;
  472. X                 break ;
  473. X      case 'l' :
  474. X      case 'r' : BLT_SCRN(x,y+SQUARE/2,SQUARE,2,RSET) ;
  475. X                 break ;
  476. X      case 'R' : BLT_SCRN(x,y+SQUARE/2,SQUARE,1,RSET) ;
  477. X    }
  478. X}
  479. X
  480. X
  481. Xdrawbug(g)
  482. Xregister struct bugrec *g ;
  483. X{
  484. X  int inc,winc ;
  485. X  inc = g->scrx - GOFFSET ;
  486. X  winc = 0 ;
  487. X  if (inc < 0)
  488. X    if (inc <= 45) return ;
  489. X    else  winc = inc ;
  490. X  else if (inc > SWIDTH-45)
  491. X    if (inc > SWIDTH - 1) return ;
  492. X    else
  493. X      {
  494. X        winc = SWIDTH-45-inc ;
  495. X        inc = 0 ;
  496. X      }
  497. X  else inc = 0 ;
  498. X
  499. X  if (g->eyesonly)
  500. X    {
  501. X      BLT_MEM_TO_SCRN(g->scrx-GOFFSET-inc,g->scry-GOFFSET,
  502. X                      45+winc,21,RXOR,eyes[g->dir],-inc,0) ;
  503. X/* Fake BLT to get speed same. */
  504. X      BLT_MEM(bugpics[GIND(g)][g->pic],0,0,45+winc,21,RRPL,
  505. X              bugpics[GIND(g)][g->pic],0,0) ;
  506. X    }
  507. X  else if (g->bluetime > 0)
  508. X    {
  509. X      if ((g->bluetime < blueblink) &&
  510. X          (g->bluetime % blueincblink > blueincblink / 2))
  511. X        BLT_MEM_TO_SCRN(g->scrx-GOFFSET-inc,g->scry-GOFFSET,
  512. X                        45+winc,45,RXOR,bluepics[g->pic],-inc,0) ;
  513. X      else
  514. X        BLT_MEM_TO_SCRN(g->scrx-GOFFSET-inc,g->scry-GOFFSET,
  515. X                        45+winc,45,RXOR,bluebug[g->pic],-inc,0) ;
  516. X/* Fake BLT to get speed same. */
  517. X      BLT_MEM(eyes[g->dir],0,0,45+winc,21,RRPL,eyes[g->dir],0,0) ;
  518. X    }
  519. X  else
  520. X    { 
  521. X      BLT_MEM_TO_SCRN(g->scrx-GOFFSET-inc,g->scry-GOFFSET,
  522. X                      45+winc,45,RXOR,bugpics[GIND(g)][g->pic],-inc,0) ;
  523. X      BLT_MEM_TO_SCRN(g->scrx-GOFFSET-inc,g->scry-GOFFSET,
  524. X                      45+winc,21,RXOR,eyes[g->dir],-inc,0) ;
  525. X    }
  526. X}
  527. X
  528. X
  529. Xdrawcir(p,x,y)             /* Draw the specified screen on the screen. */
  530. Xint x,y ;
  531. XPixrect *p ;
  532. X
  533. X{
  534. X  if (x < 0) return ;                   /* Fully off left side. */
  535. X  else if (x > SWIDTH+1) return ;       /* Fully off right side. */
  536. X
  537. X  if (!(oldcx == x && oldcy == y))
  538. X    {
  539. X      BLT_MEM_TO_SCRN(oldcx-GOFFSET+5,oldcy-GOFFSET+5,45,45,RXOR,curcircle,0,0) ;
  540. X      curcircle = p ;
  541. X      BLT_MEM_TO_SCRN(x-GOFFSET+5,y-GOFFSET+5,45,45,RXOR,curcircle,0,0) ;
  542. X      oldcx = x ;
  543. X      oldcy = y ;
  544. X    }
  545. X}
  546. X
  547. X
  548. Xdrawcorner(mx,my,dir)
  549. Xint dir,mx,my ;
  550. X
  551. X/*  Draw a corner at MAZE position mx,my turning the direction dir. */
  552. X
  553. X{
  554. X  int x,y ;
  555. X
  556. X  TRANSPT(mx,my,x,y) ;
  557. X  BLT_MEM_TO_SCRN(x,y,SQUARE,SQUARE,RRPL,corner[dir],0,0) ;
  558. X}
  559. Xdrawdot(mx,my,size)        /* XORS a dot at the maze position mx,my. */
  560. Xint mx,my,size ;
  561. X
  562. X{
  563. X   TRANSPT(mx,my,mx,my) ;
  564. X   if (size == BIGDOT) BLT_MEM_TO_SCRN(mx,my,24,24,RXOR,bigdot,0,0) ;
  565. X   else if (size == SMALLDOT) BLT_MEM_TO_SCRN(mx+9,my+9,7,7,RXOR,smalldot,9,9) ;
  566. X}
  567. X
  568. X
  569. Xdrawmaze()     /* Draw the maze,the dots,the scores, etc on the screen. */
  570. X{
  571. X  int x,y ;
  572. X  clear_screen() ;
  573. X  for (y = 0; y <= YSIZE+1; y++)
  574. X    {
  575. X      walls[1][y] = 1 ;
  576. X      walls[0][y] = 1 ;
  577. X      walls[XSIZE+4][y] = 1 ;
  578. X      walls[XSIZE+5][y] = 1 ;
  579. X      for (x = 0; x <= XSIZE+1; x++) walls[x+2][y] = 0 ;
  580. X    }
  581. X  for (y = 0; y <= YSIZE+1; y++)
  582. X    for (x = 0; x <= XSIZE+1; x++)
  583. X      if ((maze[x][y] == 's') || (maze[x][y] == 'S') || (maze[x][y] == 'T'))
  584. X        drawbox(x,y) ;
  585. X      else if (maze[x][y] == 'x') walls[x+2][y] = 1 ;   /* Borders. */
  586. X  PPAUSE(pausetime*30) ;
  587. X  BLT_SCRN(XBASE-(SQUARE/2)-2,YBASE-(SQUARE/2)-2,
  588. X                  SQUARE*(XSIZE+1)+6,SQUARE*(YSIZE+1)+6,RINV) ;
  589. X  fixexits() ;
  590. X
  591. X  for (y = 1; y <= YSIZE; y++)
  592. X    for (x = 1; x <= XSIZE; x++)
  593. X      if (dots[player][x+1][y] == SMALLDOT)
  594. X        {
  595. X          PPAUSE(pausetime*5) ;
  596. X          drawdot(x,y,SMALLDOT) ;
  597. X        }
  598. X      else if (dots[player][x+1][y] == BIGDOT)
  599. X        {
  600. X          PPAUSE(pausetime*5) ;
  601. X          drawdot(x,y,BIGDOT) ;
  602. X        }
  603. X
  604. X  for (x = 1; x <= 4; x++) showplayerscore(x) ;
  605. X
  606. X  SPRINTF(buffer,"High Score (%1d)",skilllevel) ;
  607. X  WRITELN(310,20,buffer) ;
  608. X  if (!highscore) WRITELN(348,35,"0") ;
  609. X  else
  610. X    { 
  611. X      SPRINTF(buffer,"%1d0",highscore) ;
  612. X      WRITELN(348,35,buffer) ;
  613. X    }
  614. X
  615. X  for (x = 1; x <= numcir[player]; x++)
  616. X    {
  617. X      PPAUSE(pausetime*30) ;
  618. X      BLT_MEM_TO_SCRN(30+(x-1)*60,20,50,50,RXOR,circles[RIGHT][0],0,0) ;
  619. X    }
  620. X
  621. X  BLT_MEM_TO_SCRN(705,25,45,45,RRPL,fruitpics[fruitmaze[player]],0,0) ;
  622. X  BLT_SCRN(700,20,55,55,RINV) ;
  623. X  SPRINTF(buffer,"%1d0",fruitscore(fruitmaze[player])) ;
  624. X  WRITELN(710,15,buffer) ;
  625. X
  626. X  if (autoplay && (!demomode))
  627. X    {
  628. X      SCHRFUNC(RXOR) ;
  629. X      WRITELN(339,YBASE+SQUARE*16,"GAME OVER!") ;
  630. X      SCHRFUNC(RRPL) ;
  631. X      WRITELN(300,65,"Type DEL to begin") ;
  632. X      WRITELN(480,50,"Auto Score") ;
  633. X      WRITELN(489,65,"0") ;
  634. X    }
  635. X}
  636. X
  637. X
  638. Xdocredits()
  639. X{
  640. X  int g,x,y,i,j ;
  641. X  credits = 1 ;
  642. X  clear_screen() ;
  643. X  dohelp() ;
  644. X  WRITELN(5,860,"Type DEL to begin") ;
  645. X  for (i = 0; i < 100; i++) LONGPAUSE() ;
  646. X
  647. X  newbugs(0) ;
  648. X  UNTRANSPT(130,350,dotx,doty) ;
  649. X  UNTRANSPT(860,350,x,y) ;
  650. X  TRANSPT(x,y,i,ciry) ;
  651. X  BLT_SCRN(3,ciry-37,762,100,RINV) ;
  652. X
  653. X  for (g = POKEY; g <= SHADOW; g++)
  654. X    {
  655. X      bugs[g].mx = x + g * 2 ;
  656. X      bugs[g].my = doty ;
  657. X      bugs[g].dir = g ;
  658. X      TRANSPT(bugs[g].mx,bugs[g].my,bugs[g].scrx,bugs[g].scry) ;
  659. X      drawbug(&bugs[g]) ;                        /* Should be invisible. */
  660. X    }
  661. X  drawdot(dotx,doty,BIGDOT) ;
  662. X  cirx = 720 ;
  663. X  inc = 0 ;
  664. X  movei = 1 ;
  665. X  progstate = MOVELEFT ;
  666. X}
  667. X
  668. X
  669. Xmove_left()      /* Animate screen and bugs left. */
  670. X
  671. X{
  672. X  int g ;
  673. X
  674. X  if (movei % 8) cirx-- ;
  675. X  drawcir(circles[LEFT][inc],cirx,ciry) ;
  676. X  if (movei % 4 == 0) inc = (inc + 1) % 4 ;
  677. X  for (g = POKEY; g <= SHADOW; g++)
  678. X    {
  679. X      drawbug(&bugs[g]) ;               /* Erase old. */
  680. X      bugs[g].scrx-- ;
  681. X      if (movei % 13 == 0) bugs[g].pic = (bugs[g].pic + 1) % 2 ;
  682. X      if (movei % 18 == 0) bugs[g].dir = (bugs[g].dir + 1) % 4 ;
  683. X      drawbug(&bugs[g]) ;               /* Draw new. */
  684. X    }
  685. X  if (++movei > 662)
  686. X    {
  687. X      credits = 2 ;
  688. X      drawdot(dotx,doty,BIGDOT) ;
  689. X      for (g = POKEY; g <= SHADOW; g++)
  690. X        {
  691. X          drawbug(&bugs[g]) ;           /* Erase old. */
  692. X          bugs[g].bluetime = 32000 ;
  693. X          drawbug(&bugs[g]) ;           /* Draw new as blue. */
  694. X        } 
  695. X      SCHRFUNC(RXOR) ;
  696. X      movej = 200 ;
  697. X      movex = 1 ;
  698. X      movei = 1 ;
  699. X      progstate = MOVERIGHT ;
  700. X    }
  701. X}
  702. X
  703. X
  704. Xmove_right()    /* Animate eating screen and bugs right. */
  705. X
  706. X{
  707. X  int g,i ;
  708. X
  709. X   PPAUSE(8*movex) ;
  710. X   if (movei % 26) cirx++ ;
  711. X   drawcir(circles[RIGHT][inc],cirx,ciry) ;
  712. X   if (movei % 4 == 0) inc = (inc + 1) % 4 ;
  713. X   for (g = POKEY; g <= SHADOW; g++)
  714. X     if (!bugs[g].eyesonly)
  715. X       {
  716. X         drawbug(&bugs[g]) ;            /* Erase old. */
  717. X         if (movei % 2) bugs[g].scrx++ ;
  718. X         if (movei % 13 == 0) bugs[g].pic = (bugs[g].pic + 1) % 2 ;
  719. X         if (cirx >= bugs[g].scrx-20)
  720. X           {
  721. X             bugs[g].eyesonly = 1 ;
  722. X             SPRINTF(buffer,"%1d",movej) ;
  723. X             WRITELN(bugs[g].scrx-20,440,buffer) ;
  724. X             for (i = 0; i < 60; i++) LONGPAUSE() ;
  725. X             SPRINTF(buffer,"%1d",movej) ;
  726. X             WRITELN(bugs[g].scrx-20,440,buffer) ;
  727. X             movej *= 2 ;
  728. X             movex++ ;
  729. X           }
  730. X         else drawbug(&bugs[g]) ;       /* Draw new. */
  731. X       }
  732. X  if (++movei > 665)
  733. X    {
  734. X      SCHRFUNC(RRPL) ;
  735. X      for (i = 0; i < 100; i++) LONGPAUSE() ;
  736. X      credits = 0 ;
  737. X      progstate = INITGAME ;
  738. X    }
  739. X}
  740. X
  741. X
  742. Xdohelp()
  743. X
  744. X{
  745. X  int g,i,x,y ;
  746. X  char line[MAXLINE] ;
  747. X  FILE *fn ;
  748. X
  749. X  write_bold(105,100,titlestring) ;
  750. X  WRITELN(105,120,"Original version by Brad A. Myers with pictures of fruit by Terry Vavra.") ;
  751. X
  752. X  for (g = POKEY; g <= SHADOW; g++)
  753. X    {
  754. X      if (g > 1) y = YBASE + 130 ;
  755. X      else y = YBASE + 50 ;
  756. X      x = (g % 2) ? 384 : 100 ;
  757. X
  758. X      BLT_MEM_TO_SCRN(x,y,45,45,RRPL,bugpics[g][0],0,0) ;
  759. X      BLT_MEM_TO_SCRN(x,y,45,21,RXOR,eyes[g],0,0) ;
  760. X      for (i = 0; i < 40; i++) LONGPAUSE() ;
  761. X      SPRINTF(buffer,"- %s",names[g]) ;
  762. X      WRITELN(x+60,y+25,buffer) ;
  763. X      for (i = 0; i < 40; i++) LONGPAUSE() ;
  764. X    }
  765. X
  766. X  if ((fn = fopen(h_name,"r")) == NULL)
  767. X    {
  768. X      FPRINTF(stderr,"\nsidtool: can't open %s\n",h_name) ;
  769. X      exit(-1) ;
  770. X    }
  771. X  x = 105 ;
  772. X  y = 465 ;
  773. X  i = 0 ;
  774. X  while (get_string(fn,line) != -1)
  775. X    {
  776. X      WRITELN(x,i*15+y,line) ;
  777. X      i++ ;
  778. X    }
  779. X  if (!autoplay) make_control_panel() ;
  780. X  if (!autoplay) display_settings() ;
  781. X}
  782. X
  783. X
  784. Xdoplay()
  785. X
  786. X{
  787. X  if (remove)                /* Jump here if have been eaten or starting new game. */
  788. X    {
  789. X      removecircle() ;
  790. X      numcir[player]-- ;
  791. X    }
  792. X  curdir = LEFT ;             /* Jump here if got all dots. */
  793. X  fruiton = 0 ;
  794. X  sc = ' ' ;
  795. X  inc = 0 ;
  796. X  count = 1 ;
  797. X  posx = (SWIDTH / 2) - 11 ;
  798. X  posy = YBASE + SQUARE * 21 ;
  799. X  fruittime = randomrange(1000,2500) ;
  800. X  UNTRANSPT(posx,posy,cirmx,cirmy) ;
  801. X  drawcir(circles[curdir][inc],posx,posy) ;
  802. X  newbugs(1) ;
  803. X  if (demomode || !autoplay)
  804. X    {
  805. X      SCHRFUNC(RXOR) ;
  806. X      WRITELN(357,YBASE+SQUARE*16,"READY!") ;
  807. X      blinkpause() ;
  808. X      SCHRFUNC(RXOR) ;
  809. X      WRITELN(357,YBASE+SQUARE*16,"READY!") ;
  810. X      SCHRFUNC(RRPL) ;
  811. X    }
  812. X}
  813. X
  814. X
  815. Xmake_play()         /* Perform next movement of each sid tool object. */
  816. X
  817. X{
  818. X  updatebugs() ;
  819. X  if (checkcollision(cirmx,cirmy,&g)) handlecollision(&bugs[g]) ;
  820. X  if (fruittime != -1)
  821. X    {
  822. X      fruittime-- ;
  823. X      if (!fruittime) updatefruit() ;
  824. X    }
  825. X  newdir = curdir ;
  826. X  if (GCENTERED(posx,posy))
  827. X    {
  828. X      if (autoplay)
  829. X        newdir = dorandomdir(curdir,posx,posy,cirmx,cirmy,&x,&y,&nx,&ny,1) ;
  830. X      else
  831. X        switch (curdir)
  832. X          {
  833. X            case UP    :      if (sc == 'r' && !walls[cirmx+3][cirmy]) newdir = RIGHT ;
  834. X                         else if (sc == 'l' && !walls[cirmx+1][cirmy]) newdir = LEFT ;
  835. X                         else if (sc == 'd' && !walls[cirmx+2][cirmy+1]) newdir = DOWN ;
  836. X                         break ;
  837. X
  838. X            case DOWN  :      if (sc == 'r' && !walls[cirmx+3][cirmy]) newdir = RIGHT ;
  839. X                         else if (sc == 'l' && !walls[cirmx+1][cirmy]) newdir = LEFT ;
  840. X                         else if (sc == 'u' && !walls[cirmx+2][cirmy-1]) newdir = UP ;
  841. X                         break ;
  842. X
  843. X            case RIGHT :      if (sc == 'l' && !walls[cirmx+1][cirmy]) newdir = LEFT ;
  844. X                         else if (sc == 'u' && !walls[cirmx+2][cirmy-1]) newdir = UP ;
  845. X                         else if (sc == 'd' && !walls[cirmx+2][cirmy+1]) newdir = DOWN ;
  846. X                         break ;
  847. X
  848. X            case LEFT  :      if (sc == 'r' && !walls[cirmx+3][cirmy]) newdir = RIGHT ;
  849. X                         else if (sc == 'u' && !walls[cirmx+2][cirmy-1]) newdir = UP ;
  850. X                         else if (sc == 'd' && !walls[cirmx+2][cirmy+1]) newdir = DOWN ;
  851. X                         break ;
  852. X          }
  853. X    }    
  854. X  if (doinc(newdir,posx,posy,cirmx,cirmy,&x,&y,&nx,&ny)) doupdate() ;
  855. X  else
  856. X    { 
  857. X      if (!GCENTERED(posx,posy)) doupdate() ;          /* Until centered. */
  858. X      else
  859. X        { 
  860. X          if (oldcurdir != curdir)
  861. X            {
  862. X              BLT_MEM_TO_SCRN(oldcx-GOFFSET+5,oldcy-GOFFSET+5,
  863. X                              45,45,RXOR,curcircle,0,0) ;
  864. X              curcircle = circles[curdir][0] ;
  865. X              BLT_MEM_TO_SCRN(oldcx-GOFFSET+5,oldcy-GOFFSET+5,
  866. X                              45,45,RXOR,curcircle,0,0) ;
  867. X              oldcurdir = curdir ;
  868. X            }
  869. X        }    
  870. X    }    
  871. X  if (checkcollision(cirmx,cirmy,&g)) handlecollision(&bugs[g]) ;
  872. X}
  873. X
  874. X
  875. Xdoupdate()
  876. X
  877. X{
  878. X  count++ ;
  879. X  if (count % circatchup == 0) return ;       /* Go slower than bugs. */
  880. X  drawcir(circles[newdir][inc],x,y) ;
  881. X  if (count % 4 == 0) inc = (inc + 1) % 4 ;
  882. X  if (fruiton)
  883. X    if ((nx == FRUITMX) && (ny == FRUITMY)) destroyfruit() ;
  884. X  if (dots[player][nx+1][ny] != NODOT)
  885. X    {
  886. X      if (dots[player][nx+1][ny] == SMALLDOT) updatescore(1) ;
  887. X      else
  888. X        { 
  889. X          changebugs() ;
  890. X          updatescore(5) ;
  891. X        }
  892. X      numdots[player]-- ;
  893. X      drawdot(nx,ny,dots[player][nx+1][ny]) ;
  894. X      dots[player][nx+1][ny] = NODOT ;
  895. X      if (!numdots[player])
  896. X        {
  897. X          resetmaze() ;
  898. X          gamestate = FALSE ;
  899. X          progstate = RESETGAME ;
  900. X          longjmp(exception,val) ;
  901. X        }
  902. X    }    
  903. X  curdir = newdir ;
  904. X  posx = x ;
  905. X  posy = y ;
  906. X  cirmx = nx ;
  907. X  cirmy = ny ;
  908. X}
  909. X
  910. X
  911. Xexplodecircle(posx,posy)
  912. Xint posx,posy ;
  913. X{
  914. X  int i ;
  915. X  for (i = 0; i <= 8; i++)
  916. X    {
  917. X      BLT_MEM_TO_SCRN(oldcx-GOFFSET+5,oldcy-GOFFSET+5,45,45,RXOR,curcircle,0,0) ;
  918. X      curcircle = circleexplode[i] ;
  919. X      BLT_MEM_TO_SCRN(posx-GOFFSET+5,posy-GOFFSET+5,45,45,RXOR,curcircle,0,0) ;
  920. X      oldcx = posx ;
  921. X      oldcy = posy ;
  922. X      PPAUSE(pausetime*70) ;
  923. X    } 
  924. X  for (i = 0; i < 80; i++) LONGPAUSE() ;
  925. X}
  926. X
  927. X
  928. Xfixexits()
  929. X
  930. X/*  Look for tunnels on the borders.  For each, show the area as black
  931. X *  on the screen and set the walls and tunnel global variables to
  932. X *  reflect the presence of the tunnel.
  933. X */
  934. X
  935. X{
  936. X  int x,y,t ;
  937. X
  938. X  PPAUSE(pausetime*30) ;
  939. X  for (y = 1; y <= YSIZE; y++)
  940. X    if (maze[0][y] == ' ')
  941. X      {
  942. X        walls[1][y] = 0 ;
  943. X        walls[0][y] = 0 ;
  944. X        x = -1 ;
  945. X        do
  946. X          {
  947. X            x++ ;
  948. X            tunnel[x][y] = 1 ;
  949. X          }
  950. X        while (maze[x][y] == ' ') ;
  951. X        TRANSPT(0,y,x,t) ;
  952. X        BLT_SCRN(3,t-2-SQUARE/2,XBASE-(SQUARE/2)-5,SQUARE*2+6,RINV) ;
  953. X      }
  954. X
  955. X  PPAUSE(pausetime*30) ;
  956. X  for (y = 1; y <= YSIZE; y++)
  957. X    if (maze[XSIZE+1][y] == ' ')
  958. X      {
  959. X        walls[XSIZE+4][y] = 0 ;
  960. X        walls[XSIZE+5][y] = 0 ;
  961. X        x = XSIZE+1 ;
  962. X        do
  963. X          {
  964. X            x-- ;
  965. X            tunnel[x][y] = 1 ;
  966. X          }
  967. X        while (maze[x][y] == ' ') ;
  968. X        TRANSPT(0,y,x,t) ;
  969. X        BLT_SCRN(XBASE-(SQUARE/2)+SQUARE*(XSIZE+1)+4,t-2-SQUARE/2,
  970. X                           XBASE-(SQUARE/2)-5,SQUARE*2+6,RINV) ;
  971. X      }
  972. X}
  973. X
  974. X
  975. Xget_button_option()
  976. X
  977. X{
  978. X  if (!c) return ;
  979. X  else if (c >= BUT_AUTO+2 && c <= BUT_START+2)
  980. X    {
  981. X      BLT_SCRN(SQUARE/2+100*(c-2)+BUTXOFF,SQUARE/2+BUTYOFF,70,SQUARE,RINV) ;
  982. X      PPAUSE(pausetime*100) ;
  983. X      BLT_SCRN(SQUARE/2+100*(c-2)+BUTXOFF,SQUARE/2+BUTYOFF,70,SQUARE,RINV) ;
  984. X      progstate = MAKESEL ;
  985. X      button = c - 2 ;
  986. X      c = 0 ;
  987. X    }
  988. X}
  989. X
  990. X
  991. Xinitialize()
  992. X
  993. X{
  994. X  int fd,i,j,g,x,y ;
  995. X  struct timeb tp ;
  996. X  FILE *fn ;
  997. X
  998. X  ftime(&tp) ;
  999. X  for (x = 1; x < tp.millitm % 10; x++) y = (int) random() ;    /* Randomize start. */
  1000. X
  1001. X  if (!demomode) FPRINTF(stdout," Random") ;
  1002. X  if (!demomode) FPRINTF(stdout," Memory") ;
  1003. X
  1004. X  if ((fd = open(a_name,0)) == -1)
  1005. X    {
  1006. X      FPRINTF(stderr,"sidtool: unable to open %s.\n",a_name) ;
  1007. X      exit(-1) ;
  1008. X    }
  1009. X
  1010. X  for (i = UR; i <= LU; i++) corner[i] = load_picture(fd) ;
  1011. X
  1012. X  bigdot = load_picture(fd) ;
  1013. X  smalldot = load_picture(fd) ;
  1014. X
  1015. X  for (i = RIGHT; i <= DOWN; i++)
  1016. X    for (j = 0; j <= 3; j++) circles[i][j] = load_picture(fd) ;
  1017. X  for (i = POKEY; i <= SHADOW; i++)
  1018. X    for (j = 0; j <= 1; j++) bugpics[i][j] = load_picture(fd) ;
  1019. X
  1020. X  for (i = 0; i <= 1; i++) bluebug[i] = load_picture(fd) ;
  1021. X  for (i = 0; i <= 1; i++) bluepics[i] = load_picture(fd) ;
  1022. X  for (i = 0; i <= 3; i++) eyes[i] = load_picture(fd) ;
  1023. X  for (i = 0; i <= 8; i++) circleexplode[i] = load_picture(fd) ;
  1024. X  for (i = 1; i <= 8; i++) fruitpics[i] = load_picture(fd) ;
  1025. X
  1026. X  CLOSE(fd) ;
  1027. X
  1028. X  if (!demomode) FPRINTF(stdout," File") ;
  1029. X
  1030. X  if ((fn = fopen(m_name,"r")) == NULL)
  1031. X    {
  1032. X      FPRINTF(stderr,"\nsidtool: can't open %s\n",m_name) ;
  1033. X      exit(-1) ;
  1034. X    }
  1035. X
  1036. X  for (y = 0; y <= YSIZE+1; y++)
  1037. X    {
  1038. X      FGETS(buffer,MAXLINE,fn) ;
  1039. X      for (x = 0; x <= XSIZE+1; x++) maze[x][y] = buffer[x] ;
  1040. X    }
  1041. X  FCLOSE(fn) ;
  1042. X
  1043. X if (!demomode) FPRINTF(stdout," Maze") ;
  1044. X
  1045. X  TRANSPT(FRUITMX,FRUITMY,fruitx,fruity) ;
  1046. X  readallhighscores() ;
  1047. X  highscore = allhighscores[skilllevel].score ;
  1048. X  if (!demomode) FPRINTF(stdout," HighScore") ;
  1049. X
  1050. X  g = POKEY ;
  1051. X  for (y = 1; y <= YSIZE; y++)
  1052. X    for (x = 1; x <= XSIZE; x++)
  1053. X      if ((maze[x][y] >= '0') && (maze[x][y] <= '9'))
  1054. X        {
  1055. X          startpos[g].x = x ;
  1056. X          startpos[g].y = y ;
  1057. X          startpos[g].time = maze[x][y] - '0' ;
  1058. X          if (g < SHADOW) g++ ;
  1059. X          if (maze[x][y] == '0')
  1060. X            {
  1061. X              boxx = x ;
  1062. X              boxy = y ;
  1063. X            }
  1064. X        }    
  1065. X
  1066. X  if (!demomode) FPRINTF(stdout," Starting\n") ;
  1067. X  for (x = 0; x < XSIZE+3; x++)
  1068. X    for (y = 0; y < YSIZE; y++) tunnel[x][y] = 0 ;
  1069. X}
  1070. X
  1071. X
  1072. Xmake_button(x,y,but_name)
  1073. Xint x,y ;
  1074. Xchar but_name[MAXLINE] ;
  1075. X{
  1076. X  int len ;
  1077. X
  1078. X  len = strlen(but_name) * 10 ;
  1079. X  BLT_MEM_TO_SCRN(x,y,SQUARE,SQUARE,RRPL,corner[UR],0,0) ;
  1080. X  BLT_MEM_TO_SCRN(x,y+SQUARE,SQUARE,SQUARE,RRPL,corner[LU],0,0) ;
  1081. X
  1082. X  BLT_SCRN(x+SQUARE,y+SQUARE/2,len,2,RSET) ;
  1083. X  BLT_SCRN(x+SQUARE,y+SQUARE*3/2,len,2,RSET) ;
  1084. X
  1085. X  BLT_MEM_TO_SCRN(x+len,y,SQUARE,SQUARE,RRPL,corner[RD],0,0) ;
  1086. X  BLT_MEM_TO_SCRN(x+len,y+SQUARE,SQUARE,SQUARE,RRPL,corner[DL],0,0) ;
  1087. X  write_bold(x+SQUARE-5,y+SQUARE*3/2-10,but_name) ;
  1088. X}
  1089. X
  1090. X
  1091. Xmake_control_panel()
  1092. X
  1093. X{
  1094. X  int i ;
  1095. X
  1096. X  BLT_SCRN(0,0,width,YBASE-20,RCLR) ;                 /* Clear panel area. */
  1097. X  for (i = BUT_AUTO; i <= BUT_START; i++)
  1098. X    make_button(100*i+BUTXOFF,BUTYOFF,but_names[i]) ; /* Make option buttons. */
  1099. X}
  1100. X
  1101. X
  1102. Xremovecircle()
  1103. X
  1104. X{
  1105. X  BLT_MEM_TO_SCRN(30+(numcir[player]-1)*60,20,50,50,RXOR,circles[RIGHT][0],0,0) ;
  1106. X}
  1107. X
  1108. X
  1109. Xresetmaze()
  1110. X
  1111. X{
  1112. X  int i,j ;
  1113. X
  1114. X  erasebugs() ;
  1115. X  LONGPAUSE() ;
  1116. X  for (i = 1; i <= 20; i++)
  1117. X    {
  1118. X      BLT_MEM_TO_SCRN(oldcx-GOFFSET+5,oldcy-GOFFSET+5,45,45,RXOR,curcircle,0,0) ;
  1119. X      for (j = 0; j < 10; j++) LONGPAUSE() ;
  1120. X    }
  1121. X  LONGPAUSE() ;
  1122. X  if (fruitmaze[player] < 8) fruitmaze[player]++ ;
  1123. X  fruitchances[player] = 0 ;
  1124. X  setdots(player) ;
  1125. X  drawmaze() ;
  1126. X  if (curbluetime[player] > 1) curbluetime[player] -= 60 ;
  1127. X}
  1128. X
  1129. X
  1130. Xupdatefruit()
  1131. X
  1132. X{
  1133. X  Pixrect *p ;
  1134. X
  1135. X  p = fruitpics[fruitmaze[player]] ;
  1136. X  BLT_MEM_TO_SCRN(fruitx-GOFFSET,fruity-GOFFSET,45,45,RXOR,p,0,0) ;
  1137. X  if (fruiton)                        /* Turning fruit off. */
  1138. X    {
  1139. X      fruitchances[player]++ ;
  1140. X      if (fruitchances[player] > 2) fruittime = -1 ;    /* Already had 2 chances. */
  1141. X      else fruittime = randomrange(1000,2500) ;
  1142. X    }
  1143. X  else fruittime = randomrange(500,1000) ;              /* Turning fruit on. */
  1144. X  fruiton = !fruiton ;
  1145. X}
  1146. X
  1147. X
  1148. Xupdatescore(amt)
  1149. Xint amt ;
  1150. X
  1151. X{
  1152. X  int i,temp,x,y ;
  1153. X
  1154. X  if (autoplay)
  1155. X    if (!demomode)
  1156. X      {
  1157. X        autoscore += amt ;
  1158. X        SPRINTF(buffer,"%1d0",autoscore) ;
  1159. X        WRITELN(489,65,buffer) ;
  1160. X        return ;
  1161. X      }
  1162. X  temp = score[player] + amt ;
  1163. X  if (temp >= 1000)
  1164. X    if (score[player] < 1000)
  1165. X      {
  1166. X        for (i = 1; i < 7; i++)
  1167. X          {
  1168. X            BLT_MEM_TO_SCRN(oldcx-GOFFSET+5,oldcy-GOFFSET+5,45,45,RXOR,curcircle,0,0) ;
  1169. X            for (i = 0; i < 10; i++) LONGPAUSE() ;
  1170. X          }
  1171. X        numcir[player]++ ;
  1172. X        BLT_MEM_TO_SCRN(30+(numcir[player]-1)*60,20,50,50,RXOR,circles[RIGHT][0],0,0) ;
  1173. X      }
  1174. X  score[player] = temp ;
  1175. X  x = (player % 2) ? 217 : 597 ;
  1176. X  y = (player < 3) ? 40  : 80 ;
  1177. X  SPRINTF(buffer,"%1d0",score[player]) ;
  1178. X  WRITELN(x,y,buffer) ;
  1179. X  if (score[player] > highscore)
  1180. X    {
  1181. X      highplayer = player ;
  1182. X      highscore = score[player] ;
  1183. X      SPRINTF(buffer,"%1d0",highscore) ;
  1184. X      WRITELN(348,35,buffer) ;
  1185. X    }
  1186. X}
  1187. END_OF_sid_blt.c
  1188. if test 21194 -ne `wc -c <sid_blt.c`; then
  1189.     echo shar: \"sid_blt.c\" unpacked with wrong size!
  1190. fi
  1191. # end of overwriting check
  1192. fi
  1193. if test -f sid_main.c -a "${1}" != "-c" ; then 
  1194.   echo shar: Will not over-write existing file \"sid_main.c\"
  1195. else
  1196. echo shar: Extracting \"sid_main.c\" \(23265 characters\)
  1197. sed "s/^X//" >sid_main.c <<'END_OF_sid_main.c'
  1198. X/*  sid_main.c
  1199. X *
  1200. X *  Sid Tool - the Sun Interactive Debugger program.
  1201. X *
  1202. X *  Written by Rich Burridge - Sun Microsystems Australia (Melbourne).
  1203. X *
  1204. X *  Version 2.1.  -  April 1987.
  1205. X *
  1206. X *  No responsibility is taken for any errors inherent either to the code
  1207. X *  or the comments of this program, but if reported to me then an attempt
  1208. X *  will be made to fix them.
  1209. X */
  1210. X
  1211. X#include <stdio.h>
  1212. X#include <strings.h>
  1213. X#include <setjmp.h>
  1214. X#include <sys/fcntl.h>
  1215. X#include "bltstuff.h"
  1216. X#include "patchlevel.h"
  1217. X#include "sidtool.h"
  1218. X#include <suntool/sunview.h>
  1219. X#include <suntool/canvas.h>
  1220. X
  1221. XCanvas canvas ;
  1222. XFrame base_frame ;
  1223. XPixwin *pw ;
  1224. X
  1225. Xjmp_buf exception ;
  1226. Xint val ;
  1227. X
  1228. Xextern etext() ;
  1229. Xextern restore_screen() ;
  1230. X
  1231. XNotify_value main_loop() ;
  1232. Xvoid event_proc() ;
  1233. X
  1234. Xshort sid_image[] = {
  1235. X#include "sidtool.icon"
  1236. X} ;
  1237. XDEFINE_ICON_FROM_IMAGE(sid_icon,sid_image) ;
  1238. X
  1239. Xstruct scorerec allhighscores[11] ;
  1240. Xstruct startrec startpos[4] ;
  1241. Xstruct bugrec bugs[4] ;
  1242. X
  1243. Xchar but_names[7][8] =    /*  Control panel stuff. */
  1244. X     {
  1245. X       " Auto  ",
  1246. X       " Help  ",
  1247. X       " Level ",
  1248. X       "Players",
  1249. X       " Quit  ",
  1250. X       " Scores",
  1251. X       " Start "
  1252. X     } ;
  1253. X
  1254. Xchar names[4][MAXLINE] =
  1255. X     {
  1256. X       "Time Dependencies",
  1257. X       "Uninitialized Variables",
  1258. X       "Fence Posts",
  1259. X       "Multiple Process Interaction"
  1260. X     } ;
  1261. X
  1262. Xchar old_key_vals[4][MAXLINE] ;       /* Function key string values to save. */
  1263. Xchar new_key_vals[4][MAXLINE] =       /* Function key values used by sidtool. */
  1264. X     {
  1265. X       "u",                  /* R8  - UPARROW. */
  1266. X       "d",                  /* R14 - DOWNARROW. */
  1267. X       "l",                  /* R10 - LEFTARROW. */
  1268. X       "r",                  /* R12 - RIGHTARROW. */
  1269. X     } ;
  1270. X
  1271. Xchar maze[XSIZE+2][YSIZE+2] ;
  1272. Xchar sc,buffer[MAXLINE] ;
  1273. Xchar s_name[MAXLINE] ;     /* Score file name. */
  1274. Xchar a_name[MAXLINE] ;     /* Animate file name. */
  1275. Xchar h_name[MAXLINE] ;     /* Help file name. */
  1276. Xchar m_name[MAXLINE] ;     /* Maze file name. */
  1277. Xchar thisscore[MAXLINE] ;  /* User name for new high score. */
  1278. Xchar titlestring[MAXLINE] ;
  1279. X
  1280. Xint blueblink,blueincblink,boxx,boxy,fruittime,fruitx,fruity,numplayers ;
  1281. Xint skilllevel,circatchup,pausetime,highplayer,autoscore,lastnumplayers ;
  1282. Xint curbluetime[MAXNUMPLAYERS+1],score[MAXNUMPLAYERS+1] ;
  1283. Xint numcir[MAXNUMPLAYERS+1],fruitmaze[MAXNUMPLAYERS+1] ;
  1284. Xint numdots[MAXNUMPLAYERS+1],fruitchances[MAXNUMPLAYERS+1] ;
  1285. Xint fruitsgotten[MAXNUMPLAYERS+1][9] ;
  1286. Xint highscore,player,cirmx,cirmy,bugssincedot ;
  1287. Xint walls[XSIZE+6][YSIZE+1] ;
  1288. Xint dots[MAXNUMPLAYERS+1][XSIZE+4][YSIZE+2] ;
  1289. Xint tunnel[XSIZE+4][YSIZE+2] ;
  1290. X
  1291. Xint key_stations[9] = {69, 113, 91, 93} ;
  1292. X
  1293. Xint button ;       /* Indicates users selection from control panel. */
  1294. Xint c ;            /* Contains latest mouse or keyboard interaction. */
  1295. Xint canvasfd ;     /* File descriptor for canvas subwindow. */
  1296. Xint curdir ;       /* Current direction of the screen. */
  1297. Xint oldcurdir ;    /* Old direction of the screen. */
  1298. Xint g,newdir,posx,posy,x,y,nx,ny,count,inc ;
  1299. Xint orgx,orgy,width,height ;    /* Position and dimension of window. */
  1300. Xint oldcx,oldcy ;  /* Old position of the screen. */
  1301. Xint on = 0 ;       /* Current blinking state of score. */
  1302. Xint canvasflags ;  /* Used to setup no delay for canvas. */
  1303. Xint credits ;      /* Direction of credits if on. */
  1304. Xint cirx ;         /* X position of screen during credits. */
  1305. Xint ciry ;         /* Y position of screen during credits. */
  1306. Xint dotx ;         /* X position of BIGDOT during credits. */
  1307. Xint doty ;         /* Y position of BIGDOT during credits. */
  1308. Xint movei,movej,movex ; /* Used to animate screen during credits. */
  1309. Xint progstate ;    /* State machine for main loop. */
  1310. Xint redraw;        /* If non-zero, then screen should be redrawn. */
  1311. Xint savedstate ;   /* State machine value after Ctrl S. */
  1312. Xint scorei ;       /* No of chars in high score user name. */
  1313. Xint speed ;        /* Class (speed) of this Sun machine. */
  1314. Xint started ;      /* Indicates if we have started a game. */
  1315. X
  1316. XBOOLEAN autoplay ;
  1317. XBOOLEAN demomode ;
  1318. XBOOLEAN fruiton ;
  1319. XBOOLEAN gamestate ;     /* State of the game, 1 = remove circle. */
  1320. XBOOLEAN remove ;        /* Whether Sun screen should be removed. */
  1321. XFILE *fopen() ;
  1322. X
  1323. Xextern int sfunc ;      /* Used by SCHRFUNC for cursor function. */
  1324. Xextern Pixfont *pf ;
  1325. X
  1326. X
  1327. Xdrawbox(mx,my)
  1328. Xint mx,my ;
  1329. X
  1330. X/*  Draws a box starting at maze position mx, my. Mx, my should be an
  1331. X *  s or S position in maze. Travels around path until reach x or s.
  1332. X */
  1333. X
  1334. X{
  1335. X  int last ;
  1336. X
  1337. X  last = 'r' ;
  1338. X  PPAUSE(pausetime*20) ;
  1339. X  walls[mx+2][my] = 1 ;
  1340. X  if (maze[mx][my] == 's') drawcorner(mx,my,UR) ;
  1341. X  else if (maze[mx][my] == 'S') ddrawline(mx,my,'r') ;
  1342. X  else if (maze[mx][my] == 'T')
  1343. X    {
  1344. X      ddrawline(mx,my,'l') ;
  1345. X      mx -= 2 ;
  1346. X      last = 'l' ;
  1347. X    }
  1348. X   mx++ ;
  1349. X   for (;;)
  1350. X     {
  1351. X       PPAUSE(2*pausetime) ;
  1352. X       walls[mx+2][my] = 1 ;
  1353. X       switch (maze[mx][my])
  1354. X         {
  1355. X           case 's' :
  1356. X           case 'S' :
  1357. X           case 'T' : return ;
  1358. X           case 'd' : if (last == 'r') drawcorner(mx,my,RD) ;
  1359. X                      else if (last == 'l') drawcorner(mx,my,UR) ;
  1360. X                      else ddrawline(mx,my,'d') ;
  1361. X                      last = 'd' ;
  1362. X                      my++ ;
  1363. X                      break ;
  1364. X           case 'l' : if (last == 'd') drawcorner(mx,my,DL) ;
  1365. X                      else if (last == 'u') drawcorner(mx,my,RD) ;
  1366. X                      else ddrawline(mx,my,'l') ;
  1367. X                      last = 'l' ;
  1368. X                      mx-- ;
  1369. X                      break ;
  1370. X           case 'r' :
  1371. X           case 'R' : if (last == 'u') drawcorner(mx,my,UR) ;
  1372. X                      else if (last == 'd') drawcorner(mx,my,LU) ;
  1373. X                      else ddrawline(mx,my,maze[mx][my]) ;
  1374. X                      last = 'r' ;
  1375. X                      mx++ ;
  1376. X                      break ;
  1377. X           case 'u' : if (last == 'l') drawcorner(mx,my,LU) ;
  1378. X                      else if (last == 'r') drawcorner(mx,my,DL) ;
  1379. X                      else ddrawline(mx,my,'u') ;
  1380. X                      last = 'u' ;
  1381. X                      my-- ;
  1382. X                      break ;
  1383. X           case 'x' : ddrawline(mx,my,last) ;
  1384. X                      return ;
  1385. X         }
  1386. X      }   
  1387. X}
  1388. X
  1389. X
  1390. Xsetdots(player)
  1391. Xint player ;
  1392. X
  1393. X{
  1394. X  int x,y ;
  1395. X
  1396. X  for (y = 1; y <= YSIZE; y++)
  1397. X    {
  1398. X      dots[player][0][y] = NODOT ;
  1399. X      dots[player][1][y] = NODOT ;
  1400. X      dots[player][XSIZE+2][y] = NODOT ;
  1401. X      dots[player][XSIZE+3][y] = NODOT ;
  1402. X      for (x = 1; x <= XSIZE; x++)
  1403. X        if (maze[x][y] == '.')
  1404. X          {
  1405. X            dots[player][x+1][y] = SMALLDOT ;
  1406. X            numdots[player]++ ;
  1407. X          }
  1408. X        else if (maze[x][y] == '*')
  1409. X          {
  1410. X            dots[player][x+1][y] = BIGDOT ;
  1411. X            numdots[player]++ ;
  1412. X          }
  1413. X        else dots[player][x+1][y] = NODOT ;
  1414. X    }
  1415. X}
  1416. X
  1417. X
  1418. Xreadallhighscores()
  1419. X
  1420. X/*  Reads all high scores and names into the global table allhighscores.
  1421. X *  If file not found, then sets all high scores to zero.
  1422. X */
  1423. X
  1424. X{
  1425. X  int hsfile,level ;
  1426. X
  1427. X  if ((hsfile = open(s_name,2)) == -1)
  1428. X    {
  1429. X      if ((hsfile = creat(s_name,0777)) == -1)
  1430. X        {
  1431. X          FPRINTF(stderr,"sidtool: unable to create highscores file.\n") ;
  1432. X          return ;
  1433. X        }
  1434. X
  1435. X      for (level = 0; level <= 10; level++)
  1436. X        {
  1437. X          allhighscores[level].score = 0 ;
  1438. X          STRCPY(allhighscores[level].who," ") ;
  1439. X          puths(hsfile,allhighscores[level]) ;
  1440. X        }
  1441. X    }
  1442. X  else
  1443. X    for (level = 1; level <= 10; level++) geths(hsfile,&allhighscores[level]) ;
  1444. X  CLOSE(hsfile) ;
  1445. X}
  1446. X
  1447. X
  1448. Xwritehighscore()
  1449. X
  1450. X/*  If highscore is better than old high score for this skill level then
  1451. X *  asks for player's name and enters name and score into table and writes file.
  1452. X */
  1453. X
  1454. X{
  1455. X  if ((highscore >= allhighscores[skilllevel].score) &&
  1456. X        (highplayer != -1) && (!demomode))
  1457. X    {
  1458. X      clear_screen() ;
  1459. X      SPRINTF(buffer,"Player %1d has beaten the high score for skill level %1d.",
  1460. X                     highplayer,skilllevel) ;
  1461. X      WRITELN(100,140,buffer) ;
  1462. X      if (allhighscores[skilllevel].score)
  1463. X        {
  1464. X          SPRINTF(buffer,"The old record was %1d0 held by: %s.",
  1465. X                         allhighscores[skilllevel].score,
  1466. X                         allhighscores[skilllevel].who) ;
  1467. X          WRITELN(100,160,buffer) ;
  1468. X        }
  1469. X      SPRINTF(buffer,"Type player %1d's name or initials: ",highplayer) ;
  1470. X      WRITELN(100,200,buffer) ;
  1471. X      scorei = 0 ;
  1472. X      c = 0 ;
  1473. X      thisscore[scorei] = '_' ;
  1474. X      thisscore[scorei+1] = '\0' ;
  1475. X      WRITELN(370,200,thisscore) ;
  1476. X      progstate = NEXTLINE ;
  1477. X    }
  1478. X  else progstate = DOCREDIT ;
  1479. X}
  1480. X
  1481. X
  1482. Xgetnewscore(x,y)      /* Get new user name for highscore. */
  1483. Xint x,y ;
  1484. X
  1485. X{
  1486. X  if (c)
  1487. X    {
  1488. X      switch (c)
  1489. X        {
  1490. X          case BSPACE :
  1491. X          case DEL    : if (scorei)
  1492. X                          {   
  1493. X                            scorei-- ;
  1494. X                            thisscore[scorei] = ' ' ;
  1495. X                            thisscore[scorei+1] = '\0' ;
  1496. X                            WRITELN(x,y,thisscore) ;
  1497. X                            thisscore[scorei] = '\0' ;
  1498. X                          } 
  1499. X                        break ;
  1500. X          case CR     : thisscore[scorei] = '\0' ;
  1501. X                        if (!scorei) WRITELN(100,220,"   ** No name given. **") ;
  1502. X                        else
  1503. X                          {
  1504. X                            STRCPY(allhighscores[skilllevel].who,thisscore) ;
  1505. X                            savescorefile() ;
  1506. X                            progstate = DOCREDIT ;
  1507. X                          }
  1508. X                        break ;
  1509. X          default     : if (c < ' ') break ;
  1510. X                        thisscore[scorei++] = c ;
  1511. X                        thisscore[scorei] = '\0' ;
  1512. X                        WRITELN(x,y,thisscore) ;
  1513. X        }
  1514. X      c = 0 ;
  1515. X    }
  1516. X}
  1517. X
  1518. X
  1519. Xsavescorefile()     /* Write away new highscore values. */
  1520. X
  1521. X{
  1522. X  int fd,level ;
  1523. X
  1524. X  allhighscores[skilllevel].score = highscore ;
  1525. X  if ((fd = open(s_name,1)) == -1)
  1526. X    FPRINTF(stderr,"sidtool: unable to open highscores file.\n") ;
  1527. X  else
  1528. X    { 
  1529. X      for (level = 1; level <= 10; level++) puths(fd,allhighscores[level]) ;
  1530. X      CLOSE(fd) ;
  1531. X    }
  1532. X}
  1533. X
  1534. X
  1535. Xinitgame()
  1536. X
  1537. X{
  1538. X  int i,j ;
  1539. X
  1540. X  if (autoplay) autoscore = 0 ;
  1541. X  pausetime = -skilllevel * 20 + (speed * 100) ;
  1542. X  circatchup = -skilllevel * 4 + 46 ;
  1543. X  highplayer = -1 ;
  1544. X  for (j = 1; j < MAXNUMPLAYERS; j++)
  1545. X    {
  1546. X      numdots[j] = 0 ;
  1547. X      numcir[j] = 3 ;
  1548. X      fruitchances[j] = 0 ;
  1549. X      setdots(j) ;
  1550. X      curbluetime[j] = 1 + (-skilllevel * 60 + 900) ;
  1551. X      if (!autoplay)
  1552. X        {
  1553. X          score[j] = 0 ;
  1554. X          if (demomode) fruitmaze[j] = 8 ;
  1555. X          else fruitmaze[j] = 1 ;
  1556. X          for (i = 1; i < 8; i++)
  1557. X            if (demomode) fruitsgotten[j][i] = 1 ;
  1558. X            else fruitsgotten[j][i] = 0 ;
  1559. X        }
  1560. X    }
  1561. X}
  1562. X
  1563. X
  1564. Xshowplayerscore(player)
  1565. Xint player ;
  1566. X
  1567. X{
  1568. X  int x,y ;
  1569. X
  1570. X  SCHRFUNC(RXOR) ;
  1571. X  x = (player % 2) ? 190 : 570 ;
  1572. X  y = (player < 3) ? 25  : 65 ;
  1573. X  SPRINTF(buffer,"  Player %1d ",player) ;
  1574. X  WRITELN(x,y,buffer) ;
  1575. X  if (!score[player]) WRITELN(x+27,y+15,"0") ;
  1576. X  else
  1577. X    {
  1578. X      SPRINTF(buffer,"%1d0",score[player]) ;
  1579. X      WRITELN(x+27,y+15,buffer) ;
  1580. X    }
  1581. X  SCHRFUNC(RRPL) ;
  1582. X}
  1583. X
  1584. X
  1585. Xblinkpause()
  1586. X
  1587. X/*  Wait a while and check keyboard for commands while blinking current players score. */
  1588. X
  1589. X{
  1590. X  int i,j ;
  1591. X
  1592. X  on = 1 ;
  1593. X  if (!autoplay)
  1594. X    for (i = 1; i <= 16; i++)
  1595. X      {
  1596. X        showplayerscore(player) ;
  1597. X        on = !on ;
  1598. X        for (j = 0; j < 10; j++) LONGPAUSE() ;
  1599. X      }
  1600. X}
  1601. X
  1602. X
  1603. Xdoinc(dir,posx,posy,mx,my,x,y,nx,ny)
  1604. Xint dir,posx,posy,mx,my,*x,*y,*nx,*ny ;
  1605. X
  1606. X{
  1607. X  register int status,tx,ty ;
  1608. X
  1609. X  *x = posx ;
  1610. X  *y = posy ;
  1611. X  tx = mx ;
  1612. X  ty = my ;
  1613. X
  1614. X  switch (dir)
  1615. X    {
  1616. X      case UP    : *y = posy - 2 ;
  1617. X                   ty = my - 1 ;
  1618. X                   break ;
  1619. X      case DOWN  : *y = posy + 2 ;
  1620. X                   ty = my + 1 ;
  1621. X                   break ;
  1622. X      case LEFT  : *x = posx - 2 ;
  1623. X                   tx = mx - 1 ;
  1624. X                   break ;
  1625. X      case RIGHT : *x = posx + 2 ;
  1626. X                   tx = mx + 1 ;
  1627. X                   break ;
  1628. X    }
  1629. X  UNTRANSPT(*x,*y,*nx,*ny) ;
  1630. X  if (tx == -2) tx = XSIZE + 2 ;
  1631. X  else if (tx == XSIZE + 3) tx = -1 ;
  1632. X  status = 1 ;
  1633. X
  1634. X  if ((*nx == -2) && (dir == LEFT))
  1635. X    {
  1636. X      *nx = XSIZE + 2 ;
  1637. X      TRANSPT(*nx,*ny,*x,*y) ;
  1638. X    }
  1639. X  else if ((*nx == XSIZE + 3) && (dir == RIGHT))
  1640. X    {
  1641. X      *nx = -1 ;
  1642. X      TRANSPT(*nx,*ny,*x,*y) ;
  1643. X    }
  1644. X  else if (!(walls[*nx+2][*ny] ||
  1645. X            (GCENTERED(posx,posy) && walls[tx+2][ty]))) /* do nothing. */ ;
  1646. X  else status = 0 ;
  1647. X  return(status) ;
  1648. X}
  1649. X
  1650. X
  1651. Xheadto(destx,desty,scrx,scry,mx,my,dir,x,y,nx,ny)   /* Only called when GCENTERED. */
  1652. Xint *dir,destx,desty,scrx,scry,mx,my,*x,*y,*nx,*ny ;
  1653. X
  1654. X{
  1655. X  int dirar[5],rev,i,s,xinc,yinc ;
  1656. X
  1657. X  rev = REVERSEDIR(*dir) ;
  1658. X  xinc = mx - destx ;
  1659. X  yinc = my - desty ;
  1660. X  if (abs(xinc) > abs(yinc)) s = 2 ;
  1661. X  else s = 1 ;
  1662. X  if (xinc < 0)
  1663. X    {
  1664. X      dirar[3-s] = RIGHT ;
  1665. X      dirar[s+2] = LEFT ;
  1666. X    }
  1667. X  else
  1668. X    {
  1669. X      dirar[3-s] = LEFT ;
  1670. X      dirar[s+2] = RIGHT ;
  1671. X    }
  1672. X  if (yinc < 0)
  1673. X    {
  1674. X      dirar[s] = DOWN ;
  1675. X      dirar[5-s] = UP ;
  1676. X    }
  1677. X  else
  1678. X    {
  1679. X      dirar[s] = UP ;
  1680. X      dirar[5-s] = DOWN ;
  1681. X    }
  1682. X
  1683. X  for (i = 1; i <= 4; i++)     /* Adjust so reverse is last choice. */
  1684. X    if (dirar[i] == rev)
  1685. X      {
  1686. X        for (s = i; s <= 3; s++) dirar[s] = dirar[s+1] ;
  1687. X        dirar[4] = rev ;
  1688. X        break ;
  1689. X      }
  1690. X
  1691. X  for (s = 1; s <= 4; s++)
  1692. X    {
  1693. X      if (checkinc(dirar[s],mx,my))
  1694. X        {
  1695. X          *dir = dirar[s] ;
  1696. X          DOINC(*dir,scrx,scry,mx,my,x,y,nx,ny) ;
  1697. X          return ;
  1698. X        }
  1699. X    }
  1700. X}
  1701. X
  1702. X
  1703. Xdorandomdir(dir,scrx,scry,mx,my,x,y,nx,ny,ranrange)
  1704. Xint dir,scrx,scry,mx,my,*x,*y,*nx,*ny,ranrange ;
  1705. X
  1706. X{
  1707. X  int i,test,newdir,rev,status ;
  1708. X
  1709. X  test = randomrange(1,ranrange) ;
  1710. X  rev = REVERSEDIR(dir) ;
  1711. X  if ((test == 1) || (!checkinc(dir,mx,my)))
  1712. X    {
  1713. X      newdir = randomrange(0,3) ;
  1714. X      for (i = 0; i <= 3; i++)
  1715. X        {
  1716. X          if (newdir != rev)
  1717. X            if (checkinc(newdir,mx,my))
  1718. X              {
  1719. X                status = newdir ;
  1720. X                DOINC(newdir,scrx,scry,mx,my,x,y,nx,ny) ;
  1721. X                return(status) ;
  1722. X              }
  1723. X          newdir = (newdir + 1) % 4 ;
  1724. X        }
  1725. X    }
  1726. X  else
  1727. X    {
  1728. X      DOINC(dir,scrx,scry,mx,my,x,y,nx,ny) ;
  1729. X      status = dir ;
  1730. X    }
  1731. X  return(status) ;
  1732. X}
  1733. X
  1734. X
  1735. Xupdatebugs()
  1736. X
  1737. X/* Move each bug one bit in appropriate direction; change direction if appropriate. */
  1738. X
  1739. X{
  1740. X  register struct bugrec *g ;
  1741. X  int bemean ;
  1742. X
  1743. X  for (g = &bugs[POKEY]; g <= &bugs[SHADOW]; g++)
  1744. X    {
  1745. X      g->count++ ;
  1746. X      if (g->inbox || g->intunnel)
  1747. X        if (g->count % 2 == 0) return ;               /* Slow in box. */
  1748. X
  1749. X      if (g->bluetime > 0)
  1750. X        {
  1751. X          if (g->count % CATCHUP == 0) return ;       /* Go slower if blue. */
  1752. X          drawbug(g) ;                        /* Erase old before change blueTime. */
  1753. X          g->bluetime-- ;
  1754. X        }
  1755. X      else drawbug(g) ;                    /* Erase old. */
  1756. X
  1757. X      if (g->count % 7 == 0) g->pic = (g->pic + 1) % 2 ;
  1758. X
  1759. X      if (GCENTERED(g->scrx,g->scry))
  1760. X        {
  1761. X          g->intunnel = tunnel[g->mx+1][g->my] ;
  1762. X
  1763. X          if (!g->bluetime)
  1764. X            if (skilllevel < 5)
  1765. X              bemean = randomrange(0,10-skilllevel-GIND(g)) == 0 ;
  1766. X            else bemean = randomrange(0,skilllevel-5+GIND(g)) != 0 ;
  1767. X          else bemean = FALSE ;
  1768. X
  1769. X          if (g->inbox)
  1770. X            if ((g->mx == boxx) && (g->my == boxy)) g->inbox = FALSE ;
  1771. X
  1772. X          if (g->eyesonly)
  1773. X            {
  1774. X              if ((!g->enteringbox) && (g->mx == boxx) && (g->my == boxy))
  1775. X                {
  1776. X                  g->dir = DOWN ;
  1777. X                  g->enteringbox = TRUE ;
  1778. X                  DOINC(g->dir,g->scrx,g->scry,g->mx,g->my,&x,&y,&nx,&ny) ; 
  1779. X                }
  1780. X              else if (g->enteringbox)
  1781. X                if ((g->my > boxy + 2) &&
  1782. X                    (!doinc(g->dir,g->scrx,g->scry,g->mx,g->my,&x,&y,&nx,&ny)))
  1783. X                  {
  1784. X                    g->dir = UP ;
  1785. X                    g->enteringbox = FALSE ;
  1786. X                    g->inbox = TRUE ;
  1787. X                    g->eyesonly = FALSE ;
  1788. X                    DOINC(g->dir,g->scrx,g->scry,g->mx,g->my,&x,&y,&nx,&ny) ;
  1789. X                  }
  1790. X                else DOINC(g->dir,g->scrx,g->scry,g->mx,g->my,&x,&y,&nx,&ny) ;
  1791. X              else headto(boxx,boxy,g->scrx,g->scry,g->mx,g->my,&g->dir,&x,&y,&nx,&ny) ;
  1792. X            }
  1793. X          else if (g->boxtime)          /* Inbox should be true also. */
  1794. X            {
  1795. X              g->boxtime-- ;
  1796. X              if (g->boxtime < 0)       /* Heading to exit. */
  1797. X                {
  1798. X                  if (g->mx == boxx)    /* Found exit. */
  1799. X                    {
  1800. X                      g->boxtime = 0 ;
  1801. X                      g->dir = UP ;
  1802. X                      DOINC(g->dir,g->scrx,g->scry,g->mx,g->my,&x,&y,&nx,&ny) ;
  1803. X                    }
  1804. X                  else headto(boxx,boxy,g->scrx,g->scry,g->mx,g->my,&g->dir,&x,&y,&nx,&ny) ;
  1805. X                }
  1806. X              else if (!g->boxtime)      /* Start heading to exit. */
  1807. X                {
  1808. X                  g->boxtime = -1 ;
  1809. X                  headto(boxx,boxy,g->scrx,g->scry,g->mx,g->my,&g->dir,&x,&y,&nx,&ny) ;
  1810. X                }
  1811. X              else if (!doinc(g->dir,g->scrx,g->scry,g->mx,g->my,&x,&y,&nx,&ny))
  1812. X                {
  1813. X                  g->dir = REVERSEDIR(g->dir) ; /* Bounce up a down a while. */
  1814. X                  DOINC(g->dir,g->scrx,g->scry,g->mx,g->my,&x,&y,&nx,&ny) ;
  1815. X                }
  1816. X            }
  1817. X           else if (g->inbox)     /* Must be leaving the box; just keep going. */
  1818. X                  DOINC(g->dir,g->scrx,g->scry,
  1819. X                        g->mx,g->my,&x,&y,&nx,&ny) ;
  1820. X           else if (bemean)              /* Chase the circle. */
  1821. X             headto(cirmx,cirmy,g->scrx,g->scry,g->mx,g->my,&g->dir,&x,&y,&nx,&ny) ;
  1822. X           else g->dir = dorandomdir(g->dir,g->scrx,g->scry,
  1823. X                                            g->mx,g->my,&x,&y,&nx,&ny,3) ;
  1824. X         }
  1825. X       else DOINC(g->dir,g->scrx,g->scry,g->mx,g->my,&x,&y,&nx,&ny) ;
  1826. X
  1827. X       g->scrx = x ;
  1828. X       g->scry = y ;
  1829. X       g->mx = nx ;
  1830. X       g->my = ny ;
  1831. X       drawbug(g) ;                /* Draw new. */
  1832. X    }
  1833. X}
  1834. X
  1835. X
  1836. Xmain(argc,argv)
  1837. Xint argc ;
  1838. Xchar *argv[] ;
  1839. X
  1840. X{
  1841. X  get_options(argc,argv) ;          /* Get command line options. */
  1842. X  function_keys(KEY_SET) ;          /* Set direction arrow function keys. */
  1843. X
  1844. X  if ((pf = pf_open("/usr/lib/fonts/fixedwidthfonts/screen.r.14")) == NULL)
  1845. X    {
  1846. X      FPRINTF("Can't open screen.r.14 font.\n") ;
  1847. X      function_keys(KEY_RESET) ;
  1848. X      exit(1) ;
  1849. X    }
  1850. X
  1851. X  base_frame = window_create(NULL, FRAME,
  1852. X                             FRAME_LABEL, titlestring,
  1853. X                             FRAME_ICON, &sid_icon,
  1854. X                             WIN_X, orgx,
  1855. X                             WIN_Y, orgy,
  1856. X                             WIN_WIDTH, width,
  1857. X                             WIN_HEIGHT, height,
  1858. X                             WIN_FONT, pf,
  1859. X                             FRAME_ARGS, argc, argv,
  1860. X                             0) ;
  1861. X  canvas = window_create(base_frame, CANVAS,
  1862. X                         CANVAS_RETAINED, FALSE,
  1863. X                         CANVAS_FAST_MONO, TRUE,
  1864. X                         CANVAS_REPAINT_PROC, restore_screen,
  1865. X                         WIN_EVENT_PROC, event_proc,
  1866. X                         0) ;
  1867. X
  1868. X  window_set(canvas, WIN_CONSUME_KBD_EVENTS, WIN_ASCII_EVENTS, 0) ;
  1869. X  window_set(canvas, WIN_CONSUME_KBD_EVENTS, WIN_LEFT_KEYS, 0) ;
  1870. X  window_set(canvas,WIN_IGNORE_PICK_EVENT,LOC_MOVE,0) ;
  1871. X
  1872. X  pw = canvas_pixwin(canvas) ;
  1873. X
  1874. X/* Set up no delay for events within the canvas. */
  1875. X  canvasfd = (int) window_get(canvas,WIN_FD) ;
  1876. X  canvasflags = fcntl(canvasfd,F_GETFL,0) ;
  1877. X  canvasflags |= FNDELAY ;
  1878. X  FCNTL(canvasfd,F_SETFL,canvasflags) ;
  1879. X
  1880. X  sfunc = PIX_SRC ;                  /* Used by WRITELN. */
  1881. X  iocursormode(OFFCURSOR) ;
  1882. X
  1883. X  initrandom() ;
  1884. X  numplayers = 1 ;
  1885. X  skilllevel = 5 ;
  1886. X  lastnumplayers = 1 ;
  1887. X  autoplay = FALSE ;
  1888. X  initgame() ;
  1889. X  initialize() ;
  1890. X  redraw = 0 ;                       /* Don't redraw the screen, the first time. */
  1891. X  started = 1 ;
  1892. X  autoplay = 1 ;
  1893. X  progstate = STARTUP ;
  1894. X
  1895. X  (void) notify_set_itimer_func(base_frame, main_loop, ITIMER_REAL,
  1896. X                        &NOTIFY_POLLING_ITIMER, ((struct itimerval *) 0)) ;
  1897. X  window_main_loop(base_frame) ;
  1898. X  function_keys(KEY_RESET) ;         /* Restore direction arrow function keys. */
  1899. X  exit(0) ;
  1900. X}
  1901. X
  1902. X
  1903. X/*ARGSUSED*/
  1904. Xvoid
  1905. Xevent_proc(window,event,arg)
  1906. XWindow *window ;
  1907. XEvent *event ;
  1908. Xcaddr_t arg ;
  1909. X
  1910. X{
  1911. X  int x,y ;     /* Position of mouse when button pressed. */
  1912. X  int i ;
  1913. X
  1914. X  if (event_is_ascii(event))
  1915. X    {
  1916. X      c = event_id(event) ;
  1917. X      if (progstate == NEXTLINE) return ;
  1918. X      if ((c == DEL) && !demomode)
  1919. X        {
  1920. X          c = 0 ;
  1921. X          started = 0 ;
  1922. X          progstate = DELHIT ;
  1923. X          return ;
  1924. X        }
  1925. X      else if (c == CTRLS)
  1926. X        {
  1927. X          savedstate = progstate ;
  1928. X          progstate = CTRLSHIT ;
  1929. X          return ;
  1930. X        }
  1931. X      else if (c == CTRLQ)
  1932. X        {
  1933. X          progstate = savedstate ;
  1934. X          return ;
  1935. X        }
  1936. X      else if (!autoplay) sc = c ;
  1937. X    }
  1938. X  else if (event_is_down(event) && event_is_button(event))
  1939. X    {
  1940. X      x = event_x(event) ;
  1941. X      y = event_y(event) ;
  1942. X      if (y > BUTYOFF && y < BUTYOFF+2*SQUARE)
  1943. X        for (i = BUT_AUTO; i <= BUT_START; i++)
  1944. X          if (x > BUTXOFF+i*100 && x < BUTXOFF+i*100+120) c = i+2 ;
  1945. X    }
  1946. X}
  1947. X
  1948. X
  1949. X/*ARGSUSED*/
  1950. Xstatic Notify_value
  1951. Xmain_loop(client, itimer_type)
  1952. XNotify_client client ;
  1953. Xint itimer_type ;
  1954. X
  1955. X{
  1956. X  int i ;
  1957. X
  1958. X  switch (progstate)
  1959. X    {
  1960. X      case STARTUP   : SETJMP(exception) ;
  1961. X                       if (progstate) break ;
  1962. X                       else progstate = INITGAME ;
  1963. X                       break ;
  1964. X      case INITGAME  : initgame() ;
  1965. X                       progstate = PLAY ;
  1966. X                       break ;
  1967. X      case PLAY      : play() ;
  1968. X                       progstate = DOPLAY ;
  1969. X                       break ;
  1970. X      case DOPLAY    : doplay() ;
  1971. X                       progstate = MAKEPLAY ;
  1972. X                       break ;
  1973. X      case MAKEPLAY  : make_play() ;
  1974. X                       break ;
  1975. X      case DOREST    : numplayers = 1 ;
  1976. X                       progstate = HIGHSCORE ;
  1977. X                       break ;
  1978. X      case HIGHSCORE : writehighscore() ;
  1979. X                       break ;
  1980. X      case NEXTLINE  : getnewscore(365,200) ;
  1981. X                       break ;
  1982. X      case DOCREDIT  : if (!demomode)
  1983. X                         {
  1984. X                           dohighscores() ;
  1985. X                           WRITELN(5,860,"Type DEL to begin") ;
  1986. X                           for (i = 1; i <= 200; i++) LONGPAUSE() ;
  1987. X                         }
  1988. X                       docredits() ;
  1989. X                       break ;
  1990. X      case MOVELEFT  : move_left() ;
  1991. X                       break ;
  1992. X      case MOVERIGHT : move_right() ;
  1993. X                       break ;
  1994. X      case DELHIT    : autoplay = FALSE ;
  1995. X                       iocursormode(TRACKCURSOR) ;
  1996. X                       make_control_panel() ;
  1997. X                       display_settings() ;
  1998. X                       progstate = GETBUT ;
  1999. X                       break ;
  2000. X      case GETBUT    : get_button_option() ;
  2001. X                       break ;
  2002. X      case MAKESEL   : make_selection() ;
  2003. X                       break ;
  2004. X      case DOLEAVE   : SCHRFUNC(RRPL) ;
  2005. X                       autoplay = TRUE ;
  2006. X                       progstate = DOREST ;
  2007. X                       break ;
  2008. X      case RESETGAME : remove = gamestate ;
  2009. X                       progstate = DOPLAY ;
  2010. X                       break ;
  2011. X      case CTRLSHIT  : break ;
  2012. X    } 
  2013. X}
  2014. END_OF_sid_main.c
  2015. if test 23265 -ne `wc -c <sid_main.c`; then
  2016.     echo shar: \"sid_main.c\" unpacked with wrong size!
  2017. fi
  2018. # end of overwriting check
  2019. fi
  2020. echo shar: End of archive 1 \(of 5\).
  2021. cp /dev/null ark1isdone
  2022. MISSING=""
  2023. for I in 1 2 3 4 5 ; do
  2024.     if test ! -f ark${I}isdone ; then
  2025.     MISSING="${MISSING} ${I}"
  2026.     fi
  2027. done
  2028. if test "${MISSING}" = "" ; then
  2029.     echo You have unpacked all 5 archives.
  2030.     rm -f ark[1-9]isdone
  2031. else
  2032.     echo You still need to unpack the following archives:
  2033.     echo "        " ${MISSING}
  2034. fi
  2035. ##  End of shell archive.
  2036. exit 0
  2037.