#ifndef COMPILE_H
#include "COMPILE.H"
#endif
#ifdef MEDIA767_AU2E
#define MASK0x1000_FILE_OPENED 0x1000
#define C110_MAX_FILENAME_LENGTH 110

#define C00_RESULT_SUCCESS                      0
#define C03_RESULT_                             3
#define C04_RESULT_                             4
#define C06_RESULT_                             6
#define C07_RESULT_                             7
#define C08_RESULT_                             8
#define C09_RESULT_DISK_IS_WRITE_PROTECTED      9
#define C12_RESULT_FILE_IS_NOT_OPENED          12
#define C17_RESULT_FILE_ALREADY_OPENED         17
#define C22_RESULT_                            22

extern char F7102_DoesFileNameMatchPattern();
extern unsigned int16_t F0090_strlen();
extern long F1362_IsFloppyDriveEmpty();
extern long F1107_GetDiskChangeCounter();
extern char FIO1_26_();
extern long F1363_IsFloppyDiskWriteProtected();

extern void F1344_UninitializeData();
extern void F1345_InitializeData();


typedef struct {
        int16_t _w_0x00_Signature;
        unsigned int16_t _ui_0x02_Flags;
        FILE_HANDLE _ps_0x04_FileHandle;
        unsigned char _uc_0x08_DelayAfterFileClosed;
        unsigned char _auc_0x09_FileName[C110_MAX_FILENAME_LENGTH];
        unsigned char _auc_0x77_DeviceName[C110_MAX_FILENAME_LENGTH]; /* + 1 padding byte for alignment */
        unsigned int16_t _ui_0xE6_FloppyDriveIndex;
        BOOLEAN _w_0xE8_UseDefaultFloppyDriveDeviceName;
} FIO1_FILE;


unsigned char G3441_[sizeof(struct InfoData) + 4]; /* Space to store a long aligned structure */
char G3870_ac_Unreferenced[224];
unsigned char G3321_[sizeof(struct InfoData) + 4]; /* Space to store a long aligned structure */
char* G3446_apc_FloppyDriveNames[4] = { "DF0:", "DF1:", "DF2:", "DF3:" };
long G3449_Unreferenced;
BOOLEAN G3443_aB_FloppyDrivePresent[5];
struct Process* G3445_as_DeviceProcess[5];
unsigned int16_t G3322_aui_DiskChangeCounter[5];
int16_t G3442_[4]; /* Probably static in F1327_FIO1_23_ */
char G3444_ac_FloppyDriveName[5] = "DF0:"; /* Probably static in F1345_InitializeData */


int16_t F1316_InitializeLibrary(
)
{
        F1345_InitializeData();
        return C00_RESULT_SUCCESS;
}

void F1317_UninitializeLibrary(
)
{
        ASM_STUB_PREFIX
        F1344_UninitializeData();
        ASM_STUB_SUFFIX
}

int16_t F1318_FIO1_29_(
FIO1_FILE* P4422_ps_FIO1File,
long P4423_,
char* P4493_pc_FileName)
{
        register FIO1_FILE* L4818_ps_FIO1File;
        register int16_t L4070_i_Result;


        ASM_STUB_PREFIX
        L4070_i_Result = C00_RESULT_SUCCESS;
        L4818_ps_FIO1File = P4422_ps_FIO1File;
        L4818_ps_FIO1File->_w_0x00_Signature = 0x52A3;
        L4818_ps_FIO1File->_ui_0x02_Flags = 0;
        L4818_ps_FIO1File->_uc_0x08_DelayAfterFileClosed = 0;
        L4818_ps_FIO1File->_ps_0x04_FileHandle = NULL;
        if (F0090_strlen(P4493_pc_FileName) >= C110_MAX_FILENAME_LENGTH) {
                L4070_i_Result = C03_RESULT_;
        } else {
                F0088_strcpy(L4818_ps_FIO1File->_auc_0x09_FileName, P4493_pc_FileName);
                F1347_(L4818_ps_FIO1File, &L4818_ps_FIO1File->_ui_0xE6_FloppyDriveIndex);
        }
        ASM_STUB_SUFFIX
        return L4070_i_Result;
}

int16_t F1319_FIO1_28_(
FIO1_FILE* P4424_ps_FIO1File)
{
        int16_t L4820_i_Result;
        FIO1_FILE* L4821_ps_FIO1File;


        ASM_STUB_PREFIX
        L4820_i_Result = C00_RESULT_SUCCESS;
        if (F1346_(P4424_ps_FIO1File, &L4821_ps_FIO1File) < 0) {
                L4820_i_Result = C03_RESULT_;
        } else {
                L4821_ps_FIO1File->_w_0x00_Signature = 0x52A4;
        }
        ASM_STUB_SUFFIX
        return L4820_i_Result;
}

long F1320_FIO1_27_(
)
{
        long L4822_;


        ASM_STUB_PREFIX
        L4822_ = 234; /* 0xEA */
        ASM_STUB_SUFFIX
        return L4822_;
}

void F1321_FIO1_07_SubstituteStringInFileName(
FIO1_FILE* P4425_ps_FIO1File,
char* P4426_pc_StringToReplace,
char* P4427_pc_ReplacementString)
{
        FIO1_FILE* L4823_ps_FIO1File;
        char L4824_ac_OutputFileName[C110_MAX_FILENAME_LENGTH];


        ASM_STUB_PREFIX
        if (F1346_(P4425_ps_FIO1File, &L4823_ps_FIO1File) >= 0) {
                if (F7097_strstr(P4426_pc_StringToReplace, L4823_ps_FIO1File->_auc_0x09_FileName) >= 0) {
                        if (F7098_SubstituteString(L4823_ps_FIO1File->_auc_0x09_FileName, P4426_pc_StringToReplace, P4427_pc_ReplacementString, L4824_ac_OutputFileName, C110_MAX_FILENAME_LENGTH) >= 0) {
                                F0088_strcpy(L4823_ps_FIO1File->_auc_0x09_FileName, L4824_ac_OutputFileName);
                        }
                }
        }
        ASM_STUB_SUFFIX
}

