#ifndef COMPILE_H
#include "COMPILE.H"
#endif
#ifdef MEDIA413_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
struct Text_Scroller G1057_s_TextScroller = {
        F0562_SCROLLER_Task,
        1,
        NULL,
        "TextScroller",
        NULL,
        NULL,
        "ScrTextMom",
        NULL,
        "ScrTextKid",
        1,
        4096 };
int16_t G0354_i_MessageAreaScrollingLineCount = -1;
struct RastPort* G1105_ps_RastPort;
struct BitMap* G1106_ps_BitMap_NewMessageLine;


void F0562_SCROLLER_Task(
)
{
        struct MsgPort* L1753_ps_MsgPort = NULL;
        struct MsgPort* L1754_pc_ReplyPort = NULL;
        TEXT_SCROLLER_MESSAGE* L1755_ps_ReceivedMessage = NULL;
        TEXT_SCROLLER_MESSAGE* L1756_ps_StopTextScrollerMessage = NULL;


        int_start();
        L1753_ps_MsgPort = CreatePort(G1057_s_TextScroller.PortNameKid, G1057_s_TextScroller.Priority);
        if (L1753_ps_MsgPort == NULL) {
                Alert(0x80444DA0, 0L);
                goto T0562000;
        }
        L1756_ps_StopTextScrollerMessage = AllocMem((long)sizeof(TEXT_SCROLLER_MESSAGE), MEMF_PUBLIC | MEMF_CLEAR);
        if (L1756_ps_StopTextScrollerMessage == NULL) {
                Alert(0x80444DA1, 0L);
                goto T0562000;
        }
        L1756_ps_StopTextScrollerMessage->BaseMessage.mn_Node.ln_Type = NT_MESSAGE;
        L1756_ps_StopTextScrollerMessage->BaseMessage.mn_Node.ln_Pri = G1057_s_TextScroller.Priority;
        L1756_ps_StopTextScrollerMessage->BaseMessage.mn_Length = sizeof(TEXT_SCROLLER_MESSAGE);
        L1756_ps_StopTextScrollerMessage->BaseMessage.mn_ReplyPort = L1753_ps_MsgPort;
        L1756_ps_StopTextScrollerMessage->ScrollCommand = 2;
        for (;;) { /*_Infinite loop_*/
                if (G0354_i_MessageAreaScrollingLineCount == -1) {
                        WaitPort(L1753_ps_MsgPort);
                        for (;;) { /*_Infinite loop_*/
                                if ((L1755_ps_ReceivedMessage = (TEXT_SCROLLER_MESSAGE*)GetMsg(L1753_ps_MsgPort)) == NULL)
                                        break;
                                switch(L1755_ps_ReceivedMessage->ScrollCommand) {
                                        case 0: /* Init */
                                                G1105_ps_RastPort = L1755_ps_ReceivedMessage->RastPort;
                                                G1106_ps_BitMap_NewMessageLine = L1755_ps_ReceivedMessage->BitMap;
                                                L1754_pc_ReplyPort = L1755_ps_ReceivedMessage->BaseMessage.mn_ReplyPort;
                                                break;
                                        case 1: /* Start scrolling */
                                                G0354_i_MessageAreaScrollingLineCount = 0;
                                                break;
                                        case 3: /* No action */
                                        default:
                                                goto T0562000;
                                                break;
                                }
                                ReplyMsg(L1755_ps_ReceivedMessage);
                        }
                } else {
                        F0510_AMIGA_WaitBottomOfViewPort();
                        F0563_SCROLLER_UpdateMessageArea();
                        if (G0354_i_MessageAreaScrollingLineCount == -1) {
                                PutMsg(L1754_pc_ReplyPort, L1756_ps_StopTextScrollerMessage);
                                WaitPort(L1753_ps_MsgPort);
                                GetMsg(L1753_ps_MsgPort);
                        }
                }
        }
        T0562000:
        if (L1753_ps_MsgPort) {
                DeletePort(L1753_ps_MsgPort);
        }
        if (L1756_ps_StopTextScrollerMessage) {
                FreeMem(L1756_ps_StopTextScrollerMessage, (long)sizeof(TEXT_SCROLLER_MESSAGE));
        }
        if (L1755_ps_ReceivedMessage) {
                ReplyMsg(L1755_ps_ReceivedMessage);
        }
        Wait(0L);
        int_end();
}

void F0563_SCROLLER_UpdateMessageArea(
)
{
        static int16_t G1107_i_Height;


        if (G0354_i_MessageAreaScrollingLineCount >= 0) {
                ScrollRaster(G1105_ps_RastPort, 0L, 1L, 0L, 173L, 320L, (long)(200 - G0354_i_MessageAreaScrollingLineCount)); /* In specified RastPort, scroll rectangle from (0, 173) to (320, 200 - n) by Dx = 0 and Dy = 1 toward (0,0) */
                if (G0354_i_MessageAreaScrollingLineCount == -1) {
                         G1107_i_Height = 7;
                } else {
                        G0354_i_MessageAreaScrollingLineCount++;
                        G1107_i_Height = G0354_i_MessageAreaScrollingLineCount;
                        if (G0354_i_MessageAreaScrollingLineCount == 7) {
                                G0354_i_MessageAreaScrollingLineCount = -1;
                        }
                        BltBitMap(G1106_ps_BitMap_NewMessageLine, 0L, 0L, G1105_ps_RastPort->BitMap, 0L, (long)(200 - G1107_i_Height), 320L, (long)G1107_i_Height, 192L, 255L, 0L); /* 192 means 'copy' bitmap without change */
                }
        }
}
#endif
