#ifndef COMPILE_H
#include "COMPILE.H"
#endif
#ifdef MEDIA643_A31E_X31J
#ifdef MEDIA692_X31J
#define F2281_MEM1_05_ClearBytes        CLEARMEM
#define F7317_MEM1_04_CopyBytes         MOVEMEM
#endif


void F2281_MEM1_05_ClearBytes(P0008_pc_Buffer, P3548_i_, P0009_i_ByteCount)
char* P0008_pc_Buffer;
int16_t P3548_i_;
int16_t P0009_i_ByteCount;
{
        static long G9013_al_BlankData[13]; /* Used to clear memory areas */


        ASM_STUB_PREFIX
#ifdef MEDIA692_X31J
        if (!M007_GET(P3548_i_, MASK0x0008_MEMREQ)) {
#endif
                asm {
                                movem.l D0-D7/A0-A6,-(A7)
                                move.l  P0009_i_ByteCount(A6),D0
                                beq.s   @T0008005
                                move.l  P0008_pc_Buffer(A6),D1
                                beq.s   @T0008005
                                add.l   D0,D1
                                movea.l D1,A0                           /* Address of the last byte to clear (start clearing from the end) */
                                andi.b  #1,D1
                                beq.s   @T0008000
                                clr.b   -(A0)
                                subq.l  #1,D0
                        @T0008000:
                                subi.l  #52,D0                          /* 52 bytes is the total size of all 13 registers used in the operation */
                                bmi.s   @T0008002                       /* Branch if there are less than 52 bytes left to clear */
                                movem.l G9013_al_BlankData,D1-D7/A1-A6  /* Initialize all registers to 0 except A0 and D0 (the function parameters) and A7 (stack pointer) */
                        @T0008001:
                                movem.l D1-D7/A1-A6,-(A0)               /* Decrement A0 and save all registers at A0, effectively clearing 52 bytes of data at A0 in one instruction */
                                subi.l  #52,D0                          /* The number of bytes left to clear */
                                bpl.s   @T0008001
                        @T0008002:
                                addi.w  #52,D0                          /* The number of bytes left to clear (now less than 52) */
                                bra.s   @T0008004
                        @T0008003:
                                clr.b   -(A0)                           /* Decrement address in A0 and clear byte at A0 */
                        @T0008004:
                                dbf     D0,@T0008003
                        @T0008005:
                                movem.l (A7)+,D0-D7/A0-A6
                }
#ifdef MEDIA692_X31J
        }
#endif
        ASM_STUB_SUFFIX
}

void F7317_MEM1_04_CopyBytes(P0005_pc_Source, P0006_pc_Destination, P4179_, P4499_, P0007_l_ByteCount)
char* P0005_pc_Source;
char* P0006_pc_Destination;
int16_t P4179_;
int16_t P4499_;
long P0007_l_ByteCount;
{
        ASM_STUB_PREFIX
#ifdef MEDIA692_X31J
        if (!M007_GET(P4179_, MASK0x0010_MEMREQ) && !M007_GET(P4499_, MASK0x0010_MEMREQ)) {
#endif
                asm {
                                movem.l d0-d7/a0-a6,-(sp)
                                move.l  P0007_l_ByteCount(a6),d7
                                movea.l P0005_pc_Source(a6),a3
                                movea.l P0006_pc_Destination(a6),a2
                                move.l  a3,d0
                                beq.w   @Tloc_3A4
                                move.l  a2,d1
                                beq.w   @Tloc_3A4
                                andi.w  #1,d0
                                beq.s   @Tloc_2DE
                                andi.w  #1,d1
                                bne.s   @Tloc_322
                                bra.s   @Tloc_2E4
                        @Tloc_2DE:
                                andi.w  #1,d1
                                beq.s   @Tloc_346
                        @Tloc_2E4:
                                cmpa.l  a2,a3
                                bpl.s   @Tloc_318
                                adda.l  d7,a3
                                adda.l  d7,a2
                                bra.s   @Tloc_2FE
                        @Tloc_2EE:
                                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_2FE:
                                subq.l  #8,d7
                                bpl.s   @Tloc_2EE
                                addq.l  #8,d7
                                bra.w   @Tloc_37C
                        @Tloc_308:
                                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_318:
                                subq.l  #8,d7
                                bpl.s   @Tloc_308
                                addq.l  #8,d7
                                bra.w   @Tloc_3A0
                        @Tloc_322:
                                cmpa.l  a2,a3
                                bpl.s   @Tloc_33A
                                adda.l  d7,a3
                                adda.l  d7,a2
                                moveq   #1,d6
                                and.l   d7,d6
                                bne.s   @Tloc_36A
                                subq.l  #1,d7
                                bmi.w   @Tloc_3A4
                                move.b  -(a3),-(a2)
                                bra.s   @Tloc_36A
                        @Tloc_33A:
                                subq.l  #1,d7
                                bmi.w   @Tloc_3A4
                                move.b  (a3)+,(a2)+
                                bra.w   @Tloc_38E
                        @Tloc_346:
                                cmpa.l  a2,a3
                                bpl.s   @Tloc_38E
                                adda.l  d7,a3
                                adda.l  d7,a2
                                moveq   #1,d6
                                and.l   d7,d6
                                beq.s   @Tloc_36A
                                subq.l  #1,d7
                                bmi.w   @Tloc_3A4
                                move.b  -(a3),-(a2)
                                bra.s   @Tloc_36A
                        @Tloc_35E:
                                lea     -48(a3),a3
                                movem.l (a3),d0-d6/a0-a1/a4-a6
                                movem.l d0-d6/a0-a1/a4-a6,-(a2)
                        @Tloc_36A:
                                subi.l  #48,d7
                                bpl.s   @Tloc_35E
                                addi.l  #48,d7
                                bra.s   @Tloc_37C
                        @Tloc_37A:
                                move.b  -(a3),-(a2)
                        @Tloc_37C:
                                subq.l  #1,d7
                                bpl.s   @Tloc_37A
                                bra.s   @Tloc_3A4
                        @Tloc_382:
                                movem.l (a3)+,d0-d6/a0-a1/a4-a6
                                movem.l d0-d6/a0-a1/a4-a6,(a2)
                                lea     48(a2),a2
                        @Tloc_38E:
                                subi.l  #48,d7
                                bpl.s   @Tloc_382
                                addi.l  #48,d7
                                bra.s   @Tloc_3A0
                        @Tloc_39E:
                                move.b  (a3)+,(a2)+
                        @Tloc_3A0:
                                subq.l  #1,d7
                                bpl.s   @Tloc_39E
                        @Tloc_3A4:
                                movem.l (sp)+,d0-d7/a0-a6
                }
#ifdef MEDIA692_X31J
        }
#endif
        ASM_STUB_SUFFIX
}
#endif
