#ifndef COMPILE_H
#include "COMPILE.H"
#endif
#ifdef MEDIA774_SU1E_AU1E_AU2E
HINT_GRAPHICS* G3677_ps_HintGraphics;

#if (defined(MEDIA772_SU1E) && (EXETYPE == C07_HINT))
unsigned char* G0348_Bitmap_Screen;
BOOLEAN G0578_B_UseByteBoxCoordinates;
#endif

#if (defined(MEDIA772_SU1E) && (EXETYPE == C07_HINT))
char G3656_ac_DecompressedHintContent[2240]; /* to HINTHINT.C */
int16_t G3645_i_SelectedHintCount; /* to HINTHINT.C */
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; /* to HINTHINT.C */
long G3714_l_CurrentHintPageIndex = 9999999; /* to HINTHINT.C */

int16_t G3572_B_DebugEnabled = C1_TRUE; /* to HINTDBG.C */
int16_t G3684_i_CallDepth; /* to HINTDBG.C */
char* G3731_apc_DebugCategoryNames[64] = { /* to HINTDBG.C */
        "zero",         /*  0 */
        "CLUELESS",     /*  1 */
        "CLUEDIN",      /*  2 */
        "TITLES",       /*  3 */
        "OFFERCLUE",    /*  4 */
        "EVENTS",       /*  5 */
        "DISPLAYS",     /*  6 */
        "ERRORS",       /*  7 */
        "PARTIES",      /*  8 */
        "TEXTS",        /*  9 */
        "HINTS",        /* 10 */
        "TIMES",        /* 11 */
        "EXITS",        /* 12 */
        "DICTIONARIES", /* 13 */
        "SYSTEMS",      /* 14 */
        "MEMORIES",     /* 15 */
        "TESTS",        /* 16 */
        "RESOURCES",    /* 17 */
        "DIALOGS",      /* 18 */
        "OFFERINGS",    /* 19 */
        "DISKS",        /* 20 */
        "DIRECTIONS",   /* 21 */
        "PALETTES",     /* 22 */
        "zero",         /* 23 */
        "CREATE",       /* 24 */
        "KILL",         /* 25 */
        "ADD",          /* 26 */
        "PAIR",         /* 27 */
        "WAIT",         /* 28 */
        "SHOW",         /* 29 */
        "FORCE",        /* 30 */
        "CHECK",        /* 31 */
        "LOAD",         /* 32 */
        "SAVE",         /* 33 */
        "REMOVE",       /* 34 */
        "ACCESS",       /* 35 */
        "COUNT",        /* 36 */
        "ALLOC",        /* 37 */
        "BREAK",        /* 38 */
        "ALLOC_AUTO",   /* 39 */
        "FLY",          /* 40 */
        "MOSQUITO",     /* 41 */
        "TEST",         /* 42 */
        "DEALLOC",      /* 43 */
        "SUBTRACT",     /* 44 */
        "REM_ALLOC",    /* 45 */
        "REM_DEALLOC",  /* 46 */
        "DE_ACCESS",    /* 47 */
        "GET_KEY",      /* 48 */
        "MOVE",         /* 49 */
        "PAIR_IN",      /* 50 */
        "PAIR_OUT",     /* 51 */
        "PAIR_KILL",    /* 52 */
        "DESTROY",      /* 53 */
        "TELL",         /* 54 */
        "READ",         /* 55 */
        "FIND",         /* 56 */
        "FADE",         /* 57 */
        "FLIP",         /* 58 */
        "FLIP_IN",      /* 59 */
        "FLIP_OUT",     /* 60 */
        "CHANGE",       /* 61 */
        "SWAP",         /* 62 */
        "STUFF" };      /* 63 */
/* strings, border between two .C source files */
#endif


