#ifndef COMPILE_H
#include "COMPILE.H"
#endif
#ifdef MEDIA754_A36M_A31E_A31M_A33M_A35E_A35M_AU1E_AU2E_AU2F_AU2G_AU3E
#if (EXETYPE == C03_GAME)
unsigned char* G3169_puc_ChipMemoryBlock1Bottom;
#ifdef MEDIA758_A36M_A35E_A35M
unsigned char* G3250_puc_ChipMemoryBlock2Bottom;
#endif
unsigned char* G3170_puc_FastMemoryBlockBottom;
#ifdef MEDIA618_A31E
unsigned long G3167_l_ChipMemoryBlock1ByteCount;
unsigned long G3168_l_FastMemoryBlockByteCount;
#endif
#ifdef MEDIA755_A36M_A31M_A33M_A35E_A35M
long G3167_l_ChipMemoryBlock1ByteCount;
#endif
#ifdef MEDIA758_A36M_A35E_A35M
long G3251_l_ChipMemoryBlock2ByteCount;
#endif
#ifdef MEDIA755_A36M_A31M_A33M_A35E_A35M
long G3168_l_FastMemoryBlockByteCount;
#endif
struct Task* G3165_ps_CurrentTask;
#endif
unsigned char* G3153_puc_A5Backup;
#if ((EXETYPE == C03_GAME) || (EXETYPE == C01_SWOOSH) || (EXETYPE == C07_HINT) || (defined(MEDIA762_AU1E) && (EXETYPE == C06_CEDT)))
struct MsgPort* G3155_ps_MsgPort;
struct IOStdReq* G3156_ps_IOStdReq_Console;
#endif
#if (EXETYPE == C03_GAME)
struct IOStdReq* G1034_ps_IOStdReq;
struct MsgPort* G3158_ps_MsgPort1;
BOOLEAN G3157_B_InputDeviceAllocated;
#endif
#if ((EXETYPE == C03_GAME) || (EXETYPE == C01_SWOOSH) || (EXETYPE == C07_HINT) || (defined(MEDIA762_AU1E) && (EXETYPE == C06_CEDT)))
FILE_HANDLE G3160_ps_NIL2;
FILE_HANDLE G3159_ps_NIL1;
#endif
#if (EXETYPE == C03_GAME)
AMISTRUCT* G3161_ac_Buffer724Bytes;
BOOLEAN G3164_B_;
unsigned char* G3162_;
unsigned char* G3163_;
#endif


void F1157_BackupA5(
)
{
        asm {
                move.l  a5,G3153_puc_A5Backup(a5)
        }
}

#if (EXETYPE != C03_GAME)
void F9073_DisplayError(P2857_)
long P2857_;
{
        long L3684_l_ = 0xDEADBEEF;


        Alert(P2857_, &L3684_l_);
}
#endif

void F1069_OpenDosLibrary(
)
{
        if ((DOSBase = (BPTR)OpenLibrary("dos.library", 31L)) == NULL) {
#if (EXETYPE == C03_GAME)
                F1050_AlertCSBSystemError(0x80FF0001);
#else
                F9073_DisplayError(0x80F10001);
#endif
        }
}

void F1070_CloseDosLibrary(
)
{
        if (DOSBase) {
                CloseLibrary(DOSBase);
                DOSBase = NULL;
        }
}

#if (EXETYPE != C12_FIO1)
void F1071_OpenGraphicsLibrary(
)
{
        if ((GfxBase = (struct GfxBase*)OpenLibrary("graphics.library", 31L)) == NULL) {
#if (EXETYPE == C03_GAME)
                F1050_AlertCSBSystemError(0x80FF0003);
#else
                F9073_DisplayError(0x80F10003);
#endif
        }
}

void F1072_CloseGraphicsLibrary(
)
{
        if (GfxBase) {
                CloseLibrary(GfxBase);
                GfxBase = NULL;
        }
}

void F1073_OpenIntuitionLibrary(
)
{
        if ((IntuitionBase = (struct IntuitionBase*)OpenLibrary("intuition.library", 31L)) == NULL) {
#if (EXETYPE == C03_GAME)
                F1050_AlertCSBSystemError(0x80FF0004);
#else
                F9073_DisplayError(0x80F10004);
#endif
        }
}

void F1074_CloseIntuitionLibrary(
)
{
        if (IntuitionBase) {
                CloseLibrary(IntuitionBase);
                IntuitionBase = NULL;
        }
}
#endif

