
/*****************************************************\
*  CDx demo program -- Sensing Disc Changes           *
*                                                     *
*  Copyright © 1992 Xetec, Inc.                       *
*                                                     *
*  Marty Flickinger                     Feb 27, 1992  *
*******************************************************
* This demo shows how to detect CD disc changes from  *
* an Intuition-based application.                     *
\*****************************************************/


#include <exec/types.h>
#include <intuition/intuition.h>

struct	Window			*Window;
struct	IntuitionBase	*IntuitionBase;


void	Cleanup(void);

/* Intuition stuff */

struct NewWindow NewWindow =
{
	0,0,
	190,30,
	0,1,
	CLOSEWINDOW | DISKINSERTED | DISKREMOVED,
	WINDOWCLOSE | WINDOWDEPTH | ACTIVATE | NOCAREREFRESH,
	NULL,
	NULL,
	"Disc Change Test",
	NULL,
 	NULL,
	100,25,
	640,200,
	WBENCHSCREEN
};


void main(argc,argv)
int	argc;
char	**argv;
{
	struct	IntuiMessage	*IntMsg;
	ULONG		MIClass;


	IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",0);
	if (IntuitionBase == NULL)
		Cleanup();

	Window = (struct Window *)OpenWindow(&NewWindow);
	if (Window == NULL)
		Cleanup();

	for (;;) {
		Wait(1<<Window->UserPort->mp_SigBit);

		while (IntMsg=(struct IntuiMessage *)GetMsg(Window->UserPort)) {
			MIClass	= IntMsg->Class;					/* Get pertinent info */
			ReplyMsg((struct Message *)IntMsg);		/* Reply to message quickly */

			if (MIClass == CLOSEWINDOW) {				/* Close down? */
				while (IntMsg=(struct IntuiMessage *) GetMsg(Window->UserPort))
					ReplyMsg(IntMsg);
				Cleanup();
			}
			else if (MIClass == DISKINSERTED)
				printf("Inserted!\n");
			else if (MIClass == DISKREMOVED)
				printf("Removed!\n");
		}
	}
}



void Cleanup(void)
{
	if (Window)				CloseWindow(Window);
	if (IntuitionBase)	CloseLibrary((struct Library *)IntuitionBase);

	exit(0);
}