long F1872_LoadGraphics(char* P5664_, register HINT_GRAPHICS* P5665_ps_HintGraphics, char** P5666_) {
        register int16_t* L5527_;
        register int16_t L5528_;
        int16_t L5529_i_GraphicCount;
        long L5530_;
        long L5531_;
        long L5743_l_Unreferenced;
        long L5532_;
        int16_t L5533_;


        P5665_ps_HintGraphics->_i_0x00_IORequestIndex = F1855_GetAvailableIORequestIndex();
        if ((long)P5665_ps_HintGraphics->_i_0x00_IORequestIndex != 0) {
                return 0;
        }
        F1931_(14, 40, (long)P5665_ps_HintGraphics->_i_0x00_IORequestIndex, P5664_, -1L);
        L5532_ = F1857_PerformIORequestOperation(P5665_ps_HintGraphics->_i_0x00_IORequestIndex, C02_OPEN_FILE);
        if (L5532_) {
                L5533_ = 0;
        } else {
                F1859_SetIORequestValue(P5665_ps_HintGraphics->_i_0x00_IORequestIndex, 16, (long)sizeof(L5529_i_GraphicCount));
                F1859_SetIORequestValue(P5665_ps_HintGraphics->_i_0x00_IORequestIndex, 8, (long)&L5529_i_GraphicCount);
                L5532_ = F1857_PerformIORequestOperation(P5665_ps_HintGraphics->_i_0x00_IORequestIndex, C07_READ_FILE); /* Read number of graphics in file */
                if (L5532_) {
                        L5533_ = 0;
                } else {
#ifdef MEDIA772_SU1E
                        P5665_ps_HintGraphics->_pl_0x04_GraphicOffsets = (long*)F1886_Memory(17, C14_ALLOCATE, (long)((L5529_i_GraphicCount + 1) * sizeof(long)));
#endif
#ifdef MEDIA763_AU1E_AU2E
                        P5665_ps_HintGraphics->_pl_0x04_GraphicOffsets = (long*)F1886_Memory(-1, C14_ALLOCATE, (long)((L5529_i_GraphicCount + 1) * sizeof(long)));
#endif
                        F1859_SetIORequestValue(P5665_ps_HintGraphics->_i_0x00_IORequestIndex, 16, (long)(L5529_i_GraphicCount * 2));
                        F1859_SetIORequestValue(P5665_ps_HintGraphics->_i_0x00_IORequestIndex, 8, (long)P5665_ps_HintGraphics->_pl_0x04_GraphicOffsets);
                        L5532_ = F1857_PerformIORequestOperation(P5665_ps_HintGraphics->_i_0x00_IORequestIndex, C07_READ_FILE); /* Read size of each graphic */
                        if (L5532_) {
                                L5533_ = 0;
                        } else {
                                P5665_ps_HintGraphics->_i_0x02_MaximumGraphicIndex = L5529_i_GraphicCount - 1;
                                L5527_ = P5665_ps_HintGraphics->_pl_0x04_GraphicOffsets;
                                if (P5666_) {
#ifdef MEDIA772_SU1E
                                        *P5666_ = (char*)F1886_Memory(14, C14_ALLOCATE, (long)((L5529_i_GraphicCount + 1) * 2));
#endif
#ifdef MEDIA763_AU1E_AU2E
                                        *P5666_ = (char*)F1886_Memory(-1, C14_ALLOCATE, (long)((L5529_i_GraphicCount + 1) * 2));
#endif
                                        F7317_MAIN_CopyBytes_Alt(P5665_ps_HintGraphics->_pl_0x04_GraphicOffsets, (char*)*P5666_, MASK0x0400_MEMREQ, MASK0x0400_MEMREQ, (long)((L5529_i_GraphicCount + 1) * 2));
                                }
                                for (L5528_ = L5529_i_GraphicCount - 1; L5528_ >= 0; L5528_--) { /* Convert size values from int16_t to long */
                                        P5665_ps_HintGraphics->_pl_0x04_GraphicOffsets[L5528_] = L5527_[L5528_];
                                }
                                L5530_ = (L5529_i_GraphicCount << 2) + 2;
                                for (L5528_ = 0; L5528_ <= L5529_i_GraphicCount; L5528_++) { /* Replace size values by offset values */
                                        L5531_ = P5665_ps_HintGraphics->_pl_0x04_GraphicOffsets[L5528_];
                                        P5665_ps_HintGraphics->_pl_0x04_GraphicOffsets[L5528_] = L5530_;
                                        L5530_ += L5531_;
                                }
                                G3677_ps_HintGraphics = P5665_ps_HintGraphics;
                                return 0;
                        }
                }
        }
        F1857_PerformIORequestOperation(P5665_ps_HintGraphics->_i_0x00_IORequestIndex, C10_CLOSE_FILE);
        F1856_CloseFile(P5665_ps_HintGraphics->_i_0x00_IORequestIndex);
        return 1;
}

#ifdef MEDIA772_SU1E
void F1873_Pre_F1875_FreeHintGraphics_CPSX(
)
{
#include "FAKE4.C"
}
#endif

void F1875_FreeHintGraphics_CPSX(
)
{
        register HINT_GRAPHICS* L5534_ps_HintGraphics;


        L5534_ps_HintGraphics = G3677_ps_HintGraphics;
        F1857_PerformIORequestOperation(L5534_ps_HintGraphics->_i_0x00_IORequestIndex, C10_CLOSE_FILE);
        F1856_CloseFile(L5534_ps_HintGraphics->_i_0x00_IORequestIndex);
#ifdef MEDIA772_SU1E
        F1886_Memory(17, C20_FREE, L5534_ps_HintGraphics->_pl_0x04_GraphicOffsets);
#ifndef NOCOPYPROTECTION
        F1901_CopyProtectionRoutine_CPSX();
#endif
#endif
#ifdef MEDIA763_AU1E_AU2E
        F1886_Memory(-1, C20_FREE, L5534_ps_HintGraphics->_pl_0x04_GraphicOffsets);
#endif
}

