#ifndef COMPILE_H
#include "COMPILE.H"
#endif
#ifdef MEDIA437_A20E_A20F_A20G_A21E_A22E_A22G_A31E_A31M_A33M_A35E_A35M
#ifndef NOCOPYPROTECTION
#ifdef MEDIA433_A20E_A20F_A20G_A21E_A22E_A22G
struct Interrupt* G1080_ps_Interrupt_CPSX;


void F0567_COPYPROA_InitFloppyInterruptHandler_CPSX(
)
{
        G1080_ps_Interrupt_CPSX = (struct Interrupt*)AllocMem((long)sizeof(struct Interrupt), MEMF_PUBLIC);
        if (G1080_ps_Interrupt_CPSX == NULL) {
                Alert(0x80444D80, 0L);
                F0507_AMIGA_DeinitializeAndInfiniteLoop();
        }
        G1080_ps_Interrupt_CPSX->is_Node.ln_Type = NT_INTERRUPT;
        G1080_ps_Interrupt_CPSX->is_Node.ln_Name = NULL;
        G1080_ps_Interrupt_CPSX->is_Node.ln_Pri = 0;
        G1080_ps_Interrupt_CPSX->is_Data = (APTR)&G0625_i_FloppyDriveDMATimeout_CPSDF;
        G1080_ps_Interrupt_CPSX->is_Code = S0570_COPYPROA_IntHandlerStub_CPSX;
}

void F0568_COPYPROA_CleanupFloppyInterruptHandler_CPSX(
)
{
        if (G1080_ps_Interrupt_CPSX) {
                FreeMem(G1080_ps_Interrupt_CPSX, (long)sizeof(struct Interrupt));
        }
}

void F0569_COPYPROA_FloppyInterruptHandler_CPSX(
)
{
        int_start();
        if (G0625_i_FloppyDriveDMATimeout_CPSDF == 3) {
                G0625_i_FloppyDriveDMATimeout_CPSDF = 4;
        }
        ciab.ciaprb = CIAF_DSKSEL3 | CIAF_DSKSEL2 | CIAF_DSKSEL1 | CIAF_DSKDIREC | CIAF_DSKSTEP; /* 0x73. Select drive 0 (internal drive) */
        if (!(ciaa.ciapra & CIAF_DSKTRACK0)) { /* If drive head is over track 0 */
                custom.dsklen = 0x8201;
                custom.dsklen = 0x8201; /* 0x8000: Secondary disk DMA enable, 0x0201: Number of words to transfer = 513 = 1026 bytes. The value must be written twice to actually start the DMA */
        }
        int_end();
}


#asm
_S0570_COPYPROA_IntHandlerStub_C:
        movem.l a0-a1,-(sp)
        bsr.s _F0569_COPYPROA_FloppyInterruptH
        addq.l  #8,sp
        rts
#endasm
#endif
#ifdef MEDIA626_A31E_A31M_A33M_A35E_A35M
struct Interrupt G3224_s_Interrupt_CPSX;

int16_t F0569_COPYPROA_FloppyInterruptHandler_CPSX(
)
{
        asm {
                        movem.l d1-d7/a0-a6,-(sp)
                        movea.l (a1),a5
        }
        if (G0625_i_FloppyDriveDMATimeout_CPSDF == 3) {
                G0625_i_FloppyDriveDMATimeout_CPSDF = 4;
                ciab.ciaprb = CIAF_DSKSEL3 | CIAF_DSKSEL2 | CIAF_DSKSEL1 | CIAF_DSKDIREC | CIAF_DSKSTEP; /* 0x73. Select drive 0 (internal drive) */
                if ((ciaa.ciapra & CIAF_DSKTRACK0) == 0) { /* If drive head is over track 0 */
                /*asm {
                        move.b  (0xBFE001).l,d0
                        andi.l  #0x10,d0
                        tst.l   d0
                        bne.s   @Tloc_11B18
                }*/
                        custom.dsklen = 0x846A;
                        custom.dsklen = 0x846A; /* 0x8000: Secondary disk DMA enable, 0x046A: Number of words to transfer = 1130 = 2260 bytes. The value must be written twice to actually start the DMA */
                }
        }
        asm {
                /*@Tloc_11B18:*/
                        movem.l (sp)+,d1-d7/a0-a6
        }
        return 0;
}

void F0567_COPYPROA_InitFloppyInterruptHandler_CPSX(
)
{
        G3224_s_Interrupt_CPSX.is_Node.ln_Type = NT_INTERRUPT;
        G3224_s_Interrupt_CPSX.is_Node.ln_Name = NULL;
        G3224_s_Interrupt_CPSX.is_Node.ln_Pri = 127;
        G3224_s_Interrupt_CPSX.is_Data = (APTR)&G3153_puc_A5Backup;
        G3224_s_Interrupt_CPSX.is_Code = F0569_COPYPROA_FloppyInterruptHandler_CPSX;
}
#endif
#endif
#endif