char F1322_FIO1_26_(
FIO1_FILE* P4428_ps_FIO1File)
{
        FIO1_FILE* L4825_ps_FIO1File;
        char L4826_;


        ASM_STUB_PREFIX
        L4826_ = 0;
        if (F1346_(P4428_ps_FIO1File, &L4825_ps_FIO1File) >= 0) {
                if (L4825_ps_FIO1File->_w_0xE8_UseDefaultFloppyDriveDeviceName) {
                        if ((F1107_GetDiskChangeCounter(L4825_ps_FIO1File->_ui_0xE6_FloppyDriveIndex) != G3322_aui_DiskChangeCounter[L4825_ps_FIO1File->_ui_0xE6_FloppyDriveIndex]) || F1362_IsFloppyDriveEmpty(L4825_ps_FIO1File->_ui_0xE6_FloppyDriveIndex)) {
                                G3322_aui_DiskChangeCounter[L4825_ps_FIO1File->_ui_0xE6_FloppyDriveIndex] = F1107_GetDiskChangeCounter(L4825_ps_FIO1File->_ui_0xE6_FloppyDriveIndex);
                                L4826_ = 1;
                        }
                }
        }
        ASM_STUB_SUFFIX
        return L4826_;
}

unsigned int16_t F1323_FIO1_25_(
FIO1_FILE* P4429_ps_FIO1File,
unsigned char* P4430_,
unsigned int16_t P4431_,
int16_t P4432_,
int16_t* P4433_)
{
        register unsigned char* L5083_;
        register unsigned char L5084_;
        register unsigned int16_t L5086_i_Result;
        register int16_t L5087_;
        unsigned char* L5076_;
        char* L5077_;
        FIO1_FILE* L5078_ps_FIO1File;
        unsigned int16_t L5079_;
        char L5080_ac_FileName[C110_MAX_FILENAME_LENGTH];
        char L5081_ac_FileName[C110_MAX_FILENAME_LENGTH];
        struct InfoData* L5082_ps_InfoData;
        struct FileLock* L5083_ps_FileLock;


        ASM_STUB_PREFIX
        *P4433_ = 0;
        L5079_ = 0;
        L5086_i_Result = C00_RESULT_SUCCESS;
        L5083_ps_FileLock = NULL;
        L5082_ps_InfoData = (struct InfoData*)(((long)G3441_ + 3) & 0xFFFFFFFC); /* structure must be long aligned */
        if (F1346_(P4429_ps_FIO1File, &L5078_ps_FIO1File) < 0) {
                L5086_i_Result = C03_RESULT_;
                goto loc_11D6;
        }
        F0088_strcpy(L5080_ac_FileName, L5078_ps_FIO1File->_auc_0x09_FileName);
        L5083_ = L5080_ac_FileName;
        for (L5076_ = L5083_; L5084_ = *L5083_; L5083_++) {
                if (L5084_ == '/') {
                        L5076_ = L5083_;
                }
                if (L5084_ == ':') {
                        L5076_ = L5083_;
                }
        }
        if (L5076_[1] == '\0') {
                L5086_i_Result = C03_RESULT_;
                goto loc_11D6;
        }
        L5076_++;
        F0088_strcpy(L5081_ac_FileName, L5076_);
        *L5076_ = '\0';
        if ((L5083_ps_FileLock = Lock(L5080_ac_FileName, ACCESS_READ)) == NULL) {
                L5086_i_Result = C22_RESULT_;
                goto loc_11D6;
        }
        L5083_ = P4430_;
        if (Examine(L5083_ps_FileLock, L5082_ps_InfoData) == 0) {
                goto loc_11CE;
        }
        L5077_ = &L5082_ps_InfoData->id_DiskState;
        do {
                if ((L5082_ps_InfoData->id_UnitNumber < 0) && F7102_DoesFileNameMatchPattern(L5077_, L5081_ac_FileName)) {
                        if (F0090_strlen(L5077_) + 1 > P4431_) {
                                *(L5077_ + P4431_ - 1) = 0;
                        }
                        F0088_strcpy(L5083_, L5077_);
                        L5083_ += P4431_;
                        L5079_++;
                }
        } while (ExNext(L5083_ps_FileLock, L5082_ps_InfoData) && (L5079_ < P4432_));
        loc_11CE:
        *P4433_ = L5079_;
        loc_11D6:
        if ((long)L5086_i_Result) {
                L5086_i_Result = C00_RESULT_SUCCESS;
                *P4433_ = 0;
        }
        if (L5083_ps_FileLock) {
                UnLock(L5083_ps_FileLock);
        }
        ASM_STUB_SUFFIX
        return L5086_i_Result;
}

int16_t F1324_FIO1_24_(
long P5022_,
long P5023_,
long P5024_,
int16_t* P5025_)
{
        register char* L5088_;
        register int16_t L5089_;
        register int16_t L5090_i_Result;
        register int16_t L5091_;
        char L5152_ac_Unreferenced[290];


        ASM_STUB_PREFIX
        *P5025_ = 0;
        L5090_i_Result = C00_RESULT_SUCCESS;
        ASM_STUB_SUFFIX
        return L5090_i_Result;
}

