#ifndef COMPILE_H
#include "COMPILE.H"
#endif
#ifdef MEDIA774_SU1E_AU1E_AU2E
#ifdef MEDIA772_SU1E
extern long F1941_();
#endif

#ifdef MEDIA763_AU1E_AU2E
char G3656_ac_DecompressedHintContent[2240];
int16_t G3645_i_SelectedHintCount;
HINT_SQUARE* G3639_ps_HintLocations;
HINT* G3640_ps_Hints;
int16_t* G3641_pi_HintByteCounts = NULL;
unsigned int16_t G3649_i_HintSquareCount;
int16_t G3651_i_HintCount;
long G3653_l_HintDataOffset;
unsigned int16_t G3644_aui_SelectedHintIndices[7];
unsigned int16_t G3643_ui_SelectedHintIndex;
STRUCTHINT G3646_;
long G3730_;
BOOLEAN G3642_B_HintDataLoaded;
int16_t G3709_i_SelectedHintPageIndex = 1;
int16_t G3710_i_SelectedHintIndex;
STRUCT22B* G3712_ps_HintTitle;
STRUCT22B* G3713_ps_HintPageText;
long G3711_l_CurrentHintIndex = 9999999;
long G3714_l_CurrentHintPageIndex = 9999999;
int16_t G3572_B_DebugEnabled = C1_TRUE;
#endif


#ifdef MEDIA772_SU1E
int16_t F1934_Checksum_CPSX(register unsigned char* P5781_, register unsigned char* P5782_) {
        register int16_t L5650_;


        L5650_ = 0;
        while (P5781_ < P5782_) {
                L5650_ ^= *P5781_++;
        }
        return L5650_;
}

#ifndef NOCOPYPROTECTION
void F1935_Pre_F1937_Hints_CPSX(
)
{
#include "FAKE3.C"
}
#endif
#endif

