#ifndef COMPILE_H
#include "COMPILE.H"
#endif
#ifdef MEDIA016_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_P20JA_P20JB_I34E_I34M_F31E_F31J_P31J
#ifdef MEDIA413_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
long G1014_l_AvailableFastMemoryByteCount;
unsigned char* G1015_puc_AllocatedFastMemory;
#endif

#ifdef MEDIA007_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E
overlay "start"
#endif
#ifdef MEDIA351_G14ED_G20E_G21E
segment "gsthings"
#endif


#ifdef MEDIA349_G14ED
long F2231_(
P6093_)
unsigned long P6093_ FINAL_SEPARATOR
{
        if (P6093_ == -1L) {
                CompactMem();
                return MaxBlock();
        } else {
                return (long)*NewHandle(P6093_, _ownerid, attrLocked | attrFixed, NULL);
        }
}
#endif

#ifdef MEDIA551_F20E_F20J_F31E_F31J
long F2242_MEM_AVAIL(
void
)
{
        unsigned long L6495_;
        unsigned long L6494_;
        unsigned char* L6493_;


        L6495_ = 0;
        L6494_ = 400000;
        while (L6494_ > 1000) {
                if ((L6493_ = malloc(L6495_ + L6494_)) != NULL) {
                        free(L6493_);
                        L6495_ = L6495_ + L6494_;
                        continue;
                }
                L6494_ >>= 1;
        }
        return L6495_ & 0xFFFFFFFE;
}
#endif