BOOLEAN F1325_FIO1_04_IsDiskWriteable(
FIO1_FILE* P4434_ps_FIO1File)
{
        BOOLEAN L5092_;
        FIO1_FILE* L5093_ps_FIO1File;


        ASM_STUB_PREFIX
        L5092_ = C0_FALSE;
        if (F1346_(P4434_ps_FIO1File, &L5093_ps_FIO1File) >= 0) {
                if (L5093_ps_FIO1File->_w_0xE8_UseDefaultFloppyDriveDeviceName) {
                        L5092_ = F1349_IsDiskWriteProtected(L5093_ps_FIO1File->_w_0xE8_UseDefaultFloppyDriveDeviceName, L5093_ps_FIO1File->_ui_0xE6_FloppyDriveIndex) == 0;
                }
        }
        ASM_STUB_SUFFIX
        return L5092_;
}

int16_t F1326_FIO1_05_FormatSaveDisk(
FIO1_FILE* P4435_ps_FIO1File)
{
        int16_t L5094_i_Result;
        FIO1_FILE* L5095_ps_FIO1File;


        ASM_STUB_PREFIX
        L5094_i_Result = C03_RESULT_;
        if (FIO1_04_IsDiskWriteable(P4435_ps_FIO1File) >= 0) {
                if (F1346_(P4435_ps_FIO1File, &L5095_ps_FIO1File) >= 0) {
                        if (L5095_ps_FIO1File->_w_0xE8_UseDefaultFloppyDriveDeviceName) {
                                if (F0519_FLOPPY_GetFormatResult(L5095_ps_FIO1File->_ui_0xE6_FloppyDriveIndex, "DungeonSave") == 0) {
                                        L5094_i_Result = C00_RESULT_SUCCESS;
                                } else {
                                        L5094_i_Result = C08_RESULT_;
                                }
                        }
                }
        }
        ASM_STUB_SUFFIX
        return L5094_i_Result;
}

int16_t F1327_FIO1_23_(
FIO1_FILE* P4436_ps_FIO1File,
int16_t* P4437_)
{
        int16_t L5096_i_Result;
        int16_t L5097_;
        FIO1_FILE* L5098_ps_FIO1File;
        struct InfoData* L5099_ps_InfoData;
        struct FileLock* L5100_ps_FileLock;


        ASM_STUB_PREFIX
        L5097_ = 0;
        L5096_i_Result = C00_RESULT_SUCCESS;
        L5099_ps_InfoData = (struct InfoData*)(((long)G3441_ + 3) & 0xFFFFFFFC); /* structure must be long aligned */
        L5100_ps_FileLock = NULL;
        if (F1346_(P4436_ps_FIO1File, &L5098_ps_FIO1File) < 0) {
                L5096_i_Result = C03_RESULT_;
        } else {
                if (L5098_ps_FIO1File->_w_0xE8_UseDefaultFloppyDriveDeviceName) {
                        F1348_IsFloppyDiskInDrive(L5098_ps_FIO1File->_ui_0xE6_FloppyDriveIndex, L5098_ps_FIO1File->_auc_0x77_DeviceName);
                        if ((G3442_[L5098_ps_FIO1File->_ui_0xE6_FloppyDriveIndex] == 0) || FIO1_26_(P4436_ps_FIO1File)) {
                                if ((L5100_ps_FileLock = Lock(L5098_ps_FIO1File->_auc_0x77_DeviceName, ACCESS_READ)) == NULL) {
                                        L5096_i_Result = C22_RESULT_;
                                } else {
                                        if (Examine(L5100_ps_FileLock, L5099_ps_InfoData)) {
                                                if (F0087_strcmp("FTL_CSB_Utility", &L5099_ps_InfoData->id_DiskState) == 0) {
                                                        L5097_ = 3;
                                                } else {
                                                        L5097_ = 1;
                                                }
                                        } else {
                                                L5096_i_Result = C22_RESULT_;
                                        }
                                }
                        } else {
                                L5097_ = G3442_[L5098_ps_FIO1File->_ui_0xE6_FloppyDriveIndex];
                        }
                } else {
                        L5097_ = 1;
                }
        }
        if (L5098_ps_FIO1File->_w_0xE8_UseDefaultFloppyDriveDeviceName) {
                G3442_[L5098_ps_FIO1File->_ui_0xE6_FloppyDriveIndex] = L5097_;
        }
        if (L5100_ps_FileLock) {
                UnLock(L5100_ps_FileLock);
        }
        *P4437_ = L5097_;
        ASM_STUB_SUFFIX
        return L5096_i_Result;
}

int16_t F1328_FIO1_22_(
FIO1_FILE* P4438_ps_FIO1File)
{
        unsigned int16_t L5101_i_Result;
        char* L5102_;


        ASM_STUB_PREFIX
        if (F1346_(P4438_ps_FIO1File, &L5102_) < 0) {
                L5101_i_Result = C03_RESULT_;
        } else {
                L5101_i_Result = FIO1_21_Open(P4438_ps_FIO1File, 0);
                if ((long)L5101_i_Result == 0) {
                        FIO1_19_Close(P4438_ps_FIO1File);
                } else {
                        L5101_i_Result = C17_RESULT_FILE_ALREADY_OPENED;
                }
        }
        ASM_STUB_SUFFIX
        return L5101_i_Result;
}