#if ((EXETYPE == C03_GAME) || (EXETYPE == C07_HINT) || (EXETYPE == C01_SWOOSH) || (defined(MEDIA762_AU1E) && (EXETYPE == C06_CEDT)))
void F1075_OpenLayersLibrary(
)
{
        if ((LayersBase = (APTR)OpenLibrary("layers.library", 31L)) == NULL) {
#if (EXETYPE == C03_GAME)
                F1050_AlertCSBSystemError(0x80FF0005);
#else
                F9073_DisplayError(0x80F10005);
#endif
        }
}

void F1076_CloseLayersLibrary(
)
{
        if (LayersBase) {
                CloseLibrary(LayersBase);
                LayersBase = NULL;
        }
}

void F1077_OpenConsoleDevice(
)
{
        G3154_ps_Device_Console = NULL;
        if ((G3155_ps_MsgPort = CreatePort(NULL, 0L)) == NULL) {
#if (EXETYPE == C03_GAME)
                F1050_AlertCSBSystemError(0x80FF000A);
#else
                F9073_DisplayError(0x80F1000A);
#endif
        }
        if ((G3156_ps_IOStdReq_Console = CreateStdIO(G3155_ps_MsgPort)) == NULL) {
#if (EXETYPE == C03_GAME)
                F1050_AlertCSBSystemError(0x80FF000B);
#else
                F9073_DisplayError(0x80F1000A);
#endif
        }
        if (OpenDevice("console.device", -1L, G3156_ps_IOStdReq_Console, 0L)) {
#if (EXETYPE == C03_GAME)
                F1050_AlertCSBSystemError(0x80FF000C);
#else
                F9073_DisplayError(0x80F1000A);
#endif
        }
        G3154_ps_Device_Console = G3156_ps_IOStdReq_Console->io_Device;
}

void F1078_CloseConsoleDevice(
)
{
        if (G3154_ps_Device_Console) {
                CloseDevice(G3156_ps_IOStdReq_Console);
                G3154_ps_Device_Console = NULL;
        }
        if (G3156_ps_IOStdReq_Console) {
                DeleteStdIO(G3156_ps_IOStdReq_Console);
                G3156_ps_IOStdReq_Console = NULL;
        }
        if (G3155_ps_MsgPort) {
                DeletePort(G3155_ps_MsgPort);
                G3155_ps_MsgPort = NULL;
        }
}
#endif

#if (EXETYPE == C03_GAME)
void F1079_OpenInputDevice(
)
{
        G3157_B_InputDeviceAllocated = C0_FALSE;
        if ((G3158_ps_MsgPort1 = CreatePort(NULL, 0L)) == NULL) {
                F1050_AlertCSBSystemError(0x80FF000D);
        }
        if ((G1034_ps_IOStdReq = CreateStdIO(G3158_ps_MsgPort1)) == NULL) {
                F1050_AlertCSBSystemError(0x80FF000E);
        }
        if (OpenDevice("input.device", 0L, G1034_ps_IOStdReq, 0L)) {
                F1050_AlertCSBSystemError(0x80FF000F);
        }
        G3157_B_InputDeviceAllocated = C1_TRUE;
}

void F1080_CloseInputDevice(
)
{
        if (G3157_B_InputDeviceAllocated) {
                CloseDevice(G1034_ps_IOStdReq);
                G3157_B_InputDeviceAllocated = C0_FALSE;
        }
        if (G1034_ps_IOStdReq) {
                DeleteStdIO(G1034_ps_IOStdReq);
                G1034_ps_IOStdReq = NULL;
        }
        if (G3158_ps_MsgPort1) {
                DeletePort(G3158_ps_MsgPort1);
                G3158_ps_MsgPort1 = NULL;
        }
}
#endif

#if ((EXETYPE == C03_GAME) || (EXETYPE == C07_HINT) || (EXETYPE == C01_SWOOSH) || (defined(MEDIA762_AU1E) && (EXETYPE == C06_CEDT)))
void F1081_OpenNIL(
)
{
        if ((G3160_ps_NIL2 = G3159_ps_NIL1 = Open("NIL:", MODE_NEWFILE)) == NULL) {
#if (EXETYPE == C03_GAME)
                F1050_AlertCSBSystemError(0x80FF0002);
#else
                F9073_DisplayError(0x80F10002);
#endif
        }
}

