#ifndef COMPILE_H
#include "COMPILE.H"
#endif
#ifdef MEDIA774_SU1E_AU1E_AU2E
#undef Floprd
#define Floprd(a, b, c, d, e, f, g) (long)R0056_TOS_CallXBIOS(0x08, a, b, c, d, e, f, g)

extern void F1762_();
extern unsigned char** F7227_RequestMemoryHandle();
extern long F1857_PerformIORequestOperation();
extern long F1770_();
extern char* F0088_strcpy();
extern char* F0086_strcat();
extern unsigned int16_t F0090_strlen();
extern long F7101_sprintf();
extern long F7228_FreeMemory();


extern int16_t G3545_i_Counter;


IOREQ** G3670_IORequests;
unsigned char** G3671_puc_IOBuffer;
int16_t G3675_;
unsigned int16_t G3669_ui_IORequestCount;
char G3673_ac_FileName[22];
char G3674_ac_FileName[22];
#ifdef MEDIA772_SU1E
char* G3672_apc_DriveLetters[5] = { "A:\\", "B:\\", "C:\\", "D:\\", "E:\\" };
#endif
#ifdef MEDIA763_AU1E_AU2E
unsigned int16_t G3859_;
char* G3672_apc_DriveLetters[4] = { "DF0:", "DF1:", "DF2:", "DF3:" };
#endif
/* strings, border between two .C source files */


IOREQ* F1836_GetIORequest(int16_t P5609_i_IORequestIndex) {
        register IOREQ* L5459_ps_IORequest;


        if ((P5609_i_IORequestIndex < 0) || (P5609_i_IORequestIndex >= G3669_ui_IORequestCount)) {
                F1770_(C1_TRUE, 0x0106000E, (long)P5609_i_IORequestIndex);
        }
        L5459_ps_IORequest = *G3670_IORequests;
        L5459_ps_IORequest = L5459_ps_IORequest + P5609_i_IORequestIndex;
        if (L5459_ps_IORequest->_ui_0x04 == 0) {
                F1770_(C1_TRUE, 0x0106000E, (long)P5609_i_IORequestIndex);
        }
        return L5459_ps_IORequest;
}