int16_t F1329_FIO1_21_Open(
FIO1_FILE* P4439_ps_FIO1File,
unsigned char P4440_)
{
        register FILE_HANDLE L5103_ps_FileHandle;
        register int16_t L5104_i_Result;
        FIO1_FILE* L5105_ps_FIO1File;


        ASM_STUB_PREFIX
        if (F1346_(P4439_ps_FIO1File, &L5105_ps_FIO1File) < 0) {
                L5104_i_Result = C03_RESULT_;
        } else {
                if (M007_GET(L5105_ps_FIO1File->_ui_0x02_Flags, MASK0x1000_FILE_OPENED)) {
                        L5104_i_Result = C17_RESULT_FILE_ALREADY_OPENED;
                } else {
                        if (L5105_ps_FIO1File->_w_0xE8_UseDefaultFloppyDriveDeviceName) {
                                F1348_IsFloppyDiskInDrive(L5105_ps_FIO1File->_ui_0xE6_FloppyDriveIndex, L5105_ps_FIO1File->_auc_0x77_DeviceName);
                        }
                        if ((L5103_ps_FileHandle = F0770_FILE_Open(L5105_ps_FIO1File->_auc_0x09_FileName, P4440_)) == NULL) {
                                L5104_i_Result = C04_RESULT_;
                        } else {
                                L5105_ps_FIO1File->_uc_0x08_DelayAfterFileClosed = P4440_;
                                L5104_i_Result = C00_RESULT_SUCCESS;
                                M008_SET(L5105_ps_FIO1File->_ui_0x02_Flags, MASK0x1000_FILE_OPENED);
                                L5105_ps_FIO1File->_ps_0x04_FileHandle = L5103_ps_FileHandle;
                        }
                }
        }
        ASM_STUB_SUFFIX
        return L5104_i_Result;
}

int16_t F1330_FIO1_20_Create(
FIO1_FILE* P4441_ps_FIO1File)
{
        register FILE_HANDLE L5106_ps_FileHandle;
        register int16_t L5107_i_Result;
        FIO1_FILE* L5108_ps_FIO1File;


        ASM_STUB_PREFIX
        if (F1346_(P4441_ps_FIO1File, &L5108_ps_FIO1File) < 0) {
                L5107_i_Result = C03_RESULT_;
        } else {
                if (M007_GET(L5108_ps_FIO1File->_ui_0x02_Flags, MASK0x1000_FILE_OPENED)) {
                        L5107_i_Result = C17_RESULT_FILE_ALREADY_OPENED;
                } else {
                        L5108_ps_FIO1File->_uc_0x08_DelayAfterFileClosed = 2;
                        if (L5108_ps_FIO1File->_w_0xE8_UseDefaultFloppyDriveDeviceName) {
                                F1348_IsFloppyDiskInDrive(L5108_ps_FIO1File->_ui_0xE6_FloppyDriveIndex, L5108_ps_FIO1File->_auc_0x77_DeviceName);
                        }
                        if (F1349_IsDiskWriteProtected(L5108_ps_FIO1File->_w_0xE8_UseDefaultFloppyDriveDeviceName, L5108_ps_FIO1File->_ui_0xE6_FloppyDriveIndex) == C0_FALSE) {
                                if ((L5106_ps_FileHandle = F0776_FILE_Create(L5108_ps_FIO1File->_auc_0x09_FileName)) == NULL) {
                                        L5107_i_Result = C08_RESULT_;
                                } else {
                                        L5107_i_Result = C00_RESULT_SUCCESS;
                                        M008_SET(L5108_ps_FIO1File->_ui_0x02_Flags, MASK0x1000_FILE_OPENED);
                                        L5108_ps_FIO1File->_ps_0x04_FileHandle = L5106_ps_FileHandle;
                                }
                        } else {
                                L5107_i_Result = C09_RESULT_DISK_IS_WRITE_PROTECTED;
                        }
                }
        }
        ASM_STUB_SUFFIX
        return L5107_i_Result;
}

int16_t F1331_FIO1_19_Close(
FIO1_FILE* P4442_ps_FIO1File)
{
        register int16_t L5109_i_Result;
        FIO1_FILE* L5110_ps_FIO1File;


        ASM_STUB_PREFIX
        if (F1346_(P4442_ps_FIO1File, &L5110_ps_FIO1File) < 0) {
                L5109_i_Result = C03_RESULT_;
        } else {
                if (!M007_GET(L5110_ps_FIO1File->_ui_0x02_Flags, MASK0x1000_FILE_OPENED)) {
                        L5109_i_Result = C12_RESULT_FILE_IS_NOT_OPENED;
                } else {
                        F0771_FILE_Close(L5110_ps_FIO1File->_ps_0x04_FileHandle);
                        if ((L5110_ps_FIO1File->_uc_0x08_DelayAfterFileClosed == 2) || (L5110_ps_FIO1File->_uc_0x08_DelayAfterFileClosed == 1)) {
                                Delay(200L);
                        }
                        L5109_i_Result = C00_RESULT_SUCCESS;
                        M009_CLEAR(L5110_ps_FIO1File->_ui_0x02_Flags, MASK0x1000_FILE_OPENED);
                }
        }
        ASM_STUB_SUFFIX
        return L5109_i_Result;
}

int16_t F1332_FIO1_18_GetSize(
FIO1_FILE* P4443_ps_FIO1File,
long* P4444_pl_ByteCount)
{
        register int16_t L5111_i_Result;
        FIO1_FILE* L5112_ps_FIO1File;
        long L5113_l_Unreferenced;


        ASM_STUB_PREFIX
        if (F1346_(P4443_ps_FIO1File, &L5112_ps_FIO1File) < 0) {
                L5111_i_Result = C03_RESULT_;
        } else {
                if (!M007_GET(L5112_ps_FIO1File->_ui_0x02_Flags, MASK0x1000_FILE_OPENED)) {
                        L5111_i_Result = C12_RESULT_FILE_IS_NOT_OPENED;
                } else {
                        if ((*P4444_pl_ByteCount = F0775_FILE_GetSize(L5112_ps_FIO1File->_ps_0x04_FileHandle)) == -1) {
                                L5111_i_Result = C22_RESULT_;
                        } else {
                                L5111_i_Result = C00_RESULT_SUCCESS;
                        }
                }
        }
        ASM_STUB_SUFFIX
        return L5111_i_Result;
}

