#ifndef COMPILE_H
#include "COMPILE.H"
#endif
#ifdef MEDIA678_F31E_F31J_X31J_P31J_SU1E_AU1E_AU2E_AU3E
#ifdef MEDIA671_F31E_F31J_P31J
void F0007_MAIN_CopyBytes(char* P0005_pc_Source, char* P0006_pc_Destination, long P0007_l_ByteCount)
{
#ifdef MEDIA670_F31E_F31J
        int16_t L6579_;

        if ((unsigned char*)P0005_pc_Source > (unsigned char*)P0006_pc_Destination) {
                L6579_ = 0;
                while (L6579_ < P0007_l_ByteCount) {
                        P0006_pc_Destination[L6579_] = P0005_pc_Source[L6579_];
                        L6579_++;
                }
        } else {
                L6579_ = P0007_l_ByteCount;
                while (--L6579_ >= 0) {
                        P0006_pc_Destination[L6579_] = P0005_pc_Source[L6579_];
                }
        }
#endif
#ifdef MEDIA667_P31J
        if ((unsigned char huge*)P0005_pc_Source > (unsigned char huge*)P0006_pc_Destination) {
                asm cld
                asm push    ds
                asm lds     si, P0005_pc_Source
                asm les     di, P0006_pc_Destination
                asm mov     cx, P0007_l_ByteCount
                asm shr     cx, 1
                asm pushf
                asm rep movsw
                asm popf
                asm jnb     loc_1FEDB
                asm movsb
                loc_1FEDB:
                asm pop     ds
        } else {
                (char*)P0005_pc_Source += P0007_l_ByteCount - 1;
                (char*)P0006_pc_Destination += P0007_l_ByteCount - 1;
                asm std
                asm push    ds
                asm lds     si, P0005_pc_Source
                asm les     di, P0006_pc_Destination
                asm mov     cx, P0007_l_ByteCount
                asm rep movsb
                asm pop     ds
        }
#endif
}
#endif

void F7317_MAIN_CopyBytes_Alt(char HUGE* P0005_pc_Source, char HUGE* P0006_pc_Destination, int16_t P4179_, int16_t P4499_, long P0007_l_ByteCount)
{
#ifdef MEDIA700_X31J_SU1E_AU1E_AU2E_AU3E
        asm {
#if (defined(MEDIA772_SU1E) && (EXETYPE == C04_SWITCH))
                        movem.l d4-d7/a2-a6,-(sp)
#else
                        movem.l d3-d7/a2-a6,-(sp)
#endif
                        move.l  P0007_l_ByteCount(a6),d7
                        beq.w   @Tloc_2EE8
                        movea.l P0005_pc_Source(a6),a3
                        movea.l P0006_pc_Destination(a6),a2
                        move.l  a3,d0
                        move.l  a2,d1
                        andi.w  #1,d0
                        beq.s   @Tloc_2DFE
                        andi.w  #1,d1
                        bne.s   @Tloc_2E5E
                        bra.s   @Tloc_2E04
                @Tloc_2DFE:
                        andi.w  #1,d1
                        beq.s   @Tloc_2E7A
                @Tloc_2E04:
                        cmpa.l  a2,a3
                        bpl.s   @Tloc_2E46
                        adda.l  d7,a3
                        adda.l  d7,a2
                        bra.s   @Tloc_2E1E
                @Tloc_2E0E:
                        move.b  -(a3),-(a2)
                        move.b  -(a3),-(a2)
                        move.b  -(a3),-(a2)
                        move.b  -(a3),-(a2)
                        move.b  -(a3),-(a2)
                        move.b  -(a3),-(a2)
                        move.b  -(a3),-(a2)
                        move.b  -(a3),-(a2)
                @Tloc_2E1E:
                        subq.w  #8,d7
                        bcc.s   @Tloc_2E0E
                        swap    d7
                        tst.w   d7
                        beq.s   @Tloc_2E2E
                        subq.w  #1,d7
                        swap    d7
                        bra.s   @Tloc_2E0E
                @Tloc_2E2E:
                        swap    d7
                        addq.w  #8,d7
                        bra.w   @Tloc_2EB6
                @Tloc_2E36:
                        move.b  (a3)+,(a2)+
                        move.b  (a3)+,(a2)+
                        move.b  (a3)+,(a2)+
                        move.b  (a3)+,(a2)+
                        move.b  (a3)+,(a2)+
                        move.b  (a3)+,(a2)+
                        move.b  (a3)+,(a2)+
                        move.b  (a3)+,(a2)+
                @Tloc_2E46:
                        subq.w  #8,d7
                        bcc.s   @Tloc_2E36
                        swap    d7
                        tst.w   d7
                        beq.s   @Tloc_2E56
                        subq.w  #1,d7
                        swap    d7
                        bra.s   @Tloc_2E36
                @Tloc_2E56:
                        swap    d7
                        addq.w  #8,d7
                        bra.w   @Tloc_2EE4
                @Tloc_2E5E:
                        cmpa.l  a2,a3
                        bpl.s   @Tloc_2E72
                        adda.l  d7,a3
                        adda.l  d7,a2
                        moveq   #1,d6
                        and.w   d7,d6
                        bne.s   @Tloc_2E9A
                        subq.l  #1,d7
                        move.b  -(a3),-(a2)
                        bra.s   @Tloc_2E9A
                @Tloc_2E72:
                        subq.l  #1,d7
                        move.b  (a3)+,(a2)+
                        bra.w   @Tloc_2EC8
                @Tloc_2E7A:
                        cmpa.l  a2,a3
                        bpl.s   @Tloc_2EC8
                        adda.l  d7,a3
                        adda.l  d7,a2
                        moveq   #1,d6
                        and.w   d7,d6
                        beq.s   @Tloc_2E9A
                        subq.w  #1,d7
                        move.b  -(a3),-(a2)
                        bra.s   @Tloc_2E9A
                @Tloc_2E8E:
                        lea     -0x30(a3),a3
                        movem.l (a3),d0-d6/a0-a1/a4-a6
                        movem.l d0-d6/a0-a1/a4-a6,-(a2)
                @Tloc_2E9A:
                        subi.w  #0x30,d7
                        bcc.s   @Tloc_2E8E
                        swap    d7
                        tst.w   d7
                        beq.s   @Tloc_2EAC
                        subq.w  #1,d7
                        swap    d7
                        bra.s   @Tloc_2E8E
                @Tloc_2EAC:
                        swap    d7
                        addi.w  #0x30,d7
                        bra.s   @Tloc_2EB6
                @Tloc_2EB4:
                        move.b  -(a3),-(a2)
                @Tloc_2EB6:
                        dbf     d7,@Tloc_2EB4
                        bra.s   @Tloc_2EE8
                @Tloc_2EBC:
                        movem.l (a3)+,d0-d6/a0-a1/a4-a6
                        movem.l d0-d6/a0-a1/a4-a6,(a2)
                        lea     0x30(a2),a2
                @Tloc_2EC8:
                        subi.w  #0x30,d7
                        bcc.s   @Tloc_2EBC
                        swap    d7
                        tst.w   d7
                        beq.s   @Tloc_2EDA
                        subq.w  #1,d7
                        swap    d7
                        bra.s   @Tloc_2EBC
                @Tloc_2EDA:
                        swap    d7
                        addi.w  #0x30,d7
                        bra.s   @Tloc_2EE4
                @Tloc_2EE2:
                        move.b  (a3)+,(a2)+
                @Tloc_2EE4:
                        dbf     d7,@Tloc_2EE2
                @Tloc_2EE8:
#if (defined(MEDIA772_SU1E) && (EXETYPE == C04_SWITCH))
                        movem.l (sp)+,d4-d7/a2-a6
#else
                        movem.l (sp)+,d3-d7/a2-a6
#endif
        }
#endif
#ifdef MEDIA671_F31E_F31J_P31J
        F0007_MAIN_CopyBytes(P0005_pc_Source, P0006_pc_Destination, P0007_l_ByteCount);
#endif
}

