#ifndef COMPILE_H
#include "COMPILE.H"
#endif
#ifdef MEDIA055_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J
#ifdef MEDIA007_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E
overlay "show"
#endif
#ifdef MEDIA351_G14ED_G20E_G21E
segment "gsthings"
#endif

void F0131_VIDEO_FlipVertical(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0196_puc_Bitmap, P0197_i_ByteWidth, P0198_i_Height)
#endif
unsigned char*   P0196_puc_Bitmap  SEPARATOR
#ifdef MEDIA056_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_A36M_A31E_A31M_A33M_A35E_A35M_X31J
unsigned int16_t P0197_i_ByteWidth SEPARATOR
unsigned int16_t P0198_i_Height    FINAL_SEPARATOR
#endif
#ifdef MEDIA670_F31E_F31J
int16_t          P0197_i_ByteWidth SEPARATOR
int16_t          P0198_i_Height    FINAL_SEPARATOR
#endif
{
#ifdef MEDIA007_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E
        asm {
                        movem.l D4-D7/A2,-(A7)
                        move.w  P0198_i_Height(A6),D7
                        move.w  P0197_i_ByteWidth(A6),D6         /* This value is always a multiple of 8 because the width of images is always a multiple of 16 pixels */
                        movea.l P0196_puc_Bitmap(A6),A0          /* A0 will successively point to half of the image lines starting from the first line */
                        movea.l A0,A1
                        move.w  D7,D0
                        subq.w  #1,D0
                        mulu.w  D6,D0
                        adda.w  D0,A1                           /* Address of the last line in the image. A1 will sucessively point to half of the image lines starting from the last line */
                        movea.w D6,A2
                        adda.w  A2,A2                           /* Width in pixels */
                        lsr.w   #3,D6                           /* Number of 8 bytes blocks (16 pixels) in one line */
                T0131001_Loop:
                        subq.w  #2,D7                           /* The number of image lines left to process is decreased */
                        bmi     T0131006_Return                 /* If the number of lines left to process is less than 2 then no more lines can be swapped */
                        swap    D7                              /* The most significant word of D7 now contains the number of image lines left to process */
                        move.w  D6,D7                           /* The least significant word of D7 now contains the number of longs to swap between lines */
                T0131002_Loop:
                        subq.w  #3,D7
                        bmi.s   T0131003                        /* If there are less than 3 blocks of 8 bytes left to swap between lines */
                        movem.l (A0),D0-D5                      /* Save 6x4 = 24 bytes from address A0 to registers */
                        move.l  (A1)+,(A0)+                     /* Copy 4 bytes from address A1 to address A0 */
                        move.l  (A1)+,(A0)+                     /* Copy 4 bytes from address A1 to address A0 */
                        move.l  (A1)+,(A0)+                     /* Copy 4 bytes from address A1 to address A0 */
                        move.l  (A1)+,(A0)+                     /* Copy 4 bytes from address A1 to address A0 */
                        move.l  (A1)+,(A0)+                     /* Copy 4 bytes from address A1 to address A0 */
                        move.l  (A1)+,(A0)+                     /* Copy 4 bytes from address A1 to address A0 */
                        movem.l D0-D5,-0x0018(A1)               /* Restore 24 bytes from registers to address A1 - 24. This effectively swaps 24 bytes from the first line of image and last line of image */
                        tst.w   D7
                        bne.s   T0131002_Loop
                        bra.s   T0131005
                T0131003:
                        addq.w  #2,D7
                T0131004:
                        move.l  (A0),D0                         /* Save 4 bytes from address A0 to D0 */
                        move.l  (A1),(A0)+                      /* Copy 4 bytes from address A1 to address A0 */
                        move.l  D0,(A1)+                        /* Restore 4 bytes from D0 to address A1. This effectively swaps 4 bytes */
                        move.l  (A0),D0                         /* Save 4 bytes from address A0 to D0 */
                        move.l  (A1),(A0)+                      /* Copy 4 bytes from address A1 to address A0 */
                        move.l  D0,(A1)+                        /* Restore 4 bytes from D0 to address A1. This effectively swaps 4 bytes */
                        dbf     D7,T0131004
                T0131005:
                        suba.w  A2,A1                           /* Move A1 to point to the previous line */
                        swap    D7                              /* The least significant word of D7 now contains the number of image lines left to process. The most significant word of D7 now contains the number of longs to swap between lines */
                        tst.w   D7
                        bne     T0131001_Loop                   /* If there are lines left to swap */
                T0131006_Return:
                        movem.l (A7)+,D4-D7/A2
        }
#endif
#ifdef MEDIA351_G14ED_G20E_G21E
        unsigned char* L6324_;
        int16_t L6325_;
        int16_t L6326_;


        L6325_ = P0197_i_ByteWidth - 2;
        L6326_ = P0198_i_Height >> 1;
        L6324_ = P0196_puc_Bitmap + (P0197_i_ByteWidth * (P0198_i_Height - 1));
        asm {
                        LDX        L6326_
                L080CAD:
                        LDY        L6325_
                L080CAF:
                        LDA        [P0196_puc_Bitmap],Y
                        PHA
                        LDA        [L6324_],Y
                        STA        [P0196_puc_Bitmap],Y
                        PLA
                        STA        [L6324_],Y
                        DEY
                        DEY
                        BPL        L080CAF
                        DEX
                        BEQ        L080CD8
                        CLC
                        LDA        P0196_puc_Bitmap
                        ADC        P0197_i_ByteWidth
                        STA        P0196_puc_Bitmap
                        BCC        L080CCB
                        INC        P0196_puc_Bitmap+2
                L080CCB:
                        SEC
                        LDA        L6324_
                        SBC        P0197_i_ByteWidth
                        STA        L6324_
                        BCS        L080CAD
                        DEC        L6324_+2
                        BRA        L080CAD
                L080CD8:
        }
#endif
#ifdef MEDIA413_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        AztecCDirective_asm
                        movem.l d4-d7/a2-a5,-(sp)
                        movea.l 8(a5),a0                ; P0196_puc_Bitmap
                        move.w  12(a5),d6               ; P0197_i_ByteWidth
                        move.w  14(a5),d7               ; P0198_i_Height
                        lsr.w   #2,d6
                        moveq   #0,d0
                        move.w  d7,d0
                        mulu.w  d6,d0
                        movea.l d0,a3
                        move.w  d6,d4
                        movea.w d4,a2
                        adda.w  a2,a2
                        lsr.w   #1,d6
                        swap    d6
                        move.w  d7,d6
                        swap    d6
                        movea.l a0,a4
                        move.w  #4,d5
                T0131007:
                        subq.w  #1,d5
                        bmi.s   T0131014
                        movea.l a4,a0
                        adda.w  a3,a4
                        movea.l a4,a1
                        suba.w  d4,a1
                        move.l  d6,d7
                T0131008:
                        move.w  d6,d7
                        swap    d7
                        subq.w  #2,d7
                        bmi.s   T0131007
                        swap    d7
                T0131009:
                        subq.w  #8,d7
                        bmi.s   T0131010
                        movem.l (a0),d0-d3
                        move.l  (a1)+,(a0)+
                        move.l  (a1)+,(a0)+
                        move.l  (a1)+,(a0)+
                        move.l  (a1)+,(a0)+
                        movem.l d0-d3,-$10(a1)
                        tst.w   d7
                        bne.s   T0131009
                        bra.s   T0131013
                T0131010:
                        addq.w  #8,d7
                        btst    #2,d7
                        beq.s   T0131011
                        movem.l (a0),d0-d1
                        move.l  (a1)+,(a0)+
                        move.l  (a1)+,(a0)+
                        movem.l d0-d1,-8(a1)
                T0131011:
                        btst    #1,d7
                        beq.s   T0131012
                        move.l  (a0),d0
                        move.l  (a1),(a0)+
                        move.l  d0,(a1)+
                T0131012:
                        btst    #0,d7
                        beq.s   T0131013
                        move.w  (a0),d0
                        move.w  (a1),(a0)+
                        move.w  d0,(a1)+
                T0131013:
                        suba.w  a2,a1
                        bra.s   T0131008
                T0131014:
                        movem.l (sp)+,d4-d7/a2-a5
        AztecCDirective_endasm
#endif
#ifdef MEDIA607_X30J_X31J
#if (EXETYPE == C13_GRF1)
        ASM_STUB_PREFIX
#endif
        asm {
                        movem.l d3-d7/a2-a3,-(sp)
                        move.w  P0198_i_Height(a6),d7
                        move.w  P0197_i_ByteWidth(a6),d5
                        addq.w  #1,d5
                        lsr.w   #1,d5
                        movea.l P0196_puc_Bitmap(a6),a0
                        movea.l a0,a1
                        move.w  d7,d0
                        subq.w  #1,d0
                        mulu.w  d5,d0
                        adda.w  d0,a1
                        movea.w d5,a2
                        adda.w  a2,a2
                        btst    #0,d5
                        beq.s   @Tloc_50C6
                        bra.s   @Tloc_507E
                @Tloc_5072:
                        move.b  (a0),d0
                        move.b  (a1),(a0)+
                        move.b  d0,(a1)+
                @Tloc_5078:
                        dbf     d6,@Tloc_5072
                        suba.w  a2,a1
                @Tloc_507E:
                        move.w  d5,d6
                        subq.w  #2,d7
                        bpl.s   @Tloc_5078
                        bra.s   @Tloc_50CA
                @Tloc_5086:
                        move.w  d5,d6
                @Tloc_5088:
                        subi.w  #24,d6
                        bmi.s   @Tloc_50A6
                        movem.l (a0),d0-d4/a3
                        move.l  (a1)+,(a0)+
                        move.l  (a1)+,(a0)+
                        move.l  (a1)+,(a0)+
                        move.l  (a1)+,(a0)+
                        move.l  (a1)+,(a0)+
                        move.l  (a1)+,(a0)+
                        movem.l d0-d4/a3,-24(a1)
                        bra.s   @Tloc_5088
                @Tloc_50A6:
                        addi.w  #20,d6
                        bmi.s   @Tloc_50B6
                @Tloc_50AC:
                        move.l  (a0),d0
                        move.l  (a1),(a0)+
                        move.l  d0,(a1)+
                        subq.w  #4,d6
                        bpl.s   @Tloc_50AC
                @Tloc_50B6:
                        addq.w  #4,d6
                        bra.s   @Tloc_50C0
                @Tloc_50BA:
                        move.b  (a0),d0
                        move.b  (a1),(a0)+
                        move.b  d0,(a1)+
                @Tloc_50C0:
                        dbf     d6,@Tloc_50BA
                        suba.w  a2,a1
                @Tloc_50C6:
                        subq.w  #2,d7
                        bpl.s   @Tloc_5086
                @Tloc_50CA:
                        movem.l (sp)+,d3-d7/a2-a3
        }
#if (EXETYPE == C13_GRF1)
        ASM_STUB_SUFFIX
#endif
#endif
#ifdef MEDIA746_A36M_A31E_A31M_A33M_A35E_A35M
#if (EXETYPE == C13_GRF1)
        ASM_STUB_PREFIX
#endif
        asm {
                        movem.l d3-d7/a2-a6,-(sp)
                        movea.l P0196_puc_Bitmap(a6),a0
                        move.w  P0197_i_ByteWidth(a6),d6
                        move.w  P0198_i_Height(a6),d7
                        addi.w  #0xF,d6
                        andi.w  #0xFFF0,d6
                        lsr.w   #3,d6
                        moveq   #0,d0
                        move.w  d7,d0
                        mulu.w  d6,d0
                        movea.l d0,a3
                        move.w  d6,d4
                        movea.w d4,a2
                        adda.w  a2,a2
                        lsr.w   #1,d6
                        swap    d6
                        move.w  d7,d6
                        swap    d6
                        movea.l a0,a4
                        move.w  #4,d5
                @Tloc_10BF4:
                        subq.w  #1,d5
                        bmi     @Tloc_10C5C
                        movea.l a4,a0
                        adda.w  a3,a4
                        movea.l a4,a1
                        suba.w  d4,a1
                        move.l  d6,d7
                @Tloc_10C04:
                        move.w  d6,d7
                        swap    d7
                        subq.w  #2,d7
                        bmi.s   @Tloc_10BF4
                        swap    d7
                @Tloc_10C0E:
                        subq.w  #8,d7
                        bmi.s   @Tloc_10C2A
                        movem.l (a0),d0-d3
                        move.l  (a1)+,(a0)+
                        move.l  (a1)+,(a0)+
                        move.l  (a1)+,(a0)+
                        move.l  (a1)+,(a0)+
                        movem.l d0-d3,-0x10(a1)
                        tst.w   d7
                        bne.s   @Tloc_10C0E
                        bra.s   @Tloc_10C58
                @Tloc_10C2A:
                        addq.w  #8,d7
                        btst    #2,d7
                        beq.s   @Tloc_10C40
                        movem.l (a0),d0-d1
                        move.l  (a1)+,(a0)+
                        move.l  (a1)+,(a0)+
                        movem.l d0-d1,-8(a1)
                @Tloc_10C40:
                        btst    #1,d7
                        beq.s   @Tloc_10C4C
                        move.l  (a0),d0
                        move.l  (a1),(a0)+
                        move.l  d0,(a1)+
                @Tloc_10C4C:
                        btst    #0,d7
                        beq.s   @Tloc_10C58
                        move.w  (a0),d0
                        move.w  (a1),(a0)+
                        move.w  d0,(a1)+
                @Tloc_10C58:
                        suba.w  a2,a1
                        bra.s   @Tloc_10C04
                @Tloc_10C5C:
                        movem.l (sp)+,d3-d7/a2-a6
        }
#if (EXETYPE == C13_GRF1)
        ASM_STUB_SUFFIX
#endif
#endif
#ifdef MEDIA551_F20E_F20J_F31E_F31J
        unsigned int16_t L6541_;
        unsigned int16_t L6542_;
        unsigned int16_t L6543_;
        unsigned char L6544_;
        unsigned int16_t L6546_;
        unsigned int16_t L6545_;


        P0197_i_ByteWidth = (int)((P0197_i_ByteWidth + 31) & 0xFFFFFFE0) >> 1;
        L6542_ = P0198_i_Height >> 1;
        for (L6541_ = 0; L6541_ < L6542_; L6541_++) {
                L6543_ = L6541_ * P0197_i_ByteWidth;
                L6545_ = P0197_i_ByteWidth * (P0198_i_Height - L6541_ - 1);
                for (L6546_ = 0; L6546_ < P0197_i_ByteWidth; L6546_++) {
                        L6544_ = P0196_puc_Bitmap[L6543_ + L6546_];
                        P0196_puc_Bitmap[L6543_ + L6546_] = P0196_puc_Bitmap[L6545_ + L6546_];
                        P0196_puc_Bitmap[L6545_ + L6546_] = L6544_;
                }
        }
#endif
}
#endif
