#ifndef COMPILE_H
#include "COMPILE.H"
#endif
#ifdef MEDIA774_SU1E_AU1E_AU2E
extern long F1769_GetLastErrorCode();
extern void F1956_EndProgram();
extern void F7317_MAIN_CopyBytes_Alt();
extern long F1886_Memory();
extern void F1923_Pre_F1925_CPSX();
extern void F1926_Post_F1925_CPSX();
extern void F1893_ColorPalette();
extern void F1898_();
extern void F1905_();
extern void F1906_();
extern void F1372_SetVerticalBlankInterrupt();
#ifdef MEDIA772_SU1E
extern long F1931_();
#endif
extern void F1932_();
extern long F1937_Hints_CPSX();
extern unsigned int16_t F1944_ChecksumAdd();
extern void F1947_BlitBitmapToOrFromScreen();
extern long F1955_Input_CPSX();
extern long F1965_();
extern void F1966_DebugEnter();
extern void F1967_DebugExit();
extern void F0924_SetCriticalErrorHandler();
extern void F1897_FadeToPalette();
#ifdef MEDIA772_SU1E
extern long F1925_CPSX();
#endif


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

void F1889_Screen_CPSX(int16_t P5699_, int16_t P5700_) {
        HINT_PALETTE L5562_;
#ifdef MEDIA772_SU1E
        char L5745_ac_Unreferenced[18];
#endif
        STRUCT16B* L5563_;
#ifdef MEDIA772_SU1E
        long L5746_l_Unreferenced;
#endif
#ifdef MEDIA763_AU1E_AU2E
        long L5566_;
#endif
        int16_t L5564_;
        int16_t L5565_;
#ifdef MEDIA772_SU1E
        long L5566_;
#endif
#ifdef MEDIA763_AU1E_AU2E
        long L5876_;
        unsigned char* L5870_;
#endif


#ifdef MEDIA773_SU1E_AU1E
        F1966_DebugEnter(14, P5700_);
#endif
        switch (P5700_) {
                case 19:
                        break;
                case 1:
#ifdef MEDIA772_SU1E
                        G3611_puc_Bitmap_Oracle = NULL;
                        G3612_ = NULL;
#endif
                        G3613_puc_Bitmap_Font = NULL;
#ifdef MEDIA763_AU1E_AU2E
                        G3612_ = NULL;
                        G3611_puc_Bitmap_Oracle = NULL;
#endif
                        G3601_l_VerticalBlankCount = 0;
#ifdef MEDIA772_SU1E
                        F1372_SetVerticalBlankInterrupt(1);
                        F0924_SetCriticalErrorHandler();
                        F1886_Memory(14, C01_INITIALIZE);
                        F1768_();
                        F1853_(10);
                        if (F1769_GetLastErrorCode()) {
                                F1956_EndProgram(14, 18, 96L);
                        }
                        for (L5565_ = 0; L5565_ < 3; L5565_++) {
                                if (F1931_(P5699_, 12, G3637_apc_FileNames[C3_HCSB_DAT], 0L) == 1) {
                                        break;
                                }
                        }
                        if (L5565_ >= 3) {
                                F1956_EndProgram(P5699_, 18, 12L);
                        }
                        if (L5566_ = F1872_LoadGraphics(G3637_apc_FileNames[C3_HCSB_DAT], &G3615_s_HintGraphics, NULL)) {
                                F1956_EndProgram(P5699_, 18, L5566_);
                        }
                        F1985_CPSX();
                        if (L5566_ = F1878_LoadGraphic(G3609_aui_GraphicIntegers, C0_HINT_GRAPHIC_INTEGERS)) {
                                F1956_EndProgram(P5699_, 18, L5566_);
                        }
                        G3611_puc_Bitmap_Oracle = (unsigned char*)F1886_Memory(P5699_, C14_ALLOCATE, 32768L);
                        if (L5566_ = F1880_LoadBitmapFromGraphic(G3611_puc_Bitmap_Oracle, C1_HINT_GRAPHIC_ORACLE)) {
                                F1956_EndProgram(P5699_, 18, L5566_);
                        }
                        F1893_ColorPalette(P5699_, C01_INITIALIZE);
                        G3613_puc_Bitmap_Font = (unsigned char*)F1886_Memory(14, C16_ALLOCATE_AND_INITIALIZE, (long)M075_BITMAP_BYTE_COUNT(C256_HINT_FONT_WIDTH, M739_HINT_FONT_HEIGHT));
                        if (L5566_ = F1880_LoadBitmapFromGraphic(G3613_puc_Bitmap_Font, C2_HINT_GRAPHIC_FONT)) {
                                F1956_EndProgram(P5699_, 18, L5566_);
                        }
                        F1884_Text(P5699_, C26_SET_FONT_COLOR, (long)G3609_aui_GraphicIntegers[5], (long)G3609_aui_GraphicIntegers[4]);
                        L5562_._i_0x00 = 13;
                        L5562_._pui_0x02_SourcePalette = NULL;
                        L5562_._pui_0x06_TargetPalette = G3617_aui_Palette;
                        L5562_._i_0x0A = 273;
                        L5562_._i_0x0C = 2;
                        L5562_._i_0x0E = 7;
                        F1893_ColorPalette(14, C34_FADE_TO_PALETTE, &L5562_);
                        F1525_OpenVDIWorkstation(0);
                        G3618_apuc_Screens[0] = Logbase();
                        G3612_ = G3618_apuc_Screens[1] = (unsigned char*)F1886_Memory(6, C14_ALLOCATE, 33024L);
                        G3620_i_ScreenIndex = 1;
                        if (G3618_apuc_Screens[G3620_i_ScreenIndex]) {
                                G3618_apuc_Screens[G3620_i_ScreenIndex] = G3618_apuc_Screens[G3620_i_ScreenIndex] + ((256 - (long)G3618_apuc_Screens[G3620_i_ScreenIndex]) & 0xFF);
                        }
                        G0348_Bitmap_Screen = G3618_apuc_Screens[G3620_i_ScreenIndex];
                        F1947_BlitBitmapToOrFromScreen(G3621_ai_XYZ_Screen, G3611_puc_Bitmap_Oracle, C1_BITMAP_TO_SCREEN);
                        F1531_MouseHandler(1, G3404_VDIHandle);
                        F1530_ShowMousePointerAsArrow(G3404_VDIHandle, 0);
                        F1889_Screen_CPSX(P5699_, 35);
                        G3622_++;
                        L5562_._pui_0x06_TargetPalette = G3603_aui_Palette_HintOracle;
                        F1893_ColorPalette(14, C34_FADE_TO_PALETTE, &L5562_);
                        F1875_FreeHintGraphics_CPSX();
                        F1932_(G3588_ps_DiskErrorPleaseTryAgain);
                        F1905_();
                        F0008_MAIN_ClearBytes(G3623_Game, (long)sizeof(G3623_Game));
#endif
#ifdef MEDIA763_AU1E_AU2E
                        G3624_ = C1_TRUE;
                        F2022_F1889_SubForInit();
#endif
                        break;
                case 2:
                        F1932_(G3589_ps_DiskErrorPleaseTryAgain);
                        F1931_(P5699_, 12, G3637_apc_FileNames[C3_HCSB_DAT], G3583_ps_PleaseInsertCSBUtilityDisk);
#ifdef MEDIA772_SU1E
                        F0077_MOUSE_EnableScreenUpdate_CPSE();
                        if ((G3620_i_ScreenIndex ? 0 : 1) != C0_FALSE) {
                                F7317_MAIN_CopyBytes_Alt(G3618_apuc_Screens[G3620_i_ScreenIndex ? 0 : 1], G3618_apuc_Screens[G3620_i_ScreenIndex], MASK0x0008_MEMREQ, MASK0x0008_MEMREQ, 32768L);
#endif
#ifdef MEDIA763_AU1E_AU2E
                        F1527_MOUSE_EnableScreenUpdate_CPSE();
                        if (G3620_i_ScreenIndex != 1) {
                                L5870_ = F2015_();
                                F7317_MAIN_CopyBytes_Alt(L5870_, F2016_(), MASK0x0008_MEMREQ, MASK0x0008_MEMREQ, G3852_);
#endif
                                F1889_Screen_CPSX(14, 35);
                        }
                        F1937_Hints_CPSX(P5699_, C02_UNINITIALIZE);
                        F1955_Input_CPSX(P5699_, 30);
                        F1854_();
                        F1906_();
                        F1925_CPSX(P5699_, C02_UNLOAD_GAME);
                        F1940_CPSX(P5699_, C02_UNINITIALIZE);
                        F1893_ColorPalette(P5699_, C02_UNINITIALIZE);
#ifdef MEDIA772_SU1E
                        if (G3612_) {
                                F1886_Memory(P5699_, C20_FREE, G3612_);
                        }
                        if (G3611_puc_Bitmap_Oracle) {
                                F1886_Memory(P5699_, C20_FREE, G3611_puc_Bitmap_Oracle);
                        }
                        if (G3613_puc_Bitmap_Font) {
                                F1886_Memory(P5699_, C20_FREE, G3613_puc_Bitmap_Font);
                        }
                        F1886_Memory(14, C02_UNINITIALIZE);
                        F1531_MouseHandler(2, 0);
                        F1372_SetVerticalBlankInterrupt(2);
                        F1526_CloseWorkstationAndExitApplication();
#endif
#ifdef MEDIA763_AU1E_AU2E
                        F2023_F1889_SubForUninit();
#endif
                        break;
                case 30:
#ifdef MEDIA772_SU1E
                        while (!G3506_);
                        while (G3506_);
#endif
                        break;
                case 35:
#ifdef MEDIA763_AU1E_AU2E
                        F2017_(G3620_i_ScreenIndex);
#endif
                        G3620_i_ScreenIndex = G3620_i_ScreenIndex ? 0 : 1;
#ifdef MEDIA772_SU1E
                        F0077_MOUSE_EnableScreenUpdate_CPSE();
                        Setscreen(G3618_apuc_Screens[G3620_i_ScreenIndex ? 0 : 1], G3618_apuc_Screens[G3620_i_ScreenIndex ? 0 : 1], -1);
                        F0078_MOUSE_DisableScreenUpdate();
#endif
                        if (G3624_) {
                                G3624_ = C0_FALSE;
#ifdef MEDIA772_SU1E
                                G0348_Bitmap_Screen = Physbase();
#endif
#ifdef MEDIA763_AU1E_AU2E
                                F2018_();
#endif
                        }
#ifdef MEDIA772_SU1E
                        L5565_ = F1934_Checksum_CPSX(*((char**)((char*)F1923_Pre_F1925_CPSX + 2)), *((char**)((char*)F1926_Post_F1925_CPSX + 2)));
                        asm {
                                @Tloc_56D2:
                                        move.w  P5700_(a6),d0
                                        move.w  #0x6F,d1 ; 'o'
                                        bra.s   @Tloc_56E2
                                        asl.w   #1,d0
                                        add.w   d0,d1
                                        bra.s   @Tloc_56E4
                                @Tloc_56E2:
                                        moveq   #0,d0
                                @Tloc_56E4:
                                        cmp.w   d0,d1
                                        bcc.s   @Tloc_56F0
                                        move.w  -2(a6),d1
                                        add.w   d0,d1
                                        asl.w   #1,d1
                                @Tloc_56F0:
                                        lea     @Tloc_56D2,a0
                                        move.w  L5565_(a6),d0
                                        cmp.w   6(a0),d0
                                        beq.s   @Tloc_5706
                                        move.w  #1,L5565_(a6)
                                        bra.s   @Tloc_570C
                                @Tloc_5706:
                                        move.w  #0,L5565_(a6)
                                @Tloc_570C:
                        }
                        if (L5565_) {
                                F1956_EndProgram(14, 18, 501L);
                        }
                        G0348_Bitmap_Screen = G3618_apuc_Screens[G3620_i_ScreenIndex];
#endif
#ifdef MEDIA763_AU1E_AU2E
                        G0348_Bitmap_Screen = F2016_();
#endif
                        F1947_BlitBitmapToOrFromScreen(G3621_ai_XYZ_Screen, G3611_puc_Bitmap_Oracle, C1_BITMAP_TO_SCREEN);
                        break;
                case 36:
#ifdef MEDIA772_SU1E
                        G0348_Bitmap_Screen = G3618_apuc_Screens[G3620_i_ScreenIndex ? 0 : 1];
#endif
#ifdef MEDIA763_AU1E_AU2E
                        G0348_Bitmap_Screen = F2015_();
#endif
                        break;
                case 37:
#ifdef MEDIA772_SU1E
                        G0348_Bitmap_Screen = G3618_apuc_Screens[G3620_i_ScreenIndex];
#endif
#ifdef MEDIA763_AU1E_AU2E
                        G0348_Bitmap_Screen = F2016_();
#endif
                        break;
                case 31:
                        F1884_Text(P5699_, C26_SET_FONT_COLOR, (long)G3609_aui_GraphicIntegers[2]);
                        F1955_Input_CPSX(P5699_, 6, 0L);
                        L5562_._i_0x00 = 13;
                        L5562_._pui_0x02_SourcePalette = NULL;
                        L5562_._pui_0x06_TargetPalette = G3603_aui_Palette_HintOracle;
                        F1893_ColorPalette(14, C09_COPY_PALETTE, &L5562_);
                        G3603_aui_Palette_HintOracle[G3609_aui_GraphicIntegers[0]] = G3609_aui_GraphicIntegers[1];
#ifdef MEDIA772_SU1E
                        L5562_._i_0x0A = 273;
                        L5562_._i_0x0C = G3609_aui_GraphicIntegers[12];
                        L5562_._i_0x0E = G3609_aui_GraphicIntegers[13];
#endif
                        F1893_ColorPalette(P5699_, C34_FADE_TO_PALETTE, &L5562_);
#ifdef MEDIA772_SU1E
                        L5562_._i_0x0C = G3609_aui_GraphicIntegers[10];
                        L5562_._i_0x0E = G3609_aui_GraphicIntegers[11];
                        F1893_ColorPalette(P5699_, C34_FADE_TO_PALETTE, &L5562_);
                        F0357_COMMAND_DiscardAllInput();
#endif
                        F1889_Screen_CPSX(P5699_, 35);
#ifdef MEDIA772_SU1E
                        G3631_ = G3601_l_VerticalBlankCount;
#endif
#ifdef MEDIA763_AU1E_AU2E
                        F0357_COMMAND_DiscardAllInput();
                        L5876_ = G3601_l_VerticalBlankCount;
#endif
                        F1884_Text(P5699_, C26_SET_FONT_COLOR, (long)G3609_aui_GraphicIntegers[2]);
                        F1955_Input_CPSX(P5699_, 6, 0L);
                        F1884_Text(P5699_, C26_SET_FONT_COLOR, (long)G3609_aui_GraphicIntegers[0]);
                        L5564_ = F1965_(9, 13);
                        for (L5565_ = L5564_; L5565_ > 0; L5565_--) {
                                L5563_ = (STRUCT16B*)F1965_(9, 12, (long)L5565_);
                                if ((L5563_->_i_0x00 == 8) && (L5563_->_ps_0x08->_i_0x00 == 3)) {
                                        F1884_Text(9, C06_PRINT, L5563_->_ps_0x08);
                                        if (L5563_->_l_0x0C == 8) {
                                                F1898_(&L5563_->_ps_0x08->_ai_XYZ_0x06, 1, G3609_aui_GraphicIntegers[6], -1);
                                        }
                                        if (L5563_->_l_0x04 == 20) {
                                                F1884_Text(9, C20_FREE, L5563_->_ps_0x08);
                                        }
                                        F1965_(9, 29, (long)L5565_);
                                }
                        }
                        G3603_aui_Palette_HintOracle[G3609_aui_GraphicIntegers[0]] = G3609_aui_GraphicIntegers[3];
#ifdef MEDIA772_SU1E
                        while (G3601_l_VerticalBlankCount < G3609_aui_GraphicIntegers[9] + G3631_);
#endif
#ifdef MEDIA763_AU1E_AU2E
                        while (G3601_l_VerticalBlankCount < G3609_aui_GraphicIntegers[9] + L5876_);
#endif
                        F1889_Screen_CPSX(P5699_, 35);
#ifdef MEDIA772_SU1E
                        L5562_._i_0x0C = G3609_aui_GraphicIntegers[10];
                        L5562_._i_0x0E = G3609_aui_GraphicIntegers[11];
                        F1893_ColorPalette(P5699_, C34_FADE_TO_PALETTE, &L5562_);
                        L5562_._i_0x0C = G3609_aui_GraphicIntegers[12];
                        L5562_._i_0x0E = G3609_aui_GraphicIntegers[13];
#endif
                        F1893_ColorPalette(P5699_, C34_FADE_TO_PALETTE, &L5562_);
                        F1884_Text(P5699_, C26_SET_FONT_COLOR, (long)G3609_aui_GraphicIntegers[4]);
                        break;
                default:
                        F1956_EndProgram(P5699_, 18, 15L);
        }
#ifdef MEDIA773_SU1E_AU1E
        F1967_DebugExit(14, P5700_);
#endif
}

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

void F1892_(int16_t P5703_, int16_t P5704_, long P5705_) {
        int16_t L5567_;


#ifdef MEDIA773_SU1E_AU1E
        F1966_DebugEnter(11, P5704_);
#endif
        switch (P5704_) {
                case 5:
#ifdef MEDIA772_SU1E
                        L5567_ = F1944_ChecksumAdd(*((char**)((char*)F1887_Pre_F1889_Screen_CPSX + 2)), *((char**)((char*)F1890_Post_F1889_Screen_CPSX + 2)));
                        asm {
                                @Tloc_5A52:
                                        move.w  P5704_(a6),d0
                                        move.w  #0x7AE1,d1
                                        bra.s   @Tloc_5A62
                                        asl.w   #1,d0
                                        add.w   d0,d1
                                        bra.s   @Tloc_5A64
                                @Tloc_5A62:
                                        moveq   #0,d0
                                @Tloc_5A64:
                                        cmp.w   d0,d1
                                        bcc.s   @Tloc_5A70
                                        move.w  L5567_(a6),d1
                                        add.w   d0,d1
                                        asl.w   #1,d1
                                @Tloc_5A70:
                                        lea     @Tloc_5A52,a0
                                        move.w  L5567_(a6),d0
                                        cmp.w   6(a0),d0
                                        beq.s   @Tloc_5A86
                                        move.w  #1,L5567_(a6)
                                        bra.s   @Tloc_5A8C
                                @Tloc_5A86:
                                        move.w  #0,L5567_(a6)
                                @Tloc_5A8C:
                        }
                        if (L5567_) {
                                F1956_EndProgram(P5703_, 18, 506L);
                        }
#endif
                        L5567_ = P5705_;
                        while (L5567_--) {
#ifdef MEDIA772_SU1E
                                M526_WaitVerticalBlank();
#endif
#ifdef MEDIA763_AU1E_AU2E
                                F7323_WaitVerticalBlank();
#endif
                        }
                        break;
                default:
                        F1956_EndProgram(P5703_, 18, 14L);
        }
#ifdef MEDIA773_SU1E_AU1E
        F1967_DebugExit(11, P5704_);
#endif
}
#endif
