
/*****************************************************************************
 *
 * colorp program cycles the pointer colors
 *
 * =Robert J. Mical=
 * 10 July 1985
 * 
 * CONFIDENTIAL and PROPRIETARY
 * Copyright (C) 1985, COMMODORE-AMIGA, INC.
 * All Rights Reserved
 *
 *
 ****************************************************************************/

#include "idemoall.h"

struct GfxBase *GfxBase;
struct IntuitionBase *IntuitionBase;

set_timer(sec, micro, timermsg)
ULONG sec, micro;
struct IOStdReq *timermsg;
{
    timermsg->io_Command = TR_ADDREQUEST;    /* add a new timer request */
    timermsg->io_Actual = sec;    /* seconds */
    timermsg->io_Length = micro;    /* microseconds */
    SendIO(timermsg);	/* post a request to the timer */
}



main()
{
    SHORT red[3], green[3], blue[3];
    BOOL bumpgreen[3], bumpblue[3];
    SHORT redinc[3], greeninc[3], blueinc[3];
    SHORT i;
    struct View *view;
    struct ViewPort *vport;
    struct MsgPort *timerport;
    struct IOStdReq *timermsg;


    if ((GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 0)) == 0)
	printf("Woah, no graphics library in main!");

    if ((IntuitionBase = (LONG *)OpenLibrary("intuition.library", 0)) == 0)
	printf("Woah, no intuition library in main!");


/* ==========================================================================
 * === OK, here's the real program! =========================================
 * ==========================================================================
 */

    view = (struct View *)ViewAddress();
    vport = view->ViewPort;
    
    timerport = (struct MsgPort *)CreatePort(0, 0);
    if (timerport == 0) exit(FALSE);

    timermsg = (struct IOStdReq *)CreateStdIO(timerport);
    if (timermsg == 0) exit(FALSE);

    OpenDevice(TIMERNAME, UNIT_VBLANK, timermsg, 0);

    for (i = 0; i < 3; i ++)
	{
	red[i] = i * 7;
	green[i] = blue[i] = i;
	redinc[i] = greeninc[i] = blueinc[i] = 1;
	bumpgreen[i] = bumpblue[i] = FALSE;
	}

    FOREVER
	{
	/* 100000 microseconds = .10 sec */
	set_timer(0, 100000, timermsg);

	Wait(1 << timerport->mp_SigBit);

	GetMsg(timerport);	/* this does nothing more than "clear" */

	for (i = 0; i < 3; i++)
	    {
	    SetRGB4(vport, 17 + i, red[i], green[i], blue[i]);

	    if (bumpblue[i])
		{
		bumpblue[i] = FALSE;
		blue[i] += blueinc[i];
		if ((blue[i] == 0) || (blue[i] == 15))
		    {
		    blueinc[i] = -blueinc[i];
		    }
		}
	    else if (bumpgreen[i])
		{
		bumpgreen[i] = FALSE;
		green[i] += greeninc[i];
		if ((green[i] == 0) || (green[i] == 15))
		    {
		    greeninc[i] = -greeninc[i];
		    bumpblue[i] = TRUE;
		    }
		}
	    else
		{
		red[i] += redinc[i];
		if ((red[i] == 0) || (red[i] == 15))
		    {
		    redinc[i] = -redinc[i];
		    bumpgreen[i] = TRUE;
		    }
		}
	    }
	}
}


