#ifndef COMPILE_H
#include "COMPILE.H"
#endif
#ifdef MEDIA377_G14ED_G20E_G21E_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J_AU1E_AU2E_AU2F
#ifdef MEDIA351_G14ED_G20E_G21E
segment "gsthings"


#ifdef MEDIA349_G14ED
void F2229_(
)   /* Similar to F2162_ShutDown */
{
        *G3952_puc_ = G3953_i_SoundVolumeLevel;
        F2174_();
        F2227_F2174_sub();
        SchShutDown();
        EMShutDown();
        QDShutDown();
        MTShutDown();
}

void F2230_(
)
{
        F2229_();
        exit(1);
}

void F2228_CallProDOS_FORMAT(
P6081_ps_)
FormatRecPtr P6081_ps_ FINAL_SEPARATOR
{
        *((FormatRecPtr)G4056_auc_ParameterBlock) = *P6081_ps_;
        c2pstr(P6081_ps_->devName);
        c2pstr(P6081_ps_->volName);
        FORMAT(G4056_auc_ParameterBlock);
        p2cstr(P6081_ps_->devName);
        p2cstr(P6081_ps_->volName);
}

void F2214_CallProDOS_CREATE(
P6082_ps_)
FileRecPtr P6082_ps_ FINAL_SEPARATOR
{
        *((FileRecPtr)G4056_auc_ParameterBlock) = *P6082_ps_;
        c2pstr(P6082_ps_->pathname);
        CREATE(G4056_auc_ParameterBlock);
        p2cstr(P6082_ps_->pathname);
}

void F2215_CallProDOS_DESTROY(
P6083_ps_)
PathNameRecPtr P6083_ps_ FINAL_SEPARATOR
{
        *((PathNameRecPtr)G4056_auc_ParameterBlock) = *P6083_ps_;
        c2pstr(P6083_ps_->pathname);
        DESTROY(G4056_auc_ParameterBlock);
        p2cstr(P6083_ps_->pathname);
}

void F2216_CallProDOS_CHANGE_PATH(
P6084_ps_)
PathNameRecPtr P6084_ps_ FINAL_SEPARATOR
{
        *((PathNameRecPtr)G4056_auc_ParameterBlock) = *P6084_ps_;
        c2pstr(P6084_ps_->pathname);
        c2pstr(P6084_ps_->newPathname);
        CHANGE_PATH(G4056_auc_ParameterBlock);
        p2cstr(P6084_ps_->pathname);
        p2cstr(P6084_ps_->newPathname);
}

void F2217_CallProDOS_VOLUME(
P6085_ps_)
VolumeRecPtr P6085_ps_ FINAL_SEPARATOR
{
        *((VolumeRecPtr)G4056_auc_ParameterBlock) = *P6085_ps_;
        c2pstr(P6085_ps_->deviceName);
        VOLUME(G4056_auc_ParameterBlock);
        *P6085_ps_ = *((VolumeRecPtr)G4056_auc_ParameterBlock);
        p2cstr(P6085_ps_->deviceName);
        if (!_toolErr) {
                p2cstr(P6085_ps_->volName);
        }
}

void F2218_CallProDOS_OPEN(
P6086_ps_)
OpenRecPtr P6086_ps_ FINAL_SEPARATOR
{
        *((OpenRecPtr)G4056_auc_ParameterBlock) = *P6086_ps_;
        c2pstr(P6086_ps_->openPathname);
        OPEN(G4056_auc_ParameterBlock);
        *P6086_ps_ = *((OpenRecPtr)G4056_auc_ParameterBlock);
        p2cstr(P6086_ps_->openPathname);
}

void F2219_CallProDOS_READ(
P6087_ps_)
FileIORecPtr P6087_ps_ FINAL_SEPARATOR
{
        *((FileIORecPtr)G4056_auc_ParameterBlock) = *P6087_ps_;
        READ(G4056_auc_ParameterBlock);
        *P6087_ps_ = *((FileIORecPtr)G4056_auc_ParameterBlock);
}

void F2220_CallProDOS_WRITE(
P6088_ps_)
FileIORecPtr P6088_ps_ FINAL_SEPARATOR
{
        *((FileIORecPtr)G4056_auc_ParameterBlock) = *P6088_ps_;
        WRITE(G4056_auc_ParameterBlock);
        *P6088_ps_ = *((FileIORecPtr)G4056_auc_ParameterBlock);
}

void F2221_CallProDOS_CLOSE(
P6089_ps_)
FileIORecPtr P6089_ps_ FINAL_SEPARATOR
{
        *((FileIORecPtr)G4056_auc_ParameterBlock) = *P6089_ps_;
        CLOSE(G4056_auc_ParameterBlock);
}

void F2222_CallProDOS_SET_MARK(
P6080_ps_)
MarkRecPtr P6080_ps_ FINAL_SEPARATOR
{
        *((MarkRecPtr)G4056_auc_ParameterBlock) = *P6080_ps_;
        SET_MARK(G4056_auc_ParameterBlock);
}

void F2223_CallProDOS_GET_DEV_NUM(
P6090_ps_)
DevNumRecPtr P6090_ps_ FINAL_SEPARATOR
{
        *((DevNumRecPtr)G4056_auc_ParameterBlock) = *P6090_ps_;
        c2pstr(P6090_ps_->devName);
        GET_DEV_NUM(G4056_auc_ParameterBlock);
        *P6090_ps_ = *((DevNumRecPtr)G4056_auc_ParameterBlock);
        p2cstr(P6090_ps_->devName);
}

void F2224_CallProDOS_GET_BOOT_VOL(
P6091_ps_)
PathNameRecPtr P6091_ps_ FINAL_SEPARATOR
{
        *((PathNameRecPtr)G4056_auc_ParameterBlock) = *P6091_ps_;
        GET_BOOT_VOL(G4056_auc_ParameterBlock);
        if (!_toolErr) {
                p2cstr(P6091_ps_->pathname);
        }
}

