#ifndef COMPILE_H
#include "COMPILE.H"
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
int16_t F0540_INPUT_Crawcin(
void
)
{
#ifdef MEDIA488_F20E_F20J
        return F2253_KEYREAD();
#endif
#ifdef MEDIA670_F31E_F31J
        int16_t L6501_;


        L6501_ = F2253_KEYREAD();
        if (L6501_ == 0x44D) { /* Ignore SHIFT */
                return 0x4D;
        } else {
                if (L6501_ == 0x450) { /* Ignore SHIFT */
                        return 0x50;
                } else {
                        return L6501_;
                }
        }
#endif
#ifdef MEDIA463_P20JA_P20JB_I34E_I34M_P31J
        unsigned int16_t L2944_ui_;


#ifdef MEDIA457_P20JA
        if ((L2944_ui_ = (*(G2162_IODriver->IODRV_00_GetKeyboardInput))()) == 0x0C53) { /*  CTRL-ALT-DEL 0x80 = ALT, 0x40 = CTRL, 0x53 = Scancode of 'DEL' */
                F0444_STARTEND_Endgame(C0_FALSE);
        } else {
#endif
#ifdef MEDIA480_P20JB_I34E_I34M_P31J
        L2944_ui_ = (*(G2162_IODriver->IODRV_00_GetKeyboardInput))();
#endif
#ifdef MEDIA707_I34E_I34M
        if (L2944_ui_ == 0x0C53) { /*  CTRL-ALT-DEL 0x80 = ALT, 0x40 = CTRL, 0x53 = Scancode of 'DEL' */
                G2151_ExitGameImmediately = C1_TRUE;
        } else {
                if (L2944_ui_ == 0x0410) { /* CTRL-Q, 0x0400 = CTRL, 0x0010 = Scancode of 'Q' ('A' on French keyboard */
                        G2151_ExitGameImmediately = C1_TRUE;
                }
        }
        switch (L2944_ui_ - 0x1248) { /* 0x1000 = Extended Keyboard Scancode, 0x02 = SHIFT, 0x48 = Up arrow */
                case 0: /* 0x48 = Scancode of Up arrow */
                        L2944_ui_ = 'L'; /* 0x4C corresponds to Turn Forward */
                        break;
                case 8: /* 0x50 = Scancode of Down arrow */
                        L2944_ui_ = 'P'; /* 0x50 corresponds to Move Backward */
                        break;
                case 3: /* 0x4B = Scancode of Left arrow */
                        L2944_ui_ = 'K'; /* 0x4B corresponds to Turn Left */
                        break;
                case 5: /* 0x4D = Scancode of Right arrow */
                        L2944_ui_ = 'M'; /* 0x4D corresponds to Turn Right */
        }
#endif
                return L2944_ui_;
#ifdef MEDIA457_P20JA
        }
#endif
#endif
#ifdef MEDIA577_X30J
        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:
        }
#endif
#ifdef MEDIA692_X31J
        asm {
                        moveq   #0,d0           /* B_KEYINP */
                        trap    #0xF            /* TRAP 15 (IOCS CALL) */
                        tst.b   d0
                        bne.s   @Tloc_20F9C
                        lsr.w   #8,d0
                        ori.w   #0x100,d0
                        cmpi.w  #0x170,d0
                        bne.s   @Tloc_20F5C
                        move.w  #1,G3140_(a5)
                        bra.s   @Tlocret_20FBA
                @Tloc_20F5C:
                        cmpi.w  #0x1F0,d0
                        bne.s   @Tloc_20F6A
                        move.w  #0,G3140_(a5)
                        bra.s   @Tlocret_20FBA
                @Tloc_20F6A:
                        cmpi.w  #0x171,d0
                        bne.s   @Tloc_20F78
                        move.w  #1,G3141_(a5)
                        bra.s   @Tlocret_20FBA
                @Tloc_20F78:
                        cmpi.w  #0x1F1,d0
                        bne.s   @Tloc_20F86
                        move.w  #0,G3141_(a5)
                        bra.s   @Tlocret_20FBA
                @Tloc_20F86:
                        tst.w   G3140_(a5)
                        beq.s   @Tloc_20F90
                        ori.w   #0x800,d0
                @Tloc_20F90:
                        tst.w   G3141_(a5)
                        beq.s   @Tlocret_20FBA
                        ori.w   #0x400,d0
                        bra.s   @Tlocret_20FBA
                @Tloc_20F9C:
                        moveq   #0,d1
                        cmpi.w  #0x3F00,d0
                        bcs.s   @Tloc_20FB4
                        cmpi.w  #0x51FF,d0
                        bhi.s   @Tloc_20FB4
                        cmpi.w  #0x4E0D,d0
                        beq.s   @Tloc_20FB4
                        move.w  #0x200,d1
                @Tloc_20FB4:
                        andi.w  #0xFF,d0
                        or.w    d1,d0
                @Tlocret_20FBA:
        }
