home *** CD-ROM | disk | FTP | other *** search
- /*
- * This code is copyright ADE Muffett, September 1991, and is distributed as
- * part of the ASP .plan description language compiler. This code is freely
- * redistributable as long as this copyright notice remains intact. No
- * responsibility is assumed by the author for any situation which arises
- * from the use of this code, including insanity, late nights, or disk
- * storage problems.
- */
-
- #include "asp.h"
- #undef DEBUG
-
- static char currline[SCREENWIDTH + 1]; /* The state of the union... */
-
- /* nothing */
- void
- Noop ()
- {
- }
- /* Throw a newline */
- void
- LineFeed ()
- {
- static char lf = '\n';
-
- putchar (lf);
- NullSet (currline, sizeof (currline));
- SpaceFlood (currline, sizeof (currline));
- currline[SCREENWIDTH] = '\0';
- }
- /* Throw a carriage return */
- void
- CReturn ()
- {
- static char cr = '\r';
-
- putchar (cr);
- }
- /* Fast clear of the current line */
- void
- Wipe ()
- {
- NullSet (stdline, sizeof (stdline));
- }
- /* Fast clear of the current line */
- void
- Clear ()
- {
- Wipe ();
- UpdateCR ();
- }
- /* show something onto screen destructively */
- void
- Show (cstring, dstring)
- char *cstring;
- char *dstring;
- {
- Wipe ();
- Overlay (stdline, dstring);
- UpdateCR ();
- }
- /* show something onto screen non destructively */
- void
- TShow (cstring, dstring)
- char *cstring;
- char *dstring;
- {
- TransparentOverlay (stdline, dstring);
- UpdateCR ();
- }
- /* Pause about 1 second @ 9600 baud */
- void
- Pause ()
- {
- register int i;
-
- for (i = 0; i < LOOP_COUNT; i++)
- {
- CReturn ();
- }
- for (i = (LOOP_COUNT * (speed / DUMMY_RETURNS)); i; i--)
- {
- CReturn ();
- }
- }
- /* Trim off all whitespace from a text line */
- void
- Trim (ptr)
- register char *ptr;
- {
- while (*ptr)
- {
- ptr++;
- }
- while (isspace (*(--ptr)));
- *(++ptr) = '\0';
- }
- /* the display primitive */
- int
- Update ()
- {
- register int i;
- int j;
- int print_anim;
- int print_stdline;
- char diffline[SCREENWIDTH + 1];
-
- /* fix up all spaces */
- SpaceFlood (background, SCREENWIDTH);
- background[SCREENWIDTH] = '\0';
- Trim (background);
-
- SpaceFlood (stdline, SCREENWIDTH);
- stdline[SCREENWIDTH] = '\0';
- Trim (stdline);
-
- SpaceFlood (anim_buffer, SCREENWIDTH);
- anim_buffer[SCREENWIDTH] = '\0';
- Trim (anim_buffer);
-
- SpaceFlood (foreground, SCREENWIDTH);
- foreground[SCREENWIDTH] = '\0';
- Trim (foreground);
-
- #ifdef DEBUG
- printf ("bg'%s'\n", background);
- printf ("st'%s'\n", stdline);
- printf ("ab'%s'\n", anim_buffer);
- printf ("fg'%s'\n", foreground);
- #endif
-
- /* zero the differences buffer */
- NullSet (diffline, sizeof (diffline));
- SpaceFlood (diffline, SCREENWIDTH);
- diffline[SCREENWIDTH] = '\0';
-
- TransparentOverlay (diffline, background);
- TransparentOverlay (diffline, stdline);
- TransparentOverlay (diffline, anim_buffer);
- TransparentOverlay (diffline, foreground);
- Trim (diffline);
-
- /* and tidy up the memory copy of the current line */
- Trim (currline); /* this is what the screen is */
-
- i = strlen (diffline);
- j = strlen (currline);
- if (i < j)
- {
- for (; i < j && i < SCREENWIDTH; i++)
- {
- diffline[i] = ' ';
- }
- diffline[j] = '\0';
- }
- diffline[SCREENWIDTH] = '\0';
-
- /* there is a difference between screen and stdline+overstrikes */
- if (strcmp (currline, diffline))
- {
- char printline[SCREENWIDTH + 1];
-
- /* backup diffline */
- Memcpy (printline, diffline, sizeof (printline));
-
- /* don't print common trailing characters except space */
- if ((i = strlen (currline)) == strlen (diffline))
- {
- while (i-- && (diffline[i] == currline[i]))
- {
- printline[i] = '\0';
- }
- }
- /* print only what is necessary to make changes */
- printf ("%s", printline);
-
- /* make diffline the current line */
- Memcpy (currline, diffline, sizeof (currline));
-
- /* fill out line */
- return (strlen (printline));
- } else
- {
- return (SCREENWIDTH);
- }
- }
- /* save typing */
- void
- UpdateCR ()
- {
- register int i;
-
- i = Update ();
- CReturn ();
-
- while (smooth && (i++ < SCREENWIDTH))
- {
- CReturn ();
- }
-
- for (i = 0; i < (speed * DUMMY_RETURNS); i++)
- {
- CReturn ();
- }
- }
- /* END OF DISPLAY PRIMITIVES */
-