void F1082_CloseNIL(
)
{
        if (G3160_ps_NIL2) {
                Close(G3160_ps_NIL2);
        }
        G3159_ps_NIL1 = NULL;
        G3160_ps_NIL2 = NULL;
}
#endif

#if (EXETYPE == C03_GAME)
void F1083_Allocate724Bytes(
)
{
        if ((G3161_ac_Buffer724Bytes = AllocMem((long)sizeof(AMISTRUCT), MEMF_CLEAR)) == NULL) {
                F1050_AlertCSBSystemError(0x80FF0010);
        }
}

void F1084_Free724Bytes(
)
{
        if (G3161_ac_Buffer724Bytes) {
                FreeMem(G3161_ac_Buffer724Bytes, (long)sizeof(AMISTRUCT));
        }
        G3161_ac_Buffer724Bytes = NULL;
}

int16_t F1085_IntuitionVectorReplacement(
)
{
        return 0;
}

void F1086_ReplaceIntuitionVectors(
)
{
        /* Replace vector of function 'AutoRequest' in intuition.library */
        G3162_ = (unsigned char*)SetFunction(IntuitionBase, (long)-0x15C, F1085_IntuitionVectorReplacement); /* 0xFFFFFEA4 -348 */
        /* Replace vector of function 'BuildSysRequest' in intuition.library */
        G3163_ = (unsigned char*)SetFunction(IntuitionBase, (long)-0x168, F1085_IntuitionVectorReplacement); /* 0xFFFFFE98 -360 */
        G3164_B_ = C1_TRUE;
}

void F1087_RestoreIntuitionVectors(
)
{
        if (G3164_B_) {
                G3164_B_ = C0_FALSE;
                /* Restore vector of function 'AutoRequest' in intuition.library */
                /* Restore vector of function 'BuildSysRequest' in intuition.library */
                if (((unsigned char*)SetFunction(IntuitionBase, (long)-0x15C, G3162_) != F1085_IntuitionVectorReplacement) || ((unsigned char*)SetFunction(IntuitionBase, (long)-0x168, G3163_) != F1085_IntuitionVectorReplacement)) {
                        F1050_AlertCSBSystemError(0x80FF0015);
                }
        }
}
#endif

#if ((defined(MEDIA762_AU1E) && (EXETYPE == C06_CEDT)) || (EXETYPE == C07_HINT) || (EXETYPE == C01_SWOOSH))
void F1282_WriteString(char* P4378_pc_String) {
        Write(G3159_ps_NIL1, P4378_pc_String, (long)(unsigned int16_t)F0090_strlen(P4378_pc_String));
}

void F1283_WriteCharacter_Unreferenced(char P4379_c_Character) {
        Write(G3159_ps_NIL1, &P4379_c_Character, 1L);
}

void F1284_(
)
{
        WaitForChar(G3160_ps_NIL2, 1L);
}

int16_t F1285_(
)
{
        char L6602_;


        Read(G3160_ps_NIL2, &L6602_, 1L);
        return L6602_;
}
#endif

void F1088_OpenAmigaStuff(
)
{
        F1065_SetExecBase();
        F1157_BackupA5();
#if (EXETYPE == C03_GAME)
        F1083_Allocate724Bytes();
        F1073_OpenIntuitionLibrary();
        G3165_ps_CurrentTask = FindTask(0L);
#endif
        F1069_OpenDosLibrary();
#if (EXETYPE != C12_FIO1)
        F1071_OpenGraphicsLibrary();
#endif
#if ((EXETYPE == C03_GAME) || (EXETYPE == C07_HINT) || (EXETYPE == C01_SWOOSH) || (defined(MEDIA762_AU1E) && (EXETYPE == C06_CEDT)))
        F1075_OpenLayersLibrary();
#endif
#if ((EXETYPE != C03_GAME) && (EXETYPE != C12_FIO1))
        F1073_OpenIntuitionLibrary();
#endif
#if (EXETYPE == C03_GAME)
        F1086_ReplaceIntuitionVectors();
        F1079_OpenInputDevice();
#endif
#if ((EXETYPE == C03_GAME) || (EXETYPE == C07_HINT) || (EXETYPE == C01_SWOOSH) || (defined(MEDIA762_AU1E) && (EXETYPE == C06_CEDT)))
        F1077_OpenConsoleDevice();
        F1081_OpenNIL();
#endif
}

