/*
 * $Id$
 *
 * $Date$
 * $Revision$
 *
 * (C) 1999,2000 by Hyperion
 * All rights reserved
 *
 * This file is part of the MiniGL library project
 * See the file Licence.txt for more details
 *
 */

#include "mgl/config.h"
#ifdef USE_68K_SWITCHER

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

void SwitcherTask(void)
{
    struct IntuitionBase *IntuitionBase;
    struct ExecBase *SysBase;
    struct Task *me;
    ULONG *memarea;
    BOOL running = TRUE;
    ULONG recv;

    SysBase = *((struct ExecBase **)(4));

    me = FindTask(0);
    if (!me)
	return;

    recv = Wait(SIGBREAKF_CTRL_E|SIGBREAKF_CTRL_C);     // Wait for parent to signal us that our UserData is valid

    if (recv & SIGBREAKF_CTRL_C)
	return;

    memarea = me->tc_UserData;

    IntuitionBase = (struct IntuitionBase *)(*memarea);

    if (!IntuitionBase)
	return;

    while (running)
    {
	recv = Wait(SIGBREAKF_CTRL_F|SIGBREAKF_CTRL_C);    // ^C will kill us, ^F will call the buffer switch

	if (recv & SIGBREAKF_CTRL_C)
	{
	    running = FALSE;
	    break;
	}

	if (recv & SIGBREAKF_CTRL_F)
	{
	    struct Screen *scr = (struct Screen *)(memarea[0]);
	    struct ScreenBuffer *sb = (struct ScreenBuffer *)(memarea[1]);
	    while (!ChangeScreenBuffer(scr, sb));
	}
    }

    return;
}

#endif
