#ifndef COMPILE_H
#include "COMPILE.H"
#endif
#ifdef MEDIA678_F31E_F31J_X31J_P31J_SU1E_AU1E_AU2E_AU3E
char* F7069_CopyStringFirstLine(
#ifdef MEDIA773_SU1E_AU1E
register char* P3728_pc_ButtonTexts, register char* P3729_pc_TargetString, register char P3731_c_SeparatorCharacter)
{
        register char L3983_c_;
        unsigned char* L3984_puc_;


        while ((L3983_c_ = *P3728_pc_ButtonTexts++) != '\0') {
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
REGISTER unsigned char* P3728_pc_ButtonTexts, REGISTER unsigned char* P3729_pc_TargetString, int16_t P3730_i_TargetStringSize, REGISTER unsigned char P3731_c_SeparatorCharacter)
{
        REGISTER unsigned char L3983_c_;
        REGISTER unsigned char* L3984_puc_;


        while (L3983_c_ = *P3728_pc_ButtonTexts++) {
#endif
                if (L3983_c_ == P3731_c_SeparatorCharacter) {
                        goto loc_15256;
                }
#ifdef MEDIA773_SU1E_AU1E
                if (L3983_c_ == '@') {
                        L3984_puc_ = G3774_pc_SaveFloppyDriveName;
                        goto loc_4AA;
                } else {
                        if (L3983_c_ == '#') {
                                L3984_puc_ = G3775_pc_GameFloppyDriveName;
                                loc_4AA:
                                while (*P3729_pc_TargetString++ = *L3984_puc_++);
                                P3729_pc_TargetString--;
                        } else {
#endif
                                if (L3983_c_ == '$') {
                                        L3984_puc_ = G2246_CMPData.Name;
#ifdef MEDIA773_SU1E_AU1E
                                        goto loc_4AA;
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
                                        while (*P3729_pc_TargetString++ = *L3984_puc_++);
                                        P3729_pc_TargetString--;
#endif
                                } else {
                                        *P3729_pc_TargetString++ = L3983_c_;
                                }
#ifdef MEDIA773_SU1E_AU1E
                        }
                }
#endif
        }
        P3728_pc_ButtonTexts = NULL;
        loc_15256:
        *P3729_pc_TargetString = '\0';
        return M772_CAST_PC(P3728_pc_ButtonTexts);
}

void F7070_DrawDialogTitle(char* P3732_pc_, int16_t P3733_i_, int16_t P3734_i_, int16_t P3735_i_Color)
{
#ifdef MEDIA773_SU1E_AU1E
        char L3986_ac_[40];
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
        UDSTRUCT3 L3985_s_;
        char L3986_ac_[50];
#endif


        while (P3732_pc_) {
#ifdef MEDIA773_SU1E_AU1E
                P3732_pc_ = F7069_CopyStringFirstLine(P3732_pc_, L3986_ac_, '\n');
#ifdef MEDIA772_SU1E
                F7339_PrintTextToScreen(P3733_i_ - ((int16_t)F0090_strlen(L3986_ac_) * 6 >> 1), P3734_i_, P3735_i_Color, C12_COLOR_DARKEST_GRAY, L3986_ac_);
#endif
#ifdef MEDIA762_AU1E
                F7339_PrintTextToScreen(P3733_i_ - ((int16_t)(F0090_strlen(L3986_ac_) * 6) >> 1), P3734_i_, P3735_i_Color, C12_COLOR_DARKEST_GRAY, L3986_ac_);
#endif
                P3734_i_ += 13;
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
                P3732_pc_ = F7069_CopyStringFirstLine(M774_CAST_PUC(P3732_pc_), M774_CAST_PUC(L3986_ac_), 50, '\n');
                F7342_BuildUDSTRUCT3(L3986_ac_, &L3985_s_);
                if (F0090_strlen(L3986_ac_)) {
                        F7339_PrintTextToScreen(P3733_i_ - (L3985_s_.i_E >> 1), P3734_i_, P3735_i_Color, C12_COLOR_DARKEST_GRAY, L3986_ac_);
                }
                P3734_i_ += L3985_s_.i_8;
#endif
        }
}

void F7071_(
)
{
#ifdef MEDIA773_SU1E_AU1E
        if (G7113_DialogBitmapIndex) {
                G7113_DialogBitmapIndex = 0;
#endif
#ifdef MEDIA772_SU1E
                F0132_VIDEO_Blit(G3784_, G0348_Bitmap_Screen, G2256_ai_Box_FilePickerDialog, 0, 0, 104, C160_BYTE_WIDTH_SCREEN, CM1_COLOR_NO_TRANSPARENCY);
#endif
#ifdef MEDIA762_AU1E
                F0132_VIDEO_Blit(G3935_, G0348_Bitmap_Screen, G2256_ai_Box_FilePickerDialog, 0, 0, 208, 320, CM1_COLOR_NO_TRANSPARENCY, 102, 200);
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
        if (G7113_DialogBitmapIndex > 0) {
                G7113_DialogBitmapIndex--;
                F7255_(G2244_apuc_DialogBitmaps[G7113_DialogBitmapIndex], G2256_ai_Box_FilePickerDialog);
#endif
                if (G7112_HideMousePointerCount) {
                        G7112_HideMousePointerCount--;
                        F0078_MOUSE_DisableScreenUpdate();
                }
        }
}

int16_t F7072_GetDialogChoiceOrdinal(char* P3736_pc_, unsigned int16_t P3737_i_Color, char* P3738_pc_String, INPUT_INFO* P3739_ps_DialogInputInfo)
{
        REGISTER long L6030_l_Unreferenced;
        REGISTER MOUSE2_INPUT* L3987_ps_;
        REGISTER int16_t L3992_i_ChoiceOrdinal;
        REGISTER int16_t L3993_i_;
        REGISTER BOOLEAN L3988_B_InvertBox;
        INPUT_INFO** L3989_pps_BackupInputInfoList;
        INPUT_INFO* L3990_aps_DialogInputInfoList[6];
        char L3991_ac_[50];


#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
        L3989_pps_BackupInputInfoList = NULL;
#endif
        F0008_MAIN_ClearBytes(M772_CAST_PC(L3990_aps_DialogInputInfoList), (long)sizeof(L3990_aps_DialogInputInfoList));
        L3990_aps_DialogInputInfoList[0] = P3739_ps_DialogInputInfo;
        L3988_B_InvertBox = M007_GET(P3737_i_Color, MASK0x8000_INVERT_BOX);
        M727_CLEAR(P3737_i_Color, MASK0x8000_INVERT_BOX);
        if (G7112_HideMousePointerCount == 0) {
                G7112_HideMousePointerCount++;
                F0077_MOUSE_EnableScreenUpdate_CPSE();
        }
#ifdef MEDIA773_SU1E_AU1E
        if (G7113_DialogBitmapIndex == 0) {
                G7113_DialogBitmapIndex = 1;
#endif
#ifdef MEDIA772_SU1E
                F0132_VIDEO_Blit(G0348_Bitmap_Screen, G3784_, G2302_ai_Box_DialogDimensions, 62, 48, C160_BYTE_WIDTH_SCREEN, 104, CM1_COLOR_NO_TRANSPARENCY);
        }
#endif
#ifdef MEDIA762_AU1E
                F0132_VIDEO_Blit(G0348_Bitmap_Screen, G3935_, G2302_ai_Box_DialogDimensions, 62, 48, 320, 208, CM1_COLOR_NO_TRANSPARENCY, 200, 102);
        }
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
        if (G7113_DialogBitmapIndex < 2) {
                F7256_(M773_CAST_PI(G2244_apuc_DialogBitmaps[G7113_DialogBitmapIndex]), G2256_ai_Box_FilePickerDialog);
                G7113_DialogBitmapIndex++;
        }
#endif
        F7030_DrawFilledBox(G2256_ai_Box_FilePickerDialog, -2, C15_COLOR_WHITE, C12_COLOR_DARKEST_GRAY);
#ifdef MEDIA773_SU1E_AU1E
        F7070_DrawDialogTitle(P3736_pc_, 159, 65, P3737_i_Color);
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
        F7070_DrawDialogTitle(P3736_pc_, G7031_, G7032_, P3737_i_Color);
#endif
        if (P3739_ps_DialogInputInfo == NULL) {
#ifdef MEDIA773_SU1E_AU1E
                return; /* BUGX_XX No return value specified */
        }
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
                L3992_i_ChoiceOrdinal = 0;
        } else {
#endif
                L3993_i_ = 0;
                L3987_ps_ = P3739_ps_DialogInputInfo->MouseInput;
                while ((L3987_ps_->Command != 0) && P3738_pc_String) {
#ifdef MEDIA773_SU1E_AU1E
                        P3738_pc_String = F7069_CopyStringFirstLine(P3738_pc_String, L3991_ac_, '\n');
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
                        P3738_pc_String = F7069_CopyStringFirstLine(M774_CAST_PUC(P3738_pc_String), M774_CAST_PUC(L3991_ac_), 50, '\n');
#endif
                        F7034_DrawButton(L3987_ps_, L3991_ac_, C02_COLOR_LIGHT_GRAY);
                        L3993_i_++;
                        L3987_ps_++;
                }
                L3989_pps_BackupInputInfoList = F7014_SetCurrentInputInfoList(L3990_aps_DialogInputInfoList);
                F0078_MOUSE_DisableScreenUpdate();
                while ((L3992_i_ChoiceOrdinal = F7015_ProcessNextUDCommand(&G2257_Command)) == 0);
                F0077_MOUSE_EnableScreenUpdate_CPSE();
                if (L3988_B_InvertBox) {
                        if ((L3992_i_ChoiceOrdinal & 0xFF) <= L3993_i_) {
                                F7248_InvertBox(P3739_ps_DialogInputInfo->MouseInput[M001_ORDINAL_TO_INDEX(L3992_i_ChoiceOrdinal & 0xFF)].Box);
                        }
                } else {
                        F7071_();
                }
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
        }
        if (L3989_pps_BackupInputInfoList) {
#endif
                F7014_SetCurrentInputInfoList(L3989_pps_BackupInputInfoList);
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
        }
#endif
        return L3992_i_ChoiceOrdinal;
}
#endif
