#ifndef COMPILE_H
#include "COMPILE.H"
#endif
#ifdef MEDIA676_F31E_F31J_X31J_P31J_AU1E_AU2E_AU3E
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
extern BACKUP_PORTRAIT G2328_s_TempPortrait;
extern BACKUP_PORTRAIT G2329_s_UndoPortrait;
extern unsigned char* G2243_OnScreenPortraitBitmaps[4];
#endif
#ifdef MEDIA768_AU2E_AU3E
extern CEDTAMISTRU G3918_;
#endif


#ifdef MEDIA670_F31E_F31J
unsigned char G0235_auc_Graphic559_ThingDataByteCount[16] = { 4, 6, 4, 8, 16, 4, 4, 4, 4, 8, 4, 0, 0, 0, 8, 4 };
unsigned char* G7117_Bitmap_Mirror;
unsigned char* G7116_Bitmap_FilePickerArrows;
int16_t G7114_LoadedChampionCount;
CMP G2246_CMPData;
long G7110_RandomSeed;
GAME* G7111_Games; /* Pointer to array of 2 structs of size 902 */
int16_t G7113_DialogBitmapIndex;
int16_t G7112_HideMousePointerCount;
unsigned char* G2244_apuc_DialogBitmaps[2];
long G7115_DialogByteCount;
BACKUP_PORTRAIT G2329_s_UndoPortrait;
BACKUP_PORTRAIT G2328_s_TempPortrait;
unsigned char* G2243_OnScreenPortraitBitmaps[4];
#endif
#ifdef MEDIA699_X31J_AU2E_AU3E
int16_t G7114_LoadedChampionCount;
GAME* G7111_Games; /* Pointer to array of 2 structs of size 902 */
CMP G2246_CMPData;
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
FILE_PICKER G4186_s_FilePicker = { 0, NULL, NULL, 0, 0, 0, { 0, 0, 0, 0 }, 0, 0, NULL, { NULL, NULL, NULL, NULL, NULL, NULL } };
int16_t G2301_Unreferenced = 0;
FILE_PICKER_FILENAME G4187_FilePickerFileName = { 0, { 0, 0, 0, 0 }, C0_FALSE };
#ifdef MEDIA671_F31E_F31J_P31J
char G2331_Unreferenced = 0; /* alignment ? already removed for X31J AU2E AU3E. Required for P31J. */
#endif
#endif


#include "CEDTINC4.C"

#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
int16_t F7073_(char P3740_c_, char* P3741_pc_, int16_t P3742_i_Color, char* P3743_pc_, INPUT_INFO* P3744_ps_, char* P3745_pc_, INPUT_INFO* P3746_ps_)
{
        int16_t L3995_i_;
        unsigned int16_t L3994_ui_;


        if (P3740_c_) {
                L3995_i_ = F7072_GetDialogChoiceOrdinal(P3741_pc_, P3742_i_Color | MASK0x8000_INVERT_BOX, P3743_pc_, P3744_ps_);
                if (L3995_i_ == 2) {
                        L3995_i_ = 3;
                }
        } else {
                L3995_i_ = F7072_GetDialogChoiceOrdinal(P3741_pc_, P3742_i_Color | MASK0x8000_INVERT_BOX, P3745_pc_, P3746_ps_);
        }
        for (L3994_ui_ = 0; L3994_ui_ < 5; L3994_ui_++) {
                F7323_WaitVerticalBlank();
        }
        F7071_();
        return L3995_i_;
}
#endif

#ifdef MEDIA762_AU1E
int16_t F7074_DrawDialogErrorMessage(char* P3747_pc_, unsigned int16_t P3748_ui_Color)
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
void F7074_DrawDialogErrorMessage(char* P3747_pc_, unsigned int16_t P3748_ui_Color)
#endif
{
#ifdef MEDIA762_AU1E
        return F7072_GetDialogChoiceOrdinal(P3747_pc_, P3748_ui_Color, G7060_OK, &G2263_s_Input_Dialog1Choice);
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
        unsigned int16_t L3996_i_;


        F7072_GetDialogChoiceOrdinal(P3747_pc_, P3748_ui_Color | MASK0x8000_INVERT_BOX, G7060_OK, &G2263_s_Input_Dialog1Choice);
        for (L3996_i_ = 0; L3996_i_ < 5; L3996_i_++) {
                F7323_WaitVerticalBlank();
        }
        if (!M007_GET(P3748_ui_Color, MASK0x8000_UNKNOWN)) {
                F7071_();
        }
#endif
}

#ifdef MEDIA762_AU1E
#include "CEDTINCJ.C"
#endif

