#ifndef COMPILE_H
#include "COMPILE.H"
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
#ifdef MEDIA699_X31J_AU2E_AU3E
UDSTRUCT6 G2265_KeyboardInputSpecialCharacters[22] = {
        { 0x0008, 0x0008 },
        { 0x000D, 0x000D },
        { 0x001B, 0x001B },
        { 0x012C, 0x520B },
        { 0x012E, 0x5209 },
        { 0x0130, 0x5208 },
        { 0x0132, 0x520A },
        { 0x6300, 0x5201 },
        { 0x6400, 0x5202 },
        { 0x6500, 0x5203 },
        { 0x6600, 0x5204 },
        { 0xFFFF, 0x520D },
        { 0xFFFF, 0x520E },
        { 0xFFFF, 0x520F },
        { 0xFFFF, 0x5210 },
        { 0xFFFF, 0x5205 },
        { 0xFFFF, 0x520C },
        { 0xFFFF, 0x5211 },
        { 0xFFFF, 0x5212 },
        { 0xFFFF, 0x5206 },
        { 0xFFFF, 0x5207 },
        { 0xFFFF, 0x0000 } };
#endif
#ifdef MEDIA671_F31E_F31J_P31J
UDSTRUCT6 G2265_KeyboardInputSpecialCharacters[19] = {
        { 0x003B0000, 0x5201 },
        { 0x003C0000, 0x5202 },
        { 0x003D0000, 0x5203 },
        { 0x003E0000, 0x5204 },
        { 0x00440000, 0x5205 },
        { 0x00470037, 0x520C },
        { 0x00480000, 0x520A },
        { 0x00480038, 0x520D },
        { 0x004B0000, 0x5208 },
        { 0x004B0034, 0x520E },
        { 0x004D0000, 0x5209 },
        { 0x004D0036, 0x520F },
        { 0x00500000, 0x520B },
        { 0x00500032, 0x5210 },
        { 0x00520030, 0x5211 },
        { 0x0053007F, 0x5212 },
        { 0x00610000, 0x5206 },
        { 0x00620000, 0x5207 },
        { 0x00FFFFFF, 0      } };
#endif


#ifdef MEDIA692_X31J
int F7327_GetCharacterFromKeyboard(
)
{
        asm {
                        moveq   #0,d0           /* B_KEYINP */
                        trap    #0xF            /* TRAP 15 (IOCS CALL) */
                        tst.b   d0
                        bne.s   @Tloc_20116
                        cmpi.w  #0x3B00,d0
                        bne.s   @Tloc_200F2
                        move.w  #0x130,d0
                        bra.s   @Tlocret_20134
                @Tloc_200F2:
                        cmpi.w  #0x3C00,d0
                        bne.s   @Tloc_200FE
                        move.w  #0x132,d0
                        bra.s   @Tlocret_20134
                @Tloc_200FE:
                        cmpi.w  #0x3D00,d0
                        bne.s   @Tloc_2010A
                        move.w  #0x12E,d0
                        bra.s   @Tlocret_20134
                @Tloc_2010A:
                        cmpi.w  #0x3E00,d0
                        bne.s   @Tlocret_20134
                        move.w  #0x12C,d0
                        bra.s   @Tlocret_20134
                @Tloc_20116:
                        moveq   #0,d1
                        cmpi.w  #0x3F00,d0
                        bcs.s   @Tloc_2012E
                        cmpi.w  #0x51FF,d0
                        bhi.s   @Tloc_2012E
                        cmpi.w  #0x4E0D,d0
                        beq.s   @Tloc_2012E
                        move.w  #0x100,d1
                @Tloc_2012E:
                        andi.w  #0xFF,d0
                        or.w    d1,d0
                @Tlocret_20134:
        }
}

char F7320_CallF0760_Cconis(
)
{
        asm {
                moveq   #1,d0           /* B_KEYSNS */
                trap    #0xF            /* TRAP 15 (IOCS CALL) */
                swap    d0
        }
}
#endif

#ifdef MEDIA768_AU2E_AU3E
char F2133_(
)
{
        char L6103_;
        USIODATA L6104_;


        if (F2113_GetFirstUsioDataInFilteredQueueOfSpecifiedTypeIndex_KeepInQueue(1, &L6104_)) {
                L6103_ = 1;
        } else {
                L6103_ = 0;
        }
        return L6103_;
}
#endif

