#ifndef COMPILE_H
#include "COMPILE.H"
#endif
#ifdef MEDIA153_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_A31E_A31M_A33M_A35E_A35M
#ifndef NOCOPYPROTECTION
#ifdef MEDIA007_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E
overlay "show"

asm {
        R0138_CPSEF_HiddenCodeLauncher:
                lea     V0138005_BufferIsUsed_FirstWords(PC),A0
                clr.w   (A0)+                                                   /* Clear first word so that the buffer is now marked as free */
                movea.l V0138000_JMPTargetAddress_PatchedFunction(PC),A1        /* Address of patched function */
                move.l  (A0)+,(A1)+                                             /* Restore the first two words (a long) */
                move.w  (A0),(A1)                                               /* Restore the third word */
                movea.l V0138001_GetGraphicAddressFunction(PC),A0
                move.w  V0138002_GraphicIndex(PC),-(A7)
                jsr     (A0)
                movea.l D0,A0                                                   /* Address of graphic (hidden code) in memory */
                move.l  V0138004_HiddenCodeParameters(PC),-(A7)                 /* Address of result structure */
                move.l  V0138003_SectorBuffer(PC),-(A7)                         /* Address of buffer storing copy protection sector */
                jsr     (A0)                                                    /* Run hidden code */
                lea     0x000A(A7),A7
                dc.w    0x4EF9                                                  /* Jump to original patched function. Note: the execution result of graphic #21 or #538 is stored in the result structure by the routine itself, return value in D0 is ignored */
        V0138000_JMPTargetAddress_PatchedFunction:
                dc.l    0x00000000
        V0138001_GetGraphicAddressFunction:
                dc.l    0x00000000
        V0138002_GraphicIndex:
                dc.w    0x0000
        V0138003_SectorBuffer:
                dc.l    0x00000000
        V0138004_HiddenCodeParameters:
                dc.l    0x00000000
        V0138005_BufferIsUsed_FirstWords:
                dc.w    0x0000                                                  /* First word is 0 if buffer is not used, set to 1 if used */
                dc.w    0x0000,0x0000,0x0000                                    /* Copy of the first three words of the patched function (they were replaced with a jump to this routine) */
}
#endif
#ifdef MEDIA413_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
#asm
        _R0138_CPSEF_HiddenCodeLauncher:
                lea     V0138005_BufferIsUsed_FirstWords(PC),A0
                clr.w   (A0)+
                movea.l V0138000_JMPTargetAddress_PatchedFunction(PC),A1
                move.l  (A0)+,(A1)+
                move.w  (A0),(A1)
                movea.l V0138001_GetGraphicAddressFunction(PC),A0
                move.w  V0138002_GraphicIndex(PC),-(A7)
                jsr     (A0)
                movea.l D0,A0
                move.l  V0138004_HiddenCodeParameters(PC),-(A7)
                move.l  V0138003_SectorBuffer(PC),-(A7)
                jsr     (A0)
                lea     $000A(A7),A7
                dc.w    $4EF9
        V0138000_JMPTargetAddress_PatchedFunction:
                dc.l    $00000000
        V0138001_GetGraphicAddressFunction:
                dc.l    $00000000
        V0138002_GraphicIndex:
                dc.w    $0000
        V0138003_SectorBuffer:
                dc.l    $00000000
        V0138004_HiddenCodeParameters:
                dc.l    $00000000
        V0138005_BufferIsUsed_FirstWords:
                dc.w    $0000
                dc.w    $0000,$0000,$0000
#endasm
#endif
#ifdef MEDIA626_A31E_A31M_A33M_A35E_A35M
void R0138_CPSEF_HiddenCodeLauncher(
)
{
        asm {
                        lea     @T0138005_BufferIsUsed_FirstWords(PC),A0
                        clr.w   (A0)+
                        movea.l @T0138000_JMPTargetAddress_PatchedFunction(PC),A1
                        move.l  (A0)+,(A1)+
                        move.w  (A0),(A1)
                        movea.l @T0138001_GetGraphicAddressFunction(PC),A0
                        move.w  @T0138002_GraphicIndex(PC),-(A7)
                        jsr     (A0)
                        movea.l D0,A0
                        move.l  @T0138004_HiddenCodeParameters(PC),-(A7)
                        move.l  @T0138003_SectorBuffer(PC),-(A7)
                        jsr     (A0)
                        lea     0x000A(A7),A7
                        dc.w    0x4EF9
                @T0138000_JMPTargetAddress_PatchedFunction:
                        dc.l    0x00000000
                @T0138001_GetGraphicAddressFunction:
                        dc.l    0x00000000
                @T0138002_GraphicIndex:
                        dc.w    0x0000
                @T0138003_SectorBuffer:
                        dc.l    0x00000000
                @T0138004_HiddenCodeParameters:
                        dc.l    0x00000000
                @T0138005_BufferIsUsed_FirstWords:
                        dc.w    0x0000
                        dc.w    0x0000,0x0000,0x0000
        }
}
#endif
#endif
#endif