void F1089_CloseAmigaStuff(
)
{
#if ((EXETYPE == C03_GAME) || (EXETYPE == C07_HINT) || (EXETYPE == C01_SWOOSH) || (defined(MEDIA762_AU1E) && (EXETYPE == C06_CEDT)))
        F1082_CloseNIL();
        F1078_CloseConsoleDevice();
#endif
#if (EXETYPE == C03_GAME)
        F1080_CloseInputDevice();
#endif
        F1070_CloseDosLibrary();
#if (EXETYPE != C12_FIO1)
        F1072_CloseGraphicsLibrary();
#endif
#if ((EXETYPE == C03_GAME) || (EXETYPE == C07_HINT) || (EXETYPE == C01_SWOOSH) || (defined(MEDIA762_AU1E) && (EXETYPE == C06_CEDT)))
        F1076_CloseLayersLibrary();
#endif
#if (EXETYPE == C03_GAME)
        F1087_RestoreIntuitionVectors();
#endif
#if (EXETYPE != C12_FIO1)
        F1074_CloseIntuitionLibrary();
#endif
#if (EXETYPE == C03_GAME)
        F1084_Free724Bytes();
#endif
}

#if (EXETYPE == C03_GAME)
char* F1090_GetCSBInternalErrorMessage(
)
{
        asm {
                        lea     @Tbyte_5E8,a0
                        move.l  a0,d0
                        rts
                @Tbyte_5E8:
                        dc.b 0x00, 0xB8                                 /* 16 bit X coordinate */
                        dc.b 0x10                                       /* 8 bit Y coordinate */
                        dc.b "Chaos Strikes Back System Error 00", 0    /* Null terminated string */
                        dc.b 0xFF                                       /* Non-null continuation byte, there is another substring */
                        dc.b 0x00, 0xB8                                 /* 16 bit X coordinate */
                        dc.b 0x1C                                       /* 8 bit Y coordinate */
                        dc.b "Press Left Mouse Button to Restart", 0    /* Null terminated string */
                        dc.b 0x00                                       /* Null continuation byte, no more substrings */
        }
}

char* F1091_GetCSBSystemErrorMessage(
)
{
        asm {
                        lea     @Tbyte_640,a0
                        move.l  a0,d0
                        rts
                @Tbyte_640:
                        dc.b 0x00, 0x94                                         /* 16 bit X coordinate */
                        dc.b 0x10                                               /* 8 bit Y coordinate */
                        dc.b "Chaos Strikes Back Internal Error: 00000000", 0   /* Null terminated string */
                        dc.b 0xFF                                               /* Non-null continuation byte, there is another substring */
                        dc.b 0x00, 0xB8                                         /* 16 bit X coordinate */
                        dc.b 0x1C                                               /* 8 bit Y coordinate */
                        dc.b "Press Left Mouse Button to Restart", 0            /* Null terminated string */
                        dc.b 0x00                                               /* Null continuation byte, no more substrings */
        }
}

char* F1092_GetHexadecimalDigits(
)
{
        asm {
                        lea     @Tbyte_6A2,a0
                        move.l  a0,d0
                        rts
                @Tbyte_6A2:
                        dc.b "0123456789abcdef"
        }
}

void F1093_DisplayAlertCSBInternalError(P2790_i_ErrorCode)
int16_t P2790_i_ErrorCode;
{
        register char* L2593_pc_CSBInternalErrorMessage;
        register char* L2594_pc_HexadecimalDigits;


        L2593_pc_CSBInternalErrorMessage = F1090_GetCSBInternalErrorMessage() + 37; /* Address of first '0' to replace by actual error value */
        L2594_pc_HexadecimalDigits = F1092_GetHexadecimalDigits();
        *--L2593_pc_CSBInternalErrorMessage = L2594_pc_HexadecimalDigits[P2790_i_ErrorCode % 10];
        P2790_i_ErrorCode /= 10;
        *--L2593_pc_CSBInternalErrorMessage = L2594_pc_HexadecimalDigits[P2790_i_ErrorCode % 10];
        Disable();
        DisplayAlert(AT_DeadEnd, F1090_GetCSBInternalErrorMessage(), 42L);
        ResetAmiga();
}