long F1937_Hints_CPSX(int16_t P5786_, int16_t P5787_, ...) {
        register HINT_SQUARE* L5652_;
        register unsigned int16_t L5653_i_PartyMapX;
        register unsigned int16_t L5654_i_PartyMapY;
        register unsigned int16_t L5655_i_PartyMapIndex;
        long L5656_l_Result;
        long L5657_;
        long L5750_l_Unreferenced;
        int16_t L5658_;
        int16_t L5659_;
        HINT* L5660_ps_Hint;
        HINT_PALETTE L5662_s_HintPalette;
        int16_t* L5663_pi_XYZ;
        char* L5664_;


#ifdef MEDIA773_SU1E_AU1E
        F1966_DebugEnter(3, P5787_);
#endif
        switch (P5787_) {
                case C01_INITIALIZE:
                        G3639_ps_HintLocations = NULL;
                        G3640_ps_Hints = NULL;
                        G3641_pi_HintByteCounts = NULL;
                        G3642_B_HintDataLoaded = C0_FALSE;
                        break;
                case C07_SET_SELECTED_HINT_INDEX:
                        G3643_ui_SelectedHintIndex = *(int16_t*)(&P5787_ + 2);
                        break;
                case C13_GET_SELECTED_HINT_INFO:
                        switch (P5786_) {
                                case 1:
                                case 2:
                                        L5656_l_Result = G3645_i_SelectedHintCount;
                                        break;
                                case 4:
                                        L5656_l_Result = G3640_ps_Hints[G3644_aui_SelectedHintIndices[G3643_ui_SelectedHintIndex]].PageCount;
                                        break;
                                default:
                                        F1956_EndProgram(P5786_, 18, 5L);
                        }
                        break;
                case C02_UNINITIALIZE:
                        if (G3642_B_HintDataLoaded) {
                                if (G3639_ps_HintLocations) {
#ifdef MEDIA772_SU1E
                                        F1886_Memory(17, C20_FREE, G3639_ps_HintLocations);
#endif
#ifdef MEDIA763_AU1E_AU2E
                                        F1886_Memory(-1, C20_FREE, G3639_ps_HintLocations);
#endif
                                }
                                if (G3640_ps_Hints) {
#ifdef MEDIA772_SU1E
                                        F1886_Memory(17, C20_FREE, G3640_ps_Hints);
#endif
#ifdef MEDIA763_AU1E_AU2E
                                        F1886_Memory(-1, C20_FREE, G3640_ps_Hints);
#endif
                                }
                                if (G3641_pi_HintByteCounts) {
#ifdef MEDIA772_SU1E
                                        F1886_Memory(17, C20_FREE, G3641_pi_HintByteCounts);
#endif
#ifdef MEDIA763_AU1E_AU2E
                                        F1886_Memory(-1, C20_FREE, G3641_pi_HintByteCounts);
#endif
                                }
                                G3642_B_HintDataLoaded = C0_FALSE;
                        }
                        break;
                case C09_SELECT_HINTS:
                        F1937_Hints_CPSX(P5786_, C02_UNINITIALIZE);
#ifdef MEDIA772_SU1E
                        L5658_ = F1941_(P5786_, 25);
#endif
#ifdef MEDIA763_AU1E_AU2E
                        L5658_ = F1925_CPSX(P5786_, 25);
#endif
                        G3646_._pps_0x00_HintSquares = &G3639_ps_HintLocations;
                        G3646_._pps_0x04_Hints = &G3640_ps_Hints;
                        G3646_._ppl_0x08_HintByteCounts = &G3641_pi_HintByteCounts;
                        G3646_._pi_0x0C_HintSquareCount = &G3649_i_HintSquareCount;
                        G3646_._pi_0x10_HintCount = &G3651_i_HintCount;
                        G3646_._pl_0x14_HintDataOffset = &G3653_l_HintDataOffset;
                        for (;;) {
                                L5657_ = F1925_CPSX(P5786_, 9, C02L_LOAD_HINTS_FILE, (long)L5658_, &G3646_);
                                if (L5657_ == 1) {
                                        break;
                                }
                                F1885_(3, 8, G3584_ps_DiskErrorPleaseTryAgain);
                        }
#ifdef MEDIA772_SU1E
#ifndef NOCOPYPROTECTION
                        F1901_CopyProtectionRoutine_CPSX();
#endif
#endif
                        L5653_i_PartyMapX = G3623_Game[0].GlobalData.PartyMapX;
                        L5654_i_PartyMapY = G3623_Game[0].GlobalData.PartyMapY;
                        L5655_i_PartyMapIndex = G3623_Game[0].GlobalData.PartyMapIndex;
                        L5652_ = G3639_ps_HintLocations;
                        G3645_i_SelectedHintCount = 0;
                        L5658_ = 0;
                        while (L5658_ < G3649_i_HintSquareCount) {
                                if (L5652_->MapIndex == (char)L5655_i_PartyMapIndex) {
                                        if (((L5652_->MapX == (unsigned char)L5653_i_PartyMapX) && (L5652_->MapY == (unsigned char)L5654_i_PartyMapY)) || ((L5652_->MapX == (unsigned char)255) && (L5652_->MapY == (unsigned char)255))) {
                                                G3644_aui_SelectedHintIndices[G3645_i_SelectedHintCount++] = L5652_->HintIndex;
                                                if (G3645_i_SelectedHintCount >= 7) {
                                                        break;
                                                }
                                        }
                                }
                                L5658_++;
                                L5652_++;
                        }
                        G3642_B_HintDataLoaded = C1_TRUE;
                        break;
                case C06_DRAW_HINT_LIST:
                        switch (P5786_) {
                                case 2:
                                        L5659_ = F1937_Hints_CPSX(P5786_, C13_GET_SELECTED_HINT_INFO);
                                        for (L5658_ = 0; L5658_ < G3645_i_SelectedHintCount; L5658_++) {
                                                F1955_Input_CPSX(P5786_, 3, (long)L5658_ + 10, 0L);
                                                L5657_ = (long)F1884_Text(P5786_, C16_ALLOCATE_AND_INITIALIZE, (long)(int16_t)F0090_strlen(G3640_ps_Hints[G3644_aui_SelectedHintIndices[L5658_]].Title));
                                                ((STRUCT22B*)L5657_)->_i_0x00 = 3;
                                                F1909_CopyStringUntilCharacter(G3640_ps_Hints[G3644_aui_SelectedHintIndices[L5658_]].Title, ((STRUCT22B*)L5657_)->_pc_0x02_String, '\0');
                                                L5663_pi_XYZ = (int16_t*)F1955_Input_CPSX(P5786_, C12_INPUT_INFO_FROM_COMMAND, (long)L5658_ + 10, C3L_GET_HINT_BUTTON_BOX);
                                                ((STRUCT22B*)L5657_)->_ai_XYZ_0x06[0] = L5663_pi_XYZ[0];
                                                ((STRUCT22B*)L5657_)->_ai_XYZ_0x06[1] = L5663_pi_XYZ[1];
                                                ((STRUCT22B*)L5657_)->_ai_XYZ_0x06[2] = L5663_pi_XYZ[2];
                                                ((STRUCT22B*)L5657_)->_ai_XYZ_0x06[3] = L5663_pi_XYZ[3];
                                                L5662_s_HintPalette._i_0x00 = 13;
                                                L5662_s_HintPalette._pui_0x06_TargetPalette = G3603_aui_Palette_HintOracle;
                                                G3603_aui_Palette_HintOracle[G3609_aui_GraphicIntegers[8]] = G3609_aui_GraphicIntegers[36];
                                                F1893_ColorPalette(P5786_, C38_SET_PALETTE, &L5662_s_HintPalette);
                                                F1965_(19, 27, 6L, L5663_pi_XYZ);
                                                F1965_(9, 27, 20L, L5657_, 8L);
                                                F1955_Input_CPSX(P5786_, C12_INPUT_INFO_FROM_COMMAND, (long)L5658_ + 10, C5L_SET_HINT_BUTTON_STRING, G3640_ps_Hints[G3644_aui_SelectedHintIndices[L5658_]].Title);
                                        }
                                        F1889_Screen_CPSX(P5786_, 31);
#ifdef MEDIA772_SU1E
                                        F0077_MOUSE_EnableScreenUpdate_CPSE();
#endif
#ifdef MEDIA763_AU1E_AU2E
                                        F1527_MOUSE_EnableScreenUpdate_CPSE();
#endif
                                        F1889_Screen_CPSX(3, 36);
                                        for (;;) {
                                                L5657_ = F1965_(19, 28, 6L, -1L);
                                                if ((((STRUCT16B*)L5657_) == NULL) || (((STRUCT16B*)L5657_)->_i_0x00 != 8)) {
                                                        break;
                                                }
#ifdef MEDIA772_SU1E
                                                F1904_ApplyPaletteChangesToScreenArea((int16_t*)((STRUCT16B*)L5657_)->_ps_0x08, G3655_auc_PaletteChanges);
#endif
                                                F1965_(19, 29, (long)((STRUCT16B*)L5657_)->_i_0x02);
                                        }
                                        F1889_Screen_CPSX(3, 37);
#ifdef MEDIA772_SU1E
                                        F0078_MOUSE_DisableScreenUpdate();
#endif
#ifdef MEDIA763_AU1E_AU2E
                                        F1528_MOUSE_DisableScreenUpdate();
#endif
                                        break;
                                default:
                                        F1956_EndProgram(P5786_, 18, 6L, (long)P5786_);
                        }
                        break;
                case C12_GET_HINT_TITLE_OR_PAGE:
                        L5656_l_Result = 0;
                        if (*(int16_t*)(&P5787_ + 2) > G3645_i_SelectedHintCount) {
                                F1956_EndProgram(P5786_, 18, 7L);
                        } else {
                                L5660_ps_Hint = &G3640_ps_Hints[G3644_aui_SelectedHintIndices[*(int16_t*)(&P5787_ + 2)]];
                                if ((*(int16_t*)(&P5787_ + 4)) > L5660_ps_Hint->PageCount) {
                                        F1956_EndProgram(P5786_, 18, 8L);
                                } else {
                                        if (*(int16_t*)(&P5787_ + 4)) { /* If hint page */
                                                L5656_l_Result = (long)G3656_ac_DecompressedHintContent;
                                                for (L5658_ = 1; L5658_ < *(int16_t*)(&P5787_ + 4); L5658_++) {
                                                        L5664_ = (char*)L5656_l_Result;
                                                        while (*L5664_++);
                                                        L5656_l_Result = (long)L5664_;
                                                }
                                        } else { /* If hint title */
                                                *(long*)(&P5787_ + 3) = 1;
#ifdef MEDIA772_SU1E
                                                L5657_ = (long)F1886_Memory(P5786_, C14_ALLOCATE, (long)sizeof(HINT_CONTENT));
#endif
#ifdef MEDIA763_AU1E_AU2E
                                                L5657_ = (long)F1886_Memory(-1, C14_ALLOCATE, (long)sizeof(HINT_CONTENT));
#endif
                                                ((HINT_CONTENT*)L5657_)->_i_0x00 = 12;
                                                ((HINT_CONTENT*)L5657_)->_i_0x02_FileNameIndex = C2_HCSB_HTC;
                                                ((HINT_CONTENT*)L5657_)->_l_0x04_Offset = G3653_l_HintDataOffset;
                                                for (L5658_ = 0; L5658_ < L5660_ps_Hint->FirstPageIndex + (*(int16_t*)(&P5787_ + 4)) - 1; L5658_++) {
                                                        ((HINT_CONTENT*)L5657_)->_l_0x04_Offset += G3641_pi_HintByteCounts[L5658_];
                                                }
                                                ((HINT_CONTENT*)L5657_)->_l_0x08_ByteCount = G3641_pi_HintByteCounts[L5658_];
                                                ((HINT_CONTENT*)L5657_)->_pc_0x0C_DecompressedHintContent = G3656_ac_DecompressedHintContent;
                                                for (;;) {
                                                        if (!F1925_CPSX(P5786_, C32_LOAD_HINT_CONTENT, L5657_)) {
                                                                break;
                                                        }
                                                        F1885_(3, 8, G3585_ps_DiskError_LoadHintContent);
                                                }
#ifdef MEDIA772_SU1E
                                                F1886_Memory(P5786_, C20_FREE, L5657_);
#endif
#ifdef MEDIA763_AU1E_AU2E
                                                F1886_Memory(-1, C20_FREE, L5657_);
#endif
                                                L5656_l_Result = (long)L5660_ps_Hint->Title;
                                        }
                                }
                        }
                        break;
                default:
                        F1956_EndProgram(P5786_, 18, 9L);
        }
#ifdef MEDIA773_SU1E_AU1E
        F1967_DebugExit(3, P5787_);
#endif
        return L5656_l_Result;
}

