#ifndef COMPILE_H
#include "COMPILE.H"
#endif
#ifdef MEDIA426_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_A36M_A31E_A31M_A33M_A35E_A35M_AU1E_AU2E_AU2F_AU2G_AU3E
#if (EXETYPE == C03_GAME)
#include "COPYPRO2.C"
#endif


#ifdef MEDIA626_A31E_A31M_A33M_A35E_A35M
#if (EXETYPE == C03_GAME)
struct MiscResource* G3188_ps_DiskResource_CPSX;
#ifndef NOCOPYPROTECTION
struct DiscResourceUnit* G3189_ps_DiskResourceUnit_CPSX;
struct MsgPort* G3190_ps_MsgPort_CPSX;
#endif
#endif
#endif
#ifdef MEDIA413_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
char G1081_ac_DriveDeviceName[4] = { 'd', 'f', '0', ':' };
#endif
#ifdef MEDIA752_A36M_A31E_A31M_A33M_A35E_A35M_AU1E_AU2E
struct MsgPort* G3184_ps_MsgPort = NULL;
#endif
struct MsgPort* G1082_ps_MsgPort = NULL;
#ifdef MEDIA752_A36M_A31E_A31M_A33M_A35E_A35M_AU1E_AU2E
struct IOExtTD* G3181_ps_IOExtTD = NULL;
#endif
struct StandardPacket* G1083_ps_StandardPacket = NULL;
#ifdef MEDIA752_A36M_A31E_A31M_A33M_A35E_A35M_AU1E_AU2E
APTR G3183_TrackBuffer = NULL;
struct IOExtTD* G3176_ps_IOExtTD = NULL;
struct MsgPort* G3186_ps_MsgPort = NULL;
BOOLEAN G3182_B_TrackdiskDeviceOpened = C0_FALSE;
#if ((EXETYPE == C03_GAME) || (EXETYPE == C06_CEDT) || (EXETYPE == C07_HINT) || (EXETYPE == C12_FIO1))
char G1081_ac_DriveDeviceName[4] = { 'd', 'f', '0', ':' };
#endif
#endif


#ifdef MEDIA752_A36M_A31E_A31M_A33M_A35E_A35M_AU1E_AU2E
void F1111_CPSX(
)
{
        if ((G3183_TrackBuffer = AllocMem(TD_SECTOR * NUMSECS, MEMF_CHIP | MEMF_CLEAR)) == NULL) {
#if (EXETYPE == C03_GAME)
                F1050_AlertCSBSystemError(0x80FF0025);
#else
                F9073_DisplayError(0x80F1000C);
#endif
        }
        if ((G3184_ps_MsgPort = CreatePort(NULL, 16L)) == NULL) {
#if (EXETYPE == C03_GAME)
                F1050_AlertCSBSystemError(0x80FF0006);
#else
                F9073_DisplayError(0x80F10006);
#endif
        }
        if ((G3181_ps_IOExtTD = CreateExtIO(G3184_ps_MsgPort, (long)sizeof(struct IOExtTD))) == NULL) {
#if (EXETYPE == C03_GAME)
                F1050_AlertCSBSystemError(0x80FF0007);
#else
                F9073_DisplayError(0x80F10007);
#endif
        }
        if ((G1082_ps_MsgPort = CreatePort(NULL, 16L)) == NULL) {
#if (EXETYPE == C03_GAME)
                F1050_AlertCSBSystemError(0x80FF0008);
#else
                F9073_DisplayError(0x80F10008);
#endif
        }
        if ((G1083_ps_StandardPacket = AllocMem((long)sizeof(struct StandardPacket), MEMF_CLEAR | MEMF_PUBLIC)) == NULL) {
#if (EXETYPE == C03_GAME)
                F1050_AlertCSBSystemError(0x80FF0009);
#else
                F9073_DisplayError(0x80F10009);
#endif
        }
        if ((G3186_ps_MsgPort = CreatePort(NULL, 16L)) == NULL) {
#if (EXETYPE == C03_GAME)
                F1050_AlertCSBSystemError(0x80FF0026);
#else
                F9073_DisplayError(0x80F1000D);
#endif
        }
        if ((G3176_ps_IOExtTD = CreateExtIO(G3186_ps_MsgPort, (long)sizeof(struct IOExtTD))) == NULL) {
#if (EXETYPE == C03_GAME)
                F1050_AlertCSBSystemError(0x80FF0027);
#else
                F9073_DisplayError(0x80F1000E);
#endif
        }
#if (defined(MEDIA626_A31E_A31M_A33M_A35E_A35M) && (EXETYPE == C03_GAME))
#ifndef NOCOPYPROTECTION
        if ((G3188_ps_DiskResource_CPSX = G1054_ps_DiskResource_CPSX = OpenResource("disk.resource", 0L)) == NULL) {
                F1050_AlertCSBSystemError(0x80FF0011);
        }
        if ((G3189_ps_DiskResourceUnit_CPSX = G1053_ps_DiscResourceUnit_CPSX = AllocMem((long)sizeof(struct DiscResourceUnit), MEMF_CLEAR | MEMF_PUBLIC)) == NULL) {
                F1050_AlertCSBSystemError(0x80FF0028);
        }
        if ((G3190_ps_MsgPort_CPSX = G3189_ps_DiskResourceUnit_CPSX->dru_Message.mn_ReplyPort = CreatePort(NULL, 16L)) == NULL) {
                F1050_AlertCSBSystemError(0x80FF0012);
        }
#endif
#endif
}
#endif

void F0518_FLOPPY_Deinitialize_CPSX(
)
{
#ifdef MEDIA413_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        if (G0734_ps_AmigaData->IOExtTD) {
                FreeMem(G0734_ps_AmigaData->IOExtTD, (long)sizeof(struct IOExtTD));
        }
        if (G0734_ps_AmigaData->IOExtTDReplyPort) {
                DeletePort(G0734_ps_AmigaData->IOExtTDReplyPort);
        }
        if (G0734_ps_AmigaData->TrackBuffer) {
                FreeMem(G0734_ps_AmigaData->TrackBuffer, TD_SECTOR * NUMSECS);
        }
#endif
#ifdef MEDIA752_A36M_A31E_A31M_A33M_A35E_A35M_AU1E_AU2E
#if (defined(MEDIA626_A31E_A31M_A33M_A35E_A35M) && (EXETYPE == C03_GAME))
#ifndef NOCOPYPROTECTION
        if (G3190_ps_MsgPort_CPSX) {
                DeletePort(G3190_ps_MsgPort_CPSX);
        }
        G3190_ps_MsgPort_CPSX = NULL;
        if (G3189_ps_DiskResourceUnit_CPSX) {
                FreeMem(G3189_ps_DiskResourceUnit_CPSX, (long)sizeof(struct DiscResourceUnit));
        }
        G3189_ps_DiskResourceUnit_CPSX = NULL;
#endif
#endif
        if (G3176_ps_IOExtTD) {
                DeleteExtIO(G3176_ps_IOExtTD);
        }
        G3176_ps_IOExtTD = NULL;
        if (G3186_ps_MsgPort) {
                DeletePort(G3186_ps_MsgPort);
        }
        G3186_ps_MsgPort = NULL;
        if (G1083_ps_StandardPacket) {
                FreeMem(G1083_ps_StandardPacket, (long)sizeof(struct StandardPacket));
        }
        G1083_ps_StandardPacket = NULL;
        if (G1082_ps_MsgPort) {
                DeletePort(G1082_ps_MsgPort);
        }
        G1082_ps_MsgPort = NULL;
        if (G3181_ps_IOExtTD) {
                DeleteExtIO(G3181_ps_IOExtTD);
        }
        G3181_ps_IOExtTD = NULL;
        if (G3184_ps_MsgPort) {
                DeletePort(G3184_ps_MsgPort);
        }
        G3184_ps_MsgPort = NULL;
        if (G3183_TrackBuffer) {
                FreeMem(G3183_TrackBuffer, TD_SECTOR * NUMSECS);
        }
        G3183_TrackBuffer = NULL;
#endif
}

