#ifndef COMPILE_H
#include "COMPILE.H"
#endif
#ifdef MEDIA774_SU1E_AU1E_AU2E
#ifdef MEDIA772_SU1E
extern void F1899_Pre_F1901_CopyProtectionRoutine_CPSX();
extern void F1902_Post_F1901_CopyProtectionRoutine_CPSX();
extern void F1916_Pre_F1918_LoadGame_CPSX();
extern void F1919_Post_F1918_LoadGame_CPSX();
#endif
#ifdef MEDIA763_AU1E_AU2E
extern FTL_LIBRARY* F9008_OpenPRIM();
#endif

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

unsigned int16_t F1944_ChecksumAdd(unsigned int16_t* P5801_, register unsigned int16_t* P5802_) {
        register unsigned int16_t* L5670_;
        register unsigned int16_t L5671_;


        L5670_ = P5801_;
        L5671_ = 0;
        while ((long)L5670_ < (long)P5802_) {
                L5671_ += *L5670_;
                L5670_++;
        }
        return L5671_;
}
#endif

void main(
#ifdef MEDIA763_AU1E_AU2E
FTL_LIBRARY* P5945_, FTL_EXECUTABLE* P5946_
#endif
)
{
        int16_t L5672_i_CommandIndex;
        int16_t L5673_;
        int16_t L5674_;
        STRUCT22B* L5675_;


#ifdef MEDIA772_SU1E
#ifndef NOCOPYPROTECTION
        goto loc_8422;
        asm {
                dc.b "Copyright (C), 1989 Software Heaven Inc. !"
        }
        loc_8422:
        L5673_ = F1934_Checksum_CPSX(*((char**)((char*)F1899_Pre_F1901_CopyProtectionRoutine_CPSX + 2)), *((char**)((char*)F1902_Post_F1901_CopyProtectionRoutine_CPSX + 2)));
        asm {
                        lea     @Tloc_8450,a1
                        move.w  L5673_(a6),d1
                        cmp.w   6(a1),d1
                        beq.s   @Tloc_844A
                        move.w  #1,L5673_(a6)
                        bra.s   @Tloc_8450
                @Tloc_844A:
                        move.w  #0,L5673_(a6)
                @Tloc_8450:
                        move.w  #0xC8,d1
                        move.w  #0x1E,d1
                        add.w   L5673_(a6),d1
                        beq.s   @Tloc_846C
                        move.w  L5675_(a6),d1
                        cmp.w   d0,d1
                        beq.s   @Tloc_846C
                        move.w  #0xFFFF,d0
                        bra.s   @Tloc_846E
                @Tloc_846C:
                        asl.w   #1,d0
                @Tloc_846E:
        }
        if (L5673_) {
                F1956_EndProgram(14, 18, 502L);
        }
#endif
#endif
#ifdef MEDIA763_AU1E_AU2E
        G3622_ = 0;
        if (F9008_OpenPRIM(P5945_, 2)) {
                F1067_InitAmigaStuff();
                F1886_Memory(14, C01_INITIALIZE);
#endif
                F1759_();
#ifdef MEDIA762_AU1E
                F1282_WriteString("UNPROTECTED version\n\r");
#endif
#ifdef MEDIA772_SU1E
                G3543_B_ = G3544_B_ = G3546_B_ = G3572_B_DebugEnabled = C1_TRUE;
#endif
#ifdef MEDIA763_AU1E_AU2E
                G3572_B_DebugEnabled = C1_TRUE;
                G3546_B_ = C1_TRUE;
                G3544_B_ = C1_TRUE;
#endif
                G3576_i_Unused = 0;
#ifdef MEDIA773_SU1E_AU1E
                F1969_DebugInitialize();
#endif
                F1889_Screen_CPSX(10, 1);
                F1937_Hints_CPSX(10, C01_INITIALIZE);
#ifdef MEDIA772_SU1E
#ifndef NOCOPYPROTECTION
                F1952_CheckCopyProtectionSector_CPSX();
#endif
#endif
                F1965_(10, 1);
                F1955_Input_CPSX(10, C01_INITIALIZE);
                L5673_ = 1;
                F1955_Input_CPSX(L5673_, 3, 1L, 0L);
                F1955_Input_CPSX(L5673_, 3, 2L, 0L);
                L5675_ = ((int16_t)F1931_(L5673_, 13) > 1) ? G3578_ps_InsertDiskInDriveBThenPressLoad : G3577_ps_InsertDiskInDriveAThenPressLoad;
                F1885_(L5673_, 6, L5675_);
                do {
                        L5672_i_CommandIndex = F1955_Input_CPSX(L5673_, 5, (long)L5673_);
                        L5672_i_CommandIndex = F1955_Input_CPSX(L5673_, 8, (long)L5672_i_CommandIndex);
                        switch (L5672_i_CommandIndex) { /* Command index values from field Command of G3598_as_HintButtons */
                                case C01_HINT_COMMAND_LOAD:
                                        switch (L5673_) {
                                                case 1:
                                                        F1940_CPSX(L5673_, C02_UNINITIALIZE);
                                                        if (F1925_CPSX(L5673_, 9, 501L) != 1) {
                                                                L5673_ = 1;
                                                                F1955_Input_CPSX(L5673_, 3, 1L, 0L);
                                                                F1955_Input_CPSX(L5673_, 3, 2L, 0L);
                                                                L5675_ = ((int16_t)F1931_(L5673_, 13) > 1) ? G3578_ps_InsertDiskInDriveBThenPressLoad : G3577_ps_InsertDiskInDriveAThenPressLoad;
                                                                F1885_(L5673_, 6, L5675_);
                                                        } else {
                                                                F1937_Hints_CPSX(L5673_, C09_SELECT_HINTS);
                                                                if ((int16_t)F1937_Hints_CPSX(L5673_, C13_GET_SELECTED_HINT_INFO) > 0) {
                                                                        L5673_ = 2;
                                                                        F1955_Input_CPSX(L5673_, 3, 5L, 0L);
                                                                        F1937_Hints_CPSX(L5673_, C06_DRAW_HINT_LIST);
                                                                } else {
                                                                        L5673_ = 2;
                                                                        F1955_Input_CPSX(L5673_, 3, 5L, 0L);
                                                                        F1885_(L5673_, 6, G3581_ps_NoClueForThisLocation);
                                                                }
                                                        }
                                                        break;
                                                default:
                                                        F1956_EndProgram(L5673_, 18, 41L);
                                        }
                                        break;
                                case C02_HINT_COMMAND_EXIT:
                                        F1894_ExitHintOracle(L5673_, 31);
                                        break;
                                case C10_HINT_COMMAND_HINT_0:
                                case C11_HINT_COMMAND_HINT_1:
                                case C12_HINT_COMMAND_HINT_2:
                                case C13_HINT_COMMAND_HINT_3:
                                case C14_HINT_COMMAND_HINT_4:
                                case C15_HINT_COMMAND_HINT_5:
                                case C16_HINT_COMMAND_HINT_6:
#ifdef MEDIA772_SU1E
#ifndef NOCOPYPROTECTION
                                        L5674_ = F1908_Checksum_CPSX(*((char**)((char*)F1916_Pre_F1918_LoadGame_CPSX + 2)), *((char**)((char*)F1919_Post_F1918_LoadGame_CPSX + 2)));
                                        asm {
                                                @Tloc_8704:
                                                        move.w  L5673_(a6),d1
                                                        cmpi.w  #0x8888,d1
                                                        bcc.s   @Tloc_8712
                                                        moveq   #1,d0
                                                        bra.s   @Tloc_8714
                                                @Tloc_8712:
                                                        moveq   #0,d0
                                                @Tloc_8714:
                                                        move.w  L5675_(a6),d1
                                                        cmp.w   d0,d1
                                                        bcc.s   @Tloc_8720
                                                        moveq   #1,d0
                                                        bra.s   @Tloc_8722
                                                @Tloc_8720:
                                                        moveq   #0,d0
                                                @Tloc_8722:
                                                        lea     @Tloc_8704,a0
                                                        move.w  L5674_(a6),d0
                                                        cmp.w   6(a0),d0
                                                        beq.s   @Tloc_8738
                                                        move.w  #1,L5674_(a6)
                                                        bra.s   @Tloc_873E
                                                @Tloc_8738:
                                                        move.w  #0,L5674_(a6)
                                                @Tloc_873E:
                                        }
                                        if (L5674_) {
                                                F1956_EndProgram(14, 18, 503L);
                                                for (;;);
                                        }
#endif
#endif
                                        L5673_ = 4;
                                        F1937_Hints_CPSX(L5673_, C07_SET_SELECTED_HINT_INDEX, (long)L5672_i_CommandIndex - 10);
                                        F1940_CPSX(L5673_, 36, (long)L5672_i_CommandIndex - 10, 0L);
                                        break;
                                case C05_HINT_COMMAND_DONE:
                                        switch (L5673_) {
                                                case 4:
                                                        L5673_ = 2;
                                                        F1955_Input_CPSX(L5673_, 3, 5L, 0L);
                                                        F1937_Hints_CPSX(L5673_, C06_DRAW_HINT_LIST);
                                                        break;
                                                case 2:
                                                        L5673_ = 1;
                                                        F1955_Input_CPSX(L5673_, 3, 1L, 0L);
                                                        F1955_Input_CPSX(L5673_, 3, 2L, 0L);
                                                        L5675_ = ((int16_t)F1931_(L5673_, 13) > 1) ? G3578_ps_InsertDiskInDriveBThenPressLoad : G3577_ps_InsertDiskInDriveAThenPressLoad;
                                                        F1885_(L5673_, 6, L5675_);
                                                        break;
                                                default:
                                                        F1956_EndProgram(L5673_, 18, 75L);
                                        }
                                        break;
                                case C03_HINT_COMMAND_LAST:
                                case C04_HINT_COMMAND_NEXT:
                                        F1940_CPSX(L5673_, 36, 0L, (L5672_i_CommandIndex == C03_HINT_COMMAND_LAST) ? -1L : 1L);
                                        break;
                                default:
                                        F1956_EndProgram(1, 18, 42L);
                                        break;
                                case 0:
                                        break;
                        }
                } while (L5672_i_CommandIndex != 2);
#ifdef MEDIA773_SU1E_AU1E
                F1969_DebugInitialize();
#endif
#ifdef MEDIA763_AU1E_AU2E
                F1889_Screen_CPSX(10, C02_UNINITIALIZE);
                F1886_Memory(14, C02_UNINITIALIZE);
                P5946_->Parameter = FTL_APPB;
                F1068_FreeAmigaStuff();
        } else {
                P5946_->Parameter = FTL_APPB;
        }
#endif
}

#ifdef MEDIA772_SU1E
void F1945_Pre_F1944_ChecksumAdd_main(
)
{
#include "FAKE1.C"
}
#endif
#endif