int16_t F1333_FIO1_17_Tell(
FIO1_FILE* P4445_ps_FIO1File,
long* P4446_)
{
        int16_t L5114_i_Result;
        FIO1_FILE* L5115_ps_FIO1File;


        ASM_STUB_PREFIX
        L5114_i_Result = C00_RESULT_SUCCESS;
        if (F1346_(P4445_ps_FIO1File, &L5115_ps_FIO1File) < 0) {
                L5114_i_Result = C03_RESULT_;
        } else {
                if (!M007_GET(L5115_ps_FIO1File->_ui_0x02_Flags, MASK0x1000_FILE_OPENED)) {
                        L5114_i_Result = C12_RESULT_FILE_IS_NOT_OPENED;
                } else {
                        if ((*P4446_ = F0779_FILE_Tell(L5115_ps_FIO1File->_ps_0x04_FileHandle)) == -1) {
                                L5114_i_Result = C22_RESULT_;
                        }
                }
        }
        ASM_STUB_SUFFIX
        return L5114_i_Result;
}

int16_t F1334_FIO1_16_Seek(
FIO1_FILE* P4447_ps_FIO1File,
long P4448_)
{
        register int16_t L5116_i_Result;
        FIO1_FILE* L5117_ps_FIO1File;


        ASM_STUB_PREFIX
        L5116_i_Result = C00_RESULT_SUCCESS;
        if (F1346_(P4447_ps_FIO1File, &L5117_ps_FIO1File) < 0) {
                L5116_i_Result = C03_RESULT_;
        } else {
                if (!M007_GET(L5117_ps_FIO1File->_ui_0x02_Flags, MASK0x1000_FILE_OPENED)) {
                        L5116_i_Result = C12_RESULT_FILE_IS_NOT_OPENED;
                } else {
                        if (P4448_ > 0x7FFFFFFF) {
                                L5116_i_Result = C03_RESULT_;
                        } else {
                                if (F0774_FILE_Seek(L5117_ps_FIO1File->_ps_0x04_FileHandle, P4448_) == -1) {
                                        L5116_i_Result = C03_RESULT_;
                                }
                        }
                }
        }
        ASM_STUB_SUFFIX
        return L5116_i_Result;
}

int16_t F1335_FIO1_15_Read(
FIO1_FILE* P4449_ps_FIO1File,
unsigned long P4450_ul_ByteCount,
unsigned char* P4451_puc_Buffer)
{
        register int16_t L5118_i_Result;
        FIO1_FILE* L5119_ps_FIO1File;


        ASM_STUB_PREFIX
        L5118_i_Result = C00_RESULT_SUCCESS;
        if (F1346_(P4449_ps_FIO1File, &L5119_ps_FIO1File) < 0) {
                L5118_i_Result = C03_RESULT_;
        } else {
                if (!M007_GET(L5119_ps_FIO1File->_ui_0x02_Flags, MASK0x1000_FILE_OPENED)) {
                        L5118_i_Result = C12_RESULT_FILE_IS_NOT_OPENED;
                } else {
                        if (P4450_ul_ByteCount) {
                                if (P4450_ul_ByteCount > 0x7FFFFFFF) {
                                        L5118_i_Result = C03_RESULT_;
                                } else {
                                        if (F0772_FILE_Read(L5119_ps_FIO1File->_ps_0x04_FileHandle, P4450_ul_ByteCount, P4451_puc_Buffer) == 0) {
                                                L5118_i_Result = C07_RESULT_;
                                        }
                                }
                        }
                }
        }
        ASM_STUB_SUFFIX
        return L5118_i_Result;
}

int16_t F1336_FIO1_14_Write(
FIO1_FILE* P4452_ps_FIO1File,
unsigned long P4453_ul_ByteCount,
unsigned char* P4454_puc_Buffer)
{
        register unsigned int16_t L5120_i_Result;
        FIO1_FILE* L5121_ps_FIO1File;
        unsigned long L5122_;


        ASM_STUB_PREFIX
        L5120_i_Result = C00_RESULT_SUCCESS;
        if (F1346_(P4452_ps_FIO1File, &L5121_ps_FIO1File) < 0) {
                L5120_i_Result = C03_RESULT_;
        } else {
                if (!M007_GET(L5121_ps_FIO1File->_ui_0x02_Flags, MASK0x1000_FILE_OPENED)) {
                        L5120_i_Result = C12_RESULT_FILE_IS_NOT_OPENED;
                } else {
                        if (P4453_ul_ByteCount != 0) {
                                if (P4453_ul_ByteCount > 0x7FFFFFFF) {
                                        L5120_i_Result = C03_RESULT_;
                                } else {
                                        if (F0773_FILE_Write(L5121_ps_FIO1File->_ps_0x04_FileHandle, P4453_ul_ByteCount, P4454_puc_Buffer) == 0) {
                                                if (F1349_IsDiskWriteProtected(L5121_ps_FIO1File->_w_0xE8_UseDefaultFloppyDriveDeviceName, L5121_ps_FIO1File->_ui_0xE6_FloppyDriveIndex)) {
                                                        L5120_i_Result = C09_RESULT_DISK_IS_WRITE_PROTECTED;
                                                } else {
                                                        L5120_i_Result = FIO1_13_Lock(P4452_ps_FIO1File, &L5122_);
                                                        if (((long)L5120_i_Result == 0) && (L5122_ < P4453_ul_ByteCount)) {
                                                                L5120_i_Result = C06_RESULT_;
                                                        } else {
                                                                L5120_i_Result = C08_RESULT_;
                                                        }
                                                }
                                        }
                                }
                        }
                }
        }
        ASM_STUB_SUFFIX
        return L5120_i_Result;
}