#ifdef MEDIA772_SU1E
void F1876_Post_F1875_FreeHintGraphics_CPSX(
)
{
#include "FAKE4.C"
}
#endif

long F1878_LoadGraphic(unsigned char* P5671_puc_Graphic, int16_t P5672_i_GraphicIndex) {
        register HINT_GRAPHICS* L5535_ps_HintGraphic;
        register int16_t L5536_;
        register int16_t L5537_;
        long L5538_;
        long L5539_;


        L5535_ps_HintGraphic = G3677_ps_HintGraphics;
        F1859_SetIORequestValue(L5535_ps_HintGraphic->_i_0x00_IORequestIndex, 16, L5535_ps_HintGraphic->_pl_0x04_GraphicOffsets[P5672_i_GraphicIndex]);
        L5538_ = F1857_PerformIORequestOperation(L5535_ps_HintGraphic->_i_0x00_IORequestIndex, C09_SET_CURRENT_POSITION);
        if (L5538_) {
                L5539_ = 66;
        } else {
                F1859_SetIORequestValue(L5535_ps_HintGraphic->_i_0x00_IORequestIndex, 16, L5535_ps_HintGraphic->_pl_0x04_GraphicOffsets[P5672_i_GraphicIndex + 1] - L5535_ps_HintGraphic->_pl_0x04_GraphicOffsets[P5672_i_GraphicIndex]); /* Set size of graphic to read */
                F1859_SetIORequestValue(L5535_ps_HintGraphic->_i_0x00_IORequestIndex, 8, (long)P5671_puc_Graphic);
                L5538_ = F1857_PerformIORequestOperation(L5535_ps_HintGraphic->_i_0x00_IORequestIndex, C07_READ_FILE);
                if (L5538_) {
                        L5539_ = 67;
                } else {
                        L5539_ = 0;
                }
        }
        return L5539_;
}

long F1879_BlitBitmapFromGraphic(unsigned char* P5673_puc_Bitmap, int16_t P5674_i_GraphicIndex, int16_t P5675_i_X, int16_t P5676_i_Y) {
        unsigned char* L5540_;
        int16_t L5731_i_Unreferenced;
        long L5541_;


#ifdef MEDIA772_SU1E
        if (L5540_ = (unsigned char*)F1886_Memory(17, C14_ALLOCATE, G3677_ps_HintGraphics->_pl_0x04_GraphicOffsets[P5674_i_GraphicIndex + 1] - G3677_ps_HintGraphics->_pl_0x04_GraphicOffsets[P5674_i_GraphicIndex])) {
#endif
#ifdef MEDIA763_AU1E_AU2E
        if (L5540_ = (unsigned char*)F1886_Memory(-1, C14_ALLOCATE, G3677_ps_HintGraphics->_pl_0x04_GraphicOffsets[P5674_i_GraphicIndex + 1] - G3677_ps_HintGraphics->_pl_0x04_GraphicOffsets[P5674_i_GraphicIndex])) {
#endif
                if ((L5541_ = F1878_LoadGraphic(L5540_, P5674_i_GraphicIndex)) == 0) {
                        F0466_EXPAND_GraphicToBitmap(L5540_, P5673_puc_Bitmap, P5675_i_X, P5676_i_Y);
                }
#ifdef MEDIA772_SU1E
                F1886_Memory(17, C20_FREE, L5540_);
        } else {
                F1603_TerminateTOSProgram(2); /* Return code 2: Error in the parameters */
#endif
#ifdef MEDIA763_AU1E_AU2E
                F1886_Memory(-1, C20_FREE, L5540_);
#endif
        }
        return L5541_;
}

long F1880_LoadBitmapFromGraphic(unsigned char* P5677_puc_Bitmap, int16_t P5678_i_GraphicIndex) {
        return F1879_BlitBitmapFromGraphic(P5677_puc_Bitmap, P5678_i_GraphicIndex, 0, 0);
}

#ifdef MEDIA767_AU2E
unsigned int16_t F2026_GetGraphicByteCount(unsigned int16_t P5951_) {
        register HINT_GRAPHICS* L5899_;


        L5899_ = G3677_ps_HintGraphics;
        return L5899_->_pl_0x04_GraphicOffsets[P5951_ + 1] - L5899_->_pl_0x04_GraphicOffsets[P5951_];
}
#endif
#endif