void F0008_MAIN_ClearBytes(char HUGE* P0008_pc_Buffer, unsigned long P0009_i_ByteCount)
{
#ifdef MEDIA700_X31J_SU1E_AU1E_AU2E_AU3E
        asm {
#if (defined(MEDIA772_SU1E) && (EXETYPE == C04_SWITCH))
                        movem.l d4-d7/a2-a6,-(sp)
#else
                        movem.l d3-d7/a2-a6,-(sp)
#endif
                        move.l  P0009_i_ByteCount(a6),d0
                        beq.w   @Tloc_2F6C
                        movea.l P0008_pc_Buffer(a6),a0
                        move.w  a0,d1
                        andi.w  #1,d1
                        beq.s   @Tloc_2F14
                        clr.b   (a0)+
                        subq.l  #1,d0
                        beq.w   @Tloc_2F6C
                @Tloc_2F14:
                        adda.l  d0,a0
                        move.w  a0,d1
                        andi.w  #1,d1
                        beq.s   @Tloc_2F26
                        clr.b   -(a0)
                        subq.l  #1,d0
                        beq.w   @Tloc_2F6C
                @Tloc_2F26:
                        subi.l  #52,d0
                        bcs.s   @Tloc_2F60
                        moveq   #0,d1
                        moveq   #0,d2
                        moveq   #0,d3
                        moveq   #0,d4
                        moveq   #0,d5
                        moveq   #0,d6
                        moveq   #0,d7
                        movea.l d7,a1
                        movea.l d7,a2
                        movea.l d7,a3
                        movea.l d7,a4
                        movea.l d7,a5
                        movea.l d7,a6
                @Tloc_2F48:
                        movem.l d1-d7/a1-a6,-(a0)
                        subi.w  #52,d0
                        bcc.s   @Tloc_2F48
                        swap    d0
                        tst.w   d0
                        beq.s   @Tloc_2F5E
                        subq.w  #1,d0
                        swap    d0
                        bra.s   @Tloc_2F48
                @Tloc_2F5E:
                        swap    d0
                @Tloc_2F60:
                        addi.w  #52,d0
                        bra.s   @Tloc_2F68
                @Tloc_2F66:
                        clr.b   -(a0)
                @Tloc_2F68:
                        dbf     d0,@Tloc_2F66
                @Tloc_2F6C:
#if (defined(MEDIA772_SU1E) && (EXETYPE == C04_SWITCH))
                        movem.l (sp)+,d4-d7/a2-a6
#else
                        movem.l (sp)+,d3-d7/a2-a6
#endif
        }
#endif
#ifdef MEDIA671_F31E_F31J_P31J
        while (P0009_i_ByteCount > 0) {
                *P0008_pc_Buffer = 0;
                P0008_pc_Buffer += 1;
                P0009_i_ByteCount--;
        }
#endif
}
#endif