int16_t F1337_FIO1_13_Lock(
FIO1_FILE* P4401_ps_FIO1File,
long* P4402_)
{
        register int16_t L4800_i_Result;
        FIO1_FILE* L4799_ps_FIO1File;
        struct InfoData* L4797_ps_InfoData;
        struct FileLock* L4798_ps_FileLock;


        ASM_STUB_PREFIX
        L4798_ps_FileLock = NULL;
        L4797_ps_InfoData = (struct InfoData*)(((long)G3321_ + 3) & 0xFFFFFFFC); /* structure must be long aligned */
        if (F1346_(P4401_ps_FIO1File, &L4799_ps_FIO1File) < 0) {
                L4800_i_Result = C03_RESULT_;
        } else {
                if ((L4798_ps_FileLock = Lock(L4799_ps_FIO1File->_auc_0x77_DeviceName, ACCESS_READ)) == NULL) {
                        L4800_i_Result = C22_RESULT_;
                } else {
                        if (Info(L4798_ps_FileLock, L4797_ps_InfoData)) {
                                *P4402_ = L4797_ps_InfoData->id_NumBlocks * L4797_ps_InfoData->id_BytesPerBlock;
                                L4800_i_Result = C00_RESULT_SUCCESS;
                        } else {
                                L4800_i_Result = C22_RESULT_;
                        }
                }
        }
        if (L4798_ps_FileLock) {
                UnLock(L4798_ps_FileLock);
        }
        ASM_STUB_SUFFIX
        return L4800_i_Result;
}

int16_t F1338_FIO1_12_Delete(
FIO1_FILE* P4455_ps_FIO1File)
{
        register int16_t L5123_i_Result;
        FIO1_FILE* L5124_ps_FIO1File;


        ASM_STUB_PREFIX
        if (F1346_(P4455_ps_FIO1File, &L5124_ps_FIO1File) < 0) {
                L5123_i_Result = C03_RESULT_;
        } else {
                if (M007_GET(L5124_ps_FIO1File->_ui_0x02_Flags, MASK0x1000_FILE_OPENED)) {
                        L5123_i_Result = C12_RESULT_FILE_IS_NOT_OPENED;
                } else {
                        if (F0777_FILE_Delete(L5124_ps_FIO1File->_auc_0x09_FileName)) {
                                L5123_i_Result = C00_RESULT_SUCCESS;
                        } else {
                                if (F1349_IsDiskWriteProtected(L5124_ps_FIO1File->_w_0xE8_UseDefaultFloppyDriveDeviceName, L5124_ps_FIO1File->_ui_0xE6_FloppyDriveIndex)) {
                                        L5123_i_Result = C09_RESULT_DISK_IS_WRITE_PROTECTED;
                                } else {
                                        L5123_i_Result = C04_RESULT_;
                                }
                        }
                }
        }
        ASM_STUB_SUFFIX
        return L5123_i_Result;
}

int16_t F1339_FIO1_11_Rename(
FIO1_FILE* P4456_ps_FIO1File,
FIO1_FILE* P4457_ps_FIO1File)
{
        register int16_t L5125_i_Result;
        FIO1_FILE* L5126_ps_FIO1File;
        FIO1_FILE* L5127_ps_FIO1File;


        ASM_STUB_PREFIX
        if ((F1346_(P4456_ps_FIO1File, &L5126_ps_FIO1File) < 0) || (F1346_(P4457_ps_FIO1File, &L5127_ps_FIO1File) < 0)) {
                L5125_i_Result = C03_RESULT_;
        } else {
                if (M007_GET(L5126_ps_FIO1File->_ui_0x02_Flags, MASK0x1000_FILE_OPENED) || M007_GET(L5127_ps_FIO1File->_ui_0x02_Flags, MASK0x1000_FILE_OPENED)) {
                        L5125_i_Result = C12_RESULT_FILE_IS_NOT_OPENED;
                } else {
                        if (F0778_FILE_Rename(L5126_ps_FIO1File->_auc_0x09_FileName, L5127_ps_FIO1File->_auc_0x09_FileName)) {
                                L5125_i_Result = C00_RESULT_SUCCESS;
                        } else {
                                if (F1349_IsDiskWriteProtected(L5126_ps_FIO1File->_w_0xE8_UseDefaultFloppyDriveDeviceName, L5126_ps_FIO1File->_ui_0xE6_FloppyDriveIndex)) {
                                        L5125_i_Result = C09_RESULT_DISK_IS_WRITE_PROTECTED;
                                } else {
                                        L5125_i_Result = C04_RESULT_;
                                }
                        }
                }
        }
        ASM_STUB_SUFFIX
        return L5125_i_Result;
}

int16_t F1340_FIO1_09_(
)
{
        int16_t L5128_i_DriveIndex;
        int16_t L5129_;


        ASM_STUB_PREFIX
        for (L5128_i_DriveIndex = 0, L5129_ = 0; L5128_i_DriveIndex < 4; L5128_i_DriveIndex++) {
                if (F1106_IsTrackdiskDeviceOpened(L5128_i_DriveIndex)) {
                        L5129_++;
                }
        }
        ASM_STUB_SUFFIX
        return L5129_;
}

char F1341_FIO1_10_(
FIO1_FILE* P4458_ps_FIO1File)
{
        FIO1_FILE* L5130_ps_FIO1File;
        char L5131_;


        ASM_STUB_PREFIX
        if ((F1346_(P4458_ps_FIO1File, &L5130_ps_FIO1File) < 0) || !M007_GET(L5130_ps_FIO1File->_ui_0x02_Flags, MASK0x1000_FILE_OPENED)) {
                L5131_ = 1;
        } else {
                L5131_ = 0;
        }
        ASM_STUB_SUFFIX
        return L5131_;
}