#ifdef MEDIA413_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
int16_t F0519_FLOPPY_GetFormatResult(
P0944_i_DriveIndex, P0945_pc_DiskName)
int16_t P0944_i_DriveIndex SEPARATOR
char*   P0945_pc_DiskName  FINAL_SEPARATOR
{
        long L1697_l_Unreferenced;
        char* L1698_pc_TrackFillerString = "DOS";
        long L1699_ac_TrackFillerLong = 0;
        ULONG L1700_ul_DiskChangeCount;
        int16_t L1701_i_Result = 0;
        unsigned int16_t L1702_ui_Counter;
        int16_t L1703_i_Unreferenced;
        unsigned int16_t L1704_ui_TrackIndex;
        char* L1705_pc_DiskName;
        APTR L1706_ppuc_TrackContent;
        long* L1707_pl_TrackContent;


        G1081_ac_DriveDeviceName[2] = P0944_i_DriveIndex + '0';
        F0008_MAIN_ClearBytes(G0734_ps_AmigaData->TrackBuffer, TD_SECTOR * NUMSECS);
        L1706_ppuc_TrackContent = (APTR)G0734_ps_AmigaData->TrackBuffer;
        L1707_pl_TrackContent = (long*)L1706_ppuc_TrackContent;
        for (L1702_ui_Counter = 0; L1702_ui_Counter < 3; L1702_ui_Counter++) {
                L1699_ac_TrackFillerLong = L1698_pc_TrackFillerString[L1702_ui_Counter] | (L1699_ac_TrackFillerLong << 8);
        }
        L1699_ac_TrackFillerLong <<= 8;
        for (L1702_ui_Counter = 0; L1702_ui_Counter < TD_SECTOR * NUMSECS / 4; L1702_ui_Counter++) {
                L1707_pl_TrackContent[L1702_ui_Counter] = (L1702_ui_Counter & 0xFF) | L1699_ac_TrackFillerLong;
        }
        if (F0524_FLOPPY_OpenTrackdiskDevice(P0944_i_DriveIndex)) {
                if (L1701_i_Result = F0523_FLOPPY_InhibitFileSystem(G1081_ac_DriveDeviceName, 1)) {
                        goto T0519001;
                }
                F0526_FLOPPY_DoTrackdiskDeviceIO(TD_CHANGENUM, 0L, 0);
                L1700_ul_DiskChangeCount = G0734_ps_AmigaData->IOExtTD->iotd_Req.io_Actual;
#ifdef MEDIA430_A20ED_A20E_A21E_A22E
                F0043_TEXT_MESSAGEAREA_ClearAllRows();
#endif
                for (L1704_ui_TrackIndex = 0; L1704_ui_TrackIndex < NUMTRACKS; L1704_ui_TrackIndex++) {
#ifdef MEDIA430_A20ED_A20E_A21E_A22E
                        strcpy(G0353_ac_StringBuildBuffer, "FORMATTING TRACK XX, SIDE X");
                        G0353_ac_StringBuildBuffer[17] = ((L1704_ui_TrackIndex / 2) / 10) + '0';
                        G0353_ac_StringBuildBuffer[18] = ((L1704_ui_TrackIndex / 2) % 10) + '0';
                        G0353_ac_StringBuildBuffer[26] = (L1704_ui_TrackIndex & 1) + '0';
                        F0553_TEXT_MESSAGEAREA_MoveCursorToTopLeft();
                        F0047_TEXT_MESSAGEAREA_PrintMessage(C15_COLOR_WHITE, G0353_ac_StringBuildBuffer);
#endif
                        G0734_ps_AmigaData->IOExtTD->iotd_Req.io_Command = TD_FORMAT;
                        G0734_ps_AmigaData->IOExtTD->iotd_Req.io_Flags = 0;
                        G0734_ps_AmigaData->IOExtTD->iotd_Req.io_Data = L1706_ppuc_TrackContent;
                        G0734_ps_AmigaData->IOExtTD->iotd_Count = L1700_ul_DiskChangeCount;
                        G0734_ps_AmigaData->IOExtTD->iotd_Req.io_Length = TD_SECTOR * NUMSECS;
                        G0734_ps_AmigaData->IOExtTD->iotd_Req.io_Offset = L1704_ui_TrackIndex * (TD_SECTOR * NUMSECS);
                        DoIO(G0734_ps_AmigaData->IOExtTD);
                        if (L1701_i_Result = F0521_FLOPPY_GetIOError(G0734_ps_AmigaData->IOExtTD, "Formatting error")) {
                                goto T0519000;
                        }
#ifdef MEDIA430_A20ED_A20E_A21E_A22E
                        strcpy(G0353_ac_StringBuildBuffer, "VERIFYING  TRACK XX, SIDE X");
                        G0353_ac_StringBuildBuffer[17] = ((L1704_ui_TrackIndex / 2) / 10) + '0';
                        G0353_ac_StringBuildBuffer[18] = ((L1704_ui_TrackIndex / 2) % 10) + '0';
                        G0353_ac_StringBuildBuffer[26] = (L1704_ui_TrackIndex & 1) + '0';
                        F0553_TEXT_MESSAGEAREA_MoveCursorToTopLeft();
                        F0047_TEXT_MESSAGEAREA_PrintMessage(C15_COLOR_WHITE, G0353_ac_StringBuildBuffer);
#endif
                        G0734_ps_AmigaData->IOExtTD->iotd_Req.io_Command = TD_RAWREAD;
                        G0734_ps_AmigaData->IOExtTD->iotd_Req.io_Flags = 0;
                        G0734_ps_AmigaData->IOExtTD->iotd_Req.io_Data = L1706_ppuc_TrackContent;
                        G0734_ps_AmigaData->IOExtTD->iotd_Count = L1700_ul_DiskChangeCount;
                        G0734_ps_AmigaData->IOExtTD->iotd_Req.io_Actual = 0;
                        G0734_ps_AmigaData->IOExtTD->iotd_Req.io_Offset = L1704_ui_TrackIndex;
                        G0734_ps_AmigaData->IOExtTD->iotd_Req.io_Length = TD_SECTOR * NUMSECS;
                        DoIO(G0734_ps_AmigaData->IOExtTD);
                        L1701_i_Result = F0521_FLOPPY_GetIOError(G0734_ps_AmigaData->IOExtTD, "Verification error");
                        if ((L1701_i_Result != 0) && (L1701_i_Result != -4)) {
                                goto T0519000;
                        }
                }
                /* Prepare root sector */
                for (L1702_ui_Counter = 0; L1702_ui_Counter < 128; L1702_ui_Counter++) {
                        L1707_pl_TrackContent[L1702_ui_Counter] = 0;
                }
                L1707_pl_TrackContent[0] = 2; /* Block primary type = T_HEADER (value 2) */
                L1707_pl_TrackContent[3] = 0x48; /* Hash table size in long, value 0x48 for floppy disk */
                L1707_pl_TrackContent[78] = 0xFFFFFFFF; /* Bitmap flag, -1 means VALID */
                L1707_pl_TrackContent[79] = 881; /* Bitmap blocks pointers (first one at bm_pages[0]) */
                DateStamp((struct DateStamp*)&L1707_pl_TrackContent[105]); /* Last root alteration date */
                DateStamp((struct DateStamp*)&L1707_pl_TrackContent[121]); /* Filesystem creation date */
                L1705_pc_DiskName = (char*)&L1707_pl_TrackContent[108];
                *L1705_pc_DiskName = strlen(P0945_pc_DiskName); /* Length of disk name */
                for (L1702_ui_Counter = 0; L1702_ui_Counter < *L1705_pc_DiskName; L1702_ui_Counter++) {
                        (L1705_pc_DiskName + 1)[L1702_ui_Counter] = P0945_pc_DiskName[L1702_ui_Counter]; /* Disk name */
                }
                L1707_pl_TrackContent[127] = 1; /* Block secondary type = ST_ROOT (value 1) */
                L1707_pl_TrackContent[5] = 0 - F0520_FLOPPY_GetSectorChecksum(L1707_pl_TrackContent); /* Root block checksum */
                G0734_ps_AmigaData->IOExtTD->iotd_Req.io_Command = CMD_WRITE;
                G0734_ps_AmigaData->IOExtTD->iotd_Req.io_Length = TD_SECTOR;
                G0734_ps_AmigaData->IOExtTD->iotd_Req.io_Offset = NUMCYLS * NUMSECS * TD_SECTOR; /* First sector on second side */
                DoIO(G0734_ps_AmigaData->IOExtTD);
                if (L1701_i_Result = F0521_FLOPPY_GetIOError(G0734_ps_AmigaData->IOExtTD, "Error writing root block")) {
                        goto T0519000;
                }
                for (L1702_ui_Counter = 1; L1702_ui_Counter < 55; L1702_ui_Counter++) {
                        L1707_pl_TrackContent[L1702_ui_Counter] = 0xFFFFFFFF; /* 54 * 32 = 1760 bits = 2 x 880, one bit for each block on the floppy disk */
                }
                L1707_pl_TrackContent[28] = 0xFFFF3FFF; /* Block x is used */
                L1707_pl_TrackContent[55] = 0x3FFFFFFF; /* Block x is used */
                L1707_pl_TrackContent[0] = 0; /* First 32 blocks are used */
                for (L1702_ui_Counter = 56; L1702_ui_Counter < 128; L1702_ui_Counter++) {
                        L1707_pl_TrackContent[L1702_ui_Counter] = 0; /* Clear the rest of the sector */
                }
                L1707_pl_TrackContent[0] = 0 - F0520_FLOPPY_GetSectorChecksum(L1707_pl_TrackContent); /* Bitmap block checksum */
                G0734_ps_AmigaData->IOExtTD->iotd_Req.io_Length = TD_SECTOR;
                G0734_ps_AmigaData->IOExtTD->iotd_Req.io_Offset = NUMCYLS * NUMSECS * TD_SECTOR + TD_SECTOR; /* Second sector on second side */
                DoIO(G0734_ps_AmigaData->IOExtTD);
                L1701_i_Result = F0521_FLOPPY_GetIOError(G0734_ps_AmigaData->IOExtTD, "Error writing bitmap");
                T0519000:
                F0526_FLOPPY_DoTrackdiskDeviceIO(ETD_UPDATE, 0L, 0); /* Flush buffered track to disk */
                F0526_FLOPPY_DoTrackdiskDeviceIO(TD_MOTOR, 0L, 0); /* Turn off motor */
                F0523_FLOPPY_InhibitFileSystem(G1081_ac_DriveDeviceName, 0);
                Delay(150L);
        }
        T0519001:
#ifdef MEDIA430_A20ED_A20E_A21E_A22E
        F0043_TEXT_MESSAGEAREA_ClearAllRows();
#endif
        CloseDevice(G0734_ps_AmigaData->IOExtTD);
        return L1701_i_Result;
}