void F2225_CallProDOS_QUIT(
P6092_ps_)
PathNameRecPtr P6092_ps_ FINAL_SEPARATOR
{
        *((PathNameRecPtr)G4056_auc_ParameterBlock) = *P6092_ps_;
        c2pstr(P6092_ps_->pathname);
        QUIT(G4056_auc_ParameterBlock);
        p2cstr(P6092_ps_->pathname);
}

BOOLEAN F0774_FILE_Seek(
P2170_i_FileHandle, P2171_l_Offset)
FILE_HANDLE P2170_i_FileHandle SEPARATOR
long        P2171_l_Offset     FINAL_SEPARATOR
{
        MarkRec L6375_;


        L6375_.markRefNum = P2170_i_FileHandle;
        L6375_.position = P2171_l_Offset;
        F2222_CallProDOS_SET_MARK(&L6375_);
        return (_toolErr == 0);
}

BOOLEAN F0772_FILE_Read(
P2164_i_FileHandle, P2165_ul_ByteCount, P2166_puc_Buffer)
FILE_HANDLE    P2164_i_FileHandle SEPARATOR
unsigned long  P2165_ul_ByteCount SEPARATOR
unsigned char* P2166_puc_Buffer   FINAL_SEPARATOR
{
        FileIORec L6376_;


        L6376_.fileRefNum = P2164_i_FileHandle;
        L6376_.dataBuffer = P2166_puc_Buffer;
        L6376_.requestCount = P2165_ul_ByteCount;
        F2219_CallProDOS_READ(&L6376_);
        return ((_toolErr == 0) && (L6376_.transferCount == L6376_.requestCount));
}

BOOLEAN F0773_FILE_Write(
P2167_i_FileHandle, P2168_ul_ByteCount, P2169_puc_Buffer)
FILE_HANDLE    P2167_i_FileHandle SEPARATOR
unsigned long  P2168_ul_ByteCount SEPARATOR
unsigned char* P2169_puc_Buffer   FINAL_SEPARATOR
{
        FileIORec L6377_;


        L6377_.fileRefNum = P2167_i_FileHandle;
        L6377_.dataBuffer = P2169_puc_Buffer;
        L6377_.requestCount = P2168_ul_ByteCount;
        F2220_CallProDOS_WRITE(&L6377_);
        return ((_toolErr == 0) && (L6377_.transferCount == L6377_.requestCount));
}

FILE_HANDLE F0770_FILE_Open(
P2162_pc_FileName)
char* P2162_pc_FileName FINAL_SEPARATOR
{
        OpenRec L6378_;


        L6378_.openPathname = P2162_pc_FileName;
        F2218_CallProDOS_OPEN(&L6378_);
        if (_toolErr == 0) {
                return L6378_.openRefNum;
        } else {
                return -1;
        }
}

void F0771_FILE_Close(
P2163_i_FileHandle)
FILE_HANDLE P2163_i_FileHandle FINAL_SEPARATOR
{
        FileIORec L6378_;


        L6378_.fileRefNum = P2163_i_FileHandle;
        F2221_CallProDOS_CLOSE(&L6378_);
}

FILE_HANDLE F0776_FILE_Create(
P2174_pc_FileName)
char* P2174_pc_FileName FINAL_SEPARATOR
{
        FileRec L6379_;


        L6379_.pathname = P2174_pc_FileName;
        L6379_.fAccess = destroyEnable | renameEnable | writeEnable | readEnable;
        L6379_.fileType = 0;
        L6379_.auxType = 0;
        L6379_.storageType = seedling;
        L6379_.createDate = L6379_.createTime = 0;
        F2214_CallProDOS_CREATE(&L6379_);
        if (_toolErr == 0) {
                return F0770_FILE_Open(P2174_pc_FileName);
        } else {
                return -1;
        }
}

void F0777_FILE_Delete(
P2175_pc_FileName)
char* P2175_pc_FileName FINAL_SEPARATOR
{
        PathNameRec L6380_;


        L6380_.pathname = P2175_pc_FileName;
        F2215_CallProDOS_DESTROY(&L6380_);
}

void F0778_FILE_Rename(
P2176_pc_SourceFileName, P2177_pc_DestinationFileName)
char* P2176_pc_SourceFileName      SEPARATOR
char* P2177_pc_DestinationFileName FINAL_SEPARATOR
{
        PathNameRec L6381_;


        L6381_.pathname = P2176_pc_SourceFileName;
        L6381_.newPathname = P2177_pc_DestinationFileName;
        F2216_CallProDOS_CHANGE_PATH(&L6381_);
}

BOOLEAN F0780_FILE_IsHandleInvalid(
P2179_i_FileHandle)
FILE_HANDLE P2179_i_FileHandle FINAL_SEPARATOR
{
        return P2179_i_FileHandle < 0;
}
#endif

#ifdef MEDIA388_G20E_G21E
char* F2154_(
P6062_, P6063_)
char*        P6062_ SEPARATOR
GSString255* P6063_ FINAL_SEPARATOR
{
        P6063_->length = strlen(P6062_);
        strcpy(P6063_->text, P6062_);
        return (char*)P6063_;
}

BOOLEAN F0774_FILE_Seek(
P2170_i_FileHandle, P2171_l_Offset)
FILE_HANDLE P2170_i_FileHandle SEPARATOR
long P2171_l_Offset        FINAL_SEPARATOR
{
        SetPositionRecGS L6375_;


        L6375_.pCount = 3;
        L6375_.refNum = P2170_i_FileHandle;
        L6375_.base = startPlus;
        L6375_.displacement = P2171_l_Offset;
        SetMark(&L6375_);
        return (_toolErr == 0);
}

BOOLEAN F0772_FILE_Read(
P2164_i_FileHandle, P2165_ul_ByteCount, P2166_puc_Buffer)
FILE_HANDLE        P2164_i_FileHandle SEPARATOR
unsigned long  P2165_ul_ByteCount SEPARATOR
unsigned char* P2166_puc_Buffer   FINAL_SEPARATOR
{
        IORecGS L6376_;


        L6376_.pCount = 5;
        L6376_.refNum = P2164_i_FileHandle;
        L6376_.dataBuffer = P2166_puc_Buffer;
        L6376_.requestCount = P2165_ul_ByteCount;
        L6376_.cachePriority = cacheOff;
        Read(&L6376_);
        return ((_toolErr == 0) && (L6376_.transferCount == L6376_.requestCount));
}