#ifdef MEDIA670_F31E_F31J
unsigned char* F2243_CallMalloc(
long P6104_ FINAL_SEPARATOR
{
        return malloc(P6104_);
}

void F2244_CallFree(
unsigned char* P6105_ FINAL_SEPARATOR
{
        free(P6105_);
}
#endif

void F0448_STARTUP1_InitializeMemoryManager_CPSADEF(
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
void
#endif
)
{
#ifdef MEDIA007_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E
        REGISTER long L1437_l_AvailableHeapMemoryByteCount;
        REGISTER long L1438_l_AvailableGEMMemoryBottom;
        REGISTER long L1439_l_AvailableGEMMemoryByteCount;
#ifdef MEDIA006_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB /* CHANGE7_05_OPTIMIZATION */
#ifndef NOCOPYPROTECTION
        REGISTER BOOLEAN L1441_B_CommandLineParameterIsAUTO_CPSA;
#endif
#endif
#ifdef MEDIA006_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB /* CHANGE7_14_FIX Useless code removed */
        REGISTER char* L1442_pc_HeapMemoryBottom_Useless; /* BUG0_00 Useless code */
#endif
#ifdef MEDIA006_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB /* CHANGE7_08_OPTIMIZATION Variable definition changed */
        REGISTER char* L1443_pc_SupervisorStack;
#endif
#ifdef MEDIA006_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB /* CHANGE7_05_OPTIMIZATION */
#ifndef NOCOPYPROTECTION
        char L1444_ac_CommandLineParameters_CPSA[130];
#endif
#endif
#ifdef MEDIA265_S20E_S21E /* CHANGE7_08_OPTIMIZATION Variable definition changed */
        REGISTER long L1440_l_SupervisorStack;
#endif


        Cconws("\33f"); /* VT-52 command to hide the cursor. 33 (octal) = 1B (hexadecimal) = 27 (decimal) = ESC (Megamax C does not support hexadecimal character constants) */
#ifdef MEDIA006_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB /* CHANGE7_05_OPTIMIZATION */
        Supexec(S0059_TOS_SetException257Vector_CriticalError);
#ifndef NOCOPYPROTECTION
        F0458_START_GetCommandLineParameters_CPSA(L1444_ac_CommandLineParameters_CPSA);
#endif
#endif
        L1437_l_AvailableHeapMemoryByteCount = Malloc(-1L) - 20;
#ifdef MEDIA006_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB /* CHANGE7_08_OPTIMIZATION */
        L1443_pc_SupervisorStack = (char*)Super(0L);
#endif
#ifdef MEDIA265_S20E_S21E /* CHANGE7_08_OPTIMIZATION */
        L1440_l_SupervisorStack = Super(0L);
#endif
        asm {
                movea.l C0x04F2_ADDRESS_SYSTEM_VARIABLE__sysbase,A1     /* Address of the OSHEADER BIOS structure */
                move.l  12(A1),L1438_l_AvailableGEMMemoryBottom         /* os_end. Address of the first byte not used by the OS (BIOS/GEMDOS/VDI) */
                movea.l 20(A1),A0                                       /* os_magic. Address of the GEM_MUPB structure (GEM memory-usage parameter block) */
                move.l  4(A0),L1439_l_AvailableGEMMemoryByteCount       /* gm_end. Address of the end of the memory required by GEM (from the GEM_MUPB) */
        }
        L1439_l_AvailableGEMMemoryByteCount -= L1438_l_AvailableGEMMemoryBottom;
#ifdef MEDIA006_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB /* CHANGE7_08_OPTIMIZATION */
        Super(L1443_pc_SupervisorStack);
#endif
#ifdef MEDIA006_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB /* CHANGE7_14_FIX Useless code removed */
        F0475_MEMORY_Initialize(L1442_pc_HeapMemoryBottom_Useless = (char*)Malloc(L1437_l_AvailableHeapMemoryByteCount), L1437_l_AvailableHeapMemoryByteCount, L1438_l_AvailableGEMMemoryBottom, L1439_l_AvailableGEMMemoryByteCount); /* BUG0_00 Useless code */
#endif
#ifdef MEDIA265_S20E_S21E /* CHANGE7_08_OPTIMIZATION */
        Super(L1440_l_SupervisorStack);
#endif
#ifdef MEDIA265_S20E_S21E /* CHANGE7_14_FIX Useless code removed */
        F0475_MEMORY_Initialize(Malloc(L1437_l_AvailableHeapMemoryByteCount), L1437_l_AvailableHeapMemoryByteCount, L1438_l_AvailableGEMMemoryBottom, L1439_l_AvailableGEMMemoryByteCount);
#endif
#ifdef MEDIA006_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB /* CHANGE7_05_OPTIMIZATION */
#ifndef NOCOPYPROTECTION
        L1441_B_CommandLineParameterIsAUTO_CPSA = (L1444_ac_CommandLineParameters_CPSA[0] == 'A') && (L1444_ac_CommandLineParameters_CPSA[1] == 'U') && (L1444_ac_CommandLineParameters_CPSA[2] == 'T') && (L1444_ac_CommandLineParameters_CPSA[3] == 'O');
#endif
        F0479_MEMORY_ReadGraphicsDatHeader();
        F0460_START_InitializeGraphicData();
#ifndef NOCOPYPROTECTION
        F0447_STARTEND_HangIfFalse_CPSA(L1441_B_CommandLineParameterIsAUTO_CPSA);
#endif
        F0437_STARTEND_DrawTitle();
        F0094_DUNGEONVIEW_LoadFloorSet(C0_FLOOR_SET_STONE);
        F0095_DUNGEONVIEW_LoadWallSet(C0_WALL_SET_STONE);
#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
        F0054_TEXT_Initialize();
        F0031_OBJECT_LoadNames();
        F0007_MAIN_CopyBytes(G0021_aaui_Graphic562_Palette_DungeonView[0], G0346_aui_Palette_MiddleScreen, sizeof(G0346_aui_Palette_MiddleScreen));
        F0007_MAIN_CopyBytes(G0021_aaui_Graphic562_Palette_DungeonView[0], G0347_aui_Palette_TopAndBottomScreen, sizeof(G0347_aui_Palette_TopAndBottomScreen));
#ifndef NOCOPYPROTECTION
        G0626_pfv_S0080_CPSDF_CheckDMATransferCompletion = F0211_CPSDF_GetSubroutineAbsoluteAddress(S0080_CPSDF_CheckDMATransferCompletion);
        G0627_pfv_S0081_CPSDF_TurnOffFloppyDrive = F0211_CPSDF_GetSubroutineAbsoluteAddress(S0081_CPSDF_TurnOffFloppyDrive);
#endif
        F0066_MOUSE_Initialize();
        Supexec(F0018_MAIN_SetExceptionVectors);
        Jdisint(C05_INTERRUPT_TIMER_C);
        F0062_SOUND_Initialize();
        M526_WaitVerticalBlank();
        F0441_STARTEND_ProcessEntrance();
        while (F0435_STARTEND_LoadGame() != C01_LOAD_GAME_SUCCESS) {
                F0477_MEMORY_OpenGraphicsDat_CPSDF();
                F0441_STARTEND_ProcessEntrance();
        }
        F0477_MEMORY_OpenGraphicsDat_CPSDF();
        F0396_MENUS_LoadSpellAreaLinesBitmap();
        F0476_MEMORY_InitializeGraphicMemory();
        F0462_START_StartGame_CPSEF();
        F0478_MEMORY_CloseGraphicsDat_CPSDF();
        if (G0298_B_NewGame) {
                F0267_MOVE_GetMoveResult_CPSCE(C0xFFFF_THING_PARTY, CM1_MAPX_NOT_ON_A_SQUARE, 0, G0306_i_PartyMapX, G0307_i_PartyMapY);
        }
        F0078_MOUSE_DisableScreenUpdate();
        F0357_COMMAND_DiscardAllInput();
#endif
#endif
#ifdef MEDIA351_G14ED_G20E_G21E
        long L6373_;
        unsigned long L6374_;
#ifdef MEDIA349_G14ED
        int16_t L6443_i_Unreferenced;
#endif


#ifdef MEDIA349_G14ED
        SchStartUp();
        L6373_ = F2231_(-1L) - 65536;
        L6374_ = F2231_(L6373_);
#endif
#ifdef MEDIA388_G20E_G21E
        F2179_InitializeGraphicData();
        _ownerid = MMStartUp();
        CompactMem();
#ifdef MEDIA387_G20E
        if ((L6373_ = MaxBlock() - 65536) <= 0) { /* Bug: G20E fails to load the game dungeon ("Dungeon Master fatal error ->002C" = C44_ERROR_NOT_ENOUGH_CACHE_MEMORY_AFTER_LOADING_GRAPHICS) on Apple IIGS with ROM03 and no memory expansion. The Kid Dungeon loads fine. */
#endif
#ifdef MEDIA409_G21E
        if ((L6373_ = MaxBlock() - 16384) <= 0) { /* Fix: G21E works on Apple IIGS with ROM03 and no memory expansion */
#endif
                F2165_PrintErrorMessage(0, "Not enough free RAM for Dungeon Master   ");
        }
        L6374_ = (unsigned long)*NewHandle(L6373_, _ownerid, attrLocked | attrFixed, NULL);
#endif
        if ((int16_t)L6374_ & 1) {
                L6374_++;
                L6373_--;
        }
        if (L6373_ & 1) {
                L6373_--;
        }
        F0475_MEMORY_Initialize(L6374_, L6373_, NULL, NULL);
        G3979_puc_ = F0468_MEMORY_Allocate((long)0x8000, C1_ALLOCATION_PERMANENT);
#ifdef MEDIA349_G14ED
        F2179_InitializeGraphicData();
#endif
        F2175_();
        F2173_();
#ifdef MEDIA349_G14ED
        F2226_F2173_sub();
#endif
        G3952_puc_ = GetAddr(6);
        G3953_i_SoundVolumeLevel = *G3952_puc_ & 0x0F;
        *G3952_puc_ = 0x0F;
        asm {
                LDA        #0
                PHA
                PHA
                PHA
                PHA
                LDX        #0xd03          /* ReadTimeHex */
                JSL        0xe10000
                PLA
                STA        G0349_ul_LastRandomNumber
                PLA
                STA        G0349_ul_LastRandomNumber+2
                PLA
                PLA
#ifdef MEDIA349_G14ED
                SEP        #0x30
                LDA        0x03F4       /* Change byte value to force the next reset to be a cold reset (if value at 0x03F4 is not equal to value at 0x03F3 XOR value 0xA5) */
                DEC        A
                STA        0x03F4
                REP        #0x30
#endif
        }
#endif
#ifdef MEDIA413_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        REGISTER int16_t L1652_i_Unreferenced;
#ifdef MEDIA448_A21E_A22E
        REGISTER long L1653_l_;
#endif
        struct Process* L1654_ps_Process;


        GfxBase = (struct GfxBase*)OpenLibrary("graphics.library", 0L);
        if (GfxBase == NULL) {
                Alert(0x80444D50, 0L);
                F0507_AMIGA_DeinitializeAndInfiniteLoop();
        }
        L1654_ps_Process = (struct Process*)FindTask(0L);
        L1654_ps_Process->pr_WindowPtr = -1;
        G0348_Bitmap_Screen = G0734_ps_AmigaData->ScreenBuffer;
        F0545_MOUSE_AllocateMemory();
        F0555_TEXT_AllocateMemory();
        F0557_SCROLLER_Initialize(&G1057_s_TextScroller, G1056_ps_MessageAreaNewRowBitMap);
        F0536_INPUT_Initialize();
        F0575_VerticalBlank_Initialize();
#ifndef NOCOPYPROTECTION
        F0567_COPYPROA_InitFloppyInterruptHandler_CPSX();
        F0571_COPYPROB_InitializeDiskChangeHandler_CPSX();
#endif
        F0508_AMIGA_BuildPaletteChangeCopperList(G1055_aui_Palette_Swoosh, G1055_aui_Palette_Swoosh);
        F0007_MAIN_CopyBytes(G0021_aaui_Graphic562_Palette_DungeonView[0], G0347_aui_Palette_TopAndBottomScreen, sizeof(G0347_aui_Palette_TopAndBottomScreen));
#ifndef NOCOPYPROTECTION
        M517_FuzzySectorReadingBuffer_CPSE = AllocMem((long)(1026), MEMF_CHIP);
        if (M517_FuzzySectorReadingBuffer_CPSE == NULL) {
                Alert(0x80444D51, 0L);
                F0507_AMIGA_DeinitializeAndInfiniteLoop();
        }
        G1053_ps_DiscResourceUnit_CPSX = G0734_ps_AmigaData->DiscResourceUnit;
        G1054_ps_DiskResource_CPSX = G0734_ps_AmigaData->DiskResource;
#endif
        G1018_l_AvailableChipMemoryByteCount = AvailMem(MEMF_LARGEST | MEMF_CHIP);
#ifdef MEDIA412_A20ED_A20E_A20F_A20G_A21E
        if (G0734_ps_AmigaData->NotEnoughRAM == C0_FALSE) {
                G1018_l_AvailableChipMemoryByteCount -= 2400;
        }
#endif
#ifdef MEDIA455_A22E_A22G
        if (G0734_ps_AmigaData->NotEnoughRAM == C0_FALSE); /* The test is bypassed with a nop. This was probably hacked directly in the executable file */
        ;
        AztecCDirective_asm
                nop
        AztecCDirective_endasm
        G1018_l_AvailableChipMemoryByteCount -= 12000; /* 12000 = 5 * 2400 */
#endif
        G1014_l_AvailableFastMemoryByteCount = AvailMem(MEMF_LARGEST | MEMF_FAST);
#ifdef MEDIA427_A20ED_A20E_A20F_A20G_A22G
        if (G1014_l_AvailableFastMemoryByteCount > 280000) {
                G1014_l_AvailableFastMemoryByteCount = 280000;
        } else {
                if (G1018_l_AvailableChipMemoryByteCount - 250000 > G1014_l_AvailableFastMemoryByteCount) {
                        G1014_l_AvailableFastMemoryByteCount = 0;
                }
        }
        if ((G1014_l_AvailableFastMemoryByteCount == 0) && (G1018_l_AvailableChipMemoryByteCount > 530000)) { /* 250000 + 280000 = 530000 */
                G1018_l_AvailableChipMemoryByteCount = 530000;
        }
#endif
#ifdef MEDIA448_A21E_A22E
        M009_CLEAR(G1018_l_AvailableChipMemoryByteCount, 1);
        M009_CLEAR(G1014_l_AvailableFastMemoryByteCount, 1);
        L1653_l_ = F0535_MEMORY_GetGraphicsDatFileSize() + 1;
        M009_CLEAR(L1653_l_, 1); /* Make sure size is even */
        if (G1014_l_AvailableFastMemoryByteCount > L1653_l_) {
                G1014_l_AvailableFastMemoryByteCount = L1653_l_;
        }
#endif
        G1019_puc_AvailableGEMMemoryBottom = NULL;
        G1020_l_AvailableGEMMemoryByteCount = 0;
        G1021_puc_AvailableChipMemoryBottom = AllocMem(G1018_l_AvailableChipMemoryByteCount, MEMF_CHIP);
        if (G1014_l_AvailableFastMemoryByteCount != 0) {
                G1015_puc_AllocatedFastMemory = AllocMem(G1014_l_AvailableFastMemoryByteCount, MEMF_FAST);
        } else {
                G1020_l_AvailableGEMMemoryByteCount = AvailMem(MEMF_LARGEST | MEMF_CHIP);
                G1020_l_AvailableGEMMemoryByteCount = 0;
        }
        if ((G1021_puc_AvailableChipMemoryBottom == NULL) || ((G1014_l_AvailableFastMemoryByteCount > 0) && (G1015_puc_AllocatedFastMemory == NULL))) {
                Alert(0x80444D52, 0L);
        }
        F0475_MEMORY_Initialize(G1021_puc_AvailableChipMemoryBottom, G1018_l_AvailableChipMemoryByteCount, G1019_puc_AvailableGEMMemoryBottom, G1020_l_AvailableGEMMemoryByteCount);
#endif
#ifdef MEDIA463_P20JA_P20JB_I34E_I34M_P31J
#ifdef MEDIA458_P20JA_P20JB
        unsigned char* L3033_puc_BaseMemoryBottom;
        long L3034_l_BaseMemorySize;


        L3034_l_BaseMemorySize = coreleft(); /* Get free RAM size */
        if ((L3033_puc_BaseMemoryBottom = farmalloc(L3034_l_BaseMemorySize)) == NULL) {
#endif
#ifdef MEDIA709_I34E_I34M_P31J
        G2166_l_BaseMemorySize = coreleft(); /* Get free RAM size */
        if ((G2165_puc_BaseMemoryBottom = farmalloc(G2166_l_BaseMemorySize)) == NULL) {
#endif
#ifdef MEDIA457_P20JA
                printf("can't alloc test memory\n");
#endif
#ifdef MEDIA459_P20JA_P20JB_P31J
                exit(0);
#endif
#ifdef MEDIA707_I34E_I34M
                _exit(0);
#endif
        }
#ifdef MEDIA458_P20JA_P20JB
        F0475_MEMORY_Initialize(L3033_puc_BaseMemoryBottom, L3034_l_BaseMemorySize, NULL, NULL);
#endif
#ifdef MEDIA667_P31J
        F0475_MEMORY_Initialize(G2165_puc_BaseMemoryBottom, G2166_l_BaseMemorySize, NULL, NULL);
#endif
#ifdef MEDIA707_I34E_I34M
        G2169_l_EMSMemorySize = F0748_Get_EMS_Memory(&G2168_puc_EMSMemoryBottom);
        F0475_MEMORY_Initialize(G2165_puc_BaseMemoryBottom, G2166_l_BaseMemorySize, G2168_puc_EMSMemoryBottom, G2169_l_EMSMemorySize, NULL);
#endif
        F0699_InitVideoInterrupt();
        F0713_InitIOInterrupt();
#ifdef MEDIA459_P20JA_P20JB_P31J
        F0642_AllocateFontMemory();
#endif
        G0349_ul_LastRandomNumber = 31459L * F0718_GetTime();
#ifdef MEDIA707_I34E_I34M
        F0642_AllocateFontMemory();
#endif
#endif
#ifdef MEDIA488_F20E_F20J
        unsigned char* L6498_;
        unsigned long L6497_;


        F2245_INIT_TOWNS();
        L6497_ = F2242_MEM_AVAIL() - 100000;
        if ((L6498_ = malloc(L6497_)) == NULL) {
                printf("can't alloc test memory\n");
                exit(0);
        }
        F0475_MEMORY_Initialize(L6498_, L6497_, 0, 0);
        F0642_AllocateFontMemory();
#endif
#ifdef MEDIA670_F31E_F31J
        G2166_l_BaseMemorySize = F2242_MEM_AVAIL();
        if ((G2165_puc_BaseMemoryBottom = F2243_CallMalloc(G2166_l_BaseMemorySize)) == NULL) {
                exit(0);
        }
        F0475_MEMORY_Initialize(G2165_puc_BaseMemoryBottom, G2166_l_BaseMemorySize, 0, 0);
        F0642_AllocateFontMemory();
        F2245_INIT_TOWNS();
#endif
}

#ifdef MEDIA413_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
unsigned int16_t* G0731_pui_Palette_FadeFrom;
unsigned int16_t G1016_aui_Palette_FadeTemporary[16];
unsigned int16_t* G1058_pui_Palette_MousePointer = G1131_aui_Palette_MousePointer;


void F0506_AMIGA_AllocateData(
)
{
        F0503_SOUND_LoadAll();
        F0517_MENUS_AllocateSpellAreaBitmaps();
        F0564_VIEWPORT_InitializeBitPlanes(G0296_puc_Bitmap_Viewport, G0348_Bitmap_Screen);
}

void F0507_AMIGA_DeinitializeAndInfiniteLoop(
)
{
        REGISTER int16_t L1681_i_Unreferenced;


#ifdef MEDIA410_A20ED
        F0559_SCROLLER_Deinitialize(&G1057_s_TextScroller);
        F0538_INPUT_Deinitialize();
        F0576_VerticalBlank_Deinitialize();
        F0518_FLOPPY_Deinitialize_CPSX();
        F0501_SOUND_Deinitialize();
        F0478_MEMORY_CloseGraphicsDat_CPSDF();
        F0556_TEXT_Deinitialize();
        F0546_MOUSE_Deinitialize();
#endif
        for (;;); /*_Infinite loop_*/
}

void F0508_AMIGA_BuildPaletteChangeCopperList(
P0940_pui_Palette_MiddleScreen, P0941_pui_Palette_TopAndBottomScreen) /* Build list of instructions for the copper to change the color palette while drawing the screen */
unsigned int16_t* P0940_pui_Palette_MiddleScreen       SEPARATOR
unsigned int16_t* P0941_pui_Palette_TopAndBottomScreen FINAL_SEPARATOR
{
        REGISTER int16_t L1682_i_ColorIndex;


        G0731_pui_Palette_FadeFrom = P0941_pui_Palette_TopAndBottomScreen;
        CINIT(G0734_ps_AmigaData->CopperList, 66L); /* 66 instructions maximum in copper list */
        for (L1682_i_ColorIndex = 0; L1682_i_ColorIndex < 16; L1682_i_ColorIndex++) {
                CMOVE(G0734_ps_AmigaData->CopperList, custom.color[L1682_i_ColorIndex], (long)P0941_pui_Palette_TopAndBottomScreen[L1682_i_ColorIndex]);
        }
        L1682_i_ColorIndex = 16;
        for (; L1682_i_ColorIndex < 32; L1682_i_ColorIndex++) {
                CMOVE(G0734_ps_AmigaData->CopperList, custom.color[L1682_i_ColorIndex], (long)G1058_pui_Palette_MousePointer[L1682_i_ColorIndex - 16]);
        }
        CWAIT(G0734_ps_AmigaData->CopperList, 31L, 0L); /* When 31 lines have been drawn (champion status boxes on top of the screen), change palette */
        for (L1682_i_ColorIndex = 0; L1682_i_ColorIndex < 16; L1682_i_ColorIndex++) {
                CMOVE(G0734_ps_AmigaData->CopperList, custom.color[L1682_i_ColorIndex], (long)P0940_pui_Palette_MiddleScreen[L1682_i_ColorIndex]);
        }
        CWAIT(G0734_ps_AmigaData->CopperList, 170L, 0L); /* When 170 lines have been drawn (dungeon viewport), change palette */
        for (L1682_i_ColorIndex = 0; L1682_i_ColorIndex < 16; L1682_i_ColorIndex++) {
                CMOVE(G0734_ps_AmigaData->CopperList, custom.color[L1682_i_ColorIndex], (long)P0941_pui_Palette_TopAndBottomScreen[L1682_i_ColorIndex]);
        }
        CEND(G0734_ps_AmigaData->CopperList);
        MrgCop(&G0734_ps_AmigaData->GameView);
}

#include "PALETTE.C"

void F0509_AMIGA_FillScreen(
P0942_ui_Color)
unsigned int16_t P0942_ui_Color FINAL_SEPARATOR
{
        SetRast(&G0734_ps_AmigaData->RastPort, (long)P0942_ui_Color);
        WaitBlit();
}

void F0510_AMIGA_WaitBottomOfViewPort(
)
{
        WaitBOVP(&G0734_ps_AmigaData->ViewPort);
}

void F0511_AMIGA_EmptyFunction(
)
{
}

#include "DECOMPDU.C"

#ifdef MEDIA448_A21E_A22E
BOOLEAN F0512_STARTUP1_IsAltKeyPressed(
)
{
        REGISTER int16_t L1683_i_Result;
        REGISTER long L1684_l_Unused;
        REGISTER int16_t L1685_i_Unreferenced;
        REGISTER int16_t L1686_i_Unreferenced;


        L1683_i_Result = C0_FALSE;
        G1144_s_IOStdReq = AllocMem((long)sizeof(struct IOStdReq), MEMF_CHIP | MEMF_CLEAR);
        if (G1144_s_IOStdReq == NULL) {
                Alert(0x80444D53, 0L);
        }
        G1145_ps_MsgPort = CreatePort(NULL, 0L);
        if (G1145_ps_MsgPort == NULL) {
                Alert(0x80444D54, 0L);
        }
        G1144_s_IOStdReq->io_Message.mn_ReplyPort = G1145_ps_MsgPort;
        if (L1684_l_Unused = OpenDevice("keyboard.device", 0L, G1144_s_IOStdReq, 0L)) {
                return 0;
        }
        G1144_s_IOStdReq->io_Command = KBD_READMATRIX;
        G1144_s_IOStdReq->io_Flags = IOF_QUICK;
        G1144_s_IOStdReq->io_Data = (APTR)G1146_ac_KeyboardMatrix;
        G1144_s_IOStdReq->io_Length = sizeof(G1146_ac_KeyboardMatrix); /* 13 bytes = 104 bits, one bit for each keyboard key */
        DoIO(G1144_s_IOStdReq);
        if ((G1146_ac_KeyboardMatrix[12] & 0x10) || (G1146_ac_KeyboardMatrix[12] & 0x20)) { /* Keycode 100 = Left Alt; Keycode 101 = Right Alt */
                L1683_i_Result = C1_TRUE;
        }
        CloseDevice(G1144_s_IOStdReq);
        if (G1144_s_IOStdReq != NULL) {
                FreeMem(G1144_s_IOStdReq, (long)sizeof(struct IOStdReq));
        }
        if (G1145_ps_MsgPort != NULL) {
                DeletePort(G1145_ps_MsgPort);
        }
        return L1683_i_Result;
}
#endif
#endif
#endif
