#ifndef COMPILE_H
#include "COMPILE.H"
#endif
#ifdef MEDIA042_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
#ifdef MEDIA746_A36M_A31E_A31M_A33M_A35E_A35M
BOOLEAN F1128_IsLeftMouseButtonDown(
void
)
{
        asm {
                moveq   #0,d0
                btst    #6,(0xBFE001).l /* (ciaa.ciapra & CIAF_GAMEPORT0) */
                seq     d0
        }
}

void F1052_WaitForScanLine(
int16_t P2817_ FINAL_SEPARATOR
{
        asm {
                        moveq   #0,d2
                        move.w  P2817_(a6),d2
                        addi.w  #44,d2
                        lsl.l   #8,d2
                        lea     (0xDFF004).l,a0  /* VPOSR and VHPOSR */
                        move.l  #0x1FF00,d1      /* Mask to get vertical position from register */
                @Tloc_5A52:
                        move.l  (a0),d0
                        and.l   d1,d0
                        cmp.l   d2,d0
                        blt.s   @Tloc_5A52
        }
}

void F1129_(
register PLANEPTR P2818_              SEPARATOR
unsigned int16_t  P2819_ui_ColorIndex SEPARATOR
register int16_t  P2820_i_Width       SEPARATOR
register int16_t  P2821_i_Height      FINAL_SEPARATOR
{
        register unsigned int16_t L3396_ui_;


        L3396_ui_ = RASSIZE(P2820_i_Width, P2821_i_Height);
        InitBitMap(&G3161_ac_Buffer724Bytes->_BitMap, 4L, (long)P2820_i_Width, (long)P2821_i_Height);
        if (G3208_B_) {
                InitRastPort(&G3161_ac_Buffer724Bytes->_RastPort);
                G3161_ac_Buffer724Bytes->_RastPort.BitMap = &G3161_ac_Buffer724Bytes->_BitMap;
                G3208_B_ = C0_FALSE;
        }
        G3161_ac_Buffer724Bytes->_BitMap.Planes[0] = P2818_;
        G3161_ac_Buffer724Bytes->_BitMap.Planes[1] = P2818_ + L3396_ui_;
        G3161_ac_Buffer724Bytes->_BitMap.Planes[2] = P2818_ + L3396_ui_ * 2;
        G3161_ac_Buffer724Bytes->_BitMap.Planes[3] = P2818_ + L3396_ui_ * 3;
        SetAPen(&G3161_ac_Buffer724Bytes->_RastPort, (long)P2819_ui_ColorIndex);
}
#endif

void F0135_VIDEO_FillBox(
#ifdef MEDIA008_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E
P0221_puc_Bitmap, P0222_pi_Box, P0223_i_Color, P0224_i_ByteWidth)
#endif
#ifdef MEDIA413_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0221_puc_Bitmap, P0222_pi_Box, P0223_i_Color, P0224_i_ByteWidth, P0929_i_Height)
#endif
unsigned char*            P0221_puc_Bitmap  SEPARATOR
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
int16_t*                  P0222_pi_Box      SEPARATOR
#endif
#ifdef MEDIA525_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_F31E_F31J_X31J_P31J
int16_t*                  P2219_pi_XYZ      SEPARATOR
#endif
#ifdef MEDIA746_A36M_A31E_A31M_A33M_A35E_A35M
register int16_t*         P2219_pi_XYZ      SEPARATOR
#endif
#ifdef MEDIA099_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
unsigned int16_t          P0223_i_Color     SEPARATOR /* If bit 15 is set then only every other pixel is overwritten */
#endif
#ifdef MEDIA413_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
register unsigned int16_t P0223_i_Color     SEPARATOR
#endif
#ifdef MEDIA007_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E
int16_t                   P0224_i_ByteWidth FINAL_SEPARATOR
#endif
#ifdef MEDIA351_G14ED_G20E_G21E
unsigned int16_t          P0224_i_ByteWidth FINAL_SEPARATOR
#endif
#ifdef MEDIA413_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
int16_t                   P0224_i_ByteWidth SEPARATOR
#endif
#ifdef MEDIA526_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_X31J_P31J
unsigned int16_t          P2221_i_Width     FINAL_SEPARATOR
#endif
#ifdef MEDIA670_F31E_F31J
int16_t                   P2221_i_Width     FINAL_SEPARATOR
#endif
#ifdef MEDIA746_A36M_A31E_A31M_A33M_A35E_A35M
int16_t                   P2221_i_Width     SEPARATOR
#endif
#ifdef MEDIA425_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_A36M_A31E_A31M_A33M_A35E_A35M
int16_t                   P0929_i_Height    FINAL_SEPARATOR
#endif
{
#ifdef MEDIA007_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E
        asm {
                        movem.l D4-D7,-(A7)
                        movea.l P0222_pi_Box(A6),A0
                        tst.w   G0578_B_UseByteBoxCoordinates(A4)
                        beq.s   T0135001                                /* If using words in box coordinates */
                        moveq   #0,D0
                        moveq   #0,D1
                        moveq   #0,D2
                        moveq   #0,D3
                        move.b  (A0)+,D0                                /* First byte of P0222_pi_Box */
                        move.b  (A0)+,D1                                /* Second byte of P0222_pi_Box */
                        move.b  (A0)+,D2                                /* Third byte of P0222_pi_Box */
                        move.b  (A0),D3                                 /* Fourth byte of P0222_pi_Box */
                        bra.s   T0135002
                T0135001:
                        move.w  (A0)+,D0                                /* First word of P0222_pi_Box */
                        move.w  (A0)+,D1                                /* Second word of P0222_pi_Box */
                        move.w  (A0)+,D2                                /* Third word of P0222_pi_Box */
                        move.w  (A0),D3                                 /* Fourth word of P0222_pi_Box */
                T0135002:
                        swap    D0
                        move.w  D2,D0
                        swap    D0
                        movea.l P0221_puc_Bitmap(A6),A1
                        sub.w   D2,D3
                        swap    D3
                        mulu.w  P0224_i_ByteWidth(A6),D2
                        adda.w  D2,A1
                        lea     V0135000_Masks(PC),A0
                        moveq   #15,D6
                        and.w   D0,D6
                        add.w   D6,D6
                        move.w  0(A0,D6.w),D6
                        lsr.w   #4,D0
                        moveq   #15,D4
                        and.w   D1,D4
                        addq.w  #1,D4
                        add.w   D4,D4
                        move.w  0(A0,D4.w),D4
                        not.w   D4
                        lsr.w   #4,D1
                        move.w  D0,D2
                        lsl.w   #3,D2
                        adda.w  D2,A1
                        sub.w   D0,D1
                        move.w  D1,D3
                        bne.s   T0135003
                        or.w    D4,D6
                T0135003:
                        subq.w  #1,D3
                        swap    D3
                        addq.w  #1,D1
                        lsl.w   #3,D1
                        move.w  P0224_i_ByteWidth(A6),D7
                        sub.w   D1,D7
                        move.w  D4,D5
                        not.w   D5
                        move.w  D6,D1
                        not.w   D1
                        swap    D7
                        clr.w   D7
                        btst    #15,P0223_i_Color(A6)
                        beq.s   T0135004                                /* Branch if Bit 15 of P0223_i_Color = 0 */
                        swap    D0
                        move.w  #0x5555,D7
                        btst    #0,D0
                        bne.s   T0135004
                        add.w   D7,D7
                T0135004:
                        moveq   #0x0F,D0
                        and.w   P0223_i_Color(A6),D0                     /* Color index extracted from P0223_i_Color by removing bit 15 */
                        add.w   D0,D0
                        move.w  D0,D2
                        add.w   D0,D0
                        add.w   D2,D0
                        jmp     2(PC,D0.w)
                T0135005:
                        lea     T0135016(PC),A0
                        bra.s   T0135006
                        lea     T0135015(PC),A0
                        bra.s   T0135006
                        lea     T0135019(PC),A0
                        bra.s   T0135006
                        lea     T0135014(PC),A0
                        bra.s   T0135006
                        lea     T0135024(PC),A0
                        bra.s   T0135006
                        lea     T0135027(PC),A0
                        bra.s   T0135006
                        lea     T0135018(PC),A0
                        bra.s   T0135006
                        lea     T0135013(PC),A0
                        bra.s   T0135006
                        lea     T0135022(PC),A0
                        bra.s   T0135006
                        lea     T0135021(PC),A0
                        bra.s   T0135006
                        lea     T0135026(PC),A0
                        bra.s   T0135006
                        lea     T0135025(PC),A0
                        bra.s   T0135006
                        lea     T0135023(PC),A0
                        bra.s   T0135006
                        lea     T0135020(PC),A0
                        bra.s   T0135006
                        lea     T0135017(PC),A0
                        bra.s   T0135006
                        lea     T0135012(PC),A0
                T0135006:
                        swap    D3
                        move.w  D3,D2
                        swap    D3
                        move.w  D6,D0
                        or.w    D7,D0
                        and.w   D0,(A1)
                        and.w   D0,2(A1)
                        and.w   D0,4(A1)
                        and.w   D0,6(A1)
                        not.w   D7
                        move.w  D1,D0
                        and.w   D7,D0
                        not.w   D7
                        jsr     (A0)
                        addq.l  #8,A1
                        tst.w   D2
                        bmi.s   T0135010
                        dbf     D2,T0135007
                        bra.s   T0135009
                T0135007:
                        move.w  D7,D0
                        not.w   D0
                T0135008:
                        and.w   D7,(A1)
                        and.w   D7,2(A1)
                        and.w   D7,4(A1)
                        and.w   D7,6(A1)
                        jsr     (A0)
                        addq.l  #8,A1
                        dbf     D2,T0135008
                T0135009:
                        move.w  D4,D0
                        or.w    D7,D0
                        and.w   D0,(A1)
                        and.w   D0,2(A1)
                        and.w   D0,4(A1)
                        and.w   D0,6(A1)
                        not.w   D7
                        move.w  D5,D0
                        and.w   D7,D0
                        not.w   D7
                        jsr     (A0)
                        addq.l  #8,A1
                T0135010:
                        swap    D7
                        adda.w  D7,A1
                        swap    D7
                        tst.w   D7
                        beq.s   T0135011
                        not.w   D7
                T0135011:
                        dbf     D3,T0135006
                        movem.l (A7)+,D4-D7
                        bra.s   T0135029_Return
                T0135012:
                        or.w    D0,6(A1)
                T0135013:
                        or.w    D0,4(A1)
                T0135014:
                        or.w    D0,2(A1)
                T0135015:
                        or.w    D0,(A1)
                T0135016:
                        rts
                T0135017:
                        or.w    D0,6(A1)
                T0135018:
                        or.w    D0,4(A1)
                T0135019:
                        or.w    D0,2(A1)
                        rts
                T0135020:
                        or.w    D0,4(A1)
                T0135021:
                        or.w    D0,(A1)
                T0135022:
                        or.w    D0,6(A1)
                        rts
                T0135023:
                        or.w    D0,6(A1)
                T0135024:
                        or.w    D0,4(A1)
                        rts
                T0135025:
                        or.w    D0,(A1)
                T0135026:
                        or.w    D0,6(A1)
                        or.w    D0,2(A1)
                        rts
                T0135027:
                        or.w    D0,4(A1)
                        or.w    D0,(A1)
                        rts
                V0135000_Masks:
                        dc.w    0x0000,0x8000,0xC000,0xE000
                        dc.w    0xF000,0xF800,0xFC00,0xFE00
                        dc.w    0xFF00,0xFF80,0xFFC0,0xFFE0
                        dc.w    0xFFF0,0xFFF8,0xFFFC,0xFFFE
                        dc.w    0xFFFF
                T0135029_Return:
        }
#endif
#ifdef MEDIA351_G14ED_G20E_G21E
        int16_t L6331_;
        unsigned int16_t L6327_;
        unsigned int16_t L6328_;
        int16_t L6329_;
        int16_t L6330_;
        int16_t L6332_;
        char L6333_;
        char L6334_;


        if (G0578_B_UseByteBoxCoordinates == C1_TRUE) {
                L6327_ = M768_BOX_LEFT(((char*)P0222_pi_Box));
                L6328_ = M769_BOX_RIGHT(((char*)P0222_pi_Box));
                L6330_ = M771_BOX_BOTTOM(((char*)P0222_pi_Box));
                L6329_ = M770_BOX_TOP(((char*)P0222_pi_Box));
        } else {
                L6327_ = M768_BOX_LEFT(P0222_pi_Box);
                L6328_ = M769_BOX_RIGHT(P0222_pi_Box);
                L6330_ = M771_BOX_BOTTOM(P0222_pi_Box);
                L6329_ = M770_BOX_TOP(P0222_pi_Box);
        }
        L6331_ = L6330_ - L6329_ + 1;
        P0223_i_Color = P0223_i_Color | (P0223_i_Color << 4);
        P0221_puc_Bitmap += (P0224_i_ByteWidth * L6329_) + (L6327_ >> 1);
        L6332_ = (L6328_ - L6327_ + 1) >> 1;
        if (L6327_ % 2) {
                L6333_ = 0x0F;
        } else {
                L6333_ = 0xFF;
        }
        if (L6328_ % 2) {
                L6334_ = 0xFF;
        } else {
                L6334_ = 0xF0;
        }
        if ((L6333_ & L6334_) == 0xFF) {
                L6332_--;
        }
        if (L6332_ == 0) {
                if (L6327_ == L6328_) {
                        L6333_ &= L6334_;
                } else {
                        L6333_ |= L6334_;
                }
        }
        asm {
                L080E9E:
                        SEP        #0x30
                        LDY        L6332_
                        BEQ        L080EB8
                        LDA        P0223_i_Color
                        EOR        [P0221_puc_Bitmap],Y
                        AND        L6334_
                        EOR        [P0221_puc_Bitmap],Y
                        STA        [P0221_puc_Bitmap],Y
                        DEY
                        BEQ        L080EB8
                L080EB1:
                        LDA        P0223_i_Color
                        STA        [P0221_puc_Bitmap],Y
                        DEY
                        BNE        L080EB1
                L080EB8:
                        LDA        P0223_i_Color
                        EOR        [P0221_puc_Bitmap],Y
                        AND        L6333_
                        EOR        [P0221_puc_Bitmap],Y
                        STA        [P0221_puc_Bitmap],Y
                        REP        #0x30
                        CLC
                        LDA        P0221_puc_Bitmap
                        ADC        P0224_i_ByteWidth
                        STA        P0221_puc_Bitmap
                        BCC        L080ECF
                        INC        P0221_puc_Bitmap+2
                L080ECF:
                        DEC        L6331_
                        BNE        L080E9E
        }
#endif
#ifdef MEDIA413_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        REGISTER int16_t L1629_i_Height;
        unsigned char* L1630_puc_Bitmap;
        int16_t L1631_i_X1;
        int16_t L1632_i_X2;
        unsigned int16_t L1633_ui_Width;
        long L1634_i_Unreferenced;


        if (G0578_B_UseByteBoxCoordinates) {
                L1631_i_X1 = M768_BOX_LEFT(((unsigned char*)P0222_pi_Box));
                L1632_i_X2 = M769_BOX_RIGHT(((unsigned char*)P0222_pi_Box));
                L1629_i_Height = M771_BOX_BOTTOM(((unsigned char*)P0222_pi_Box)) - M770_BOX_TOP(((unsigned char*)P0222_pi_Box));
        } else {
                L1631_i_X1 = M768_BOX_LEFT(P0222_pi_Box);
                L1632_i_X2 = M769_BOX_RIGHT(P0222_pi_Box);
                L1629_i_Height = M771_BOX_BOTTOM(P0222_pi_Box) - M770_BOX_TOP(P0222_pi_Box);
        }
        L1633_ui_Width = ((L1632_i_X2 - (L1631_i_X1 & 0xFFF0) + 16) & 0xFFF0) >> 1;
        F0491_CACHE_IsDerivedBitmapInCache(C000_DERIVED_BITMAP_VIEWPORT);
        F0134_VIDEO_FillBitmap(L1630_puc_Bitmap = F0492_CACHE_GetDerivedBitmap(C000_DERIVED_BITMAP_VIEWPORT), P0223_i_Color, (L1629_i_Height + 1) * (L1633_ui_Width >> 3));
        F0132_VIDEO_Blit(L1630_puc_Bitmap, P0221_puc_Bitmap, P0222_pi_Box, L1631_i_X1 & 0x0F, 0, L1633_ui_Width, P0224_i_ByteWidth, CM1_COLOR_NO_TRANSPARENCY, L1629_i_Height + 1, P0929_i_Height);
        F0493_CACHE_AddDerivedBitmap(C000_DERIVED_BITMAP_VIEWPORT);
        F0480_CACHE_ReleaseBlock(C000_DERIVED_BITMAP_VIEWPORT | MASK0x8000_DERIVED_BITMAP);
#endif
#ifdef MEDIA463_P20JA_P20JB_I34E_I34M_P31J
#ifdef MEDIA709_I34E_I34M_P31J
        int16_t L3397_ai_Box[4];
#endif


        if (P0221_puc_Bitmap != NULL) {
                F0692_FillBox(P0221_puc_Bitmap, P2219_pi_XYZ, P0223_i_Color, P2221_i_Width);
        } else {
#ifdef MEDIA458_P20JA_P20JB
                (*(G2156_VideoDriver->VIDRV_01_FillBox))(P0221_puc_Bitmap, P2219_pi_XYZ, P0223_i_Color, P2221_i_Width);
#endif
#ifdef MEDIA709_I34E_I34M_P31J
                M768_BOX_LEFT(L3397_ai_Box) = M704_ZONE_LEFT(P2219_pi_XYZ);
                M769_BOX_RIGHT(L3397_ai_Box) = M705_ZONE_RIGHT(P2219_pi_XYZ);
                M770_BOX_TOP(L3397_ai_Box) = M706_ZONE_TOP(P2219_pi_XYZ);
                M771_BOX_BOTTOM(L3397_ai_Box) = M707_ZONE_BOTTOM(P2219_pi_XYZ);
                (*(G2156_VideoDriver->VIDRV_01_FillBox))(P0221_puc_Bitmap, L3397_ai_Box, P0223_i_Color, P2221_i_Width);
#endif
        }
#endif
#ifdef MEDIA577_X30J
        register int16_t L3399_;
        register int16_t L3400_;
        register int16_t L3401_;
        register int16_t L3402_;
        register int16_t L3403_;
        long L3404_l_SupervisorStack;


        asm {
                        move.l  P2219_pi_XYZ(a6),d0
                        beq.w   @Tloc_1FA20
                        movea.l d0,a0
                        movem.w (a0)+,d3-d6
                        sub.w   d3,d4
                        sub.w   d5,d6
                        lea     G3098_(a5),a0
                        adda.w  P0223_i_Color(a6),a0
                        move.b  (a0),d2
                        move.l  P0221_puc_Bitmap(a6),d0
                        bne.s   @Tloc_1F98C
                        movea.l G3090_X68000VideoMemoryAddress(a5),a1
                        move.w  G3089_(a5),d1
                        bra.w   @Tloc_1F9F0
                @Tloc_1F98C:
                        movea.l d0,a1
                        move.w  P2221_i_Width(a6),d1
                        addq.w  #1,d1
                        lsr.w   #1,d1
                        mulu.w  d1,d5
                        adda.l  d5,a1
                        move.w  d4,d7
                        lsr.w   #1,d3
                        adda.w  d3,a1
                        bcc.s   @Tloc_1F9AE
                        lea     @Tloc_1F9CE,a0
                        addq.w  #3,d7
                        moveq   #0xF,d5
                        and.b   d2,d5
                        bra.s   @Tloc_1F9BE
                @Tloc_1F9AE:
                        tst.w   d7
                        bne.s   @Tloc_1F9B8
                        lea     @Tloc_1F9E2,a0
                        bra.s   @Tloc_1F9BC
                @Tloc_1F9B8:
                        lea     @Tloc_1F9DA,a0
                @Tloc_1F9BC:
                        addq.w  #2,d7
                @Tloc_1F9BE:
                        lsr.w   #1,d7
                        bcs.s   @Tloc_1F9C8
                        moveq   #0xFFFFFFF0,d3
                        and.b   d2,d3
                        moveq   #0xF,d0
                @Tloc_1F9C8:
                        sub.w   d7,d1
                        move.w  d4,d7
                        jmp     (a0)
                @Tloc_1F9CE:
                        andi.b  #0xF0,(a1)
                        or.b    d5,(a1)+
                        subq.w  #1,d7
                        beq.s   @Tloc_1F9E2
                        bcs.s   @Tloc_1F9E6
                @Tloc_1F9DA:
                        move.b  d2,(a1)+
                        subq.w  #2,d7
                        bhi.s   @Tloc_1F9DA
                        bcs.s   @Tloc_1F9E6
                @Tloc_1F9E2:
                        and.b   d0,(a1)
                        or.b    d3,(a1)+
                @Tloc_1F9E6:
                        subq.w  #1,d6
                        bcs.s   @Tloc_1FA20
                        move.w  d4,d7
                        adda.w  d1,a1
                        jmp     (a0)
                @Tloc_1F9F0:
                        andi.w  #0xF,d2
                        mulu.w  d1,d5
                        adda.l  d5,a1
                        add.w   d3,d3
                        adda.w  d3,a1
                        addq.w  #1,d4
                        add.w   d4,d4
                        sub.w   d4,d1
                        clr.l   -(sp)
                        dc.w    0xFF20  /* DOS CALL SUPER */
                        move.l  d0,L3404_l_SupervisorStack(a6)
                @Tloc_1FA0A:
                        move.w  d4,d7
                @Tloc_1FA0C:
                        move.w  d2,(a1)+
                        subq.w  #2,d7
                        bgt.s   @Tloc_1FA0C
                        adda.w  d1,a1
                        subq.w  #1,d6
                        bcc.s   @Tloc_1FA0A
                        move.l  L3404_l_SupervisorStack(a6),-(sp)
                        dc.w    0xFF20  /* DOS CALL SUPER */
                        addq.l  #4,sp
                @Tloc_1FA20:
        }
#endif
#ifdef MEDIA692_X31J
        if (P0221_puc_Bitmap == NULL) {
                VDEO_08_FillScreenBox(0, P2219_pi_XYZ, P0223_i_Color);
        } else {
                GRF1_08_FillBox(P0221_puc_Bitmap, P2219_pi_XYZ, P0223_i_Color, P2221_i_Width, 0);
        }
#endif
#ifdef MEDIA746_A36M_A31E_A31M_A33M_A35E_A35M
        if (!P2219_pi_XYZ) {
                return;
        }
        if (P0221_puc_Bitmap == NULL) {
                P0221_puc_Bitmap = G0348_Bitmap_Screen;
        }
        F1129_(P0221_puc_Bitmap, P0223_i_Color, P2221_i_Width, P0929_i_Height);
        if (P0221_puc_Bitmap == G0348_Bitmap_Screen) {
                F1052_WaitForScanLine(M707_ZONE_BOTTOM(P2219_pi_XYZ));
        }
        RectFill(&G3161_ac_Buffer724Bytes->_RastPort, (long)M704_ZONE_LEFT(P2219_pi_XYZ), (long)M706_ZONE_TOP(P2219_pi_XYZ), (long)(P2219_pi_XYZ[0] + P2219_pi_XYZ[2]) - 1, (long)(P2219_pi_XYZ[1] + P2219_pi_XYZ[3]) - 1);
        /* (long)M705_ZONE_RIGHT(P2219_pi_XYZ), (long)M707_ZONE_BOTTOM(P2219_pi_XYZ)); */
        WaitBlit();
#endif
#ifdef MEDIA551_F20E_F20J_F31E_F31J
        unsigned int16_t L6574_;
        unsigned int16_t L6525_i_X1;
        unsigned int16_t L6524_i_Y1;
        unsigned int16_t L6573_i_X2;
        unsigned int16_t L6526_i_Y2;
        unsigned int16_t L6572_;
        unsigned int16_t L6523_;


        L6525_i_X1 = M704_ZONE_LEFT(P2219_pi_XYZ);
        L6573_i_X2 = M705_ZONE_RIGHT(P2219_pi_XYZ);
        L6524_i_Y1 = M706_ZONE_TOP(P2219_pi_XYZ);
        L6526_i_Y2 = M707_ZONE_BOTTOM(P2219_pi_XYZ);
        P2221_i_Width = ((int)((P2221_i_Width + 31) & 0xFFFFFFE0) >> 1) * 2;
        L6523_ = L6573_i_X2 - L6525_i_X1 + 1;
        L6572_ = L6526_i_Y2 - L6524_i_Y1 + 1;
        L6574_ = (L6524_i_Y1 * P2221_i_Width) + L6525_i_X1;
        if (P0221_puc_Bitmap == NULL) {
                EGB_writePage(G4105_WORK, G4103_WRITE_PAGE);
                EGB_writeMode(G4105_WORK, 0);
                EGB_color(G4105_WORK, 2, P0223_i_Color);
                EGB_paintMode(G4105_WORK, 32);
                WORD(G4106_EGBPARA + 0) = L6525_i_X1;
                WORD(G4106_EGBPARA + 2) = L6524_i_Y1;
                WORD(G4106_EGBPARA + 4) = L6573_i_X2;
                WORD(G4106_EGBPARA + 6) = L6526_i_Y2;
                EGB_viewport(G4105_WORK, G4106_EGBPARA);
                WORD(G4106_EGBPARA + 0) = L6525_i_X1;
                WORD(G4106_EGBPARA + 2) = L6524_i_Y1;
                WORD(G4106_EGBPARA + 4) = L6573_i_X2;
                WORD(G4106_EGBPARA + 6) = L6526_i_Y2;
                EGB_rectangle(G4105_WORK, G4106_EGBPARA);
        } else {
                EGB_resolutionRam(G4105_WORK, 128, 4, P2221_i_Width, L6526_i_Y2 + 1, P0221_puc_Bitmap);
                EGB_writePage(G4105_WORK, 128);
                EGB_writeMode(G4105_WORK, 0);
                EGB_color(G4105_WORK, 2, P0223_i_Color);
                EGB_paintMode(G4105_WORK, 32);
                WORD(G4106_EGBPARA + 0) = L6525_i_X1;
                WORD(G4106_EGBPARA + 2) = L6524_i_Y1;
                WORD(G4106_EGBPARA + 4) = L6573_i_X2;
                WORD(G4106_EGBPARA + 6) = L6526_i_Y2;
                EGB_viewport(G4105_WORK, G4106_EGBPARA);
                WORD(G4106_EGBPARA + 0) = L6525_i_X1;
                WORD(G4106_EGBPARA + 2) = L6524_i_Y1;
                WORD(G4106_EGBPARA + 4) = L6573_i_X2;
                WORD(G4106_EGBPARA + 6) = L6526_i_Y2;
                EGB_rectangle(G4105_WORK, G4106_EGBPARA);
        }
#endif
}

#ifdef MEDIA611_X30J_A36M_A31E_A31M_A33M_A35E_A35M
void F1032_GRF1_12_HatchBox(
unsigned char*    P2760_puc_Bitmap SEPARATOR
#ifdef MEDIA577_X30J
int16_t*          P2761_pi_XYZ     SEPARATOR
#endif
#ifdef MEDIA746_A36M_A31E_A31M_A33M_A35E_A35M
register int16_t* P2761_pi_XYZ     SEPARATOR
#endif
int16_t           P2762_i_         SEPARATOR
#ifdef MEDIA577_X30J
int16_t           P2780_           FINAL_SEPARATOR
#endif
#ifdef MEDIA746_A36M_A31E_A31M_A33M_A35E_A35M
int16_t           P2780_           SEPARATOR
int16_t           P2822_           FINAL_SEPARATOR
#endif
{
#ifdef MEDIA577_X30J
        register int16_t L3406_;
        register int16_t L3407_;
        register int16_t L3408_;
        register int16_t L3409_;
        register int16_t L3410_;
        long L3405_l_SupervisorStack;


        asm {
                        move.l  P2761_pi_XYZ(a6),d0
                        beq.w   @Tloc_1FA8E
                        movea.l d0,a0
                        movem.w (a0)+,d3-d6
                        sub.w   d3,d4
                        sub.w   d5,d6
                        moveq   #0xF,d2
                        and.w   P2762_i_(a6),d2
                        movea.l G3090_X68000VideoMemoryAddress(a5),a1
                        move.w  G3089_(a5),d1
                        mulu.w  d1,d5
                        adda.l  d5,a1
                        eor.w   d3,d5
                        andi.w  #1,d5
                        seq     d5
                        add.w   d3,d3
                        adda.w  d3,a1
                        addq.w  #1,d4
                        add.w   d4,d4
                        sub.w   d4,d1
                        clr.l   -(sp)
                        dc.w    0xFF20  /* DOS CALL SUPER */
                        move.l  d0,L3405_l_SupervisorStack(a6)
                @Tloc_1FA6E:
                        move.w  d4,d7
                        not.b   d5
                        beq.s   @Tloc_1FA7A
                @Tloc_1FA74:
                        addq.l  #2,a1
                        subq.w  #2,d7
                        ble.s   @Tloc_1FA80
                @Tloc_1FA7A:
                        move.w  d2,(a1)+
                        subq.w  #2,d7
                        bgt.s   @Tloc_1FA74
                @Tloc_1FA80:
                        adda.w  d1,a1
                        subq.w  #1,d6
                        bcc.s   @Tloc_1FA6E
                        move.l  L3405_l_SupervisorStack(a6),-(sp)
                        dc.w    0xFF20  /* DOS CALL SUPER */
                        addq.l  #4,sp
                @Tloc_1FA8E:
        }
#endif
#ifdef MEDIA746_A36M_A31E_A31M_A33M_A35E_A35M
        if (!P2761_pi_XYZ) {
                return;
        }
        if (P2760_puc_Bitmap == NULL) {
                P2760_puc_Bitmap = G0348_Bitmap_Screen;
        }
        F1129_(P2760_puc_Bitmap, P2762_i_, P2780_, P2822_);
        G3161_ac_Buffer724Bytes->_RastPort.AreaPtrn = G3209_;
        G3161_ac_Buffer724Bytes->_RastPort.AreaPtSz = 1;
        SetDrMd(&G3161_ac_Buffer724Bytes->_RastPort, JAM1);
        if (P2760_puc_Bitmap == G0348_Bitmap_Screen) {
                F1052_WaitForScanLine(M707_ZONE_BOTTOM(P2761_pi_XYZ));
        }
        RectFill(&G3161_ac_Buffer724Bytes->_RastPort, (long)M704_ZONE_LEFT(P2761_pi_XYZ), (long)M706_ZONE_TOP(P2761_pi_XYZ), (long)(P2761_pi_XYZ[0] + P2761_pi_XYZ[2]) - 1, (long)(P2761_pi_XYZ[1] + P2761_pi_XYZ[3]) - 1);
        /* (long)M705_ZONE_RIGHT(P2761_pi_XYZ), (long)M707_ZONE_BOTTOM(P2761_pi_XYZ)); */
        G3161_ac_Buffer724Bytes->_RastPort.AreaPtrn = NULL;
        G3161_ac_Buffer724Bytes->_RastPort.AreaPtSz = 0;
        WaitBlit();
#endif
}
#endif

#ifdef MEDIA746_A36M_A31E_A31M_A33M_A35E_A35M
void F0732_FillScreenArea(
int16_t*         P2222_pi_Box   SEPARATOR
unsigned int16_t P2223_ui_Color FINAL_SEPARATOR
{
        if (P2222_pi_Box == NULL) {
                return;
        }
        SetDrMd(&G3191_ps_MsgPort_FTL_DRIA_Video->_0x0A0_RastPort, JAM1);
        SetAPen(&G3191_ps_MsgPort_FTL_DRIA_Video->_0x0A0_RastPort, (long)P2223_ui_Color);
        G3191_ps_MsgPort_FTL_DRIA_Video->_0x0A0_RastPort.Mask = 0x0F;
        F1052_WaitForScanLine(M707_ZONE_BOTTOM(P2222_pi_Box));
        RectFill(&G3191_ps_MsgPort_FTL_DRIA_Video->_0x0A0_RastPort, (long)M704_ZONE_LEFT(P2222_pi_Box), (long)M706_ZONE_TOP(P2222_pi_Box), (long)(P2222_pi_Box[0] + P2222_pi_Box[2]) - 1, (long)(P2222_pi_Box[1] + P2222_pi_Box[3]) - 1);
        /* (long)M705_ZONE_RIGHT(P2222_pi_Box), (long)M707_ZONE_BOTTOM(P2222_pi_Box)); */
        WaitBlit();
}

void F1131_InvertBox(
int16_t* P2823_pi_XYZ FINAL_SEPARATOR
{
        if (P2823_pi_XYZ == NULL) {
                return;
        }
        SetDrMd(&G3191_ps_MsgPort_FTL_DRIA_Video->_0x0A0_RastPort, COMPLEMENT);
        SetAPen(&G3191_ps_MsgPort_FTL_DRIA_Video->_0x0A0_RastPort, -1L);
        G3191_ps_MsgPort_FTL_DRIA_Video->_0x0A0_RastPort.Mask = 0x0F;
        F1052_WaitForScanLine(M707_ZONE_BOTTOM(P2823_pi_XYZ));
        RectFill(&G3191_ps_MsgPort_FTL_DRIA_Video->_0x0A0_RastPort, (long)M704_ZONE_LEFT(P2823_pi_XYZ), (long)M706_ZONE_TOP(P2823_pi_XYZ), (long)(P2823_pi_XYZ[0] + P2823_pi_XYZ[2]) - 1, (long)(P2823_pi_XYZ[1] + P2823_pi_XYZ[3]) - 1);
        /* (long)M705_ZONE_RIGHT(P2823_pi_XYZ), (long)M707_ZONE_BOTTOM(P2823_pi_XYZ)); */
        WaitBlit();
}

void F0509_AMIGA_FillScreen(
unsigned int16_t P0942_ui_Color FINAL_SEPARATOR
{
        unsigned char** L3411_ppuc_;


        L3411_ppuc_ = G3191_ps_MsgPort_FTL_DRIA_Video->_0x078_Bitmap.Planes;
        F1052_WaitForScanLine(64);
        asm {
                        movem.l d3-d4/a2-a3,-(sp)
                        move.w  P0942_ui_Color(a6),d3
                        lsr.w   #1,d3
                        scs     d0
                        ext.w   d0
                        ext.l   d0
                        lsr.w   #1,d3
                        scs     d1
                        ext.w   d1
                        ext.l   d1
                        lsr.w   #1,d3
                        scs     d2
                        ext.w   d2
                        ext.l   d2
                        lsr.w   #1,d3
                        scs     d3
                        ext.w   d3
                        ext.l   d3
                        movea.l L3411_ppuc_(a6),a3
                        movea.l (a3)+,a0
                        movea.l (a3)+,a1
                        movea.l (a3)+,a2
                        movea.l (a3),a3
                        move.w  #999,d4
                @Tloc_5E2A:
                        move.l  d0,(a0)+
                        move.l  d1,(a1)+
                        move.l  d2,(a2)+
                        move.l  d3,(a3)+
                        move.l  d0,(a0)+
                        move.l  d1,(a1)+
                        move.l  d2,(a2)+
                        move.l  d3,(a3)+
                        dbf     d4,@Tloc_5E2A
                        movem.l (sp)+,d3-d4/a2-a3
        }
}

#include "CONVBOXC.C"
#endif
#endif
#ifdef MEDIA774_SU1E_AU1E_AU2E
#if (defined(MEDIA772_SU1E) && (EXETYPE != C07_HINT))
unsigned char* G0348_Bitmap_Screen;
BOOLEAN G0578_B_UseByteBoxCoordinates;
#endif
#ifdef MEDIA763_AU1E_AU2E
struct RastPort G3262_s_RastPort;
struct BitMap G3263_s_BitMap;
BOOLEAN G3208_B_ = C1_TRUE;
#endif


#if (defined(MEDIA772_SU1E) && (EXETYPE != C07_HINT))
void F0021_MAIN_BlitToScreen(
unsigned char* P0023_puc_Bitmap,
int16_t* P0024_pi_Box,
int16_t P0025_i_BitmapByteWidth,
int16_t P0026_i_TransparentColor) {
        G0578_B_UseByteBoxCoordinates = C0_FALSE;
        F0132_VIDEO_Blit(P0023_puc_Bitmap, G0348_Bitmap_Screen, P0024_pi_Box, 0, 0, P0025_i_BitmapByteWidth, C160_BYTE_WIDTH_SCREEN, P0026_i_TransparentColor);
}
#endif

#ifdef MEDIA763_AU1E_AU2E
BOOLEAN F1128_IsLeftMouseButtonDown(
void
)
{
        asm {
                moveq   #0,d0
                btst    #6,(0xBFE001).l /* (ciaa.ciapra & CIAF_GAMEPORT0) */
                seq     d0
        }
}

int16_t F2047_GetMouseX(
)
{
        return G3191_ps_MsgPort_FTL_DRIA_Video->_0x10C_Window->MouseX;
}

int16_t F2048_GetMouseY(
)
{
        return G3191_ps_MsgPort_FTL_DRIA_Video->_0x10C_Window->MouseY;
}

void F0135_VIDEO_FillBox(register unsigned char* P0221_puc_Bitmap, unsigned int16_t* P2219_pui_XYZ, unsigned int16_t P2220_ui_Color, register unsigned int16_t P2221_ui_Width, register unsigned int16_t P0929_ui_Height) {
        register unsigned int16_t L5827_;


        L5827_ = RASSIZE(P2221_ui_Width * 2, P0929_ui_Height);
        InitBitMap(&G3263_s_BitMap, 4L, (long)P2221_ui_Width * 2, (long)P0929_ui_Height);
        if (G3208_B_) {
                InitRastPort(&G3262_s_RastPort);
                G3262_s_RastPort.BitMap = &G3263_s_BitMap;
                G3208_B_--;
        }
        G3263_s_BitMap.Planes[0] = P0221_puc_Bitmap;
        G3263_s_BitMap.Planes[1] = P0221_puc_Bitmap + L5827_;
        G3263_s_BitMap.Planes[2] = P0221_puc_Bitmap + L5827_ * 2;
        G3263_s_BitMap.Planes[3] = P0221_puc_Bitmap + L5827_ * 3;
        SetAPen(&G3262_s_RastPort, (long)P2220_ui_Color);
        RectFill(&G3262_s_RastPort, (long)M704_ZONE_LEFT(P2219_pui_XYZ), (long)P2219_pui_XYZ[2], (long)P2219_pui_XYZ[1], (long)P2219_pui_XYZ[3]);
}

void F7260_FillScreenBox(
unsigned int16_t* P2222_pi_Box,
unsigned int16_t P4038_ui_Color)
{
        SetDrMd(&G3191_ps_MsgPort_FTL_DRIA_Video->_0x108_Screen->RastPort, JAM1);
        SetAPen(&G3191_ps_MsgPort_FTL_DRIA_Video->_0x108_Screen->RastPort, (long)P4038_ui_Color);
        RectFill(&G3191_ps_MsgPort_FTL_DRIA_Video->_0x108_Screen->RastPort, (long)M704_ZONE_LEFT(P2222_pi_Box), (long)P2222_pi_Box[2], (long)P2222_pi_Box[1], (long)P2222_pi_Box[3]);
}
#endif

#if ((EXETYPE == C07_HINT) || (defined(MEDIA772_SU1E) && (EXETYPE == C05_ANIM)))
void F0732_FillScreenArea(
int16_t* P2222_pi_Box,
unsigned int16_t P2223_ui_Color)
{
#ifdef MEDIA772_SU1E
        F0135_VIDEO_FillBox(G0348_Bitmap_Screen, P2222_pi_Box, P2223_ui_Color, C160_BYTE_WIDTH_SCREEN);
#endif
#ifdef MEDIA763_AU1E_AU2E
        F0135_VIDEO_FillBox(G3191_ps_MsgPort_FTL_DRIA_Video->_0x078_Bitmap.Planes[0], P2222_pi_Box, P2223_ui_Color, C160_BYTE_WIDTH_SCREEN, C200_HEIGHT_SCREEN);
        F0135_VIDEO_FillBox(G3835_s_BitMap_Screen.Planes[0], P2222_pi_Box, P2223_ui_Color, C160_BYTE_WIDTH_SCREEN, C200_HEIGHT_SCREEN);
#endif
}
#endif

#ifdef MEDIA763_AU1E_AU2E
void F1131_InvertBox(unsigned int16_t* P2823_pi_XYZ)
{
        SetDrMd(&G3191_ps_MsgPort_FTL_DRIA_Video->_0x108_Screen->RastPort, COMPLEMENT);
        SetAPen(&G3191_ps_MsgPort_FTL_DRIA_Video->_0x108_Screen->RastPort, (long)CM1_COLOR_NO_TRANSPARENCY);
        RectFill(&G3191_ps_MsgPort_FTL_DRIA_Video->_0x108_Screen->RastPort, (long)M704_ZONE_LEFT(P2823_pi_XYZ), (long)P2823_pi_XYZ[2], (long)P2823_pi_XYZ[1], (long)P2823_pi_XYZ[3]);
}
#endif

#if (defined(MEDIA763_AU1E_AU2E) && (EXETYPE == C07_HINT))
void F2053_(
)
{
        F2045_FadeToPalette(G3829_aui_Palette, 0);
        SetRast(&G3191_ps_MsgPort_FTL_DRIA_Video->_0x108_Screen->RastPort, 0L);
}
#endif
#endif
