#ifndef COMPILE_H
#include "COMPILE.H"
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
#ifdef MEDIA692_X31J
extern void F2081_();
#endif
#ifdef MEDIA699_X31J_AU2E_AU3E
extern void F1024_SetTrap14VectorErrorProcessing();
extern unsigned char F2087_();
extern void F2094_Call_DOS_FFLUSH();
extern void F2085_EjectFloppyDisk();
#endif

static int16_t F7308_Return0(int16_t P4098_i_);
static int16_t F7309_(FILE_DESCRIPTOR* P4099_ps_, FILE_DESCRIPTOR** P4100_pps_);
#ifdef MEDIA692_X31J
static int16_t F7313_GetDriveIndex(FILE_DESCRIPTOR* P4104_ps_, int16_t* P5956_);
#endif
#ifdef MEDIA671_F31E_F31J_P31J
static int16_t F7313_GetDriveIndex(FILE_DESCRIPTOR* P4104_ps_);
#endif
#ifdef MEDIA674_F31E_F31J_X31J_P31J
static int16_t F7311_(unsigned char* P4102_puc_);
static int16_t F7312_(int16_t P4103_i_);
#endif

#ifdef MEDIA692_X31J
char* G2282_[4] = {
        "A: ",
        "B: ",
        "C: ",
        NULL
};
#endif
#ifdef MEDIA671_F31E_F31J_P31J
char* G2282_[17] = {
        ".\\",
        "A:\\",
        "B:\\",
        "C:\\",
        "D:\\",
        "E:\\",
        "F:\\",
        "G:\\",
        "H:\\",
        "I:\\",
        "J:\\",
        "K:\\",
        "L:\\",
        "M:\\",
        "N:\\",
        "O:\\",
        NULL
};
#endif
#ifdef MEDIA674_F31E_F31J_X31J_P31J
UDSTRUCT7 G2298_[2] = {
        { 3, "CHAOS STRIKES BACK" },
        { 0, NULL } };
#endif
#ifdef MEDIA671_F31E_F31J_P31J
UDSTRUCT6 G2299_[18] = {
        { 0xFFFFFFFF, 0x63 },
        { 0xFFFFFFFE, 0x19 },
        { 0xFFFFFFFD, 0x02 },
        { 0xFFFFFFFC, 0x07 },
        { 0xFFFFFFFB, 0x1A },
        { 0xFFFFFFFA, 0x1A },
        { 0xFFFFFFF9, 0x15 },
        { 0xFFFFFFF8, 0x1A },
        { 0xFFFFFFF6, 0x08 },
        { 0xFFFFFFF5, 0x07 },
        { 0xFFFFFFF3, 0x09 },
        { 0xFFFFFFF2, 0x19 },
        { 0xFFFFFFF1, 0x15 },
        { 0xFFFFFFF0, 0x08 },
        { 0xFFFFFFEF, 0x15 },
        { 0xFFFFFFDF, 0x04 },
        { 0xFFFFFFDE, 0x04 },
        {          1, 0x63 }        };
#endif
#ifdef MEDIA667_P31J
extern CEDT_DRIVE_INFO G4194_;
#endif
#ifdef MEDIA670_F31E_F31J
CEDT_DRIVE_INFO G4194_;
#endif
#ifdef MEDIA692_X31J
CEDT_DRIVE_INFO G4194_;
int16_t G3885_[3];
#endif
#ifdef MEDIA674_F31E_F31J_X31J_P31J
UDSTRUCT8 G2281_[2] = {
#ifdef MEDIA692_X31J
        { MASK0x0080_MEMREQ | MASK0x0001_MEMREQ,  6145, NULL, NULL, NULL, 0 },
#endif
#ifdef MEDIA671_F31E_F31J_P31J
        { MASK0x0080_MEMREQ | MASK0x0001_MEMREQ, 10000, (UDSTRUCT1 *(*)(struct udstruct8 *Pxxxx_ps_))NULL, (void (*)(struct udstruct8 *Pxxxx_ps_))NULL, NULL, 0 },
#endif
        {                                     0,     0, (UDSTRUCT1 *(*)(struct udstruct8 *Pxxxx_ps_))NULL, (void (*)(struct udstruct8 *Pxxxx_ps_))NULL, NULL, 0 }
};
#endif
#ifdef MEDIA670_F31E_F31J
unsigned int16_t G7165_;
#endif
#ifdef MEDIA692_X31J
unsigned int16_t G7165_;
int16_t G3091_i_ErrorCount;
char G3901_[8] = "FTLSave";
char* G3886_;
#endif
/* strings from initializers, down to and including 'CHAOS STRIKES BACK' */
/* "A:\\MINI.DAT" */
/* COPYRIGHT (C)" */
/* SOFTWARE HEAVEN, INC." */
/* COPYRIGHT (C)" */
/* "\*.*" */


void F7285_(int16_t* P4056_pi_, UDSTRUCT8** P4057_pps_)
{
#ifdef MEDIA674_F31E_F31J_X31J_P31J
        G7165_ = 0;
        for (;;) { /*_Infinite loop_*/
                if (G2281_[G7165_].UDS8_MemReqFlags == 0) {
                        break;
                }
                G7165_++;
        };
        *P4056_pi_ = G7165_;
        *P4057_pps_ = G2281_;
#endif
#ifdef MEDIA768_AU2E_AU3E
        *P4056_pi_ = 0;
#endif
}