#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
void F7075_(INPUT_INFO* P3749_ps_, unsigned int16_t P3750_i_)
{
        int16_t L3997_i_;


        F7248_InvertBox(P3749_ps_->MouseInput[P3750_i_ - 1].Box);
        for (L3997_i_ = 0; L3997_i_ < 50; L3997_i_++) {
                F7323_WaitVerticalBlank();
        }
}
#endif

#include "CEDTINC7.C"
#include "CEDTINC9.C"
#ifdef MEDIA762_AU1E
#include "CEDTINCC.C"
#endif
#include "CEDTINCF.C"

#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
int16_t F7083_DrawInitialFilePickerFileList(FILE_LIST* P3758_ps_)
{
        int16_t L4017_i_;
        REGISTER long L6032_l_Unreferenced;


        if (!(G4186_s_FilePicker.OnScreen & 1)) {
                L4017_i_ = -1;
        } else {
                G4186_s_FilePicker.FirstFileNameIndex = 0;
                G4186_s_FilePicker.FileList = P3758_ps_;
                F7081_SortFileNamesIfPossible();
                F7080_DrawFilePickerFileList();
                if (G4187_FilePickerFileName.InvertSelectedBoxRequested) {
                        F7248_InvertBox(G4187_FilePickerFileName.Box_Selected);
                        G4187_FilePickerFileName.InvertSelectedBoxRequested = C0_FALSE;
                }
                L4017_i_ = 0;
        }
        if (L4017_i_);
        return L4017_i_;
}

int16_t F7084_ProcessFilePickerInput(
)
{
        int16_t L4018_i_;
        REGISTER unsigned int16_t L4024_ui_;
        REGISTER int16_t L4019_i_FileCount;
        REGISTER int16_t L4025_i_;
        BOOLEAN L4020_B_ClickOnArrow;
        UD_COMMAND L4021_s_Command;
        int16_t L4022_i_MouseX;
        int16_t L4023_i_MouseY;


        if (!(G4186_s_FilePicker.OnScreen & 1)) {
                L4018_i_ = -1;
        } else {
                if (G4187_FilePickerFileName.InvertSelectedBoxRequested) {
                        F7248_InvertBox(G4187_FilePickerFileName.Box_Selected);
                        G4187_FilePickerFileName.InvertSelectedBoxRequested = C0_FALSE;
                }
                L4019_i_FileCount = G4186_s_FilePicker.FileList->FileCount;
                L4024_ui_ = 0;
                do {
                        if (!(M007_GET(F7274_GetMouseStatus(&L4022_i_MouseX, &L4023_i_MouseY), MASK0x0002_MOUSE_LEFT_BUTTON)) || ((L4024_ui_ >= C04_COMMAND_PICKER_UP_ARROW) && (F7006_IsPointInBox(G2285_as_FilePickerDialogButtons[L4024_ui_ - 1].Box, L4022_i_MouseX, L4023_i_MouseY) == 0))) {
                                if (L4024_ui_ >= C04_COMMAND_PICKER_UP_ARROW) {
                                        F7248_InvertBox(G4187_FilePickerFileName.Box_Selected);
                                        G4187_FilePickerFileName.InvertSelectedBoxRequested = C0_FALSE;
                                }
                                L4024_ui_ = 0;
                        }
                        F0078_MOUSE_DisableScreenUpdate();
                        loc_15BA2:
                        L4020_B_ClickOnArrow = (L4024_ui_ >= C04_COMMAND_PICKER_UP_ARROW);
                        if (!L4020_B_ClickOnArrow) {
                                do {
                                        L4024_ui_ = F7015_ProcessNextUDCommand(&L4021_s_Command);
                                } while (L4024_ui_ == 0);
                        }
                        F7317_MAIN_CopyBytes_Alt((char*)G2285_as_FilePickerDialogButtons[L4024_ui_ - 1].Box, (char*)G4187_FilePickerFileName.Box_Selected, MASK0x0400_MEMREQ, MASK0x0400_MEMREQ, 8L);
                        if (L4024_ui_ == C01_COMMAND_PICKER_FILE_LIST) {
                                L4025_i_ = (L4021_s_Command.Y - G4186_s_FilePicker.FileListTopOnScreen) / G7049_FilePickerFileListLineHeight;
                                if (L4025_i_ > G7048_FilePickerFileListVisibleFileNameCount - 1) {
                                        L4025_i_ = G7048_FilePickerFileListVisibleFileNameCount - 1;
                                }
                                if (L4025_i_ >= L4019_i_FileCount) {
                                        goto loc_15BA2;
                                }
                                M770_BOX_TOP(G4187_FilePickerFileName.Box_Selected) += (L4025_i_ * G7049_FilePickerFileListLineHeight);
                                M771_BOX_BOTTOM(G4187_FilePickerFileName.Box_Selected) = M770_BOX_TOP(G4187_FilePickerFileName.Box_Selected) + G7049_FilePickerFileListLineHeight;
                        }
                        if (!L4020_B_ClickOnArrow) {
                                F0077_MOUSE_EnableScreenUpdate_CPSE();
                                F7248_InvertBox(G4187_FilePickerFileName.Box_Selected);
                                G4187_FilePickerFileName.InvertSelectedBoxRequested = C1_TRUE;
                        }
                        if (L4024_ui_ >= C04_COMMAND_PICKER_UP_ARROW) {
                                if (((L4024_ui_ == C04_COMMAND_PICKER_UP_ARROW) && (G4186_s_FilePicker.FirstFileNameIndex > 0)) || ((L4024_ui_ == C05_COMMAND_PICKER_DOWN_ARROW) && (L4019_i_FileCount > G4186_s_FilePicker.FirstFileNameIndex + G7048_FilePickerFileListVisibleFileNameCount))) {
                                        if (L4024_ui_ == C04_COMMAND_PICKER_UP_ARROW) {
                                                G4186_s_FilePicker.FirstFileNameIndex--;
                                        } else {
                                                G4186_s_FilePicker.FirstFileNameIndex++;
                                        }
                                        F7323_WaitVerticalBlank();
                                        if (L4020_B_ClickOnArrow) {
                                                F0077_MOUSE_EnableScreenUpdate_CPSE();
                                        }
                                        F7080_DrawFilePickerFileList();
                                } else {
                                        if (L4020_B_ClickOnArrow) {
                                                F7323_WaitVerticalBlank();
                                                F0077_MOUSE_EnableScreenUpdate_CPSE();
                                        }
                                }
                        }
                } while (L4024_ui_ >= C04_COMMAND_PICKER_UP_ARROW);
                switch (L4024_ui_) {
                        case C01_COMMAND_PICKER_FILE_LIST:
                                L4024_ui_ = L4025_i_ + G4186_s_FilePicker.FirstFileNameIndex;
                                break;
                        case C02_COMMAND_PICKER_NEW_DISK:
                                L4024_ui_ = -1;
                                break;
                        case C03_COMMAND_PICKER_CANCEL:
                                L4024_ui_ = -2;
                }
                L4018_i_ = 0;
        }
        if (L4018_i_ < 0) {
                L4024_ui_ = -2;
        }
        if (G4186_s_FilePicker.FileList->pfv_08_z) {
                L4024_ui_ = (*G4186_s_FilePicker.FileList->pfv_08_z)(L4024_ui_, G4186_s_FilePicker.FileList);
        }
        return L4024_ui_;
}