long F0520_FLOPPY_GetSectorChecksum(
P0946_pc_)
register long* P0946_pc_ FINAL_SEPARATOR
{
        register int16_t L2610_i_;
        register long L2611_l_;


        L2611_l_ = 0;
        for (L2610_i_ = 0; L2610_i_ < 128; L2610_i_++) {
                L2611_l_ += *P0946_pc_++;
        }
        return L2611_l_;
}

int16_t F0521_FLOPPY_GetIOError(
P0947_ps_, P0948_pc_ErrorMessage)
struct IOStdReq* P0947_ps_             SEPARATOR
char*            P0948_pc_ErrorMessage FINAL_SEPARATOR
{
        REGISTER int16_t L1711_i_;


        L1711_i_ = P0947_ps_->io_Error;
        return L1711_i_;
}
#endif

#ifdef MEDIA752_A36M_A31E_A31M_A33M_A35E_A35M_AU1E_AU2E
BOOLEAN F0524_FLOPPY_OpenTrackdiskDevice(
P0955_i_DriveIndex)
int16_t P0955_i_DriveIndex;
{
        return G3182_B_TrackdiskDeviceOpened = (OpenDevice("trackdisk.device", (long)P0955_i_DriveIndex, G3181_ps_IOExtTD, 0L) == 0);
}

void F1114_CloseTrackdiskDevice(
)
{
        if (G3182_B_TrackdiskDeviceOpened) {
                CloseDevice(G3181_ps_IOExtTD);
        }
        G3182_B_TrackdiskDeviceOpened = C0_FALSE;
}

int16_t F0526_FLOPPY_DoTrackdiskDeviceIO(
long P0957_ul_Command,
ULONG P0958_ul_Length,
UBYTE P0959_uc_Flags)
{
        G3181_ps_IOExtTD->iotd_Req.io_Command = (UWORD)P0957_ul_Command;
        G3181_ps_IOExtTD->iotd_Req.io_Flags = P0959_uc_Flags;
        G3181_ps_IOExtTD->iotd_Req.io_Length = P0958_ul_Length;
        DoIO(G3181_ps_IOExtTD);
#if (EXETYPE == C09_CNFG)
        return G3181_ps_IOExtTD->iotd_Req.io_Error;
#endif
}
#endif

