#ifndef COMPILE_H
#include "COMPILE.H"
#endif
#ifdef MEDIA774_SU1E_AU1E_AU2E
#ifdef MEDIA772_SU1E
extern char G3746_[];
extern char G3747_[];


extern void F1957_();
extern void F1919_Post_F1918_LoadGame_CPSX();
extern void F1916_Pre_F1918_LoadGame_CPSX();
extern void F1902_Post_F1901_CopyProtectionRoutine_CPSX();
extern void F1899_Pre_F1901_CopyProtectionRoutine_CPSX();
extern long F1857_PerformIORequestOperation();
extern unsigned int16_t F0090_strlen();
extern long F1886_Memory();
extern void F1889_Screen_CPSX();
extern void F1923_Pre_F1925_CPSX();
extern void F1926_Post_F1925_CPSX();
extern void F1893_ColorPalette();
extern int16_t F1901_CopyProtectionRoutine_CPSX();
extern void F1950_Pre_F1952_CheckCopyProtectionSector_CPSX();
extern void F1953_Post_F1952_CheckCopyProtectionSector_CPSX();
extern long F1931_();
extern void F1932_();
extern long F1941_();
extern long F1955_Input_CPSX();
extern void F1956_EndProgram();
extern long F1965_();
extern void F1966_DebugEnter();
extern void F1967_DebugExit();
extern void F1969_DebugInitialize();
extern long F1861_GetIORequestOutputValue();
extern long F1925_CPSX();
#endif


char* F1920_AllocateMemory(long P5756_) {
        char* L5625_;


#ifdef MEDIA772_SU1E
        L5625_ = (char*)F1886_Memory(17, C14_ALLOCATE, P5756_);
#endif
#ifdef MEDIA763_AU1E_AU2E
        L5625_ = (char*)F1886_Memory(-1, C14_ALLOCATE, P5756_);
#endif
        if (!L5625_) {
                F1956_EndProgram(17, 18, "get mem");
                for (;;);
        }
        return L5625_;
}

void F1921_FreeMemory(char* P5757_) {
        if (P5757_) {
#ifdef MEDIA772_SU1E
                F1886_Memory(17, C20_FREE, P5757_);
#endif
#ifdef MEDIA763_AU1E_AU2E
                F1886_Memory(-1, C20_FREE, P5757_);
#endif
        }
}

