#ifndef COMPILE_H
#include "COMPILE.H"
#endif
#ifdef MEDIA042_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
#ifdef MEDIA413_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
long G1018_l_AvailableChipMemoryByteCount;
unsigned char* G1019_puc_AvailableGEMMemoryBottom;
long G1020_l_AvailableGEMMemoryByteCount;
unsigned char* G1021_puc_AvailableChipMemoryBottom;
#endif
#ifdef MEDIA425_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_A36M_A31E_A31M_A33M_A35E_A35M
FILE_HANDLE G1134_ps_GraphicsDatFileHandle;
#endif
#ifdef MEDIA098_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_F31E_F31J_X31J_P31J
FILE_HANDLE G0630_i_GraphicsDatFileHandle;
#endif
int16_t G0631_i_GraphicsDatFileReferenceCount;
unsigned int16_t G0632_ui_GraphicCount;
long G0633_l_GraphicsDatFileSize;
unsigned int16_t* G0634_pui_GraphicCompressedByteCount;
unsigned int16_t* G0635_pui_GraphicDecompressedByteCount;
unsigned char HUGE** G0636_ppuc_Graphics;
unsigned int16_t* G0637_pui_NativeBitmapBlockIndices;
unsigned int16_t* G0638_pui_DerivedBitmapBlockIndices;
#ifdef MEDIA040_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_P31J
unsigned int16_t* G0639_DerivedBitmapByteCount;
#endif
#ifdef MEDIA692_X31J
unsigned long* G0639_DerivedBitmapByteCount;
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
GRATTR* G2005_GraphicWidthHeight;
#endif
int16_t G0640_i_FloppyDiskReadBufferGraphicsDatChunkIndex = -1;
#ifdef MEDIA593_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
int16_t G2065_GraphicsDatFileFormat = -1;
#endif
unsigned char HUGE* G0641_puc_CacheMemoryBottom;
#ifdef MEDIA047_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
unsigned char HUGE* G0642_puc_GraphicMemoryBottom; /* C31J: Check if this should be swapped with G0649_puc_GraphicMemoryTop */
#endif
unsigned char HUGE* G0643_puc_FloppyDiskReadBuffer_CPSDF;
int16_t G0644_i_FloppyDiskReadBufferContentType_CPSDF;
unsigned char HUGE* G0645_puc_HeapMemoryTop;
unsigned char HUGE* G0646_puc_AvailableHeapMemoryTop;
#ifdef MEDIA072_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_X30J_P20JA_P20JB_A36M_A31E_A31M_A33M_A35E_A35M_X31J
long G0647_l_Unreferenced; /* BUG0_00 Useless code */
#endif
#ifdef MEDIA553_F20E_F20J_I34E_I34M_F31E_F31J_P31J
long G2209_Unreferenced; /* Merge: most probably identical to G0647_l_Unreferenced. =>Remove conditions, included in all versions */
#endif
long G0648_l_AvailableHeapMemoryByteCount;
#ifdef MEDIA452_A21E_A22E_A31E_A31M_A33M
long G1148_l_MemorySize;
#endif
#ifdef MEDIA728_I34E_I34M_A36M_A35E_A35M
unsigned char HUGE* G2182_puc_AvailableEMSMemoryTop;
#endif
#ifdef MEDIA033_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A31E_A31M_A33M_F31E_F31J_X31J_P31J
unsigned char HUGE* G0649_puc_GraphicMemoryTop;
#endif
#ifdef MEDIA022_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_A31E_A31M_A33M_F31E_F31J_X31J_P31J
unsigned char HUGE* G0650_puc_GraphicMemoryBottomTemp;
#endif
#ifdef MEDIA758_A36M_A35E_A35M
long G0653_l_AvailableGEMMemoryByteCount;
#endif
#ifdef MEDIA728_I34E_I34M_A36M_A35E_A35M
MEMORY_AREA G2058_GraphicBaseMemoryArea; /* First address may be G0649_puc_GraphicMemoryTop. Second address is G0650_puc_GraphicMemoryBottomTemp */
MEMORY_AREA G2057_GraphicEMSMemoryArea;
#endif
unsigned char HUGE* G0651_puc_CacheMemoryTop;
#ifdef MEDIA728_I34E_I34M_A36M_A35E_A35M
MEMORY_CHUNK* G2137_ps_FirstMemoryChunk;
#endif
#ifdef MEDIA022_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_A31E_A31M_A33M_F31E_F31J_X31J_P31J
unsigned char HUGE* G0652_puc_AvailableGEMMemoryBottom; /* replaced by G2182_puc_AvailableEMSMemoryTop */
#endif
#ifdef MEDIA033_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A31E_A31M_A33M_F31E_F31J_X31J_P31J
long G0653_l_AvailableGEMMemoryByteCount;
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
BOOLEAN G2232_B_GraphicMemoryInitialized;
#endif
#ifdef MEDIA758_A36M_A35E_A35M
BOOLEAN G3074_B_MemoryInitializationComplete;
#endif
#ifdef MEDIA022_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_A31E_A31M_A33M_F31E_F31J_X31J_P31J
BOOLEAN G0654_B_GraphicMemoryInitialized;
#endif
unsigned char HUGE** G0655_ppuc_Blocks;
long G0656_l_AvailableCacheMemoryByteCount;
unsigned char HUGE* G0657_puc_FirstUnusedBlock;
unsigned char HUGE* G0658_puc_FirstUsedBlock;
unsigned char HUGE* G0659_puc_LastUsedBlock;
unsigned char HUGE* G0660_puc_FirstReferencedUsedBlock;
#ifdef MEDIA022_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_A31E_A31M_A33M_F31E_F31J_X31J_P31J
BOOLEAN G0661_B_LargeHeapMemory;
#endif
long G0662_l_LastResetCacheUsageCountsTime;
#ifdef MEDIA624_A31E_A31M_A33M_X31J_P31J
long G2231_l_ByteCount;
#endif
#ifdef MEDIA728_I34E_I34M_A36M_A35E_A35M
BOOLEAN G2136_B_EvaluatingMemoryRequirements;
long G2138_l_AvailableMemoryByteCountForSounds;
#endif
#ifdef MEDIA722_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_X31J_P31J
long G2173_l_AvailableCacheMemoryByteCountAfterLoadingGraphics; /* Some memory size drawn when "mem" typed in game */
#endif
#ifdef MEDIA736_I34M_A36M_A31M_A33M_A35M
int16_t G2004_LocalizedGraphicIndices[10][3] = {
        {   4, 728, 738 },
        {   6, 729, 739 },
        {  27, 730, 740 },
        {  30, 731, 741 },
        {  31, 732, 742 },
        {  32, 733, 743 },
        {  40, 734, 744 },
        { 694, 735, 745 },
        { 699, 736, 746 },
        { 700, 737, 747 } };
#endif
#ifdef MEDIA722_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_X31J_P31J
int16_t G2066_ = 0;
#endif
#ifdef MEDIA749_A36M_A31E_A31M_A33M_A35E_A35M_X31J
char G2006_[8] = { '_', 'm', 'e', 'm', 'd', 'b', 'g', 0 };
#endif
#ifdef MEDIA709_I34E_I34M_P31J
char G2006_[8] = { 'm', 'e', 'm', 0, 0, 0, 0, 0 };
#endif
#ifdef MEDIA707_I34E_I34M
long G2198_Unreferenced;
#endif


#ifdef MEDIA007_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E
overlay "memory"
#endif
#ifdef MEDIA351_G14ED_G20E_G21E
segment "memory"
#endif

STATICFUNCTION long F0467_MEMORY_GetGraphicOffset(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0875_ui_GraphicIndex)
#endif
REGISTER unsigned int16_t P0875_ui_GraphicIndex FINAL_SEPARATOR
{
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        REGISTER long L1479_l_Offset;
#endif
        REGISTER unsigned int16_t L1480_ui_GraphicIndex;
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER long L1479_l_Offset;
#endif


#ifdef MEDIA014_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J
        L1479_l_Offset = 2 + (G0632_ui_GraphicCount << 2);
#endif
#ifdef MEDIA593_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        if (G2065_GraphicsDatFileFormat == 1) {
                L1479_l_Offset = (sizeof(int16_t) * 2) + (G0632_ui_GraphicCount * (sizeof(int16_t) * 4)); /* Header size: 2 ints (magic number / number of graphics) + 4 ints per graphic (width / height / two attributes) */
        } else {
                L1479_l_Offset = sizeof(int16_t) + (G0632_ui_GraphicCount * (sizeof(int16_t) * 2)); /* Header size: 1 int16_t (number of graphics) + 2 ints per graphic (width / height) */
        }
#endif
        for (L1480_ui_GraphicIndex = 0; L1480_ui_GraphicIndex < P0875_ui_GraphicIndex; L1480_ui_GraphicIndex++) {
                L1479_l_Offset += G0634_pui_GraphicCompressedByteCount[L1480_ui_GraphicIndex];
        }
        return L1479_l_Offset;
}