void F1094_DisplayAlertCSBSystemError(P2791_ul_ErrorCode)
unsigned long P2791_ul_ErrorCode;
{
        register char* L2595_pc_CSBSystemErrorMessage;
        register char* L2596_pc_HexadecimalDigits;
        register int16_t D7;


        D7 = 0;
        L2595_pc_CSBSystemErrorMessage = F1091_GetCSBSystemErrorMessage() + 46; /* Address of first '0' to replace by actual error value */
        L2596_pc_HexadecimalDigits = F1092_GetHexadecimalDigits();
        while (D7 < 8) {
                *--L2595_pc_CSBSystemErrorMessage = L2596_pc_HexadecimalDigits[P2791_ul_ErrorCode & 0x0F];
                D7++;
                P2791_ul_ErrorCode >>= 4;
        }
        Disable();
        DisplayAlert(AT_DeadEnd, F1091_GetCSBSystemErrorMessage(), 42L);
        ResetAmiga();
}

void F1050_AlertCSBSystemError(P2792_)
long P2792_;
{
        long L2597_l_;


        if (IntuitionBase) {
                F1094_DisplayAlertCSBSystemError(P2792_);
        }
        if (P2792_ & AT_DeadEnd) {
                L2597_l_ = 0xDEADBEEF;
        } else {
                L2597_l_ = 0xFEEDBEEF;
        }
        Alert(AT_DeadEnd | P2792_, &L2597_l_);
}

#ifdef MEDIA758_A36M_A35E_A35M
long F1066_GetUsableChipMemoryByteCount(
)
{ /* Returns the maximum amount of chip memory that can be allocated while leaving to the OS and other programs at least 16K available including at least one block of at least 8K */
        register char* L2598_pc_ChipMemoryLargestBlockBottom;
        register long L2599_l_ChipMemoryRequirement;
        register long L2600_l_LargestChipMemoryBlockRequirement;
        register long L2601_l_;
        register long L2602_l_SecondLargestChipMemoryBlockByteCount;
        register long L2603_l_AvailableChipMemoryExceptLargestBlockByteCount;


        L2599_l_ChipMemoryRequirement = MEMF_CHIP;
        L2600_l_LargestChipMemoryBlockRequirement = L2599_l_ChipMemoryRequirement | MEMF_LARGEST;
        Forbid();
        if (((L2601_l_ = AvailMem(L2600_l_LargestChipMemoryBlockRequirement)) < 8192) || (AvailMem(L2599_l_ChipMemoryRequirement) < 16384)) { /* If the largest chip memory block is smaller than 8K or if there is not at least 16K of available chip memory */
                L2601_l_ = 0;
        } else {
                if ((L2598_pc_ChipMemoryLargestBlockBottom = AllocMem(L2601_l_, L2599_l_ChipMemoryRequirement)) == NULL) {
                        F1050_AlertCSBSystemError(0x80FF0017);
                }
                L2602_l_SecondLargestChipMemoryBlockByteCount = AvailMem(L2600_l_LargestChipMemoryBlockRequirement);
                L2603_l_AvailableChipMemoryExceptLargestBlockByteCount = AvailMem(L2599_l_ChipMemoryRequirement);
                if (L2598_pc_ChipMemoryLargestBlockBottom != NULL) {
                        FreeMem(L2598_pc_ChipMemoryLargestBlockBottom, L2601_l_);
                }
                if (L2602_l_SecondLargestChipMemoryBlockByteCount < 8192) { /* Make sure at least one 8K block remains available */
                        L2601_l_ -= 8192;
                        L2603_l_AvailableChipMemoryExceptLargestBlockByteCount += 8192;
                }
                if (L2603_l_AvailableChipMemoryExceptLargestBlockByteCount < 16384) { /* Make sure a total of at least 16K remains available */
                        L2601_l_ -= 16384 - L2603_l_AvailableChipMemoryExceptLargestBlockByteCount;
                }
                if (L2601_l_ < 0) {
                        L2601_l_ = 0;
                }
        }
        Permit();
        return L2601_l_;
}
#endif