long F0522_FLOPPY_SendDosPacket(
#ifdef MEDIA413_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0949_ps_MsgPort, P0950_l_DosPacketType, P0951_pl_Arguments, P0952_ArgumentCount)
#endif
struct MsgPort* P0949_ps_MsgPort      SEPARATOR
long            P0950_l_DosPacketType SEPARATOR
long*           P0951_pl_Arguments    SEPARATOR
#ifdef MEDIA413_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
long            P0952_ArgumentCount   FINAL_SEPARATOR
#endif
#ifdef MEDIA752_A36M_A31E_A31M_A33M_A35E_A35M_AU1E_AU2E
#if ((EXETYPE == C03_GAME) || (EXETYPE == C06_CEDT) || (EXETYPE == C12_FIO1))
register int16_t P0952_ArgumentCount  FINAL_SEPARATOR
#endif
#if ((EXETYPE == C07_HINT) || (EXETYPE == C09_CNFG))
long            P0952_ArgumentCount   FINAL_SEPARATOR
#endif
#endif
{
#ifdef MEDIA413_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        long L1712_ArgumentIndex;
        long* L1713_pl_StandardPacketArguments;
        long L1714_l_DOSActionResult;


        L1714_l_DOSActionResult = 0;
        if (G1082_ps_MsgPort == NULL) {
                if ((G1082_ps_MsgPort = CreatePort(NULL, 0L)) == NULL) {
                        return 0;
                }
        }
        if (G1083_ps_StandardPacket == NULL) {
                G1083_ps_StandardPacket = AllocMem((long)sizeof(struct StandardPacket), MEMF_PUBLIC | MEMF_CLEAR);
        }
        if (G1083_ps_StandardPacket != NULL) {
                G1083_ps_StandardPacket->sp_Msg.mn_Node.ln_Name = (char*)&G1083_ps_StandardPacket->sp_Pkt;
                G1083_ps_StandardPacket->sp_Pkt.dp_Link = &G1083_ps_StandardPacket->sp_Msg;
                G1083_ps_StandardPacket->sp_Pkt.dp_Port = G1082_ps_MsgPort;
                G1083_ps_StandardPacket->sp_Pkt.dp_Type = P0950_l_DosPacketType;
                L1713_pl_StandardPacketArguments = &G1083_ps_StandardPacket->sp_Pkt.dp_Arg1;
                for (L1712_ArgumentIndex = 0; (L1712_ArgumentIndex < P0952_ArgumentCount) && (L1712_ArgumentIndex < 7); L1712_ArgumentIndex++) {
                        L1713_pl_StandardPacketArguments[L1712_ArgumentIndex] = P0951_pl_Arguments[L1712_ArgumentIndex];
                }
                PutMsg(P0949_ps_MsgPort, G1083_ps_StandardPacket);
                WaitPort(G1082_ps_MsgPort);
                GetMsg(G1082_ps_MsgPort);
                L1714_l_DOSActionResult = G1083_ps_StandardPacket->sp_Pkt.dp_Res1;
        }
        return L1714_l_DOSActionResult;
#endif
#ifdef MEDIA752_A36M_A31E_A31M_A33M_A35E_A35M_AU1E_AU2E
#if ((EXETYPE == C03_GAME) || (EXETYPE == C06_CEDT) || (EXETYPE == C12_FIO1))
        register long* L1713_pl_StandardPacketArguments;
        register int16_t L1712_ArgumentIndex;
#endif
#if ((EXETYPE == C07_HINT) || (EXETYPE == C09_CNFG))
        long L1712_ArgumentIndex;
        long* L1713_pl_StandardPacketArguments;
        long L1714_l_DOSActionResult;
#endif


#if ((EXETYPE == C07_HINT) || (EXETYPE == C09_CNFG))
        L1714_l_DOSActionResult = 0;
#endif
        G1083_ps_StandardPacket->sp_Msg.mn_Node.ln_Name = (char*)&G1083_ps_StandardPacket->sp_Pkt;
        G1083_ps_StandardPacket->sp_Pkt.dp_Link = &G1083_ps_StandardPacket->sp_Msg;
        G1083_ps_StandardPacket->sp_Pkt.dp_Port = G1082_ps_MsgPort;
        G1083_ps_StandardPacket->sp_Pkt.dp_Type = P0950_l_DosPacketType;
        L1713_pl_StandardPacketArguments = &G1083_ps_StandardPacket->sp_Pkt.dp_Arg1;
        for (L1712_ArgumentIndex = 0; (L1712_ArgumentIndex < P0952_ArgumentCount) && (L1712_ArgumentIndex < 7); L1712_ArgumentIndex++) {
                L1713_pl_StandardPacketArguments[L1712_ArgumentIndex] = P0951_pl_Arguments[L1712_ArgumentIndex];
        }
        PutMsg(P0949_ps_MsgPort, G1083_ps_StandardPacket);
        WaitPort(G1082_ps_MsgPort);
        GetMsg(G1082_ps_MsgPort);
#if ((EXETYPE == C03_GAME) || (EXETYPE == C06_CEDT) || (EXETYPE == C12_FIO1))
        return G1083_ps_StandardPacket->sp_Pkt.dp_Res1;
#endif
#if ((EXETYPE == C07_HINT) || (EXETYPE == C09_CNFG))
        L1714_l_DOSActionResult = G1083_ps_StandardPacket->sp_Pkt.dp_Res1;
        return L1714_l_DOSActionResult;
#endif
#endif
}

BOOLEAN F0523_FLOPPY_InhibitFileSystem(
#ifdef MEDIA413_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0953_pc_DriveDeviceName, P0954_i_Argument1)
#endif
char*   P0953_pc_DriveDeviceName SEPARATOR
int16_t P0954_i_Argument1        FINAL_SEPARATOR
{
#ifdef MEDIA413_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        struct Process* L1715_ps_Process;
        long L1716_l_Unreferenced;
        long L1717_l_Arguments;
        long L1718_l_Unreferenced;


        if ((L1715_ps_Process = DeviceProc(P0953_pc_DriveDeviceName)) == NULL) {
                return C1_TRUE;
        }
        L1717_l_Arguments = P0954_i_Argument1;
        return (F0522_FLOPPY_SendDosPacket(L1715_ps_Process, ACTION_INHIBIT, &L1717_l_Arguments, 1) == NULL);
#endif
#ifdef MEDIA752_A36M_A31E_A31M_A33M_A35E_A35M_AU1E_AU2E
#if ((EXETYPE == C03_GAME) || (EXETYPE == C06_CEDT) || (EXETYPE == C12_FIO1))
        register struct Process* L1715_ps_Process;
#endif
#if ((EXETYPE == C07_HINT) || (EXETYPE == C09_CNFG))
        struct Process* L1715_ps_Process;
#endif
        long L1716_l_Unreferenced;
        long L1717_l_Arguments;
#if ((EXETYPE == C07_HINT) || (EXETYPE == C09_CNFG))
        long L1718_l_Unreferenced;
#endif


        if ((L1715_ps_Process = DeviceProc(P0953_pc_DriveDeviceName)) == NULL) {
                return C1_TRUE;
        }
        L1717_l_Arguments = P0954_i_Argument1;
#if ((EXETYPE == C03_GAME) || (EXETYPE == C06_CEDT) || (EXETYPE == C12_FIO1))
        return (F0522_FLOPPY_SendDosPacket(L1715_ps_Process, ACTION_INHIBIT, &L1717_l_Arguments, 1) == NULL);
#endif
#if ((EXETYPE == C07_HINT) || (EXETYPE == C09_CNFG))
        return (F0522_FLOPPY_SendDosPacket(L1715_ps_Process, ACTION_INHIBIT, &L1717_l_Arguments, 1L) == NULL);
#endif
#endif
}

#ifdef MEDIA413_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
BOOLEAN F0524_FLOPPY_OpenTrackdiskDevice(
P0955_i_DriveIndex)
int16_t P0955_i_DriveIndex FINAL_SEPARATOR
{
        if (OpenDevice("trackdisk.device", (long)P0955_i_DriveIndex, G0734_ps_AmigaData->IOExtTD, 0L)) {
                return C0_FALSE;
        }
        return C1_TRUE;
}

int16_t F0525_FLOPPY_GetWriteProtectionState(
P0956_i_DriveIndex)
int16_t P0956_i_DriveIndex FINAL_SEPARATOR
{
#ifdef MEDIA433_A20E_A20F_A20G_A21E_A22E_A22G /* Linked to copy protection ? */
        REGISTER long L1719_l_DiskChangeHandlerData;
#endif
        int16_t L1720_i_DiskState;

        L1720_i_DiskState = 0;
#ifdef MEDIA433_A20E_A20F_A20G_A21E_A22E_A22G /* Linked to copy protection ? */
        L1719_l_DiskChangeHandlerData = (P0956_i_DriveIndex == 0) ? G1084_l_GameDiskChangeVerticalBlankCount : G1085_l_SaveDiskChangeVerticalBlankCount;
        if (G1086_VerticalBlankCount > 240) {
                if (G1086_VerticalBlankCount - L1719_l_DiskChangeHandlerData < 240) {
                        return 0; /* No disk in drive */
                }
        }
#endif
        if (!F0524_FLOPPY_OpenTrackdiskDevice(P0956_i_DriveIndex)) {
                return 0;
        }
        F0526_FLOPPY_DoTrackdiskDeviceIO(TD_CHANGESTATE, 0L, 0);
        if (G0734_ps_AmigaData->IOExtTD->iotd_Req.io_Actual) {
                L1720_i_DiskState = 0; /* No disk in drive */
        } else {
                F0526_FLOPPY_DoTrackdiskDeviceIO(TD_PROTSTATUS, 0L, 0);
                if (G0734_ps_AmigaData->IOExtTD->iotd_Req.io_Actual) {
                        L1720_i_DiskState = 1; /* Disk is write protected */
                } else {
                        L1720_i_DiskState = 2; /* Disk is not write protected */
                }
        }
        CloseDevice(G0734_ps_AmigaData->IOExtTD);
        return L1720_i_DiskState;
}

int16_t F0526_FLOPPY_DoTrackdiskDeviceIO(
P0957_ul_Command, P0958_ul_Length, P0959_uc_Flags)
long  P0957_ul_Command SEPARATOR
ULONG P0958_ul_Length  SEPARATOR
UBYTE P0959_uc_Flags   FINAL_SEPARATOR
{
        G0734_ps_AmigaData->IOExtTD->iotd_Req.io_Command = (UWORD)P0957_ul_Command;
        G0734_ps_AmigaData->IOExtTD->iotd_Req.io_Flags = P0959_uc_Flags;
        G0734_ps_AmigaData->IOExtTD->iotd_Req.io_Length = P0958_ul_Length;
        return DoIO(G0734_ps_AmigaData->IOExtTD);
}
#endif

#ifdef MEDIA752_A36M_A31E_A31M_A33M_A35E_A35M_AU1E_AU2E
#if ((EXETYPE == C03_GAME) || (EXETYPE == C06_CEDT) || (EXETYPE == C12_FIO1))
int16_t F1118_(P2806_pc_DeviceName, P2807_)
char* P2806_pc_DeviceName;
register char* P2807_;
{
        register int16_t L2604_i_;
        struct Process* L2605_ps_Process;
        long L2606_al_[2]; /* BUGX_XX: L2606_al_[1] not initialized. A structure for the dos packet? */
        char L2607_ac_[35];
        char* L2608_pc_;
        register char* L2609_pc_;


        if ((L2605_ps_Process = DeviceProc(P2806_pc_DeviceName)) == NULL) {
                return 1;
        }
        L2609_pc_ = L2608_pc_ = (char*)((unsigned long)(&L2607_ac_[3]) & 0xFFFFFFFC);
        *L2609_pc_++ = L2604_i_ = M544_STRLEN(P2807_);
        while (L2604_i_--) {
                *L2609_pc_++ = *P2807_++;
        }
        L2606_al_[0] = (unsigned long)L2608_pc_ >> 2;
        return (F0522_FLOPPY_SendDosPacket(L2605_ps_Process, ACTION_RENAME_DISK, &L2606_al_, 1) == NULL);
}
#endif

long F0520_FLOPPY_GetSectorChecksum(
register long* P0946_pc_ FINAL_SEPARATOR
{
        register int16_t L2610_i_;
        register long L2611_l_;


        L2611_l_ = 0;
        for (L2610_i_ = 0; L2610_i_ < 128; L2610_i_++) {
                L2611_l_ += *P0946_pc_++;
        }
        return L2611_l_;
}

#if ((EXETYPE == C03_GAME) || (EXETYPE == C06_CEDT) || (EXETYPE == C12_FIO1) || (EXETYPE == C07_HINT))
int16_t F0519_FLOPPY_GetFormatResult(P0944_i_DriveIndex, P0945_pc_DiskName)
int16_t P0944_i_DriveIndex;
char* P0945_pc_DiskName;
{
        register int16_t L2612_i_Unreferenced;
        register ULONG L1700_ul_DiskChangeCount;
        register int16_t L1701_i_Result = 0;
        register int16_t L1702_i_Counter;
        int16_t L2613_i_;
        register int16_t L1704_i_TrackIndex;
        char* L1705_pc_DiskName;
        register APTR L1706_ppuc_TrackContent;
        register long* L1707_pl_TrackContent;
#if ((defined(MEDIA744_A36M) && (EXETYPE == C03_GAME)) || (EXETYPE == C12_FIO1))
        int16_t L2614_i_Unreferenced;
#endif
#if (EXETYPE == C12_FIO1)
        register long* L5149_;
#endif


        L2613_i_ = 0;
        G1081_ac_DriveDeviceName[2] = P0944_i_DriveIndex + '0';
        if (F0524_FLOPPY_OpenTrackdiskDevice(P0944_i_DriveIndex) && ((L1701_i_Result = F0523_FLOPPY_InhibitFileSystem(G1081_ac_DriveDeviceName, 1)) == 0)) {
                F0526_FLOPPY_DoTrackdiskDeviceIO(TD_CHANGENUM, 0L, 0);
                L1700_ul_DiskChangeCount = G3181_ps_IOExtTD->iotd_Req.io_Actual;
                L1706_ppuc_TrackContent = G3183_TrackBuffer;
                for (L1704_i_TrackIndex = 0; L1704_i_TrackIndex < NUMTRACKS; L1704_i_TrackIndex++) {
                        T0519003:
                        L1707_pl_TrackContent = (long*)L1706_ppuc_TrackContent;
#if ((defined(MEDIA626_A31E_A31M_A33M_A35E_A35M) && (EXETYPE == C03_GAME)) || (EXETYPE == C06_CEDT) || (EXETYPE == C12_FIO1) || (EXETYPE == C07_HINT))
                        for (L1702_i_Counter = 0; L1702_i_Counter < TD_SECTOR * NUMSECS / 4; L1702_i_Counter++) {
#endif
#if (defined(MEDIA744_A36M) && (EXETYPE == C03_GAME))
                        for (L1702_i_Counter = 0; L1702_i_Counter < (unsigned int16_t)(TD_SECTOR * NUMSECS / 4); L1702_i_Counter++) {
#endif
                                *L1707_pl_TrackContent++ = (L1702_i_Counter & 0xFF) | 0x444F5300; /* 'DOS\0' */
                        }
#if (EXETYPE == C03_GAME)
                        F1110_DrawFormatProgressBar(320, L1704_i_TrackIndex * 2);
#endif
                        G3181_ps_IOExtTD->iotd_Req.io_Command = ETD_FORMAT;
                        G3181_ps_IOExtTD->iotd_Req.io_Length = TD_SECTOR * NUMSECS;
                        G3181_ps_IOExtTD->iotd_Req.io_Data = L1706_ppuc_TrackContent;
                        G3181_ps_IOExtTD->iotd_Req.io_Offset = L1704_i_TrackIndex * NUMSECS * TD_SECTOR;
                        G3181_ps_IOExtTD->iotd_Req.io_Flags = 0;
                        G3181_ps_IOExtTD->iotd_Req.io_Actual = 0;
                        G3181_ps_IOExtTD->iotd_Count = L1700_ul_DiskChangeCount;
                        G3181_ps_IOExtTD->iotd_SecLabel = 0;
                        DoIO(G3181_ps_IOExtTD);
                        if (L1701_i_Result = G3181_ps_IOExtTD->iotd_Req.io_Error) {
                                T0519002:
                                if ((L1701_i_Result == TDERR_DiskChanged) || (L1701_i_Result == TDERR_WriteProt) || (++L2613_i_ > 3)) {
                                        goto T0519000;
                                }
                                L1701_i_Result = 0;
                                goto T0519003;
                        }
#if (EXETYPE == C03_GAME)
                        F1110_DrawFormatProgressBar(320, (L1704_i_TrackIndex * 2) + 1);
#endif
                        G3181_ps_IOExtTD->iotd_Req.io_Command = ETD_READ;
                        G3181_ps_IOExtTD->iotd_Req.io_Length = TD_SECTOR * NUMSECS;
                        G3181_ps_IOExtTD->iotd_Req.io_Data = L1706_ppuc_TrackContent;
                        G3181_ps_IOExtTD->iotd_Req.io_Offset = L1704_i_TrackIndex * NUMSECS * TD_SECTOR;
                        G3181_ps_IOExtTD->iotd_Req.io_Flags = 0;
                        G3181_ps_IOExtTD->iotd_Req.io_Actual = 0;
                        G3181_ps_IOExtTD->iotd_Count = L1700_ul_DiskChangeCount;
                        G3181_ps_IOExtTD->iotd_SecLabel = 0;
                        DoIO(G3181_ps_IOExtTD);
                        if (L1701_i_Result = G3181_ps_IOExtTD->iotd_Req.io_Error) {
                                goto T0519002;
                        }
                        L1707_pl_TrackContent = (long*)L1706_ppuc_TrackContent;
#if ((defined(MEDIA626_A31E_A31M_A33M_A35E_A35M) && (EXETYPE == C03_GAME)) || (EXETYPE == C06_CEDT) || (EXETYPE == C12_FIO1) || (EXETYPE == C07_HINT))
                        for (L1702_i_Counter = 0; L1702_i_Counter < TD_SECTOR * NUMSECS / 4; L1702_i_Counter++) {
#endif
#if (defined(MEDIA744_A36M) && (EXETYPE == C03_GAME))
                        for (L1702_i_Counter = 0; L1702_i_Counter < (unsigned int16_t)(TD_SECTOR * NUMSECS / 4); L1702_i_Counter++) {
#endif
                                if (*L1707_pl_TrackContent++ != ((L1702_i_Counter & 0xFF) | 0x444F5300)) { /* 'DOS\0' */
                                        L1701_i_Result = -1;
                                        goto T0519002;
                                }
                        }
                        L2613_i_ = 0;
                }
                /* Prepare root sector */
#if (EXETYPE == C12_FIO1)
                L5149_ = L1706_ppuc_TrackContent;
                L2614_i_Unreferenced = 128;
                while (L2614_i_Unreferenced-- != 0) {
                        *L5149_++ = 0;
                }
#else
                F0008_MAIN_ClearBytes(L1706_ppuc_TrackContent, TD_SECTOR);
#endif
                L1707_pl_TrackContent = (long*)L1706_ppuc_TrackContent;
                L1707_pl_TrackContent[0] = 2; /* Block primary type = T_HEADER (value 2) */
                L1707_pl_TrackContent[3] = 0x48; /* Hash table size in long, value 0x48 for floppy disk */
                L1707_pl_TrackContent[78] = 0xFFFFFFFF; /* Bitmap flag, -1 means VALID */
                L1707_pl_TrackContent[79] = 881; /* Bitmap blocks pointers (first one at bm_pages[0]) */
                DateStamp((struct DateStamp*)&L1707_pl_TrackContent[121]); /* Filesystem creation date */
                DateStamp((struct DateStamp*)&L1707_pl_TrackContent[105]); /* Last root alteration date */
                L1705_pc_DiskName = (char*)&L1707_pl_TrackContent[108];
                *L1705_pc_DiskName = M544_STRLEN(P0945_pc_DiskName); /* Length of disk name */
                for (L1702_i_Counter = 0; L1702_i_Counter < *L1705_pc_DiskName; L1702_i_Counter++) {
                        (L1705_pc_DiskName + 1)[L1702_i_Counter] = P0945_pc_DiskName[L1702_i_Counter]; /* Disk name */
                }
                L1707_pl_TrackContent[127] = 1; /* Block secondary type = ST_ROOT (value 1) */
                L1707_pl_TrackContent[5] = 0 - F0520_FLOPPY_GetSectorChecksum(L1707_pl_TrackContent); /* Root block checksum */
                G3181_ps_IOExtTD->iotd_Req.io_Command = ETD_WRITE;
                G3181_ps_IOExtTD->iotd_Req.io_Length = TD_SECTOR;
                G3181_ps_IOExtTD->iotd_Req.io_Data = L1706_ppuc_TrackContent;
                G3181_ps_IOExtTD->iotd_Req.io_Offset = NUMCYLS * NUMSECS * TD_SECTOR; /* First sector on second side */
                G3181_ps_IOExtTD->iotd_Req.io_Flags = 0;
                G3181_ps_IOExtTD->iotd_Req.io_Actual = 0;
                G3181_ps_IOExtTD->iotd_Count = L1700_ul_DiskChangeCount;
                G3181_ps_IOExtTD->iotd_SecLabel = 0;
                DoIO(G3181_ps_IOExtTD);
                if (L1701_i_Result = G3181_ps_IOExtTD->iotd_Req.io_Error) {
                        goto T0519000;
                }
                for (L1702_i_Counter = 1; L1702_i_Counter < 55; L1702_i_Counter++) {
                        L1707_pl_TrackContent[L1702_i_Counter] = 0xFFFFFFFF; /* 54 * 32 = 1760 bits = 2 x 880, one bit for each block on the floppy disk */
                }
                L1707_pl_TrackContent[28] = 0xFFFF3FFF; /* Block x is used */
                L1707_pl_TrackContent[55] = 0x3FFFFFFF; /* Block x is used */
                L1707_pl_TrackContent[0] = 0; /* First 32 blocks are used */
                for (L1702_i_Counter = 56; L1702_i_Counter < 128; L1702_i_Counter++) {
                        L1707_pl_TrackContent[L1702_i_Counter] = 0; /* Clear the rest of the sector */
                }
                L1707_pl_TrackContent[0] = 0 - F0520_FLOPPY_GetSectorChecksum(L1707_pl_TrackContent); /* Bitmap block checksum */
                G3181_ps_IOExtTD->iotd_Req.io_Command = ETD_WRITE;
                G3181_ps_IOExtTD->iotd_Req.io_Length = TD_SECTOR;
                G3181_ps_IOExtTD->iotd_Req.io_Data = L1706_ppuc_TrackContent;
                G3181_ps_IOExtTD->iotd_Req.io_Offset = NUMCYLS * NUMSECS * TD_SECTOR + TD_SECTOR; /* Second sector on second side */
                G3181_ps_IOExtTD->iotd_Req.io_Flags = 0;
                G3181_ps_IOExtTD->iotd_Req.io_Actual = 0;
                G3181_ps_IOExtTD->iotd_Count = L1700_ul_DiskChangeCount;
                G3181_ps_IOExtTD->iotd_SecLabel = 0;
                DoIO(G3181_ps_IOExtTD);
                if (L1701_i_Result = G3181_ps_IOExtTD->iotd_Req.io_Error) {
                        goto T0519000;
                }
                T0519000:
                G3181_ps_IOExtTD->iotd_Count = L1700_ul_DiskChangeCount;
                G3181_ps_IOExtTD->iotd_SecLabel = 0;
                F0526_FLOPPY_DoTrackdiskDeviceIO(ETD_UPDATE, 0L, 0); /* Flush buffered track to disk */
                F0526_FLOPPY_DoTrackdiskDeviceIO(TD_MOTOR, 0L, 0); /* Turn off motor */
                F0523_FLOPPY_InhibitFileSystem(G1081_ac_DriveDeviceName, 0);
                Delay(150L);
        }
        T0519001:
        F1114_CloseTrackdiskDevice();
        return L1701_i_Result;
}
#endif

BOOLEAN F1106_IsTrackdiskDeviceOpened(P2797_i_DriveIndex)
int16_t P2797_i_DriveIndex;
{
        register int16_t L2615_i_TrackdiskDeviceOpened;


        if (L2615_i_TrackdiskDeviceOpened = F0524_FLOPPY_OpenTrackdiskDevice(P2797_i_DriveIndex)) {
                F1114_CloseTrackdiskDevice();
        }
        return L2615_i_TrackdiskDeviceOpened;
}

long F1107_GetDiskChangeCounter(P2798_i_DriveIndex)
int16_t P2798_i_DriveIndex;
{
        register long L2616_l_DiskChangeCounter;


        if (F0524_FLOPPY_OpenTrackdiskDevice(P2798_i_DriveIndex) == C0_FALSE) {
                return -1;
        }
        F0526_FLOPPY_DoTrackdiskDeviceIO(TD_CHANGENUM, 0L, 0);
        L2616_l_DiskChangeCounter = G3181_ps_IOExtTD->iotd_Req.io_Actual;
        F1114_CloseTrackdiskDevice();
        return L2616_l_DiskChangeCounter;
}

#if (EXETYPE == C12_FIO1)
long F1362_IsFloppyDriveEmpty(
int16_t P4489_i_DriveIndex)
{
        register long L4829_l_NoDiskInDrive;


        if (F0524_FLOPPY_OpenTrackdiskDevice(P4489_i_DriveIndex) == 0) {
                return -1;
        }
        F0526_FLOPPY_DoTrackdiskDeviceIO(TD_CHANGESTATE, 0L, 0);
        L4829_l_NoDiskInDrive = G3181_ps_IOExtTD->iotd_Req.io_Actual; /* Value 0 means there is a disk in the drive else there is no disk */
        F1114_CloseTrackdiskDevice();
        return L4829_l_NoDiskInDrive;
}

long F1363_IsFloppyDiskWriteProtected(
int16_t P4490_i_DriveIndex)
{
        register long L4830_l_DiskIsWriteProtected;


        if (F0524_FLOPPY_OpenTrackdiskDevice(P4490_i_DriveIndex) == 0) {
                return -1;
        }
        F0526_FLOPPY_DoTrackdiskDeviceIO(TD_PROTSTATUS, 0L, 0);
        L4830_l_DiskIsWriteProtected = G3181_ps_IOExtTD->iotd_Req.io_Actual; /* Value 0 if floppy disk is not write-protected else another value */
        F1114_CloseTrackdiskDevice();
        return L4830_l_DiskIsWriteProtected;
}
#endif

long F1108_GetDiskChangeCounter(
int16_t P2795_i_DriveIndex)
{
        register long L2617_l_DiskChangeCounter;


        if (OpenDevice("trackdisk.device", (long)P2795_i_DriveIndex, G3176_ps_IOExtTD, 0L)) {
                return -1;
        }
        G3176_ps_IOExtTD->iotd_Req.io_Command = TD_CHANGENUM;
        G3176_ps_IOExtTD->iotd_Req.io_Flags = 0;
        G3176_ps_IOExtTD->iotd_Req.io_Length = 0;
        DoIO(G3176_ps_IOExtTD);
        L2617_l_DiskChangeCounter = G3176_ps_IOExtTD->iotd_Req.io_Actual;
        CloseDevice(G3176_ps_IOExtTD);
        return L2617_l_DiskChangeCounter;
}

int16_t F1109_GetDiskState(
int16_t P2796_i_FloppyDriveIndex)
{
        register int16_t L1720_i_DiskState;


        L1720_i_DiskState = 0; /* No disk in drive */
        if (F0524_FLOPPY_OpenTrackdiskDevice(P2796_i_FloppyDriveIndex)) {
                F0526_FLOPPY_DoTrackdiskDeviceIO(TD_CHANGESTATE, 0L, 0);
                if (!G3181_ps_IOExtTD->iotd_Req.io_Actual) {
                        L1720_i_DiskState = 1; /* Disk is write protected */
                        F0526_FLOPPY_DoTrackdiskDeviceIO(TD_PROTSTATUS, 0L, 0);
                        if (!G3181_ps_IOExtTD->iotd_Req.io_Actual) {
                                L1720_i_DiskState = 2; /* Disk is not write protected */
                        }
                }
                F1114_CloseTrackdiskDevice();
        }
        return L1720_i_DiskState;
}

#if (EXETYPE == C09_CNFG)
long F1271_(P4372_, P4373_, P4374_)
ULONG P4372_;
APTR P4373_;
ULONG P4374_;
{
        G3181_ps_IOExtTD->iotd_Req.io_Command = CMD_READ;
        G3181_ps_IOExtTD->iotd_Req.io_Length = P4374_;
        G3181_ps_IOExtTD->iotd_Req.io_Data = P4373_;
        G3181_ps_IOExtTD->iotd_Req.io_Offset = P4372_;
        G3181_ps_IOExtTD->iotd_Req.io_Flags = 0;
        G3181_ps_IOExtTD->iotd_Req.io_Actual = 0;
        G3181_ps_IOExtTD->iotd_Count = 0;
        G3181_ps_IOExtTD->iotd_SecLabel = 0;
        DoIO(G3181_ps_IOExtTD);
        return G3181_ps_IOExtTD->iotd_Req.io_Error;
}
#endif

#if (EXETYPE == C03_GAME)
void F1110_DrawFormatProgressBar(P2810_i_MaximumValue, P2811_i_CurrentValue)
int16_t P2810_i_MaximumValue;
unsigned int16_t P2811_i_CurrentValue;
{
        register int16_t L2618_i_;
        int16_t L2619_ai_XYZ[4];


        if ((L2618_i_ = (P2811_i_CurrentValue * 192) / P2810_i_MaximumValue) == 0) { /* Progress bar maximum width is 1912 pixels */
                return;
        }
        M704_ZONE_LEFT(L2619_ai_XYZ) = 16;
        M706_ZONE_TOP(L2619_ai_XYZ) = 108;
        M708_ZONE_WIDTH(L2619_ai_XYZ) = L2618_i_;
        M709_ZONE_HEIGHT(L2619_ai_XYZ) = 6;
        F0732_FillScreenArea(L2619_ai_XYZ, C10_COLOR_FLESH); /* Progress bar */
        M704_ZONE_LEFT(L2619_ai_XYZ) = 18;
        M706_ZONE_TOP(L2619_ai_XYZ) = 114;
        M708_ZONE_WIDTH(L2619_ai_XYZ) = L2618_i_;
        M709_ZONE_HEIGHT(L2619_ai_XYZ) = 2;
        F0732_FillScreenArea(L2619_ai_XYZ, C03_COLOR_DARK_BROWN); /* Shadow (below) */
        M704_ZONE_LEFT(L2619_ai_XYZ) = L2618_i_ + 16;
        M706_ZONE_TOP(L2619_ai_XYZ) = 110;
        M708_ZONE_WIDTH(L2619_ai_XYZ) = 2;
        M709_ZONE_HEIGHT(L2619_ai_XYZ) = 6;
        F0732_FillScreenArea(L2619_ai_XYZ, C03_COLOR_DARK_BROWN); /* Shadow (right) */
}
#endif
#endif

#ifdef MEDIA423_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_A31E_A31M_A33M_A35E_A35M
#if (EXETYPE == C03_GAME)
#ifndef NOCOPYPROTECTION
long F0527_FLOPPY_ReadFuzzySector_CPSX(
#ifdef MEDIA413_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0960_pui_SectorBuffer)
unsigned int16_t* P0960_pui_SectorBuffer;
#endif
#ifdef MEDIA626_A31E_A31M_A33M_A35E_A35M
register unsigned int16_t* P0960_pui_SectorBuffer)
#endif
{
        register long L1721_l_;


#ifdef MEDIA413_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
                T0527000:
                #asm
                                movea.l _G1053_ps_DiscResourceUnit_CPSX,a1
                                move.l  a6,-(sp)
                                movea.l _G1054_ps_DiskResource_CPSX,a6
                                jsr     -$12(a6)                        ; disk.resource/GetUnit (see DR_GETUNIT in disk.h)
                                movea.l (sp)+,a6
                        public _G1053_ps_DiscResourceUnit_CPSX
                        public _G1054_ps_DiskResource_CPSX
                #endasm
                ciaa.ciaicr = CIAICRF_TA; /* CIAA interrupt control register */
                #asm
                        move.b ($BFEE01).l,d0   ; CIAA_CRA
                        and.b  #$C0,d0          ; Preserve CIACRAF_TODIN () and CIACRAF_SPMODE (Serial port mode).
                                                ; Clear CIACRAF_START (stop timer A), CIACRAF_PBON (PB6 is normal operation)
                                                ; CIACRAF_OUTMODE (pulse), CIACRAF_RUNMODE (continuous mode)
                                                ; CIACRAF_LOAD (no effect), CIACRAF_INMODE (Timer A counts 02 pulses)
                        or.b   #8,d0            ; CIACRAF_RUNMODE (one-shot mode)
                        move.b d0,($BFEE01).l   ; CIAA_CRA
                #endasm
                ciaa.ciatalo = 100;
                ciaa.ciatahi = 8;
#endif
#ifdef MEDIA626_A31E_A31M_A33M_A35E_A35M
        do {
                asm {
                                movem.l d3-d7/a2-a6,-(sp)
                        @Tloc_5460:
                                bset    #0,G3171_c_ReadingCopyProtectionSector_CPSX(a5)
                                bne.s   @Tloc_5460
                }
                asm {
                        @Tloc_5468:
                                movea.l G1053_ps_DiscResourceUnit_CPSX(a5),a1
                                movea.l G1054_ps_DiskResource_CPSX(a5),a6
                                jsr     -0x12(a6)                        /* disk.resource/GetUnit (see DR_GETUNIT in disk.h) */
                                tst.l   d0
                                bne.s   @Tloc_5492
                                movea.l ExecBase(a5),a6
                                movea.l G1053_ps_DiscResourceUnit_CPSX(a5),a4
                                movea.l 0xE(a4),a0
                                jsr     -0x180(a6)
                                movea.l 0xE(a4),a0
                                jsr     -0x174(a6)
                                bra.s   @Tloc_5468
                        @Tloc_5492:
                                movem.l (sp)+,d3-d7/a2-a6
                }
#endif
                ciab.ciaprb = CIAF_DSKSEL3 | CIAF_DSKSEL2 | CIAF_DSKSEL1 | CIAF_DSKSEL0 | CIAF_DSKDIREC | CIAF_DSKSTEP; /* 0x7B. MOTOR ON, do not select any drive, select head 0 */
                ciab.ciaprb = CIAF_DSKSEL3 | CIAF_DSKSEL2 | CIAF_DSKSEL1 | CIAF_DSKDIREC | CIAF_DSKSTEP; /* 0x73. Select drive 0 (internal drive) */
                /* The two previous instructions instruct the system to switch on the motor of drive 0 */
                while (ciaa.ciapra & CIAF_DSKRDY); /* 0x20 Wait until the drive is ready (CIAF_DSKRDY is 0 when drive is rotating at speed if the motor is on) */
#ifdef MEDIA626_A31E_A31M_A33M_A35E_A35M
                G3210_WaitForCopperInterrupt_CPSX = C1_TRUE;
                while (G3210_WaitForCopperInterrupt_CPSX);
#endif
                while (ciaa.ciapra & CIAF_DSKTRACK0) { /* 0x10 CIAF_DSKTRACK0 is 0 when the drive head is on track 0 */
                        ciab.ciaprb = CIAF_DSKSEL3 | CIAF_DSKSEL2 | CIAF_DSKSEL1 | CIAF_DSKDIREC; /* 0x72 CIAF_DSKDIREC is 1 to step out toward track 0 */
#ifdef MEDIA413_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
                        #asm
                                nop
                                nop
                        #endasm
#endif
#ifdef MEDIA626_A31E_A31M_A33M_A35E_A35M
                        asm {
                                nop
                                nop
                        }
#endif
                        ciab.ciaprb = CIAF_DSKSEL3 | CIAF_DSKSEL2 | CIAF_DSKSEL1 | CIAF_DSKDIREC | CIAF_DSKSTEP; /* 0x73. Select drive 0 (internal drive) */
                        /* Each iteration of the loop causes a pulse on CIAF_DSKSTEP causing the drive to step one track toward track 0 (copy protected sector is on track 0, side 1) */
#ifdef MEDIA413_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
                        ciaa.ciacra |= CIACRAF_START; /* Start Timer A */
                        do {} while (!(ciaa.ciaicr & CIAICRF_TA)); /* CIAA interrupt control register. Cause a delay to let enough time for the drive to step */
#endif
#ifdef MEDIA626_A31E_A31M_A33M_A35E_A35M
                        G3210_WaitForCopperInterrupt_CPSX = C1_TRUE;
                        while (G3210_WaitForCopperInterrupt_CPSX);
#endif
                        while (ciaa.ciapra & CIAF_DSKRDY); /* 0x20 */
                }
                custom.intreq = INTF_DSKBLK; /* 0x0002.  0x8000: Clear specified bits without changing other bits. 0x0002: Clear 'Disk block finished' interrupt bit */
                custom.dmacon = 0x8010; /* 0x8000: set other specified bits without affecting other bits. 0x0010: Disk DMA enable */
                custom.dsklen = 0x4000; /* Force the DMA for the disk to be turned off */
                custom.adkcon = ADKF_SETCLR | ADKF_WORDSYNC; /* 0x8400. Enable sync with sync mark (set this bit without affecting other bits) */
                custom.dsksync = 0x5545;  /* MFM sync mark corresponding to data byte 0xFB. In Atari ST, the sync mark used is 0x4489 and the first byte after synchronization is 0xFB (data address mark) which is processed by the FDC and not returned. On Amiga 0xFB is used for the synchronization so that the first word returned is the actual first word of data in the sector */
                custom.dskpt = (APTR)P0960_pui_SectorBuffer;
                custom.intreq = 0x2000; /* 0x8000: Clear specified bits without changing other bits. 0x2000: Disable external interrupt request 6 (generated by CIAB) */
                custom.intena = 0xA000; /* 0x8000: Set specified bits without changing other bits. 0x2000: Enable external interrupt 6 (generated by CIAB) */
                ciab.ciaicr = CIAICRF_SETCLR | CIAICRF_FLG; /* 0x90. CIAB interrupt control register. Sets bit 4 CIAICRF_FLG and preserve other bits in the MASK register */
                L1721_l_ = 0xC3500; /* 800000 */
#ifdef MEDIA413_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
                T0527001:
                if (L1721_l_--) {
                        if (ciab.ciaicr & CIAICRF_FLG) { /* CIAB interrupt control register */
                                custom.dsklen = 0x8201;
                                custom.dsklen = 0x8201; /* 0x8000: Secondary disk DMA enable, 0x0201: Number of words to transfer = 513 = 1026 bytes. The value must be written twice to actually start the DMA */
                        } else {
                                goto T0527001; /* Replace by a loop ? */
                        }
                }
#endif
#ifdef MEDIA626_A31E_A31M_A33M_A35E_A35M
                while (L1721_l_--) {
                        if (!(ciab.ciaicr & CIAICRF_FLG)) { /* CIAB interrupt control register */
                                continue;
                        }
                        custom.dsklen = 0x846A;
                        custom.dsklen = 0x846A; /* 0x8000: Secondary disk DMA enable, 0x046A: Number of words to transfer = 1130 = 2260 bytes. The value must be written twice to actually start the DMA */
                        break;
                }
#endif
                if (L1721_l_ > 0) {
                        L1721_l_ = 0xC3500;
#ifdef MEDIA413_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
                        while (L1721_l_-- && !(custom.intreqr & INTF_DSKBLK)); /* Wait until 'Disk block finished' interrupt request bit is set, indicating the end of the read operation */
#endif
#ifdef MEDIA626_A31E_A31M_A33M_A35E_A35M
                        while (L1721_l_--) {
                                if (custom.intreqr & INTF_DSKBLK) { /* Wait until 'Disk block finished' interrupt request bit is set, indicating the end of the read operation */
                                        break;
                                }
                        }
#endif
                }
                custom.intreq = INTF_DSKBLK; /* 0x0002.  0x8000: Clear specified bits without changing other bits. 0x0002: Clear 'Disk block finished' interrupt bit */
                custom.dsklen = 0x4000; /* Force the DMA for the disk to be turned off */
                ciab.ciaprb = (unsigned int16_t)(CIAF_DSKMOTOR | CIAF_DSKSEL3 | CIAF_DSKSEL2 | CIAF_DSKSEL1 | CIAF_DSKSEL0 | CIAF_DSKSIDE | CIAF_DSKDIREC | CIAF_DSKSTEP); /* 0xFF */
                ciab.ciaprb = (unsigned int16_t)(CIAF_DSKMOTOR | CIAF_DSKSEL3 | CIAF_DSKSEL2 | CIAF_DSKSEL1 | CIAF_DSKSIDE | CIAF_DSKDIREC | CIAF_DSKSTEP); /* 0xF7 */
                /* The two previous instructions instruct the system to switch off the motor of drive 0 */
#ifdef MEDIA413_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
                #asm
                        move.l  a6,-(sp)
                        movea.l _G1054_ps_DiskResource_CPSX,a6
                        jsr     -$18(a6)                        ; disk.resource/GiveUnit (see DR_GIVEUNIT in disk.h)
                        movea.l (sp)+,a6
                #endasm
                if ((M007_GET(P0960_pui_SectorBuffer[510], MASK0x5555_MFM_DATA_BITS) != 0x1014) || /* 'F' */
                    (M007_GET(P0960_pui_SectorBuffer[511], MASK0x5555_MFM_DATA_BITS) != 0x1004)) { /* 'B' */
                        goto T0527000;
                }
#endif
#ifdef MEDIA626_A31E_A31M_A33M_A35E_A35M
                asm {
                        movem.l d3-d7/a2-a6,-(sp)
                        movea.l G1054_ps_DiskResource_CPSX(a5),a6
                        jsr     -0x18(a6)                        /* disk.resource/GiveUnit (see DR_GIVEUNIT in disk.h) */
                        clr.b   G3171_c_ReadingCopyProtectionSector_CPSX(a5)
                        movem.l (sp)+,d3-d7/a2-a6
                }
        } while ((M007_GET(P0960_pui_SectorBuffer[1125], MASK0x5555_MFM_DATA_BITS) != 0x1014) || /* 'F' */
                 (M007_GET(P0960_pui_SectorBuffer[1126], MASK0x5555_MFM_DATA_BITS) != 0x1004)); /* 'B' */
#endif
        return (L1721_l_ > 0);
}
#endif
#endif
#endif
#endif