BOOLEAN F0773_FILE_Write(
P2167_i_FileHandle, P2168_ul_ByteCount, P2169_puc_Buffer)
FILE_HANDLE        P2167_i_FileHandle SEPARATOR
unsigned long  P2168_ul_ByteCount SEPARATOR
unsigned char* P2169_puc_Buffer   FINAL_SEPARATOR
{
        IORecGS L6377_;


        L6377_.pCount = 5;
        L6377_.refNum = P2167_i_FileHandle;
        L6377_.dataBuffer = P2169_puc_Buffer;
        L6377_.requestCount = P2168_ul_ByteCount;
        L6377_.cachePriority = cacheOff;
        Write(&L6377_);
        return ((_toolErr == 0) && (L6377_.transferCount == L6377_.requestCount));
}

FILE_HANDLE F0770_FILE_Open(
P2162_pc_FileName)
char* P2162_pc_FileName FINAL_SEPARATOR
{
        OpenRecGS L6378_;
        GSString255 L6384_;


        L6378_.pCount = 2;
        L6378_.pathname = (GSString255*)F2154_(P2162_pc_FileName, &L6384_);
        Open(&L6378_);
        if (_toolErr == 0) {
                return L6378_.refNum;
        } else {
                return -1;
        }
}

void F0771_FILE_Close(
P2163_i_FileHandle)
FILE_HANDLE P2163_i_FileHandle FINAL_SEPARATOR
{
        RefNumRecGS L6378_;


        L6378_.pCount = 1;
        L6378_.refNum = P2163_i_FileHandle;
        Close(&L6378_);
}

FILE_HANDLE F0776_FILE_Create(
P2174_pc_FileName)
char* P2174_pc_FileName FINAL_SEPARATOR
{
        CreateRecGS L6379_;
        GSString255 L6385_;


        L6379_.pCount = 5;
        L6379_.pathname = (GSString255*)F2154_(P2174_pc_FileName, &L6385_);
        L6379_.access = destroyEnable | renameEnable | writeEnable | readEnable;
        L6379_.fileType = 0;
        L6379_.auxType = 0;
        L6379_.storageType = seedling;
        Create(&L6379_);
        if (_toolErr == 0) {
                return F0770_FILE_Open(P2174_pc_FileName);
        } else {
                return -1;
        }
}

void F0777_FILE_Delete(
P2175_pc_FileName)
char* P2175_pc_FileName FINAL_SEPARATOR
{
        NameRecGS L6380_;
        GSString255 L6386_;


        L6380_.pCount = 1;
        L6380_.pathname = (GSString255*)F2154_(P2175_pc_FileName, &L6386_);
        Destroy(&L6380_);
}

void F0778_FILE_Rename(
P2176_pc_SourceFileName, P2177_pc_DestinationFileName)
char* P2176_pc_SourceFileName      SEPARATOR
char* P2177_pc_DestinationFileName FINAL_SEPARATOR
{
        ChangePathRecGS L6381_;
        GSString255 L6387_;
        GSString255 L6388_;


        L6381_.pCount = 2;
        L6381_.pathname = (GSString255*)F2154_(P2176_pc_SourceFileName, &L6387_);
        L6381_.newPathname = (GSString255*)F2154_(P2177_pc_DestinationFileName, &L6388_);
        ChangePath(&L6381_);
}

long F0779_FILE_Tell(
P2172_i_FileHandle)
FILE_HANDLE P2172_i_FileHandle FINAL_SEPARATOR
{
        PositionRecGS L6382_;


        L6382_.pCount = 2;
        L6382_.refNum = P2172_i_FileHandle;
        GetMark(&L6382_);
        return L6382_.position;
}

unsigned long F0775_FILE_GetSize(
P2173_i_FileHandle)
FILE_HANDLE P2173_i_FileHandle FINAL_SEPARATOR
{
        EOFRecGS L6383_;


        L6383_.pCount = 2;
        L6383_.refNum = P2173_i_FileHandle;
        GetEOF(&L6383_);
        return L6383_.eof;
}

BOOLEAN F0780_FILE_IsHandleInvalid(
P2179_i_FileHandle)
FILE_HANDLE P2179_i_FileHandle FINAL_SEPARATOR
{
        return P2179_i_FileHandle < 0;
}
#endif
#endif

#ifdef MEDIA463_P20JA_P20JB_I34E_I34M_P31J
FILE_HANDLE F0770_FILE_Open(
char* P2162_pc_FileName)
{
        asm     push    ds
        asm     lds     dx, P2162_pc_FileName
        asm     mov     ah, 3Dh
        asm     mov     al, 2
        asm     int     21h     /* DOS - 2+ - OPEN DISK FILE WITH HANDLE */
                                /* DS:DX -> ASCIZ filename, AL = access mode, 2 - read & write */
#if (EXETYPE == C06_CEDT)
        asm     pop     ds
#endif
        asm     jnb     loc_13FEA
        asm     mov     ax, 0FFFFh
        loc_13FEA: ;
#if ((EXETYPE == C03_GAME) || (EXETYPE == C05_ANIM) || (EXETYPE == C11_SELECTOR))
        asm     pop     ds
#endif
}

void F0771_FILE_Close(
FILE_HANDLE P2163_i_FileHandle)
{
        asm     mov     bx, P2163_i_FileHandle
        asm     mov     ah, 3Eh
        asm     int     21h     /* DOS - 2+ - CLOSE A FILE WITH HANDLE */
                                /* BX = file handle */
}

