/************************************************************
  yoyo.c  By: Stephen Vermeulen

  Copyright (C) 1987 By Stephen Vermeulen

  Purpose: display hack in frustration

  Syntax: YoYo
************************************************************/

#include <intuition/intuition.h>
#include <exec/memory.h>
#include <stdio.h>
#include <functions.h>
#include <math.h>

#define NO_INTUITION   1
#define NO_GRAPHICS    2

struct IntuitionBase *IntuitionBase;
struct GfxBase *GfxBase;

/************************************************************
  The following routine just opens the libraries
************************************************************/

short OpenLibs()
{
  short flags; /* any libraries that do not open get recorded here */

  flags = 0;
  IntuitionBase = (struct IntuitionBase *)
                  OpenLibrary("intuition.library", 0L);
  GfxBase =       (struct GfxBase *)
                  OpenLibrary("graphics.library", 0L);
  if (!IntuitionBase) flags |= NO_INTUITION;
  if (!GfxBase) flags |= NO_GRAPHICS;
  return(flags);
}

void CloseLibs(flags)
short flags;
{
  if (!(flags & NO_INTUITION)) CloseLibrary(IntuitionBase);
  if (!(flags & NO_GRAPHICS))  CloseLibrary(GfxBase);
}

struct NewWindow my_window =
{
  280, 190, 80, 10, -1, -1,
  CLOSEWINDOW, WINDOWCLOSE | SIMPLE_REFRESH,
  NULL, NULL, (UBYTE *) "YoYo",
  NULL, NULL, 80, 10, 80, 10, WBENCHSCREEN
};

void main(argc, argv)
short argc;
char *argv[];
{
  short lib_flags, init_flags;
  struct Window *w;
  struct Screen *s;
  struct IntuiMessage *mess;
  short i, j;

  lib_flags  = OpenLibs();
  if (!lib_flags)
  {
    w = (struct Window *) OpenWindow(&my_window);
    if (w)
    {
      s = w->WScreen;

      for (;;)
      {
        if (mess = (struct IntuiMessage *) GetMsg(w->UserPort))
        {
          ReplyMsg(mess);
          goto done;
        }
        Delay(10L);
        for (j = 0; j < 40; ++j)
          MoveScreen(s, 0L, 5L);
        for (j = 0; j < 40; ++j)
          MoveScreen(s, 0L, -5L);
      }
done:
      CloseWindow(w);
    }
  }
  CloseLibs(lib_flags);
}
