/* BorderBlank par Leu Simon GRIS le 16.8.95 */

#define SYSBASE struct ExecBase * SysBase = (*((struct ExecBase **) 4))

#define __USE_SYSBASE

#include <dos/dos.h>
#include <dos/dosextens.h>

#include <workbench/startup.h>

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

#include <graphics/GfxBase.h>
#include <proto/graphics.h>

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

#include <hardware/custom.h>

LONG Main(void);

#ifdef BORDERSPRITE
static char Verstag[] = "\0$VER: BSprite 1.0 (16.8.95) by Leu Simon Gris";
#endif
#ifdef BORDERBLANK
static char Verstag[] = "\0$VER: BBlank 1.0 (16.8.95) by Leu Simon Gris";
#endif

__saveds LONG Main(void)
{
    SYSBASE;
    struct Process          *nous;
    struct MsgPort          *msgPort;
    struct WBStartup        *wBStartup;
    struct GfxBase          *GfxBase;
    struct IntuitionBase    *IntuitionBase;
    LONG                    returncode = RETURN_FAIL;

    nous = (struct Process *)(SysBase->ThisTask);

    if( nous->pr_CLI == NULL )
    {
        msgPort = &(nous->pr_MsgPort);
        WaitPort(msgPort);
        wBStartup = (struct WBStartup*)GetMsg(msgPort);
    }

    GfxBase = (struct GfxBase*)OpenLibrary("graphics.library",39);
    if( GfxBase != NULL )
    {
        IntuitionBase = (struct IntuitionBase*)
                        OpenLibrary("intuition.library",0);
        if( IntuitionBase != NULL )
        {
#ifdef BORDERSPRITE
            GfxBase->BP3Bits ^= BPLCON3_EXTBLKZD;
#endif
#ifdef BORDERBLANK
            GfxBase->BP3Bits ^= BPLCON3_BRDNBLNK;
#endif
            RemakeDisplay();
            returncode = RETURN_OK;
            CloseLibrary((struct Library *)IntuitionBase);
        }
        CloseLibrary((struct Library *)GfxBase);
    }

    if( nous->pr_CLI == NULL )
    {
        Forbid();
        ReplyMsg((struct Message *)wBStartup);
    }

    return(returncode);
}

