#ifndef COMPILE_H
#include "COMPILE.H"
#endif
#ifdef MEDIA413_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
struct Message* F0557_SCROLLER_Initialize(P0977_ps_TextScroller, P0978_ps_BitMap)
REGISTER struct Text_Scroller* P0977_ps_TextScroller;
struct BitMap* P0978_ps_BitMap;
{
        P0977_ps_TextScroller->MsgPortMom = CreatePort(P0977_ps_TextScroller->PortNameMom, 0L);
        if (P0977_ps_TextScroller->MsgPortMom == NULL) {
                Alert(0x80444D70, 0L);
                F0507_AMIGA_DeinitializeAndInfiniteLoop();
        }
        P0977_ps_TextScroller->MyMessage = AllocMem((long)sizeof(TEXT_SCROLLER_MESSAGE), MEMF_PUBLIC | MEMF_CLEAR);
        if (P0977_ps_TextScroller->MyMessage == NULL) {
                Alert(0x80444D71, 0L);
                F0558_SCROLLER_CancelInitialize(P0977_ps_TextScroller);
                return NULL;
        }
        P0977_ps_TextScroller->MyMessage->BaseMessage.mn_Node.ln_Type = NT_MESSAGE;
        P0977_ps_TextScroller->MyMessage->BaseMessage.mn_Node.ln_Pri = P0977_ps_TextScroller->Priority;
        P0977_ps_TextScroller->MyMessage->BaseMessage.mn_Length = sizeof(TEXT_SCROLLER_MESSAGE);
        P0977_ps_TextScroller->MyMessage->BaseMessage.mn_ReplyPort = P0977_ps_TextScroller->MsgPortMom;
        P0977_ps_TextScroller->MyMessage->ScrollCommand = 0;
        P0977_ps_TextScroller->MyMessage->RastPort = &G0734_ps_AmigaData->RastPort;
        P0977_ps_TextScroller->MyMessage->LogicalScreenBase = G0348_Bitmap_Screen;
        P0977_ps_TextScroller->MyMessage->BitMap = P0978_ps_BitMap;
        P0977_ps_TextScroller->Task = CreateTask(P0977_ps_TextScroller->TaskName, P0977_ps_TextScroller->Priority, P0977_ps_TextScroller->EntryPoint, P0977_ps_TextScroller->StackSize);
        if (P0977_ps_TextScroller->Task == NULL) {
                Alert(0x80444D72, 0L);
                F0558_SCROLLER_CancelInitialize(P0977_ps_TextScroller);
                return NULL;
        }
        P0977_ps_TextScroller->MsgPortKid = FindPort(P0977_ps_TextScroller->PortNameKid);
        if (P0977_ps_TextScroller->MsgPortKid == NULL) {
                Alert(0x80444D73, 0L);
                F0558_SCROLLER_CancelInitialize(P0977_ps_TextScroller);
                return NULL;
        }
        PutMsg(P0977_ps_TextScroller->MsgPortKid, P0977_ps_TextScroller->MyMessage);
        WaitPort(P0977_ps_TextScroller->MsgPortMom);
        return GetMsg(P0977_ps_TextScroller->MsgPortMom);
}

void F0558_SCROLLER_CancelInitialize(P0979_ps_TextScroller)
REGISTER struct Text_Scroller* P0979_ps_TextScroller;
{
        if (P0979_ps_TextScroller->Task) {
                DeleteTask(P0979_ps_TextScroller->Task);
                P0979_ps_TextScroller->Task = NULL;
        }
        if (P0979_ps_TextScroller->MsgPortMom) {
                DeletePort(P0979_ps_TextScroller->MsgPortMom);
        }
}

void F0559_SCROLLER_Deinitialize(P0980_ps_TextScroller)
REGISTER struct Text_Scroller* P0980_ps_TextScroller;
{
        if (P0980_ps_TextScroller->Task) {
                F0560_SCROLLER_SetCommand(P0980_ps_TextScroller, 3);
                DeleteTask(P0980_ps_TextScroller->Task);
        }
        if (P0980_ps_TextScroller->MyMessage) {
                FreeMem(P0980_ps_TextScroller->MyMessage, (long)sizeof(TEXT_SCROLLER_MESSAGE));
        }
        if (P0980_ps_TextScroller->MsgPortMom) {
                DeletePort(P0980_ps_TextScroller->MsgPortMom);
        }
}

void F0560_SCROLLER_SetCommand(P0981_ps_TextScroller, P0982_i_ScrollCommand)
REGISTER struct Text_Scroller* P0981_ps_TextScroller;
REGISTER int16_t P0982_i_ScrollCommand;
{
        F0561_SCROLLER_IsTextScrolling(P0981_ps_TextScroller, C1_TRUE);
        if ((P0982_i_ScrollCommand == 1) || (P0982_i_ScrollCommand == 4) || (P0982_i_ScrollCommand == 5)) {
                P0981_ps_TextScroller->IsScrolling = C0_FALSE;
        }
        P0981_ps_TextScroller->MyMessage->ScrollCommand = P0982_i_ScrollCommand;
        PutMsg(P0981_ps_TextScroller->MsgPortKid, P0981_ps_TextScroller->MyMessage);
        WaitPort(P0981_ps_TextScroller->MsgPortMom);
        GetMsg(P0981_ps_TextScroller->MsgPortMom);
}

BOOLEAN F0561_SCROLLER_IsTextScrolling(P0983_ps_TextScroller, P0984_B_WaitEndOfScrolling)
REGISTER struct Text_Scroller* P0983_ps_TextScroller;
BOOLEAN P0984_B_WaitEndOfScrolling;
{
        TEXT_SCROLLER_MESSAGE* L1752_ps_Message;


        if (P0983_ps_TextScroller->IsScrolling == C1_TRUE) {
                return C1_TRUE;
        }
        if (P0984_B_WaitEndOfScrolling) {
                WaitPort(P0983_ps_TextScroller->MsgPortMom);
        }
        L1752_ps_Message = (TEXT_SCROLLER_MESSAGE*)GetMsg(P0983_ps_TextScroller->MsgPortMom);
        if (L1752_ps_Message == NULL) {
                P0983_ps_TextScroller->IsScrolling == C0_FALSE; /* BUG0_00 Useless code */
        } else {
                if (L1752_ps_Message->ScrollCommand == 2) {
                        P0983_ps_TextScroller->IsScrolling = C1_TRUE;
                } else {
                        P0983_ps_TextScroller->IsScrolling = C0_FALSE;
                }
                ReplyMsg(L1752_ps_Message);
        }
        return P0983_ps_TextScroller->IsScrolling;
}
#endif