long F1837_(register long P5892_, register IOREQ* P5893_) {
#ifdef MEDIA773_SU1E_AU1E
        switch (P5892_) {
                case 0x01060003:
                        F7101_sprintf(P5893_->_ac_0x16_ErrorMessage, "Can't find file '%s' on %%s\n", P5893_->_pc_0x52_FileName);
                        break;
                case 0x0106000C:
                case 0x01060004:
                        F0088_strcpy(P5893_->_ac_0x16_ErrorMessage, "Can't find %%s anywhere");
                        break;
                case 0x01060006:
                        F7101_sprintf(P5893_->_ac_0x16_ErrorMessage, "There's no room left on %%s in %s", P5893_->_ac_0x0A_DriveName);
                        break;
                case 0x01060007:
#ifdef MEDIA772_SU1E
                        if (P5893_->_i_0x02_FileHandle == -1) {
#endif
#ifdef MEDIA762_AU1E
                        if (P5893_->_i_0x02_FileHandle == 0) {
#endif
                                F0088_strcpy(P5893_->_ac_0x16_ErrorMessage, "A read error occured on %s");
                        } else {
                                F7101_sprintf(P5893_->_ac_0x16_ErrorMessage, "A read error occured on file %s in %%s", P5893_->_pc_0x52_FileName);
                        }
                        break;
                case 0x01060008:
#ifdef MEDIA772_SU1E
                        if (P5893_->_i_0x02_FileHandle == -1) {
#endif
#ifdef MEDIA762_AU1E
                        if (P5893_->_i_0x02_FileHandle == 0) {
#endif
                                F0088_strcpy(P5893_->_ac_0x16_ErrorMessage, "A write error occured on %s");
                        } else {
                                F7101_sprintf(P5893_->_ac_0x16_ErrorMessage, "A write error occured on file %s in %%s", P5893_->_pc_0x52_FileName);
                        }
                        break;
                case 0x01060009:
                        F7101_sprintf(P5893_->_ac_0x16_ErrorMessage, "Please unwrite-protect %%s and reinsert in %s", P5893_->_ac_0x0A_DriveName);
                        break;
                case 0x0106000D:
                        F7101_sprintf(P5893_->_ac_0x16_ErrorMessage, "Please reinsert %%s in %s", P5893_->_ac_0x0A_DriveName);
                        break;
                case 0x010600FF:
                        F7101_sprintf(P5893_->_ac_0x16_ErrorMessage, "IO Error occured on %%s in %s", P5893_->_ac_0x0A_DriveName);
        }
#endif
#ifdef MEDIA767_AU2E
        F7101_sprintf(P5893_->_ac_0x16_ErrorMessage, "io error\n");
#endif
        P5892_ = F1770_(C0_FALSE, P5892_, (long)P5893_->_i_0x00);
        return P5892_;
}

unsigned int16_t F1838_(register unsigned int16_t P5610_, unsigned int16_t P5611_, unsigned int16_t P5612_) {
        register int16_t L5460_;
        register int16_t L5461_;


        L5460_ = 1;
        L5461_ = 0;
        P5610_ >>= P5611_;
        while (P5611_++ <= P5612_) {
                if (P5610_ & L5460_) {
                        L5461_++;
                }
                L5460_ += L5460_;
        }
        return L5461_;
}

void F1839_(register char* P5613_, register char* P5614_, register int16_t P5615_) {
        register int16_t L5462_;


        L5462_ = 0;
        while (*P5613_ && P5615_) {
                *P5614_++ = *P5613_++;
                P5615_--;
        }
        *P5614_ = 0;
}

void F1840_(register char* P5616_, register char* P5617_, register int16_t P5618_) {
        register int16_t L5463_;


        L5463_ = 0;
        while (*P5616_ && (P5618_ != 0)) {
                *P5617_++ = *P5616_++;
                P5618_--;
        }
        while (P5618_--) {
                *P5617_++ = '\0';
        }
}

BOOLEAN F1841_(register char* P5619_, register char* P5620_, register int16_t P5621_) {
        register int16_t L5464_;


        L5464_ = C1_TRUE;
        while (P5621_--) {
                if (*P5619_++ != *P5620_++) {
                        L5464_ = C0_FALSE;
                        break;
                }
        }
        return L5464_;
}

void F1842_(register IOREQ* P5622_, register int16_t P5623_, register int16_t P5624_) {
        if (!(P5622_->_i_0x06_Flags & P5623_) || ((P5622_->_i_0x06_Flags & P5624_) != P5624_)) {
                F1770_(C1_TRUE, 0x01060005, P5622_);
        }
}

int16_t F1843_GetFixedDrvmap(
)
{
        register int16_t L5465_;
#ifdef MEDIA772_SU1E
        long L5466_l_SupervisorStack;
#endif


#ifdef MEDIA772_SU1E
        L5466_l_SupervisorStack = Super(0L);
        L5465_ = *(int16_t*)0x000004A6; /* _ nflops : number of floppy drives currently connected to the system */
        Super(L5466_l_SupervisorStack);
        if (L5465_ == 2) { /* If there are 2 floppy disk drives */
                L5465_ = 3; /* Bits 0 & 1 for A: and B: */
        }
        L5465_ |= (int16_t)Drvmap() & 0xFC; /* Drvmap always indicates that drives A: and B: are available. Replace bits for A: and B: by actual status */
#endif
#ifdef MEDIA763_AU1E_AU2E
        L5465_ = 1;
#endif
        return L5465_;
}

long F1844_(unsigned int16_t P5625_i_DeviceIndex, long* P5626_) {
#ifdef MEDIA772_SU1E
        register DTA* L5467_;
#endif
        register long L5468_;
#ifdef MEDIA772_SU1E
        long L5739_l_Unreferenced;
        DTA* L5469_ps_DTABackup;
#endif


        L5468_ = 0;
#ifdef MEDIA772_SU1E
        L5467_ = (DTA*)*G3671_puc_IOBuffer;
        L5469_ps_DTABackup = Fgetdta();
        Fsetdta(L5467_);
        F0088_strcpy(G3673_ac_FileName, G3672_apc_DriveLetters[P5625_i_DeviceIndex - 1]);
        F0086_strcat(G3673_ac_FileName, "*.*");
        Fsfirst(G3673_ac_FileName, 8);
        F1840_(L5467_->d_fname, G3673_ac_FileName, 12);
        Fsetdta(L5469_ps_DTABackup);
        if (P5625_i_DeviceIndex < 3) {
                if (Floprd(L5467_, 0L, P5625_i_DeviceIndex - 1, 1, 0, 0, 2) == 0) {
                        F1840_(&L5467_->d_reserved[2], G3674_ac_FileName, 6);
                        *P5626_ = ((long)L5467_->d_reserved[8] << 16) | ((long)L5467_->d_reserved[9] << 8) | (long)L5467_->d_reserved[10];
                } else {
                        L5468_ = 0x01060004;
                }
        } else {
                *P5626_ = (long)P5625_i_DeviceIndex + 0x01000000;
                F1840_(G3672_apc_DriveLetters[P5625_i_DeviceIndex - 1], G3674_ac_FileName, 6);
        }
#endif
        return L5468_;
}

#ifdef MEDIA763_AU1E_AU2E
long F2006_(register IOREQ* P5943_) {
        register struct FileLock* L5865_ps_FileLock;
        register int16_t L5866_i_Unreferenced;
        register long L5867_l_;


        L5867_l_ = 0;
        do {
                if (P5943_->_i_0x74 == 32) {
                        if (L5865_ps_FileLock = Lock(P5943_->_ac_0x0A_DriveName, ACCESS_READ)) {
                                UnLock(L5865_ps_FileLock);
                        } else {
                                L5867_l_ = 0x0106000D;
                        }
                }
                if (L5867_l_) {
                        L5867_l_ = F1837_(L5867_l_, P5943_);
                }
        } while (L5867_l_ == 0x0102FFFE);
        return L5867_l_;
}
#endif

long F1845_(register IOREQ* P5627_) {
#ifdef MEDIA772_SU1E
        register int16_t L5470_;
#endif
        register long L5471_;
#ifdef MEDIA772_SU1E
        long L5472_;
#endif


#ifdef MEDIA763_AU1E_AU2E
        if (P5627_->_i_0x02_FileHandle == NULL) {
                L5471_ = F1837_(0x0106000F, P5627_);
        } else {
#endif
                do {
#ifdef MEDIA763_AU1E_AU2E
                        L5471_ = 0;
#endif
                        if (P5627_->_i_0x74 == 32) {
#ifdef MEDIA772_SU1E
                                switch (L5470_ = Mediach(P5627_->_ui_0x08_DeviceIndex)) {
                                        case 2:
                                                L5471_ = 0x0106000D;
                                                break;
                                        case 1:
                                                if ((L5471_ = F1844_(P5627_->_ui_0x08_DeviceIndex, &L5472_)) == 0) {
                                                        L5471_ = (L5472_ == P5627_->_l_0x78) ? 0 : 0x0106000D;
                                                }
                                                break;
                                        case 0:
                                                L5471_ = 0;
                                                break;
                                }
                        } else {
                                L5471_ = 0;
#endif
#ifdef MEDIA763_AU1E_AU2E
                                if (Seek(P5627_->_i_0x02_FileHandle, 0L, OFFSET_CURRENT) == -1) {
                                        L5471_ = 0x0106000D;
                                }
#endif
                        }
                        if (L5471_) {
                                L5471_ = F1837_(L5471_, P5627_);
                        }
                } while (L5471_ == 0x0102FFFE);
#ifdef MEDIA763_AU1E_AU2E
        }
#endif
        return L5471_;
}

long F1846_(register IOREQ* P5628_) {
#ifdef MEDIA772_SU1E
        register char* L5473_;
#endif
#ifdef MEDIA763_AU1E_AU2E
        register struct FileLock* L5473_ps_FileLock;
#endif
        register long L5474_;
#ifdef MEDIA772_SU1E
        register int16_t L5475_;
        register int16_t L5476_;
        long L5477_;
#endif


#ifdef MEDIA772_SU1E
        if (P5628_->_i_0x06_Flags & 0x8000) {
#endif
                do {
#ifdef MEDIA763_AU1E_AU2E
                        L5474_ = 0x01060004;
#endif
                        if (P5628_->_i_0x06_Flags & 0x0100) {
#ifdef MEDIA772_SU1E
                                if ((L5474_ = F1844_(P5628_->_ui_0x08_DeviceIndex, &L5477_)) == 0) {
                                        if (((P5628_->_i_0x06_Flags & 0x0200) && (P5628_->_l_0x78 != L5477_)) || ((P5628_->_i_0x06_Flags & 0x0020) && !F1841_(G3674_ac_FileName, P5628_->_ac_0x62, 6)) || ((P5628_->_i_0x06_Flags & 0x0040) && !F1841_(G3673_ac_FileName, P5628_->_ac_0x68, 12))) {
                                                L5474_ = 0x0106000C;
                                        } else {
                                                L5474_ = 0;
                                        }
                                }
                        } else {
                                F1842_(P5628_, 608, 128);
                                L5475_ = F1843_GetFixedDrvmap();
                                if (P5628_->_i_0x74 == ' ') {
                                        L5475_ = F1838_(L5475_, 0, 1);
                                        L5476_ = 1;
                                } else {
                                        L5475_ = F1838_(L5475_, 2, 5);
                                        L5476_ = 3;
                                }
                                while (L5475_--) {
                                        if ((L5474_ = F1844_(L5476_ + L5475_, &L5477_)) == 0) {
                                                if (((P5628_->_i_0x06_Flags & 0x0200) && (P5628_->_l_0x78 == L5477_)) || ((P5628_->_i_0x06_Flags & 0x0020) && F1841_(G3674_ac_FileName, P5628_->_ac_0x62, 6)) || ((P5628_->_i_0x06_Flags & 0x0040) && F1841_(G3673_ac_FileName, P5628_->_ac_0x68, 12))) {
                                                        P5628_->_ui_0x08_DeviceIndex = L5475_ + L5476_;
                                                        P5628_->_i_0x76 = P5628_->_i_0x74 + L5475_;
                                                        L5474_ = 0;
                                                        break;
                                                }
                                        }
                                        L5474_ = 0x0106000C;
                                }
                        }
                        if ((L5474_ == 0x0106000C) || (L5474_ == 0x01060004)) {
#endif
#ifdef MEDIA763_AU1E_AU2E
                                if (L5473_ps_FileLock = Lock(P5628_->_ac_0x0A_DriveName, ACCESS_READ)) {
                                        UnLock(L5473_ps_FileLock);
                                        L5474_ = 0;
                                }
                        }
                        if (L5474_) {
#endif
                                L5474_ = F1837_(L5474_, P5628_);
#ifdef MEDIA772_SU1E
                        } else {
                                if (!L5474_) {
                                        F1840_(G3673_ac_FileName, P5628_->_ac_0x68, 12);
                                        F1840_(G3674_ac_FileName, P5628_->_ac_0x62, 6);
                                        P5628_->_l_0x78 = L5477_;
                                        M008_SET(P5628_->_i_0x06_Flags, 0x3E0);
                                        M009_CLEAR(P5628_->_i_0x06_Flags, 0x8000);
                                }
#endif
                        }
                } while (L5474_ == 0x0102FFFE);
#ifdef MEDIA772_SU1E
        } else {
                L5474_ = F1845_(P5628_);
        }
#endif
        return L5474_;
}

long F1847_(
#ifdef MEDIA772_SU1E
int16_t P5629_, register IOREQ* P5630_) {
#endif
#ifdef MEDIA763_AU1E_AU2E
register long P5629_, register IOREQ* P5630_) {
#endif
        register long L5478_;


#ifdef MEDIA772_SU1E
        if (P5629_ >= 0) {
#endif
#ifdef MEDIA763_AU1E_AU2E
        if (P5629_ == 0) {
#endif
                return 0;
        } else {
                switch (P5629_) {
#ifdef MEDIA763_AU1E_AU2E
                        case 221:
                                L5478_ = 0x01060006;
                                break;
#endif
#ifdef MEDIA772_SU1E
                        case -10:
#endif
#ifdef MEDIA763_AU1E_AU2E
                        case 222:
                        case 223:
                        case 203:
#endif
                                L5478_ = 0x01060008;
                                break;
#ifdef MEDIA772_SU1E
                        case -11:
#endif
#ifdef MEDIA763_AU1E_AU2E
                        case 224:
#endif
                                L5478_ = 0x01060007;
                                break;
#ifdef MEDIA772_SU1E
                        case -13:
#endif
#ifdef MEDIA763_AU1E_AU2E
                        case 214:
#endif
                                L5478_ = 0x01060009;
                                break;
#ifdef MEDIA763_AU1E_AU2E
                        case 218:
                                L5478_ = 0x01060004;
                                break;
#endif
#ifdef MEDIA772_SU1E
                        case -14:
#endif
#ifdef MEDIA763_AU1E_AU2E
                        case 226:
#endif
                                L5478_ = 0x0106000D;
                                break;
#ifdef MEDIA772_SU1E
                        case -33:
#endif
#ifdef MEDIA763_AU1E_AU2E
                        case 204:
                        case 205:
#endif
                                L5478_ = 0x01060003;
                                break;
#ifdef MEDIA772_SU1E
                        case -34:
#endif
#ifdef MEDIA763_AU1E_AU2E
                        case 215:
                        case 225:
#endif
                                L5478_ = 0x0106000B;
                                break;
                        default:
                                L5478_ = 0x010600FF;
                }
                P5630_->_l_0x12_ReturnCode = L5478_;
                L5478_ = F1837_(L5478_, P5630_);
                return L5478_;
        }
}

long F1848_OpenOrCreateFile(
#ifdef MEDIA772_SU1E
IOREQ* P5631_) {
#endif
#ifdef MEDIA763_AU1E_AU2E
IOREQ* P5631_, long P5944_) {
#endif
        register long L5479_;
        register int16_t L5480_i_FileHandle;


        F1842_(P5631_, 992, 2);
        do {
                if ((L5479_ = F1846_(P5631_)) == 0) {
                        F0088_strcpy(G3673_ac_FileName, P5631_->_ac_0x0A_DriveName);
                        F0086_strcat(G3673_ac_FileName, P5631_->_pc_0x52_FileName);
#ifdef MEDIA772_SU1E
                        if (P5631_->_ui_0x04 == 2) {
                                L5480_i_FileHandle = Fopen(G3673_ac_FileName, C2_READ_WRITE_ACCESS);
                        } else {
                                L5480_i_FileHandle = Fcreate(G3673_ac_FileName, C0_FILE_ATTRIBUTES);
                        }
                        L5479_ = F1847_(L5480_i_FileHandle, P5631_);
                        if (L5479_ == 0) {
                                P5631_->_i_0x02_FileHandle = L5480_i_FileHandle;
#endif
#ifdef MEDIA763_AU1E_AU2E
                        if ((P5631_->_i_0x02_FileHandle = Open(G3673_ac_FileName, P5944_)) == NULL) {
                                L5479_ = F1847_(IoErr(), P5631_);
#endif
                        }
                }
        } while (L5479_ == 0x0102FFFE);
        return L5479_;
}

long F1849_DeleteFile(IOREQ* P5632_) {
        register long L5481_;
        register int16_t L5482_;


        F1842_(P5632_, -1, 258);
        do {
                if ((L5481_ = F1846_(P5632_)) == 0) {
                        F0088_strcpy(G3673_ac_FileName, P5632_->_ac_0x0A_DriveName);
                        F0086_strcat(G3673_ac_FileName, P5632_->_pc_0x52_FileName);
#ifdef MEDIA772_SU1E
                        L5482_ = Fdelete(G3673_ac_FileName);
                        L5481_ = F1847_(L5482_, P5632_);
#endif
                }
        } while (L5481_ == 0x0102FFFE);
        return L5481_;
}

long F1850_RenameFile(IOREQ* P5633_) {
        register long L5483_;
        register int16_t L5484_;


        F1842_(P5633_, -1, 6);
        do {
                if ((L5483_ = F1846_(P5633_)) == 0) {
                        F0088_strcpy(G3673_ac_FileName, P5633_->_ac_0x0A_DriveName);
                        F0086_strcat(G3673_ac_FileName, P5633_->_pc_0x52_FileName);
                        F0088_strcpy(G3674_ac_FileName, P5633_->_ac_0x0A_DriveName);
                        F0086_strcat(G3674_ac_FileName, P5633_->_pc_0x56_ColorComponents_FileName);
#ifdef MEDIA772_SU1E
                        L5484_ = Frename(0, G3673_ac_FileName, G3674_ac_FileName);
                        L5483_ = F1847_(L5484_, P5633_);
#endif
                }
        } while (L5483_ == 0x0102FFFE);
        return L5483_;
}

long F1851_GetDirectoryFileList(register IOREQ* P5634_) {
#ifdef MEDIA772_SU1E
        register char* L5485_;
#endif
        register long L5486_;
#ifdef MEDIA772_SU1E
        register int16_t L5487_;
        register int16_t L5488_;
        register unsigned int16_t L5489_;
        DTA* L5490_;
        DTA* L5491_ps_DTABackup;
#endif


        F1842_(P5634_, -1, 262);
#ifdef MEDIA772_SU1E
        L5490_ = *G3671_puc_IOBuffer;
#endif
        do {
                if (L5486_ = F1846_(P5634_)) {
                        continue;
                }
                F0088_strcpy(G3673_ac_FileName, P5634_->_ac_0x0A_DriveName);
                F0086_strcat(G3673_ac_FileName, P5634_->_pc_0x52_FileName);
#ifdef MEDIA772_SU1E
                L5491_ps_DTABackup = Fgetdta();
                Fsetdta(L5490_);
                L5485_ = P5634_->_pc_0x56_ColorComponents_FileName;
                L5488_ = 0;
                L5487_ = 0;
                P5634_->_l_0x0E_OutputValue = 0;
                while (L5488_ >= 0) {
                        if (L5487_ == 0) {
                                L5488_ = Fsfirst(G3673_ac_FileName, 0);
                        } else {
                                L5488_ = Fsnext();
                        }
                        if (L5488_ >= 0) {
                                L5489_ = F0090_strlen(L5490_->d_fname);
                                L5489_++;
                                if (P5634_->_ul_0x5E_ByteCount >= L5487_ + L5489_) {
                                        F0088_strcpy(L5485_, L5490_->d_fname);
                                        L5485_ += L5489_;
                                        L5487_ += L5489_;
                                        P5634_->_l_0x0E_OutputValue++;
                                } else {
                                        L5488_ = -1;
                                }
                        }
                }
                Fsetdta(L5491_ps_DTABackup);
#endif
        } while (L5486_ == 0x0102FFFE);
        return L5486_;
}

long F1852_(IOREQ* P5635_) {
        register long L5492_;
#ifdef MEDIA772_SU1E
        register long L5493_;
        DISKINFO L5494_;
#endif


        F1842_(P5635_, 864, 0);
        do {
                if ((L5492_ = F1846_(P5635_)) == 0) {
#ifdef MEDIA772_SU1E
                        Dfree(&L5494_, P5635_->_ui_0x08_DeviceIndex);
                        L5493_ = L5494_.b_secsize * L5494_.b_clsize;
                        if (P5635_->_ui_0x04 == 25) {
                                P5635_->_l_0x0E_OutputValue = L5493_ * (L5494_.b_total - L5494_.b_free);
                        } else {
                                P5635_->_l_0x0E_OutputValue = L5493_ * L5494_.b_free;
                        }
#endif
                }
        } while (L5492_ == 0x0102FFFE);
        return L5492_;
}

void F1853_(register unsigned int16_t P5636_) {
        register IOREQ* L5498_;
        register unsigned char* L5499_;
        register int16_t L5500_;
        long L5501_;


        L5501_ = 0;
        L5499_ = (unsigned char*)F7227_RequestMemoryHandle((long)P5636_ * sizeof(IOREQ), MASK0x0400_MEMREQ | MASK0x0001_MEMREQ);
        if ((L5499_ == NULL) != 0) {
#ifdef MEDIA773_SU1E_AU1E
                F1770_(C1_TRUE, 0x01060010, "No mem for IORequests\n");
#endif
#ifdef MEDIA767_AU2E
                F1770_(C1_TRUE, 0x01060010, NULL);
#endif
        }
        G3670_IORequests = (IOREQ**)L5499_;
        L5499_ = (unsigned char*)F7227_RequestMemoryHandle(1024L, MASK0x0080_MEMREQ | MASK0x0001_MEMREQ);
        if ((L5499_ == NULL) != 0) {
#ifdef MEDIA773_SU1E_AU1E
                F1770_(C1_TRUE, 0x01060010, "No mem for IO buffer\n");
#endif
#ifdef MEDIA767_AU2E
                F1770_(C1_TRUE, 0x01060010, NULL);
#endif
        }
        G3671_puc_IOBuffer = L5499_;
        G3675_ = 0;
        G3669_ui_IORequestCount = P5636_;
        L5498_ = *G3670_IORequests;
        L5500_ = 0;
        while (L5500_ < P5636_) {
                L5498_->_i_0x00 = L5500_;
                L5498_->_ui_0x04 = 0;
                L5500_++;
                L5498_++;
        }
#ifdef MEDIA763_AU1E_AU2E
        G3859_ = 0;
        for (L5500_ = 0; L5500_ < 4; L5500_++) {
                if (F1106_IsTrackdiskDeviceOpened(L5500_)) {
                        G3672_apc_DriveLetters[G3859_++][2] = '0' + L5500_;
                }
        }
#endif
}

void F1854_(
)
{
        F7228_FreeMemory(G3671_puc_IOBuffer);
        F7228_FreeMemory(G3670_IORequests);
}

int16_t F1855_GetAvailableIORequestIndex(
)
{
        register IOREQ* L5502_ps_IORequest;
        register int16_t L5503_i_Counter;


        L5502_ps_IORequest = *G3670_IORequests;
        L5503_i_Counter = 0;
        while (L5503_i_Counter < G3669_ui_IORequestCount) {
                if (L5502_ps_IORequest->_ui_0x04 == 0) {
                        L5502_ps_IORequest->_ac_0x0A_DriveName[0] = '\0';
                        L5502_ps_IORequest->_ui_0x04 = 1;
#ifdef MEDIA772_SU1E
                        L5502_ps_IORequest->_i_0x02_FileHandle = -1;
#endif
#ifdef MEDIA763_AU1E_AU2E
                        L5502_ps_IORequest->_i_0x02_FileHandle = NULL;
#endif
                        L5502_ps_IORequest->_i_0x06_Flags = 0;
                        break;
                }
                L5503_i_Counter++;
                L5502_ps_IORequest++;
        }
        if (L5503_i_Counter >= G3669_ui_IORequestCount) {
                return -1;
        } else {
                return L5503_i_Counter;
        }
}

void F1856_CloseFile(int16_t P5637_i_IORequestIndex) {
        register IOREQ* L5504_ps_IORequest;


        L5504_ps_IORequest = F1836_GetIORequest(P5637_i_IORequestIndex);
#ifdef MEDIA772_SU1E
        if (L5504_ps_IORequest->_i_0x02_FileHandle != -1) {
#endif
#ifdef MEDIA763_AU1E_AU2E
        if (L5504_ps_IORequest->_i_0x02_FileHandle != NULL) {
#endif
                F1857_PerformIORequestOperation(P5637_i_IORequestIndex, C10_CLOSE_FILE);
        }
        L5504_ps_IORequest->_ui_0x04 = 0;
}

long F1857_PerformIORequestOperation(register int16_t P5638_i_IORequestIndex, int16_t P5639_i_IORequestOperationIndex) {
        register IOREQ* L5505_;
        register long L5506_;
        register int16_t L5507_;
        register long L5508_;
        register int16_t L5509_;


        L5506_ = 0;
        L5505_ = F1836_GetIORequest(P5638_i_IORequestIndex);
        if (P5639_i_IORequestOperationIndex) {
                L5505_->_ui_0x04 = P5639_i_IORequestOperationIndex;
        }
        switch (P5639_i_IORequestOperationIndex) {
                case C02_OPEN_FILE:
#ifdef MEDIA763_AU1E_AU2E
                        L5506_ = F1848_OpenOrCreateFile(L5505_, MODE_OLDFILE);
                        break;
#endif
                case C03_CREATE_FILE:
#ifdef MEDIA772_SU1E
                        L5506_ = F1848_OpenOrCreateFile(L5505_);
#endif
#ifdef MEDIA763_AU1E_AU2E
                        L5506_ = F1848_OpenOrCreateFile(L5505_, MODE_NEWFILE);
#endif
                        break;
                case C10_CLOSE_FILE:
#ifdef MEDIA772_SU1E
                        do {
                                if (L5505_->_i_0x02_FileHandle == -1) {
#endif
#ifdef MEDIA763_AU1E_AU2E
                        L5506_ = 0;
                                if (L5505_->_i_0x02_FileHandle == NULL) {
#endif
                                        L5506_ = F1837_(0x0106000F, L5505_);
                                } else {
                                        if ((L5506_ = F1845_(L5505_)) == 0) {
#ifdef MEDIA772_SU1E
                                                L5507_ = Fclose(L5505_->_i_0x02_FileHandle);
                                                L5506_ = F1847_(L5507_, L5505_);
#endif
#ifdef MEDIA763_AU1E_AU2E
                                                M572_CloseFile(L5505_->_i_0x02_FileHandle);
                                                L5505_->_i_0x02_FileHandle = NULL;
#endif
                                        }
                                }
#ifdef MEDIA772_SU1E
                        } while (L5506_ == 0x0102FFFE);
                        if (L5506_ == 0) {
                                L5505_->_i_0x02_FileHandle = -1;
                        }
#endif
                        break;
                case C04_DELETE_FILE:
                        L5506_ = F1849_DeleteFile(L5505_);
                        break;
                case C05_RENAME_FILE:
                        L5506_ = F1850_RenameFile(L5505_);
                        break;
                case C06_GET_FILE_SIZE:
                        do {
#ifdef MEDIA772_SU1E
                                if (L5505_->_i_0x02_FileHandle == -1) {
#endif
#ifdef MEDIA763_AU1E_AU2E
                                L5506_ = 0;
                                if (L5505_->_i_0x02_FileHandle == NULL) {
#endif
                                        L5506_ = F1837_(0x0106000F, L5505_);
                                } else {
                                        if ((L5506_ = F1845_(L5505_)) == 0) {
#ifdef MEDIA772_SU1E
                                                L5508_ = Fseek(0L, L5505_->_i_0x02_FileHandle, C1_SEEK_FROM_CURRENT_POSITION);
                                                L5505_->_l_0x0E_OutputValue = Fseek(0L, L5505_->_i_0x02_FileHandle, C2_SEEK_FROM_END_OF_FILE);
                                                if (Fseek(L5508_, L5505_->_i_0x02_FileHandle, C0_SEEK_FROM_BEGINNING_OF_FILE) < 0) {
#endif
#ifdef MEDIA763_AU1E_AU2E
                                                if ((L5508_ = Seek(L5505_->_i_0x02_FileHandle, 0L, OFFSET_END)) == -1) {
#endif
                                                        L5506_ = F1837_(0x010600FF, L5505_);
#ifdef MEDIA763_AU1E_AU2E
                                                } else {
                                                        if ((L5505_->_l_0x0E_OutputValue = Seek(L5505_->_i_0x02_FileHandle, L5508_, OFFSET_BEGINNING)) == -1) {
                                                                L5506_ = F1837_(0x010600FF, L5505_);
                                                        }
#endif
                                                }
                                        }
                                }
                        } while (L5506_ == 0x0102FFFE);
                        break;
                case C07_READ_FILE:
                        F1842_(L5505_, -1, 26);
                        do {
#ifdef MEDIA772_SU1E
                                if (L5505_->_i_0x02_FileHandle == -1) {
#endif
#ifdef MEDIA763_AU1E_AU2E
                                L5506_ = 0;
                                if (L5505_->_i_0x02_FileHandle == NULL) {
#endif
                                        L5506_ = F1837_(0x0106000F, L5505_);
                                } else {
                                        if ((L5506_ = F1845_(L5505_)) == 0) {
#ifdef MEDIA772_SU1E
                                                L5508_ = Fread(L5505_->_i_0x02_FileHandle, L5505_->_ul_0x5E_ByteCount, L5505_->_pc_0x5A_Buffer);
#endif
#ifdef MEDIA763_AU1E_AU2E
                                                L5508_ = Read(L5505_->_i_0x02_FileHandle, L5505_->_pc_0x5A_Buffer, L5505_->_ul_0x5E_ByteCount);
#endif
                                                if (L5508_ != L5505_->_ul_0x5E_ByteCount) {
                                                        L5506_ = F1837_(0x01060007, L5505_);
                                                }
                                        }
                                }
                        } while (L5506_ == 0x0102FFFE);
                        break;
                case C08_WRITE_FILE:
                        F1842_(L5505_, -1, 26);
                        do {
#ifdef MEDIA772_SU1E
                                if (L5505_->_i_0x02_FileHandle == -1) {
#endif
#ifdef MEDIA763_AU1E_AU2E
                                L5506_ = 0;
                                if (L5505_->_i_0x02_FileHandle == NULL) {
#endif
                                        L5506_ = F1837_(0x0106000F, L5505_);
                                } else {
                                        if ((L5506_ = F1845_(L5505_)) == 0) {
#ifdef MEDIA772_SU1E
                                                L5508_ = Fwrite(L5505_->_i_0x02_FileHandle, L5505_->_ul_0x5E_ByteCount, L5505_->_pc_0x5A_Buffer);
                                                if (L5508_ < L5505_->_ul_0x5E_ByteCount) {
#endif
#ifdef MEDIA763_AU1E_AU2E
                                                L5508_ = Write(L5505_->_i_0x02_FileHandle, L5505_->_pc_0x5A_Buffer, L5505_->_ul_0x5E_ByteCount);
                                                if (L5508_ != L5505_->_ul_0x5E_ByteCount) {
#endif
                                                        L5506_ = F1837_(0x01060008, L5505_);
                                                }
                                        }
                                }
                        } while (L5506_ == 0x0102FFFE);
                        break;
                case C09_SET_CURRENT_POSITION:
                        F1842_(L5505_, -1, 18);
                        do {
#ifdef MEDIA772_SU1E
                                if (L5505_->_i_0x02_FileHandle == -1) {
#endif
#ifdef MEDIA763_AU1E_AU2E
                                L5506_ = 0;
                                if (L5505_->_i_0x02_FileHandle == NULL) {
#endif
                                        L5506_ = F1837_(0x0106000F, L5505_);
                                } else {
                                        if ((L5506_ = F1845_(L5505_)) == 0) {
#ifdef MEDIA772_SU1E
                                                L5508_ = Fseek(L5505_->_ul_0x5E_ByteCount, L5505_->_i_0x02_FileHandle, C0_SEEK_FROM_BEGINNING_OF_FILE);
#endif
#ifdef MEDIA763_AU1E_AU2E
                                                L5508_ = Seek(L5505_->_i_0x02_FileHandle, L5505_->_ul_0x5E_ByteCount, OFFSET_BEGINNING);
#endif
                                                L5505_->_l_0x0E_OutputValue = L5508_;
                                                if (L5508_ < 0) {
                                                        L5506_ = F1837_(0x010600FF, L5505_);
                                                }
                                        }
                                }
                        } while (L5506_ == 0x0102FFFE);
                        break;
                case C11_GET_CURRENT_POSITION:
                        do {
#ifdef MEDIA772_SU1E
                                if (L5505_->_i_0x02_FileHandle == -1) {
#endif
#ifdef MEDIA763_AU1E_AU2E
                                L5506_ = 0;
                                if (L5505_->_i_0x02_FileHandle == NULL) {
#endif
                                        L5506_ = F1837_(0x0106000F, L5505_);
                                } else {
                                        if ((L5506_ = F1845_(L5505_)) == 0) {
#ifdef MEDIA772_SU1E
                                                L5508_ = Fseek(0L, L5505_->_i_0x02_FileHandle, C1_SEEK_FROM_CURRENT_POSITION);
                                                L5505_->_l_0x0E_OutputValue = L5508_;
                                                if (L5508_ < 0) {
#endif
#ifdef MEDIA763_AU1E_AU2E
                                                if ((L5505_->_l_0x0E_OutputValue = Seek(L5505_->_i_0x02_FileHandle, 0L, OFFSET_CURRENT)) < 0) {
#endif
                                                        L5506_ = F1837_(0x010600FF, L5505_);
                                                }
                                        }
                                }
                        } while (L5506_ == 0x0102FFFE);
                        break;
                case C12_GET_DIRECTORY_FILE_LIST:
                        L5506_ = F1851_GetDirectoryFileList(L5505_);
                        break;
                case 20:
                        F1842_(L5505_, 864, 0);
                        do {
                                L5506_ = F1846_(L5505_);
                        } while (L5506_ == 0x0102FFFE);
                        break;
                case 21:
                        F1842_(L5505_, 864, 0);
                        do {
                                L5505_->_l_0x0E_OutputValue = 0;
                                if (((L5506_ = F1846_(L5505_)) == 0) && (L5505_->_i_0x74 == 0x40)) {
                                        L5505_->_l_0x0E_OutputValue |= 0x00000020;
                                }
                        } while (L5506_ == 0x0102FFFE);
                        break;
                case 22:
#ifdef MEDIA772_SU1E
                        F1842_(L5505_, -1, 128);
                        do {
                                L5507_ = F1843_GetFixedDrvmap();
                                L5505_->_l_0x0E_OutputValue = (L5505_->_i_0x74 == 0x20) ? (long)F1838_(L5507_, 0, 1) : (long)F1838_(L5507_, 2, 5);
                        } while (L5506_ == 0x0102FFFE);
#endif
#ifdef MEDIA763_AU1E_AU2E
                        if (L5505_->_i_0x74 == 0x20) {
                                L5506_ = 0;
                                L5505_->_l_0x0E_OutputValue = G3859_;
                        } else {
                                F1770_(C1_TRUE, 0x01FFFFFF, (long)P5638_i_IORequestIndex);
                        }
#endif
                        break;
                case 23:
                        F1770_(C1_TRUE, 0x01FFFFFF, (long)P5638_i_IORequestIndex);
                        break;
                case 24:
                        F1770_(C1_TRUE, 0x01FFFFFF, (long)P5638_i_IORequestIndex);
                        break;
                case 25:
                case 26:
#ifdef MEDIA772_SU1E
                        L5506_ = F1852_(L5505_);
#endif
#ifdef MEDIA763_AU1E_AU2E
                        F1770_(C1_TRUE, 0x01FFFFFF, (long)P5638_i_IORequestIndex);
#endif
                        break;
                        break;
                default:
                        F1770_(C1_TRUE, 0x01060001, L5505_);
        }
        if (L5506_) {
                L5505_->_l_0x12_ReturnCode = L5506_;
        }
        return L5506_;
}

long F1858_GetIORequestValue(int16_t P5640_, register int16_t P5641_) {
        register IOREQ* L5510_;
        register long L5511_;


        L5510_ = F1836_GetIORequest(P5640_);
        switch (P5641_) {
                case 0x0001:
                        L5511_ = L5510_->_l_0x12_ReturnCode;
                        break;
                case 0x0002:
                        L5511_ = (long)L5510_->_pc_0x52_FileName;
                        break;
                case 0x0004:
                        L5511_ = (long)L5510_->_pc_0x56_ColorComponents_FileName;
                        break;
                case 0x0008:
                        L5511_ = (long)L5510_->_pc_0x5A_Buffer;
                        break;
                case 0x0010:
                        L5511_ = L5510_->_ul_0x5E_ByteCount;
                        break;
                case 0x0020:
                        F1839_(L5510_->_ac_0x62, G3673_ac_FileName, 6);
                        L5511_ = (long)G3673_ac_FileName;
                        break;
                case 0x0040:
                        L5511_ = (long)L5510_->_ac_0x68;
                        break;
                case 0x0080:
                        L5511_ = L5510_->_i_0x74;
                        break;
                case 0x0100:
                        L5511_ = L5510_->_i_0x76;
                        break;
                case 0x0200:
                        L5511_ = L5510_->_l_0x78;
                        break;
                case 0x0400:
                        L5511_ = (long)L5510_->_ac_0x16_ErrorMessage;
                        break;
                case 0x000F:
                        L5511_ = L5510_->_ui_0x04;
                        break;
                case 0x001F:
                        L5511_ = (long)L5510_->_ac_0x0A_DriveName;
                        break;
                default:
                        L5511_ = 0;
        }
        return L5511_;
}

long F1859_SetIORequestValue(int16_t P5642_, int16_t P5643_, unsigned long P5644_) {
        register IOREQ* L5512_;
        register long L5513_;


        L5513_ = 0x0106000E;
        L5512_ = F1836_GetIORequest(P5642_);
        L5513_ = 0;
        switch (P5643_) {
                case 0x0001:
                        L5512_->_l_0x12_ReturnCode = P5644_;
                        break;
                case 0x0002:
                        L5512_->_pc_0x52_FileName = (char*)P5644_;
                        break;
                case 0x0004:
                        L5512_->_pc_0x56_ColorComponents_FileName = (char*)P5644_;
                        break;
                case 0x0008:
                        L5512_->_pc_0x5A_Buffer = (char*)P5644_;
                        break;
                case 0x0010:
                        L5512_->_ul_0x5E_ByteCount = P5644_;
                        break;
                case 0x0020:
                        if (P5644_) {
                                F1840_((char*)P5644_, L5512_->_ac_0x62, 6);
                        } else {
                                M009_CLEAR(L5512_->_i_0x06_Flags, 0x0020);
                                P5643_ = 0;
                        }
                        M008_SET(P5643_, 0x8000);
                        break;
                case 0x0040:
                        if (P5644_) {
                                F1840_((char*)P5644_, L5512_->_ac_0x68, 12);
                        } else {
                                M009_CLEAR(L5512_->_i_0x06_Flags, 0x0040);
                                P5643_ = 0;
                        }
                        M008_SET(P5643_, 0x8000);
                        break;
                case 0x0080:
                        if (!P5644_) {
                                P5643_ = 0;
                                M009_CLEAR(L5512_->_i_0x06_Flags, 0x0080);
                        } else {
                                if ((P5644_ == 0x0020) || (P5644_ == 0x0040)) {
                                        L5512_->_i_0x74 = P5644_;
                                } else {
                                        L5513_ = 0x0106000B;
                                }
                        }
                        M008_SET(P5643_, 0x8000);
                        break;
                case 0x0100:
                        L5512_->_ac_0x0A_DriveName[0] = '\0';
                        if (!P5644_) {
                                P5643_ = 0x8000;
                                M009_CLEAR(L5512_->_i_0x06_Flags, 0x0100);
                        } else {
                                if ((P5644_ < 32) || (P5644_ >= 68)) {
                                        L5513_ = 0x0106000B;
                                } else {
                                        L5512_->_i_0x76 = P5644_;
                                        if (P5644_ >= 64) {
#ifdef MEDIA772_SU1E
                                                L5512_->_ui_0x08_DeviceIndex = (int16_t)P5644_ - 61;
#endif
#ifdef MEDIA763_AU1E_AU2E
                                                L5512_->_ui_0x08_DeviceIndex = (int16_t)P5644_ - 64;
#endif
                                                L5512_->_i_0x74 = 64;
#ifdef MEDIA763_AU1E_AU2E
                                                L5513_ = 0x0106000B;
#endif
                                        } else {
#ifdef MEDIA772_SU1E
                                                if ((L5512_->_ui_0x08_DeviceIndex = (int16_t)P5644_ - 31) > 2) {
#endif
#ifdef MEDIA763_AU1E_AU2E
                                                if ((L5512_->_ui_0x08_DeviceIndex = (int16_t)P5644_ - 32) > (G3859_ - 1)) {
#endif
                                                        L5513_ = 0x0106000B;
                                                } else {
                                                        L5512_->_i_0x74 = 32;
                                                }
                                        }
                                        if (!L5513_) {
                                                M008_SET(P5643_, 0x8080);
#ifdef MEDIA772_SU1E
                                                F0088_strcpy(L5512_->_ac_0x0A_DriveName, G3672_apc_DriveLetters[L5512_->_ui_0x08_DeviceIndex - 1]);
#endif
#ifdef MEDIA763_AU1E_AU2E
                                                F0088_strcpy(L5512_->_ac_0x0A_DriveName, G3672_apc_DriveLetters[L5512_->_ui_0x08_DeviceIndex]);
#endif
                                        }
                                }
                        }
                        break;
                case 0x0200:
                        L5512_->_l_0x78 = P5644_;
                        M008_SET(P5643_, 0x8000);
                        break;
                case 0x0400:
                        F0088_strcpy(L5512_->_ac_0x16_ErrorMessage, P5644_);
                        break;
                default:
                        F1770_(C1_TRUE, 0x01060002, L5512_);
        }
        M008_SET(L5512_->_i_0x06_Flags, P5643_);
        if (L5513_) {
                L5512_->_l_0x12_ReturnCode = L5513_;
        }
        return L5513_;
}

long F1860_(int16_t P5645_, int16_t P5646_, int16_t P5647_, long P5648_) {
        register long L5514_;


        F1859_SetIORequestValue(P5645_, P5647_, P5648_);
        L5514_ = F1857_PerformIORequestOperation(P5645_, P5646_);
        return L5514_;
}

long F1861_GetIORequestOutputValue(int16_t P5649_) {
        register IOREQ* L5515_ps_IORequest;
        register long L5516_l_IORequestOutputValue;


        L5515_ps_IORequest = F1836_GetIORequest(P5649_);
        L5516_l_IORequestOutputValue = L5515_ps_IORequest->_l_0x0E_OutputValue;
        return L5516_l_IORequestOutputValue;
}
#endif
