[comp.sources.atari.st] v01i093: starchrt -- Diffs to Unix starchart program for ST part02/02

koreth@ssyx.ucsc.edu (Steven Grimm) (01/19/89)

Submitted-by: cs.buffalo.edu!sigmast!dgy
Posting-number: Volume 1, Issue 93
Archive-name: starchrt/part02

#!/bin/sh
# this is part 2 of a multipart archive
# do not concatenate these parts, unpack them in order with /bin/sh
# file planet.dif continued
#
CurArch=2
if test ! -r s2_seq_.tmp
then echo "Please unpack part 1 first!"
     exit 1; fi
( read Scheck
  if test "$Scheck" != $CurArch
  then echo "Please unpack part $Scheck next!"
       exit 1;
  else exit 0; fi
) < s2_seq_.tmp || exit 1
sed 's/^X//' << 'SHAR_EOF' >> planet.dif
X! }
X! #endif /* ST_MWC */
X  exit(0);
X  } /* end of program main */
X  
X***************
X*** 1023,1031 ****
X--- 1075,1089 ----
X  double aint(z)
X  	double z;
X  {
X+ #ifdef ST_MWC /* In Mark Williams C ints are 16 bits long, so use longs */
X+ 	long trunk;
X+ 	
X+ 	trunk = (long)z;
X+ #else /* !ST_MWC */
X  	int trunk;
X  	
X  	trunk = (int)z;
X+ #endif /* ST_MWC */
X  	z = (double) trunk;
X  	return(z);
X  }
SHAR_EOF
chmod 0600 planet.dif || echo "restore of planet.dif fails"
sed 's/^X//' << 'SHAR_EOF' > staranim.c &&
X#include <stdio.h>
X#include <osbind.h> /* Needed for Cconws() and Crawcin() */
X
Xextern char *getenv();
X
Xint daysinmonth[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
X
Xmain(argc, argv)
Xint argc;
Xchar *argv[];
X{
X     int debug = 0, i, j, month;
X     char *eargv[20], *eenv[2], label[10], picture[14], sday[2], smonth[3];
X
X     if (argc < 4) {
X          Cconws("Usage: ");
X          Cconws(argv[0]);
X          Cconws(" <month> <year> <arguments ... >\r\n");
X          Cconws("       <month> is an integer from 1 to 12.\r\n");
X          Cconws("       <year> is a four-digit integer.\r\n");
X          Cconws("       <arguments> are passed to starst.\r\n");
X          Cconws("Portions of this program, copyright 1984, ");
X          Cconws("Mark Williams Company.\r\n");
X          /* We want to hold the screen if invoked from the GEM desktop;
X             the desktop doesn't usually set any environment variables,
X             and if getenv() does find anything, it's probably a NULL string. */
X          if (((getenv("PATH")) == 0) || (strlen(getenv("PATH")) == 0)) {
X               Cconws("press any key to continue:  ");
X               i = Crawcin(); /* Read raw character input */
X          }
X          exit(1);
X     }
X     if (strlen(argv[2]) != 4) {
X          Cconws("Year must be in 4-digit form (e.g. 1988).\r\n");
X          if (((getenv("PATH")) == 0) || (strlen(getenv("PATH")) == 0)) {
X               Cconws("press any key to continue:  ");
X               i = Crawcin(); /* Read raw character input */
X          }
X          exit(1);
X     }
X     if ((month = atoi(argv[1])) > 100) {
X          month -= 100;
X          ++debug;
X     }
X     if ((month < 1) || (month > 12)) {
X          Cconws("Month must be an integer from 1 to 12.\r\n");
X          if (((getenv("PATH")) == 0) || (strlen(getenv("PATH")) == 0)) {
X               Cconws("press any key to continue:  ");
X               i = Crawcin(); /* Read raw character input */
X          }
X          exit(1);
X     }
X     for (i = 1; i <= daysinmonth[month - 1]; i++) {
X          sprintf(smonth, "%d", month);
X          sprintf(sday, "%d", i);
X          eargv[0]  = "planet.ttp";
X          eargv[1]  = "-y";
X          eargv[2]  = argv[2];
X          eargv[3]  = "-m";
X          eargv[4]  = smonth;
X          eargv[5]  = "-d";
X          eargv[6]  = sday;
X          eargv[7]  = "-t";
X          eargv[8]  = "12";
X          eargv[9]  = "-z";
X          eargv[10] = "0";
X          eargv[11] = eenv[1] = 0;
X          eenv[0] = "PATH=."; /* Make programs think they came from shell */
X          if (debug) {
X               Cconws("\r\n");
X               for (j = 0; eargv[j] != '\0'; j++) {
X                    Cconws(eargv[j]);
X                    Cconws(" ");
X               }
X          } else {
X               execve(eargv[0], eargv, eenv);
X          }
X          sprintf(label, "%02d/%02d/%2s", month, i, argv[2] + 2);
X          sprintf(picture, "star%02d%02d.pi1", month, i);
X          eargv[0]  = "starst.ttp";
X          eargv[1]  = "-t";
X          eargv[2]  = label;
X          eargv[3]  = "-x";
X          eargv[4]  = picture;
X          for (j = 3; j < argc; j++) {
X               eargv[j + 2] = argv[j];
X          }
X          eargv[j + 2] = '\0';
X          if (debug) {
X               Cconws("\r\n");
X               for (j = 0; eargv[j] != '\0'; j++) {
X                    Cconws(eargv[j]);
X                    Cconws(" ");
X               }
X               Cconws("\r\n");
X          } else {
X               execve(eargv[0], eargv, eenv);
X          }
X     } /* End of "for" loop */
X     if (debug && ((getenv("PATH")) == 0) || (strlen(getenv("PATH")) == 0)) {
X          Cconws("press any key to continue:  ");
X          i = Crawcin(); /* Read raw character input */
X     }
X}
SHAR_EOF
chmod 0600 staranim.c || echo "restore of staranim.c fails"
sed 's/^X//' << 'SHAR_EOF' > starargs.c &&
X/*
X** Written by Dave Yearke (dgy@sigmast), September 1988.
X** Portions of this program (c) Mark Williams Company.
X*/
X
X#include <osbind.h> /* Needed for Cconws() and Crawcin() */
X
Xmain()
X{
X     char *argptr, command[130], *eargv[20], *eenv[2];
X     int i;
X
X     Cconws("STARARGS - Utility for running Starchart ");
X     Cconws("software from the desktop.\r\n");
X     Cconws("Portions of this program, copyright 1984, ");
X     Cconws("Mark Williams Company.");
X     for (;;) {
X          *command = 128; /* Number of characters Cconrs() should read */
X          Cursconf(1, 0); /* Show cursor */
X          Cconws("\r\n\nPlease enter the full name of the program to be run ");
X          Cconws("(e.g. starst.ttp)\r\n");
X          Cconws("and its arguments, or an empty line to quit:\r\n");
X          Cconrs(command); /* Read an edited string from standard input */
X          if (*(command + 1) == 0) /* Number of chars actually read */
X               exit();
X          Cconws("\r\n");
X          command[*(command + 1) + 2] = '\0'; /* Make sure it's terminated */
X          i = 0;
X          argptr = command + 2;
X          do {
X               eargv[i] = argptr;
X               while ((*++argptr != ' ') && (*argptr != '\0'))
X                    ; /* Browse until space or end of string */
X               if (*argptr == ' ') /* If we found a space */
X                    *argptr++ = '\0'; /* End the string preceding this point */
X               while ((*argptr == ' ') && (*argptr != '\0'))
X                    ++argptr; /* Browse until non-space or end of string */
X               Cconws(eargv[i++]);
X               Cconws(" ");
X          } while (*argptr != '\0');
X          eargv[i] = eenv[1] = 0;
X          eenv[0] = "PATH=."; /* The programs will think they're being run */
X          Cconws("\r\n");     /* from a shell. */
X          execve(eargv[0], eargv, eenv);
X     }
X}
SHAR_EOF
chmod 0600 starargs.c || echo "restore of starargs.c fails"
sed 's/^X//' << 'SHAR_EOF' > starchrt.dif &&
X*** ../starchart/starchart.c	Mon Sep 19 09:12:20 1988
X--- starchrt.c	Mon Sep 26 23:50:39 1988
X***************
X*** 58,72 ****
X--- 58,87 ----
X   ![11] the -g flag sets a mag limit for star proper names, else use codes
X   */
X  
X+ #ifdef ST_MWC /* Mark Williams C for the Atari ST */
X+ #define SYSV /* MWC is almost SYSV compatible */
X+ #endif /* ST_MWC */
X+ 
X  #include <stdio.h>
X  #include <math.h>
X  #ifndef SYSV
X  #include <strings.h>
X  #else
X+ #define index strchr
X+ #ifndef SYSVR3 /* System V release 3 doesn't have this header file */
X+ #ifndef ST_MWC
X  #include <string.h>
X+ #else /* ST_MWC */
X+ char *strchr();
X+ #endif /* ST_MWC */
X+ #endif /* SYSVR3 */
X  #endif
X  #include <ctype.h>
X+ #ifndef ST_MWC
X  #include "starchart.h"
X+ #else /* ST_MWC */
X+ #include "starchrt.h"
X+ #endif /* ST_MWC */
X  
X  /*
X   * default datasets are local, unless defined in Makefile
X***************
X*** 122,127 ****
X--- 137,149 ----
X  int annodetail, objdetail;	/* flags to control output */
X  int annoswitch, objswitch;	/* switches as seen on command line */
X  float olat, olon;		/* save areas for track clipping */		
X+ #ifdef ST_MWC
X+ #ifdef INTERACTIVE
X+ extern int oldrez; /* Used to see if we've initialized the screen. */
X+ int exit_and_save = FALSE; /* Don't wait for keypress when done, save file */
X+ char picturefile[15]; /* into "picturefile" (def = star.pi1) and exit */
X+ #endif /* INTERACTIVE */
X+ #endif /* ST_MWC */
X  
X  /* the code */
X  
X***************
X*** 253,258 ****
X--- 275,297 ----
X  		case 'b': bigflag = TRUE; break;
X  		case 'a': annoswitch = TRUE; break;
X  		case 'o': objswitch = TRUE; break;
X+ #ifdef ST_MWC
X+ #ifdef INTERACTIVE
X+                 /* Exit immediately, saving the picture in a DEGAS or
X+                    NeoChrome file (Chosen by .pi1 or .neo extender */
X+ 		case 'x': exit_and_save = TRUE;
X+ 		          if (((j+1) < argc) && (argv[j+1][0] != '-'))
X+                                strcpy(picturefile, argv[++j]);
X+                           else
X+                                strcpy(picturefile, "star.pi1");
X+                           break;
X+ #else /* !INTERACTIVE */
X+                 /* Help for the GEM Desktop, which cannot redirect. */
X+ 		case 'x': if (((j+1) < argc) && (argv[j+1][0] != '-'))
X+                           freopen(argv[++j], "wb", stdout);
X+                           break;
X+ #endif /* INTERACTIVE */
X+ #endif /* ST_MWC */
X  		default:  die("unknown switch - %s", argv[j]); break;
X  		}
X  	    if (j == argc) die("trailing command line flag - %s", argv[j-1]);
X***************
X*** 373,379 ****
X--- 412,426 ----
X      if (!title) title = "LEGEND";
X      rastr(ras, chart->racen);
X      declstr(dls, chart->dlcen);
X+ #ifdef ST_MWC
X+ #ifdef INTERACTIVE /* This bleeds over into the thumbnail, so trim it */
X+     sprintf(outstr, "(%s,%s)", ras, dls, chart->maglim);
X+ #else /* !INTERACTIVE */
X      sprintf(outstr, "(%s,%s lim: %2.1f)", ras, dls, chart->maglim);
X+ #endif /* INTERACTIVE */
X+ #else /* !ST_MWC */
X+     sprintf(outstr, "(%s,%s lim: %2.1f)", ras, dls, chart->maglim);
X+ #endif /* ST_MWC */
X  /*
X   * there are reports that large point sizes (eg "16", below) cause characters
X   * to overlap on some (pic?) output devices. To fix, set values to "10".
X***************
X*** 417,422 ****
X--- 464,481 ----
X  
X      pvecsize(10); pvecsyms( 95,75,"double");   pdrawStar( 65,75, 2, 'D', NULL);
X      pvecsize(10); pvecsyms(260,75,"variable"); pdrawStar(230,75, 2, 'V', NULL);
X+ #ifdef ST_MWC
X+ #ifdef INTERACTIVE /* Adjust the legend so symbols don't overlap labels */
X+     pvecsize(10); pvecsyms( 95,50,"planet");   pdrawPlan( 75,50, 1, 'S', NULL);
X+ 					       pdrawPlan( 55,50, 1, 's', NULL);
X+ 					       pdrawPlan( 35,50, 1, 'V', NULL);
X+     pvecsize(10); pvecsyms(260,50,"galaxy");   pdrawGalx(240,50, 1, 'E', NULL);
X+ 					       pdrawGalx(215,50, 1, 'S', NULL);
X+     pvecsize(10); pvecsyms( 95,25,"nebula");   pdrawNebu( 75,25, 1, 'D', NULL);
X+ 					       pdrawNebu( 45,25, 1, 'P', NULL);
X+     pvecsize(10); pvecsyms(260,25,"cluster");  pdrawClus(240,25, 1, 'O', NULL);
X+ 					       pdrawClus(215,25, 1, 'G', NULL);
X+ #else /* !INTERACTIVE */
X      pvecsize(10); pvecsyms( 95,50,"planet");   pdrawPlan( 65,50, 1, 'S', NULL);
X      pvecsize(10); pvecsyms(260,50,"galaxy");   pdrawGalx(230,50, 1, 'E', NULL);
X  					       pdrawGalx(205,50, 1, 'S', NULL);
X***************
X*** 424,429 ****
X--- 483,490 ----
X  					       pdrawNebu( 40,25, 1, 'P', NULL);
X      pvecsize(10); pvecsyms(260,25,"cluster");  pdrawClus(230,25, 1, 'O', NULL);
X  					       pdrawClus(205,25, 1, 'G', NULL);
X+ #endif /* INTERACTIVE */
X+ #endif /* ST_MWC */
X      }
X  
X  chartbanner(chart)
X***************
X*** 495,501 ****
X  	if (sbuf[11] != 0)
X  	code[0] = sbuf[15];
X  	subcode[0] = sbuf[16];
X! 	color [0] = '\0'; strcpy (color, "  "); /* set unknowns to blanks */
X  	label [0] = '\0';
X  	name [0] = '\0'; strncat (name, &sbuf[17], strlen (&sbuf [17]) - 1);
X  	}
X--- 556,562 ----
X  	if (sbuf[11] != 0)
X  	code[0] = sbuf[15];
X  	subcode[0] = sbuf[16];
X! 	strcpy(color, "  "); /* set unknowns to blanks */
X  	label [0] = '\0';
X  	name [0] = '\0'; strncat (name, &sbuf[17], strlen (&sbuf [17]) - 1);
X  	}
X***************
X*** 554,566 ****
X--- 615,635 ----
X  /*
X   * extract color, label and name
X   */
X+ #ifdef ST_MWC
X+                 len = strlen(sbuf);
X+                 if (len > 16)
X+ #endif /* ST_MWC */
X  		strncat (color, &sbuf[16], 2);
X+ #ifdef ST_MWC
X+                 if (len > 18)
X+ #endif /* ST_MWC */
X  		strncat (label, &sbuf[18], strlen (&sbuf [18]) - 1);
X  		if  ((len = strlen (label)) > 5)
X  			{
X  			strncat (name, &label[5], len - 5);
X  			label [5] = '\0';
X  			}
X+                 break;
X  	    }
X  	}
X      return(0);
X***************
X*** 896,901 ****
X--- 965,971 ----
X      return (new -= b);
X      }
X  
X+ #ifndef INTERACTIVE
X  die(a,b)
X      char *a, *b;
X      {
X***************
X*** 904,909 ****
X--- 974,980 ----
X      fprintf(stderr,"\n");
X      exit(1);
X      }
X+ #endif /* !INTERACTIVE */
X  
X  #define LINELEN 80
X  static char legend[LINELEN];
SHAR_EOF
chmod 0600 starchrt.dif || echo "restore of starchrt.dif fails"
sed 's/^X//' << 'SHAR_EOF' > starlase.dif &&
X*** ../starchart/starlaser.c	Mon Sep 19 09:11:19 1988
X--- starlase.c	Mon Sep 26 23:41:46 1988
X***************
X*** 25,31 ****
X--- 25,35 ----
X  */
X  
X  #include <stdio.h>
X+ #ifndef ST_MWC
X  #include "starchart.h"
X+ #else /* ST_MWC */
X+ #include "starchrt.h"
X+ #endif /* ST_MWC */
X  
X  char *calloc ();
X  
SHAR_EOF
chmod 0600 starlase.dif || echo "restore of starlase.dif fails"
sed 's/^X//' << 'SHAR_EOF' > starpost.dif &&
X*** ../starchart/starpost.c	Mon Sep 19 09:11:50 1988
X--- starpost.c	Mon Sep 26 23:43:16 1988
X***************
X*** 15,21 ****
X--- 15,25 ----
X   */
X  
X  #include <stdio.h>
X+ #ifndef ST_MWC
X  #include "starchart.h"
X+ #else /* ST_MWC */
X+ #include "starchrt.h"
X+ #endif /* ST_MWC */
X  
X  /*
X   * Chart parameters (limiting magnitude and window x,y,w,h)
SHAR_EOF
chmod 0600 starpost.dif || echo "restore of starpost.dif fails"
sed 's/^X//' << 'SHAR_EOF' > starst.c &&
X/*
X** Atari ST driver for starchart.
X** Works on color systems only, compiled with Mark Williams C.
X** Written by Dave Yearke (dgy@sigmast), September 1988.
X** Portions of this program (c) Mark Williams Company.
X** Thanks to the authors of the other starchart drivers for giving
X** me some examples to work from.
X*/
X
Xextern int exit_and_save;
Xextern char *getenv(), picturefile[];
X
X#include <ctype.h>    /* isprint(), iscntrl(), etc. */
X#include <linea.h>    /* Line A (low-level graphics) routines. */
X#include <osbind.h>   /* Operating system bindings */
X#include <vdibind.h>  /* The virtual device interface routines */
X#include <xbios.h>    /* Extended BIOS bindings */
X#include "starchrt.h" /* Starchart information */
X
X/* Global line A variables used by vdi; MUST be included */
Xint contrl[12], intin[128], ptsin[128], intout[128], ptsout[128];
X/* Array used by vs_clip() */
Xint cliparray[] = { 1, 1, 319, 199 };
X/* Arrays used by v_opvwk() */
Xint work_in[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2 };
Xint work_out[57];
X
X#define TRUE 1
X#define NULL 0
X
X/*
X** Starchart was designed for 1024x768 pixels.  These macros scale the
X** image to the 320x200 Atari ST low-resolution (16-color) mode.  Also,
X** the y coord is subtracted from 200 so the image isn't upside-down.
X*/
X#define xadjust(x) ((x) * 0.3125)
X#define yadjust(y) (200 - ((y) * 0.2604167))
X
Xstruct la_font *fontp; /* Line A font header. */
Xchar line[100], linemode, *p;
Xchar scr_wrk[1024];
Xint vdihandle; /* Virtual device's handle */
X
Xint CURRX, CURRY, currez, old_color[16], oldrez = 99; /* 99 is impossible! */
X
X/*
X** Settings for the palette, given as RGB, 3 bits for each color (512 total).
X** I tried to use different registers for different types of objects so they
X** could be set individually (for example, in DEGAS you could blink a register
X** for an object you're trying to point out).
X*/
Xint new_color[16] = { 0x000,   /* Black      - Background color */
X                      0x777,   /* White      - 1st and higher mag. stars */
X                      0x666,   /* White      - 2nd mag. stars */
X                      0x555,   /* White      - 3rd mag. stars */
X                      0x444,   /* White      - 4th mag. stars */
X                      0x333,   /* White      - 5th mag. stars */
X                      0x222,   /* White      - 6th and lower mag. stars */
X                      0x222,   /* White      - Nebulae, Galaxies, Clusters */
X                      0x007,   /* Blue       - 1st and higher mag. stars */
X                      0x700,   /* Red        - 1st and higher mag. stars */
X                      0x770,   /* Yellow     - Sol */
X                      0x704,   /* Pink       - Inferior Planets */
X                      0x404,   /* Purple     - Superior Planets */
X                      0x020,   /* Dark Green - Dotted lines */
X                      0x200,   /* Dark Red   - Hyphenated lines */
X                      0x003 }; /* Deep Blue  - Text and borders */
X
X/*
X** These are reverse-image colors for the background and stars, used when the
X** 'r' key is hit when the program pauses before exiting.  Switching these
X** registers makes a nice output image for a screen dump to a printer.
X*/
Xint rev_color[8]  = { 0x777,   /* White      - Background color */
X                      0x000,   /* Black      - 1st and higher mag. stars */
X                      0x222,   /* Black      - 2nd mag. stars */
X                      0x333,   /* Black      - 3rd mag. stars */
X                      0x444,   /* Black      - 4th mag. stars */
X                      0x555,   /* Black      - 5th mag. stars */
X                      0x666,   /* Black      - 6th and lower mag. stars */
X                      0x666 }; /* Black      - Nebulae, Galaxies, Clusters */
X
X/*
X** Chart parameters (limiting magnitude and window x,y,w,h)
X*/
X
Xmapblock thumbnail =	{ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
X			3.2, 1.0, 2.05, 420, 35, 480, 195, 0.0 };
X
Xmapblock master =	{ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
X			8.0, 2.0, 2.05, 20, 265, 880, 500, 0.0 };
X
Xmapblock bigmaster =	{ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
X			8.0, 2.5, 2.5, 20,  65, 880, 700, 0.0 };
X
X/*
X** Generic functions
X*/
X
X/*
X** Initialize the graphics mode
X*/
Xvecopen()
X{
X     int i;
X
X     Cconws("\033H\033J"); /* Clear the screen */
X     if ((oldrez = Getrez()) == GR_HIGH) {
X          die("%s\n", "Sorry, this works on color systems only.");
X          Pterm(1);
X     } else if (oldrez == GR_MED)
X          Setscreen((char *)-1, (char *)-1, GR_LOW); /* Set low resolution */
X     currez = GR_LOW;
X     appl_init(); /* Initialize the application and register it with AES */
X     vdihandle = graf_handle(&i, &i, &i, &i); /* Get a VDI handle */
X     v_opnvwk(work_in, &vdihandle, work_out); /* Open the virtual workscreen */
X     vs_clip(vdihandle, 1, cliparray); /* Set the clipping rectangle */
X     for (i = 0; i < 16; i++) /* Save and set the palette */
X          old_color[i] = Setcolor(i, new_color[i]);
X
X     linea0(); /* Initialize the line A routines */
X     lineaa(); /* Hide mouse pointer */
X     Cursconf(0, 0); /* Hide cursor */
X
X     WMODE = 0; /* Writing mode = replace */
X     STYLE = 0; /* Normal Letters */
X     SRCY = 0; /* Y coord of character in font */
X     LITEMSK = 0x5555; /* Lightening and skewing masks for text */
X     SKEWMSK = 0x1111;
X     TEXTFG = 15; /* Text foreground dark blue */
X     SCRTCHP = scr_wrk; /* Scratch area for graphics */
X     LNMASK = -1; /* Solid lines */
X     WEIGHT = 1; /* Thickening factor for lines */
X     LSTLIN = -1;
X}
X
X/*
X** Clean up
X*/
Xvecclose ()
X{
X     register int i;
X
X     if (exit_and_save)
X          savepic();
X     else
X          while (1) { /* Loop if 'r' is pressed, return for anything else */
X               switch (i = Crawcin()) { /* Wait for keypress before quitting */
X               case 'r': /* Reverse the color registers */
X                    if (Setcolor(0, -1) == 0) { /* If normal, reverse it */
X                         for (i = 0; i < 8; i++)
X                              Setcolor(i, rev_color[i]);
X                    } else { /* Make it normal */
X                         for (i = 0; i < 8; i++)
X                              Setcolor(i, new_color[i]);
X                    }
X                    continue; /* Restart the loop */
X                    break;
X               case 's': /* Save as a DEGAS picture */
X                    strcpy(picturefile, "star.pi1");
X                    savepic();
X                    break;
X               case 'S': /* Save as a NeoChrome picture */
X                    strcpy(picturefile, "star.neo");
X                    savepic();
X                    break;
X               default:
X                    break;
X               }
X               break;
X          }
X     vecreset();
X}
X
X/*
X** Restore the screen
X*/
Xvecreset()
X{
X     int i;
X
X     v_clsvwk(vdihandle); /* Close the virtual workscreen */
X     appl_exit(); /* Remove the application from AES */
X     Cconws("\033H\033J"); /* Clear the screen */
X     Setscreen((char *)-1, (char *)-1, oldrez); /* Set resolution */
X     for (i = 0; i < 16; i++) /* Set the colors back to their saved values */
X          Setcolor(i, old_color[i]);
X     if (((getenv("PATH")) == 0) || (strlen(getenv("PATH")) == 0))
X          linea9(); /* Show mouse pointer */
X     else /* If called from a shell */
X          Cursconf(1, 0); /* Show cursor */
X}
X
X/*
X** Save the screen as a DEGAS or NeoChrome picture
X*/
Xsavepic()
X{
X     int neo = 0, file; /* Assume DEGAS file */
X
X     if (strrchr(picturefile, '.') != NULL) { /* Extender given */
X          if ((!strncmp(picturefile + strrchr(picturefile, '.'), ".neo", 4)) ||
X             (!strncmp(picturefile + strrchr(picturefile, '.'), ".NEO", 4)))
X               ++neo; /* Save as a NeoChrome picture */
X     } else
X          strcat(picturefile, ".pi1");
X     if ((file = creat(picturefile, 0)) == -1)
X          die("Cannot open %s.", picturefile);
X     if (neo) /* NeoChrome has two extra null bytes at the beginning */
X          if (write(file, &currez, 2) != 2)
X               die("Write failure on file %s.", picturefile);
X     if (write(file, &currez, 2) != 2) /* Write the resolution */
X          die("Write failure on file %s.", picturefile);
X     if (write(file, &new_color[0], 32) != 32) /* Write the palette info */
X          die("Write failure on file %s.", picturefile);
X     if (neo) /* NeoChrome has a 128-byte header, so we'll pad with 94 bytes */
X          for (neo = 0; neo < 47; ++neo) /* Recycle the variable "neo" */
X               if (write(file, &currez, 2) != 2)
X                    die("Write failure on file %s.", picturefile);
X     if (write(file, Physbase(), 32000) != 32000) /* Write the screen */
X          die("Write failure on file %s.", picturefile);
X     close(file); /* Done!  (that wasn't too bad, was it?) */
X}
X
X/*
X** This function is duplicated in starchrt.c for non-ST versions, using
X** the INTERACTIVE manifest constant.
X*/
Xdie(a,b)
Xchar *a, *b;
X{
X     char buf[80];
X     int i;
X
X     if (oldrez != 99) /* See if we ever initialized the screen. */
X         vecreset(); /* Reset the screen to something sane */
X     if (!strncmp(b, "\nusage", 6)) { /* Sub in the ST's usage */
X          Cconws("\n\rusage:\tstar* [ Ra Dcl Scale Title Maglim Labellim ]\n");
X          Cconws("\ror\tstar* [ -r Ra -d Dcl -s Scale -t Title -m Maglim -l ");
X          Cconws("Labellim -f x.str ]\n\ror\tstar* [ -c con (3 or 4 letters ");
X          Cconws("chosen from con.loc) -l ... ]\n\ror\tstarst -x [ file.PI1 ");
X          Cconws("| file.NEO ] ... (to exit and save screen)\n\n\r");
X          Cconws("Portions of this program, copyright 1984, ");
X          Cconws("Mark Williams Company");
X     } else {
X          sprintf(buf, a, b);
X          Cconws(buf);
X     }
X     Cconws("\n\r"); /* Cconws does not map \n into \n\r */
X     /* We want to hold the screen if invoked from the GEM desktop;
X        the desktop doesn't usually set any environment variables,
X        and if getenv() does find anything, it's probably a NULL string. */
X     if (((getenv("PATH")) == 0) || (strlen(getenv("PATH")) == 0)) {
X          Cconws("press any key to continue:  "); /* Hold screen if desktop */
X          i = Crawcin(); /* Read raw character input */
X     }
X    exit(1);
X}
X
X/*
X** Functions for manipulating text.
X*/
X
X/*
X** This function sets the point size for text. (not applicable)
X*/
Xvecsize (points)
Xint points;
X{
X}
X
X/*
X** This function puts text on the screen.
X*/
Xvecsyms (x, y, s)
Xint x,y;
Xchar *s;
X{
X     register char *ptr;
X     register unsigned int tmp;
X 
X     if (*s == '\0') /* Don't bother if the string is empty */
X          return;   /* (A null char can make linea8() crash!) */
X     fontp = la_init.li_a1[0];  /* 6x6 system font */
X     FBASE = fontp->font_data; /* Pointer to start of font form */
X     FWIDTH = fontp->font_width; /* Width of font form */
X     DELY = fontp->font_height; /* Height of character in font */
X
X     DSTX = xadjust(x);
X     if ((DSTY = yadjust(y)) > 2)
X          DSTY -= 2; /* This vertically centers the text on the line */
X     if (DSTY > 191)
X          DSTY = 191; /* Make sure the bottom line shows up */
X     ptr = s;
X     do { /* Output the characters until the end of the string is hit */
X          if (!iscntrl(*ptr)) {
X               tmp = *ptr - fontp->font_low_ade; /* Find the character data */
X               SRCX = fontp->font_char_off[tmp]; /* within the font data */
X               DELX = fontp->font_char_off[tmp + 1] - SRCX;
X               /* Check screen boundaries */
X               if ((DSTX > 0) && (DSTX < 311) && (DSTY > 0))
X                    if (isspace(*ptr)) {
X                         WMODE = 1; /* Writing mode = transparent */
X                         linea8();
X                         WMODE = 0; /* Writing mode = replace */
X                    } else 
X                         linea8(); /* Line A trap for text blit routine */
X          }
X     } while (*++ptr != '\0');
X}
X
X/*
X** This function puts text on the screen using the greek alphabet.
X** (Well, not yet, but someday ... :-))
X*/
Xvecsymsgk(s, x, y)
Xchar *s;
X{
X     vecsyms(s, x, y);
X}
X
X/*
X** Functions for drawing points and lines.
X*/
X
X/*
X** Change the current position of x and y.
X*/
Xvecmove (x, y)
Xint x,y;
X{
X     CURRX = x;
X     CURRY = y;
X}
X
X/*
X** Move to a new location (x1, y1) and draw a solid line to (x2, y2).
X*/
Xvecmovedraw (x1, y1, x2, y2)
Xint x1, y1, x2, y2;
X{
X     vecmove(x1, y1);
X     vecdraw(x2, y2);
X}
X
X/*
X** Draw a solid line to (x,y)
X*/
Xvecdraw (x, y)
Xint x,y;
X{
X     if (linemode != 'S') {
X          linemode = 'S';
X          COLBIT0 = 1; /* Set the bit plane for line drawing (color 15) */
X          COLBIT1 = 1;
X          COLBIT2 = 1;
X          COLBIT3 = 1;
X     }
X     X1 = xadjust(CURRX);
X     Y1 = yadjust(CURRY);
X     X2 = xadjust(CURRX = x);
X     Y2 = yadjust(CURRY = y);
X     linea3(); /* Line blit routine */
X}
X
X/*
X** Draw a dotted line (dark green on the ST) to (x,y)
X*/
Xvecdrawdot(x, y)
X{
X     if (linemode != 'D') {
X          linemode = 'D';
X          COLBIT0 = 1; /* Set the bit plane for line drawing (color 13) */
X          COLBIT1 = 0;
X          COLBIT2 = 1;
X          COLBIT3 = 1;
X     }
X     X1 = xadjust(CURRX);
X     Y1 = yadjust(CURRY);
X     X2 = xadjust(CURRX = x);
X     Y2 = yadjust(CURRY = y);
X     linea3();
X}
X
X/*
X** Draw a hyphenated line (dark red on the ST) to (x,y)
X*/
Xvecdrawhyph(x, y)
X{
X     if (linemode != 'H') {
X          linemode = 'H';
X          COLBIT0 = 0; /* Set the bit plane for line drawing (color 14) */
X          COLBIT1 = 1;
X          COLBIT2 = 1;
X          COLBIT3 = 1;
X     }
X     X1 = xadjust(CURRX);
X     Y1 = yadjust(CURRY);
X     X2 = xadjust(CURRX = x);
X     Y2 = yadjust(CURRY = y);
X     linea3();
X}
X
X/*
X** Draw a horizontal line.
X*/
Xdrawlen (x, y, dx, dy, len)
Xint x, y, dx, dy, len;
X{
X     if (linemode != 'S') {
X          linemode = 'S';
X          COLBIT0 = 1; /* Set the bit plane for line drawing (color 15) */
X          COLBIT1 = 1;
X          COLBIT2 = 1;
X          COLBIT3 = 1;
X     }
X     X1 = xadjust(x + dx);
X     Y1 = yadjust(y + dy);
X     X2 = xadjust(CURRX = x + dx + len - 1);
X     Y2 = yadjust(CURRY = y + dy);
X     linea3();
X}
X
X/*
X** Functions for astronomical objects.
X*/
X
X/*
X** Draw the sun or a planet
X*/
XdrawPlan(x, y, mag, type, color)
Xint x, y, mag, type;
Xchar *color;
X{
X     if (type == 'S')
X          INTIN[0] = 10; /* Yellow for the Sun */
X     else if ((type == 'M') || (type == 'V'))
X          INTIN[0] = 11; /* Pink for inferior planets (Mercury or Venus) */
X     else
X          INTIN[0] = 12; /* Purple for superior planets (m, J, s, U, or N) */
X     PTSIN[0] = xadjust(CURRX = x);
X     PTSIN[1] = yadjust(CURRY = y);
X     if (linea2() == 0) /* See if there's anything there already */
X          linea1(); /* Put a pixel on the screen */
X}
X
X/*
X** Draw a star.
X*/
XdrawStar(x, y, mag, type, color)
Xint x, y, mag, type;
Xchar *color;
X{
X     if (mag > 6)
X          INTIN[0] = 6;
X     else if (mag < 1)
X          INTIN[0] = 1;
X     else
X          INTIN[0] = mag; /* No conversion necessary, direct map into palette */
X     if (mag < 2) /* Brightest stars will be in color if possible */
X          if (color != NULL)
X               if ((color[0] == 'O') || (color[0] == 'B'))
X                    INTIN[0] = 8; /* Color register 8 holds blue */
X               else if ((color[0] == 'K') || (color[0] == 'M'))
X                    INTIN[0] = 9; /* Color register 9 holds red */
X     PTSIN[0] = xadjust(CURRX = x);
X     PTSIN[1] = yadjust(CURRY = y);
X     if (mag < 1)
X          drawBigStar(x, y); /* Bright stars clobber anything under them */
X     else if (linea2() == 0) /* See if there's anything there already */
X               linea1();
X}
X
X/*
X** Draw a bright star as a cross shape.
X*/
XdrawBigStar(x, y)
Xint x, y;
X{
X     linea1(); /* x, y */
X     --PTSIN[0];
X     linea1(); /* x-1, y */
X     ++PTSIN[0];
X     --PTSIN[1];
X     linea1(); /* x, y-1 */
X     PTSIN[1] += 2;
X     linea1(); /* x, y+1 */
X     ++PTSIN[0];
X     --PTSIN[1];
X     linea1(); /* x+1, y */
X}
X
X/*
X** Draw a nebula. ('type' = 'D' for diffuse, 'P' for planetary)
X*/
XdrawNebu(x, y, mag, type, color)
Xint x, y, mag, type;
Xchar *color;
X{
X     /* This isn't as clever as cstar() in starimag.c, but it's fast */
X     INTIN[0] = 7; /* Make 'em faint, with this shape: */
X     PTSIN[0] = xadjust(CURRX = x) - 1; /*         **       */
X     PTSIN[1] = yadjust(CURRY = y);     /*        *  *      */
X     linea1(); /* x-1, y                           **       */
X     ++PTSIN[1];
X     linea1(); /* x-1, y+1 */
X     ++PTSIN[0];
X     ++PTSIN[1];
X     linea1(); /* x, y+2 */
X     PTSIN[1] -= 3;
X     linea1(); /* x, y-1 */
X     ++PTSIN[0];
X     ++PTSIN[1];
X     linea1(); /* x+1, y */
X     ++PTSIN[1];
X     linea1(); /* x+1, y+1 */
X}
X
X/*
X** Draw a galaxy. ('type' = 'P' for sphere, 'S' for spiral)
X*/
XdrawGalx(x, y, mag, type, color)
Xint x, y, mag, type;
Xchar *color;
X{
X     int i;
X
X     CURRX = x;
X     CURRY = y;
X     INTIN[0] = 7; /* Make 'em faint, with this shape: */
X     PTSIN[0] = xadjust(CURRX = x) - 2; /*        **  *   */
X     PTSIN[1] = yadjust(CURRY = y);     /*      ******    */
X     for (i = 0; i < 6; ++i) {          /*     *  **      */
X          PTSIN[0] += 1;
X          linea1(); /* (x-2)+i, y */
X     }
X     ++PTSIN[0];
X     --PTSIN[1];
X     linea1(); /* x+4, y-1 */
X     PTSIN[0] -= 3;
X     linea1(); /* x+1, y-1 */
X     --PTSIN[0];
X     linea1(); /* x, y-1 */
X     PTSIN[1] += 2;
X     linea1(); /* x, y+1 */
X     ++PTSIN[0];
X     linea1(); /* x+1, y+1 */
X     PTSIN[0] -= 4;
X     linea1(); /* x-3, y+1 */
X}
X
X/*
X** Draw a cluster. ('type' = 'G' for glob., 'O' for open, 'C' for Galactic)
X*/
XdrawClus(x, y, mag, type, color)
Xint x, y, mag, type;
Xchar *color;
X{
X     INTIN[0] = 7; /* Make 'em faint, with this shape: */
X     PTSIN[0] = xadjust(CURRX = x);     /*         * *      */
X     PTSIN[1] = yadjust(CURRY = y);     /*        * * *     */
X     linea1(); /* x, y                             * *      */
X     PTSIN[0] -= 2;
X     linea1(); /* x-2, y */
X     ++PTSIN[0];
X     --PTSIN[1];
X     linea1(); /* x-1, y-1 */
X     PTSIN[0] += 2;
X     linea1(); /* x+1, y-1 */
X     PTSIN[1] += 2;
X     linea1(); /* x+1, y+1 */
X     PTSIN[0] -= 2;
X     linea1(); /* x-1, y+1 */
X     PTSIN[0] += 3;
X     --PTSIN[1];
X     linea1(); /* x+2, y */
X}
SHAR_EOF
chmod 0600 starst.c || echo "restore of starst.c fails"
rm -f s2_seq_.tmp
echo "You have unpacked the last part"
exit 0