#ifdef MEDIA699_X31J_AU2E_AU3E
void F1022_PrintCharacter(char P2765_c_Character)
{
        static char G3099_ac_String[2];


        G3099_ac_String[0] = P2765_c_Character;
#ifdef MEDIA692_X31J
        asm {
                pea     G3099_ac_String(a5)
                dc.w    0xFF09  /* DOS CALL PRINT */
                addq.l  #4,sp
        }
#endif
#ifdef MEDIA768_AU2E_AU3E
        PRIM_22_Console_PrintMessage(G3099_ac_String);
#endif
}

void F1023_PrintString(char* P2766_pc_String)
{
#ifdef MEDIA692_X31J
        asm {
                move.l  P2766_pc_String(a6),-(sp)
                dc.w    0xFF09  /* DOS CALL PRINT */
                addq.l  #4,sp
        }
#endif
#ifdef MEDIA768_AU2E_AU3E
        PRIM_22_Console_PrintMessage(P2766_pc_String);
#endif
}
#endif

#ifdef MEDIA768_AU2E_AU3E
int16_t F2136_GetAsciiCode(USIODATA* P6015_)
{
        register int16_t L6105_i_Unreferenced;
        register int16_t L6106_i_Unreferenced;
        register int16_t L6107_i_Unreferenced;
        int16_t L6108_i_AsciiCode;


        L6108_i_AsciiCode = P6015_->Data.UsioKeyboard.AsciiCode;
        return L6108_i_AsciiCode;
}

int16_t F2137_(
)
{
        int16_t L6109_;
        USIODATA L6110_;


        while (!F2113_GetFirstUsioDataInFilteredQueueOfSpecifiedTypeIndex_KeepInQueue(1, &L6110_));
        if (F2110_GetFirstUsioDataInFilteredQueueOfSpecifiedTypeIndex_RemoveFromQueue(1, &L6110_)) {
                L6109_ = F2136_GetAsciiCode(&L6110_);
        } else {
                L6109_ = 65;
        }
        return L6109_;
}
#endif

#ifdef MEDIA674_F31E_F31J_X31J_P31J
int16_t F7319_Crawcin(
)
{
#ifdef MEDIA692_X31J
        register unsigned int16_t L4114_;
#endif
#ifdef MEDIA667_P31J
        register unsigned long L4114_;
#endif
#ifdef MEDIA670_F31E_F31J
        int L4114_;
#endif
        REGISTER unsigned int16_t L4116_i_;
#ifdef MEDIA692_X31J
        register unsigned int16_t L4115_;
#endif
#ifdef MEDIA667_P31J
        register unsigned long L4115_;
#endif
#ifdef MEDIA670_F31E_F31J
        unsigned long L4115_;
#endif
        int16_t L4117_i_;


        L4114_ = F7327_GetCharacterFromKeyboard();
        L4116_i_ = 0;
        for (;;) { /*_Infinite loop_*/
                L4115_ = G2265_KeyboardInputSpecialCharacters[L4116_i_].l_0;
                if (L4115_ > L4114_) {
                        L4117_i_ = (long)L4114_ & 0xFF;
                        break;
                }
                if (L4115_ == L4114_) {
                        L4117_i_ = G2265_KeyboardInputSpecialCharacters[L4116_i_].i_4;
                        break;
                }
                L4116_i_++;
        };
        return L4117_i_;
}
#endif

#ifdef MEDIA671_F31E_F31J_P31J
char F7320_CallF0760_Cconis(
)
{
        F0539_INPUT_Cconis();
}

void F7321_Unreferenced(int16_t P3568_i_) {
}

void F7322_EmptyFunction(char* P3569_pc_) {
}
#endif

void F7323_WaitVerticalBlank(
)
{
#ifdef MEDIA699_X31J_AU2E_AU3E
        long L5912_;


        L5912_ = F2093_GetVerticalBlankCount();
        while (L5912_ == F2093_GetVerticalBlankCount());
#endif
#ifdef MEDIA671_F31E_F31J_P31J
        F0693_WaitVerticalBlank();
#endif
}

void F7324_EmptyFunction(
)
{
}

#ifdef MEDIA699_X31J_AU2E_AU3E
unsigned long F2093_GetVerticalBlankCount(
)
{
#ifdef MEDIA768_AU2E_AU3E
        static long G3919_l_VerticalBlankCount;


        WaitTOF();
        return G3919_l_VerticalBlankCount++;
#endif
#ifdef MEDIA692_X31J
        return G9002_VDEObase->_l_0x5A_VerticalBlankCount;
#endif
}
#endif
#endif