BOOLEAN F0772_FILE_Read(
FILE_HANDLE P2164_i_FileHandle,
unsigned long P2165_ul_ByteCount,
unsigned char huge* P2166_puc_Buffer)
{
        unsigned int16_t L2567_ui_ByteCount;
#if ((EXETYPE == C05_ANIM) || (EXETYPE == C11_SELECTOR))
        unsigned char huge* L2101_puc_Buffer;
#endif


#if ((EXETYPE == C05_ANIM) || (EXETYPE == C11_SELECTOR))
        L2101_puc_Buffer = P2166_puc_Buffer;
#endif
        while (P2165_ul_ByteCount > 0) {
                if (P2165_ul_ByteCount > 32768) {
                        L2567_ui_ByteCount = 32768;
                } else {
                        L2567_ui_ByteCount = (int16_t)P2165_ul_ByteCount;
                }
                asm     push    ds
#if ((EXETYPE == C03_GAME) || (EXETYPE == C06_CEDT))
                asm     lds     dx, P2166_puc_Buffer
#endif
#if ((EXETYPE == C05_ANIM) || (EXETYPE == C11_SELECTOR))
                asm     lds     dx, L2101_puc_Buffer
#endif
                asm     mov     cx, L2567_ui_ByteCount
                asm     mov     bx, P2164_i_FileHandle
                asm     mov     ah, 3Fh
                asm     int     21h     /* DOS - 2+ - READ FROM FILE WITH HANDLE */
                                        /* BX = file handle, CX = number of bytes to read, DS:DX -> buffer */
                asm     pop     ds
#if (EXETYPE == C06_CEDT)
                asm     jnb     loc_22396
                return C0_FALSE;
                loc_22396:
#endif
                if (_AX != L2567_ui_ByteCount) {
                        return C0_FALSE;
                }
                P2165_ul_ByteCount -= L2567_ui_ByteCount;
#if ((EXETYPE == C03_GAME) || (EXETYPE == C06_CEDT))
                P2166_puc_Buffer += L2567_ui_ByteCount;
#endif
#if ((EXETYPE == C05_ANIM) || (EXETYPE == C11_SELECTOR))
                L2101_puc_Buffer += L2567_ui_ByteCount;
#endif
        }
        return C1_TRUE;
}

#if ((EXETYPE == C03_GAME) || (EXETYPE == C06_CEDT))
BOOLEAN F0773_FILE_Write(
FILE_HANDLE P2167_i_FileHandle,
unsigned long P2168_ul_ByteCount,
unsigned char huge* P2169_puc_Buffer)
{
        unsigned int16_t L2568_ui_ByteCount;


        while (P2168_ul_ByteCount > 0) {
                if (P2168_ul_ByteCount > 0x00008000) {
                        L2568_ui_ByteCount = 0x8000;
                } else {
                        L2568_ui_ByteCount = (int16_t)P2168_ul_ByteCount;
                }
                asm     push    ds
                asm     lds     dx, P2169_puc_Buffer
                asm     mov     cx, L2568_ui_ByteCount
                asm     mov     bx, P2167_i_FileHandle
                asm     mov     ah, 40h
                                        /* DOS - 2+ - WRITE TO FILE WITH HANDLE */
                asm     int     21h     /* BX = file handle, CX = number of bytes to write, DS:DX -> buffer */
                asm     pop     ds
                asm     jnb     loc_1409A
                return C0_FALSE;
                loc_1409A:
                if (_AX != L2568_ui_ByteCount) {
                        return C0_FALSE;
                }
                P2168_ul_ByteCount -= L2568_ui_ByteCount;
                P2169_puc_Buffer += L2568_ui_ByteCount;
        }
        return C1_TRUE;
}
#endif

#if ((EXETYPE == C05_ANIM) || (EXETYPE == C11_SELECTOR))
long F0779_FILE_Tell(
FILE_HANDLE P2172_i_FileHandle)
{
        asm     mov     dx, 0
        asm     mov     cx, dx
        asm     mov     bx, P2172_i_FileHandle
        asm     mov     al, 1
        asm     mov     ah, 42h
        asm     int     21h     /* DOS - 2+ - MOVE FILE READ/WRITE POINTER (LSEEK) */
                                /* AL = method: offset from present location */
        asm     mov     ax, dx
        asm     mov     cl, 10h
        asm     shl     ax, cl
        asm     or      ax, ax
        asm     xor     dx, dx
}
#endif

BOOLEAN F0774_FILE_Seek(
FILE_HANDLE P2170_i_FileHandle,
long P2171_l_Offset)
{
        asm     les     dx, P2171_l_Offset
        asm     mov     cx, es
        asm     mov     bx, P2170_i_FileHandle
        asm     mov     al, 0
        asm     mov     ah, 42h
        asm     int     21h     /* DOS - 2+ - MOVE FILE READ/WRITE POINTER (LSEEK) */
                                /* AL = method: offset from beginning of file */
        asm     mov     ax, 1
        asm     jnb     loc_140E8
        asm     mov     ax, 0
        loc_140E8: ;
}

#ifdef MEDIA459_P20JA_P20JB_P31J
long F0779_FILE_Tell(
FILE_HANDLE P2172_i_FileHandle)
{
        asm     mov     dx, 0
        asm     mov     cx, dx
        asm     mov     bx, P2172_i_FileHandle
        asm     mov     al, 1
        asm     mov     ah, 42h
        asm     int     21h     /* DOS - 2+ - MOVE FILE READ/WRITE POINTER (LSEEK) */
                                /* AL = method: offset from present location */
#ifdef MEDIA457_P20JA
        return (((_DX << 16) != 0) || _AX);
#endif
#ifdef MEDIA472_P20JB_P31J
        asm     mov     ax, dx
        asm     mov     cl, 10h
        asm     shl     ax, cl
        asm     or      ax, ax
        asm     xor     dx, dx
#endif
}
#endif