int16_t F7085_(char P3759_c_)
{
        int16_t L4026_i_;


        if (!(G4186_s_FilePicker.OnScreen & 1)) {
                L4026_i_ = -1;
        } else {
                F7014_SetCurrentInputInfoList(G4186_s_FilePicker.InputInfo);
                L4026_i_ = 0;
        }
        if (G4187_FilePickerFileName.InvertSelectedBoxRequested) {
                F7248_InvertBox(G4187_FilePickerFileName.Box_Selected);
                G4187_FilePickerFileName.InvertSelectedBoxRequested = C0_FALSE;
        }
        if (P3759_c_) {
                F7071_();
        }
        if (G4186_s_FilePicker.FileListBitmap) {
                F7024_Free(G4186_s_FilePicker.FileListBitmap);
                G4186_s_FilePicker.FileListBitmap = NULL;
        }
        G4186_s_FilePicker.OnScreen = 0;
        if (L4026_i_);
        return L4026_i_;
}
#endif

#include "CEDTINCH.C"

#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
#include "CEDTINCR.C"
#endif

char F7089_GetFirstCellWithNoChampion(GAME* P3765_ps_)
{
        unsigned char L4035_ac_[4];
        unsigned int16_t L4036_ui_;
        unsigned int16_t L4037_i_;


        for (L4036_ui_ = 0; L4036_ui_ < 4; L4036_ui_++) {
                L4035_ac_[L4036_ui_] = 1;
        }
        for (L4036_ui_ = 0; L4036_ui_ < G7114_LoadedChampionCount; L4036_ui_++) {
                L4037_i_ = F7067_GetChampionInfo(P3765_ps_, L4036_ui_, C04_CHAMPION_INFO_CELL);
                L4035_ac_[L4037_i_] = 0;
        }
        for (L4036_ui_ = 0; L4036_ui_ < 4; L4036_ui_++) {
                if (L4035_ac_[L4036_ui_] == 1) {
                        break;
                }
        }
        return L4036_ui_;
}

#include "CEDTINCI.C"
#endif