#ifdef MEDIA773_SU1E_AU1E
BOOLEAN F1922_ReadFromHTCFile(int16_t P5758_i_IORequestIndex, long P5759_ByteCount, unsigned char* P5760_puc_Buffer, char* P5899_pc_Message) {
#endif
#ifdef MEDIA767_AU2E
BOOLEAN F1922_ReadFromHTCFile(int16_t P5758_i_IORequestIndex, long P5759_ByteCount, unsigned char* P5760_puc_Buffer) {
#endif
        F1859_SetIORequestValue(P5758_i_IORequestIndex, 16, P5759_ByteCount);
        F1859_SetIORequestValue(P5758_i_IORequestIndex, 8, (long)P5760_puc_Buffer);
        return (F1857_PerformIORequestOperation(P5758_i_IORequestIndex, C07_READ_FILE) == 0);
}

#ifdef MEDIA772_SU1E
void F1923_Pre_F1925_CPSX(
)
{
#include "FAKE3.C"
}
#endif

long F1925_CPSX(int16_t P5764_i_, int16_t P5765_, ...) {
        long L5730_;
        char* L5628_;
        char* L5629_;
        int16_t L5630_i_;
        int16_t L5631_;
        int16_t L5632_i_IORequestIndex;
        long L5633_;
        long L5634_;
        unsigned int16_t L5635_;
        unsigned int16_t L5636_i_ByteCount;
        STRUCTHINT* L5637_;
        STRUCTHINT* L5638_;
        long L5749_l_Unreferenced;
        STRUCTHINT* L5639_;


#ifdef MEDIA773_SU1E_AU1E
        F1966_DebugEnter(17, P5765_);
#endif
#ifdef MEDIA772_SU1E
#ifndef NOCOPYPROTECTION
        L5630_i_ = F1908_Checksum_CPSX(*((char**)((char*)F1950_Pre_F1952_CheckCopyProtectionSector_CPSX + 2)), *((char**)((char*)F1953_Post_F1952_CheckCopyProtectionSector_CPSX + 2)));
        asm {
                @Tloc_6CA2:
                        move.w  P5765_(a6),d0
                        move.w  #0xDDAB,d1
                        bra.s   @Tloc_6CB2
                        asl.w   #1,d0
                        add.w   d0,d1
                        bra.s   @Tloc_6CB4
                @Tloc_6CB2:
                        moveq   #0,d0
                @Tloc_6CB4:
                        cmp.w   d0,d1
                        bcc.s   @Tloc_6CC0
                        move.w  -2(a6),d1
                        add.w   d0,d1
                        asl.w   #1,d1
                @Tloc_6CC0:
                        lea     @Tloc_6CA2,a0
                        move.w  L5630_i_(a6),d0
                        cmp.w   6(a0),d0
                        beq.s   @Tloc_6CD6
                        move.w  #1,L5630_i_(a6)
                        bra.s   @Tloc_6CDC
                @Tloc_6CD6:
                        move.w  #0,L5630_i_(a6)
                @Tloc_6CDC:
        }
        if (L5630_i_) {
                F1956_EndProgram(17, 18, 500L);
        }
#endif
#endif
        switch (P5765_) {
                case 9:
                        switch (*(int16_t*)(&P5765_ + 2)) {
                                case 501:
                                        F1932_(G3590_ps_DiskErrorPleaseTryAgain);
                                        F1955_Input_CPSX(-1, C02_UNINITIALIZE);
                                        do {
                                                F1931_(P5764_i_, 12, G3637_apc_FileNames[C4_CSBGAME_DAT], 0L);
                                                L5630_i_ = F1918_LoadGame_CPSX(0);
                                                if (L5630_i_ != 100) {
                                                        F1889_Screen_CPSX(17, 35);
                                                        F1955_Input_CPSX(17, 3, 6L, 0L);
                                                        F1955_Input_CPSX(17, 3, 7L, 0L);
                                                        if (L5630_i_ == -2) {
                                                                L5631_ = F1931_(20, 13);
                                                                L5628_ = (L5631_ > 1) ? G3580_ps_InsertDiskInDriveB : G3579_ps_InsertDiskInDriveA;
                                                                F1885_(17, 6, L5628_);
                                                        } else {
                                                                F1885_(17, 6, G3591_ps_IncorrectOrDamagedSavedGame);
                                                        }
                                                        do {
                                                                L5631_ = F1955_Input_CPSX(17, 5, 0L);
                                                                L5631_ = F1955_Input_CPSX(17, 8, (long)L5631_);
                                                                if (L5631_ == 6) {
                                                                        L5630_i_ = 0;
                                                                        goto loc_6E44;
                                                                }
                                                        } while (L5631_ != 7);
                                                        L5630_i_ = 2;
                                                } else {
                                                        L5630_i_ = 1;
                                                }
                                                loc_6E44: ;
                                        } while (L5630_i_ == 0);
                                        L5730_ = L5630_i_;
                                        break;
                                case C02L_LOAD_HINTS_FILE:
                                        F1932_(G3586_ps_DiskErrorPleaseTryAgain);
                                        if (!F1931_(P5764_i_, 12, G3637_apc_FileNames[C2_HCSB_HTC], G3582_ps_PleaseInsertCSBUtilityDisk)) {
                                                L5730_ = 0;
                                        }
                                        L5632_i_IORequestIndex = F1855_GetAvailableIORequestIndex();
#ifdef MEDIA772_SU1E
#ifndef NOCOPYPROTECTION
                                        F1952_CheckCopyProtectionSector_CPSX();
#endif
#endif
                                        if (L5632_i_IORequestIndex == -1) {
                                                L5634_ = 87;
                                                L5631_ = 1;
                                                goto loc_7286;
                                        }
                                        F1931_(P5764_i_, 40, (long)L5632_i_IORequestIndex, (long)G3637_apc_FileNames[C2_HCSB_HTC], -1L);
                                        L5633_ = F1857_PerformIORequestOperation(L5632_i_IORequestIndex, C02_OPEN_FILE);
                                        if (L5633_) {
                                                L5634_ = 85;
                                                L5631_ = 1;
                                                goto loc_7286;
                                        }
                                        L5637_ = *(STRUCTHINT**)(&P5765_ + 5);
                                        L5638_ = *(STRUCTHINT**)(&P5765_ + 5);
#ifdef MEDIA773_SU1E_AU1E
                                        if (!F1922_ReadFromHTCFile(L5632_i_IORequestIndex, 2L, &L5635_, "READING FORMAT #")) {
#endif
#ifdef MEDIA767_AU2E
                                        if (!F1922_ReadFromHTCFile(L5632_i_IORequestIndex, 2L, &L5635_)) {
#endif
                                                L5634_ = 200;
                                                L5631_ = 1;
                                                goto loc_7286;
                                        }
                                        if (L5635_ != 2) {
                                                L5634_ = 55;
                                                L5631_ = 1;
                                                goto loc_7286;
                                        }
#ifdef MEDIA773_SU1E_AU1E
                                        if (!F1922_ReadFromHTCFile(L5632_i_IORequestIndex, 2L, &L5635_, "READING ID #")) {
#endif
#ifdef MEDIA767_AU2E
                                        if (!F1922_ReadFromHTCFile(L5632_i_IORequestIndex, 2L, &L5635_)) {
#endif
                                                L5634_ = 201;
                                                L5631_ = 1;
                                                goto loc_7286;
                                        }
                                        if (L5635_ != 13) {
                                                L5634_ = 81;
                                                L5631_ = 1;
                                                goto loc_7286;
                                        }
#ifdef MEDIA773_SU1E_AU1E
                                        if (!F1922_ReadFromHTCFile(L5632_i_IORequestIndex, 2L, &L5635_, "READING header amount")) {
#endif
#ifdef MEDIA767_AU2E
                                        if (!F1922_ReadFromHTCFile(L5632_i_IORequestIndex, 2L, &L5635_)) {
#endif
                                                L5634_ = 202;
                                                L5631_ = 1;
                                                goto loc_7286;
                                        }
                                        F1859_SetIORequestValue(L5632_i_IORequestIndex, 16, (long)(L5635_ * 2));
                                        L5633_ = F1857_PerformIORequestOperation(L5632_i_IORequestIndex, C09_SET_CURRENT_POSITION);
                                        if (L5633_) {
                                                L5634_ = 82;
                                                L5631_ = 1;
                                                goto loc_7286;
                                        }
#ifdef MEDIA773_SU1E_AU1E
                                        if (!F1922_ReadFromHTCFile(L5632_i_IORequestIndex, 2L, &L5635_, "READING NUM_HNTSQRS")) {
#endif
#ifdef MEDIA767_AU2E
                                        if (!F1922_ReadFromHTCFile(L5632_i_IORequestIndex, 2L, &L5635_)) {
#endif
                                                L5634_ = 203;
                                                L5631_ = 1;
                                                goto loc_7286;
                                        }
#ifdef MEDIA773_SU1E_AU1E
                                        if (!F1922_ReadFromHTCFile(L5632_i_IORequestIndex, 2L, &L5636_i_ByteCount, "READING SIZE_HNTSQRS")) {
#endif
#ifdef MEDIA767_AU2E
                                        if (!F1922_ReadFromHTCFile(L5632_i_IORequestIndex, 2L, &L5636_i_ByteCount)) {
#endif
                                                L5634_ = 204;
                                                L5631_ = 1;
                                                goto loc_7286;
                                        }
                                        *L5638_->_pi_0x0C_HintSquareCount = L5635_;
#ifdef MEDIA772_SU1E
                                        *L5637_->_pps_0x00_HintSquares = (HINT_SQUARE*)F1886_Memory(17, C14_ALLOCATE, (long)(L5635_ * L5636_i_ByteCount));
#endif
#ifdef MEDIA763_AU1E_AU2E
                                        *L5637_->_pps_0x00_HintSquares = (HINT_SQUARE*)F1886_Memory(-1, C14_ALLOCATE, (long)(L5635_ * L5636_i_ByteCount));
#endif
#ifdef MEDIA773_SU1E_AU1E
                                        if (!F1922_ReadFromHTCFile(L5632_i_IORequestIndex, (long)(L5635_ * L5636_i_ByteCount), *L5637_->_pps_0x00_HintSquares, "READING HNTSQRS")) {
#endif
#ifdef MEDIA767_AU2E
                                        if (!F1922_ReadFromHTCFile(L5632_i_IORequestIndex, (long)(L5635_ * L5636_i_ByteCount), *L5637_->_pps_0x00_HintSquares)) {
#endif
                                                L5634_ = 205;
                                                L5631_ = 2;
                                                goto loc_7286;
                                        }
#ifdef MEDIA773_SU1E_AU1E
                                        if (!F1922_ReadFromHTCFile(L5632_i_IORequestIndex, 2L, &L5635_, "READING NUM HINTS")) {
#endif
#ifdef MEDIA767_AU2E
                                        if (!F1922_ReadFromHTCFile(L5632_i_IORequestIndex, 2L, &L5635_)) {
#endif
                                                L5634_ = 206;
                                                L5631_ = 2;
                                                goto loc_7286;
                                        }
#ifdef MEDIA773_SU1E_AU1E
                                        if (!F1922_ReadFromHTCFile(L5632_i_IORequestIndex, 2L, &L5636_i_ByteCount, "READING SIZE HINTS")) {
#endif
#ifdef MEDIA767_AU2E
                                        if (!F1922_ReadFromHTCFile(L5632_i_IORequestIndex, 2L, &L5636_i_ByteCount)) {
#endif
                                                L5634_ = 207;
                                                L5631_ = 2;
                                                goto loc_7286;
                                        }
                                        *L5638_->_pi_0x10_HintCount = L5635_;
#ifdef MEDIA772_SU1E
                                        *L5637_->_pps_0x04_Hints = (HINT*)F1886_Memory(17, C14_ALLOCATE, (long)(L5635_ * L5636_i_ByteCount));
#endif
#ifdef MEDIA763_AU1E_AU2E
                                        *L5637_->_pps_0x04_Hints = (HINT*)F1886_Memory(-1, C14_ALLOCATE, (long)(L5635_ * L5636_i_ByteCount));
#endif
#ifdef MEDIA773_SU1E_AU1E
                                        if (!F1922_ReadFromHTCFile(L5632_i_IORequestIndex, (long)(L5635_ * L5636_i_ByteCount), *L5637_->_pps_0x04_Hints, "READING HINTS")) {
#endif
#ifdef MEDIA767_AU2E
                                        if (!F1922_ReadFromHTCFile(L5632_i_IORequestIndex, (long)(L5635_ * L5636_i_ByteCount), *L5637_->_pps_0x04_Hints)) {
#endif
                                                L5634_ = 208;
                                                L5631_ = 3;
                                                goto loc_7286;
                                        }
#ifdef MEDIA773_SU1E_AU1E
                                        if (!F1922_ReadFromHTCFile(L5632_i_IORequestIndex, 2L, &L5636_i_ByteCount, "READING SIZE OF SIZEPOOL")) {
#endif
#ifdef MEDIA767_AU2E
                                        if (!F1922_ReadFromHTCFile(L5632_i_IORequestIndex, 2L, &L5636_i_ByteCount)) {
#endif
                                                L5634_ = 209;
                                                L5631_ = 3;
                                                goto loc_7286;
                                        }
                                        L5636_i_ByteCount *= 2;
#ifdef MEDIA772_SU1E
                                        *L5637_->_ppl_0x08_HintByteCounts = (long*)F1886_Memory(17, C14_ALLOCATE, (long)L5636_i_ByteCount);
#endif
#ifdef MEDIA763_AU1E_AU2E
                                        *L5637_->_ppl_0x08_HintByteCounts = (long*)F1886_Memory(-1, C14_ALLOCATE, (long)L5636_i_ByteCount);
#endif
#ifdef MEDIA773_SU1E_AU1E
                                        if (!F1922_ReadFromHTCFile(L5632_i_IORequestIndex, (long)L5636_i_ByteCount, *L5637_->_ppl_0x08_HintByteCounts, "READING SIZE POOL")) {
#endif
#ifdef MEDIA767_AU2E
                                        if (!F1922_ReadFromHTCFile(L5632_i_IORequestIndex, (long)L5636_i_ByteCount, *L5637_->_ppl_0x08_HintByteCounts)) {
#endif
                                                L5634_ = 210;
                                                L5631_ = 4;
                                                goto loc_7286;
                                        }
                                        F1859_SetIORequestValue(L5632_i_IORequestIndex, 16, 0L);
                                        L5639_ = *(STRUCTHINT**)(&P5765_ + 5);
                                        L5633_ = F1857_PerformIORequestOperation(L5632_i_IORequestIndex, C11_GET_CURRENT_POSITION);
                                        if (L5633_) {
                                                L5634_ = 95;
                                                L5631_ = 4;
                                                goto loc_7286;
                                        }
                                        *L5639_->_pl_0x14_HintDataOffset = F1861_GetIORequestOutputValue(L5632_i_IORequestIndex);
                                        L5631_ = 0;
                                        loc_7286:
                                        F1857_PerformIORequestOperation(L5632_i_IORequestIndex, C10_CLOSE_FILE);
                                        F1856_CloseFile(L5632_i_IORequestIndex);
                                        if (!L5631_) {
                                                L5730_ = 1;
                                        } else {
                                                F1956_EndProgram(P5764_i_, 17, L5634_);
                                                if (L5631_ >= 4) {
#ifdef MEDIA772_SU1E
                                                        F1886_Memory(17, C20_FREE, *L5637_->_ppl_0x08_HintByteCounts);
#endif
#ifdef MEDIA763_AU1E_AU2E
                                                        F1886_Memory(-1, C20_FREE, *L5637_->_ppl_0x08_HintByteCounts);
#endif
                                                }
                                                if (L5631_ >= 3) {
#ifdef MEDIA772_SU1E
                                                        F1886_Memory(17, C20_FREE, *L5637_->_pps_0x04_Hints);
#endif
#ifdef MEDIA763_AU1E_AU2E
                                                        F1886_Memory(-1, C20_FREE, *L5637_->_pps_0x04_Hints);
#endif
                                                }
                                                if (L5631_ >= 2) {
#ifdef MEDIA772_SU1E
                                                        F1886_Memory(17, C20_FREE, *L5637_->_pps_0x00_HintSquares);
#endif
#ifdef MEDIA763_AU1E_AU2E
                                                        F1886_Memory(-1, C20_FREE, *L5637_->_pps_0x00_HintSquares);
#endif
                                                }
                                                L5730_ = 0;
                                        }
                                        break;
                                default:
                                        F1956_EndProgram(P5764_i_, 18, 56L);
                        }
                        break;
                case C32_LOAD_HINT_CONTENT:
                        L5730_ = 1;
                        if ((*((HINT_CONTENT**)(&P5765_ + 1)))->_i_0x00 != 12) {
                                L5634_ = 58;
                                L5631_ = 1;
                                goto loc_74D2;
                        }
                        F1932_(G3587_ps_DiskErrorPleaseTryAgain);
                        if (!F1931_(P5764_i_, 12, G3637_apc_FileNames[(*((HINT_CONTENT**)(&P5765_ + 1)))->_i_0x02_FileNameIndex], G3582_ps_PleaseInsertCSBUtilityDisk)) {
                                L5634_ = 59;
                                L5631_ = 1;
                                goto loc_74D2;
                        }
#ifdef MEDIA772_SU1E
#ifndef NOCOPYPROTECTION
                        F1952_CheckCopyProtectionSector_CPSX();
#endif
#endif
                        L5632_i_IORequestIndex = F1855_GetAvailableIORequestIndex();
                        if (L5632_i_IORequestIndex == -1) {
                                L5634_ = 86;
                                L5631_ = 1;
                                goto loc_74D2;
                        }
                        F1931_(P5764_i_, 40, (long)G3638_i_IORequestIndex_CSBGAME, G3637_apc_FileNames[(*((HINT_CONTENT**)(&P5765_ + 1)))->_i_0x02_FileNameIndex], -1L);
                        L5633_ = F1857_PerformIORequestOperation(L5632_i_IORequestIndex, C02_OPEN_FILE);
                        if (L5633_) {
                                L5634_ = 88;
                                L5631_ = 1;
                                goto loc_74D2;
                        }
                        F1859_SetIORequestValue(L5632_i_IORequestIndex, 16, (*((HINT_CONTENT**)(&P5765_ + 1)))->_l_0x04_Offset);
                        L5633_ = F1857_PerformIORequestOperation(L5632_i_IORequestIndex, C09_SET_CURRENT_POSITION);
                        if (L5633_) {
                                L5634_ = 89;
                                L5631_ = 1;
                                goto loc_74D2;
                        }
#ifdef MEDIA772_SU1E
                        L5628_ = (char*)F1886_Memory(P5764_i_, C14_ALLOCATE, 15009L); /* Dictionary */
                        L5629_ = (char*)F1886_Memory(P5764_i_, C14_ALLOCATE, (long)C5003L_LZW_TEMPORARY_BUFFER_BYTE_COUNT); /* Temporary buffer */
#endif
#ifdef MEDIA763_AU1E_AU2E
                        L5628_ = (char*)F1886_Memory(-1, C14_ALLOCATE, 15009L); /* Dictionary */
                        L5629_ = (char*)F1886_Memory(-1, C14_ALLOCATE, (long)C5003L_LZW_TEMPORARY_BUFFER_BYTE_COUNT); /* Temporary buffer */
#endif
                        F0497_LZW_Decompress(L5632_i_IORequestIndex, (char*)(*((HINT_CONTENT**)(&P5765_ + 1)))->_l_0x08_ByteCount, (char*)(*((HINT_CONTENT**)(&P5765_ + 1)))->_pc_0x0C_DecompressedHintContent, L5628_, L5629_);
#ifdef MEDIA772_SU1E
                        F1886_Memory(P5764_i_, C20_FREE, L5628_);
                        F1886_Memory(P5764_i_, C20_FREE, L5629_);
#endif
#ifdef MEDIA763_AU1E_AU2E
                        F1886_Memory(-1, C20_FREE, L5628_);
                        F1886_Memory(-1, C20_FREE, L5629_);
#endif
                        L5634_ = 0;
                        loc_74D2:
                        L5730_ = L5634_;
                        if (L5634_) {
                                F1956_EndProgram(P5764_i_, 17, L5634_);
                        }
                        L5633_ = F1857_PerformIORequestOperation(L5632_i_IORequestIndex, C10_CLOSE_FILE);
                        F1856_CloseFile(L5632_i_IORequestIndex);
                        break;
#ifdef MEDIA763_AU1E_AU2E
                case 25:
                        L5730_ = 0;
                        break;
#endif
                case C02_UNLOAD_GAME:
                        F1915_UnloadGame(0);
                        break;
                default:
                        F1956_EndProgram(P5764_i_, 18, 61L);
        }
#ifdef MEDIA773_SU1E_AU1E
        F1967_DebugExit(17, P5765_);
#endif
        return L5730_;
}

#ifdef MEDIA772_SU1E
void F1926_Post_F1925_CPSX(
)
{
#include "FAKE3.C"
}
#endif
#endif
