#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 F1942_Pre_F1944_ChecksumAdd_main();
extern void F1945_Pre_F1944_ChecksumAdd_main();
#endif

#ifdef MEDIA763_AU1E_AU2E
extern char F2024_IsLeftMouseButtonDown();


unsigned int16_t G3608_;
MOUSE2_INPUT G3594_as_MouseInput[12];
KEY2BOARD_INPUT G3595_as_KeyboardInput[12];
INPUT_INFO G3596_s_InputInfo = { 10, 0, G3594_as_MouseInput, G3595_as_KeyboardInput, NULL };
int16_t G3592_i_MouseInputCount;
int16_t G3593_i_KeyboardInputCount;
int16_t G3597_i_InputInfoIndex;
char G3725_ac_Unreferenced[10];
UD_COMMAND G3604_s_UDCommand;
#endif


long F1955_Input_CPSX(int16_t P5816_, int16_t P5817_, ...) {
        register HINT_BUTTON* L5691_;
        register MOUSE2_INPUT* L5692_;
        register int16_t L5693_;
        register int16_t L5694_;
        long L5695_;
        long L5696_;
        char* L5697_;
        STRUCT22B* L5698_;
#ifdef MEDIA763_AU1E_AU2E
        long L5871_;
#endif
        KEY2BOARD_INPUT* L5699_;
        HINT_PALETTE L5701_;
        int16_t* L5702_;


#ifdef MEDIA773_SU1E_AU1E
        F1966_DebugEnter(5, P5817_);
#endif
        switch (P5817_) {
                case C01_INITIALIZE:
                        G3592_i_MouseInputCount = 0;
                        G3593_i_KeyboardInputCount = 0;
                        F0008_MAIN_ClearBytes(G3594_as_MouseInput, (long)sizeof(G3594_as_MouseInput));
                        F0008_MAIN_ClearBytes(G3595_as_KeyboardInput, (long)sizeof(G3595_as_KeyboardInput));
                        G3597_i_InputInfoIndex = F7012_AddToInputInfoList(&G3596_s_InputInfo);
                        if (G3597_i_InputInfoIndex == -1) {
                                F1956_EndProgram(P5816_, 18, 37L);
                        }
                        break;
                case 30:
                        break;
                case C12_INPUT_INFO_FROM_COMMAND:
                        L5695_ = -1;
                        switch (*(int16_t*)(&P5817_ + 4)) {
                                default:
                                        break;
                                case C0L_GET_BUTTON_INDEX:
                                        for (L5693_ = 0; L5693_ < 20; L5693_++) {
#ifdef MEDIA772_SU1E
                                                if (G3598_as_HintButtons[L5693_].Command == *(char*)((char*)&P5817_ + 5)) {
#endif
#ifdef MEDIA763_AU1E_AU2E
                                                if (G3598_as_HintButtons[L5693_].Command == *(unsigned char*)((char*)&P5817_ + 5)) {
#endif
                                                        L5695_ = L5693_;
                                                        break;
                                                }
                                        }
                                        break;
                                case C1L_GET_MOUSE_INPUT_INDEX:
                                        for (L5693_ = 0; L5693_ < G3592_i_MouseInputCount; L5693_++) {
                                                if (G3594_as_MouseInput[L5693_].Command == *(char*)((char*)&P5817_ + 5)) {
                                                        L5695_ = L5693_;
                                                        break;
                                                }
                                        }
                                        break;
                                case C2L_GET_KEYBOARD_INPUT_INDEX:
                                        for (L5693_ = 0; L5693_ < G3593_i_KeyboardInputCount; L5693_++) {
                                                if (G3595_as_KeyboardInput[L5693_].Command == *(char*)((char*)&P5817_ + 5)) {
                                                        L5695_ = L5693_;
                                                        break;
                                                }
                                        }
                                        break;
                                case C3L_GET_HINT_BUTTON_BOX:
                                        for (L5693_ = 0; L5693_ < 20; L5693_++) {
#ifdef MEDIA772_SU1E
                                                if (G3598_as_HintButtons[L5693_].Command == *((char*)((char*)&P5817_ + 5))) {
#endif
#ifdef MEDIA763_AU1E_AU2E
                                                if (G3598_as_HintButtons[L5693_].Command == *((unsigned char*)((char*)&P5817_ + 5))) {
#endif
                                                        L5695_ = (long)G3598_as_HintButtons[L5693_]._ai_XYZ_0x04;
                                                        break;
                                                }
                                        }
                                        break;
                                case C4L_GET_HINT_BUTTON_STRING:
                                        for (L5693_ = 0; L5693_ < 20; L5693_++) {
#ifdef MEDIA772_SU1E
                                                if (G3598_as_HintButtons[L5693_].Command == *((char*)((char*)&P5817_ + 5))) {
#endif
#ifdef MEDIA763_AU1E_AU2E
                                                if (G3598_as_HintButtons[L5693_].Command == *((unsigned char*)((char*)&P5817_ + 5))) {
#endif
                                                        L5695_ = (long)G3598_as_HintButtons[L5693_]._pc_0x0E_String;
                                                        break;
                                                }
                                        }
                                        break;
                                case C5L_SET_HINT_BUTTON_STRING:
                                        for (L5693_ = 0; L5693_ < 20; L5693_++) {
#ifdef MEDIA772_SU1E
                                                if (G3598_as_HintButtons[L5693_].Command == *(char*)((char*)&P5817_ + 5)) {
#endif
#ifdef MEDIA763_AU1E_AU2E
                                                if (G3598_as_HintButtons[L5693_].Command == *(unsigned char*)((char*)&P5817_ + 5)) {
#endif
                                                        G3598_as_HintButtons[L5693_]._pc_0x0E_String = *(char**)(&P5817_ + 5);
                                                        break;
                                                }
                                        }
                                        break;
                                case C6L_GET_HINT_BUTTON__i_0x12:
                                        for (L5693_ = 0; L5693_ < 20; L5693_++) {
#ifdef MEDIA772_SU1E
                                                if (G3598_as_HintButtons[L5693_].Command == *(char*)((char*)&P5817_ + 5)) {
#endif
#ifdef MEDIA763_AU1E_AU2E
                                                if (G3598_as_HintButtons[L5693_].Command == *(unsigned char*)((char*)&P5817_ + 5)) {
#endif
                                                        L5695_ = G3598_as_HintButtons[L5693_]._i_0x12;
                                                        break;
                                                }
                                        }
                                        break;
                        }
                        break;
                case 8:
                        L5695_ = *((long*)(&P5817_ + 1));
                        if (L5695_) {
                                L5696_ = F1955_Input_CPSX(P5816_, C12_INPUT_INFO_FROM_COMMAND, L5695_, C3L_GET_HINT_BUTTON_BOX);
                                L5697_ = (char*)F1955_Input_CPSX(P5816_, C12_INPUT_INFO_FROM_COMMAND, L5695_, C4L_GET_HINT_BUTTON_STRING);
                                if (L5697_ == NULL) {
                                        F1956_EndProgram(P5816_, 18, 68L);
                                }
                                L5698_ = F1884_Text(P5816_, C16_ALLOCATE_AND_INITIALIZE, 0L);
                                L5702_ = (int16_t*)L5696_;
                                L5698_->_ai_XYZ_0x06[0] = L5702_[0];
                                L5698_->_ai_XYZ_0x06[1] = L5702_[1];
                                L5698_->_ai_XYZ_0x06[2] = L5702_[2];
                                L5698_->_ai_XYZ_0x06[3] = L5702_[3];
                                L5698_->_pc_0x02_String = L5697_;
#ifdef MEDIA772_SU1E
                                F0077_MOUSE_EnableScreenUpdate_CPSE();
#endif
#ifdef MEDIA763_AU1E_AU2E
                                F1527_MOUSE_EnableScreenUpdate_CPSE();
#endif
                                F1889_Screen_CPSX(P5816_, 36);
                                F1884_Text(P5816_, C26_SET_FONT_COLOR, (long)G3609_aui_GraphicIntegers[7]);
                                F1884_Text(P5816_, C06_PRINT, L5698_);
#ifdef MEDIA772_SU1E
#ifndef NOCOPYPROTECTION
                                L5693_ = F1908_Checksum_CPSX(*((char**)((char*)F1899_Pre_F1901_CopyProtectionRoutine_CPSX + 2)), *((char**)((char*)F1902_Post_F1901_CopyProtectionRoutine_CPSX + 2)));
                                asm {
                                                lea     @Tloc_8F8C,a1
                                                move.w  d7,d1
                                                cmp.w   6(a1),d1
                                                beq.s   @Tloc_8F88
                                                move.w  #1,d7
                                                bra.s   @Tloc_8F8C
                                        @Tloc_8F88:
                                                move.w  #0,d7

                                        @Tloc_8F8C:
                                                tst.w   d0
                                                bne.s   @Tloc_8F96
                                                move.w  #0xD879,d0
                                                bra.s   @Tloc_8F9C
                                        @Tloc_8F96:
                                                move.w  #0x13F,d0
                                                bra.s   @Tloc_8F9E
                                        @Tloc_8F9C:
                                                moveq   #0,d0
                                        @Tloc_8F9E:
                                                move.w  #0x96,d1
                                                cmp.w   d0,d1
                                                bcc.s   @Tloc_8FAA
                                                move.w  d0,d1
                                                asl.w   #1,d1
                                        @Tloc_8FAA:
                                }
                                if (L5693_ + 23 != 23) {
                                        F1956_EndProgram(P5816_, 18, 505L);
                                }
#endif
#endif
                                F1892_(P5816_, 5, 20L);
                                L5696_ = F1955_Input_CPSX(P5816_, C12_INPUT_INFO_FROM_COMMAND, L5695_, C6L_GET_HINT_BUTTON__i_0x12);
                                F1884_Text(P5816_, C26_SET_FONT_COLOR, L5696_);
                                F1884_Text(P5816_, C06_PRINT, L5698_);
                                F1889_Screen_CPSX(P5816_, 37);
#ifdef MEDIA772_SU1E
                                F0078_MOUSE_DisableScreenUpdate();
                                F1886_Memory(P5816_, C20_FREE, L5698_);
#endif
#ifdef MEDIA763_AU1E_AU2E
                                F1528_MOUSE_DisableScreenUpdate();
                                F1886_Memory(-1, C20_FREE, L5698_);
#endif
                                if (L5696_ != G3609_aui_GraphicIntegers[4]) {
                                        F1884_Text(P5816_, C26_SET_FONT_COLOR, (long)G3609_aui_GraphicIntegers[4]);
                                }
                                F1955_Input_CPSX(P5816_, C02_UNINITIALIZE);
                        }
                        break;
                case 6:
                        if (*((long*)(&P5817_ + 1))) {
                                L5692_ = &G3594_as_MouseInput[(unsigned int16_t)F1955_Input_CPSX(P5816_, C12_INPUT_INFO_FROM_COMMAND, *((long*)(&P5817_ + 1)), C1L_GET_MOUSE_INPUT_INDEX)];
                                L5691_ = &G3598_as_HintButtons[(unsigned int16_t)F1955_Input_CPSX(P5816_, C12_INPUT_INFO_FROM_COMMAND, *((long*)(&P5817_ + 1)), C0L_GET_BUTTON_INDEX)];
                                F1949_(P5816_, L5691_, L5692_);
                        } else {
                                L5692_ = G3594_as_MouseInput;
                                L5693_ = 0;
                                while (L5693_ < G3592_i_MouseInputCount) {
                                        L5691_ = &G3598_as_HintButtons[(unsigned int16_t)F1955_Input_CPSX(P5816_, C12_INPUT_INFO_FROM_COMMAND, (long)L5692_->Command, C0L_GET_BUTTON_INDEX)];
                                        F1949_(P5816_, L5691_, L5692_);
                                        L5693_++;
                                        L5692_++;
                                }
                        }
                        break;
                case C02_UNINITIALIZE:
                        G3592_i_MouseInputCount = 0;
                        G3593_i_KeyboardInputCount = 0;
                        F0008_MAIN_ClearBytes(G3594_as_MouseInput, (long)sizeof(G3594_as_MouseInput));
                        F0008_MAIN_ClearBytes(G3595_as_KeyboardInput, (long)sizeof(G3595_as_KeyboardInput));
                        break;
                case 3:
                        L5693_ = F1955_Input_CPSX(P5816_, C12_INPUT_INFO_FROM_COMMAND, *((long*)(&P5817_ + 1)), C0L_GET_BUTTON_INDEX);
                        if (L5693_ >= 0) {
                                L5691_ = &G3598_as_HintButtons[L5693_];
                                if (L5691_->_ai_XYZ_0x04[0] && L5691_->_ai_XYZ_0x04[1]) {
                                        L5692_ = &G3594_as_MouseInput[G3592_i_MouseInputCount++];
                                        L5692_->Command = L5691_->Command;
                                        F7317_MAIN_CopyBytes_Alt(L5691_->_ai_XYZ_0x04, L5692_->Box, MASK0x0400_MEMREQ, MASK0x0400_MEMREQ, (long)sizeof(L5691_->_ai_XYZ_0x04));
                                        L5692_->Flags = L5691_->Flags;
                                        L5692_->Button = 1;
                                        if (*((long*)(&P5817_ + 3))) {
                                                L5691_->_pc_0x0E_String = *((char**)(&P5817_ + 3));
                                        }
                                }
                                if (L5691_->_i_0x0C_KeyboardCode) {
                                        L5699_ = &G3595_as_KeyboardInput[G3593_i_KeyboardInputCount++];
                                        L5699_->Command = L5691_->Command;
                                        L5699_->Flags = L5691_->Flags;
                                        L5699_->Code = L5691_->_i_0x0C_KeyboardCode;
                                }
                        }
                        break;
                case 5:
#ifdef MEDIA772_SU1E
                        G3602_ = G3601_l_VerticalBlankCount;
#endif
#ifdef MEDIA763_AU1E_AU2E
                        L5871_ = G3601_l_VerticalBlankCount;
#endif
                        L5701_._i_0x00 = 13;
                        L5701_._pui_0x06_TargetPalette = G3603_aui_Palette_HintOracle;
                        if (G3592_i_MouseInputCount == 0) {
#ifdef MEDIA772_SU1E
                                while (!G3506_);
#endif
#ifdef MEDIA763_AU1E_AU2E
                                while (!F2024_IsLeftMouseButtonDown());
#endif
                                L5695_ = 0;
                        } else {
                                loc_9234:
                                L5694_ = F7015_ProcessNextUDCommand(&G3604_s_UDCommand) & 0xFF;
                                if (L5694_) {
                                        switch (*((int16_t*)(&P5817_ + 2))) {
                                                case 2:
                                                        G3603_aui_Palette_HintOracle[G3609_aui_GraphicIntegers[8]] = G3609_aui_GraphicIntegers[36];
                                                        F1893_ColorPalette(P5816_, C38_SET_PALETTE, &L5701_);
                                        }
                                } else {
                                        switch (*((int16_t*)(&P5817_ + 2))) {
                                                case 2:
#ifdef MEDIA772_SU1E
                                                        if (G3601_l_VerticalBlankCount > G3602_ + G3609_aui_GraphicIntegers[33]) {
                                                                G3602_ = G3601_l_VerticalBlankCount;
#endif
#ifdef MEDIA763_AU1E_AU2E
                                                        if (G3601_l_VerticalBlankCount > L5871_ + G3609_aui_GraphicIntegers[33]) {
                                                                L5871_ = G3601_l_VerticalBlankCount;
#endif
                                                                G3603_aui_Palette_HintOracle[G3609_aui_GraphicIntegers[8]] = G3609_aui_GraphicIntegers[(int16_t)G3608_ + 36];
                                                                G3608_ = (G3608_ + 1) % G3609_aui_GraphicIntegers[32];
                                                                F1893_ColorPalette(P5816_, C38_SET_PALETTE, &L5701_);
#ifdef MEDIA772_SU1E
                                                        } else {
                                                                L5693_ = F1944_ChecksumAdd(*((char**)((char*)F1942_Pre_F1944_ChecksumAdd_main + 2)), *((char**)((char*)F1945_Pre_F1944_ChecksumAdd_main + 2)));
                                                                asm {
                                                                                movem.l d4/a3,-(sp)
                                                                                lea     @Tloc_9324,a3
                                                                                move.w  d7,d4
                                                                                cmp.w   6(a3),d4
                                                                                beq.s   @Tloc_9342
                                                                                move.w  #1,d7
                                                                                bra.s   @Tloc_9346
                                                                        @Tloc_9324:
                                                                                move.w  L5695_(a6),d1
                                                                                cmpi.w  #0xE1C,d1
                                                                                bcc.s   @Tloc_9332
                                                                                moveq   #1,d0
                                                                                bra.s   @Tloc_9334
                                                                        @Tloc_9332:
                                                                                moveq   #0,d0
                                                                        @Tloc_9334:
                                                                                move.w  L5697_+2(a6),d1
                                                                                cmp.w   d0,d1
                                                                                bcc.s   @Tloc_9340
                                                                                moveq   #1,d0
                                                                                bra.s   @Tloc_9342
                                                                        @Tloc_9340:
                                                                                moveq   #0,d0
                                                                        @Tloc_9342:
                                                                                move.w  #0,d7
                                                                        @Tloc_9346:
                                                                                movem.l (sp)+,d4/a3
                                                                }
                                                                if (L5693_ + 5 != 5) {
                                                                        F1956_EndProgram(P5816_, 18, 504L);
                                                                }
#endif
                                                        }
                                                default:
                                                        goto loc_9234;
                                        }
                                }
                                L5695_ = L5694_;
                        }
                        break;
                default:
                        F1956_EndProgram(P5816_, 18, 40L);
                        break;
        }
#ifdef MEDIA773_SU1E_AU1E
        F1967_DebugExit(5, P5817_);
#endif
        return L5695_;
}
#endif