int16_t F7288_(
)
{
#ifdef MEDIA674_F31E_F31J_X31J_P31J
        REGISTER char* L4564_pc_;
#ifdef MEDIA671_F31E_F31J_P31J
        REGISTER int16_t L4566_i_Result;
#endif
        REGISTER unsigned int16_t L4565_ui_;
#ifdef MEDIA692_X31J
        REGISTER int16_t L4566_i_Result;
#endif


#ifdef MEDIA692_X31J
        L4566_i_Result = 0;
#endif
        for (L4565_ui_ = 0; L4565_ui_ < G7165_; L4565_ui_++) {
                L4564_pc_ = (char*)((G2281_[L4565_ui_].UDS8_pc_6)(&G2281_[L4565_ui_]));
                if (L4564_pc_ == NULL) {
                        L4566_i_Result = 3;
                        goto loc_DB8A;
                }
#ifdef MEDIA667_P31J
                L4564_pc_[(int16_t)G2281_[L4565_ui_].UDS8_BufferSize - 1] = 23;
#endif
#ifdef MEDIA670_F31E_F31J
                L4564_pc_[G2281_[L4565_ui_].UDS8_BufferSize - 1] = 23;
#endif
                (G2281_[L4565_ui_].UDS8_pc_A)(&G2281_[L4565_ui_]);
        }
#ifdef MEDIA671_F31E_F31J_P31J
        if (G0567_B_GameAndSaveDiskUseSameDrive) {
                G4194_.ui_0_DataDriveOrdinal = 1;
        } else {
#endif
                G4194_.ui_0_DataDriveOrdinal = 2;
#ifdef MEDIA671_F31E_F31J_P31J
        }
        for (L4565_ui_ = 0; G2282_[L4565_ui_]; L4565_ui_++);
        for (L4565_ui_ = 0; L4565_ui_ < 20; L4565_ui_++) {
#endif
#ifdef MEDIA692_X31J
        for (L4565_ui_ = 0; L4565_ui_ < 3; L4565_ui_++) {
#endif
                G4194_.ai_2_[L4565_ui_] = 0;
#ifdef MEDIA692_X31J
                G3885_[L4565_ui_] = 0;
#endif
        }
#ifdef MEDIA692_X31J
        F1024_SetTrap14VectorErrorProcessing();
        F2094_Call_DOS_FFLUSH();
#endif
#ifdef MEDIA671_F31E_F31J_P31J
        L4566_i_Result = 0;
#endif
        loc_DB8A:
        return L4566_i_Result;
#endif
}

void F7289_(int16_t* P4058_pi_, UDSTRUCT8** P4059_pps_)
{
#ifdef MEDIA674_F31E_F31J_X31J_P31J
#ifdef MEDIA692_X31J
        register char* L5942_;
#endif
        register unsigned int16_t L4567_i_; /* register keyword required for F31x */


#ifdef MEDIA692_X31J
        for (L4567_i_ = 0; L4567_i_ < 3; L4567_i_++) {
                if (G3885_[L4567_i_] > 0) {
                        F2090_(L4567_i_);
                }
        }
#endif
        *P4058_pi_ = G7165_;
        *P4059_pps_ = G2281_;
#ifdef MEDIA692_X31J
        F2094_Call_DOS_FFLUSH();
        F2081_();
#endif
#ifdef MEDIA671_F31E_F31J_P31J
        L4567_i_ = 0;
#endif
#endif
#ifdef MEDIA768_AU2E_AU3E
        *P4058_pi_ = 0;
#endif
}

int16_t F7290_(FILE_DESCRIPTOR* P4060_ps_, FILE_ID_INFO* P4061_ps_)
{
#ifdef MEDIA768_AU2E_AU3E
        int16_t L4571_i_Result;
#endif
#ifdef MEDIA674_F31E_F31J_X31J_P31J
        REGISTER int16_t L4571_i_Result;
        REGISTER FILE_DESCRIPTOR* L4568_ps_;
        REGISTER char* L4569_pc_;
#endif
        long L4570_l_;


#ifdef MEDIA692_X31J
        L4571_i_Result = 0;
#endif
#ifdef MEDIA674_F31E_F31J_X31J_P31J
        L4568_ps_ = P4060_ps_;
#endif
#ifdef MEDIA692_X31J
        L4568_ps_->Signature = 0x52A3;
#endif
#ifdef MEDIA671_F31E_F31J_P31J
        L4568_ps_->Signature = 0x5223;
#endif
#ifdef MEDIA674_F31E_F31J_X31J_P31J
        L4568_ps_->Flags = 0;
#endif
#ifdef MEDIA692_X31J
        L4568_ps_->Pad = 0;
#endif
        if (F7192_GetDataFileInfo(P4061_ps_, C13_FILE_INFO_FILE_NAME, &L4570_l_)) {
                L4571_i_Result = -1;
        } else {
#ifdef MEDIA674_F31E_F31J_X31J_P31J
                L4569_pc_ = (char*)L4570_l_;
                if (F0090_strlen(L4569_pc_) >= MAX_FILE_NAME_LENGTH) {
                        L4571_i_Result = -2;
                } else {
                        F0088_strcpy(L4568_ps_->FileName, L4569_pc_);
#ifdef MEDIA692_X31J
                        F7313_GetDriveIndex(L4568_ps_, &L4568_ps_->DriveLetterOrdinal);
                        L4568_ps_->FileName[0] = L4568_ps_->DriveLetterOrdinal + 'A';
#endif
#ifdef MEDIA671_F31E_F31J_P31J
                        if (L4568_ps_->FileName[1] == ':') {
                                L4568_ps_->DriveLetterOrdinal = M000_INDEX_TO_ORDINAL(F7313_GetDriveIndex(L4568_ps_));
                                L4568_ps_->FileName[0] = M001_ORDINAL_TO_INDEX(L4568_ps_->DriveLetterOrdinal) + 'A';
                        } else {
                                L4568_ps_->DriveLetterOrdinal = 0;
                        }
                        L4571_i_Result = 0;
#endif
                }
#endif
#ifdef MEDIA768_AU2E_AU3E
                L4571_i_Result = FIO1_29_(P4060_ps_, P4061_ps_, L4570_l_);
#endif
        }
#ifdef MEDIA668_P31J_AU2E_AU3E
        if (L4571_i_Result < 0) {
#endif
#ifdef MEDIA670_F31E_F31J
        if (L4571_i_Result < 0) {
#endif
#ifdef MEDIA692_X31J
        if (L4571_i_Result) {
#endif
                L4571_i_Result = 3;
        } else {
                L4571_i_Result = 0;
        }
        return L4571_i_Result;
}

int16_t F7291_(FILE_DESCRIPTOR* P4062_ps_)
{
#ifdef MEDIA674_F31E_F31J_X31J_P31J
        int16_t L4573_i_Result;
        FILE_DESCRIPTOR* L4572_ps_;


#ifdef MEDIA692_X31J
        L4573_i_Result = 0;
#endif
        if (F7309_(P4062_ps_, &L4572_ps_) < 0) {
                L4573_i_Result = 3;
        } else {
#ifdef MEDIA692_X31J
                L4572_ps_->Signature = 0x52A4;
#endif
#ifdef MEDIA671_F31E_F31J_P31J
                L4572_ps_->Signature = 0x5224;
                L4573_i_Result = 0;
#endif
        }
        return L4573_i_Result;
#endif
#ifdef MEDIA768_AU2E_AU3E
        FIO1_28_(P4062_ps_);
#endif
}

long F7280__GetFileDescriptorByteCount(
)
{
#ifdef MEDIA674_F31E_F31J_X31J_P31J
        return (long)sizeof(FILE_DESCRIPTOR);
#endif
#ifdef MEDIA768_AU2E_AU3E
        FIO1_27_();
#endif
}

void F7292_SubstituteStringInFileName(FILE_DESCRIPTOR* P4063_ps_, char* P4064_pc_StringToReplace, char* P4065_pc_ReplacementString)
{
#ifdef MEDIA674_F31E_F31J_X31J_P31J
        FILE_DESCRIPTOR* L4574_ps_;
        char L4575_ac_OutputFileName[MAX_FILE_NAME_LENGTH];
#ifdef MEDIA671_F31E_F31J_P31J
        int16_t L4576_i_Result;
#endif


        if (F7309_(P4063_ps_, &L4574_ps_) < 0) {
#ifdef MEDIA671_F31E_F31J_P31J
                L4576_i_Result = 3;
#endif
                return;
        }
        if (F7097_strstr(P4064_pc_StringToReplace, L4574_ps_->FileName) >= 0) {
                if (F7098_SubstituteString(L4574_ps_->FileName, P4064_pc_StringToReplace, P4065_pc_ReplacementString, L4575_ac_OutputFileName, MAX_FILE_NAME_LENGTH) < 0) {
#ifdef MEDIA671_F31E_F31J_P31J
                        L4576_i_Result = 3;
#endif
                        return;
                } else {
#ifdef MEDIA692_X31J
                        if (F0090_strlen(L4575_ac_OutputFileName) < MAX_FILE_NAME_LENGTH) {
#endif
                                F0088_strcpy(L4574_ps_->FileName, L4575_ac_OutputFileName);
#ifdef MEDIA692_X31J
                        }
#endif
                }
        }
#ifdef MEDIA671_F31E_F31J_P31J
        L4576_i_Result = 0;
#endif
#endif
#ifdef MEDIA768_AU2E_AU3E
        FIO1_07_SubstituteStringInFileName(P4063_ps_, P4064_pc_StringToReplace, P4065_pc_ReplacementString);
#endif
}

char F7293_(FILE_DESCRIPTOR* P4066_ps_)
{
#ifdef MEDIA674_F31E_F31J_X31J_P31J
#ifdef MEDIA671_F31E_F31J_P31J
        int16_t L4580_i_DriveAddress;
        long L4577_l_;
        unsigned char L4578_c_;
#endif
        FILE_DESCRIPTOR* L4579_ps_;
#ifdef MEDIA692_X31J
        int16_t L4580_i_DriveAddress;
        unsigned char L4578_c_;
        unsigned char L4577_;
#endif


        if (F7309_(P4066_ps_, &L4579_ps_) < 0) {
#ifdef MEDIA671_F31E_F31J_P31J
                L4580_i_DriveAddress = -1;
        } else {
                L4577_l_ = 0;
                if (L4577_l_ == 0) {
                        L4578_c_ = 0;
                } else {
                        L4578_c_ = 1;
                }
                L4580_i_DriveAddress = 0;
#endif
        }
#ifdef MEDIA671_F31E_F31J_P31J
        if (L4580_i_DriveAddress < 0) {
                L4578_c_ = 1;
        }
#endif
#ifdef MEDIA692_X31J
        L4580_i_DriveAddress = F2091_GetDriveAddress(L4579_ps_->DriveLetterOrdinal);
        L4577_ = F2087_(L4580_i_DriveAddress, 8);
        if (L4577_ == 255) {
                L4578_c_ = 1;
        } else {
                L4578_c_ = 0;
        }
#endif
        return L4578_c_;
#endif
#ifdef MEDIA768_AU2E_AU3E
        FIO1_26_(P4066_ps_);
#endif
}

#ifdef MEDIA699_X31J_AU2E_AU3E
#include "CEDTINC1.C"
#endif

BOOLEAN F7294_(FILE_DESCRIPTOR* P4067_ps_)
{
#ifdef MEDIA674_F31E_F31J_X31J_P31J
        FILE_DESCRIPTOR* L4581_ps_;
        REGISTER BOOLEAN L4582_B_;


        if (F7309_(P4067_ps_, &L4581_ps_) >= 0) {
#ifdef MEDIA671_F31E_F31J_P31J
                L4582_B_ = C0_FALSE;
#endif
#ifdef MEDIA692_X31J
                L4582_B_ = L4581_ps_->DriveLetterOrdinal < G4194_.ui_0_DataDriveOrdinal;
#endif
        } else {
                L4582_B_ = C0_FALSE;
        }
        return L4582_B_;
#endif
#ifdef MEDIA768_AU2E_AU3E
        FIO1_04_IsDiskWriteable(P4067_ps_);
#endif
}

int16_t F7281__EmptyFunction(FILE_DESCRIPTOR* P4068_ps_)
{
#ifdef MEDIA692_X31J
        int16_t L5947_i_Result;
        int16_t L5948_i_DriveIndex;
        FILE_DESCRIPTOR* L5949_;


        L5947_i_Result = 0;
        if (F7294_(P4068_ps_) < 0) {
                L5947_i_Result = 3;
        } else {
                if (F7309_(P4068_ps_, &L5949_) < 0) {
                        L5947_i_Result = 3;
                } else {
                        L5948_i_DriveIndex = L5949_->DriveLetterOrdinal;
                        if (F2086_(L5948_i_DriveIndex) == 3) {
                                F2085_EjectFloppyDisk(L5948_i_DriveIndex);
                                L5947_i_Result = 9;
                        } else {
                                if (!F2079_FormatFloppyDisk(L5948_i_DriveIndex)) {
                                        L5947_i_Result = 8;
                                } else {
                                        L5947_i_Result = 0;
                                }
                        }
                }
        }
        return L5947_i_Result;
#endif
#ifdef MEDIA768_AU2E_AU3E
        FIO1_05_FormatSaveDisk(P4068_ps_);
#endif
}

int16_t F7295_(FILE_DESCRIPTOR* P4069_ps_, int16_t* P4070_pi_)
{
#ifdef MEDIA674_F31E_F31J_X31J_P31J
#ifdef MEDIA692_X31J
        int16_t L4584_i_;
        int16_t L4587_i_Result;
#endif
#ifdef MEDIA670_F31E_F31J
        register int16_t L4584_i_;
        register int16_t L4585_i_;
        register unsigned int16_t L4588_ui_;
#endif
#ifdef MEDIA693_X31J_P31J
        int16_t L4585_i_;
#endif
        UDSTRUCT1* L4583_ps_;
#ifdef MEDIA693_X31J_P31J
        unsigned int16_t L4588_ui_;
#endif
#ifdef MEDIA692_X31J
        int16_t L5950_;
#endif
#ifdef MEDIA667_P31J
        int16_t L4584_i_;
#endif
#ifdef MEDIA671_F31E_F31J_P31J
        int16_t L4587_i_Result;
        FILE_DESCRIPTOR* L4586_ps_;
#endif


#ifdef MEDIA692_X31J
        L4584_i_ = 0;
        L4585_i_ = 0;
        L4587_i_Result = 0;
        F7313_GetDriveIndex(P4069_ps_, &L4588_ui_);
        if (L4588_ui_ < G4194_.ui_0_DataDriveOrdinal) {
                if ((G4194_.ai_2_[L4588_ui_] == 0) || F7293_(P4069_ps_)) {
                        for (L4584_i_ = 0; L4584_i_ < 2; L4584_i_++) {
                                F7308_Return0(L4588_ui_);
                                L4587_i_Result = 0;
                                L5950_ = F2084_CheckX68000OriginalDisk_CPSX(L4588_ui_);
                                if (!L5950_) {
                                        L4585_i_ = 0;
                                        L4587_i_Result = 7;
                                } else {
                                        if (L5950_ == 1) {
                                                L4585_i_ = 3;
                                                break;
                                        } else {
                                                L4585_i_ = 1;
                                                break;
                                        }
                                }
                        }
                } else {
                        L4585_i_ = G4194_.ai_2_[L4588_ui_];
                }
                G4194_.ai_2_[L4588_ui_] = L4585_i_;
        } else {
                L4585_i_ = 1;
                G4194_.ai_2_[L4588_ui_] = L4585_i_;
        }
        *P4070_pi_ = L4585_i_;
#endif
#ifdef MEDIA671_F31E_F31J_P31J
        if (F7309_(P4069_ps_, &L4586_ps_) < 0) {
                L4587_i_Result = 3;
        } else {
                L4583_ps_ = NULL;
                T7295001: /* ANOMALY_FMT Unwanted optimization */
                L4584_i_ = 0;
                L4587_i_Result = 0;
                L4585_i_ = 0;
                L4588_ui_ = F7313_GetDriveIndex(P4069_ps_);
                if (L4588_ui_ >= 2) {
                        goto loc_1F45D;
                }
                L4583_ps_ = (G2281_[0].UDS8_pc_6)(G2281_);
#ifdef MEDIA667_P31J
                L4584_i_ = 0;
#endif
                if (L4584_i_ < 2) {
                        if ((G4194_.ai_2_[L4588_ui_] == 0) || F7293_(P4069_ps_)) {
                                F7308_Return0(L4588_ui_);
                                L4585_i_ = F7311_((unsigned char*)L4583_ps_ + 368);
                                G4194_.ai_2_[L4588_ui_] = L4585_i_;
                        } else {
                                if (F0087_strcmp(L4586_ps_->FileName, "A:\\MINI.DAT") == 0) {
                                        L4585_i_ = 3;
                                        goto loc_1F46E;
                                } else {
                                        L4585_i_ = 1;
                                        goto loc_1F46E;
                                }
                                loc_1F45D:
                                L4585_i_ = F7312_(L4588_ui_);
                                G4194_.ai_2_[L4588_ui_] = L4585_i_;
                        }
                }
                loc_1F46E:
                *P4070_pi_ = L4585_i_;
        }
        if (L4583_ps_) {
                (G2281_[0].UDS8_pc_A)(G2281_);
        }
#endif
        return L4587_i_Result;
#endif
#ifdef MEDIA768_AU2E_AU3E
        FIO1_23_(P4069_ps_, P4070_pi_);
#endif
}

int16_t F7282__TryOpenFile(FILE_DESCRIPTOR* P4071_ps_)
{
#ifdef MEDIA674_F31E_F31J_X31J_P31J
        int16_t L4589_i_Result;
#ifdef MEDIA692_X31J
        int16_t L5951_;
        FILE_DESCRIPTOR* L5952_;


        if (F7309_(P4071_ps_, &L5952_) < 0) {
                L4589_i_Result = 3;
        } else {
                L5951_ = L5952_->Pad;
                L5952_->Pad = 0;
#endif
                L4589_i_Result = F7296_OpenFile(P4071_ps_);
                if (L4589_i_Result == 0) {
                        F7297_CloseFile(P4071_ps_);
                } else {
                        L4589_i_Result = 17;
                }
#ifdef MEDIA692_X31J
                L5952_->Pad = L5951_;
        }
#endif
        return L4589_i_Result;
#endif
#ifdef MEDIA768_AU2E_AU3E
        FIO1_22_(P4071_ps_);
#endif
}

int16_t F7296_OpenFile(FILE_DESCRIPTOR* P4072_ps_)
{
#ifdef MEDIA674_F31E_F31J_X31J_P31J
        REGISTER int16_t L4591_i_Result;
        REGISTER FILE_HANDLE L4592_i_;
        FILE_DESCRIPTOR* L4590_ps_;
#ifdef MEDIA692_X31J
        int16_t L5953_ = 0;
#endif


        if (F7309_(P4072_ps_, &L4590_ps_) < 0) {
                L4591_i_Result = 3;
        } else {
                if (M007_GET(L4590_ps_->Flags, MASK0x1000_FILE_OPENED)) {
#ifdef MEDIA692_X31J
                        L4591_i_Result = 17;
                } else {
                        if (F2088_(L4590_ps_->DriveLetterOrdinal, 1) == 1) {
                                L5953_ = 1;
                                if ((L4592_i_ = F0770_FILE_Open(L4590_ps_->FileName, L4590_ps_->Pad)) < 0) {
                                        L4591_i_Result = 4;
                                } else {
                                        L4591_i_Result = 0;
                                        L4590_ps_->Flags |= MASK0x1000_FILE_OPENED;
                                        L4590_ps_->FDFileHandle = L4592_i_;
                                }
                        } else {
                                L4591_i_Result = 99;
                        }
                }
        }
        if (L5953_ && L4591_i_Result) {
                F2089_(L4590_ps_->DriveLetterOrdinal);
#endif
#ifdef MEDIA671_F31E_F31J_P31J
                        L4591_i_Result = 12;
                } else {
                        if (F0780_FILE_IsHandleInvalid(L4592_i_ = F0770_FILE_Open(L4590_ps_->FileName))) {
                                L4591_i_Result = 4;
                        } else {
                                M008_SET(L4590_ps_->Flags, MASK0x1000_FILE_OPENED);
                                L4590_ps_->FDFileHandle = L4592_i_;
                                L4591_i_Result = 0;
                        }
                }
#endif
        }
        return L4591_i_Result;
#endif
#ifdef MEDIA768_AU2E_AU3E
        FIO1_21_Open(P4072_ps_, 0);
#endif
}

int16_t F7283__CreateFile(FILE_DESCRIPTOR* P4073_ps_)
{
#ifdef MEDIA674_F31E_F31J_X31J_P31J
        REGISTER int16_t L4594_i_Result;
        REGISTER FILE_HANDLE L4595_i_;
        FILE_DESCRIPTOR* L4593_ps_;
#ifdef MEDIA692_X31J
        int16_t L5954_ = 0;
#endif


        if (F7309_(P4073_ps_, &L4593_ps_) < 0) {
                L4594_i_Result = 3;
        } else {
                if (M007_GET(L4593_ps_->Flags, MASK0x1000_FILE_OPENED)) {
#ifdef MEDIA692_X31J
                        L4594_i_Result = 17;
                } else {
                        L4593_ps_->Pad = 1;
                        if (F2086_(L4593_ps_->DriveLetterOrdinal) != 3) {
                                if (F2088_(L4593_ps_->DriveLetterOrdinal, 1) == 1) {
                                        L5954_ = 1;
                                        if ((L4595_i_ = F0776_FILE_Create(L4593_ps_->FileName)) < 0) {
                                                L4594_i_Result = 8;
                                        } else {
                                                L4594_i_Result = 0;
                                                L4593_ps_->Flags |= MASK0x1000_FILE_OPENED;
                                                L4593_ps_->FDFileHandle = L4595_i_;
                                        }
                                } else {
                                        L4594_i_Result = 99;
                                }
                        } else {
                                F2085_EjectFloppyDisk(L4593_ps_->DriveLetterOrdinal);
                                L4594_i_Result = 9;
                        }
                }
        }
        if (L5954_ && L4594_i_Result) {
                F2089_(L4593_ps_->DriveLetterOrdinal);
#endif
#ifdef MEDIA671_F31E_F31J_P31J
                        L4594_i_Result = 12;
                } else {
                        if (F0780_FILE_IsHandleInvalid(L4595_i_ = F0776_FILE_Create(L4593_ps_->FileName))) {
                                L4594_i_Result = 99;
                        } else {
                                M008_SET(L4593_ps_->Flags, MASK0x1000_FILE_OPENED);
                                L4593_ps_->FDFileHandle = L4595_i_;
                                L4594_i_Result = 0;
                        }
                }
#endif
        }
        return L4594_i_Result;
#endif
#ifdef MEDIA768_AU2E_AU3E
        FIO1_20_Create(P4073_ps_);
#endif
}

int16_t F7297_CloseFile(FILE_DESCRIPTOR* P4074_ps_)
{
#ifdef MEDIA674_F31E_F31J_X31J_P31J
        REGISTER int16_t L4597_i_Result;
        FILE_DESCRIPTOR* L4596_ps_;


        if (F7309_(P4074_ps_, &L4596_ps_) < 0) {
                L4597_i_Result = 3;
        } else {
                if (!M007_GET(L4596_ps_->Flags, MASK0x1000_FILE_OPENED)) {
                        L4597_i_Result = 12;
                } else {
#ifdef MEDIA671_F31E_F31J_P31J
                        F0771_FILE_Close(L4596_ps_->FDFileHandle);
#endif
#ifdef MEDIA692_X31J
                        if (F0771_FILE_Close(L4596_ps_->FDFileHandle) == 0) {
                                L4597_i_Result = 12;
                        } else {
#endif
                                L4597_i_Result = 0;
                                M009_CLEAR(L4596_ps_->Flags, MASK0x1000_FILE_OPENED);
#ifdef MEDIA692_X31J
                                F2089_(L4596_ps_->DriveLetterOrdinal);
                        }
#endif
                }
        }
        return L4597_i_Result;
#endif
#ifdef MEDIA768_AU2E_AU3E
        FIO1_19_Close(P4074_ps_);
#endif
}

int16_t F7298_GetFileSize(FILE_DESCRIPTOR* P4075_ps_, long* P4076_pl_)
{
#ifdef MEDIA674_F31E_F31J_X31J_P31J
        REGISTER int16_t L4599_i_Result;
        FILE_DESCRIPTOR* L4598_ps_;
#ifdef MEDIA692_X31J
        long L5955_;
#endif


        if (F7309_(P4075_ps_, &L4598_ps_) < 0) {
                L4599_i_Result = 3;
        } else {
                if (!M007_GET(L4598_ps_->Flags, MASK0x1000_FILE_OPENED)) {
                        L4599_i_Result = 12;
                } else {
#ifdef MEDIA692_X31J
                        if (!(int16_t)F0779_FILE_Tell(L4598_ps_->FDFileHandle, &L5955_)) {
                                L4599_i_Result = 99;
                        } else {
                                if (!(int16_t)F0775_FILE_GetSize(L4598_ps_->FDFileHandle, P4076_pl_)) {
                                        L4599_i_Result = 99;
                                } else {
                                        if (!F0774_FILE_Seek(L4598_ps_->FDFileHandle, L5955_)) {
                                                L4599_i_Result = 99;
                                        }
                                }
                        }
#endif
#ifdef MEDIA671_F31E_F31J_P31J
                        *P4076_pl_ = F0775_FILE_GetSize(L4598_ps_->FDFileHandle);
                        L4599_i_Result = 0;
#endif
                }
        }
        return L4599_i_Result;
#endif
#ifdef MEDIA768_AU2E_AU3E
        FIO1_18_GetSize(P4075_ps_, P4076_pl_);
#endif
}

int16_t F7299_FSeek_FromCurrent_Unreferenced(FILE_DESCRIPTOR* P4077_ps_, long* P4078_pl_)
{
#ifdef MEDIA674_F31E_F31J_X31J_P31J
        int16_t L4601_i_Result;
        FILE_DESCRIPTOR* L4600_ps_;


        if (F7309_(P4077_ps_, &L4600_ps_) < 0) {
                L4601_i_Result = 3;
        } else {
                if (!M007_GET(L4600_ps_->Flags, MASK0x1000_FILE_OPENED)) {
                        L4601_i_Result = 12;
                } else {
#ifdef MEDIA692_X31J
                        if ((int16_t)F0779_FILE_Tell(L4600_ps_->FDFileHandle, P4078_pl_)) {
                                L4601_i_Result = 0;
                        } else {
                                L4601_i_Result = 99;
                        }
#endif
#ifdef MEDIA671_F31E_F31J_P31J
                        *P4078_pl_ = F0779_FILE_Tell(L4600_ps_->FDFileHandle);
                        L4601_i_Result = 0;
#endif
                }
        }
        return L4601_i_Result;
#endif
#ifdef MEDIA768_AU2E_AU3E
        FIO1_17_Tell(P4077_ps_, P4078_pl_);
#endif
}

int16_t F7300_Fseek(FILE_DESCRIPTOR* P4079_ps_, unsigned long P4080_ul_)
{
#ifdef MEDIA674_F31E_F31J_X31J_P31J
        FILE_DESCRIPTOR* L4602_ps_;
        REGISTER int16_t L4603_i_Result;


        if (F7309_(P4079_ps_, &L4602_ps_) < 0) {
                L4603_i_Result = 3;
        } else {
                if (!M007_GET(L4602_ps_->Flags, MASK0x1000_FILE_OPENED)) {
                        L4603_i_Result = 12;
                } else {
                        if (P4080_ul_ > 0x7FFFFFFF) {
                                L4603_i_Result = 3;
                        } else {
                                if (F0774_FILE_Seek(L4602_ps_->FDFileHandle, P4080_ul_)) {
                                        L4603_i_Result = 0;
                                } else {
#ifdef MEDIA692_X31J
                                        L4603_i_Result = 3;
#endif
#ifdef MEDIA671_F31E_F31J_P31J
                                        L4603_i_Result = 99;
#endif
                                }
                        }
                }
        }
        return L4603_i_Result;
#endif
#ifdef MEDIA768_AU2E_AU3E
        FIO1_16_Seek(P4079_ps_, P4080_ul_);
#endif
}

int16_t F7286__Fread(FILE_DESCRIPTOR* P4081_ps_, unsigned long P4082_ul_, char* P4083_pc_)
{
#ifdef MEDIA674_F31E_F31J_X31J_P31J
        FILE_DESCRIPTOR* L4604_ps_;
        REGISTER int16_t L4605_i_Result;


#ifdef MEDIA692_X31J
        L4605_i_Result = 0;
#endif
        if (F7309_(P4081_ps_, &L4604_ps_) < 0) {
                L4605_i_Result = 3;
        } else {
                if (!M007_GET(L4604_ps_->Flags, MASK0x1000_FILE_OPENED)) {
                        L4605_i_Result = 12;
                } else {
                        if (P4082_ul_ == 0) {
#ifdef MEDIA671_F31E_F31J_P31J
                                L4605_i_Result = 0;
#endif
                        } else {
                                if (P4082_ul_ > 0x7FFFFFFF) {
                                        L4605_i_Result = 3;
                                } else {
                                        if (F0772_FILE_Read(L4604_ps_->FDFileHandle, P4082_ul_, M774_CAST_PUC(P4083_pc_))) {
#ifdef MEDIA671_F31E_F31J_P31J
                                                L4605_i_Result = 0;
#endif
                                        } else {
                                                L4605_i_Result = 7;
                                        }
                                }
                        }
                }
        }
        return L4605_i_Result;
#endif
#ifdef MEDIA768_AU2E_AU3E
        FIO1_15_Read(P4081_ps_, P4082_ul_, P4083_pc_);
#endif
}

int16_t F7301_Fwrite(FILE_DESCRIPTOR* P4084_ps_, unsigned long P4085_ul_, char* P4086_pc_)
{
#ifdef MEDIA674_F31E_F31J_X31J_P31J
        FILE_DESCRIPTOR* L4606_ps_;
        long L4607_l_;
#ifdef MEDIA692_X31J
        int16_t L5956_;
#endif
        REGISTER int16_t L4608_i_Result;


#ifdef MEDIA692_X31J
        L4608_i_Result = 0;
#endif
        if (F7309_(P4084_ps_, &L4606_ps_) < 0) {
                L4608_i_Result = 3;
        } else {
                if (!M007_GET(L4606_ps_->Flags, MASK0x1000_FILE_OPENED)) {
                        L4608_i_Result = 12;
                } else {
                        if (P4085_ul_ == 0) {
#ifdef MEDIA671_F31E_F31J_P31J
                                L4608_i_Result = 0;
#endif
                        } else {
                                if (P4085_ul_ > 0x7FFFFFFF) {
                                        L4608_i_Result = 3;
                                } else {
#ifdef MEDIA692_X31J
                                        L5956_ = F2086_(L4606_ps_->DriveLetterOrdinal);
                                        if (L5956_ == 3) {
                                                F2085_EjectFloppyDisk(L4606_ps_->DriveLetterOrdinal);
                                                L4608_i_Result = 9;
                                        } else {
                                                if (L5956_ != 1) {
                                                        L4608_i_Result = 99;
                                                } else {
                                                        if (!F0773_FILE_Write(L4606_ps_->FDFileHandle, P4085_ul_, P4086_pc_)) {
#endif
#ifdef MEDIA671_F31E_F31J_P31J
                                                        if (F0773_FILE_Write(L4606_ps_->FDFileHandle, P4085_ul_, M774_CAST_PUC(P4086_pc_))) {
                                                                L4608_i_Result = 0;
                                                        } else {
#endif
                                                                L4608_i_Result = F7302_(P4084_ps_, &L4607_l_);
                                                                if ((L4608_i_Result == 0) && (L4607_l_ < P4085_ul_)) {
                                                                        L4608_i_Result = 6;
                                                                } else {
                                                                        L4608_i_Result = 8;
                                                                }
#ifdef MEDIA692_X31J
                                                        } else {
                                                                L4608_i_Result = 0;
#endif
                                                        }
#ifdef MEDIA692_X31J
                                                }
                                        }
#endif
                                }
                        }
                }
        }
        return L4608_i_Result;
#endif
#ifdef MEDIA768_AU2E_AU3E
        FIO1_14_Write(P4084_ps_, P4085_ul_, P4086_pc_);
#endif
}

int16_t F7302_(FILE_DESCRIPTOR* P4087_ps_, long* P4088_pl_)
{
#ifdef MEDIA674_F31E_F31J_X31J_P31J
        FILE_DESCRIPTOR* L4609_ps_;
        struct FREEINF L5959_;
        REGISTER int16_t L4610_i_Result;
#ifdef MEDIA692_X31J
        register long L5957_;
        register int16_t L5958_;
#endif


        if (F7309_(P4087_ps_, &L4609_ps_) < 0) {
                L4610_i_Result = 3;
        } else {
                L4610_i_Result = 0;
#ifdef MEDIA692_X31J
                L5958_ = L4609_ps_->DriveLetterOrdinal + 1;
                asm {
                                pea     L5959_(a6)
                                move.w  L5958_,-(sp)
                                dc.w    0xFF36  /* DOS CALL DSKFRE */
                                addq.l  #6,sp
                                move.l  d0,L5957_
                                bpl.s   @Tloc_E5A6
                                move.w  #21,d7
                        @Tloc_E5A6:
                }
                if (!L4610_i_Result) {
                        *P4088_pl_ = L5957_;
                }
#endif
#ifdef MEDIA671_F31E_F31J_P31J
                *P4088_pl_ = 1000000;
#endif
        }
        return L4610_i_Result;
#endif
#ifdef MEDIA768_AU2E_AU3E
        FIO1_13_Lock(P4087_ps_, P4088_pl_);
#endif
}

int16_t F7303_Fdelete(FILE_DESCRIPTOR* P4089_ps_)
{
#ifdef MEDIA674_F31E_F31J_X31J_P31J
        FILE_DESCRIPTOR* L4611_ps_;
        REGISTER int16_t L4612_i_Result;


        if (F7309_(P4089_ps_, &L4611_ps_) < 0) {
                L4612_i_Result = 3;
        } else {
                if (M007_GET(L4611_ps_->Flags, MASK0x1000_FILE_OPENED)) {
                        L4612_i_Result = 12;
                } else {
#ifdef MEDIA671_F31E_F31J_P31J
                        F0777_FILE_Delete(L4611_ps_->FileName);
#endif
#ifdef MEDIA692_X31J
                        if (F0777_FILE_Delete(L4611_ps_->FileName)) {
#endif
                                L4612_i_Result = 0;
#ifdef MEDIA692_X31J
                        } else {
                                if (F2086_(L4611_ps_->DriveLetterOrdinal) == 3) {
                                        F2085_EjectFloppyDisk(L4611_ps_->DriveLetterOrdinal);
                                        L4612_i_Result = 9;
                                } else {
                                        L4612_i_Result = 4;
                                }
#endif
#ifdef MEDIA671_F31E_F31J_P31J
                                L4612_i_Result = 0;
#endif
#ifdef MEDIA692_X31J
                        }
#endif
                }
        }
        return L4612_i_Result;
#endif
#ifdef MEDIA768_AU2E_AU3E
        FIO1_12_Delete(P4089_ps_);
#endif
}

int16_t F7304_Frename_Unreferenced(FILE_DESCRIPTOR* P4090_ps_, FILE_DESCRIPTOR* P4091_ps_)
{
#ifdef MEDIA674_F31E_F31J_X31J_P31J
        FILE_DESCRIPTOR* L4613_ps_;
        FILE_DESCRIPTOR* L4614_ps_;
        REGISTER int16_t L4615_i_Result;


        if ((F7309_(P4090_ps_, &L4613_ps_) < 0)
#ifdef MEDIA692_X31J
            || (F7309_(P4091_ps_, &L4614_ps_) < 0)
#endif
           ) {
                L4615_i_Result = 3;
        } else {
                if (M007_GET(L4613_ps_->Flags, MASK0x1000_FILE_OPENED)
#ifdef MEDIA692_X31J
                    || M007_GET(L4614_ps_->Flags, MASK0x1000_FILE_OPENED)
#endif
                   ) {
                        L4615_i_Result = 12;
                } else {
#ifdef MEDIA692_X31J
                        if (F0778_FILE_Rename(L4613_ps_->FileName, L4614_ps_->FileName)) {
                                L4615_i_Result = 0;
                        } else {
                                if (F2086_(L4613_ps_->DriveLetterOrdinal) == 3) {
                                        F2085_EjectFloppyDisk(L4613_ps_->DriveLetterOrdinal);
                                        L4615_i_Result = 9;
                                } else {
                                        L4615_i_Result = 4;
                                }
                        }
#endif
#ifdef MEDIA671_F31E_F31J_P31J
                        if (F7309_(P4091_ps_, &L4614_ps_) < 0) {
                                L4615_i_Result = 3;
                        } else {
                                if (M007_GET(L4614_ps_->Flags, MASK0x1000_FILE_OPENED)) {
                                        L4615_i_Result = 12;
                                } else {
                                        F0778_FILE_Rename(L4613_ps_->FileName, L4614_ps_->FileName);
                                        L4615_i_Result = 0;
                                }
                        }
#endif
                }
        }
        return L4615_i_Result;
#endif
#ifdef MEDIA768_AU2E_AU3E
        FIO1_11_Rename(P4090_ps_, P4091_ps_);
#endif
}

int16_t F7287__GetDataDriveOrdinal(
)
{
#ifdef MEDIA674_F31E_F31J_X31J_P31J
        return G4194_.ui_0_DataDriveOrdinal;
#endif
#ifdef MEDIA768_AU2E_AU3E
        FIO1_09_();
#endif
}

char F7305_(FILE_DESCRIPTOR* P4092_ps_)
{
#ifdef MEDIA674_F31E_F31J_X31J_P31J
        FILE_DESCRIPTOR* L4616_ps_;
        char L4617_c_;


#ifdef MEDIA671_F31E_F31J_P31J
        L4617_c_ = C1_TRUE;
#endif
        if ((F7309_(P4092_ps_, &L4616_ps_) < 0) || !M007_GET(L4616_ps_->Flags, MASK0x1000_FILE_OPENED)) {
#ifdef MEDIA692_X31J
                L4617_c_ = C1_TRUE;
#endif
        } else {
                L4617_c_ = C0_FALSE;
        }
        return L4617_c_;
#endif
#ifdef MEDIA768_AU2E_AU3E
        FIO1_10_(P4092_ps_);
#endif
}

void F7306_(FILE_DESCRIPTOR* P4093_ps_, char* P4094_pc_)
{
#ifdef MEDIA674_F31E_F31J_X31J_P31J
        REGISTER unsigned int16_t L4621_ui_;
        REGISTER unsigned int16_t L4622_ui_;
        REGISTER unsigned char* L4618_pc_;
        FILE_DESCRIPTOR* L4619_ps_;
        char L4620_ac_[MAX_FILE_NAME_LENGTH];


        if (F7309_(P4093_ps_, &L4619_ps_) < 0) {
                return;
        }
        L4618_pc_ = M774_CAST_PUC(L4619_ps_->FileName);
        for (L4621_ui_ = 0; L4618_pc_[L4621_ui_] && (L4618_pc_[L4621_ui_] != '*') && (L4621_ui_ < MAX_FILE_NAME_LENGTH - 1); L4621_ui_++) {
                L4620_ac_[L4621_ui_] = L4618_pc_[L4621_ui_];
        }
        if (L4618_pc_[L4621_ui_] == '*') {
                for (L4622_ui_ = 0; (P4094_pc_[L4622_ui_] != '\0') && (L4621_ui_ < MAX_FILE_NAME_LENGTH - 1); L4620_ac_[L4621_ui_++] = P4094_pc_[L4622_ui_++]);
                L4620_ac_[L4621_ui_] = '\0';
                F0088_strcpy(M772_CAST_PC(L4618_pc_), L4620_ac_);
        }
#endif
#ifdef MEDIA768_AU2E_AU3E
        FIO1_08_(P4093_ps_, P4094_pc_);
#endif
}

int16_t F7307_GetDrivePath(FILE_DESCRIPTOR* P4095_ps_, unsigned int16_t P4096_ui_, char** P4097_ppc_)
{
#ifdef MEDIA674_F31E_F31J_X31J_P31J
        FILE_DESCRIPTOR* L4623_ps_;
        REGISTER int16_t L4624_i_Result;


        if (F7309_(P4095_ps_, &L4623_ps_) < 0) {
                L4624_i_Result = 3;
        } else {
#ifdef MEDIA692_X31J
                L4624_i_Result = 0;
#endif
                switch (P4096_ui_) {
                        case C14_FILE_INFO_DRIVE_PATH:
                                *P4097_ppc_ = G2282_[L4623_ps_->DriveLetterOrdinal];
                                break;
                        default:
                                L4624_i_Result = 3;
#ifdef MEDIA671_F31E_F31J_P31J
                                return L4624_i_Result;
#endif
                }
#ifdef MEDIA671_F31E_F31J_P31J
                L4624_i_Result = 0;
#endif
        }
        return L4624_i_Result;
#endif
#ifdef MEDIA768_AU2E_AU3E
        FIO1_06_(P4095_ps_, P4096_ui_, P4097_ppc_);
#endif
}

#ifdef MEDIA692_X31J
BOOLEAN F2078_ReadSector_Unreferenced(char* P5968_pc_Buffer, unsigned int16_t P5969_ui_DriveIndex, unsigned int16_t P5970_ui_Track, unsigned int16_t P5971_ui_Side, unsigned int16_t P5972_ui_Sector) {
        register BOOLEAN L5960_B_ReadSectorSucceeded;
        int16_t L5961_i_DriveAddress;
        BOOLEAN L5962_B_;


        L5962_B_ = C0_FALSE;
        if ((P5969_ui_DriveIndex >= G4194_.ui_0_DataDriveOrdinal) || (P5971_ui_Side > 1) || (P5970_ui_Track > 79) || (P5972_ui_Sector > 7)) {
                L5960_B_ReadSectorSucceeded = 0;
        } else {
                if (F2088_(P5969_ui_DriveIndex, 1) != 1) {
                        L5960_B_ReadSectorSucceeded = 0;
                } else {
                        L5962_B_ = C1_TRUE;
                        L5961_i_DriveAddress = F2091_GetDriveAddress(P5969_ui_DriveIndex);
                        asm {
                                        moveq   #0x46,d0        /* B_READ */
                                        move.w  L5961_i_DriveAddress(a6),d1
                                        addi.w  #0x50,d1        /* 0x50: Mode (01010000 Bit 6 = 1: MFM, Bit 5 = 0: Do not retry, Bit 4 = 1: Seek and then execute) */
                                        move.w  #0x0300,d2      /* 0x03: Sector length 3 (0: 128, 1: 256, 2: 512, 3: 1024) */
                                        add.w   P5970_ui_Track(a6),d2
                                        lsl.l   #8,d2
                                        add.w   P5971_ui_Side(a6),d2
                                        lsl.l   #8,d2
                                        add.w   P5972_ui_Sector(a6),d2
                                        move.l  #1024,d3        /* Number of bytes to read */
                                        movea.l P5968_pc_Buffer(a6),a1
                                        trap    #0xF            /* TRAP 15 (IOCS CALL) */
                                        btst    #0x1E,d0        /* FDC Status Byte 0 (STA0) bit 6 = 1: Abnormal command termination or drive status changed */
                                        bne.s   @Tloc_E8CE
                                        btst    #0x15,d0        /* FDC Status Byte 1 (STA1) bit 5 = 1: Sector ID or CRC error on disk */
                                        bne.s   @Tloc_E8CE
                                        btst    #0xD,d0         /* FDC Status Byte 2 (STA2) bit 5 = 1: Sector data CRC error */
                                        bne.s   @Tloc_E8CE
                                        jsr     F1031_IsOperationSuccessful
                                        beq.s   @Tloc_E8CE
                                        moveq   #1,d7           /* L5960_B_ReadSectorSucceeded = 1. Read succeeeded */
                                        bra.s   @Tloc_E8D0
                                @Tloc_E8CE:
                                        moveq   #0,d7           /* L5960_B_ReadSectorSucceeded = 0. Read failed */
                                @Tloc_E8D0:
                        }
                }
        }
        if (L5962_B_) {
                F2089_(P5969_ui_DriveIndex);
        }
        return L5960_B_ReadSectorSucceeded;
}

int16_t F2079_FormatFloppyDisk(unsigned int16_t P5973_ui_DriveIndex) {
        char* L5963_;
        long L5964_;
        long L5965_;
        int16_t L5966_;
        int16_t L5967_i_DriveAddress;
        int16_t L5968_;
        int16_t L5969_;
        int16_t L5970_;
        char L5971_[32];


        L5969_ = 0;
        L5970_ = 0;
        if ((P5973_ui_DriveIndex < 0) || (P5973_ui_DriveIndex >= G4194_.ui_0_DataDriveOrdinal)) {
                L5968_ = 0;
        } else {
                F2088_(P5973_ui_DriveIndex, 0);
                L5969_ = 1;
                L5967_i_DriveAddress = F2091_GetDriveAddress(P5973_ui_DriveIndex);
                L5966_ = L5967_i_DriveAddress + 112;
                L5963_ = (G2281_[0].UDS8_pc_6)(&G2281_[0]);
                L5970_ = 1;
                asm {
                                movem.l d3-d7/a2-a5,-(sp)
                                lea     L5971_(a6),a0
                                move.l  #0x103,d1
                                moveq   #8,d0
                        @Tloc_E95E:
                                move.l  d1,(a0)+
                                addi.w  #0x100,d1
                                subq.w  #1,d0
                                bne.s   @Tloc_E95E
                                move.l  #0x3000001,L5965_(a6)
                                clr.l   L5964_(a6)
                        @Tloc_E974:
                                moveq   #0x4D,d0        /* B_FORMAT */
                                move.w  L5966_(a6),d1
                                move.l  L5965_(a6),d2
                                moveq   #0x20,d3
                                lea     L5971_(a6),a1
                                trap    #0xF            /* TRAP 15 (IOCS CALL) */
                                tst.l   d0
                                bmi.w   @Tloc_E9EC
                                jsr     F1031_IsOperationSuccessful
                                beq.s   @Tloc_E9EC
                                move.l  L5965_(a6),d2
                                eori.l  #0x100,d2
                                eori.l  #1,L5964_(a6)
                                bne.s   @Tloc_E9AC
                                addi.l  #0x10000,d2
                        @Tloc_E9AC:
                                move.l  d2,L5965_(a6)
                                andi.l  #0xFF0000,d2
                                cmpi.l  #0x4D0000,d2
                                beq.s   @Tloc_E9F6
                                moveq   #0,d3
                                lea     L5971_(a6),a1
                                move.b  L5965_+1(a6),d2
                        @Tloc_E9C8:
                                move.b  d2,(a1)
                                addq.l  #4,a1
                                addq.w  #1,d3
                                cmpi.w  #8,d3
                                bne.s   @Tloc_E9C8
                                moveq   #0,d3
                                lea     L5971_+1(a6),a1
                                move.b  L5965_+2(a6),d2
                        @Tloc_E9DE:
                                move.b  d2,(a1)
                                addq.l  #4,a1
                                addq.w  #1,d3
                                cmpi.w  #8,d3
                                bne.s   @Tloc_E9DE
                                bra.s   @Tloc_E974
                        @Tloc_E9EC:
                                move.w  #0,L5968_(a6)
                                bra.w   @Tloc_EAFE
                        @Tloc_E9F6:
                                movea.l L5963_(a6),a0
                                move.l  #0xFEFFFF00,(a0)+
                                move.w  #0x1FE,d2
                                moveq   #0,d0
                        @Tloc_EA06:
                                move.l  d0,(a0)+
                                dbf     d2,@Tloc_EA06
                                move.w  L5966_(a6),d1
                                move.l  #0x3000002,d2
                                move.l  #0x800,d3
                                movea.l L5963_(a6),a1
                                moveq   #0x45,d0        /* B_WRITE */
                                trap    #0xF            /* TRAP 15 (IOCS CALL) */
                                dc.w    0x800
                                ori.b   #0xC2,(a6)+
                                btst    #0x15,d0
                                bne.s   @Tloc_E9EC
                                btst    #0xD,d0
                                bne.s   @Tloc_E9EC
                                move.w  L5966_(a6),d1
                                move.l  #0x3000004,d2
                                move.l  #0x800,d3
                                movea.l L5963_(a6),a1
                                moveq   #0x45,d0        /* B_WRITE */
                                trap    #0xF            /* TRAP 15 (IOCS CALL) */
                                dc.w    0x800
                                ori.b   #0x98,(a6)+
                                btst    #0x15,d0
                                bne.s   @Tloc_E9EC
                                btst    #0xD,d0
                                bne.s   @Tloc_E9EC
                                movea.l L5963_(a6),a0
                                move.w  #0x5FF,d2
                                moveq   #0,d1
                        @Tloc_EA6A:
                                move.l  d1,(a0)+
                                dbf     d2,@Tloc_EA6A
                                move.w  L5966_(a6),d1
                                move.l  #0x3000006,d2
                                move.l  #0x1800,d3
                                movea.l L5963_(a6),a1
                                moveq   #0x45,d0        /* B_WRITE */
                                trap    #0xF            /* TRAP 15 (IOCS CALL) */
                                dc.w    0x800
                                ori.b   #0,(a6)+
                                dc.w    0xFF5E          /* DOS CALL ???? */
                                btst    #0x15,d0
                                bne.w   @Tloc_E9EC
                                btst    #0xD,d0
                                bne.w   @Tloc_E9EC
                                movea.l L5963_(a6),a0
                                move.w  #0xFF,d2
                                moveq   #0,d0
                        @Tloc_EAAA:
                                move.l  d0,(a0)+
                                dbf     d2,@Tloc_EAAA
                                lea     G3901_(a5),a0
                                movea.l L5963_(a6),a1
                        @Tloc_EAB8:
                                move.b  (a0)+,d0
                                beq.s   @Tloc_EAC0
                                move.b  d0,(a1)+
                                bra.s   @Tloc_EAB8
                        @Tloc_EAC0:
                                move.w  L5966_(a6),d1
                                move.l  #0x3000001,d2
                                move.l  #0x400,d3
                                movea.l L5963_(a6),a1
                                moveq   #0x45,d0        /* B_WRITE */
                                trap    #0xF            /* TRAP 15 (IOCS CALL) */
                                btst    #0x1E,d0
                                bne.w   @Tloc_E9EC
                                btst    #0x15,d0
                                bne.w   @Tloc_E9EC
                                btst    #0xD,d0
                                bne.w   @Tloc_E9EC
                                jsr     F1031_IsOperationSuccessful
                                beq.w   @Tloc_E9EC
                                move.w  #1,L5968_(a6)
                        @Tloc_EAFE:
                                movem.l (sp)+,d3-d7/a2-a5
                }
        }
        if (L5970_) {
                (G2281_[0].UDS8_pc_A)(&G2281_[0]);
        }
        if (L5969_) {
                F2089_(P5973_ui_DriveIndex);
        }
        F2094_Call_DOS_FFLUSH();
        return L5968_;
}

#include "CEDT029.C"
#endif

#ifdef MEDIA674_F31E_F31J_X31J_P31J
#include "CEDTINC2.C"
#endif

#ifdef MEDIA671_F31E_F31J_P31J
#include "CEDTINC1.C"
#endif
#endif