#ifdef MEDIA758_A36M_A35E_A35M
void F1007_AddMemoryChunk(
register MEMORY_CHUNK* P2943_ps_MemoryChunk SEPARATOR
long                   P2944_l_ByteCount    SEPARATOR
int16_t                P2945_i_Requirements FINAL_SEPARATOR
{
        P2943_ps_MemoryChunk->Next = G2137_ps_FirstMemoryChunk;
        P2943_ps_MemoryChunk->TotalByteCount = P2944_l_ByteCount - sizeof(MEMORY_CHUNK);
        P2943_ps_MemoryChunk->Requirements = P2945_i_Requirements;
        P2943_ps_MemoryChunk->InUse = C0_FALSE;
        P2943_ps_MemoryChunk->BackupTop = P2943_ps_MemoryChunk->Top = (char*)P2943_ps_MemoryChunk + P2943_ps_MemoryChunk->TotalByteCount + sizeof(MEMORY_CHUNK);
        P2943_ps_MemoryChunk->BackupAvailableByteCount = P2943_ps_MemoryChunk->AvailableByteCount = P2943_ps_MemoryChunk->TotalByteCount;
        G2137_ps_FirstMemoryChunk = P2943_ps_MemoryChunk;
}

MEMORY_CHUNK* F1008_GetLargestAvailableMemoryChunk(
register int16_t P2946_i_Requirements FINAL_SEPARATOR
{ /* Returns memory chunk with the largest TotalByteCount that is not in use and meets requirements */
        register long L1863_LargestMemoryChunkSize;
        register MEMORY_CHUNK* L1864_ps_MemoryChunk;
        register MEMORY_CHUNK* L1865_ps_SelectedMemoryChunk;


        L1865_ps_SelectedMemoryChunk = NULL;
        L1863_LargestMemoryChunkSize = 0;
        if ((L1864_ps_MemoryChunk = G2137_ps_FirstMemoryChunk) == NULL) {
                return NULL;
        }
        do {
                if (L1864_ps_MemoryChunk->InUse == C0_FALSE) {
                        if ((L1864_ps_MemoryChunk->Requirements & P2946_i_Requirements) == P2946_i_Requirements) {
                                if (L1863_LargestMemoryChunkSize < L1864_ps_MemoryChunk->TotalByteCount) {
                                        L1865_ps_SelectedMemoryChunk = L1864_ps_MemoryChunk;
                                        L1863_LargestMemoryChunkSize = L1865_ps_SelectedMemoryChunk->TotalByteCount;
                                }
                        }
                }
        } while ((L1864_ps_MemoryChunk = L1864_ps_MemoryChunk->Next) != NULL);
        if (L1865_ps_SelectedMemoryChunk != NULL) {
                L1865_ps_SelectedMemoryChunk->InUse = C1_TRUE;
        }
        return L1865_ps_SelectedMemoryChunk;
}
#endif

#ifdef MEDIA728_I34E_I34M_A36M_A35E_A35M
MEMORY_CHUNK* F0602_GetMinimumOverheadMemoryChunk(
REGISTER long    P2018_l_ByteCount    SEPARATOR
REGISTER int16_t P2019_i_Requirements FINAL_SEPARATOR /* Returns a pointer to the smallest memory chunk with appropriate requirements and large enough for the required byte count. Always returns NULL in PC version */
{
        REGISTER MEMORY_CHUNK* L1866_ps_MemoryChunk;
        REGISTER long L1867_l_OverheadByteCount;
        REGISTER MEMORY_CHUNK* L1868_ps_MinimumOverheadMemoryChunk;
        REGISTER long L1869_l_MinimumOverheadByteCount;


        L1868_ps_MinimumOverheadMemoryChunk = NULL;
        L1869_l_MinimumOverheadByteCount = 0x7FFFFFFF;
        if ((L1866_ps_MemoryChunk = G2137_ps_FirstMemoryChunk) != NULL) { /* G2137_ps_FirstMemoryChunk is always NULL in PC version */
                do {
#ifdef MEDIA758_A36M_A35E_A35M
                        if (L1866_ps_MemoryChunk->InUse == C0_FALSE) {
#endif
                                if ((L1866_ps_MemoryChunk->Requirements & P2019_i_Requirements) == P2019_i_Requirements) {
                                        if ((L1867_l_OverheadByteCount = L1866_ps_MemoryChunk->AvailableByteCount - P2018_l_ByteCount) >= 0) {
                                                if (L1867_l_OverheadByteCount < L1869_l_MinimumOverheadByteCount) {
                                                        L1869_l_MinimumOverheadByteCount = L1867_l_OverheadByteCount;
                                                        L1868_ps_MinimumOverheadMemoryChunk = L1866_ps_MemoryChunk;
                                                }
                                        }
                                }
#ifdef MEDIA758_A36M_A35E_A35M
                        }
#endif
                } while ((L1866_ps_MemoryChunk = L1866_ps_MemoryChunk->Next) != NULL);
        }
        return L1868_ps_MinimumOverheadMemoryChunk;
}

unsigned char HUGE* F0603_AllocateFromTopMemoryChunk(
REGISTER MEMORY_CHUNK* P2020_ps_MemoryChunk SEPARATOR
REGISTER long          P2021_l_ByteCount    FINAL_SEPARATOR
{
        P2020_ps_MemoryChunk->AvailableByteCount -= P2021_l_ByteCount;
        return P2020_ps_MemoryChunk->Top = P2020_ps_MemoryChunk->Top - P2021_l_ByteCount;
}

void F0604_BackupCurrentMemoryChunkInfo(
) /* No effect on PC version */
{
        REGISTER MEMORY_CHUNK* L1870_ps_MemoryChunk;


        if ((L1870_ps_MemoryChunk = G2137_ps_FirstMemoryChunk) != NULL) { /* G2137_ps_FirstMemoryChunk is always NULL in PC version */
                do {
#ifdef MEDIA758_A36M_A35E_A35M
                        if (L1870_ps_MemoryChunk->InUse == C0_FALSE) {
#endif
                                L1870_ps_MemoryChunk->BackupTop = L1870_ps_MemoryChunk->Top;
                                L1870_ps_MemoryChunk->BackupAvailableByteCount = L1870_ps_MemoryChunk->AvailableByteCount;
#ifdef MEDIA758_A36M_A35E_A35M
                        }
#endif
                } while ((L1870_ps_MemoryChunk = L1870_ps_MemoryChunk->Next) != NULL);
        }
}

void F0605_RestoreMemoryChunkInfo(
) /* No effect on PC version */
{
        REGISTER MEMORY_CHUNK* L1871_ps_MemoryChunk;


        if ((L1871_ps_MemoryChunk = G2137_ps_FirstMemoryChunk) != NULL) { /* G2137_ps_FirstMemoryChunk is always NULL in PC version */
                do {
#ifdef MEDIA758_A36M_A35E_A35M
                        if (L1871_ps_MemoryChunk->InUse == C0_FALSE) {
#endif
                                L1871_ps_MemoryChunk->Top = L1871_ps_MemoryChunk->BackupTop;
                                L1871_ps_MemoryChunk->AvailableByteCount = L1871_ps_MemoryChunk->BackupAvailableByteCount;
#ifdef MEDIA758_A36M_A35E_A35M
                        }
#endif
                } while ((L1871_ps_MemoryChunk = L1871_ps_MemoryChunk->Next) != NULL);
        }
}
#endif

unsigned char* F0468_MEMORY_Allocate(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0876_l_ByteCount, P0877_ui_AllocationType)
#endif
#ifdef MEDIA022_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_A31E_A31M_A33M_F31E_F31J_X31J_P31J
REGISTER long    P0876_l_ByteCount      SEPARATOR
unsigned int16_t P0877_ui_AllocationType FINAL_SEPARATOR
#endif
#ifdef MEDIA728_I34E_I34M_A36M_A35E_A35M
register long    P0876_l_ByteCount      SEPARATOR
unsigned int16_t P0877_ui_AllocationType SEPARATOR
int16_t          P2022_i_Requirements   FINAL_SEPARATOR /* PC: P2022_i_Requirements is either MASK0x0008_MEMREQ or MASK0x0400_MEMREQ in all calls */
#endif
{
        REGISTER unsigned char HUGE* L1481_puc_Buffer;
#ifdef MEDIA728_I34E_I34M_A36M_A35E_A35M
        REGISTER MEMORY_CHUNK* L1872_ps_MemoryChunk;
#endif
#ifdef MEDIA508_F20E_F20J_X30J_P20JA_P20JB
        REGISTER int16_t L2990_B_AllocateBitmap;
#endif


        if (P0876_l_ByteCount & 0x00000001) { /* Make sure size is even */
                P0876_l_ByteCount++;
        }
#ifdef MEDIA178_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_G14ED /* CHANGE7_30_IMPROVEMENT */
        if (P0877_ui_AllocationType && (G0653_l_AvailableGEMMemoryByteCount >= P0876_l_ByteCount)) {
                G0653_l_AvailableGEMMemoryByteCount -= P0876_l_ByteCount;
                L1481_puc_Buffer = G0652_puc_AvailableGEMMemoryBottom;
                G0652_puc_AvailableGEMMemoryBottom += P0876_l_ByteCount;
                return L1481_puc_Buffer;
        }
        if (P0876_l_ByteCount > G0648_l_AvailableHeapMemoryByteCount) {
                F0019_MAIN_DisplayErrorAndStop(C40_ERROR_OUT_OF_MEMORY);
        }
        G0648_l_AvailableHeapMemoryByteCount -= P0876_l_ByteCount;
        return (G0646_puc_AvailableHeapMemoryTop -= P0876_l_ByteCount);
#endif
#ifdef MEDIA508_F20E_F20J_X30J_P20JA_P20JB
        if (L2990_B_AllocateBitmap = M007_GET(P0877_ui_AllocationType, MASK0x8000_ALLOCATE_BITMAP)) {
                M727_CLEAR(P0877_ui_AllocationType, MASK0x8000_ALLOCATE_BITMAP);
                P0876_l_ByteCount += 4;
        }
#endif
#ifdef MEDIA291_S20E_S21E_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* CHANGE7_30_IMPROVEMENT */
#ifdef MEDIA290_S20E_S21E_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_A31E_A31M_A33M_F31E_F31J_X31J_P31J
        if ((P0877_ui_AllocationType == C1_ALLOCATION_PERMANENT) && (G0653_l_AvailableGEMMemoryByteCount >= P0876_l_ByteCount)) { /* G0653_l_AvailableGEMMemoryByteCount is always 0 on Amiga */
                G0653_l_AvailableGEMMemoryByteCount -= P0876_l_ByteCount;
                L1481_puc_Buffer = G0652_puc_AvailableGEMMemoryBottom;
                G0652_puc_AvailableGEMMemoryBottom += P0876_l_ByteCount;
#endif
#ifdef MEDIA728_I34E_I34M_A36M_A35E_A35M
        if ((P0877_ui_AllocationType == C1_ALLOCATION_PERMANENT) && ((L1872_ps_MemoryChunk = F0602_GetMinimumOverheadMemoryChunk(P0876_l_ByteCount, P2022_i_Requirements)) != NULL)) { /* F0602_GetMinimumOverheadMemoryChunk always returns NULL in PC version */
                L1481_puc_Buffer = F0603_AllocateFromTopMemoryChunk(L1872_ps_MemoryChunk, P0876_l_ByteCount); /* Never called because condition is always C0_FALSE in PC version */
#endif
        } else {
#ifdef MEDIA707_I34E_I34M
                if ((P0877_ui_AllocationType == C1_ALLOCATION_PERMANENT) && (P2022_i_Requirements == M007_GET(P2022_i_Requirements, MASK0x07F8_MEMREQ)) && (P0876_l_ByteCount <= G0653_l_AvailableGEMMemoryByteCount)) {
#endif
#ifdef MEDIA758_A36M_A35E_A35M
                if ((P0877_ui_AllocationType == C1_ALLOCATION_PERMANENT) && (P2022_i_Requirements == M007_GET(P2022_i_Requirements, MASK0x0700_MEMREQ)) && (P0876_l_ByteCount <= G0653_l_AvailableGEMMemoryByteCount)) {
#endif
#ifdef MEDIA728_I34E_I34M_A36M_A35E_A35M
                        G0653_l_AvailableGEMMemoryByteCount -= P0876_l_ByteCount;
                        L1481_puc_Buffer = G2182_puc_AvailableEMSMemoryTop = G2182_puc_AvailableEMSMemoryTop - P0876_l_ByteCount;
                } else {
#endif
                        if (P0876_l_ByteCount > G0648_l_AvailableHeapMemoryByteCount) {
                                F0019_MAIN_DisplayErrorAndStop(C40_ERROR_OUT_OF_MEMORY);
                        }
                        if (P0877_ui_AllocationType == C2_ALLOCATION_TEMPORARY_ON_BOTTOM_OF_HEAP) {
                                L1481_puc_Buffer = G0646_puc_AvailableHeapMemoryTop - G0648_l_AvailableHeapMemoryByteCount;
                        } else {
                                L1481_puc_Buffer = G0646_puc_AvailableHeapMemoryTop -= P0876_l_ByteCount;
                        }
                        G0648_l_AvailableHeapMemoryByteCount -= P0876_l_ByteCount;
#ifdef MEDIA728_I34E_I34M_A36M_A35E_A35M
                }
#endif
        }
#ifdef MEDIA508_F20E_F20J_X30J_P20JA_P20JB
        if (L2990_B_AllocateBitmap) {
#ifdef MEDIA458_P20JA_P20JB
                L1481_puc_Buffer = (unsigned char*)((unsigned char HUGE*)L1481_puc_Buffer + 1 - 1) + 4;
#endif
#ifdef MEDIA506_F20E_F20J_X30J
                L1481_puc_Buffer += 4;
#endif
        }
#endif
        return L1481_puc_Buffer;
#endif
}

void F0469_MEMORY_FreeAtHeapTop(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0878_l_ByteCount)
#endif
REGISTER long P0878_l_ByteCount FINAL_SEPARATOR
{
        if (P0878_l_ByteCount & 0x00000001) { /* Make sure size is even */
                P0878_l_ByteCount++;
        }
        G0648_l_AvailableHeapMemoryByteCount += P0878_l_ByteCount;
        G0646_puc_AvailableHeapMemoryTop += P0878_l_ByteCount;
}

#ifdef MEDIA291_S20E_S21E_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* CHANGE7_30_IMPROVEMENT */
void F0470_MEMORY_FreeAtHeapBottom(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0879_l_ByteCount)
#endif
REGISTER long P0879_l_ByteCount FINAL_SEPARATOR
{
        if (P0879_l_ByteCount & 0x00000001) { /* Make sure size is even */
                P0879_l_ByteCount++;
        }
        G0648_l_AvailableHeapMemoryByteCount += P0879_l_ByteCount;
}
#endif

#ifdef MEDIA720_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
unsigned char* F0606_AllocateMemForGraphic(
int16_t P2023_i_Width          SEPARATOR
int16_t P2024_i_Height         SEPARATOR
int16_t P2025_i_AllocationType FINAL_SEPARATOR
{
        REGISTER unsigned char* L2991_puc_Bitmap;


        L2991_puc_Bitmap = M533_F0468_MEMORY_Allocate((long)M103_BITMAP_BYTE_COUNT(P2023_i_Width, P2024_i_Height) + 2 * sizeof(int16_t), P2025_i_AllocationType, MASK0x0008_MEMREQ);
#ifdef MEDIA709_I34E_I34M_P31J
        L2991_puc_Bitmap = (unsigned char*)((unsigned char HUGE*)L2991_puc_Bitmap + 1 - 1) + 4;
#endif
#ifdef MEDIA747_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J
        L2991_puc_Bitmap += 4;
#endif
        M100_PIXEL_WIDTH(L2991_puc_Bitmap) = P2023_i_Width;
        M101_PIXEL_HEIGHT(L2991_puc_Bitmap) = P2024_i_Height;
        return (unsigned char*)L2991_puc_Bitmap;
}

void F0607_FreeMemForGraphic(
unsigned char* P2026_puc_Bitmap FINAL_SEPARATOR
{
        F0469_MEMORY_FreeAtHeapTop((long)M103_BITMAP_BYTE_COUNT(M100_PIXEL_WIDTH(P2026_puc_Bitmap), M101_PIXEL_HEIGHT(P2026_puc_Bitmap)) + 2 * sizeof(int16_t));
}
#endif

STATICFUNCTION void F0471_CACHE_RemoveUnusedBlock(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0880_puc_Block)
#endif
REGISTER unsigned char HUGE* P0880_puc_Block FINAL_SEPARATOR
{
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        REGISTER unsigned char HUGE* L1482_puc_PreviousUnusedBlock;
#endif
        REGISTER unsigned char HUGE* L1483_puc_NextUnusedBlock;
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER unsigned char HUGE* L1482_puc_PreviousUnusedBlock;
#endif


        L1482_puc_PreviousUnusedBlock = M086_UNUSED_BLOCK_PREVIOUS_ADDRESS(P0880_puc_Block);
        L1483_puc_NextUnusedBlock = M087_UNUSED_BLOCK_NEXT_ADDRESS(P0880_puc_Block);
        if (L1482_puc_PreviousUnusedBlock == NULL) {
                if (L1483_puc_NextUnusedBlock == NULL) {
                        G0657_puc_FirstUnusedBlock = NULL;
                } else {
                        G0657_puc_FirstUnusedBlock = L1483_puc_NextUnusedBlock;
                        M086_UNUSED_BLOCK_PREVIOUS_ADDRESS(L1483_puc_NextUnusedBlock) = NULL;
                }
        } else {
                M087_UNUSED_BLOCK_NEXT_ADDRESS(L1482_puc_PreviousUnusedBlock) = L1483_puc_NextUnusedBlock;
                if (L1483_puc_NextUnusedBlock != NULL) {
                        M086_UNUSED_BLOCK_PREVIOUS_ADDRESS(L1483_puc_NextUnusedBlock) = L1482_puc_PreviousUnusedBlock;
                }
        }
}

STATICFUNCTION void F0472_CACHE_AddUnusedBlock(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0881_puc_Block) /* The linked list of unused blocks is sorted from largest to smallest block size */
unsigned char HUGE* P0881_puc_Block FINAL_SEPARATOR
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
REGISTER unsigned char HUGE* P0881_puc_Block FINAL_SEPARATOR
#endif
{
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        REGISTER unsigned char* L1486_puc_FirstUnusedBlock;
#endif
        REGISTER unsigned char HUGE* L1487_puc_UnusedBlock;
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        long L1488_l_Unreferenced; /* BUG0_00 Useless code */
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER unsigned char HUGE* L1486_puc_FirstUnusedBlock;
#endif
        REGISTER long L1484_l_BlockSize;
        REGISTER BOOLEAN L1485_B_BlockAddedToUnusedList;


        L1487_puc_UnusedBlock = P0881_puc_Block;
        if (G0657_puc_FirstUnusedBlock == NULL) { /* Add the block as the only one in the list */
                G0657_puc_FirstUnusedBlock = L1487_puc_UnusedBlock;
                M086_UNUSED_BLOCK_PREVIOUS_ADDRESS(L1487_puc_UnusedBlock) = M087_UNUSED_BLOCK_NEXT_ADDRESS(L1487_puc_UnusedBlock) = NULL;
        } else {
                L1486_puc_FirstUnusedBlock = G0657_puc_FirstUnusedBlock;
                L1484_l_BlockSize = M080_BLOCK_SIZE(L1487_puc_UnusedBlock);
                if (L1484_l_BlockSize >= M080_BLOCK_SIZE(L1486_puc_FirstUnusedBlock)) { /* Add the block as the first in the list */
                        G0657_puc_FirstUnusedBlock = L1487_puc_UnusedBlock;
                        M086_UNUSED_BLOCK_PREVIOUS_ADDRESS(L1487_puc_UnusedBlock) = NULL;
                        M087_UNUSED_BLOCK_NEXT_ADDRESS(L1487_puc_UnusedBlock) = L1486_puc_FirstUnusedBlock;
                        M086_UNUSED_BLOCK_PREVIOUS_ADDRESS(L1486_puc_FirstUnusedBlock) = L1487_puc_UnusedBlock;
                } else {
                        L1485_B_BlockAddedToUnusedList = C0_FALSE;
#ifdef MEDIA007_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E
                        while (L1487_puc_UnusedBlock = M087_UNUSED_BLOCK_NEXT_ADDRESS(L1486_puc_FirstUnusedBlock)) { /* ANOMALY_ST_COMPARISON_WITH_ZERO */
#endif
#ifdef MEDIA365_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                        while ((L1487_puc_UnusedBlock = M087_UNUSED_BLOCK_NEXT_ADDRESS(L1486_puc_FirstUnusedBlock)) != NULL) {
#endif
                                if (L1484_l_BlockSize >= M080_BLOCK_SIZE(L1487_puc_UnusedBlock)) { /* Add the block in the middle of the list */
                                        M087_UNUSED_BLOCK_NEXT_ADDRESS(L1486_puc_FirstUnusedBlock) = M086_UNUSED_BLOCK_PREVIOUS_ADDRESS(L1487_puc_UnusedBlock) = P0881_puc_Block;
                                        M086_UNUSED_BLOCK_PREVIOUS_ADDRESS(P0881_puc_Block) = L1486_puc_FirstUnusedBlock;
                                        M087_UNUSED_BLOCK_NEXT_ADDRESS(P0881_puc_Block) = L1487_puc_UnusedBlock;
                                        L1485_B_BlockAddedToUnusedList = C1_TRUE;
                                        break;
                                }
#ifdef MEDIA365_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* ANOMALY_ST_BRANCH */
                                else {
#endif
                                        L1486_puc_FirstUnusedBlock = L1487_puc_UnusedBlock;
#ifdef MEDIA365_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                                }
#endif
                        }
                        if (!L1485_B_BlockAddedToUnusedList) { /* Add the block as the last in the list */
                                M087_UNUSED_BLOCK_NEXT_ADDRESS(L1486_puc_FirstUnusedBlock) = P0881_puc_Block;
                                M086_UNUSED_BLOCK_PREVIOUS_ADDRESS(P0881_puc_Block) = L1486_puc_FirstUnusedBlock;
                                M087_UNUSED_BLOCK_NEXT_ADDRESS(P0881_puc_Block) = NULL;
                        }
                }
        }
}

STATICFUNCTION void F0473_MEMORY_SortValues( /* Sorts the values in the specified array from smallest to largest */
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0882_pui_Values, P0883_ValueCount)
#endif
#ifdef MEDIA084_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_I34E_I34M_A36M_A35E_A35M
REGISTER unsigned int16_t* P0882_pui_Values    SEPARATOR
#endif
#ifdef MEDIA510_F20E_F20J_X30J_P20JA_P20JB_A31E_A31M_A33M_F31E_F31J_X31J_P31J
REGISTER int16_t*          P0882_pui_Values    SEPARATOR
#endif
#ifdef MEDIA066_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_X30J_P20JA_P20JB_A31E_A31M_A33M_X31J_P31J
unsigned int16_t           P0883_ValueCount FINAL_SEPARATOR
#endif
#ifdef MEDIA551_F20E_F20J_F31E_F31J
int16_t                    P0883_ValueCount FINAL_SEPARATOR
#endif
#ifdef MEDIA728_I34E_I34M_A36M_A35E_A35M
unsigned int16_t           P0883_ValueCount SEPARATOR
int16_t                    P2027_i_            FINAL_SEPARATOR
#endif
{
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER unsigned int16_t L1491_ui_Index;
#endif
        REGISTER unsigned int16_t L1489_ui_Index;
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER unsigned int16_t L1492_ui_Value;
        REGISTER unsigned int16_t L1495_ui_Counter;
#endif
        REGISTER unsigned int16_t L1490_ui_Counter;
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        REGISTER unsigned int16_t L1491_ui_Index;
        REGISTER unsigned int16_t L1492_ui_Value;
#endif
        int16_t L1493_i_Counter;
        int16_t L1494_i_IterationCount;
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        unsigned int16_t L1495_ui_Counter;
#endif
        unsigned int16_t L1496_ui_IterationCount;


        L1494_i_IterationCount = 0;
        L1493_i_Counter = P0883_ValueCount;
        while (L1493_i_Counter >>= 1) {
                L1494_i_IterationCount++;
        }
        for (L1493_i_Counter = L1494_i_IterationCount - 1; L1493_i_Counter >= 0; L1493_i_Counter--) {
                L1496_ui_IterationCount = (L1495_ui_Counter = (1 << L1493_i_Counter) - 1) << 1;
                for (L1490_ui_Counter = L1495_ui_Counter; L1490_ui_Counter <= L1496_ui_IterationCount; L1490_ui_Counter++) {
                        L1492_ui_Value = P0882_pui_Values[L1489_ui_Index = L1490_ui_Counter];
                        for (;;) { /*_Infinite loop_*/
                                if ((L1491_ui_Index = (L1489_ui_Index << 1) + 1) >= P0883_ValueCount)
                                        break;
#ifdef MEDIA022_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_A31E_A31M_A33M_F31E_F31J_X31J_P31J
                                if (((L1491_ui_Index + 1) < P0883_ValueCount) && (P0882_pui_Values[L1491_ui_Index + 1] >= P0882_pui_Values[L1491_ui_Index])) {
#endif
#ifdef MEDIA728_I34E_I34M_A36M_A35E_A35M
                                if (((L1491_ui_Index + 1) < P0883_ValueCount) && ((P0882_pui_Values[L1491_ui_Index + 1] & P2027_i_) >= (P0882_pui_Values[L1491_ui_Index] & P2027_i_))) {
#endif
                                        L1491_ui_Index++;
                                }
#ifdef MEDIA022_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_A31E_A31M_A33M_F31E_F31J_X31J_P31J
                                if (L1492_ui_Value < P0882_pui_Values[L1491_ui_Index]) {
#endif
#ifdef MEDIA728_I34E_I34M_A36M_A35E_A35M
                                if ((L1492_ui_Value & P2027_i_) < (P0882_pui_Values[L1491_ui_Index] & P2027_i_)) {
#endif
                                        P0882_pui_Values[L1489_ui_Index] = P0882_pui_Values[L1491_ui_Index];
                                        L1489_ui_Index = L1491_ui_Index;
                                } else {
                                        break;
                                }
                        }
                        P0882_pui_Values[L1489_ui_Index] = L1492_ui_Value;
                }
        }
#ifdef MEDIA034_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        for (L1495_ui_Counter = P0883_ValueCount - 1; L1495_ui_Counter >= 1; L1495_ui_Counter--) {
#endif
#ifdef MEDIA744_A36M
        for (L1495_ui_Counter = -1 + P0883_ValueCount; L1495_ui_Counter >= 1; L1495_ui_Counter--) {
#endif
                L1492_ui_Value = P0882_pui_Values[L1495_ui_Counter];
                P0882_pui_Values[L1495_ui_Counter] = P0882_pui_Values[L1489_ui_Index = 0];
                for (;;) { /*_Infinite loop_*/
                        if ((L1491_ui_Index = (L1489_ui_Index << 1) + 1) > (L1495_ui_Counter - 1))
                                break;
#ifdef MEDIA022_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_A31E_A31M_A33M_F31E_F31J_X31J_P31J
                        if (((L1491_ui_Index + 1) < L1495_ui_Counter) && (P0882_pui_Values[L1491_ui_Index + 1] >= P0882_pui_Values[L1491_ui_Index])) {
#endif
#ifdef MEDIA728_I34E_I34M_A36M_A35E_A35M
                        if (((L1491_ui_Index + 1) < L1495_ui_Counter) && ((P0882_pui_Values[L1491_ui_Index + 1] & P2027_i_) >= (P0882_pui_Values[L1491_ui_Index] & P2027_i_))) {
#endif
                                L1491_ui_Index++;
                        }
#ifdef MEDIA022_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_A31E_A31M_A33M_F31E_F31J_X31J_P31J
                        if (L1492_ui_Value < P0882_pui_Values[L1491_ui_Index]) {
#endif
#ifdef MEDIA728_I34E_I34M_A36M_A35E_A35M
                        if ((L1492_ui_Value & P2027_i_) < (P0882_pui_Values[L1491_ui_Index] & P2027_i_)) {
#endif
                                P0882_pui_Values[L1489_ui_Index] = P0882_pui_Values[L1491_ui_Index];
                                L1489_ui_Index = L1491_ui_Index;
                        } else {
                                break;
                        }
                }
                P0882_pui_Values[L1489_ui_Index] = L1492_ui_Value;
        }
}

#ifdef MEDIA736_I34M_A36M_A31M_A33M_A35M
int16_t F0608_GetLanguageSpecificGraphicIndex(
register int16_t P2028_i_GraphicIndex FINAL_SEPARATOR
{
        register int16_t L2992_i_;
#ifdef MEDIA742_A35M
        register int16_t L2993_i_;
#endif
#ifdef MEDIA734_I34M_A36M
        int16_t L2993_i_;
#endif


#ifdef MEDIA738_I34M_A36M_A35M
        L2993_i_ = P2028_i_GraphicIndex & (MASK0x8000_NOT_EXPANDED | MASK0x4000_DO_NOT_COPY_DIMENSIONS | MASK0x2000_LOAD_IN_BASE_MEMORY);
#endif
#ifdef MEDIA733_I34M
        M009_CLEAR((unsigned int16_t)P2028_i_GraphicIndex, MASK0x8000_NOT_EXPANDED | MASK0x4000_DO_NOT_COPY_DIMENSIONS | MASK0x2000_LOAD_IN_BASE_MEMORY);
#endif
#ifdef MEDIA760_A36M_A35M
        M009_CLEAR(P2028_i_GraphicIndex, MASK0x8000_NOT_EXPANDED | MASK0x4000_DO_NOT_COPY_DIMENSIONS | MASK0x2000_LOAD_IN_BASE_MEMORY);
#endif
        for (L2992_i_ = 0; L2992_i_ < C10_UNKNOWN; L2992_i_++) {
                if (P2028_i_GraphicIndex == G2004_LocalizedGraphicIndices[L2992_i_][C0_UNKNOWN]) {
#ifdef MEDIA655_A31M
                        P2028_i_GraphicIndex = G2004_LocalizedGraphicIndices[L2992_i_][G2000_Language];
                        break;
#endif
#ifdef MEDIA737_I34M_A36M_A33M_A35M
                        return G2004_LocalizedGraphicIndices[L2992_i_][G2000_Language];
#endif
                }
        }
#ifdef MEDIA656_A31M_A33M
        return P2028_i_GraphicIndex;
#endif
#ifdef MEDIA738_I34M_A36M_A35M
        return P2028_i_GraphicIndex | L2993_i_;
#endif
}
#endif

STATICFUNCTION void F0474_MEMORY_LoadGraphic_CPSDF(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0884_i_GraphicIndex, P0885_puc_Graphic)
#endif
int16_t             P0884_i_GraphicIndex SEPARATOR
unsigned char HUGE* P0885_puc_Graphic    FINAL_SEPARATOR
{
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        REGISTER long L1497_l_Offset;
        REGISTER long L1498_l_ReadFromOffset;
#endif
        REGISTER int16_t L1499_i_RemainingByteCount;
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        REGISTER int16_t L1500_i_StartOffsetInBuffer;
        int16_t L1501_i_GraphicsDatChunkIndex;
        int16_t L1502_i_BufferByteCount;
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER long L1498_l_ReadFromOffset;
        REGISTER long L1497_l_Offset;
        REGISTER int16_t L1501_i_GraphicsDatChunkIndex;
        int16_t L1500_i_StartOffsetInBuffer;
        REGISTER int16_t L1502_i_BufferByteCount;
#endif
        long L1503_l_FreadByteCount;


#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
        while (G0625_i_FloppyDriveDMATimeout_CPSDF);
#endif
#endif
#ifdef MEDIA505_F20E_F20J_P20JB_I34E_I34M_F31E_F31J_P31J
        F0739_MUSIC_Stop();
#endif
#ifdef MEDIA736_I34M_A36M_A31M_A33M_A35M
        P0884_i_GraphicIndex = M736_F0608_GetLanguageSpecificGraphicIndex(P0884_i_GraphicIndex);
#endif
        L1497_l_Offset = F0467_MEMORY_GetGraphicOffset(P0884_i_GraphicIndex);
        L1499_i_RemainingByteCount = G0634_pui_GraphicCompressedByteCount[P0884_i_GraphicIndex];
#ifdef MEDIA048_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_A31E_A31M_A33M_F31E_F31J_X31J_P31J
        L1501_i_GraphicsDatChunkIndex = L1497_l_Offset >> 10;
#endif
#ifdef MEDIA484_P20JB_I34E_I34M_A36M
        L1501_i_GraphicsDatChunkIndex = L1497_l_Offset / 1024;
#endif
#ifdef MEDIA741_A35E_A35M
        L1501_i_GraphicsDatChunkIndex = L1497_l_Offset / 4520;
#endif
#ifdef MEDIA039_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_F31E_F31J_X31J_P31J
        L1498_l_ReadFromOffset = (long)L1501_i_GraphicsDatChunkIndex << 10;
#endif
#ifdef MEDIA741_A35E_A35M
        L1498_l_ReadFromOffset = (long)L1501_i_GraphicsDatChunkIndex * 4520;
#endif
        while (L1499_i_RemainingByteCount > 0) {
                if ((L1501_i_GraphicsDatChunkIndex != G0640_i_FloppyDiskReadBufferGraphicsDatChunkIndex) || G0644_i_FloppyDiskReadBufferContentType_CPSDF) {
                        G0640_i_FloppyDiskReadBufferGraphicsDatChunkIndex = L1501_i_GraphicsDatChunkIndex;
#ifdef MEDIA091_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_F31E_F31J_X31J_P31J
                        if ((L1503_l_FreadByteCount = G0633_l_GraphicsDatFileSize - L1498_l_ReadFromOffset) > 1024) {
                                L1503_l_FreadByteCount = 1024;
                        }
#endif
#ifdef MEDIA626_A31E_A31M_A33M_A35E_A35M
                        if ((L1503_l_FreadByteCount = G0633_l_GraphicsDatFileSize - L1498_l_ReadFromOffset) > 4520) {
                                L1503_l_FreadByteCount = 4520;
                        }
#endif
#ifdef MEDIA433_A20E_A20F_A20G_A21E_A22E_A22G
                        if ((L1503_l_FreadByteCount = G0633_l_GraphicsDatFileSize - L1498_l_ReadFromOffset) > 2052) {
                                L1503_l_FreadByteCount = 2052;
                        }
#endif
#ifdef MEDIA007_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E
                        Fseek(L1498_l_ReadFromOffset, G0630_i_GraphicsDatFileHandle, C0_SEEK_FROM_BEGINNING_OF_FILE) >= 0; /* Result of fseek is ignored */
                        Fread(G0630_i_GraphicsDatFileHandle, (long)L1503_l_FreadByteCount, G0643_puc_FloppyDiskReadBuffer_CPSDF) == (long)L1503_l_FreadByteCount; /* Result of fread is ignored */
#endif
#ifdef MEDIA351_G14ED_G20E_G21E
                        F0774_FILE_Seek(G0630_i_GraphicsDatFileHandle, L1498_l_ReadFromOffset);
                        F0772_FILE_Read(G0630_i_GraphicsDatFileHandle, L1503_l_FreadByteCount, G0643_puc_FloppyDiskReadBuffer_CPSDF);
#endif
#ifdef MEDIA413_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
                        Seek(G1134_ps_GraphicsDatFileHandle, L1498_l_ReadFromOffset, OFFSET_BEGINNING) >= 0; /* Result of fseek is ignored */
                        Read(G1134_ps_GraphicsDatFileHandle, G0643_puc_FloppyDiskReadBuffer_CPSDF, (long)L1503_l_FreadByteCount) == (long)L1503_l_FreadByteCount; /* Result of fread is ignored */
#endif
#ifdef MEDIA525_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_F31E_F31J_X31J_P31J
                        if (!(F0774_FILE_Seek(G0630_i_GraphicsDatFileHandle, L1498_l_ReadFromOffset) && F0772_FILE_Read(G0630_i_GraphicsDatFileHandle, L1503_l_FreadByteCount, G0643_puc_FloppyDiskReadBuffer_CPSDF))) {
                                F0019_MAIN_DisplayErrorAndStop(C46_ERROR_UNABLE_TO_READ_GRAPHIC_DATA);
                        }
#endif
#ifdef MEDIA746_A36M_A31E_A31M_A33M_A35E_A35M
                        if (!(F0774_FILE_Seek(G1134_ps_GraphicsDatFileHandle, L1498_l_ReadFromOffset) && F0772_FILE_Read(G1134_ps_GraphicsDatFileHandle, L1503_l_FreadByteCount, G0643_puc_FloppyDiskReadBuffer_CPSDF))) {
                                F0019_MAIN_DisplayErrorAndStop(C46_ERROR_UNABLE_TO_READ_GRAPHIC_DATA);
                        }
#endif
                        G0644_i_FloppyDiskReadBufferContentType_CPSDF = MASK0x0000_BUFFER_CONTAINS_GRAPHIC_DATA;
                }
                L1500_i_StartOffsetInBuffer = L1497_l_Offset - L1498_l_ReadFromOffset;
#ifdef MEDIA091_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_F31E_F31J_X31J_P31J
                L1502_i_BufferByteCount = F0024_MAIN_GetMinimumValue(L1499_i_RemainingByteCount, 1024 - L1500_i_StartOffsetInBuffer);
#endif
#ifdef MEDIA433_A20E_A20F_A20G_A21E_A22E_A22G
                L1502_i_BufferByteCount = F0024_MAIN_GetMinimumValue(L1499_i_RemainingByteCount, 2052 - L1500_i_StartOffsetInBuffer);
#endif
#ifdef MEDIA626_A31E_A31M_A33M_A35E_A35M
                L1502_i_BufferByteCount = F0024_MAIN_GetMinimumValue(L1499_i_RemainingByteCount, 4520 - L1500_i_StartOffsetInBuffer);
#endif
                F0007_MAIN_CopyBytes(M772_CAST_PC(G0643_puc_FloppyDiskReadBuffer_CPSDF + L1500_i_StartOffsetInBuffer), M772_CAST_PC(P0885_puc_Graphic), M543_BYTE_COUNT_INT(L1502_i_BufferByteCount));
                L1499_i_RemainingByteCount -= L1502_i_BufferByteCount;
                L1497_l_Offset += L1502_i_BufferByteCount;
                P0885_puc_Graphic += L1502_i_BufferByteCount;
                L1501_i_GraphicsDatChunkIndex++;
#ifdef MEDIA091_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_F31E_F31J_X31J_P31J
                L1498_l_ReadFromOffset += 1024;
#endif
#ifdef MEDIA433_A20E_A20F_A20G_A21E_A22E_A22G
                L1498_l_ReadFromOffset += 2052;
#endif
#ifdef MEDIA626_A31E_A31M_A33M_A35E_A35M
                L1498_l_ReadFromOffset += 4520;
#endif
        }
}

#ifdef MEDIA033_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A31E_A31M_A33M_F31E_F31J_X31J_P31J
void F0475_MEMORY_Initialize(
#endif
#ifdef MEDIA758_A36M_A35E_A35M
BOOLEAN F0475_MEMORY_Initialize(
#endif
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0886_puc_HeapMemoryBottom, P0887_l_AvailableHeapMemoryByteCount, P0888_puc_AvailableGEMMemoryBottom, P0889_l_AvailableGEMMemoryByteCount)
#endif
#ifdef MEDIA034_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
REGISTER unsigned char HUGE* P0886_puc_HeapMemoryBottom           SEPARATOR
REGISTER long                P0887_l_AvailableHeapMemoryByteCount SEPARATOR
#endif
#ifdef MEDIA744_A36M
unsigned char HUGE*          P0886_puc_HeapMemoryBottom           SEPARATOR
unsigned long                P0887_l_AvailableHeapMemoryByteCount SEPARATOR
#endif
#ifdef MEDIA033_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A31E_A31M_A33M_F31E_F31J_X31J_P31J
unsigned char HUGE*          P0888_puc_AvailableGEMMemoryBottom   SEPARATOR
#endif
#ifdef MEDIA022_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_A31E_A31M_A33M_F31E_F31J_X31J_P31J
long                         P0889_l_AvailableGEMMemoryByteCount  FINAL_SEPARATOR
#endif
#ifdef MEDIA707_I34E_I34M
long                         P0889_l_AvailableGEMMemoryByteCount  SEPARATOR
MEMORY_CHUNK*                P2029_ps_MemoryChunk                 FINAL_SEPARATOR
#endif
#ifdef MEDIA741_A35E_A35M
REGISTER int16_t             P2753_i_Requirements                 FINAL_SEPARATOR
#endif
#ifdef MEDIA744_A36M
int16_t                      P2753_i_Requirements                 FINAL_SEPARATOR
#endif
{
#ifdef MEDIA758_A36M_A35E_A35M
        REGISTER MEMORY_CHUNK* L1873_ps_MemoryChunk;
#endif


#ifdef MEDIA033_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A31E_A31M_A33M_F31E_F31J_X31J_P31J
        G0641_puc_CacheMemoryBottom = G0651_puc_CacheMemoryTop = P0886_puc_HeapMemoryBottom;
        G0646_puc_AvailableHeapMemoryTop = G0645_puc_HeapMemoryTop = P0886_puc_HeapMemoryBottom + P0887_l_AvailableHeapMemoryByteCount;
        G0648_l_AvailableHeapMemoryByteCount = P0887_l_AvailableHeapMemoryByteCount;
#endif
#ifdef MEDIA022_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_A31E_A31M_A33M_F31E_F31J_X31J_P31J
        G0652_puc_AvailableGEMMemoryBottom = P0888_puc_AvailableGEMMemoryBottom;
#endif
#ifdef MEDIA707_I34E_I34M
        G2182_puc_AvailableEMSMemoryTop = P0888_puc_AvailableGEMMemoryBottom + P0889_l_AvailableGEMMemoryByteCount;
#endif
#ifdef MEDIA033_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A31E_A31M_A33M_F31E_F31J_X31J_P31J
        G0653_l_AvailableGEMMemoryByteCount = P0889_l_AvailableGEMMemoryByteCount;
#endif
#ifdef MEDIA707_I34E_I34M
        G2137_ps_FirstMemoryChunk = P2029_ps_MemoryChunk;
#endif
#ifdef MEDIA758_A36M_A35E_A35M
        if (G3074_B_MemoryInitializationComplete) {
                F0019_MAIN_DisplayErrorAndStop(C48_ERROR_MEMORY_ALREADY_INITIALIZED);
        }
        if (P0886_puc_HeapMemoryBottom != NULL) {
                P0887_l_AvailableHeapMemoryByteCount &= 0xFFFFFFFE;
                if (P0887_l_AvailableHeapMemoryByteCount < 44) {
                        return C0_FALSE;
                }
                F1007_AddMemoryChunk((MEMORY_CHUNK*)P0886_puc_HeapMemoryBottom, P0887_l_AvailableHeapMemoryByteCount, P2753_i_Requirements);
        } else {
                G3074_B_MemoryInitializationComplete = C1_TRUE;
                if (!(L1873_ps_MemoryChunk = F1008_GetLargestAvailableMemoryChunk(MASK0x07F8_MEMREQ))) {
                        F0019_MAIN_DisplayErrorAndStop(C49_ERROR_);
                }
                G0641_puc_CacheMemoryBottom = G0651_puc_CacheMemoryTop = (unsigned char*)L1873_ps_MemoryChunk + sizeof(MEMORY_CHUNK);
                G0646_puc_AvailableHeapMemoryTop = G0645_puc_HeapMemoryTop = (unsigned char*)L1873_ps_MemoryChunk + L1873_ps_MemoryChunk->TotalByteCount + sizeof(MEMORY_CHUNK);
                G0648_l_AvailableHeapMemoryByteCount = L1873_ps_MemoryChunk->TotalByteCount;
                if ((L1873_ps_MemoryChunk = F1008_GetLargestAvailableMemoryChunk(MASK0x0700_MEMREQ)) != NULL) {
                        G2182_puc_AvailableEMSMemoryTop = (unsigned char*)L1873_ps_MemoryChunk + L1873_ps_MemoryChunk->TotalByteCount + sizeof(MEMORY_CHUNK);
                        G0653_l_AvailableGEMMemoryByteCount = L1873_ps_MemoryChunk->TotalByteCount;
                }
#endif
#ifdef MEDIA090_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_F31E_F31J_X31J_P31J
                G0643_puc_FloppyDiskReadBuffer_CPSDF = (unsigned char*)M533_F0468_MEMORY_Allocate(1024L, C1_ALLOCATION_PERMANENT, MASK0x0400_MEMREQ);
#endif
#ifdef MEDIA626_A31E_A31M_A33M_A35E_A35M
                G0643_puc_FloppyDiskReadBuffer_CPSDF = (unsigned char*)M533_F0468_MEMORY_Allocate(4520L, C1_ALLOCATION_PERMANENT, MASK0x0280_MEMREQ);
#endif
#ifdef MEDIA744_A36M
                G0643_puc_FloppyDiskReadBuffer_CPSDF = (unsigned char*)M533_F0468_MEMORY_Allocate(1024L, C1_ALLOCATION_PERMANENT, MASK0x0280_MEMREQ);
#endif
#ifdef MEDIA433_A20E_A20F_A20G_A21E_A22E_A22G
                G0643_puc_FloppyDiskReadBuffer_CPSDF = (unsigned char*)F0468_MEMORY_Allocate(2052L, C1_ALLOCATION_PERMANENT); /* Can contain two MFM encoded sectors of 1026 bytes each */
#endif
                G0655_ppuc_Blocks = (unsigned char HUGE**)M533_F0468_MEMORY_Allocate((long)(M514_GRAPHIC_COUNT + M515_DERIVED_BITMAP_ACTUAL_COUNT) * sizeof(unsigned char*), C1_ALLOCATION_PERMANENT, MASK0x0400_MEMREQ);
                F0008_MAIN_ClearBytes(M772_CAST_PC(G0655_ppuc_Blocks), M543_BYTE_COUNT_INT((M514_GRAPHIC_COUNT + M515_DERIVED_BITMAP_ACTUAL_COUNT)) * sizeof(unsigned char*));
                G0638_pui_DerivedBitmapBlockIndices = (unsigned int16_t*)M533_F0468_MEMORY_Allocate((long)(M535_DERIVED_BITMAP_ACTUAL_COUNT_ALT * sizeof(unsigned int16_t)), C1_ALLOCATION_PERMANENT, MASK0x0400_MEMREQ);
                F0010_MAIN_WriteSpacedWords(M773_CAST_PI(G0638_pui_DerivedBitmapBlockIndices), M535_DERIVED_BITMAP_ACTUAL_COUNT_ALT, 0xFFFF, (int16_t)sizeof(int16_t));
#ifdef MEDIA040_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_P31J
                G0639_DerivedBitmapByteCount = (unsigned int16_t*)M533_F0468_MEMORY_Allocate((long)(M535_DERIVED_BITMAP_ACTUAL_COUNT_ALT * sizeof(unsigned int16_t)), C1_ALLOCATION_PERMANENT, MASK0x0400_MEMREQ);
#endif
#ifdef MEDIA692_X31J
                G0639_DerivedBitmapByteCount = (unsigned long*)M533_F0468_MEMORY_Allocate((long)(M535_DERIVED_BITMAP_ACTUAL_COUNT_ALT * sizeof(unsigned long)), C1_ALLOCATION_PERMANENT, MASK0x0400_MEMREQ);
#endif
                G0658_puc_FirstUsedBlock = G0659_puc_LastUsedBlock = G0660_puc_FirstReferencedUsedBlock = G0657_puc_FirstUnusedBlock = NULL;
                G0662_l_LastResetCacheUsageCountsTime = -1;
#ifdef MEDIA758_A36M_A35E_A35M
        }
        return C1_TRUE;
#endif
}

#ifdef MEDIA089_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A35E_A35M_F31E_F31J_X31J_P31J
void F0476_MEMORY_InitializeGraphicMemory(
#endif
#ifdef MEDIA452_A21E_A22E_A31E_A31M_A33M
BOOLEAN F0476_MEMORY_InitializeGraphicMemory(
#endif
#ifdef MEDIA008_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E
)
#endif
#ifdef MEDIA427_A20ED_A20E_A20F_A20G_A22G
P0932_puc_)
unsigned char* P0932_puc_ FINAL_SEPARATOR
#endif
#ifdef MEDIA448_A21E_A22E
P0930_i_, P0931_i_, P0932_puc_, P0933_l_MemorySize)
int16_t        P0930_i_           SEPARATOR
int16_t        P0931_i_           SEPARATOR
unsigned char* P0932_puc_         SEPARATOR
long           P0933_l_MemorySize FINAL_SEPARATOR
#endif
#ifdef MEDIA507_F20E_F20J_X30J_P20JA
int16_t P0930_i_ SEPARATOR
int16_t P0931_i_ FINAL_SEPARATOR
#endif
#ifdef MEDIA475_P20JB_F31E_F31J_X31J
long P2745_l_ FINAL_SEPARATOR
#endif
#ifdef MEDIA729_I34E_I34M_A36M_A35E_A35M_P31J
unsigned char* P2030_puc_ FINAL_SEPARATOR
#endif
#ifdef MEDIA620_A31E_A31M_A33M
long           P2745_l_   SEPARATOR
long           P2750_l_   SEPARATOR
unsigned char* P2751_puc_ SEPARATOR
long           P2752_l_   FINAL_SEPARATOR
#endif
{
#ifdef MEDIA088_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A22G
#ifdef MEDIA388_G20E_G21E
        char L6192_ac_Unreferenced[128];
#endif
#ifdef MEDIA427_A20ED_A20E_A20F_A20G_A22G
        if (P0932_puc_) {
                if (G0661_B_LargeHeapMemory = ((long)G0646_puc_AvailableHeapMemoryTop - (long)G0641_puc_CacheMemoryBottom) > 70000) {
                        F0461_START_AllocateFlippedWallBitmaps();
                }
                G0642_puc_GraphicMemoryBottom = G0646_puc_AvailableHeapMemoryTop - 10000;
                G0654_B_GraphicMemoryInitialized = C0_FALSE;
                G0649_puc_GraphicMemoryTop = G0650_puc_GraphicMemoryBottomTemp = P0932_puc_;
        } else {
#endif
                if (G0661_B_LargeHeapMemory = ((long)G0646_puc_AvailableHeapMemoryTop - (long)G0641_puc_CacheMemoryBottom) > 370000) {
                        F0461_START_AllocateFlippedWallBitmaps();
                }
                G0642_puc_GraphicMemoryBottom = G0646_puc_AvailableHeapMemoryTop - 10000;
                G0654_B_GraphicMemoryInitialized = C1_TRUE;
                G0649_puc_GraphicMemoryTop = G0650_puc_GraphicMemoryBottomTemp = G0642_puc_GraphicMemoryBottom;
#ifdef MEDIA427_A20ED_A20E_A20F_A20G_A22G
        }
#endif
        G0648_l_AvailableHeapMemoryByteCount = 10000;
        G0656_l_AvailableCacheMemoryByteCount = (long)G0642_puc_GraphicMemoryBottom - (long)G0641_puc_CacheMemoryBottom;
#endif
#ifdef MEDIA448_A21E_A22E
        REGISTER int16_t L1664_i_;
        REGISTER long L1665_l_;
        REGISTER long L1666_l_;


        L1665_l_ = 0;
        for (L1664_i_ = P0930_i_; L1664_i_ <= P0931_i_; L1665_l_ += G0635_pui_GraphicDecompressedByteCount[L1664_i_++] + 3);
        L1666_l_ = (long)G0646_puc_AvailableHeapMemoryTop - (long)G0641_puc_CacheMemoryBottom;
        L1664_i_ = 0;
        if (!P0932_puc_)
                goto T0476001;
        G0661_B_LargeHeapMemory = ((L1666_l_ + P0933_l_MemorySize) > (L1665_l_ + 104576));
        if (G0661_B_LargeHeapMemory) {
                F0461_START_AllocateFlippedWallBitmaps();
                goto T0476000;
        }
        if (P0933_l_MemorySize >= L1665_l_) {
                T0476000:
                L1664_i_ = 1;
                G0642_puc_GraphicMemoryBottom = G0646_puc_AvailableHeapMemoryTop - 10000;
                G0654_B_GraphicMemoryInitialized = C0_FALSE;
                G1148_l_MemorySize = P0933_l_MemorySize;
                G0650_puc_GraphicMemoryBottomTemp = P0932_puc_;
                G0649_puc_GraphicMemoryTop = P0932_puc_;
        } else {
                T0476001:
                G0661_B_LargeHeapMemory = (L1666_l_ > (L1665_l_ + 99576));
                if (G0661_B_LargeHeapMemory) {
                        F0461_START_AllocateFlippedWallBitmaps();
                }
                G0642_puc_GraphicMemoryBottom = G0646_puc_AvailableHeapMemoryTop - 10000;
                G0654_B_GraphicMemoryInitialized = C1_TRUE;
                G0650_puc_GraphicMemoryBottomTemp = G0642_puc_GraphicMemoryBottom;
                G0649_puc_GraphicMemoryTop = G0642_puc_GraphicMemoryBottom;
        }
        G0648_l_AvailableHeapMemoryByteCount = 10000;
        G0656_l_AvailableCacheMemoryByteCount = (long)G0642_puc_GraphicMemoryBottom - (long)G0641_puc_CacheMemoryBottom;
        return L1664_i_;
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
#ifdef MEDIA507_F20E_F20J_X30J_P20JA
        REGISTER int16_t L1664_i_;
        REGISTER long L1665_l_;
#endif
#ifdef MEDIA515_F20E_F20J_X30J_P20JA_P20JB_F31E_F31J
        REGISTER long L1666_l_;
#endif
#ifdef MEDIA623_A31E_A31M_A33M_X31J
        REGISTER int16_t L1664_i_;
#endif
#ifdef MEDIA707_I34E_I34M
        long L2994_l_ByteCount;
        unsigned char HUGE* L2995_puc_;
        long L2996_l_;
        unsigned char HUGE* L2997_puc_;
        long L2998_l_;
        unsigned char HUGE* L2999_puc_;
        BOOLEAN L3000_B_ContinueWithNextMemoryProfile;
#endif
#ifdef MEDIA758_A36M_A35E_A35M
        unsigned char HUGE* L2999_puc_;
        unsigned char HUGE* L2995_puc_;
        unsigned char HUGE* L2997_puc_;
        BOOLEAN L3000_B_ContinueWithNextMemoryProfile;
        long L2996_l_;
        long L2998_l_;
        long L2994_l_ByteCount;
#endif


#ifdef MEDIA507_F20E_F20J_X30J_P20JA
        L1665_l_ = 0;
#endif
        G2232_B_GraphicMemoryInitialized = C1_TRUE;
#ifdef MEDIA507_F20E_F20J_X30J_P20JA
        for (L1664_i_ = P0930_i_; L1664_i_ <= P0931_i_; L1665_l_ += G0635_pui_GraphicDecompressedByteCount[L1664_i_++] + 3);
#endif
#ifdef MEDIA515_F20E_F20J_X30J_P20JA_P20JB_F31E_F31J
        L1666_l_ = G0646_puc_AvailableHeapMemoryTop - G0641_puc_CacheMemoryBottom;
#endif
#ifdef MEDIA624_A31E_A31M_A33M_X31J_P31J
        G2231_l_ByteCount = G0646_puc_AvailableHeapMemoryTop - G0641_puc_CacheMemoryBottom;
#endif
#ifdef MEDIA620_A31E_A31M_A33M
        L1664_i_ = C0_FALSE;
        if (P2751_puc_) {
                G0661_B_LargeHeapMemory = ((G2231_l_ByteCount + P2752_l_) > (G2069_LargestCacheableNativeBitmapByteCount + P2745_l_ + P2750_l_ + (long)(34588))) && (G2231_l_ByteCount > G2069_LargestCacheableNativeBitmapByteCount + P2750_l_ + 29588); /* 19588 + 15000 / 19588 + 10000 */
                if (G0661_B_LargeHeapMemory) {
                        F0461_START_AllocateFlippedWallBitmaps();
                } else {
                        if (P2752_l_ < P2745_l_) {
                                goto loc_119D8;
                        }
                }
                L1664_i_ = C1_TRUE;
                G0642_puc_GraphicMemoryBottom = G0646_puc_AvailableHeapMemoryTop - G2069_LargestCacheableNativeBitmapByteCount;
                G0654_B_GraphicMemoryInitialized = C0_FALSE;
                G1148_l_MemorySize = P2752_l_;
                G0649_puc_GraphicMemoryTop = G0650_puc_GraphicMemoryBottomTemp = P2751_puc_;
        } else {
                loc_119D8:
#endif
#ifdef MEDIA667_P31J
                G0661_B_LargeHeapMemory = C0_FALSE;
#endif
#ifdef MEDIA507_F20E_F20J_X30J_P20JA
                G0661_B_LargeHeapMemory = (L1666_l_ > (L1665_l_ + G2069_LargestCacheableNativeBitmapByteCount +
#endif
#ifdef MEDIA473_P20JB_F31E_F31J
                G0661_B_LargeHeapMemory = (L1666_l_ > (G2069_LargestCacheableNativeBitmapByteCount + P2745_l_ +
#endif
#ifdef MEDIA623_A31E_A31M_A33M_X31J
                G0661_B_LargeHeapMemory = (G2231_l_ByteCount > (P2745_l_ + G2069_LargestCacheableNativeBitmapByteCount +
#endif
#ifdef MEDIA458_P20JA_P20JB
                        (long)(M075_BITMAP_BYTE_COUNT(224, 136) + M574_BITMAP_OVERHEAD +  /* Derived bitmap #0 */
                               M075_BITMAP_BYTE_COUNT(64, 111)  + M574_BITMAP_OVERHEAD +  /* Largest possible mask (graphic #71 for teleporters and fluxcages) */
                               M075_BITMAP_BYTE_COUNT(48, 31)   + M574_BITMAP_OVERHEAD)   /* Largest possible pixel source bitmap (graphics #351 to #359 for explosions at D0) */
                        )); /* = 19588 */
#endif
#ifdef MEDIA488_F20E_F20J
                        (long)(89836)
                        ));
#endif
#ifdef MEDIA670_F31E_F31J
                        (long)(29836)
                        ));
#endif
#ifdef MEDIA577_X30J
                        (long)(89588) /* = 19588 + 70000 */
                        ));
#endif
#ifdef MEDIA623_A31E_A31M_A33M_X31J
                        (long)(29588) /* = 19588 + 10000 */
                        ));
#endif
#ifdef MEDIA509_F20E_F20J_X30J_P20JA_P20JB_A31E_A31M_A33M_F31E_F31J_X31J
                if (G0661_B_LargeHeapMemory) {
                        F0461_START_AllocateFlippedWallBitmaps();
                }
#endif
#ifdef MEDIA510_F20E_F20J_X30J_P20JA_P20JB_A31E_A31M_A33M_F31E_F31J_X31J_P31J
                G0642_puc_GraphicMemoryBottom = G0646_puc_AvailableHeapMemoryTop - G2069_LargestCacheableNativeBitmapByteCount;
                G0654_B_GraphicMemoryInitialized = C1_TRUE;
                G0649_puc_GraphicMemoryTop = G0650_puc_GraphicMemoryBottomTemp = G0642_puc_GraphicMemoryBottom;
#endif
#ifdef MEDIA620_A31E_A31M_A33M
        }
#endif
#ifdef MEDIA510_F20E_F20J_X30J_P20JA_P20JB_A31E_A31M_A33M_F31E_F31J_X31J_P31J
        G0648_l_AvailableHeapMemoryByteCount = G2069_LargestCacheableNativeBitmapByteCount;
        G0656_l_AvailableCacheMemoryByteCount = G0642_puc_GraphicMemoryBottom - G0641_puc_CacheMemoryBottom;
#endif
#ifdef MEDIA728_I34E_I34M_A36M_A35E_A35M
        /* Backup original values */
        L2995_puc_ = G2182_puc_AvailableEMSMemoryTop;
        L2996_l_ = G0653_l_AvailableGEMMemoryByteCount;
        L2997_puc_ = G0646_puc_AvailableHeapMemoryTop;
        L2998_l_ = G0648_l_AvailableHeapMemoryByteCount;
        L2999_puc_ = G0641_puc_CacheMemoryBottom;
        F0604_BackupCurrentMemoryChunkInfo();
        do { /* Loop to try to load each sound memory profile from largest to smallest */
                G2182_puc_AvailableEMSMemoryTop = L2995_puc_; /* Restore original values */
                G0653_l_AvailableGEMMemoryByteCount = L2996_l_;
                G0646_puc_AvailableHeapMemoryTop = L2997_puc_;
                G0648_l_AvailableHeapMemoryByteCount = L2998_l_;
                G0641_puc_CacheMemoryBottom = L2999_puc_;
                F0605_RestoreMemoryChunkInfo();
                L3000_B_ContinueWithNextMemoryProfile = F0755_SetMemoryFlags(&P2030_puc_, &L2994_l_ByteCount); /* L2994_l_ByteCount is always set to 0 in DM PC */
                F0461_START_AllocateFlippedWallBitmaps();
#ifdef MEDIA707_I34E_I34M
                G0649_puc_GraphicMemoryTop = G0646_puc_AvailableHeapMemoryTop - G2069_LargestCacheableNativeBitmapByteCount;
                F0609_InitializeMemoryArea(&G2058_GraphicBaseMemoryArea, G0649_puc_GraphicMemoryTop, 0L, MASK0x07F8_MEMREQ);
#endif
#ifdef MEDIA758_A36M_A35E_A35M
                G0642_puc_GraphicMemoryBottom = G0646_puc_AvailableHeapMemoryTop - G2069_LargestCacheableNativeBitmapByteCount;
                F0609_InitializeMemoryArea(&G2058_GraphicBaseMemoryArea, G0642_puc_GraphicMemoryBottom, 0L, MASK0x07F8_MEMREQ);
#endif
                if (G0653_l_AvailableGEMMemoryByteCount < 10000) { /* Do not use EMS memory is there are less than 10000 bytes available */
#ifdef MEDIA707_I34E_I34M
                        F0609_InitializeMemoryArea(&G2057_GraphicEMSMemoryArea, NULL, 0L, MASK0x07F8_MEMREQ);
#endif
#ifdef MEDIA758_A36M_A35E_A35M
                        F0609_InitializeMemoryArea(&G2057_GraphicEMSMemoryArea, NULL, 0L, MASK0x0700_MEMREQ);
#endif
                } else {
#ifdef MEDIA707_I34E_I34M
                        F0609_InitializeMemoryArea(&G2057_GraphicEMSMemoryArea, G2182_puc_AvailableEMSMemoryTop, G0653_l_AvailableGEMMemoryByteCount, MASK0x07F8_MEMREQ);
#endif
#ifdef MEDIA758_A36M_A35E_A35M
                        F0609_InitializeMemoryArea(&G2057_GraphicEMSMemoryArea, G2182_puc_AvailableEMSMemoryTop, G0653_l_AvailableGEMMemoryByteCount, MASK0x0700_MEMREQ);
#endif
                }
                G0648_l_AvailableHeapMemoryByteCount = G2069_LargestCacheableNativeBitmapByteCount;
#ifdef MEDIA707_I34E_I34M
                G0656_l_AvailableCacheMemoryByteCount = G0649_puc_GraphicMemoryTop - G0641_puc_CacheMemoryBottom;
#endif
#ifdef MEDIA758_A36M_A35E_A35M
                G0656_l_AvailableCacheMemoryByteCount = G0642_puc_GraphicMemoryBottom - G0641_puc_CacheMemoryBottom;
#endif
        } while (!F0756_EvaluateMemoryRequirements(!L3000_B_ContinueWithNextMemoryProfile, L2994_l_ByteCount)); /* L2994_l_ByteCount is always 0 in DM PC */
#endif
#ifdef MEDIA620_A31E_A31M_A33M
        return L1664_i_;
#endif
#endif
}

void F0477_MEMORY_OpenGraphicsDat_CPSDF(
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
void
#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
        while (G0625_i_FloppyDriveDMATimeout_CPSDF);
#endif
#endif
        if (G0631_i_GraphicsDatFileReferenceCount++) {
                return;
        }
#ifdef MEDIA505_F20E_F20J_P20JB_I34E_I34M_F31E_F31J_P31J
        F0739_MUSIC_Stop();
#endif
#ifdef MEDIA007_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E
        G0630_i_GraphicsDatFileHandle = Fopen("A:\\GRAPHICS.DAT", C0_READ_ONLY);
#endif
#ifdef MEDIA349_G14ED
        G0630_i_GraphicsDatFileHandle = F0770_FILE_Open("/DUNGEON.MASTER/DEMOIIGS.DAT");
#endif
#ifdef MEDIA388_G20E_G21E
        G0630_i_GraphicsDatFileHandle = F0770_FILE_Open("*:GRAPHICS.GAME");
#endif
#ifdef MEDIA413_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        G1134_ps_GraphicsDatFileHandle = Open("DungeonMaster:graphics.dat", MODE_OLDFILE);
#endif
#ifdef MEDIA457_P20JA
        G0630_i_GraphicsDatFileHandle = F0770_FILE_Open("\\JDATA\\GRAPHICS.DAT");
#endif
#ifdef MEDIA469_P20JB
        G0630_i_GraphicsDatFileHandle = F0770_FILE_Open("JDATA\\GRAPHICS.DAT");
#endif
#ifdef MEDIA487_F20E
        G0630_i_GraphicsDatFileHandle = F0770_FILE_Open("Q:\\DATA\\GRAPHICS.DAT");
#endif
#ifdef MEDIA564_F20J
        G0630_i_GraphicsDatFileHandle = F0770_FILE_Open("Q:\\JDATA\\GRAPHICS.DAT");
#endif
#ifdef MEDIA669_F31E
        G0630_i_GraphicsDatFileHandle = F0770_FILE_Open("CDATA\\GRAPHICS.DAT");
#endif
#ifdef MEDIA687_F31J_P31J
        G0630_i_GraphicsDatFileHandle = F0770_FILE_Open("CJDATA\\GRAPHICS.DAT");
#endif
#ifdef MEDIA607_X30J_X31J
        G0630_i_GraphicsDatFileHandle = F0770_FILE_Open("A:\\GRAPHICS.DAT");
#endif
#ifdef MEDIA618_A31E
        G1134_ps_GraphicsDatFileHandle = F0770_FILE_Open("DungeonMaster:graphics.dat");
#endif
#ifdef MEDIA755_A36M_A31M_A33M_A35E_A35M
        G1134_ps_GraphicsDatFileHandle = F0770_FILE_Open(G2130_GraphicsDatFileName);
#endif
#ifdef MEDIA707_I34E_I34M
        G0630_i_GraphicsDatFileHandle = F0770_FILE_Open(G2130_GraphicsDatFileName);
#endif
#ifdef MEDIA169_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_X30J_X31J
        if (G0630_i_GraphicsDatFileHandle < 0) {
#endif
#ifdef MEDIA425_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_A36M_A31E_A31M_A33M_A35E_A35M
        if (G1134_ps_GraphicsDatFileHandle == NULL) {
#endif
#ifdef MEDIA351_G14ED_G20E_G21E
        if (F0780_FILE_IsHandleInvalid(G0630_i_GraphicsDatFileHandle)) {
#endif
#ifdef MEDIA496_F20E_F20J_P20JA_P20JB_I34E_I34M_F31E_F31J_P31J
        if (F0780_FILE_IsHandleInvalid(G0630_i_GraphicsDatFileHandle)) {
#endif
                F0019_MAIN_DisplayErrorAndStop(C41_ERROR_UNABLE_TO_OPEN_GRAPHICS_DAT);
        }
}

void F0478_MEMORY_CloseGraphicsDat_CPSDF(
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
void
#endif
)
{
        if (--G0631_i_GraphicsDatFileReferenceCount) {
                return;
        }
#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
        while (G0625_i_FloppyDriveDMATimeout_CPSDF);
#endif
#endif
#ifdef MEDIA505_F20E_F20J_P20JB_I34E_I34M_F31E_F31J_P31J
        F0739_MUSIC_Stop();
#endif
#ifdef MEDIA098_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_F31E_F31J_X31J_P31J
        M572_CloseFile(G0630_i_GraphicsDatFileHandle);
#endif
#ifdef MEDIA425_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_A36M_A31E_A31M_A33M_A35E_A35M
        M572_CloseFile(G1134_ps_GraphicsDatFileHandle);
#endif
}

#ifdef MEDIA448_A21E_A22E
long F0535_MEMORY_GetGraphicsDatFileSize(
)
{
        REGISTER long L1733_l_FileSize;


        if (G0631_i_GraphicsDatFileReferenceCount) {
                L1733_l_FileSize = F0534_FLOPPY_GetFileSize(G1134_ps_GraphicsDatFileHandle);
        } else {
                F0477_MEMORY_OpenGraphicsDat_CPSDF();
                L1733_l_FileSize = F0534_FLOPPY_GetFileSize(G1134_ps_GraphicsDatFileHandle);
                F0478_MEMORY_CloseGraphicsDat_CPSDF();
        }
        return L1733_l_FileSize;
}
#endif

void F0479_MEMORY_ReadGraphicsDatHeader(
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
void
#endif
) /* In versions 3.x, this function can read both old (1.x & 2.x) and new (3.x) graphics.dat header formats */
{
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        REGISTER BOOLEAN L1504_B_AllocationSuccessful;
#endif
        REGISTER unsigned int16_t L1505_ui_Multiple;
#define AL1505_ui_ByteCount    L1505_ui_Multiple
#define AL1505_ui_GraphicIndex L1505_ui_Multiple
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER unsigned int16_t L3001_;
#endif
#ifdef MEDIA593_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER long L3002_l_;
#endif


        G0631_i_GraphicsDatFileReferenceCount = 0;
        F0477_MEMORY_OpenGraphicsDat_CPSDF();
#ifdef MEDIA505_F20E_F20J_P20JB_I34E_I34M_F31E_F31J_P31J
        F0739_MUSIC_Stop();
#endif
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
#ifdef MEDIA007_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E
        L1504_B_AllocationSuccessful = ((Fread(G0630_i_GraphicsDatFileHandle, (long)sizeof(G0632_ui_GraphicCount), &G0632_ui_GraphicCount) == sizeof(G0632_ui_GraphicCount)) &&
#endif
#ifdef MEDIA351_G14ED_G20E_G21E
        L1504_B_AllocationSuccessful = ((F0772_FILE_Read(G0630_i_GraphicsDatFileHandle, (long)sizeof(G0632_ui_GraphicCount), &G0632_ui_GraphicCount)) &&
#endif
#ifdef MEDIA413_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        L1504_B_AllocationSuccessful = ((Read(G1134_ps_GraphicsDatFileHandle, &G0632_ui_GraphicCount, (long)sizeof(G0632_ui_GraphicCount)) == sizeof(G0632_ui_GraphicCount)) &&
#endif
                                        (AL1505_ui_ByteCount = G0632_ui_GraphicCount << 1) &&
                                        ((G0634_pui_GraphicCompressedByteCount = (unsigned int16_t*)F0468_MEMORY_Allocate((long)AL1505_ui_ByteCount, C1_ALLOCATION_PERMANENT)) != NULL) &&
                                        ((G0635_pui_GraphicDecompressedByteCount = (unsigned int16_t*)F0468_MEMORY_Allocate((long)AL1505_ui_ByteCount, C1_ALLOCATION_PERMANENT)) != NULL) &&
#ifdef MEDIA007_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E
                                        (Fread(G0630_i_GraphicsDatFileHandle, (long)AL1505_ui_ByteCount, G0634_pui_GraphicCompressedByteCount) == AL1505_ui_ByteCount) &&
                                        (Fread(G0630_i_GraphicsDatFileHandle, (long)AL1505_ui_ByteCount, G0635_pui_GraphicDecompressedByteCount) == AL1505_ui_ByteCount) &&
#endif
#ifdef MEDIA351_G14ED_G20E_G21E
                                        (F0772_FILE_Read(G0630_i_GraphicsDatFileHandle, (long)AL1505_ui_ByteCount, G0634_pui_GraphicCompressedByteCount)) &&
                                        (F0772_FILE_Read(G0630_i_GraphicsDatFileHandle, (long)AL1505_ui_ByteCount, G0635_pui_GraphicDecompressedByteCount)) &&
#endif
#ifdef MEDIA413_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
                                        (Read(G1134_ps_GraphicsDatFileHandle, G0634_pui_GraphicCompressedByteCount, (long)AL1505_ui_ByteCount) == AL1505_ui_ByteCount) &&
                                        (Read(G1134_ps_GraphicsDatFileHandle, G0635_pui_GraphicDecompressedByteCount, (long)AL1505_ui_ByteCount) == AL1505_ui_ByteCount) &&
#endif
                                        ((G0636_ppuc_Graphics = (unsigned char**)F0468_MEMORY_Allocate((long)(AL1505_ui_ByteCount << 1), C1_ALLOCATION_PERMANENT)) != NULL) &&
                                        ((G0637_pui_NativeBitmapBlockIndices = (unsigned int16_t*)F0468_MEMORY_Allocate((long)AL1505_ui_ByteCount, C1_ALLOCATION_PERMANENT)) != NULL));
        if (!L1504_B_AllocationSuccessful)
                goto T0479010;
#endif
#ifdef MEDIA525_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_F31E_F31J_X31J_P31J
        if (!F0772_FILE_Read(G0630_i_GraphicsDatFileHandle, (long)sizeof(G0632_ui_GraphicCount), (unsigned char HUGE*)&G0632_ui_GraphicCount)) /* Read file signature, expecting 0x8001 */
#endif
#ifdef MEDIA746_A36M_A31E_A31M_A33M_A35E_A35M
        if (!F0772_FILE_Read(G1134_ps_GraphicsDatFileHandle, (long)sizeof(G0632_ui_GraphicCount), (unsigned char HUGE*)&G0632_ui_GraphicCount)) /* Read file signature, expecting 0x8001 */
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                goto T0479010;
#endif
#ifdef MEDIA593_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        if (M007_GET(G0632_ui_GraphicCount, MASK0x8000_NEWFILEFORMAT)) {
                G2065_GraphicsDatFileFormat = M007_GET(G0632_ui_GraphicCount, MASK0x7FFF_NEWFILEFORMATID);
#endif
#ifdef MEDIA590_X30J_P20JA_P20JB_I34E_I34M_F31E_F31J_X31J_P31J
                if ((G2065_GraphicsDatFileFormat != 1) || !F0772_FILE_Read(G0630_i_GraphicsDatFileHandle, (long)sizeof(G0632_ui_GraphicCount), (unsigned char HUGE*)&G0632_ui_GraphicCount)) /* Read actual graphic count */
#endif
#ifdef MEDIA746_A36M_A31E_A31M_A33M_A35E_A35M
                if ((G2065_GraphicsDatFileFormat != 1) || !F0772_FILE_Read(G1134_ps_GraphicsDatFileHandle, (long)sizeof(G0632_ui_GraphicCount), (unsigned char HUGE*)&G0632_ui_GraphicCount)) /* Read actual graphic count */
#endif
#ifdef MEDIA593_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                        goto T0479010;
        }
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        AL1505_ui_ByteCount = G0632_ui_GraphicCount << 1;
        G0634_pui_GraphicCompressedByteCount = (unsigned int16_t*)M533_F0468_MEMORY_Allocate((long)AL1505_ui_ByteCount, C1_ALLOCATION_PERMANENT, MASK0x0400_MEMREQ);
#endif
#ifdef MEDIA521_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A31E_A31M_A33M_F31E_F31J_X31J_P31J
        G0635_pui_GraphicDecompressedByteCount = (unsigned int16_t*)M533_F0468_MEMORY_Allocate((long)AL1505_ui_ByteCount, C1_ALLOCATION_PERMANENT, MASK0x0400_MEMREQ);
#endif
#ifdef MEDIA758_A36M_A35E_A35M
        G0635_pui_GraphicDecompressedByteCount = G0634_pui_GraphicCompressedByteCount;
#endif
#ifdef MEDIA525_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_F31E_F31J_X31J_P31J
        if (!F0772_FILE_Read(G0630_i_GraphicsDatFileHandle, (long)AL1505_ui_ByteCount, (unsigned char HUGE*)G0634_pui_GraphicCompressedByteCount))
#endif
#ifdef MEDIA746_A36M_A31E_A31M_A33M_A35E_A35M
        if (!F0772_FILE_Read(G1134_ps_GraphicsDatFileHandle, (long)AL1505_ui_ByteCount, (unsigned char HUGE*)G0634_pui_GraphicCompressedByteCount))
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                goto T0479010;
#endif
#ifdef MEDIA525_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_F31E_F31J_X31J_P31J
        if (!F0772_FILE_Read(G0630_i_GraphicsDatFileHandle, (long)AL1505_ui_ByteCount, (unsigned char HUGE*)G0635_pui_GraphicDecompressedByteCount))
#endif
#ifdef MEDIA746_A36M_A31E_A31M_A33M_A35E_A35M
        if (!F0772_FILE_Read(G1134_ps_GraphicsDatFileHandle, (long)AL1505_ui_ByteCount, (unsigned char HUGE*)G0635_pui_GraphicDecompressedByteCount))
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                goto T0479010;
        G0636_ppuc_Graphics = (unsigned char HUGE**)M533_F0468_MEMORY_Allocate((long)(G0632_ui_GraphicCount * sizeof(unsigned char HUGE*)), C1_ALLOCATION_PERMANENT, MASK0x0400_MEMREQ);
        G0637_pui_NativeBitmapBlockIndices = (unsigned int16_t*)M533_F0468_MEMORY_Allocate((long)AL1505_ui_ByteCount, C1_ALLOCATION_PERMANENT, MASK0x0400_MEMREQ);
#endif
#ifdef MEDIA361_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A31E_A31M_A33M_F31E_F31J_X31J_P31J
        F0007_MAIN_CopyBytes(M772_CAST_PC(G0634_pui_GraphicCompressedByteCount), M772_CAST_PC(G0635_pui_GraphicDecompressedByteCount), M543_BYTE_COUNT_INT(AL1505_ui_ByteCount));
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
#ifdef MEDIA488_F20E_F20J
        G2005_GraphicWidthHeight = (GRATTR*)M533_F0468_MEMORY_Allocate((long)G0632_ui_GraphicCount * sizeof(GRATTR), C1_ALLOCATION_PERMANENT, MASK0x0400_MEMREQ);
#endif
#ifdef MEDIA593_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        G2005_GraphicWidthHeight = (GRATTR*)M533_F0468_MEMORY_Allocate(L3002_l_ = (long)G0632_ui_GraphicCount * sizeof(GRATTR), C1_ALLOCATION_PERMANENT, MASK0x0400_MEMREQ);
        if (G2065_GraphicsDatFileFormat == 1) {
#ifdef MEDIA590_X30J_P20JA_P20JB_I34E_I34M_F31E_F31J_X31J_P31J
                if (!F0772_FILE_Read(G0630_i_GraphicsDatFileHandle, L3002_l_, (unsigned char HUGE*)G2005_GraphicWidthHeight))
#endif
#ifdef MEDIA746_A36M_A31E_A31M_A33M_A35E_A35M
                if (!F0772_FILE_Read(G1134_ps_GraphicsDatFileHandle, L3002_l_, (unsigned char HUGE*)G2005_GraphicWidthHeight))
#endif
                        goto T0479010;
        } else { /* Read width & height of each graphic */
#endif
                for (L3001_ = 0; L3001_ < G0632_ui_GraphicCount; L3001_++) {
#ifdef MEDIA525_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_F31E_F31J_X31J_P31J
                        if (!(F0774_FILE_Seek(G0630_i_GraphicsDatFileHandle, F0467_MEMORY_GetGraphicOffset(L3001_)) && F0772_FILE_Read(G0630_i_GraphicsDatFileHandle, (long)sizeof(int16_t) * 2, (unsigned char HUGE*)&G2005_GraphicWidthHeight[L3001_])))
#endif
#ifdef MEDIA746_A36M_A31E_A31M_A33M_A35E_A35M
                        if (!(F0774_FILE_Seek(G1134_ps_GraphicsDatFileHandle, F0467_MEMORY_GetGraphicOffset(L3001_)) && F0772_FILE_Read(G1134_ps_GraphicsDatFileHandle, (long)sizeof(int16_t) * 2, (unsigned char HUGE*)&G2005_GraphicWidthHeight[L3001_])))
#endif
                                goto T0479010;
                }
#ifdef MEDIA593_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        }
#endif
#endif
        F0008_MAIN_ClearBytes(M772_CAST_PC(G0636_ppuc_Graphics), M543_BYTE_COUNT_INT(AL1505_ui_ByteCount << 1));
        F0010_MAIN_WriteSpacedWords(M773_CAST_PI(G0637_pui_NativeBitmapBlockIndices), AL1505_ui_ByteCount >>= 1, 0xFFFF, (int16_t)sizeof(int16_t));
        AL1505_ui_GraphicIndex--;
        G0633_l_GraphicsDatFileSize = F0467_MEMORY_GetGraphicOffset(AL1505_ui_GraphicIndex) + G0634_pui_GraphicCompressedByteCount[AL1505_ui_GraphicIndex];
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        if ((G0343_puc_Graphic_DialogBox = (unsigned char*)F0468_MEMORY_Allocate((long)G0635_pui_GraphicDecompressedByteCount[C000_GRAPHIC_DIALOG_BOX], C1_ALLOCATION_PERMANENT)) == NULL)
                goto T0479010;
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        G0343_puc_Graphic_DialogBox = M533_F0468_MEMORY_Allocate((long)G0635_pui_GraphicDecompressedByteCount[C000_GRAPHIC_DIALOG_BOX], C1_ALLOCATION_PERMANENT, MASK0x0400_MEMREQ);
#endif
        F0474_MEMORY_LoadGraphic_CPSDF(C000_GRAPHIC_DIALOG_BOX, G0343_puc_Graphic_DialogBox);
        return;
        T0479010:
        F0019_MAIN_DisplayErrorAndStop(C42_ERROR_UNABLE_TO_LOAD_GRAPHICS_DAT_HEADER);
}

void F0480_CACHE_ReleaseBlock(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0890_i_BitmapIndex)
int16_t P0890_i_BitmapIndex FINAL_SEPARATOR
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
REGISTER int16_t P0890_i_BitmapIndex FINAL_SEPARATOR
#endif
{
        REGISTER unsigned char HUGE* L1510_puc_BlockToRelease;
        REGISTER unsigned char HUGE* L1511_puc_Block;
        REGISTER long L1506_l_Size;
        REGISTER long L1507_l_PreviousBlockSize;
        REGISTER unsigned int16_t L1508_ui_BlockIndex;
        REGISTER unsigned int16_t L1509_ui_NextBlockIndex;


        if (P0890_i_BitmapIndex >= 0) {
                if ((L1508_ui_BlockIndex = G0637_pui_NativeBitmapBlockIndices[P0890_i_BitmapIndex]) == 0xFFFF)
                        return;
                G0637_pui_NativeBitmapBlockIndices[P0890_i_BitmapIndex] = 0xFFFF;
        } else {
                M009_CLEAR(P0890_i_BitmapIndex, MASK0x8000_DERIVED_BITMAP);
                if ((L1508_ui_BlockIndex = G0638_pui_DerivedBitmapBlockIndices[P0890_i_BitmapIndex]) == 0xFFFF)
                        return;
                G0638_pui_DerivedBitmapBlockIndices[P0890_i_BitmapIndex] = 0xFFFF;
        }
        L1510_puc_BlockToRelease = G0655_ppuc_Blocks[L1508_ui_BlockIndex];
        G0655_ppuc_Blocks[L1508_ui_BlockIndex] = NULL;
        L1506_l_Size = -M080_BLOCK_SIZE(L1510_puc_BlockToRelease);
        G0656_l_AvailableCacheMemoryByteCount += L1506_l_Size;
        L1508_ui_BlockIndex = M082_USED_BLOCK_PREVIOUS_INDEX(L1510_puc_BlockToRelease);
        L1509_ui_NextBlockIndex = M083_USED_BLOCK_NEXT_INDEX(L1510_puc_BlockToRelease);
        if (L1508_ui_BlockIndex == 0xFFFF) {
                if (L1509_ui_NextBlockIndex == 0xFFFF) {
                        G0658_puc_FirstUsedBlock = NULL;
                        G0659_puc_LastUsedBlock = NULL;
                        G0660_puc_FirstReferencedUsedBlock = NULL;
                } else {
                        G0658_puc_FirstUsedBlock = G0655_ppuc_Blocks[L1509_ui_NextBlockIndex];
                        M082_USED_BLOCK_PREVIOUS_INDEX(G0658_puc_FirstUsedBlock) = 0xFFFF;
                        if (G0660_puc_FirstReferencedUsedBlock == L1510_puc_BlockToRelease) {
#ifdef PC_FIX_CODE_SIZE
        L1508_ui_BlockIndex++;
        L1508_ui_BlockIndex++;
        L1508_ui_BlockIndex++;
        L1508_ui_BlockIndex++;
        L1508_ui_BlockIndex++;
        L1508_ui_BlockIndex++;
        L1508_ui_BlockIndex++;
#endif
                                G0660_puc_FirstReferencedUsedBlock = G0658_puc_FirstUsedBlock;
                        }
                }
        } else {
                L1511_puc_Block = G0655_ppuc_Blocks[L1508_ui_BlockIndex];
                M083_USED_BLOCK_NEXT_INDEX(L1511_puc_Block) = L1509_ui_NextBlockIndex;
                if (L1509_ui_NextBlockIndex == 0xFFFF) {
                        G0659_puc_LastUsedBlock = L1511_puc_Block;
                        if (G0660_puc_FirstReferencedUsedBlock == L1510_puc_BlockToRelease) {
#ifdef PC_FIX_CODE_SIZE
        L1508_ui_BlockIndex++;
        L1508_ui_BlockIndex++;
        L1508_ui_BlockIndex++;
        L1508_ui_BlockIndex++;
        L1508_ui_BlockIndex++;
        L1508_ui_BlockIndex++;
        L1508_ui_BlockIndex++;
        L1508_ui_BlockIndex++;
        L1508_ui_BlockIndex++;
        L1508_ui_BlockIndex++;
        L1508_ui_BlockIndex++;
#endif
                                G0660_puc_FirstReferencedUsedBlock = NULL;
                        }
                } else {
                        L1511_puc_Block = G0655_ppuc_Blocks[L1509_ui_NextBlockIndex];
                        M082_USED_BLOCK_PREVIOUS_INDEX(L1511_puc_Block) = L1508_ui_BlockIndex;
                        if (G0660_puc_FirstReferencedUsedBlock == L1510_puc_BlockToRelease) {
                                G0660_puc_FirstReferencedUsedBlock = L1511_puc_Block;
                        }
                }
        }
        if ((L1510_puc_BlockToRelease != G0641_puc_CacheMemoryBottom) && ((L1507_l_PreviousBlockSize = M079_PREVIOUS_BLOCK_SIZE(L1510_puc_BlockToRelease)) > 0)) {
                L1510_puc_BlockToRelease -= L1507_l_PreviousBlockSize;
                F0471_CACHE_RemoveUnusedBlock(L1510_puc_BlockToRelease);
                L1506_l_Size += L1507_l_PreviousBlockSize;
        }
        if ((L1510_puc_BlockToRelease + L1506_l_Size) == G0651_puc_CacheMemoryTop) {
                G0651_puc_CacheMemoryTop = L1510_puc_BlockToRelease;
                return;
        }
        if ((L1507_l_PreviousBlockSize = M080_BLOCK_SIZE(L1511_puc_Block = L1510_puc_BlockToRelease + L1506_l_Size)) > 0) {
                F0471_CACHE_RemoveUnusedBlock(L1511_puc_Block);
                L1506_l_Size += L1507_l_PreviousBlockSize;
        }
        M080_BLOCK_SIZE(L1510_puc_BlockToRelease) = L1506_l_Size;
        M079_PREVIOUS_BLOCK_SIZE(L1510_puc_BlockToRelease + L1506_l_Size) = L1506_l_Size;
        F0472_CACHE_AddUnusedBlock(L1510_puc_BlockToRelease);
}

STATICFUNCTION void F0481_CACHE_FreeMemory(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0891_l_ByteCount)
#endif
long P0891_l_ByteCount FINAL_SEPARATOR
{
        while (G0656_l_AvailableCacheMemoryByteCount < P0891_l_ByteCount) {
                if (G0658_puc_FirstUsedBlock == NULL) {
                        F0019_MAIN_DisplayErrorAndStop(C43_ERROR_NOT_ENOUGH_MEMORY_TO_ALLOCATE_BLOCK);
                }
                F0480_CACHE_ReleaseBlock(M084_USED_BLOCK_BITMAP_INDEX(G0658_puc_FirstUsedBlock));
        }
}

STATICFUNCTION void F0482_CACHE_Defragment(
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
void
#endif
) /* Compact used blocks and remove all unused blocks */
{
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER unsigned char HUGE* L1516_puc_UsedBlockToMove;
#endif
        REGISTER unsigned char HUGE* L1515_puc_UnusedBlock;
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        REGISTER unsigned char* L1516_puc_UsedBlockToMove;
#endif
        REGISTER long L1512_l_BlockSize;
        REGISTER int16_t L1513_i_BitmapIndex;
        REGISTER unsigned int16_t L1514_ui_BlockIndex;


        if (G0657_puc_FirstUnusedBlock == NULL) {
                return;
        }
        L1515_puc_UnusedBlock = L1516_puc_UsedBlockToMove = G0641_puc_CacheMemoryBottom;
        do {
                if ((L1512_l_BlockSize = M080_BLOCK_SIZE(L1516_puc_UsedBlockToMove)) > 0) { /* If block is unused */
                        L1516_puc_UsedBlockToMove += L1512_l_BlockSize;
                } else {
                        L1512_l_BlockSize = -L1512_l_BlockSize; /* Get size of used block */
                        if (L1516_puc_UsedBlockToMove != L1515_puc_UnusedBlock) {
                                L1513_i_BitmapIndex = M084_USED_BLOCK_BITMAP_INDEX(L1516_puc_UsedBlockToMove);
                                if (L1513_i_BitmapIndex >= 0) {
                                        L1514_ui_BlockIndex = G0637_pui_NativeBitmapBlockIndices[L1513_i_BitmapIndex];
                                } else {
                                        L1514_ui_BlockIndex = G0638_pui_DerivedBitmapBlockIndices[M007_GET(L1513_i_BitmapIndex, MASK0x7FFF_GRAPHIC_INDEX)];
                                }
                                G0655_ppuc_Blocks[L1514_ui_BlockIndex] = L1515_puc_UnusedBlock;
                                F0007_MAIN_CopyBytes(M772_CAST_PC(L1516_puc_UsedBlockToMove), M772_CAST_PC(L1515_puc_UnusedBlock), M573_BYTE_COUNT_LONG(L1512_l_BlockSize));
                                if (G0658_puc_FirstUsedBlock == L1516_puc_UsedBlockToMove) {
                                        G0658_puc_FirstUsedBlock = L1515_puc_UnusedBlock;
                                }
                                if (G0659_puc_LastUsedBlock == L1516_puc_UsedBlockToMove) {
                                        G0659_puc_LastUsedBlock = L1515_puc_UnusedBlock;
                                }
                                if (G0660_puc_FirstReferencedUsedBlock == L1516_puc_UsedBlockToMove) {
                                        G0660_puc_FirstReferencedUsedBlock = L1515_puc_UnusedBlock;
                                }
                        }
                        L1516_puc_UsedBlockToMove += L1512_l_BlockSize;
                        L1515_puc_UnusedBlock += L1512_l_BlockSize;
                }
        } while (L1516_puc_UsedBlockToMove != G0651_puc_CacheMemoryTop);
        G0651_puc_CacheMemoryTop = L1515_puc_UnusedBlock;
        G0657_puc_FirstUnusedBlock = NULL;
}

STATICFUNCTION unsigned char* F0483_CACHE_GetNewBlock(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0892_l_Size)
#endif
REGISTER long P0892_l_Size FINAL_SEPARATOR
{
        REGISTER unsigned char HUGE* L1519_puc_NewBlock;
        REGISTER unsigned char HUGE* L1520_puc_Block;
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        REGISTER BOOLEAN L1517_B_BlockToReuseFound;
#endif
        REGISTER long L1518_l_BlockSize;
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER BOOLEAN L1517_B_BlockToReuseFound;
#endif


        F0481_CACHE_FreeMemory(P0892_l_Size);
#ifdef MEDIA055_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J
        if (((long)G0642_puc_GraphicMemoryBottom - (long)G0651_puc_CacheMemoryTop) >= P0892_l_Size) { /* If there is enough cache memory then allocate a new block */
#endif
#ifdef MEDIA459_P20JA_P20JB_P31J
        if ((G0642_puc_GraphicMemoryBottom - G0651_puc_CacheMemoryTop) >= P0892_l_Size) { /* If there is enough cache memory then allocate a new block */
#endif
#ifdef MEDIA707_I34E_I34M
        if ((G0649_puc_GraphicMemoryTop - G0651_puc_CacheMemoryTop) >= P0892_l_Size) { /* If there is enough cache memory then allocate a new block */
#endif
                L1519_puc_NewBlock = G0651_puc_CacheMemoryTop;
                G0651_puc_CacheMemoryTop += P0892_l_Size;
        } else { /* else find an existing unused block to reuse */
                if (M080_BLOCK_SIZE(G0657_puc_FirstUnusedBlock) < P0892_l_Size) { /* If the largest unused block is not large enough */
                        F0482_CACHE_Defragment();
                        L1519_puc_NewBlock = G0651_puc_CacheMemoryTop;
                        G0651_puc_CacheMemoryTop += P0892_l_Size;
                } else { /* else find an unused block that has the required size (or split the largest block and use a part of it) */
                        L1519_puc_NewBlock = G0657_puc_FirstUnusedBlock;
                        L1517_B_BlockToReuseFound = C0_FALSE;
                        do {
                                if (M080_BLOCK_SIZE(L1519_puc_NewBlock) == P0892_l_Size) { /* If a block of exactly the required size if found */
                                        L1517_B_BlockToReuseFound = C1_TRUE;
                                } else {
                                        if ((M080_BLOCK_SIZE(L1519_puc_NewBlock) < P0892_l_Size) || ((L1520_puc_Block = M087_UNUSED_BLOCK_NEXT_ADDRESS(L1519_puc_NewBlock)) == NULL)) { /* If the block is too small or is the last in the list of unused blocks */
                                                L1519_puc_NewBlock = G0657_puc_FirstUnusedBlock;
                                                L1517_B_BlockToReuseFound = C1_TRUE;
                                        } else {
                                                L1519_puc_NewBlock = L1520_puc_Block;
                                        }
                                }
                        } while (!L1517_B_BlockToReuseFound); /* ANOMALY_ASSEMBLY_COMPILATION_DIFFERENCE jmp */
                        F0471_CACHE_RemoveUnusedBlock(L1519_puc_NewBlock);
                        L1518_l_BlockSize = M080_BLOCK_SIZE(L1519_puc_NewBlock) - P0892_l_Size;
                        if (L1518_l_BlockSize >= (M574_BITMAP_OVERHEAD + 8)) { /* The reused block is split only if the remaining size is at least 24/28 bytes because a block cannot be smaller (12/16 bytes header, 4 bytes footer and at least 8 bytes for the smallest possible bitmap of 16x1 pixels */
                                L1520_puc_Block = L1519_puc_NewBlock + P0892_l_Size;
                                M080_BLOCK_SIZE(L1520_puc_Block) = M079_PREVIOUS_BLOCK_SIZE(L1520_puc_Block + L1518_l_BlockSize) = L1518_l_BlockSize;
                                F0472_CACHE_AddUnusedBlock(L1520_puc_Block);
                        } else {
                                P0892_l_Size = M080_BLOCK_SIZE(L1519_puc_NewBlock);
                        }
                }
        }
        G0656_l_AvailableCacheMemoryByteCount -= P0892_l_Size;
        M080_BLOCK_SIZE(L1519_puc_NewBlock) = -P0892_l_Size;
        M079_PREVIOUS_BLOCK_SIZE(L1519_puc_NewBlock + P0892_l_Size) = -P0892_l_Size;
        return L1519_puc_NewBlock;
}

#ifdef MEDIA728_I34E_I34M_A36M_A35E_A35M
void F0609_InitializeMemoryArea(
MEMORY_AREA*        P2031_ps_MemoryArea   SEPARATOR
unsigned char HUGE* P2032_puc_            SEPARATOR
long                P2033_l_              SEPARATOR
unsigned int16_t    P2034_ui_Requirements FINAL_SEPARATOR
{
        if ((P2031_ps_MemoryArea->HighestAvailable = P2031_ps_MemoryArea->Bottom = P2031_ps_MemoryArea->Top = P2032_puc_) != NULL) {
                P2031_ps_MemoryArea->Bottom = P2032_puc_ - P2033_l_;
        }
        P2031_ps_MemoryArea->Requirements = P2034_ui_Requirements; /* Value is always MASK0x07F8_MEMREQ */
}

unsigned char HUGE* F0610_DefragmentMemoryArea(
register MEMORY_AREA* P2035_ps_MemoryArea FINAL_SEPARATOR
{
        register unsigned char HUGE* L1525_puc_Graphic;
        register unsigned char HUGE* L1526_puc_Graphic;
        register int16_t AL1523_i_GraphicByteCount;
        register long L1524_l_ByteCount;


        if (P2035_ps_MemoryArea->Top == NULL) {
                return P2035_ps_MemoryArea->HighestAvailable;
        }
        L1525_puc_Graphic = (L1526_puc_Graphic = P2035_ps_MemoryArea->Top) - 2;
        while (P2035_ps_MemoryArea->HighestAvailable < L1525_puc_Graphic) { /* This loop defragments the graphics memory area by removing unnecessary graphics */
                if ((AL1523_i_GraphicByteCount = M090_GRAPHIC_INDEX_OR_SIZE(L1525_puc_Graphic)) < 0) { /* A negative value is the size of the graphic */
                        L1525_puc_Graphic += AL1523_i_GraphicByteCount - 2;
                } else { /* AL1523_i_GraphicByteCount is positive, it is a graphic index */
                        AL1523_i_GraphicByteCount = M007_GET(AL1523_i_GraphicByteCount, MASK0x1FFF_GRAPHIC_INDEX);
                        L1524_l_ByteCount = L1525_puc_Graphic - G0636_ppuc_Graphics[AL1523_i_GraphicByteCount] + 2;
                        L1526_puc_Graphic -= L1524_l_ByteCount;
                        L1525_puc_Graphic -= L1524_l_ByteCount;
                        if (L1525_puc_Graphic + 2 != L1526_puc_Graphic) {
                                F0007_MAIN_CopyBytes((char*)(L1525_puc_Graphic + 2), (char*)L1526_puc_Graphic, L1524_l_ByteCount);
                                G0636_ppuc_Graphics[AL1523_i_GraphicByteCount] = L1526_puc_Graphic;
                        }
                }
        }
        L1525_puc_Graphic = P2035_ps_MemoryArea->HighestAvailable;
        P2035_ps_MemoryArea->HighestAvailable = L1526_puc_Graphic;
        return L1525_puc_Graphic;
}

void F0611_MarkGraphicAsUnused(
unsigned char HUGE* P2036_puc_Graphic    SEPARATOR
int16_t             P2037_i_GraphicIndex FINAL_SEPARATOR
{
        long L3003_l_Size;


        L3003_l_Size = M104_EVEN_INTEGER(G0635_pui_GraphicDecompressedByteCount[M007_GET(M736_F0608_GetLanguageSpecificGraphicIndex(P2037_i_GraphicIndex), MASK0x1FFF_GRAPHIC_INDEX)]);
        M090_GRAPHIC_INDEX_OR_SIZE(P2036_puc_Graphic + L3003_l_Size) = -L3003_l_Size;
}

long F0612_RemoveGraphic(
REGISTER int16_t P2038_i_GraphicIndex SEPARATOR
REGISTER long    P2039_l_CurrentSize  SEPARATOR
long             P2040_l_MaximumSize  FINAL_SEPARATOR
{
        REGISTER unsigned char HUGE* L3004_puc_Graphic;
        REGISTER long L3005_l_ByteCount;


        P2038_i_GraphicIndex = M007_GET(P2038_i_GraphicIndex, MASK0x1FFF_GRAPHIC_INDEX);
        if ((L3004_puc_Graphic = G0636_ppuc_Graphics[P2038_i_GraphicIndex]) != NULL) {
                L3005_l_ByteCount = M104_EVEN_INTEGER(G0635_pui_GraphicDecompressedByteCount[M007_GET(M736_F0608_GetLanguageSpecificGraphicIndex(P2038_i_GraphicIndex), MASK0x1FFF_GRAPHIC_INDEX)] + (int16_t)sizeof(int16_t)); /* An int16_t is added after each graphic to store the graphic index */
                if ((G2057_GraphicEMSMemoryArea.Top != NULL) && (L3004_puc_Graphic >= G2057_GraphicEMSMemoryArea.Bottom) && (L3004_puc_Graphic <= G2057_GraphicEMSMemoryArea.Top) && ((P2039_l_CurrentSize + L3005_l_ByteCount) <= P2040_l_MaximumSize)) {
                        P2039_l_CurrentSize += L3005_l_ByteCount;
                } else {
                        F0480_CACHE_ReleaseBlock(P2038_i_GraphicIndex);
                        G0636_ppuc_Graphics[P2038_i_GraphicIndex] = NULL;
                        F0611_MarkGraphicAsUnused(L3004_puc_Graphic, P2038_i_GraphicIndex);
                }
        }
        return P2039_l_CurrentSize;
}

unsigned char HUGE* F0613_AllocateGraphicInMemoryArea(
MEMORY_AREA* P2041_ps_MemoryArea SEPARATOR
long         P2042_l_ByteCount   FINAL_SEPARATOR
{
        P2041_ps_MemoryArea->HighestAvailable -= P2042_l_ByteCount;
        return P2041_ps_MemoryArea->HighestAvailable;
}

unsigned char HUGE* F0614_CopyToMemoryArea(
MEMORY_AREA*   P2043_ps_MemoryArea SEPARATOR
unsigned char* P2044_puc_Graphic   SEPARATOR
long           P2045_l_ByteCount   FINAL_SEPARATOR
{
        unsigned char HUGE* L3006_Graphic;


        L3006_Graphic = F0613_AllocateGraphicInMemoryArea(P2043_ps_MemoryArea, P2045_l_ByteCount);
        F0007_MAIN_CopyBytes(P2044_puc_Graphic, (char*)L3006_Graphic, P2045_l_ByteCount);
        return L3006_Graphic;
}
#endif

void F0484_MEMORY_LoadGraphics_CPSDEF(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0893_p_GraphicIndices, P0894_i_GraphicCount)
#endif
#ifdef MEDIA057_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_F31E_F31J
int16_t*                   P0893_p_GraphicIndices SEPARATOR
#endif
#ifdef MEDIA595_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_X31J_P31J
REGISTER unsigned int16_t* P0893_p_GraphicIndices SEPARATOR /* Function is called with an array of indices with no flags set: MASK0x8000_NOT_EXPANDED, MASK0x4000_DO_NOT_COPY_DIMENSIONS and MASK0x2000_LOAD_IN_BASE_MEMORY */
#endif
int16_t                    P0894_i_GraphicCount   FINAL_SEPARATOR
{
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER unsigned char HUGE* L1525_puc_Graphic;
        REGISTER unsigned char HUGE* L1526_puc_Graphic;
        REGISTER long L1524_l_ByteCount;
#endif
        REGISTER int16_t L1521_i_Counter1;
        REGISTER int16_t L1522_i_Counter2;
        REGISTER int16_t L1523_i_Multiple;
#define AL1523_i_GraphicIndex     L1523_i_Multiple
#define AL1523_i_GraphicByteCount L1523_i_Multiple
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        REGISTER long L1524_l_ByteCount;
#endif
#ifdef MEDIA744_A36M
        MEMORY_AREA* L3007_ps_MemoryArea;
#endif
#ifdef MEDIA536_F20E_F20J_X30J_P20JA_P20JB_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER long L1527_l_TotalGraphicByteCountRequired; /* Only D34E D34M missing. Match another variable? */
#endif
#ifdef MEDIA413_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        REGISTER unsigned char HUGE* L1525_puc_Graphic;
        REGISTER unsigned char HUGE* L1526_puc_Graphic;
#endif
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        register long L1527_l_TotalGraphicByteCountRequired;
#endif
        long L1528_l_AvailableCacheMemoryByteCountAfterLoadingGraphics;
#ifdef MEDIA008_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E
        REGISTER unsigned char HUGE* L1525_puc_Graphic;
        REGISTER unsigned char HUGE* L1526_puc_Graphic;
#endif
#ifdef MEDIA728_I34E_I34M_A36M_A35E_A35M
        long L1527_l_TotalBaseMemoryGraphicByteCountRequired;
        long L3008_l_TotalEMSMemoryGraphicByteCountRequired;
        long L3009_l_EMSMemoryAreaByteCount;
        long L3010_l_CacheMemoryToReclaim;
#endif
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        unsigned char* L1529_puc_LZWTemporaryBuffer;
#endif
        BOOLEAN L1530_B_GraphicsDatOpened;
#ifdef MEDIA453_A21E_A22E_A36M_A31E_A31M_A33M_A35E_A35M
        BOOLEAN L1667_B_;
#endif
#ifdef MEDIA452_A21E_A22E_A31E_A31M_A33M
        BOOLEAN L1668_B_;
#endif
#ifdef MEDIA715_I34E_I34M_A35E_A35M
        MEMORY_AREA* L3007_ps_MemoryArea;
#endif


        L1530_B_GraphicsDatOpened = C0_FALSE;
#ifdef MEDIA453_A21E_A22E_A36M_A31E_A31M_A33M_A35E_A35M
        L1667_B_ = C0_FALSE;
#endif
#ifdef MEDIA488_F20E_F20J
        F0739_MUSIC_Stop();
#endif
#ifdef MEDIA022_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_A31E_A31M_A33M_F31E_F31J_X31J_P31J
        F0473_MEMORY_SortValues(M773_CAST_PI(P0893_p_GraphicIndices), P0894_i_GraphicCount);
        L1527_l_TotalGraphicByteCountRequired = 0;
#endif
#ifdef MEDIA728_I34E_I34M_A36M_A35E_A35M
        F0473_MEMORY_SortValues(P0893_p_GraphicIndices, P0894_i_GraphicCount, MASK0x1FFF_GRAPHIC_INDEX);
#endif
        for (L1521_i_Counter1 = 0; L1521_i_Counter1 < P0894_i_GraphicCount; L1521_i_Counter1++) {
                AL1523_i_GraphicIndex = P0893_p_GraphicIndices[L1521_i_Counter1];
                while (((L1522_i_Counter2 = L1521_i_Counter1 + 1) < P0894_i_GraphicCount) && (AL1523_i_GraphicIndex == P0893_p_GraphicIndices[L1522_i_Counter2])) { /* Remove duplicates from array */
#ifdef MEDIA025_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                        F0007_MAIN_CopyBytes(M772_CAST_PC(&P0893_p_GraphicIndices[L1522_i_Counter2]), M772_CAST_PC(&P0893_p_GraphicIndices[L1521_i_Counter1]), M543_BYTE_COUNT_INT((P0894_i_GraphicCount-- - L1522_i_Counter2) << 1));
#endif
#ifdef MEDIA716_I34E_I34M_A36M
                        F0007_MAIN_CopyBytes((char*)&P0893_p_GraphicIndices[L1522_i_Counter2], (char*)&P0893_p_GraphicIndices[L1521_i_Counter1], (P0894_i_GraphicCount-- - L1522_i_Counter2) * sizeof(unsigned int16_t));
#endif
                }
#ifdef MEDIA022_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_A31E_A31M_A33M_F31E_F31J_X31J_P31J
                L1524_l_ByteCount = 2 + G0635_pui_GraphicDecompressedByteCount[M736_F0608_GetLanguageSpecificGraphicIndex(AL1523_i_GraphicIndex)]; /* In memory, each graphic is followed by 2 bytes containing the size of the graphic in bytes */
                if (L1524_l_ByteCount & 0x00000001) { /* Make sure size is even */
                        L1524_l_ByteCount++;
                }
                L1527_l_TotalGraphicByteCountRequired += L1524_l_ByteCount;
#endif
        }
#ifdef MEDIA088_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A22G
        if (G0654_B_GraphicMemoryInitialized) {
                L1528_l_AvailableCacheMemoryByteCountAfterLoadingGraphics = (long)G0649_puc_GraphicMemoryTop - L1527_l_TotalGraphicByteCountRequired - (long)G0641_puc_CacheMemoryBottom;
        } else {
                L1528_l_AvailableCacheMemoryByteCountAfterLoadingGraphics = (long)G0642_puc_GraphicMemoryBottom - (long)G0641_puc_CacheMemoryBottom; /* BUG0_00 Useless code. This code is never executed because G0654_B_GraphicMemoryInitialized is always C1_TRUE when this function is called. If it were C0_FALSE, G0642_puc_GraphicMemoryBottom would still be NULL and the resulting value in L1528_l_AvailableCacheMemoryByteCountAfterLoadingGraphics would be negative */
        }
#ifdef MEDIA007_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E
        G0348_Bitmap_Screen[8000] = L1528_l_AvailableCacheMemoryByteCountAfterLoadingGraphics; /* BUG0_00 Useless code. The value is stored in the first long after video memory and is never used afterwards */
#endif
        /* The required minimum memory size for the cache is the total size of all bitmaps required at one time in the cache (including the overhead of 16 bytes per block in the cache). This occurs when calling F0133_VIDEO_BlitBoxFilledWithMaskedBitmap as this function requires three bitmaps at once in the cache:
                - A bitmap used as a source of pixels (graphic #73 for a teleporter, graphic #74 for a fluxcage or graphics #351 to #359 for explosions at D0)
                - A mask (graphics #69 to #72 for a teleporter or fluxcage, no mask for explosions at D0)
                - The derived bitmap #0 which has the size of the viewport and is used as a temporary bitmap
        The resulting value is 19576 but is actually slightly above the real required minimum because:
                - When drawing an explosion, the bitmap used as pixel source is indeed the largest but no mask is used so the required size is smaller in that case
                - When drawing a teleporter or fluxcage, a mask is used but the bitmap used as pixel source is a bit smaller so the required size is smaller in that case too */
        if ((long)(M075_BITMAP_BYTE_COUNT(224, 136) + 16 +  /* Derived bitmap #0 */
                   M075_BITMAP_BYTE_COUNT(64, 111)  + 16 +  /* Largest possible mask (graphic #71 for teleporters and fluxcages) */
                   M075_BITMAP_BYTE_COUNT(48, 31)   + 16)   /* Largest possible pixel source bitmap (graphics #351 to #359 for explosions at D0) */
            > L1528_l_AvailableCacheMemoryByteCountAfterLoadingGraphics) {
                F0019_MAIN_DisplayErrorAndStop(C44_ERROR_NOT_ENOUGH_CACHE_MEMORY_AFTER_LOADING_GRAPHICS);
        }
#endif
#ifdef MEDIA728_I34E_I34M_A36M_A35E_A35M
        L1527_l_TotalBaseMemoryGraphicByteCountRequired = L3008_l_TotalEMSMemoryGraphicByteCountRequired = 0;
        L3009_l_EMSMemoryAreaByteCount = (G2057_GraphicEMSMemoryArea.Top == NULL) ? 0 : G2057_GraphicEMSMemoryArea.Top - G2057_GraphicEMSMemoryArea.Bottom;
        for (L1521_i_Counter1 = 0; L1521_i_Counter1 < P0894_i_GraphicCount; L1521_i_Counter1++) {
                AL1523_i_GraphicIndex = P0893_p_GraphicIndices[L1521_i_Counter1];
                if ((L1525_puc_Graphic = G0636_ppuc_Graphics[M007_GET(AL1523_i_GraphicIndex, MASK0x1FFF_GRAPHIC_INDEX)]) != NULL) {
                        AL1523_i_GraphicIndex = M736_F0608_GetLanguageSpecificGraphicIndex(AL1523_i_GraphicIndex);
                        L1524_l_ByteCount = M104_EVEN_INTEGER(G0635_pui_GraphicDecompressedByteCount[M007_GET(AL1523_i_GraphicIndex, MASK0x1FFF_GRAPHIC_INDEX)] + (int16_t)sizeof(int16_t));
                        M009_CLEAR(P0893_p_GraphicIndices[L1521_i_Counter1], MASK0x2000_LOAD_IN_BASE_MEMORY);
                        if ((G2058_GraphicBaseMemoryArea.Top != NULL) && (L1525_puc_Graphic >= G2058_GraphicBaseMemoryArea.Bottom) && (L1525_puc_Graphic <= G2058_GraphicBaseMemoryArea.Top)) {
                                if (!M007_GET(AL1523_i_GraphicIndex, MASK0x4000_DO_NOT_COPY_DIMENSIONS)) { /* MASK0x4000_DO_NOT_COPY_DIMENSIONS is never set so the condition is always C1_TRUE */
                                        M008_SET(P0893_p_GraphicIndices[L1521_i_Counter1], MASK0x2000_LOAD_IN_BASE_MEMORY);
                                }
                                L1527_l_TotalBaseMemoryGraphicByteCountRequired += L1524_l_ByteCount;
                        } else {
                                L3008_l_TotalEMSMemoryGraphicByteCountRequired += L1524_l_ByteCount;
                        }
                }
        }
        for (L1521_i_Counter1 = 0; L1521_i_Counter1 < P0894_i_GraphicCount; L1521_i_Counter1++) {
                AL1523_i_GraphicIndex = P0893_p_GraphicIndices[L1521_i_Counter1];
                if ((G0636_ppuc_Graphics[M007_GET(AL1523_i_GraphicIndex, MASK0x1FFF_GRAPHIC_INDEX)]) == NULL) {
                        AL1523_i_GraphicIndex = M736_F0608_GetLanguageSpecificGraphicIndex(AL1523_i_GraphicIndex);
                        L1524_l_ByteCount = M104_EVEN_INTEGER(G0635_pui_GraphicDecompressedByteCount[M007_GET(AL1523_i_GraphicIndex, MASK0x1FFF_GRAPHIC_INDEX)] + (int16_t)sizeof(int16_t));
                        if (M007_GET(AL1523_i_GraphicIndex, MASK0x4000_DO_NOT_COPY_DIMENSIONS) || (L3008_l_TotalEMSMemoryGraphicByteCountRequired + L1524_l_ByteCount > L3009_l_EMSMemoryAreaByteCount)) {
                                L1527_l_TotalBaseMemoryGraphicByteCountRequired += L1524_l_ByteCount;
                                M008_SET(P0893_p_GraphicIndices[L1521_i_Counter1], MASK0x2000_LOAD_IN_BASE_MEMORY);
                        } else {
                                L3008_l_TotalEMSMemoryGraphicByteCountRequired += L1524_l_ByteCount;
                                M009_CLEAR(P0893_p_GraphicIndices[L1521_i_Counter1], MASK0x2000_LOAD_IN_BASE_MEMORY);
                        }
                }
        }
        for (L1521_i_Counter1 = 0; L1521_i_Counter1 < P0894_i_GraphicCount; L1521_i_Counter1++) {
                AL1523_i_GraphicIndex = P0893_p_GraphicIndices[L1521_i_Counter1];
                if (((L1525_puc_Graphic = G0636_ppuc_Graphics[M007_GET(AL1523_i_GraphicIndex, MASK0x1FFF_GRAPHIC_INDEX)]) != NULL) && M007_GET(AL1523_i_GraphicIndex, MASK0x2000_LOAD_IN_BASE_MEMORY)) {
                        AL1523_i_GraphicIndex = M736_F0608_GetLanguageSpecificGraphicIndex(AL1523_i_GraphicIndex);
                        L1524_l_ByteCount = M104_EVEN_INTEGER(G0635_pui_GraphicDecompressedByteCount[M007_GET(AL1523_i_GraphicIndex, MASK0x1FFF_GRAPHIC_INDEX)] + (int16_t)sizeof(int16_t));
                        if (L3008_l_TotalEMSMemoryGraphicByteCountRequired + L1524_l_ByteCount <= L3009_l_EMSMemoryAreaByteCount) {
                                L1527_l_TotalBaseMemoryGraphicByteCountRequired -= L1524_l_ByteCount;
                                L3008_l_TotalEMSMemoryGraphicByteCountRequired += L1524_l_ByteCount;
                        } else {
                                M009_CLEAR(P0893_p_GraphicIndices[L1521_i_Counter1], MASK0x2000_LOAD_IN_BASE_MEMORY);
                        }
                }
        }
#endif
#ifdef MEDIA449_A21E_A22E_F20E_F20J_X30J_P20JA_P20JB_A31E_A31M_A33M_F31E_F31J_X31J_P31J
        if (G0654_B_GraphicMemoryInitialized) {
#endif
#ifdef MEDIA448_A21E_A22E
                L1528_l_AvailableCacheMemoryByteCountAfterLoadingGraphics = (long)G0649_puc_GraphicMemoryTop - L1527_l_TotalGraphicByteCountRequired - (long)G0641_puc_CacheMemoryBottom;
#endif
#ifdef MEDIA510_F20E_F20J_X30J_P20JA_P20JB_A31E_A31M_A33M_F31E_F31J_X31J_P31J
                L1528_l_AvailableCacheMemoryByteCountAfterLoadingGraphics = G0649_puc_GraphicMemoryTop - G0641_puc_CacheMemoryBottom - L1527_l_TotalGraphicByteCountRequired;
#endif
#ifdef MEDIA728_I34E_I34M_A36M_A35E_A35M
                L3010_l_CacheMemoryToReclaim = G2058_GraphicBaseMemoryArea.HighestAvailable - (G2058_GraphicBaseMemoryArea.Top - L1527_l_TotalBaseMemoryGraphicByteCountRequired);
                L1528_l_AvailableCacheMemoryByteCountAfterLoadingGraphics = (G2058_GraphicBaseMemoryArea.Top - G0641_puc_CacheMemoryBottom) - L1527_l_TotalBaseMemoryGraphicByteCountRequired;
#endif
#ifdef MEDIA722_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_X31J_P31J
                G2173_l_AvailableCacheMemoryByteCountAfterLoadingGraphics = L1528_l_AvailableCacheMemoryByteCountAfterLoadingGraphics;
#endif
#ifdef MEDIA728_I34E_I34M_A36M_A35E_A35M
                G2138_l_AvailableMemoryByteCountForSounds = L1528_l_AvailableCacheMemoryByteCountAfterLoadingGraphics -
                                  ((long)(M075_BITMAP_BYTE_COUNT(224, 136) + M574_BITMAP_OVERHEAD +  /* Derived bitmap #0 */
                                          M075_BITMAP_BYTE_COUNT(64, 111)  + M574_BITMAP_OVERHEAD +  /* Largest possible mask (graphic #71 for teleporters and fluxcages in Atari ST version. In the PC version the largest mask is graphic #74 with dimensions 60 x 111 but the Atari ST size was used in the formula) */
                                          M075_BITMAP_BYTE_COUNT(48, 31)   + M574_BITMAP_OVERHEAD)); /* Largest possible pixel source bitmap (graphics #351 to #359 for explosions at D0) */
                if (G2057_GraphicEMSMemoryArea.Top != NULL) {
                        G2138_l_AvailableMemoryByteCountForSounds -= 3000;
                }
                if (G2136_B_EvaluatingMemoryRequirements) {
                        return;
                }
#endif
#ifdef MEDIA450_A21E_A22E_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
#ifdef MEDIA451_A21E_A22E_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_X31J_P31J
                if ((long)(M075_BITMAP_BYTE_COUNT(224, 136) + M574_BITMAP_OVERHEAD +  /* Derived bitmap #0 */
                           M075_BITMAP_BYTE_COUNT(64, 111)  + M574_BITMAP_OVERHEAD +  /* Largest possible mask (graphic #71 for teleporters and fluxcages) */
                           M075_BITMAP_BYTE_COUNT(48, 31)   + M574_BITMAP_OVERHEAD)   /* Largest possible pixel source bitmap (graphics #351 to #359 for explosions at D0) */
#endif
#ifdef MEDIA551_F20E_F20J_F31E_F31J
                if ((long)(M103_BITMAP_BYTE_COUNT(224, 136) + M574_BITMAP_OVERHEAD +  /* Derived bitmap #0 */
                           M103_BITMAP_BYTE_COUNT(64, 111)  + M574_BITMAP_OVERHEAD +  /* Largest possible mask (graphic #71 for teleporters and fluxcages) */
                           M103_BITMAP_BYTE_COUNT(48, 31)   + M574_BITMAP_OVERHEAD)   /* Largest possible pixel source bitmap (graphics #351 to #359 for explosions at D0) */
#endif
                    > L1528_l_AvailableCacheMemoryByteCountAfterLoadingGraphics) {
                        F0019_MAIN_DisplayErrorAndStop(C44_ERROR_NOT_ENOUGH_CACHE_MEMORY_AFTER_LOADING_GRAPHICS);
                }
#endif
#ifdef MEDIA452_A21E_A22E_A31E_A31M_A33M
        } else {
#ifdef MEDIA620_A31E_A31M_A33M
                G2173_l_AvailableCacheMemoryByteCountAfterLoadingGraphics = (long)G0649_puc_GraphicMemoryTop - (long)G0650_puc_GraphicMemoryBottomTemp - L1527_l_TotalGraphicByteCountRequired;
#endif
                if (G0661_B_LargeHeapMemory) {
                        L1667_B_ = C1_TRUE;
                        L1668_B_ = C0_FALSE;
                } else {
                        if (L1527_l_TotalGraphicByteCountRequired > ((long)G0649_puc_GraphicMemoryTop - (long)G0650_puc_GraphicMemoryBottomTemp)) {
                                F0019_MAIN_DisplayErrorAndStop(C44_ERROR_NOT_ENOUGH_CACHE_MEMORY_AFTER_LOADING_GRAPHICS);
                        }
                }
#endif
#ifdef MEDIA449_A21E_A22E_F20E_F20J_X30J_P20JA_P20JB_A31E_A31M_A33M_F31E_F31J_X31J_P31J
        }
#endif
        for (L1521_i_Counter1 = 0; L1521_i_Counter1 < M535_DERIVED_BITMAP_ACTUAL_COUNT_ALT; L1521_i_Counter1++) {
                if (G0638_pui_DerivedBitmapBlockIndices[L1521_i_Counter1] != 0xFFFF) {
                        F0480_CACHE_ReleaseBlock(L1521_i_Counter1 | MASK0x8000_DERIVED_BITMAP);
                }
        }
        L1522_i_Counter2 = L1521_i_Counter1 = 0;
        do {
#ifdef MEDIA022_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_A31E_A31M_A33M_F31E_F31J_X31J_P31J
                for (AL1523_i_GraphicIndex = P0893_p_GraphicIndices[L1521_i_Counter1]; L1522_i_Counter2 < AL1523_i_GraphicIndex; L1522_i_Counter2++) { /* Remove from memory all graphics that are not in the list of graphics to load (between two graphics to load) */
#ifdef MEDIA007_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E
                        if (L1525_puc_Graphic = G0636_ppuc_Graphics[L1522_i_Counter2]) { /* If the graphic is loaded in memory (non NULL address) */ /* ANOMALY_ST_COMPARISON_WITH_ZERO */
#endif
#ifdef MEDIA359_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_A31E_A31M_A33M_F31E_F31J_X31J_P31J
                        if ((L1525_puc_Graphic = G0636_ppuc_Graphics[L1522_i_Counter2]) != NULL) { /* If the graphic is loaded in memory (non NULL address) */
#endif
                                F0480_CACHE_ReleaseBlock(L1522_i_Counter2); /* Remove the corresponding bitmap from the cache */
                                G0636_ppuc_Graphics[L1522_i_Counter2] = NULL;
                                L1524_l_ByteCount = G0635_pui_GraphicDecompressedByteCount[M736_F0608_GetLanguageSpecificGraphicIndex(L1522_i_Counter2)];
                                if (L1524_l_ByteCount & 0x00000001) { /* Make sure size is even */
                                        L1524_l_ByteCount++;
                                }
                                M090_GRAPHIC_INDEX_OR_SIZE(L1525_puc_Graphic + L1524_l_ByteCount) = -L1524_l_ByteCount; /* Negative size means the graphic buffer is unused */
                        }
                }
#endif
#ifdef MEDIA728_I34E_I34M_A36M_A35E_A35M
                for (AL1523_i_GraphicIndex = M007_GET(P0893_p_GraphicIndices[L1521_i_Counter1], MASK0x1FFF_GRAPHIC_INDEX); L1522_i_Counter2 < AL1523_i_GraphicIndex; L1522_i_Counter2++) { /* Remove from memory all graphics that are not in the list of graphics to load (between two graphics to load) */
                        L3008_l_TotalEMSMemoryGraphicByteCountRequired = F0612_RemoveGraphic(L1522_i_Counter2, L3008_l_TotalEMSMemoryGraphicByteCountRequired, L3009_l_EMSMemoryAreaByteCount);
                }
#endif
                if (G0636_ppuc_Graphics[L1522_i_Counter2++] != NULL) { /* If graphic is already in memory */
                        P0893_p_GraphicIndices[L1521_i_Counter1] = ~P0893_p_GraphicIndices[L1521_i_Counter1];
                }
        } while (++L1521_i_Counter1 < P0894_i_GraphicCount); /* ANOMALY_ASSEMBLY_COMPILATION_DIFFERENCE jmp */
#ifdef MEDIA022_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_A31E_A31M_A33M_F31E_F31J_X31J_P31J
        for (; L1522_i_Counter2 < G0632_ui_GraphicCount; L1522_i_Counter2++) { /* Same loop as the previous one to remove from memory the remaining graphics not in the list of graphics to load (after the last graphic to load) */
                if ((L1525_puc_Graphic = G0636_ppuc_Graphics[L1522_i_Counter2]) != NULL) {
                        F0480_CACHE_ReleaseBlock(L1522_i_Counter2);
                        G0636_ppuc_Graphics[L1522_i_Counter2] = NULL;
                        L1524_l_ByteCount = G0635_pui_GraphicDecompressedByteCount[M736_F0608_GetLanguageSpecificGraphicIndex(L1522_i_Counter2)];
                        if (L1524_l_ByteCount & 0x00000001) { /* Make sure size is even */
                                L1524_l_ByteCount++;
                        }
                        M090_GRAPHIC_INDEX_OR_SIZE(L1525_puc_Graphic + L1524_l_ByteCount) = -L1524_l_ByteCount;
                }
        }
        if (G0654_B_GraphicMemoryInitialized) { /* G0654_B_GraphicMemoryInitialized is always C1_TRUE when this function is called */
#ifdef MEDIA074_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_X30J_A31E_A31M_A33M_X31J
                L1524_l_ByteCount = (long)G0650_puc_GraphicMemoryBottomTemp - ((long)G0649_puc_GraphicMemoryTop - L1527_l_TotalGraphicByteCountRequired);
#endif
#ifdef MEDIA551_F20E_F20J_F31E_F31J
                L1524_l_ByteCount = G0650_puc_GraphicMemoryBottomTemp - (G0649_puc_GraphicMemoryTop + -L1527_l_TotalGraphicByteCountRequired);
#endif
#ifdef MEDIA459_P20JA_P20JB_P31J
                L1524_l_ByteCount = G0650_puc_GraphicMemoryBottomTemp - (G0649_puc_GraphicMemoryTop - L1527_l_TotalGraphicByteCountRequired);
#endif
                if (L1524_l_ByteCount > 0) {
                        F0481_CACHE_FreeMemory(L1524_l_ByteCount);
                }
                F0482_CACHE_Defragment();
                G0656_l_AvailableCacheMemoryByteCount -= L1524_l_ByteCount;
        }
        L1525_puc_Graphic = (L1526_puc_Graphic = G0649_puc_GraphicMemoryTop) - 2;
        while (L1525_puc_Graphic > G0650_puc_GraphicMemoryBottomTemp) { /* This loop defragments the graphics memory by removing unnecessary graphics */
                if ((AL1523_i_GraphicByteCount = M090_GRAPHIC_INDEX_OR_SIZE(L1525_puc_Graphic)) < 0) { /* A negative value is the size of the graphic */
                        L1525_puc_Graphic += AL1523_i_GraphicByteCount - 2;
                } else {
#ifdef MEDIA050_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_A31E_A31M_A33M_F31E_F31J_X31J
                        L1524_l_ByteCount = 2 + ((long)L1525_puc_Graphic - (long)G0636_ppuc_Graphics[AL1523_i_GraphicIndex]);
#endif
#ifdef MEDIA459_P20JA_P20JB_P31J
                        L1524_l_ByteCount = 2 + (L1525_puc_Graphic - G0636_ppuc_Graphics[AL1523_i_GraphicIndex]);
#endif
                        L1526_puc_Graphic -= L1524_l_ByteCount;
                        L1525_puc_Graphic -= L1524_l_ByteCount;
                        if (L1525_puc_Graphic + 2 != L1526_puc_Graphic) {
                                F0007_MAIN_CopyBytes(M772_CAST_PC(L1525_puc_Graphic + 2), M772_CAST_PC(L1526_puc_Graphic), M573_BYTE_COUNT_LONG(L1524_l_ByteCount));
                                G0636_ppuc_Graphics[AL1523_i_GraphicIndex] = L1526_puc_Graphic;
                        }
                }
        }
#endif
#ifdef MEDIA007_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E
        L1529_puc_LZWTemporaryBuffer = F0468_MEMORY_Allocate(C5004L_LZW_TEMPORARY_BUFFER_BYTE_COUNT, C0_ALLOCATION_TEMPORARY_ON_TOP_OF_HEAP);
#endif
#ifdef MEDIA728_I34E_I34M_A36M_A35E_A35M
        for (; L1522_i_Counter2 < G0632_ui_GraphicCount; L1522_i_Counter2++) { /* Same loop as the previous one to remove from memory the remaining graphics not in the list of graphics to load (after the last graphic to load) */
                L3008_l_TotalEMSMemoryGraphicByteCountRequired = F0612_RemoveGraphic(L1522_i_Counter2, L3008_l_TotalEMSMemoryGraphicByteCountRequired, L3009_l_EMSMemoryAreaByteCount);
        }
        F0610_DefragmentMemoryArea(&G2057_GraphicEMSMemoryArea);
        for (L1521_i_Counter1 = 0; L1521_i_Counter1 < P0894_i_GraphicCount; L1521_i_Counter1++) {
                if ((AL1523_i_GraphicIndex = P0893_p_GraphicIndices[L1521_i_Counter1]) < 0) {
                        AL1523_i_GraphicIndex = ~AL1523_i_GraphicIndex;
                        if (((L1525_puc_Graphic = G0636_ppuc_Graphics[M007_GET(AL1523_i_GraphicIndex, MASK0x1FFF_GRAPHIC_INDEX)]) != NULL) && M007_GET(AL1523_i_GraphicIndex, MASK0x2000_LOAD_IN_BASE_MEMORY)) {
                                L1524_l_ByteCount = M104_EVEN_INTEGER(G0635_pui_GraphicDecompressedByteCount[M007_GET(M736_F0608_GetLanguageSpecificGraphicIndex(AL1523_i_GraphicIndex), MASK0x1FFF_GRAPHIC_INDEX)] + (int16_t)sizeof(int16_t));
                                AL1523_i_GraphicIndex = M007_GET(AL1523_i_GraphicIndex, MASK0x1FFF_GRAPHIC_INDEX);
                                G0636_ppuc_Graphics[AL1523_i_GraphicIndex] = F0614_CopyToMemoryArea(&G2057_GraphicEMSMemoryArea, (unsigned char*)L1525_puc_Graphic, L1524_l_ByteCount);
                                F0611_MarkGraphicAsUnused(L1525_puc_Graphic, AL1523_i_GraphicIndex);
                        }
                }
        }
        F0610_DefragmentMemoryArea(&G2058_GraphicBaseMemoryArea);
        if (L3010_l_CacheMemoryToReclaim > 0) {
                F0481_CACHE_FreeMemory(L3010_l_CacheMemoryToReclaim);
        }
        F0482_CACHE_Defragment();
        G0656_l_AvailableCacheMemoryByteCount -= L3010_l_CacheMemoryToReclaim;
        G2058_GraphicBaseMemoryArea.Bottom = G2058_GraphicBaseMemoryArea.Top - L1527_l_TotalBaseMemoryGraphicByteCountRequired;
#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
        while (G0625_i_FloppyDriveDMATimeout_CPSDF);
#endif
#endif
#ifdef MEDIA481_P20JB_I34E_I34M_F31E_F31J_P31J
        F0739_MUSIC_Stop();
#endif
        for (L1521_i_Counter1 = 0; L1521_i_Counter1 < P0894_i_GraphicCount; L1521_i_Counter1++) { /* Loop to load all graphics not already loaded */
                if ((AL1523_i_GraphicIndex = P0893_p_GraphicIndices[L1521_i_Counter1]) < 0) { /* If the graphic to load is already loaded in memory */
                        P0893_p_GraphicIndices[L1521_i_Counter1] = ~P0893_p_GraphicIndices[L1521_i_Counter1];
                } else {
#ifdef MEDIA088_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A22G
                        M090_GRAPHIC_INDEX_OR_SIZE(L1526_puc_Graphic - 2) = AL1523_i_GraphicIndex;
#endif
#ifdef MEDIA027_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_A31E_F31E_F31J_X31J_P31J
                        L1524_l_ByteCount = 2 + G0635_pui_GraphicDecompressedByteCount[AL1523_i_GraphicIndex];
#endif
#ifdef MEDIA656_A31M_A33M
                        L1524_l_ByteCount = 2 + G0635_pui_GraphicDecompressedByteCount[M736_F0608_GetLanguageSpecificGraphicIndex(AL1523_i_GraphicIndex)];
#endif
#ifdef MEDIA728_I34E_I34M_A36M_A35E_A35M
                        L1524_l_ByteCount = M104_EVEN_INTEGER(G0635_pui_GraphicDecompressedByteCount[M007_GET(M736_F0608_GetLanguageSpecificGraphicIndex(AL1523_i_GraphicIndex), MASK0x1FFF_GRAPHIC_INDEX)] + (int16_t)sizeof(int16_t));
#endif
#ifdef MEDIA022_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_A31E_A31M_A33M_F31E_F31J_X31J_P31J
                        if (L1524_l_ByteCount & 0x00000001) { /* Make sure size is even */
                                L1524_l_ByteCount++;
                        }
#endif
#ifdef MEDIA452_A21E_A22E_A31E_A31M_A33M
                        if (L1667_B_ && !L1668_B_) {
                                G1148_l_MemorySize -= L1524_l_ByteCount;
                                if (G1148_l_MemorySize < 0) {
#ifdef MEDIA620_A31E_A31M_A33M
                                        G0654_B_GraphicMemoryInitialized = C1_TRUE;
#endif
                                        L1668_B_ = C1_TRUE;
                                        L1526_puc_Graphic = G0642_puc_GraphicMemoryBottom;
                                }
                        }
#endif
#ifdef MEDIA620_A31E_A31M_A33M
                        if (L1668_B_) {
                                G0656_l_AvailableCacheMemoryByteCount -= L1524_l_ByteCount;
                        }
#endif
#ifdef MEDIA449_A21E_A22E_F20E_F20J_X30J_P20JA_P20JB_A31E_A31M_A33M_F31E_F31J_X31J_P31J
                        M090_GRAPHIC_INDEX_OR_SIZE(L1526_puc_Graphic - 2) = AL1523_i_GraphicIndex;
#endif
#ifdef MEDIA022_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_A31E_A31M_A33M_F31E_F31J_X31J_P31J
                        L1526_puc_Graphic -= L1524_l_ByteCount;
#endif
#ifdef MEDIA728_I34E_I34M_A36M_A35E_A35M
                        if (M007_GET(AL1523_i_GraphicIndex, MASK0x2000_LOAD_IN_BASE_MEMORY)) {
                                L3007_ps_MemoryArea = &G2058_GraphicBaseMemoryArea;
                        } else {
                                L3007_ps_MemoryArea = &G2057_GraphicEMSMemoryArea;
                        }
                        AL1523_i_GraphicIndex = M007_GET(AL1523_i_GraphicIndex, MASK0x1FFF_GRAPHIC_INDEX);
                        L1526_puc_Graphic = F0613_AllocateGraphicInMemoryArea(L3007_ps_MemoryArea, L1524_l_ByteCount);
                        M090_GRAPHIC_INDEX_OR_SIZE(L1526_puc_Graphic + L1524_l_ByteCount - 2) = AL1523_i_GraphicIndex;
/* TO TRY: check for compiler optimization of:
Why an optimization?:
        Produces anomaly in C35x
        L3007_ps_MemoryArea is either the first of last local variable (higher probability that this is not an explicitly defined variable but added by the compiler
                        if (M007_GET(AL1523_i_GraphicIndex, MASK0x2000_LOAD_IN_BASE_MEMORY)) {
                                AL1523_i_GraphicIndex = M007_GET(AL1523_i_GraphicIndex, MASK0x1FFF_GRAPHIC_INDEX);
                                L1526_puc_Graphic = F0613_AllocateGraphicInMemoryArea(&G2058_GraphicBaseMemoryArea, L1524_l_ByteCount);
                                M090_GRAPHIC_INDEX_OR_SIZE(L1526_puc_Graphic + L1524_l_ByteCount - 2) = AL1523_i_GraphicIndex;
                        } else {
                                AL1523_i_GraphicIndex = M007_GET(AL1523_i_GraphicIndex, MASK0x1FFF_GRAPHIC_INDEX);
                                L1526_puc_Graphic = F0613_AllocateGraphicInMemoryArea(&G2057_GraphicEMSMemoryArea, L1524_l_ByteCount);
                                M090_GRAPHIC_INDEX_OR_SIZE(L1526_puc_Graphic + L1524_l_ByteCount - 2) = AL1523_i_GraphicIndex;
                        }
*/

/* TESTED KO
                        (L1526_puc_Graphic = F0613_AllocateGraphicInMemoryArea(M007_GET(AL1523_i_GraphicIndex, MASK0x2000_LOAD_IN_BASE_MEMORY) ? &G2058_GraphicBaseMemoryArea : &G2057_GraphicEMSMemoryArea, L1524_l_ByteCount))[L1524_l_ByteCount - 2] = AL1523_i_GraphicIndex = M007_GET(AL1523_i_GraphicIndex, MASK0x1FFF_GRAPHIC_INDEX);

                        L1526_puc_Graphic = F0613_AllocateGraphicInMemoryArea(M007_GET(AL1523_i_GraphicIndex, MASK0x2000_LOAD_IN_BASE_MEMORY) ? &G2058_GraphicBaseMemoryArea : &G2057_GraphicEMSMemoryArea, L1524_l_ByteCount), M090_GRAPHIC_INDEX_OR_SIZE(L1526_puc_Graphic + L1524_l_ByteCount - 2) = (AL1523_i_GraphicIndex = M007_GET(AL1523_i_GraphicIndex, MASK0x1FFF_GRAPHIC_INDEX));

                        M090_GRAPHIC_INDEX_OR_SIZE((L1526_puc_Graphic = F0613_AllocateGraphicInMemoryArea(M007_GET(AL1523_i_GraphicIndex, MASK0x2000_LOAD_IN_BASE_MEMORY) ? &G2058_GraphicBaseMemoryArea : &G2057_GraphicEMSMemoryArea, L1524_l_ByteCount)) + L1524_l_ByteCount - 2) = (AL1523_i_GraphicIndex = M007_GET(AL1523_i_GraphicIndex, MASK0x1FFF_GRAPHIC_INDEX));
*/
#endif
                        if (!L1530_B_GraphicsDatOpened) {
#ifdef MEDIA014_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J
                                F0428_DIALOG_RequireGameDiskInDrive_NoDialogDrawn(C0_DO_NOT_FORCE_DIALOG_DM_CSB, C0_FALSE);
#endif
#ifdef MEDIA593_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                                F0428_DIALOG_RequireGameDiskInDrive_NoDialogDrawn(C0_DO_NOT_FORCE_DIALOG_DM_CSB);
#endif
                                F0477_MEMORY_OpenGraphicsDat_CPSDF();
                                L1530_B_GraphicsDatOpened = C1_TRUE;
                        }
#ifdef MEDIA007_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E
                        if (G0634_pui_GraphicCompressedByteCount[AL1523_i_GraphicIndex] != G0635_pui_GraphicDecompressedByteCount[AL1523_i_GraphicIndex]) {
                                (Fseek(F0467_MEMORY_GetGraphicOffset(AL1523_i_GraphicIndex), G0630_i_GraphicsDatFileHandle, C0_SEEK_FROM_BEGINNING_OF_FILE)) >= 0; /* Result of fseek is ignored */
                                F0497_LZW_Decompress(G0630_i_GraphicsDatFileHandle, (long)G0634_pui_GraphicCompressedByteCount[AL1523_i_GraphicIndex], L1526_puc_Graphic, G0296_puc_Bitmap_Viewport, L1529_puc_LZWTemporaryBuffer);
                                G0297_B_DrawFloorAndCeilingRequested = C1_TRUE;
                        } else {
#endif
                                F0474_MEMORY_LoadGraphic_CPSDF(AL1523_i_GraphicIndex, L1526_puc_Graphic);
#ifdef MEDIA007_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E
                        }
#endif
                        G0636_ppuc_Graphics[AL1523_i_GraphicIndex] = L1526_puc_Graphic;
                }
        }
        if (L1530_B_GraphicsDatOpened) {
                F0478_MEMORY_CloseGraphicsDat_CPSDF();
        }
#ifdef MEDIA022_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_A31E_A31M_A33M_F31E_F31J_X31J_P31J
        G0650_puc_GraphicMemoryBottomTemp = L1526_puc_Graphic;
#endif
#ifdef MEDIA448_A21E_A22E
        if (L1668_B_) {
                G0642_puc_GraphicMemoryBottom = L1526_puc_Graphic;
        }
#endif
#ifdef MEDIA022_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_A31E_A31M_A33M_F31E_F31J_X31J_P31J
        if (G0654_B_GraphicMemoryInitialized) {
                G0642_puc_GraphicMemoryBottom = G0650_puc_GraphicMemoryBottomTemp;
        }
#endif
#ifdef MEDIA707_I34E_I34M
        G0649_puc_GraphicMemoryTop = G2058_GraphicBaseMemoryArea.Bottom;
#endif
#ifdef MEDIA758_A36M_A35E_A35M
        G0642_puc_GraphicMemoryBottom = G2058_GraphicBaseMemoryArea.Bottom;
#endif
#ifdef MEDIA007_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E
#ifndef NOCOPYPROTECTION
        Floprd(M517_FuzzySectorReadingBuffer_CPSE, C0L_FILLER, C0_FLOPPY_DRIVE_A, C007_SECTOR_7, C0_TRACK_0, C0_SIDE_0, C1_ONE_SECTOR);
#endif
#endif
#ifdef MEDIA368_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_X30J_P20JA_P20JB_A31E_A31M_A33M_A35E_A35M_X31J
#ifndef NOCOPYPROTECTION
        F0527_FLOPPY_ReadFuzzySector_CPSX(M517_FuzzySectorReadingBuffer_CPSE);
#endif
#endif
#ifdef MEDIA007_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E
        F0469_MEMORY_FreeAtHeapTop(C5004L_LZW_TEMPORARY_BUFFER_BYTE_COUNT);
#endif
#ifdef MEDIA620_A31E_A31M_A33M
        if (!G0654_B_GraphicMemoryInitialized) {
                G2173_l_AvailableCacheMemoryByteCountAfterLoadingGraphics = G0656_l_AvailableCacheMemoryByteCount;
        }
#endif
}

STATICFUNCTION void F0485_CACHE_ResetUsageCounts(
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
void
#endif
)
{
        REGISTER unsigned char HUGE* L1532_puc_Block;
        REGISTER unsigned int16_t L1531_ui_BlockIndex;


        G0662_l_LastResetCacheUsageCountsTime = G0313_ul_GameTime;
        G0660_puc_FirstReferencedUsedBlock = NULL;
        if ((L1532_puc_Block = G0659_puc_LastUsedBlock) == NULL) {
                return;
        }
        while (M081_USED_BLOCK_USAGE_COUNT(L1532_puc_Block) != 0) {
                M081_USED_BLOCK_USAGE_COUNT(L1532_puc_Block) = 0;
                if ((L1531_ui_BlockIndex = M082_USED_BLOCK_PREVIOUS_INDEX(L1532_puc_Block)) == 0xFFFF)
                        break;
                L1532_puc_Block = G0655_ppuc_Blocks[L1531_ui_BlockIndex];
        }
}

STATICFUNCTION void F0486_MEMORY_AddBlockToUsedList(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0895_ui_BlockIndex)
#endif
REGISTER unsigned int16_t P0895_ui_BlockIndex FINAL_SEPARATOR
{
        REGISTER unsigned char HUGE* L1536_puc_BlockToAdd;
        REGISTER unsigned char HUGE* L1537_puc_Block;
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER int16_t L1535_i_BitmapIndex;
#endif
        REGISTER unsigned int16_t L1533_ui_PreviousUsedBlockIndex;
        REGISTER int16_t L1534_i_BlockIndex;
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        REGISTER int16_t L1535_i_BitmapIndex;
#endif


        L1536_puc_BlockToAdd = G0655_ppuc_Blocks[P0895_ui_BlockIndex];
        M081_USED_BLOCK_USAGE_COUNT(L1536_puc_BlockToAdd) = 1;
        if (G0660_puc_FirstReferencedUsedBlock == NULL) {
                M083_USED_BLOCK_NEXT_INDEX(L1536_puc_BlockToAdd) = 0xFFFF;
                if (G0659_puc_LastUsedBlock == NULL) {
                        M082_USED_BLOCK_PREVIOUS_INDEX(L1536_puc_BlockToAdd) = 0xFFFF;
                        G0658_puc_FirstUsedBlock = L1536_puc_BlockToAdd;
                } else {
                        M083_USED_BLOCK_NEXT_INDEX(G0659_puc_LastUsedBlock) = P0895_ui_BlockIndex;
                        L1535_i_BitmapIndex = M084_USED_BLOCK_BITMAP_INDEX(G0659_puc_LastUsedBlock);
                        L1533_ui_PreviousUsedBlockIndex = (L1535_i_BitmapIndex >= 0) ? G0637_pui_NativeBitmapBlockIndices[L1535_i_BitmapIndex] : G0638_pui_DerivedBitmapBlockIndices[M007_GET(L1535_i_BitmapIndex, MASK0x7FFF_GRAPHIC_INDEX)];
                        M082_USED_BLOCK_PREVIOUS_INDEX(L1536_puc_BlockToAdd) = L1533_ui_PreviousUsedBlockIndex;
                }
                G0659_puc_LastUsedBlock = L1536_puc_BlockToAdd;
        } else {
                L1533_ui_PreviousUsedBlockIndex = M082_USED_BLOCK_PREVIOUS_INDEX(G0660_puc_FirstReferencedUsedBlock);
                M082_USED_BLOCK_PREVIOUS_INDEX(G0660_puc_FirstReferencedUsedBlock) = P0895_ui_BlockIndex;
                M082_USED_BLOCK_PREVIOUS_INDEX(L1536_puc_BlockToAdd) = L1533_ui_PreviousUsedBlockIndex;
                if (L1533_ui_PreviousUsedBlockIndex != 0xFFFF) {
                        L1537_puc_Block = G0655_ppuc_Blocks[L1533_ui_PreviousUsedBlockIndex];
                        M083_USED_BLOCK_NEXT_INDEX(L1536_puc_BlockToAdd) = M083_USED_BLOCK_NEXT_INDEX(L1537_puc_Block);
                        M083_USED_BLOCK_NEXT_INDEX(L1537_puc_Block) = P0895_ui_BlockIndex;
                } else {
                        L1535_i_BitmapIndex = M084_USED_BLOCK_BITMAP_INDEX(G0660_puc_FirstReferencedUsedBlock);
                        L1534_i_BlockIndex = (L1535_i_BitmapIndex >= 0) ? G0637_pui_NativeBitmapBlockIndices[L1535_i_BitmapIndex] : G0638_pui_DerivedBitmapBlockIndices[M007_GET(L1535_i_BitmapIndex, MASK0x7FFF_GRAPHIC_INDEX)];
                        M083_USED_BLOCK_NEXT_INDEX(L1536_puc_BlockToAdd) = L1534_i_BlockIndex;
                        G0658_puc_FirstUsedBlock = L1536_puc_BlockToAdd;
                }
        }
        G0660_puc_FirstReferencedUsedBlock = L1536_puc_BlockToAdd;
}

STATICFUNCTION unsigned char* F0487_CACHE_GetBlockAndIncrementUsageCount(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0896_ui_BlockIndex) /* Used blocks are sorted in decreasing order of usage count */
#endif
REGISTER unsigned int16_t P0896_ui_BlockIndex FINAL_SEPARATOR
{
        REGISTER unsigned char HUGE* L1541_puc_Block;
        REGISTER unsigned char HUGE* L1542_puc_Block;
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER unsigned char HUGE* L1543_puc_Block;
#endif
        REGISTER unsigned int16_t L1538_ui_PreviousUsedBlockIndex;
        REGISTER unsigned int16_t L1539_ui_NextUsedBlockIndex;
        REGISTER unsigned int16_t L1540_ui_UsageCount;
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        unsigned char HUGE* L1543_puc_Block;
#endif


        L1543_puc_Block = L1541_puc_Block = G0655_ppuc_Blocks[P0896_ui_BlockIndex];
        if ((L1540_ui_UsageCount = M081_USED_BLOCK_USAGE_COUNT(L1541_puc_Block)) == 0) {
                if ((L1539_ui_NextUsedBlockIndex = M083_USED_BLOCK_NEXT_INDEX(L1541_puc_Block)) == 0xFFFF) {
                        G0660_puc_FirstReferencedUsedBlock = L1541_puc_Block;
                        M081_USED_BLOCK_USAGE_COUNT(L1541_puc_Block) = 1;
                        return L1541_puc_Block;
                }
                L1542_puc_Block = G0655_ppuc_Blocks[L1539_ui_NextUsedBlockIndex];
                if ((L1538_ui_PreviousUsedBlockIndex = M082_USED_BLOCK_PREVIOUS_INDEX(L1541_puc_Block)) == 0xFFFF) {
                        G0658_puc_FirstUsedBlock = L1542_puc_Block;
                        M082_USED_BLOCK_PREVIOUS_INDEX(L1542_puc_Block) = 0xFFFF;
                } else {
                        L1541_puc_Block = G0655_ppuc_Blocks[L1538_ui_PreviousUsedBlockIndex];
                        M083_USED_BLOCK_NEXT_INDEX(L1541_puc_Block) = L1539_ui_NextUsedBlockIndex;
                        M082_USED_BLOCK_PREVIOUS_INDEX(L1542_puc_Block) = L1538_ui_PreviousUsedBlockIndex;
                }
                F0486_MEMORY_AddBlockToUsedList(P0896_ui_BlockIndex);
                return L1543_puc_Block;
        }
        M081_USED_BLOCK_USAGE_COUNT(L1541_puc_Block) = (L1540_ui_UsageCount += 1);
        if (L1541_puc_Block == G0659_puc_LastUsedBlock) {
                return L1541_puc_Block;
        }
        L1542_puc_Block = G0655_ppuc_Blocks[L1539_ui_NextUsedBlockIndex = M083_USED_BLOCK_NEXT_INDEX(L1541_puc_Block)];
        if (M081_USED_BLOCK_USAGE_COUNT(L1542_puc_Block) >= L1540_ui_UsageCount) {
                return L1541_puc_Block;
        }
        if ((L1538_ui_PreviousUsedBlockIndex = M082_USED_BLOCK_PREVIOUS_INDEX(L1541_puc_Block)) == 0xFFFF) {
                G0658_puc_FirstUsedBlock = G0660_puc_FirstReferencedUsedBlock = L1542_puc_Block;
                M082_USED_BLOCK_PREVIOUS_INDEX(L1542_puc_Block) = 0xFFFF;
        } else {
                if (G0660_puc_FirstReferencedUsedBlock == L1541_puc_Block) {
                        G0660_puc_FirstReferencedUsedBlock = L1542_puc_Block;
                }
                L1541_puc_Block = G0655_ppuc_Blocks[L1538_ui_PreviousUsedBlockIndex];
                M083_USED_BLOCK_NEXT_INDEX(L1541_puc_Block) = L1539_ui_NextUsedBlockIndex;
                M082_USED_BLOCK_PREVIOUS_INDEX(L1542_puc_Block) = L1538_ui_PreviousUsedBlockIndex;
        }
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        do {
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        for (;;) {
#endif
                L1541_puc_Block = L1542_puc_Block;
                L1538_ui_PreviousUsedBlockIndex = L1539_ui_NextUsedBlockIndex;
                if ((L1539_ui_NextUsedBlockIndex = M083_USED_BLOCK_NEXT_INDEX(L1541_puc_Block)) == 0xFFFF) {
                        M083_USED_BLOCK_NEXT_INDEX(L1541_puc_Block) = P0896_ui_BlockIndex;
                        M082_USED_BLOCK_PREVIOUS_INDEX(L1543_puc_Block) = L1538_ui_PreviousUsedBlockIndex;
                        M083_USED_BLOCK_NEXT_INDEX(L1543_puc_Block) = 0xFFFF;
                        return G0659_puc_LastUsedBlock = L1543_puc_Block;
                }
#ifdef MEDIA365_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* ANOMALY_ST_BRANCH */
                else {
#endif
                        L1542_puc_Block = G0655_ppuc_Blocks[L1539_ui_NextUsedBlockIndex];
                        if (M081_USED_BLOCK_USAGE_COUNT(L1542_puc_Block) >= L1540_ui_UsageCount) {
                                M083_USED_BLOCK_NEXT_INDEX(L1541_puc_Block) = P0896_ui_BlockIndex;
                                M082_USED_BLOCK_PREVIOUS_INDEX(L1543_puc_Block) = L1538_ui_PreviousUsedBlockIndex;
                                M083_USED_BLOCK_NEXT_INDEX(L1543_puc_Block) = L1539_ui_NextUsedBlockIndex;
                                M082_USED_BLOCK_PREVIOUS_INDEX(L1542_puc_Block) = P0896_ui_BlockIndex;
                                return L1543_puc_Block;
                        }
#ifdef MEDIA365_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                }
#endif
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        } while (C1_TRUE);
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        }
#endif
}

void F0488_MEMORY_ExpandGraphicToBitmap(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0897_i_GraphicIndex, P0898_puc_Bitmap)
#endif
int16_t                 P0897_i_GraphicIndex SEPARATOR
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
REGISTER unsigned char* P0898_puc_Bitmap     FINAL_SEPARATOR
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
unsigned char*          P0898_puc_Bitmap     FINAL_SEPARATOR
#endif
{
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        REGISTER unsigned char* L1544_puc_Graphic;
#endif
#ifdef MEDIA508_F20E_F20J_X30J_P20JA_P20JB
        unsigned char* L1544_puc_Graphic;
#endif


#ifdef MEDIA020_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB
        L1544_puc_Graphic = G0636_ppuc_Graphics[P0897_i_GraphicIndex];
        F0466_EXPAND_GraphicToBitmap(L1544_puc_Graphic, P0898_puc_Bitmap, 0, 0);
#endif
#ifdef MEDIA720_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        F0466_EXPAND_GraphicToBitmap(G0636_ppuc_Graphics[P0897_i_GraphicIndex], P0898_puc_Bitmap);
        M100_PIXEL_WIDTH(P0898_puc_Bitmap) = G2005_GraphicWidthHeight[P0897_i_GraphicIndex].Width;
        M101_PIXEL_HEIGHT(P0898_puc_Bitmap) = G2005_GraphicWidthHeight[P0897_i_GraphicIndex].Height;
#endif
}

unsigned char* F0489_MEMORY_GetNativeBitmapOrGraphic(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0899_i_NativeBitmapOrGraphicIndex)
#endif
REGISTER int16_t P0899_i_NativeBitmapOrGraphicIndex FINAL_SEPARATOR
{
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        REGISTER unsigned int16_t L1545_ui_BlockIndex;
#endif
        REGISTER unsigned char HUGE* L1547_puc_Block;
        REGISTER unsigned char HUGE* L1548_puc_Graphic;
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER unsigned int16_t L1545_ui_BlockIndex;
#endif
        REGISTER long L1546_l_ByteCount;


        if (M007_GET(P0899_i_NativeBitmapOrGraphicIndex, MASK0x8000_NOT_EXPANDED)) {
                L1548_puc_Graphic = G0636_ppuc_Graphics[M007_GET(P0899_i_NativeBitmapOrGraphicIndex, (unsigned int16_t)MASK0x7FFF_GRAPHIC_INDEX)];
                return L1548_puc_Graphic;
        }
        if (G0313_ul_GameTime != G0662_l_LastResetCacheUsageCountsTime) {
                F0485_CACHE_ResetUsageCounts();
        }
        if ((L1545_ui_BlockIndex = G0637_pui_NativeBitmapBlockIndices[P0899_i_NativeBitmapOrGraphicIndex]) != 0xFFFF) {
                return M085_USED_BLOCK_BITMAP(F0487_CACHE_GetBlockAndIncrementUsageCount(L1545_ui_BlockIndex));
        }
        L1548_puc_Graphic = G0636_ppuc_Graphics[P0899_i_NativeBitmapOrGraphicIndex];
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        L1546_l_ByteCount = 16 + (M088_GRAPHIC_BYTE_WIDTH(L1548_puc_Graphic) * M089_GRAPHIC_HEIGHT(L1548_puc_Graphic)); /* Each block contains 16 bytes of data in addition to the bitmap itself */
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        L1546_l_ByteCount = 20 + M103_BITMAP_BYTE_COUNT(M105_GRAPHIC_PIXEL_WIDTH(L1548_puc_Graphic), M089_GRAPHIC_HEIGHT(L1548_puc_Graphic)); /* Each block contains 16 bytes of data in addition to the bitmap itself */
        if (L1546_l_ByteCount & 0x00000001) { /* Make sure size is even */
                L1546_l_ByteCount++;
        }
#endif
        L1547_puc_Block = F0483_CACHE_GetNewBlock(L1546_l_ByteCount);
        L1545_ui_BlockIndex = 0;
        while (G0655_ppuc_Blocks[L1545_ui_BlockIndex++] != NULL);
#ifdef MEDIA055_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J
        G0637_pui_NativeBitmapBlockIndices[P0899_i_NativeBitmapOrGraphicIndex] = --L1545_ui_BlockIndex;
#endif
#ifdef MEDIA463_P20JA_P20JB_I34E_I34M_P31J
        L1545_ui_BlockIndex--;
        G0637_pui_NativeBitmapBlockIndices[P0899_i_NativeBitmapOrGraphicIndex] = L1545_ui_BlockIndex;
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        if (L1545_ui_BlockIndex >= (M514_GRAPHIC_COUNT + M515_DERIVED_BITMAP_ACTUAL_COUNT)) {
                F0019_MAIN_DisplayErrorAndStop(C47_ERROR_OUT_OF_GRAPHIC_BLOCKS);
        }
#endif
        G0655_ppuc_Blocks[L1545_ui_BlockIndex] = L1547_puc_Block;
        M084_USED_BLOCK_BITMAP_INDEX(L1547_puc_Block) = P0899_i_NativeBitmapOrGraphicIndex;
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        M106_USED_BLOCK_BITMAP_WIDTH(L1547_puc_Block) = M105_GRAPHIC_PIXEL_WIDTH(L1548_puc_Graphic);
        M107_USED_BLOCK_BITMAP_HEIGHT(L1547_puc_Block) = M089_GRAPHIC_HEIGHT(L1548_puc_Graphic);
#endif
        F0486_MEMORY_AddBlockToUsedList(L1545_ui_BlockIndex);
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        L1547_puc_Block += 12; /* Address of the bitmap in the block */
        F0466_EXPAND_GraphicToBitmap(L1548_puc_Graphic, L1547_puc_Block, 0, 0);
#endif
#ifdef MEDIA463_P20JA_P20JB_I34E_I34M_P31J
        L1547_puc_Block = M085_USED_BLOCK_BITMAP(L1547_puc_Block); /* Address of the bitmap in the block */
#endif
#ifdef MEDIA548_F20E_F20J_X30J_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J
        L1547_puc_Block += 16; /* Address of the bitmap in the block */
#endif
#ifdef MEDIA508_F20E_F20J_X30J_P20JA_P20JB
        F0466_EXPAND_GraphicToBitmap((unsigned char*)L1548_puc_Graphic, (unsigned char*)L1547_puc_Block, 0, 0);
#endif
#ifdef MEDIA720_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        F0466_EXPAND_GraphicToBitmap((unsigned char*)L1548_puc_Graphic, (unsigned char*)L1547_puc_Block);
#endif
        return L1547_puc_Block;
}

void F0490_MEMORY_LoadDecompressAndExpandGraphic(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0900_i_GraphicIndex, P0901_puc_Bitmap, P0902_i_DestinationX, P0903_i_DestinationY)
#endif
REGISTER int16_t             P0900_i_GraphicIndex SEPARATOR
#ifdef MEDIA020_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB
REGISTER unsigned char HUGE* P0901_puc_Bitmap     SEPARATOR
#endif
#ifdef MEDIA720_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
REGISTER unsigned char HUGE* P0901_puc_Bitmap     FINAL_SEPARATOR
#endif
#ifdef MEDIA020_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB
int16_t                      P0902_i_DestinationX SEPARATOR
int16_t                      P0903_i_DestinationY FINAL_SEPARATOR
#endif
{
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        REGISTER unsigned char* L1550_puc_LZWTemporaryBuffer;
#endif
        REGISTER BOOLEAN L1549_B_DoNotExpand;
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        REGISTER BOOLEAN L3011_B_DoNotCopyDimensions;
#endif


#ifdef MEDIA505_F20E_F20J_P20JB_I34E_I34M_F31E_F31J_P31J
        F0739_MUSIC_Stop();
#endif
        F0477_MEMORY_OpenGraphicsDat_CPSDF();
        L1549_B_DoNotExpand = M007_GET(P0900_i_GraphicIndex, MASK0x8000_NOT_EXPANDED);
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        M009_CLEAR(P0900_i_GraphicIndex, MASK0x8000_NOT_EXPANDED);
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        L3011_B_DoNotCopyDimensions = M007_GET(P0900_i_GraphicIndex, MASK0x4000_DO_NOT_COPY_DIMENSIONS);
        M009_CLEAR(P0900_i_GraphicIndex, MASK0x8000_NOT_EXPANDED | MASK0x4000_DO_NOT_COPY_DIMENSIONS);
#endif
#ifdef MEDIA007_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E
        if (G0634_pui_GraphicCompressedByteCount[P0900_i_GraphicIndex] != G0635_pui_GraphicDecompressedByteCount[P0900_i_GraphicIndex]) {
                L1550_puc_LZWTemporaryBuffer = F0468_MEMORY_Allocate(C5004L_LZW_TEMPORARY_BUFFER_BYTE_COUNT, C0_ALLOCATION_TEMPORARY_ON_TOP_OF_HEAP);
                Fseek(F0467_MEMORY_GetGraphicOffset(P0900_i_GraphicIndex), G0630_i_GraphicsDatFileHandle, C0_SEEK_FROM_BEGINNING_OF_FILE) >= 0; /* Result of fseek is ignored */
                F0497_LZW_Decompress(G0630_i_GraphicsDatFileHandle, (long)G0634_pui_GraphicCompressedByteCount[P0900_i_GraphicIndex], P0901_puc_Bitmap, G0296_puc_Bitmap_Viewport, L1550_puc_LZWTemporaryBuffer);
                G0297_B_DrawFloorAndCeilingRequested = C1_TRUE;
                F0469_MEMORY_FreeAtHeapTop(C5004L_LZW_TEMPORARY_BUFFER_BYTE_COUNT);
                if (!L1549_B_DoNotExpand) {
                        F0007_MAIN_CopyBytes(P0901_puc_Bitmap, G0296_puc_Bitmap_Viewport, G0635_pui_GraphicDecompressedByteCount[P0900_i_GraphicIndex]);
                }
        } else {
#endif
                F0474_MEMORY_LoadGraphic_CPSDF(P0900_i_GraphicIndex, L1549_B_DoNotExpand ? P0901_puc_Bitmap : G0296_puc_Bitmap_Viewport); /* G0296_puc_Bitmap_Viewport is used as a temporary buffer to store the graphic data and expand it to P0901_puc_Bitmap */
#ifdef MEDIA007_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E
        }
#endif
        if (!L1549_B_DoNotExpand) {
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                if (!L3011_B_DoNotCopyDimensions) {
                        *((long*)(P0901_puc_Bitmap - 4)) = *((long*)G0296_puc_Bitmap_Viewport);
                }
#endif
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
                F0466_EXPAND_GraphicToBitmap(G0296_puc_Bitmap_Viewport, P0901_puc_Bitmap, P0902_i_DestinationX, P0903_i_DestinationY);
#endif
#ifdef MEDIA508_F20E_F20J_X30J_P20JA_P20JB
                F0466_EXPAND_GraphicToBitmap(G0296_puc_Bitmap_Viewport, (unsigned char*)P0901_puc_Bitmap, P0902_i_DestinationX, P0903_i_DestinationY);
#endif
#ifdef MEDIA720_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
                F0466_EXPAND_GraphicToBitmap(G0296_puc_Bitmap_Viewport, (unsigned char*)P0901_puc_Bitmap);
#endif
                G0297_B_DrawFloorAndCeilingRequested = C1_TRUE;
        }
        F0478_MEMORY_CloseGraphicsDat_CPSDF();
}

/* If the specified derived bitmap is already in the cache, its reference count is incremented and the function returns C1_TRUE else a block is allocated for the derived bitmap and the function returns C0_FALSE */
BOOLEAN F0491_CACHE_IsDerivedBitmapInCache(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0904_i_DerivedBitmapIndex)
#endif
REGISTER int16_t P0904_i_DerivedBitmapIndex FINAL_SEPARATOR
{
        REGISTER unsigned int16_t L1551_ui_BlockIndex;
        REGISTER unsigned char HUGE* L1553_puc_Block;
        REGISTER unsigned long L1552_ul_ByteCount;


        if (G0313_ul_GameTime != G0662_l_LastResetCacheUsageCountsTime) {
                F0485_CACHE_ResetUsageCounts();
        }
        if ((L1551_ui_BlockIndex = G0638_pui_DerivedBitmapBlockIndices[P0904_i_DerivedBitmapIndex]) != 0xFFFF) {
                F0487_CACHE_GetBlockAndIncrementUsageCount(L1551_ui_BlockIndex);
                return C1_TRUE;
        }
        L1552_ul_ByteCount = M574_BITMAP_OVERHEAD + G0639_DerivedBitmapByteCount[P0904_i_DerivedBitmapIndex]; /* Each block contains 16 bytes of data in addition to the bitmap itself */
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        if (L1552_ul_ByteCount & 0x00000001) { /* Make sure size is even */
                L1552_ul_ByteCount++;
        }
#endif
        L1553_puc_Block = F0483_CACHE_GetNewBlock(L1552_ul_ByteCount);
        L1551_ui_BlockIndex = 0;
        while (G0655_ppuc_Blocks[L1551_ui_BlockIndex++] != NULL);
#ifdef MEDIA055_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J
        G0638_pui_DerivedBitmapBlockIndices[P0904_i_DerivedBitmapIndex] = --L1551_ui_BlockIndex;
#endif
#ifdef MEDIA463_P20JA_P20JB_I34E_I34M_P31J
        L1551_ui_BlockIndex--;
        G0638_pui_DerivedBitmapBlockIndices[P0904_i_DerivedBitmapIndex] = L1551_ui_BlockIndex;
#endif
        G0655_ppuc_Blocks[L1551_ui_BlockIndex] = L1553_puc_Block;
        M084_USED_BLOCK_BITMAP_INDEX(L1553_puc_Block) = P0904_i_DerivedBitmapIndex | MASK0x8000_DERIVED_BITMAP;
        return C0_FALSE;
}

unsigned char* F0492_CACHE_GetDerivedBitmap(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0905_i_DerivedBitmapIndex)
#endif
int16_t P0905_i_DerivedBitmapIndex FINAL_SEPARATOR
{
        return M085_USED_BLOCK_BITMAP(G0655_ppuc_Blocks[G0638_pui_DerivedBitmapBlockIndices[P0905_i_DerivedBitmapIndex]]);
}

void F0493_CACHE_AddDerivedBitmap(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0906_i_DerivedBitmapIndex)
#endif
int16_t P0906_i_DerivedBitmapIndex FINAL_SEPARATOR
{
        F0486_MEMORY_AddBlockToUsedList(G0638_pui_DerivedBitmapBlockIndices[P0906_i_DerivedBitmapIndex]);
}

#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
void F0615_CopyBitmapDimensions(
unsigned char HUGE* P2046_puc_ SEPARATOR
unsigned char HUGE* P2047_puc_ FINAL_SEPARATOR
{
        F0007_MAIN_CopyBytes((char*)(P2046_puc_ - 4), (char*)(P2047_puc_ - 4), 4L);
}

void F0616_CopyBitmap(
unsigned char HUGE* P2048_puc_SourceBitmap      SEPARATOR
unsigned char HUGE* P2049_puc_DestinationBitmap FINAL_SEPARATOR
{
        F0007_MAIN_CopyBytes((char*)(P2048_puc_SourceBitmap - 4), (char*)(P2049_puc_DestinationBitmap - 4), (long)(M103_BITMAP_BYTE_COUNT(M100_PIXEL_WIDTH(P2048_puc_SourceBitmap), M101_PIXEL_HEIGHT(P2048_puc_SourceBitmap)) + 4));
}
#endif

unsigned int16_t F0494_MEMORY_GetGraphicDecompressedByteCount(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0907_i_GraphicIndex)
#endif
int16_t P0907_i_GraphicIndex FINAL_SEPARATOR
{
        return G0635_pui_GraphicDecompressedByteCount[M736_F0608_GetLanguageSpecificGraphicIndex(P0907_i_GraphicIndex)];
}

#ifdef MEDIA593_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
long F0440_STARTEND_GetTemporarilyLoadedGraphicByteCount(
int16_t         P0850_i_GraphicIndex SEPARATOR
#ifdef MEDIA580_X30J_P20JA_P20JB_A31E_A31M_A33M_F31E_F31J_X31J_P31J
unsigned char** P0851_ppuc_Graphic   FINAL_SEPARATOR
#endif
#ifdef MEDIA728_I34E_I34M_A36M_A35E_A35M
unsigned char** P0851_ppuc_Graphic   SEPARATOR
int16_t         P2050_i_Requirements FINAL_SEPARATOR
#endif
{
        long L1401_l_GraphicDecompressedByteCount;


#ifdef MEDIA579_X30J_P20JA_P20JB
        F0490_MEMORY_LoadDecompressAndExpandGraphic(P0850_i_GraphicIndex | (MASK0x8000_NOT_EXPANDED | MASK0x4000_DO_NOT_COPY_DIMENSIONS), *P0851_ppuc_Graphic = M533_F0468_MEMORY_Allocate(L1401_l_GraphicDecompressedByteCount = F0494_MEMORY_GetGraphicDecompressedByteCount(P0850_i_GraphicIndex), C0_ALLOCATION_TEMPORARY_ON_TOP_OF_HEAP, P2050_i_Requirements), 0, 0);
#endif
#ifdef MEDIA720_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        F0490_MEMORY_LoadDecompressAndExpandGraphic(P0850_i_GraphicIndex | (MASK0x8000_NOT_EXPANDED | MASK0x4000_DO_NOT_COPY_DIMENSIONS), *P0851_ppuc_Graphic = M533_F0468_MEMORY_Allocate(L1401_l_GraphicDecompressedByteCount = F0494_MEMORY_GetGraphicDecompressedByteCount(P0850_i_GraphicIndex), C0_ALLOCATION_TEMPORARY_ON_TOP_OF_HEAP, P2050_i_Requirements));
#endif
        return L1401_l_GraphicDecompressedByteCount;
}
#endif

#ifdef MEDIA720_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
unsigned char* F0763_LoadEndgameBitmapExpanded(
REGISTER int16_t P2051_i_GraphicIndex FINAL_SEPARATOR
{
        REGISTER unsigned char* L3012_puc_;


        L3012_puc_ = F0606_AllocateMemForGraphic(G2005_GraphicWidthHeight[P2051_i_GraphicIndex].Width, G2005_GraphicWidthHeight[P2051_i_GraphicIndex].Height, C0_ALLOCATION_TEMPORARY_ON_TOP_OF_HEAP);
        F0490_MEMORY_LoadDecompressAndExpandGraphic(P2051_i_GraphicIndex, L3012_puc_);
        return L3012_puc_;
}
#endif

#ifdef MEDIA722_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_X31J_P31J
void F0617_PrintMemoryUsage(
int16_t P2052_i_Character FINAL_SEPARATOR
{
#ifdef MEDIA728_I34E_I34M_A36M_A35E_A35M
        char L3013_ac_DebugString[10];
#endif


        if (G2006_[G2066_++] != F0711_ConvertScanCodeToASCII(P2052_i_Character)) {
                G2066_ = 0;
        } else {
                if (!G2006_[G2066_]) {
                        F0047_TEXT_MESSAGEAREA_PrintMessage(C15_COLOR_WHITE, "\nDM: ");
#ifdef MEDIA624_A31E_A31M_A33M_X31J_P31J
                        F0647_PrintLongForDebugMemory(C15_COLOR_WHITE, G0648_l_AvailableHeapMemoryByteCount);
                        F0647_PrintLongForDebugMemory(C15_COLOR_WHITE, G0656_l_AvailableCacheMemoryByteCount);
#endif
#ifdef MEDIA620_A31E_A31M_A33M
                        F0647_PrintLongForDebugMemory(C15_COLOR_WHITE, G1148_l_MemorySize);
#endif
#ifdef MEDIA624_A31E_A31M_A33M_X31J_P31J
                        F0647_PrintLongForDebugMemory(C15_COLOR_WHITE, G2231_l_ByteCount);
                        F0647_PrintLongForDebugMemory(C15_COLOR_WHITE, G0661_B_LargeHeapMemory);
#endif
#ifdef MEDIA620_A31E_A31M_A33M
                        F0647_PrintLongForDebugMemory(C15_COLOR_WHITE, (unsigned int16_t)G0654_B_GraphicMemoryInitialized);
#endif
#ifdef MEDIA707_I34E_I34M
                        F0647_PrintLongForDebugMemory(C15_COLOR_WHITE, G2166_l_BaseMemorySize);
                        F0647_PrintLongForDebugMemory(C15_COLOR_WHITE, G2169_l_EMSMemorySize);
#endif
                        F0647_PrintLongForDebugMemory(C15_COLOR_WHITE, G2173_l_AvailableCacheMemoryByteCountAfterLoadingGraphics);
#ifdef MEDIA728_I34E_I34M_A36M_A35E_A35M
                        M547_STRCPY(L3013_ac_DebugString, "------ ");
                        if (G2040_auc_MemoryFlags[C0_MEM_]) {
                                L3013_ac_DebugString[0] = 'G';
                        }
                        if (G2040_auc_MemoryFlags[C1_MEM_FLIPPED_WALS]) {
                                L3013_ac_DebugString[1] = 'W';
                        }
                        if (G2040_auc_MemoryFlags[C2_MEM_UNUSED]) {
                                L3013_ac_DebugString[2] = 'F';
                        }
                        if (G2040_auc_MemoryFlags[C3_MEM_BASE_SOUNDS]) {
                                L3013_ac_DebugString[3] = 'S';
                        }
                        if (G2040_auc_MemoryFlags[C4_MEM_ATTACK_SOUNDS]) {
                                L3013_ac_DebugString[4] = 'A';
                        }
                        if (G2040_auc_MemoryFlags[C5_MEM_MOVEMENT_SOUNDS]) {
                                L3013_ac_DebugString[5] = 'M';
                        }
                        F0047_TEXT_MESSAGEAREA_PrintMessage(C15_COLOR_WHITE, L3013_ac_DebugString);
#endif
#ifdef MEDIA746_A36M_A31E_A31M_A33M_A35E_A35M
                        F0047_TEXT_MESSAGEAREA_PrintMessage(C15_COLOR_WHITE, "\nAM: ");
                        F0647_PrintLongForDebugMemory(C15_COLOR_WHITE, AvailMem(MEMF_CHIP));
                        F0647_PrintLongForDebugMemory(C15_COLOR_WHITE, AvailMem(MEMF_FAST));
                        F0647_PrintLongForDebugMemory(C15_COLOR_WHITE, AvailMem(MEMF_CHIP | MEMF_LARGEST));
                        F0647_PrintLongForDebugMemory(C15_COLOR_WHITE, AvailMem(MEMF_FAST | MEMF_LARGEST));
                        F0647_PrintLongForDebugMemory(C15_COLOR_WHITE, G3167_l_ChipMemoryBlock1ByteCount);
                        F0647_PrintLongForDebugMemory(C15_COLOR_WHITE, G3168_l_FastMemoryBlockByteCount);
                        F0047_TEXT_MESSAGEAREA_PrintMessage(C15_COLOR_WHITE, "\nAM: ");
#ifdef MEDIA758_A36M_A35E_A35M
                        F0647_PrintLongForDebugMemory(C15_COLOR_WHITE, (long)G3251_l_ChipMemoryBlock2ByteCount);
#endif
                        F0647_PrintLongForDebugMemory(C15_COLOR_WHITE, (long)G3169_puc_ChipMemoryBlock1Bottom);
#ifdef MEDIA758_A36M_A35E_A35M
                        F0647_PrintLongForDebugMemory(C15_COLOR_WHITE, (long)G3250_puc_ChipMemoryBlock2Bottom);
#endif
                        F0647_PrintLongForDebugMemory(C15_COLOR_WHITE, (long)G3170_puc_FastMemoryBlockBottom);
                        F0647_PrintLongForDebugMemory(C15_COLOR_WHITE, (long)G3165_ps_CurrentTask);
#endif
                        G2066_ = 0;
                }
        }
}
#endif
#endif