unsigned long F0775_FILE_GetSize(
FILE_HANDLE P2173_i_FileHandle)
{
        long L2569_l_Offset1;
#ifdef MEDIA457_P20JA
        long L2570_l_Offset2;
#endif
#ifdef MEDIA480_P20JB_I34E_I34M_P31J
        unsigned int16_t L2571_ui_Segment;
        unsigned int16_t L2572_ui_Offset;
#endif


        L2569_l_Offset1 = F0779_FILE_Tell(P2173_i_FileHandle); /* ANOMALY_ASSEMBLY_COMPILATION_DIFFERENCE nop */
        asm     mov     dx, 0   /* CX:DX = offset from origin of new file position */
        asm     mov     cx, dx
        asm     mov     bx, P2173_i_FileHandle  /* BX = file handle */
        asm     mov     al, 2   /* AL = origin of move 00h start of file 01h current file position 02h end of file */
        asm     mov     ah, 42h
        asm     int     21h     /* DOS - 2+ - MOVE FILE READ/WRITE POINTER (LSEEK) */
                                /* AL = method: offset from end of file */
#ifdef MEDIA457_P20JA
        L2570_l_Offset2 = (((_DX << 16) != 0) || _AX);
        F0774_FILE_Seek(P2173_i_FileHandle, L2569_l_Offset1);
        return L2570_l_Offset2;
#endif
#ifdef MEDIA480_P20JB_I34E_I34M_P31J
        asm     mov     L2572_ui_Offset, ax
        asm     mov     L2571_ui_Segment, dx
        F0774_FILE_Seek(P2173_i_FileHandle, L2569_l_Offset1);
        asm     mov     dx, L2571_ui_Segment
        asm     mov     ax, L2572_ui_Offset
#endif
}

#if ((EXETYPE == C03_GAME) || (EXETYPE == C06_CEDT))
FILE_HANDLE F0776_FILE_Create(
char* P2174_pc_FileName)
{
        asm     push    ds
        asm     lds     dx, P2174_pc_FileName
        asm     mov     ah, 3Ch
        asm     mov     cx, 0
        asm     int     21h     /* DOS - 2+ - CREATE A FILE WITH HANDLE (CREAT) */
                                /* CX = attributes for file, DS:DX -> ASCIZ filename (may include drive and path) */
#if (EXETYPE == C06_CEDT)
        asm     pop     ds
#endif
        asm     jnb     loc_14140
        asm     mov     ax, 0FFFFh
        loc_14140: ;
#if (EXETYPE == C03_GAME)
        asm     pop     ds
#endif
}

void F0777_FILE_Delete(
char* P2175_pc_FileName)
{
        asm     push    ds
        asm     lds     dx, P2175_pc_FileName
        asm     mov     ah, 41h
        asm     int     21h     /* DOS - 2+ - DELETE A FILE (UNLINK) */
                                /* DS:DX -> ASCIZ pathname of file to delete (no wildcards allowed) */
        asm     pop     ds
}

void F0778_FILE_Rename(
char* P2176_pc_SourceFileName,
char* P2177_pc_DestinationFileName)
{
        asm     push    ds
        asm     les     di, P2177_pc_DestinationFileName
        asm     lds     dx, P2176_pc_SourceFileName
        asm     mov     ah, 56h
        asm     int     21h     /* DOS - 2+ - RENAME A FILE */
                                /* DS:DX -> ASCIZ old name (drive and path allowed, no wildcards), ES:DI -> ASCIZ new name */
        asm     pop     ds
}

#ifdef MEDIA707_I34E_I34M
long F0779_FILE_Tell(
FILE_HANDLE P2172_i_FileHandle)
{
        asm     mov     dx, 0
        asm     mov     cx, dx
        asm     mov     bx, P2172_i_FileHandle
        asm     mov     al, 1
        asm     mov     ah, 42h
        asm     int     21h     /* DOS - 2+ - MOVE FILE READ/WRITE POINTER (LSEEK) */
        asm                     /* AL = method: offset from present location */
        asm     mov     ax, dx
        asm     mov     cl, 10h
        asm     shl     ax, cl
        asm     or      ax, ax
        asm     xor     dx, dx
}
#endif
#endif

BOOLEAN F0780_FILE_IsHandleInvalid(
FILE_HANDLE P2179_i_FileHandle)
{
        return P2179_i_FileHandle < 0;
}
#endif

#ifdef MEDIA607_X30J_X31J
#if (EXETYPE == C05_ANIM)
int16_t G3091_i_ErrorCount;
#endif
#if (EXETYPE == C06_CEDT)
extern char* G3886_;
#endif


BOOLEAN F1031_IsOperationSuccessful(
void
)
{
#if (EXETYPE == C06_CEDT)
        BOOLEAN L5940_B_ReturnValue;


        asm {
                        movem.l d1-d7/a0-a6,-(sp)
                        tst.w   G3091_i_ErrorCount(a5)
                        beq.s   @Tloc_EB46
                        clr.w   G3091_i_ErrorCount(a5)
                        moveq   #C0_FALSE,d0
                        bra.s   @Tloc_EB48
                @Tloc_EB46:
                        moveq   #C1_TRUE,d0
                @Tloc_EB48:
                        move.w  d0,L5940_B_ReturnValue(a6)
                        movem.l (sp)+,d1-d7/a0-a6
        }
        return L5940_B_ReturnValue;
#else
        if (G3091_i_ErrorCount) {
                G3091_i_ErrorCount = 0;
                return C0_FALSE;
        }
        return C1_TRUE;
#endif
}

#if (EXETYPE == C06_CEDT)
void F2081_(
)
{
        asm {
                move.l  G3886_(a5),-(sp)
                move.w  #46,-(sp)
                dc.w    0xFF25  /* DOS CALL INTVCS */
                addq.l  #6,sp
        }
}

void F1024_SetTrap14VectorErrorProcessing(
)
{
        G3091_i_ErrorCount = 0;
        asm {
                        lea     @TA5Backup,a0
                        move.l  a5,(a0)
                        pea     @Tloc_1FCC8
                        move.w  #46,-(sp)       /* Replace TRAP 14 (error processing on X68000) exception handler address (vector 46) */
                        dc.w    0xFF25          /* DOS CALL INTVCS */
                        addq.l  #6,sp
                        lea     @THandlerBackup,a0
                        move.l  d0,(a0)
                        move.l  d0,G3886_(a5)
                        bra.s   @Tlocret_1FCE6
                @Tloc_1FCC8:
                        movem.l a0/a5,-(sp)
                        lea     @TA5Backup,a0
                        movea.l (a0),a5
                        ror.w   #8,d7
                        addq.w  #1,G3091_i_ErrorCount(a5)    /* Increment error count each time TRAP 14 is called */
                        move.b  #2,d7
                        movem.l (sp)+,a0/a5
                        rte
                @THandlerBackup
                        dc.l 0
                @TA5Backup:
                        dc.l 0
                @Tlocret_1FCE6:
        }
}
#endif