#ifdef MEDIA772_SU1E
#ifndef NOCOPYPROTECTION
void F1938_Post_F1937_Hints_CPSX(
)
{
#include "FAKE2.C"
}
#endif
#endif

long F1940_CPSX(int16_t P5792_, int16_t P5793_, ...) {
        long L5665_;
        char* L5666_;
#ifdef MEDIA772_SU1E
        int16_t L5667_;
#endif


#ifdef MEDIA773_SU1E_AU1E
        F1966_DebugEnter(19, P5793_);
#endif
#ifdef MEDIA772_SU1E
#ifndef NOCOPYPROTECTION
        L5667_ = F1908_Checksum_CPSX(*((char**)((char*)F1935_Pre_F1937_Hints_CPSX + 2)), *((char**)((char*)F1938_Post_F1937_Hints_CPSX + 2)));
        asm {
                @Tloc_8000:
                        move.w  L5665_(a6),d1
                        cmpi.w  #0xE88B,d1
                        bcc.s   @Tloc_800E
                        moveq   #1,d0
                        bra.s   @Tloc_8010
                @Tloc_800E:
                        moveq   #0,d0
                @Tloc_8010:
                        move.w  L5667_(a6),d1
                        cmp.w   d0,d1
                        bcc.s   @Tloc_801C
                        moveq   #1,d0
                        bra.s   @Tloc_801E
                @Tloc_801C:
                        moveq   #0,d0
                @Tloc_801E:
                        lea     @Tloc_8000,a0
                        move.w  L5667_(a6),d0
                        cmp.w   6(a0),d0
                        beq.s   @Tloc_8034
                        move.w  #1,L5667_(a6)
                        bra.s   @Tloc_803A
                @Tloc_8034:
                        move.w  #0,L5667_(a6)
                @Tloc_803A:
        }
        L5667_ += 23;
#endif
#endif
        switch (P5793_) {
                case 36:
                        if (*((long*)(&P5793_ + 3)) == 0) { /* If specified hint index is not 0 then change hint selection */
                                G3709_i_SelectedHintPageIndex = 1;
                                G3710_i_SelectedHintIndex = *((int16_t*)(&P5793_ + 2));
                        } else { /* Else update page index (+1 for next, -1 for last) */
                                G3709_i_SelectedHintPageIndex += *((int16_t*)(&P5793_ + 4));
                        }
                        F1940_CPSX(4, C07_UPDATE_CURRENT_HINT_TEXT, (long)G3710_i_SelectedHintIndex, (long)G3709_i_SelectedHintPageIndex, 0L);
                        F1955_Input_CPSX(4, 3, 5L, 0L);
                        if ((int16_t)F1937_Hints_CPSX(4, C13_GET_SELECTED_HINT_INFO) > G3709_i_SelectedHintPageIndex) {
                                F1955_Input_CPSX(4, 3, 4L, 0L);
                        }
                        if (G3709_i_SelectedHintPageIndex > 1) {
                                F1955_Input_CPSX(4, 3, 3L, 0L);
                        }
                        F1889_Screen_CPSX(P5792_, 31);
                        break;
                case C07_UPDATE_CURRENT_HINT_TEXT:
                        if (*((long*)(&P5793_ + 1)) != G3711_l_CurrentHintIndex) {
                                if (G3712_ps_HintTitle) {
                                        F1884_Text(P5792_, C20_FREE, G3712_ps_HintTitle);
                                }
                                if (G3713_ps_HintPageText) {
                                        F1884_Text(P5792_, C20_FREE, G3713_ps_HintPageText);
                                }
                                G3712_ps_HintTitle = NULL;
                                G3713_ps_HintPageText = NULL;
                        } else {
                                if (*((long*)(&P5793_ + 3)) != G3714_l_CurrentHintPageIndex) {
                                        if (G3713_ps_HintPageText) {
                                                F1884_Text(P5792_, C20_FREE, G3713_ps_HintPageText);
                                        }
                                        G3713_ps_HintPageText = NULL;
                                }
                        }
                        G3711_l_CurrentHintIndex = *((long*)(&P5793_ + 1));
                        G3714_l_CurrentHintPageIndex = *((long*)(&P5793_ + 3));
                        if (G3712_ps_HintTitle == NULL) {
                                L5666_ = (char*)F1937_Hints_CPSX(P5792_, C12_GET_HINT_TITLE_OR_PAGE, *((long*)(&P5793_ + 1)), 0L); /* Page #0 = Hint Title */
                                if (L5666_ == NULL) {
                                        break;
                                }
                                G3712_ps_HintTitle = (STRUCT22B*)F1884_Text(P5792_, C16_ALLOCATE_AND_INITIALIZE, (long)(int16_t)F0090_strlen(L5666_) + 1);
                                F1909_CopyStringUntilCharacter(L5666_, G3712_ps_HintTitle->_pc_0x02_String, '\0');
                                G3712_ps_HintTitle->_ai_XYZ_0x06[0] = G3621_ai_XYZ_Screen[0] + 10;
                                G3712_ps_HintTitle->_ai_XYZ_0x06[1] = G3621_ai_XYZ_Screen[1] - 10;
                                G3712_ps_HintTitle->_ai_XYZ_0x06[2] = G3621_ai_XYZ_Screen[2] + 5;
                                G3712_ps_HintTitle->_ai_XYZ_0x06[3] = G3621_ai_XYZ_Screen[2] + 30;
                        }
#ifdef MEDIA772_SU1E
#ifndef NOCOPYPROTECTION
                        if (L5667_ != 23) {
                                F1956_EndProgram(P5792_, 18, 508L);
                        }
#endif
#endif
                        if (G3713_ps_HintPageText == NULL) {
                                L5666_ = (char*)F1937_Hints_CPSX(P5792_, C12_GET_HINT_TITLE_OR_PAGE, *((long*)(&P5793_ + 1)), *((long*)(&P5793_ + 3))); /* Page #1 to #7 = Hint page content */
                                if (L5666_ == NULL) {
                                        break;
                                }
                                G3713_ps_HintPageText = (STRUCT22B*)F1884_Text(P5792_, C16_ALLOCATE_AND_INITIALIZE, (long)(int16_t)F0090_strlen(L5666_) + 1);
                                F1909_CopyStringUntilCharacter(L5666_, G3713_ps_HintPageText->_pc_0x02_String, 0);
                                G3713_ps_HintPageText->_ai_XYZ_0x06[0] = G3621_ai_XYZ_Screen[0] + 34;
                                G3713_ps_HintPageText->_ai_XYZ_0x06[1] = G3621_ai_XYZ_Screen[1] - 34;
                                G3713_ps_HintPageText->_ai_XYZ_0x06[2] = 31;
                                G3713_ps_HintPageText->_ai_XYZ_0x06[3] = 164;
                        }
                        F1965_(9, 27, 34L, G3713_ps_HintPageText, 6L);
                        break;
                case C02_UNINITIALIZE:
                        if (G3712_ps_HintTitle) {
                                F1884_Text(P5792_, C20_FREE, G3712_ps_HintTitle);
                        }
                        if (G3713_ps_HintPageText) {
                                F1884_Text(P5792_, C20_FREE, G3713_ps_HintPageText);
                        }
                        G3712_ps_HintTitle = NULL;
                        G3713_ps_HintPageText = NULL;
                        G3711_l_CurrentHintIndex = 9999999;
                        G3714_l_CurrentHintPageIndex = 9999999;
                        break;
                default:
                        F1956_EndProgram(P5792_, 18, 11L);
        }
#ifdef MEDIA773_SU1E_AU1E
        F1967_DebugExit(19, P5793_);
#endif
        return L5665_;
}

#ifdef MEDIA772_SU1E
long F1941_(int16_t P5796_, int16_t P5797_) {
        long L5668_;


        F1966_DebugEnter(8, P5797_);
        switch (P5797_) {
                case 25:
                        L5668_ = 0;
                        break;
                default:
                        F1956_EndProgram(P5796_, 18, 48L);
        }
        F1967_DebugExit(8, P5797_);
        return L5668_;
}
#endif
#endif