#endif
#ifdef MEDIA746_A36M_A31E_A31M_A33M_A35E_A35M
        register int16_t L2945_i_Key;


        while (!F1099_IsKeyBufferNotEmpty());
        L2945_i_Key = F1098_GetFirstKeyFromBuffer();
        return L2945_i_Key;
#endif
}

#ifdef MEDIA709_I34E_I34M_P31J
int16_t F0711_ConvertScanCodeToASCII(
int16_t P2397_i_ FINAL_SEPARATOR
{
        int16_t L2946_i_;


        L2946_i_ = (*(G2162_IODriver->IODRV_26_ConvertScanCodeToASCII))(P2397_i_);
        return L2946_i_;
}
#endif

BOOLEAN F0539_INPUT_Cconis(
void
)
{
#ifdef MEDIA463_P20JA_P20JB_I34E_I34M_P31J
        return (*(G2162_IODriver->IODRV_01_IsKeyboardInputPresent))();
#endif
#ifdef MEDIA607_X30J_X31J
        asm {
                moveq   #1,d0           /* B_KEYSNS */
                trap    #0xF            /* TRAP 15 (IOCS CALL) */
                swap    d0
        }
#endif
#ifdef MEDIA746_A36M_A31E_A31M_A33M_A35E_A35M
        return F1099_IsKeyBufferNotEmpty();
#endif
#ifdef MEDIA551_F20E_F20J_F31E_F31J
        return F2254_KEYAVAIL();
#endif
}

#ifdef MEDIA749_A36M_A31E_A31M_A33M_A35E_A35M_X31J
char F0711_ConvertScanCodeToASCII(
int16_t P2397_i_ FINAL_SEPARATOR
{
#ifdef MEDIA746_A36M_A31E_A31M_A33M_A35E_A35M
        return P2397_i_ & 0x7F;
#endif
#ifdef MEDIA692_X31J
        if (P2397_i_ & 0x100) {
                return '\0';
        } else {
                return P2397_i_ & 0xFF;
        }
#endif
}
#endif

#ifdef MEDIA746_A36M_A31E_A31M_A33M_A35E_A35M
void F1034_(
char* P2768_pc_String FINAL_SEPARATOR
{
        if (FindTask(0L) == G3165_ps_CurrentTask) {
                Write(G3159_ps_NIL1, P2768_pc_String, (long)F0090_strlen(P2768_pc_String));
        }
}

void F1035_Unreferenced(
int P2769_i_ FINAL_SEPARATOR
{
        int16_t L2947_i_;


        L2947_i_ = ((char)P2769_i_ << 8) & 0xFF00; /* Create a one character string */
        F1034_(&L2947_i_);
}
#endif

#ifdef MEDIA607_X30J_X31J
void F1022_PrintCharacter(
char P2765_c_Character FINAL_SEPARATOR
{
        G3099_ac_String[0] = P2765_c_Character;
        asm {
                pea     G3099_ac_String(a5)
                dc.w    0xFF09  /* DOS CALL PRINT */
                addq.l  #4,sp
        }
}

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

#ifdef MEDIA595_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_X31J_P31J
BOOLEAN F0712_AnyKeyboardOrMouseInput(
void
)
{
#ifdef MEDIA463_P20JA_P20JB_I34E_I34M_P31J
        int16_t L2948_i_A;
        int16_t L2949_i_B;
        int16_t L2950_i_C;


        F0706_GetMouseState(&L2948_i_A, &L2949_i_B, &L2950_i_C);
        return (L2950_i_C != 0) || (F0539_INPUT_Cconis());
#endif
#ifdef MEDIA607_X30J_X31J
        return (G0588_i_MouseButtonsStatus || F0539_INPUT_Cconis());
#endif
#ifdef MEDIA746_A36M_A31E_A31M_A33M_A35E_A35M
        return (F0539_INPUT_Cconis() || G0588_i_MouseButtonsStatus);
#endif
}
#endif

#ifdef MEDIA607_X30J_X31J
#ifndef NOCOPYPROTECTION
long F0527_FLOPPY_ReadFuzzySector_CPSX(
char* P2767_pc_Buffer FINAL_SEPARATOR
{
        asm {
                move.l  d3,-(sp)
                moveq   #0x46,d0        /* B_READ */
                move.w  #0x9050,d1      /* 0x90 (PDA) Drive 0. 0x50: Mode (01010000 Bit 6 = 1: MFM, Bit 5 = 0: Do not retry, Bit 4 = 1: Seek and then execute) */
                move.l  #0x01010109,d2  /* 4 bytes: Sector length 1 (0: 128, 1: 256, 2: 512, 3: 1024), Track 1 (0..79), Side 1 (0..1), Sector 9 (1..n) */
                move.l  #256,d3         /* Number of bytes to read */
                movea.l P2767_pc_Buffer(a6),a1
                trap    #0xF            /* TRAP 15 (IOCS CALL) */
                move.l  (sp)+,d3
        }
}
#endif
#endif

#ifdef MEDIA746_A36M_A31E_A31M_A33M_A35E_A35M
int16_t F0533_FLOPPY_WriteSavedGameInfoFiles(
void
)
{
}

#include "VBLANK.C"
#endif
#endif