void F1342_FIO1_08_(
FIO1_FILE* P4459_ps_FIO1File,
char* P4460_)
{
        register unsigned char* L5136_;
        register unsigned int16_t L5137_;
        register unsigned int16_t L5138_;
        FIO1_FILE* L5139_ps_FIO1File;
        char L5140_ac_FileName[C110_MAX_FILENAME_LENGTH];


        ASM_STUB_PREFIX
        if (F1346_(P4459_ps_FIO1File, &L5139_ps_FIO1File) >= 0) {
                L5136_ = L5139_ps_FIO1File->_auc_0x09_FileName;
                for (L5137_ = 0; L5136_[L5137_] && (L5136_[L5137_] != '*') && (L5137_ < (sizeof(L5140_ac_FileName) - 1)); L5137_++) {
                        L5140_ac_FileName[L5137_] = L5136_[L5137_];
                }
                if (L5136_[L5137_] == '*') {
                        L5138_ = 0;
                        while ((P4460_[L5138_] != '\0') && (L5137_ < (sizeof(L5140_ac_FileName) - 1))) {
                                L5140_ac_FileName[L5137_++] = P4460_[L5138_++];
                        }
                        L5140_ac_FileName[L5137_] = '\0';
                        F0088_strcpy(L5136_, L5140_ac_FileName);
                }
        }
        ASM_STUB_SUFFIX
}

int16_t F1343_FIO1_06_(
FIO1_FILE* P4461_ps_FIO1File,
int16_t P4462_,
char** P4463_)
{
        register int16_t L5141_i_Result;
        FIO1_FILE* L5142_ps_FIO1File;


        ASM_STUB_PREFIX
        if (F1346_(P4461_ps_FIO1File, &L5142_ps_FIO1File) < 0) {
                L5141_i_Result = C03_RESULT_;
        } else {
                L5141_i_Result = C00_RESULT_SUCCESS;
                switch (P4462_) {
                        case 14:
                                if (L5142_ps_FIO1File->_w_0xE8_UseDefaultFloppyDriveDeviceName) {
                                        *P4463_ = G3446_apc_FloppyDriveNames[L5142_ps_FIO1File->_ui_0xE6_FloppyDriveIndex];
                                } else {
                                        *P4463_ = L5142_ps_FIO1File->_auc_0x77_DeviceName;
                                }
                                break;
                        default:
                                L5141_i_Result = C03_RESULT_;
                }
        }
        ASM_STUB_SUFFIX
        return L5141_i_Result;
}

void F1344_UninitializeData(
)
{
        F0518_FLOPPY_Deinitialize_CPSX();
}

void F1345_InitializeData(
)
{
        int16_t L5134_i_DriveIndex;


        F1111_CPSX();
        for (L5134_i_DriveIndex = 0; L5134_i_DriveIndex < 4; L5134_i_DriveIndex++) {
                if (F1106_IsTrackdiskDeviceOpened(L5134_i_DriveIndex)) {
                        G3443_aB_FloppyDrivePresent[L5134_i_DriveIndex] = C1_TRUE;
                        G3444_ac_FloppyDriveName[2] = '0' + L5134_i_DriveIndex;
                        G3445_as_DeviceProcess[L5134_i_DriveIndex] = DeviceProc(G3444_ac_FloppyDriveName);
                        G3322_aui_DiskChangeCounter[L5134_i_DriveIndex] = F1107_GetDiskChangeCounter(L5134_i_DriveIndex);
                }
        }
}

int16_t F1346_(
FIO1_FILE* P4464_ps_FIO1File,
FIO1_FILE** P4465_pps_FIO1File)
{
        register FIO1_FILE* L5132_ps_FIO1File;
        register int16_t L5133_;


        L5133_ = 0;
        L5132_ps_FIO1File = P4464_ps_FIO1File;
        *P4465_pps_FIO1File = L5132_ps_FIO1File;
        if (L5132_ps_FIO1File->_w_0x00_Signature != 0x52A3) {
                L5133_ = -1;
        }
        return L5133_;
}