BOOLEAN F0774_FILE_Seek(
FILE_HANDLE P2170_i_FileHandle,
long P2171_l_Offset)
{
        asm {
                        clr.w   -(sp)
                        move.l  P2171_l_Offset(a6),-(sp)
                        move.w  P2170_i_FileHandle(a6),-(sp)
                        dc.w    0xFF42          /* DOS CALL SEEK */
                        addq.l  #8,sp
                        cmp.l   P2171_l_Offset(a6),d0
                        bne.s   @Tloc_1FBAA
                        jsr     F1031_IsOperationSuccessful
                        bra.s   @Tloc_1FBAC
                @Tloc_1FBAA:
                        moveq   #0,d0
                @Tloc_1FBAC:
        }
}

long F0779_FILE_Tell(
#if (EXETYPE == C06_CEDT)
FILE_HANDLE P2172_i_FileHandle,
long* P5965_)
#else
FILE_HANDLE P2172_i_FileHandle)
#endif
{
        asm {
                        move.w  #1,-(sp)
                        clr.l   -(sp)
                        move.w  P2172_i_FileHandle(a6),-(sp)
                        dc.w    0xFF42          /* DOS CALL SEEK */
                        addq.l  #8,sp
#if (EXETYPE == C06_CEDT)
                        tst.l   d0
                        bmi.s   @Tloc_EBEA
                        moveq   #0,d0
                        bra.s   @Tloc_EBF4
                @Tloc_EBEA:
                        movea.l P5965_(a6),a0
                        move.l  d0,(a0)
                        jsr     F1031_IsOperationSuccessful
                @Tloc_EBF4:
#endif
        }
#if (EXETYPE != C06_CEDT)
        G3091_i_ErrorCount = 0;
#endif
}

unsigned long F0775_FILE_GetSize(
#if (EXETYPE == C06_CEDT)
FILE_HANDLE P2173_i_FileHandle,
long* P5966_)
#else
FILE_HANDLE P2173_i_FileHandle)
#endif
{
        asm {
                        move.w  #2,-(sp)
                        clr.l   -(sp)
                        move.w  P2173_i_FileHandle(a6),-(sp)
                        dc.w    0xFF42          /* DOS CALL SEEK */
                        addq.l  #8,sp
#if (EXETYPE == C06_CEDT)
                        tst.l   d0
                        bmi.s   @Tloc_EC12
                        moveq   #0,d0
                        bra.s   @Tloc_EC1C
                @Tloc_EC12:
                        movea.l P5966_(a6),a0
                        move.l  d0,(a0)
                        jsr     F1031_IsOperationSuccessful
                @Tloc_EC1C:
#endif
        }
#if (EXETYPE != C06_CEDT)
        G3091_i_ErrorCount = 0;
#endif
}

