#ifndef COMPILE_H
#include "COMPILE.H"
#endif
#ifdef MEDIA413_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
struct ExecMessage* G0722_ps_ExecMessage;
long _savsp;
long _stkbase;

_main(
)
{
        REGISTER struct Process* pp;
        struct Process* _FindTask();
        REGISTER struct MsgPort* pMsgPort;
        void* _OpenLibrary();
        void* _GetMsg();


        _stkbase = _savsp - *((long*)_savsp+1) + 8;
        *(long*)_stkbase = 0x4d414e58L;
        pp = _FindTask(0L);
        pp->pr_WindowPtr = -1;
        pMsgPort = &pp->pr_MsgPort;
        _WaitPort(pMsgPort);
        G0722_ps_ExecMessage = _GetMsg(pMsgPort);
        G0734_ps_AmigaData = G0722_ps_ExecMessage->AmigaData;
        DOSBase = G0722_ps_ExecMessage->DOSBase;
        F0500__MAIN_ConfigurePorts();
        main();
        exit(0);
}

exit(code)
{
        long ret = code;


#asm
        mc68881
        move.l   4,a6           ;get ExecBase
        btst.b   #4,$129(a6)    ;check for 68881 flag in AttnFlags
        beq      1$             ;skip if not
        move.l   a5,-(sp)
        lea      2$,a5
        jsr      -30(a6)        ;do it in supervisor mode
        move.l   (sp)+,a5
        bra      1$
2$
        clr.l    -(sp)
        frestore (sp)+          ;reset the ffp stuff
        rte                     ;and return
1$
#endasm
        _Forbid();
        _ReplyMsg(G0722_ps_ExecMessage);
#asm
        move.l   -4(a5),d0      ;pick up return exit code
        move.l   __savsp#,sp    ;get back original stack pointer
        rts                     ;and exit
#endasm
}

void F0500__MAIN_ConfigurePorts(
)
{
        DeletePort(G0734_ps_AmigaData->IOAudio1ReplyPort);
        DeletePort(G0734_ps_AmigaData->IOAudio2ReplyPort);
        DeletePort(G0734_ps_AmigaData->IOAudio3ReplyPort);
        DeletePort(G0734_ps_AmigaData->IOAudio4ReplyPort);
        DeletePort(G0734_ps_AmigaData->IOAudio5ReplyPort);
        DeletePort(G0734_ps_AmigaData->IOAudio6ReplyPort);
        G0734_ps_AmigaData->IOAudio1ReplyPort = CreatePort(NULL, 0L);
        G0734_ps_AmigaData->IOAudio2ReplyPort = CreatePort(NULL, 0L);
        G0734_ps_AmigaData->IOAudio3ReplyPort = CreatePort(NULL, 0L);
        if ((G0734_ps_AmigaData->IOAudio1ReplyPort == NULL) || (G0734_ps_AmigaData->IOAudio2ReplyPort == NULL) || (G0734_ps_AmigaData->IOAudio3ReplyPort == NULL)) {
                Alert(0x80444D41, 0L);
        }
        G0734_ps_AmigaData->IOAudio4ReplyPort = CreatePort(NULL, 0L);
        G0734_ps_AmigaData->IOAudio5ReplyPort = CreatePort(NULL, 0L);
        G0734_ps_AmigaData->IOAudio6ReplyPort = CreatePort(NULL, 0L);
        if ((G0734_ps_AmigaData->IOAudio4ReplyPort == NULL) || (G0734_ps_AmigaData->IOAudio5ReplyPort == NULL) || (G0734_ps_AmigaData->IOAudio6ReplyPort == NULL)) {
                Alert(0x80444D41, 0L);
        }
        G0734_ps_AmigaData->Sound1LeftChannel->ioa_Request.io_Message.mn_ReplyPort = G0734_ps_AmigaData->IOAudio1ReplyPort;
        G0734_ps_AmigaData->Sound1RightChannel->ioa_Request.io_Message.mn_ReplyPort = G0734_ps_AmigaData->IOAudio2ReplyPort;
        G0734_ps_AmigaData->Sound1Control->ioa_Request.io_Message.mn_ReplyPort = G0734_ps_AmigaData->IOAudio3ReplyPort;
        G0734_ps_AmigaData->Sound2LeftChannel->ioa_Request.io_Message.mn_ReplyPort = G0734_ps_AmigaData->IOAudio4ReplyPort;
        G0734_ps_AmigaData->Sound2RightChannel->ioa_Request.io_Message.mn_ReplyPort = G0734_ps_AmigaData->IOAudio5ReplyPort;
        G0734_ps_AmigaData->Sound2Control->ioa_Request.io_Message.mn_ReplyPort = G0734_ps_AmigaData->IOAudio6ReplyPort;
        DeletePort(G0734_ps_AmigaData->IOExtTDReplyPort);
        G0734_ps_AmigaData->IOExtTDReplyPort = CreatePort(NULL, 0L);
        if (G0734_ps_AmigaData->IOExtTDReplyPort == NULL) {
                Alert(0x80444DC2, 0L);
        }
}
#endif