int16_t F1347_(
FIO1_FILE* P4466_ps_FIO1File,
int16_t* P4467_)
{
        unsigned int16_t L5143_ui_FloppyDriveIndex;
        int16_t L5144_;
        int16_t L5145_;
        unsigned char L5146_;
        FIO1_FILE* L5147_ps_FIO1File;
        struct Process* L5148_ps_Process;


        if (F1346_(P4466_ps_FIO1File, &L5147_ps_FIO1File) < 0) {
                return C03_RESULT_;
        }
        L5143_ui_FloppyDriveIndex = 0;
        L5147_ps_FIO1File->_w_0xE8_UseDefaultFloppyDriveDeviceName = C0_FALSE;
        if ((L5147_ps_FIO1File->_auc_0x09_FileName[3] == ':') || (L5147_ps_FIO1File->_auc_0x09_FileName[1] == ':')) {
                if ((L5147_ps_FIO1File->_auc_0x09_FileName[1] == ':')) {
                        L5143_ui_FloppyDriveIndex = L5147_ps_FIO1File->_auc_0x09_FileName[0] - '1';
                        L5147_ps_FIO1File->_w_0xE8_UseDefaultFloppyDriveDeviceName = C1_TRUE;
                } else {
                        if (L5147_ps_FIO1File->_auc_0x09_FileName[3] == ':') {
                                L5143_ui_FloppyDriveIndex = L5147_ps_FIO1File->_auc_0x09_FileName[2] - '0';
                                if ((L5147_ps_FIO1File->_auc_0x09_FileName[1] != 'f') && (L5147_ps_FIO1File->_auc_0x09_FileName[1] != 'F')) {
                                        L5143_ui_FloppyDriveIndex = 0;
                                        L5147_ps_FIO1File->_w_0xE8_UseDefaultFloppyDriveDeviceName = C0_FALSE;
                                } else {
                                        L5147_ps_FIO1File->_w_0xE8_UseDefaultFloppyDriveDeviceName = C1_TRUE;
                                }
                        }
                }
                if (L5143_ui_FloppyDriveIndex > 0) {
                        if (G3443_aB_FloppyDrivePresent[L5143_ui_FloppyDriveIndex] == C0_FALSE) {
                                while (L5143_ui_FloppyDriveIndex < 4) {
                                        if (G3443_aB_FloppyDrivePresent[L5143_ui_FloppyDriveIndex] != C0_FALSE) {
                                                break;
                                        }
                                        L5143_ui_FloppyDriveIndex++;
                                }
                        }
                        if (G3443_aB_FloppyDrivePresent[L5143_ui_FloppyDriveIndex] == C0_FALSE) {
                                L5143_ui_FloppyDriveIndex = 0;
                        }
                        L5147_ps_FIO1File->_w_0xE8_UseDefaultFloppyDriveDeviceName = C1_TRUE;
                }
        }
        if (L5147_ps_FIO1File->_w_0xE8_UseDefaultFloppyDriveDeviceName) {
                F0088_strcpy(L5147_ps_FIO1File->_auc_0x77_DeviceName, G3446_apc_FloppyDriveNames[L5143_ui_FloppyDriveIndex]);
                if (L5147_ps_FIO1File->_auc_0x09_FileName[1] == ':') {
                        F0086_strcat(L5147_ps_FIO1File->_auc_0x77_DeviceName, &L5147_ps_FIO1File->_auc_0x09_FileName[2]);
                        F0088_strcpy(L5147_ps_FIO1File->_auc_0x09_FileName, L5147_ps_FIO1File->_auc_0x77_DeviceName);
                        F0088_strcpy(L5147_ps_FIO1File->_auc_0x77_DeviceName, G3446_apc_FloppyDriveNames[L5143_ui_FloppyDriveIndex]);
                }
        } else {
                L5145_ = 0;
                L5144_ = 0;
                while ((L5146_ = L5147_ps_FIO1File->_auc_0x09_FileName[L5144_++]) != 0) {
                        L5147_ps_FIO1File->_auc_0x77_DeviceName[L5145_++] = L5146_;
                        if (L5146_ == ':') {
                                break;
                        }
                        if (L5145_ <= 29) {
                                continue;
                        }
                        if (L5147_ps_FIO1File->_auc_0x09_FileName[L5144_] != ':') {
                                break;
                        }
                }
                if (L5146_ != ':') {
                        L5147_ps_FIO1File->_auc_0x77_DeviceName[L5145_++] = ':';
                }
                L5147_ps_FIO1File->_auc_0x77_DeviceName[L5145_] = '\0';
        }
        L5148_ps_Process = DeviceProc(L5147_ps_FIO1File->_auc_0x77_DeviceName);
        if (L5148_ps_Process) {
                for (L5144_ = 0; L5144_ < 4; L5144_++) {
                        if (G3445_as_DeviceProcess[L5144_] == L5148_ps_Process) {
                                L5147_ps_FIO1File->_w_0xE8_UseDefaultFloppyDriveDeviceName = C1_TRUE;
                                L5143_ui_FloppyDriveIndex = L5144_;
                                break;
                        }
                }
        }
        *P4467_ = L5143_ui_FloppyDriveIndex;
        return C00_RESULT_SUCCESS;
}

BOOLEAN F1348_IsFloppyDiskInDrive(
int16_t P4468_i_FloppyDriveIndex,
char* P4469_pc_FileName)
{
        int16_t L4831_i_Counter;
        struct FileLock* L4832_ps_FileLock;
        int16_t L4833_i_DiskState;
        BOOLEAN L4834_B_FloppyDiskInDrive;


        L4831_i_Counter = 0;
        L4834_B_FloppyDiskInDrive = C0_FALSE;
        L4832_ps_FileLock = NULL;
        if (F1362_IsFloppyDriveEmpty(P4468_i_FloppyDriveIndex) == 0) {
                L4834_B_FloppyDiskInDrive = C1_TRUE;
                goto loc_2026;
        }
        do {
                if (L4831_i_Counter) {
                        Delay(12L);
                }
                L4833_i_DiskState = F1109_GetDiskState(P4468_i_FloppyDriveIndex);
        } while (!L4833_i_DiskState && L4831_i_Counter++ < 12);
        if (L4833_i_DiskState) {
                L4834_B_FloppyDiskInDrive = C1_TRUE;
                loc_2026:
                L4831_i_Counter = 0;
                do {
                        if (L4831_i_Counter) {
                                Delay(6L);
                        }
                        L4832_ps_FileLock = Lock(P4469_pc_FileName); /* BUGX_XX: second parameter missing in call. No consequence because the lock is not used */
                } while ((L4832_ps_FileLock == NULL) && L4831_i_Counter++ < 20);
        }
        if (L4832_ps_FileLock) {
                UnLock(L4832_ps_FileLock);
        }
        return L4834_B_FloppyDiskInDrive;
}

BOOLEAN F1349_IsDiskWriteProtected(
BOOLEAN P4470_B_IsFloppyDisk,
unsigned int16_t P4471_ui_DriveIndex)
{
        if (P4470_B_IsFloppyDisk) {
                if (F1363_IsFloppyDiskWriteProtected(P4471_ui_DriveIndex) == 0) {
                        return C0_FALSE;
                } else {
                        return C1_TRUE;
                }
        }
        return C0_FALSE;
}
#endif