FILE_HANDLE F0770_FILE_Open(
#if (EXETYPE == C06_CEDT)
char* P2162_pc_FileName,
int16_t P5967_)
#else
char* P2162_pc_FileName)
#endif
{
#if (EXETYPE == C06_CEDT)
        int16_t L5941_;


        if (P5967_ == 0) {
                L5941_ = 0;
        } else {
                if (P5967_ == 1) {
                        L5941_ = 2;
                } else {
                        L5941_ = 2;
                }
        }
        asm {
                        move.w  L5941_,-(sp)
#else
        asm {
#ifdef MEDIA577_X30J
                        move.w  #2,-(sp)
#endif
#ifdef MEDIA692_X31J
#if (EXETYPE == C05_ANIM)
                        move.w  #0,-(sp)
#endif
#if (EXETYPE == C03_GAME)
                        clr.w   -(sp)
#endif
#endif
#endif
                        move.l  P2162_pc_FileName(a6),-(sp)
                        dc.w    0xFF3D          /* DOS CALL OPEN */
                        addq.l  #6,sp
                        move.w  d0,d1
                        jsr     F1031_IsOperationSuccessful
                        bne.s   @Tloc_1FBFE
                        moveq   #0xFFFFFFFF,d0
                @Tloc_1FBFE:
                        move.l  d1,d0
        }
}

FILE_HANDLE F0776_FILE_Create(
char* P2174_pc_FileName)
{
        asm {
                        move.w  #0x20,-(sp)
                        move.l  P2174_pc_FileName(a6),-(sp)
                        dc.w    0xFF3C          /* DOS CALL CREATE */
                        addq.l  #6,sp
                        move.w  d0,d1
                        jsr     F1031_IsOperationSuccessful
                        bne.s   @Tloc_1FC1E
                        moveq   #0xFFFFFFFF,d0
                @Tloc_1FC1E:
                        move.l  d1,d0
        }
}

#if (EXETYPE == C06_CEDT)
int16_t F0771_FILE_Close(
#else
void F0771_FILE_Close(
#endif
FILE_HANDLE P2163_i_FileHandle)
{
        asm {
                        move.w  P2163_i_FileHandle(a6),-(sp)
                        dc.w    0xFF3E          /* DOS CALL CLOSE */
                        addq.l  #2,sp
#if (EXETYPE == C06_CEDT)
                        jsr     F1031_IsOperationSuccessful
#endif
        }
#if (EXETYPE != C06_CEDT)
        G3091_i_ErrorCount = 0;
#endif
}

#if (EXETYPE == C06_CEDT)
int16_t F0777_FILE_Delete(
#else
void F0777_FILE_Delete(
#endif
char* P2175_pc_FileName)
{
        asm {
                        move.l  P2175_pc_FileName(a6),-(sp)
                        dc.w    0xFF41          /* DOS CALL DELETE */
                        addq.l  #4,sp
#if (EXETYPE == C06_CEDT)
                        jsr     F1031_IsOperationSuccessful
#endif
        }
#if (EXETYPE != C06_CEDT)
        G3091_i_ErrorCount = 0;
#endif
}

#if (EXETYPE == C06_CEDT)
int16_t F0778_FILE_Rename(
#else
void F0778_FILE_Rename(
#endif
char* P2176_pc_SourceFileName,
char* P2177_pc_DestinationFileName)
{
        asm {
                        move.l  P2177_pc_DestinationFileName(a6),-(sp)
                        move.l  P2176_pc_SourceFileName(a6),-(sp)
                        dc.w    0xFF56          /* DOS CALL RENAME */
                        addq.l  #8,sp
#if (EXETYPE == C06_CEDT)
                        jsr     F1031_IsOperationSuccessful
#endif
        }
#if (EXETYPE != C06_CEDT)
        G3091_i_ErrorCount = 0;
#endif
}

BOOLEAN F0772_FILE_Read(
FILE_HANDLE P2164_i_FileHandle,
unsigned long P2165_ul_ByteCount,
unsigned char* P2166_puc_Buffer)
{
        asm {
                        move.l  P2165_ul_ByteCount(a6),-(sp)
                        move.l  P2166_puc_Buffer(a6),-(sp)
                        move.w  P2164_i_FileHandle(a6),-(sp)
                        dc.w    0xFF3F          /* DOS CALL READ */
                        lea     0xA(sp),sp
                        cmp.l   P2165_ul_ByteCount(a6),d0
                        bne.s   @Tloc_1FC86
                        jsr     F1031_IsOperationSuccessful
                        bra.s   @Tloc_1FC88
                @Tloc_1FC86:
                        moveq   #0,d0
                @Tloc_1FC88:
        }
}

BOOLEAN F0773_FILE_Write(
FILE_HANDLE P2167_i_FileHandle,
unsigned long P2168_ul_ByteCount,
unsigned char* P2169_puc_Buffer)
{
        asm {
                        move.l  P2168_ul_ByteCount(a6),-(sp)
                        move.l  P2169_puc_Buffer(a6),-(sp)
                        move.w  P2167_i_FileHandle(a6),-(sp)
                        dc.w    0xFF40          /* DOS CALL WRITE */
                        lea     0xA(sp),sp
                        cmp.l   P2168_ul_ByteCount(a6),d0
                        bne.s   @Tloc_1FCAE
                        jsr     F1031_IsOperationSuccessful
                        bra.s   @Tloc_1FCB0
                @Tloc_1FCAE:
                        moveq   #0,d0
                @Tloc_1FCB0:
        }
}

#if (EXETYPE != C06_CEDT)
void F1024_SetTrap14VectorErrorProcessing(
)
{
        asm {
                        lea     @TA5Backup,a0
                        move.l  a5,(a0)
                        pea     @Tloc_1FCC8
                        move.w  #46,-(sp)       /* Replace TRAP 14 (error processing on X68000) exception handler address (vector 46) */
                        dc.w    0xFF25          /* DOS CALL INTVCS */
                        addq.l  #6,sp
                        bra.s   @Tlocret_1FCE6
                @Tloc_1FCC8:
                        movem.l a0/a5,-(sp)
#if (defined(MEDIA577_X30J) || (defined(MEDIA692_X31J) && (EXETYPE == C05_ANIM)))
                        lea     @TA5Backup,a0
                        movea.l (a0),a5
#endif
#if (defined(MEDIA692_X31J) && (EXETYPE == C03_GAME))
                        movea.l @TA5Backup,a5
#endif
                        ror.w   #8,d7
                        addq.w  #1,G3091_i_ErrorCount(a5)    /* Increment error count each time TRAP 14 is called */
#if (defined(MEDIA577_X30J) || (defined(MEDIA692_X31J) && (EXETYPE == C05_ANIM)))
                        move.b  #2,d7
#endif
#if (defined(MEDIA692_X31J) && (EXETYPE == C03_GAME))
                        move.b  #3,d7
#endif
                        movem.l (sp)+,a0/a5
                        rte
                @TA5Backup:
                        dc.l 0
                @Tlocret_1FCE6:
        }
}

int16_t F1025_GetFloppyDriveStatus(
int16_t P2759_i_PDA)
{
        asm {
                        moveq   #0x4E,d0                /* B_DRVCHK */
                        move.w  P2759_i_PDA(a6),d1      /* 0x90 for Drive 0, 0x91 for Drive 1 */
                        lsl.w   #8,d1
                        clr.w   d2
                        trap    #0xF                    /* TRAP 15 (IOCS CALL) */
                        clr.w   G3091_i_ErrorCount(a5)
                        btst    #2,d0                   /* Not ready */
                        beq.s   @Tloc_1FD06
                        moveq   #2,d0                   /* D0=2 if drive not ready */
                        bra.s   @Tloc_1FD12
                @Tloc_1FD06:
                        btst    #3,d0                   /* Protected */
                        beq.s   @Tloc_1FD10
                        moveq   #1,d0                   /* D0=1 if floppy disk is protected */
                        bra.s   @Tloc_1FD12
                @Tloc_1FD10:
                        moveq   #0,d0                   /* D0=0 if drive is ready and floppy disk is not protected */
                @Tloc_1FD12:
        }
}
#endif
#endif

#ifdef MEDIA753_A36M_A31E_A31M_A33M_A35E_A35M_AU1E_AU2E_AU2F
FILE_HANDLE F0770_FILE_Open(
char* P2162_pc_FileName FINAL_SEPARATOR
{
#if (EXETYPE == C08_LANG)
        FILE_HANDLE L4793_;


        L4793_ = Open(P2162_pc_FileName, MODE_OLDFILE);
        return L4793_;
#else
        return Open(P2162_pc_FileName, MODE_OLDFILE);
#endif
}

FILE_HANDLE F0776_FILE_Create(
char* P2174_pc_FileName FINAL_SEPARATOR
{
#if (EXETYPE == C08_LANG)
        FILE_HANDLE L4794_;


        L4794_ = Open(P2174_pc_FileName, MODE_NEWFILE);
        return L4794_;
#else
        return Open(P2174_pc_FileName, MODE_NEWFILE);
#endif
}

void F0771_FILE_Close(
FILE_HANDLE P2163_i_FileHandle FINAL_SEPARATOR
{
        if (P2163_i_FileHandle) {
                Close(P2163_i_FileHandle);
        }
}

long F0774_FILE_Seek(
FILE_HANDLE P2170_i_FileHandle SEPARATOR
long               P2171_l_Offset     FINAL_SEPARATOR
{
        Seek(P2170_i_FileHandle, P2171_l_Offset, OFFSET_BEGINNING);
#if (EXETYPE != C12_FIO1)
        return -1;
#endif
}

long F0772_FILE_Read(
FILE_HANDLE P2164_i_FileHandle SEPARATOR
unsigned long      P2165_ul_ByteCount SEPARATOR
unsigned char*     P2166_puc_Buffer   FINAL_SEPARATOR
{
        return (Read(P2164_i_FileHandle, P2166_puc_Buffer, P2165_ul_ByteCount) == P2165_ul_ByteCount);
}

long F0773_FILE_Write(
FILE_HANDLE P2167_i_FileHandle SEPARATOR
unsigned long      P2168_ul_ByteCount SEPARATOR
unsigned char*     P2169_puc_Buffer   FINAL_SEPARATOR
{
        return (Write(P2167_i_FileHandle, P2169_puc_Buffer, P2168_ul_ByteCount) == P2168_ul_ByteCount);
}

long F0779_FILE_Tell(
FILE_HANDLE P2172_i_FileHandle FINAL_SEPARATOR
{
        return Seek(P2172_i_FileHandle, 0L, OFFSET_CURRENT);
}

unsigned long F0775_FILE_GetSize(
FILE_HANDLE P2173_i_FileHandle FINAL_SEPARATOR
{
        long L2591_l_;
        long L2592_l_;

        L2591_l_ = Seek(P2173_i_FileHandle, 0L, OFFSET_CURRENT);
        Seek(P2173_i_FileHandle, 0L, OFFSET_END);
        L2592_l_ = Seek(P2173_i_FileHandle, 0L, OFFSET_BEGINNING);
        Seek(P2173_i_FileHandle, L2591_l_, OFFSET_BEGINNING);
        return L2592_l_;
}

long F0777_FILE_Delete(
char* P2175_pc_FileName FINAL_SEPARATOR
{
        return DeleteFile(P2175_pc_FileName);
}

long F0778_FILE_Rename(
char* P2176_pc_SourceFileName      SEPARATOR
char* P2177_pc_DestinationFileName FINAL_SEPARATOR
{
        return Rename(P2176_pc_SourceFileName, P2177_pc_DestinationFileName);
}
#endif

#ifdef MEDIA551_F20E_F20J_F31E_F31J
FILE_HANDLE F0770_FILE_Open(
char* P2162_pc_FileName FINAL_SEPARATOR
{
        return G4081_i_FileHandle = fopen(P2162_pc_FileName, "rb");
}

void F0771_FILE_Close(
FILE_HANDLE P2163_i_FileHandle FINAL_SEPARATOR
{
        fclose(P2163_i_FileHandle);
}

BOOLEAN F0772_FILE_Read(
FILE_HANDLE         P2164_i_FileHandle SEPARATOR
unsigned long       P2165_ul_ByteCount SEPARATOR
unsigned char*      P2166_puc_Buffer   FINAL_SEPARATOR
{
        unsigned int L2567_ui_ByteCount;
        long L6499_l_Offset;
        int L6500_;


        L6499_l_Offset = ftell(P2164_i_FileHandle);
        for (L6500_ = 0; L6500_ < 4; L6500_++) {
                L2567_ui_ByteCount = fread(P2166_puc_Buffer, 1, P2165_ul_ByteCount, P2164_i_FileHandle);
                if (L2567_ui_ByteCount == P2165_ul_ByteCount) {
                        break;
                }
                if (P2164_i_FileHandle->_flag & _END_OF_FILE) {
                        return C0_FALSE;
                }
                fseek(P2164_i_FileHandle, L6499_l_Offset, SEEK_SET);
        }
        return (L2567_ui_ByteCount == P2165_ul_ByteCount);
}

BOOLEAN F0773_FILE_Write(
FILE_HANDLE         P2167_i_FileHandle SEPARATOR
unsigned long       P2168_ul_ByteCount SEPARATOR
unsigned char*      P2169_puc_Buffer   FINAL_SEPARATOR
{
        return (fwrite(P2169_puc_Buffer, 1, P2168_ul_ByteCount, P2167_i_FileHandle) == P2168_ul_ByteCount);
}

BOOLEAN F0774_FILE_Seek(
FILE_HANDLE P2170_i_FileHandle SEPARATOR
long        P2171_l_Offset     FINAL_SEPARATOR
{
        return (fseek(P2170_i_FileHandle, P2171_l_Offset, SEEK_SET) == 0);
}

long F0779_FILE_Tell(
FILE_HANDLE P2172_i_FileHandle FINAL_SEPARATOR
{
        return ftell(P2172_i_FileHandle);
}

unsigned long F0775_FILE_GetSize(
FILE_HANDLE P2173_i_FileHandle FINAL_SEPARATOR
{
        fseek(P2173_i_FileHandle, 0, SEEK_END);
        return ftell(P2173_i_FileHandle);
}

FILE_HANDLE F0776_FILE_Create(
char* P2174_pc_FileName FINAL_SEPARATOR
{
        return G4081_i_FileHandle = fopen(P2174_pc_FileName, "wb");
}

void F0777_FILE_Delete(
char* P2175_pc_FileName FINAL_SEPARATOR
{
        remove(P2175_pc_FileName);
}

void F0778_FILE_Rename(
char* P2176_pc_SourceFileName      SEPARATOR
char* P2177_pc_DestinationFileName FINAL_SEPARATOR
{
        rename(P2176_pc_SourceFileName, P2177_pc_DestinationFileName);
}

BOOLEAN F0780_FILE_IsHandleInvalid(
FILE_HANDLE P2179_i_FileHandle FINAL_SEPARATOR
{
        return (G4081_i_FileHandle == 0);
}
#endif
#endif