void F1067_InitAmigaStuff(
)
{
#ifdef MEDIA625_A31E_A31M_A33M_A35E
        G3134_PRIM_Executable->Parameter = 0;
#endif
#ifdef MEDIA760_A36M_A35M
        G3134_PRIM_Executable->Parameter = FTL_APPB;
#endif
        F1088_OpenAmigaStuff();
        F0575_VerticalBlank_Initialize();
        F1133_AddCopperInterrupt();
        F1111_CPSX();
#ifdef MEDIA626_A31E_A31M_A33M_A35E_A35M
        F1149_Init_CPSX();
#endif
        F0945_InitAudioData();
        F1123_();
#ifdef MEDIA626_A31E_A31M_A33M_A35E_A35M
        F0567_COPYPROA_InitFloppyInterruptHandler_CPSX();
        if ((G1001_pc_FuzzySectorReadingBuffer_CPSE = AllocMem(2260L, MEMF_CHIP)) == NULL) {
                F1050_AlertCSBSystemError(0x80FF0016);
        }
#endif
        G0349_ul_LastRandomNumber = IntuitionBase->Micros;
        Forbid();
#ifdef MEDIA620_A31E_A31M_A33M
        G3167_l_ChipMemoryBlock1ByteCount = AvailMem(MEMF_LARGEST | MEMF_CHIP); /* All Amiga computers have chip memory */
        G3168_l_FastMemoryBlockByteCount = AvailMem(MEMF_LARGEST | MEMF_FAST); /* Some Amiga computers have fast memory */
        G3167_l_ChipMemoryBlock1ByteCount -= 16384; /* Leave at least 16K available to the OS and other programs */
#endif
#ifdef MEDIA758_A36M_A35E_A35M
        G3167_l_ChipMemoryBlock1ByteCount = F1066_GetUsableChipMemoryByteCount() & 0xFFFFFFFE;
        G3168_l_FastMemoryBlockByteCount = AvailMem(MEMF_LARGEST | MEMF_FAST) & 0xFFFFFFFE;
        if (G3167_l_ChipMemoryBlock1ByteCount < 0) {
                G3167_l_ChipMemoryBlock1ByteCount = 0;
        }
        if (G3168_l_FastMemoryBlockByteCount < 96) {
                G3168_l_FastMemoryBlockByteCount = 0;
        }
#endif
        if (G3168_l_FastMemoryBlockByteCount > 524288) { /* Limit fast memory used by the game to 512K */
                G3168_l_FastMemoryBlockByteCount = 524288;
        }
#ifdef MEDIA620_A31E_A31M_A33M
        M009_CLEAR(G3167_l_ChipMemoryBlock1ByteCount, 1);
        M009_CLEAR(G3168_l_FastMemoryBlockByteCount, 1);
        if (G3167_l_ChipMemoryBlock1ByteCount < 0) {
                G3167_l_ChipMemoryBlock1ByteCount = 0;
        }
        if (G3168_l_FastMemoryBlockByteCount < 0) {
                G3168_l_FastMemoryBlockByteCount = 0;
        }
#endif
        G3169_puc_ChipMemoryBlock1Bottom = AllocMem(G3167_l_ChipMemoryBlock1ByteCount, MEMF_CHIP);
        if (G3168_l_FastMemoryBlockByteCount) {
                G3170_puc_FastMemoryBlockBottom = AllocMem(G3168_l_FastMemoryBlockByteCount, MEMF_FAST);
        }
#ifdef MEDIA758_A36M_A35E_A35M
        G3251_l_ChipMemoryBlock2ByteCount = F1066_GetUsableChipMemoryByteCount() & 0xFFFFFFFE;
        if (G3251_l_ChipMemoryBlock2ByteCount < 96) {
                G3251_l_ChipMemoryBlock2ByteCount = 0;
        }
        if (G3251_l_ChipMemoryBlock2ByteCount) {
                G3250_puc_ChipMemoryBlock2Bottom = AllocMem(G3251_l_ChipMemoryBlock2ByteCount, MEMF_CHIP);
        }
#endif
        Permit();
#ifdef MEDIA620_A31E_A31M_A33M
        if ((G3169_puc_ChipMemoryBlock1Bottom == NULL) || ((G3168_l_FastMemoryBlockByteCount > 0) && (G3170_puc_FastMemoryBlockBottom == NULL))) {
#endif
#ifdef MEDIA758_A36M_A35E_A35M
        if ((G3169_puc_ChipMemoryBlock1Bottom == NULL) || ((G3168_l_FastMemoryBlockByteCount > 0) && (G3170_puc_FastMemoryBlockBottom == NULL)) || ((G3251_l_ChipMemoryBlock2ByteCount > 0) && (G3250_puc_ChipMemoryBlock2Bottom == NULL))) {
#endif
                F1050_AlertCSBSystemError(0x80FF0017);
        }
#ifdef MEDIA620_A31E_A31M_A33M
        F0475_MEMORY_Initialize(G3169_puc_ChipMemoryBlock1Bottom, G3167_l_ChipMemoryBlock1ByteCount, 0L, 0L);
#endif
#ifdef MEDIA758_A36M_A35E_A35M
        F0475_MEMORY_Initialize(G3169_puc_ChipMemoryBlock1Bottom, G3167_l_ChipMemoryBlock1ByteCount, MASK0x07F8_MEMREQ);
        if (G3170_puc_FastMemoryBlockBottom) {
                F0475_MEMORY_Initialize(G3170_puc_FastMemoryBlockBottom, G3168_l_FastMemoryBlockByteCount, MASK0x0700_MEMREQ);
        }
        if (G3250_puc_ChipMemoryBlock2Bottom) {
                F0475_MEMORY_Initialize(G3250_puc_ChipMemoryBlock2Bottom, G3251_l_ChipMemoryBlock2ByteCount, MASK0x07F8_MEMREQ);
        }
        F0475_MEMORY_Initialize(NULL, 0L, 0);
#endif
}

void F1068_FreeAmigaStuff(
)
{
        WaitBlit();
#ifdef MEDIA758_A36M_A35E_A35M
        if (G3250_puc_ChipMemoryBlock2Bottom) {
                FreeMem(G3250_puc_ChipMemoryBlock2Bottom, G3251_l_ChipMemoryBlock2ByteCount);
        }
        G3250_puc_ChipMemoryBlock2Bottom = NULL;
#endif
#ifdef MEDIA620_A31E_A31M_A33M
        if (G3169_puc_ChipMemoryBlock1Bottom) {
                FreeMem(G3169_puc_ChipMemoryBlock1Bottom, G3167_l_ChipMemoryBlock1ByteCount);
        }
        G3169_puc_ChipMemoryBlock1Bottom = NULL;
#endif
        if (G3170_puc_FastMemoryBlockBottom) {
                FreeMem(G3170_puc_FastMemoryBlockBottom, G3168_l_FastMemoryBlockByteCount);
        }
        G3170_puc_FastMemoryBlockBottom = NULL;
#ifdef MEDIA758_A36M_A35E_A35M
        if (G3169_puc_ChipMemoryBlock1Bottom) {
                FreeMem(G3169_puc_ChipMemoryBlock1Bottom, G3167_l_ChipMemoryBlock1ByteCount);
        }
        G3169_puc_ChipMemoryBlock1Bottom = NULL;
#endif
#ifdef MEDIA626_A31E_A31M_A33M_A35E_A35M
        if (G1001_pc_FuzzySectorReadingBuffer_CPSE) {
                FreeMem(G1001_pc_FuzzySectorReadingBuffer_CPSE, 2260L);
        }
        G1001_pc_FuzzySectorReadingBuffer_CPSE = NULL;
#endif
        F1124_();
        F0946_ReleaseAudioData();
#ifdef MEDIA626_A31E_A31M_A33M_A35E_A35M
        F1150_Free_CPSX();
#endif
        F0518_FLOPPY_Deinitialize_CPSX();
        F1134_RemoveCopperInterrupt();
        F0576_VerticalBlank_Deinitialize();
        F1089_CloseAmigaStuff();
}

void F0750_CPSX(
)
{
        if (G0302_B_GameWon) {
                F1125_();
        } else {
                F1126_();
        }
        WaitBlit();
#ifdef MEDIA626_A31E_A31M_A33M_A35E_A35M
#ifndef NOCOPYPROTECTION
        while (G3171_c_ReadingCopyProtectionSector_CPSX);
#endif
#endif
        F1045_();
        F0538_INPUT_Deinitialize();
        F1068_FreeAmigaStuff();
}
#endif

#if ((defined(MEDIA763_AU1E_AU2E) && (EXETYPE == C07_HINT)) || (defined(MEDIA762_AU1E) && (EXETYPE == C06_CEDT)) || (EXETYPE == C12_FIO1) || (defined(MEDIA618_A31E) && (EXETYPE == C01_SWOOSH)) || (defined(MEDIA662_A31M_A35M) && (EXETYPE == C08_LANG)))
#include "FILE.C"     /* Cannot be a standalone C file in THINK C project (not linked in executable if no function is referenced) */
#endif
#endif
