#ifndef COMPILE_H
#include "COMPILE.H"
#endif
#ifdef MEDIA626_A31E_A31M_A33M_A35E_A35M
#ifndef NOCOPYPROTECTION
APTR G3194_Backup_ExceptCode_CPSX;
APTR G3195_Backup_ExceptData_CPSX;
BOOLEAN G3196_B_CustomExceptCodeInstalled_CPSX;
long G3193_l_SignalNumber_CPSX = -1;
#endif


#ifndef NOCOPYPROTECTION
void F1148_CustomExceptCode_CPSX(
)
{
        asm {
                move.l  d0,-(sp)
                movea.l (a1),a5
                movea.l G1054_ps_DiskResource_CPSX(a5),a6
                jsr     -0x18(a6)                       /* disk.resource/GiveUnit (see DR_GIVEUNIT in disk.h) */
                clr.b   G3171_c_ReadingCopyProtectionSector_CPSX(a5)
                move.l  (sp)+,d0
        }
}

void F1149_Init_CPSX(
)
{
        register struct Process* L2620_ps_Process;


        if ((G3193_l_SignalNumber_CPSX = AllocSignal(16L)) == -1) {
                F1050_AlertCSBSystemError(0x80FF0014);
        }
        L2620_ps_Process = (struct Process*)FindTask(0L);
        G3194_Backup_ExceptCode_CPSX = L2620_ps_Process->pr_Task.tc_ExceptCode;
        G3195_Backup_ExceptData_CPSX = L2620_ps_Process->pr_Task.tc_ExceptData;
        L2620_ps_Process->pr_Task.tc_ExceptCode = F1148_CustomExceptCode_CPSX;
        L2620_ps_Process->pr_Task.tc_ExceptData = &G3153_puc_A5Backup;
        G3196_B_CustomExceptCodeInstalled_CPSX = C1_TRUE;
        SetExcept(0x10000, 0x10000); /* Enable triggering of exception code when signal 16 occurs */
}

void F1150_Free_CPSX(
)
{
        register struct Process* L2621_ps_Process;


        if (G3196_B_CustomExceptCodeInstalled_CPSX) {
                SetExcept(0L, 0x10000); /* Disable triggering of exception code when signal 16 occurs */
                G3196_B_CustomExceptCodeInstalled_CPSX = C0_FALSE;
                L2621_ps_Process = (struct Process*)FindTask(0L);
                L2621_ps_Process->pr_Task.tc_ExceptCode = G3194_Backup_ExceptCode_CPSX;
                L2621_ps_Process->pr_Task.tc_ExceptData = G3195_Backup_ExceptData_CPSX;
        }
        if (G3193_l_SignalNumber_CPSX != -1) {
                FreeSignal(16L);
                G3193_l_SignalNumber_CPSX = -1;
        }
}
#endif
#endif
