#ifndef COMPILE_H
#include "COMPILE.H"
#endif
#ifdef MEDIA701_I34E
#define C1_NO_SOUND              1
#define C2_PC_SPKR_SOUND         2
#define C3_FTL_SOUND_ADAPTER     3
#define C4_TANDY_1000_TLSL_SOUND 4
#define C5_DISNEY_SOUND_SOURCE   5
#define C6_SOUND_BLASTER         6
#define C7_ADLIB_SOUND           7

typedef struct {
        unsigned char Program[14];
        char Parameters[20];
        unsigned char Value1;
        unsigned char Value3[4];
} COMMAND_LINE;

extern int16_t G8000_/* = 0x0220 */;
extern char G8001_/* = 0 */;


unsigned int16_t _stklen = 500;
int16_t G8028_ = 0;
int16_t G8029_ = 0;
int16_t G8030_ = 0;
int16_t G8031_ = 0;
int16_t G8032_ = 0;
int16_t G8033_ = 10;
int16_t G8034_ = 16;
int16_t G8035_[8] = { 10, 9, 8, 6, 5, 4, 3, 1 };
int16_t G8036_[8] = { 16, 14, 12, 10, 8, 6, 4, 2 };
int16_t G8037_ = 0;
unsigned char G8038_ScanCodeToLowercaseASCII[128] = {
        0x00,
        0x1B,
        0x31, /*  1 */
        0x32, /*  2 */
        0x33, /*  3 */
        0x34, /*  4 */
        0x35, /*  5 */
        0x36, /*  6 */
        0x37, /*  7 */
        0x38, /*  8 */
        0x39, /*  9 */
        0x30, /*  0 */
        0x2D, /*  - */
        0x3D, /*  = */
        0x08,
        0x09,
        0x71, /*  q */
        0x77, /*  w */
        0x65, /*  e */
        0x72, /*  r */
        0x74, /*  t */
        0x79, /*  y */
        0x75, /*  u */
        0x69, /*  i */
        0x6F, /*  o */
        0x70, /*  p */
        0x5B, /*  [ */
        0x5D, /*  ] */
        0x0D,
        0x00,
        0x61, /*  a */
        0x73, /*  s */
        0x64, /*  d */
        0x66, /*  f */
        0x67, /*  g */
        0x68, /*  h */
        0x6A, /*  j */
        0x6B, /*  k */
        0x6C, /*  l */
        0x3B, /*  ; */
        0x00,
        0x00,
        0x00,
        0x5C, /*  \ */
        0x7A, /*  z */
        0x78, /*  x */
        0x63, /*  c */
        0x76, /*  v */
        0x62, /*  b */
        0x6E, /*  n */
        0x6D, /*  m */
        0x2C, /*  , */
        0x2E, /*  . */
        0x2F, /*  / */
        0x00,
        0x2A, /*  * */
        0x00,
        0x20,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x2D, /*  - */
        0x00,
        0x00,
        0x00,
        0x2B, /*  + */
        0x00,
        0x00,
        0x00,
        0x00,
        0x7F, /*   */
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00 };
unsigned char G8039_ScanCodeToUppercaseASCII[128] = {
        0x00,
        0x1B,
        0x21, /*  ! */
        0x40, /*  @ */
        0x23, /*  # */
        0x24, /*  $ */
        0x25, /*  % */
        0x5E, /*  ^ */
        0x26, /*  & */
        0x2A, /*  * */
        0x28, /*  ( */
        0x29, /*  ) */
        0x5F, /*  _ */
        0x2B, /*  + */
        0x08,
        0x09,
        0x51, /*  Q */
        0x57, /*  W */
        0x45, /*  E */
        0x52, /*  R */
        0x54, /*  T */
        0x59, /*  Y */
        0x55, /*  U */
        0x49, /*  I */
        0x4F, /*  O */
        0x50, /*  P */
        0x7B, /*  { */
        0x7D, /*  } */
        0x0D,
        0x00,
        0x41, /*  A */
        0x53, /*  S */
        0x44, /*  D */
        0x46, /*  F */
        0x47, /*  G */
        0x48, /*  H */
        0x4A, /*  J */
        0x4B, /*  K */
        0x4C, /*  L */
        0x3A, /*  : */
        0x00,
        0x00,
        0x00,
        0x7C, /*  | */
        0x5A, /*  Z */
        0x58, /*  X */
        0x43, /*  C */
        0x56, /*  V */
        0x42, /*  B */
        0x4E, /*  N */
        0x4D, /*  M */
        0x3C, /*  < */
        0x3E, /*  > */
        0x3F, /*  ? */
        0x00,
        0x2A, /*  * */
        0x00,
        0x20,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x2D, /*  - */
        0x00,
        0x00,
        0x00,
        0x2B, /*  + */
        0x00,
        0x00,
        0x00,
        0x00,
        0x7F, /*   */
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00,
        0x00 };
int16_t G8040_CurrentMouseX = 0;
int16_t G8041_CurrentMouseY = 0;
int16_t G8042_MouseX = 0;
int16_t G8043_MouseY = 0;
BOOLEAN G8044_MouseHandlerConfigured = C0_FALSE;
int16_t G8045_ = 0;
int16_t G8046_ = 0;
int16_t G8047_ = 0;
int16_t G8048_ = 0;
int16_t G8049_ = 0;
int16_t G8050_ = 0;
int16_t G8051_ = 0;
int16_t G8052_ = 0;



char G8053_;
VIDEO_DRIVER* G2156_VideoDriver;
int16_t G8055_;
int16_t G8056_;
int16_t G8057_;
int16_t G8058_;
int16_t G8059_[10];
int16_t G8060_;
int16_t G8061_TemporaryValue;
unsigned int16_t G8062_;
char G8063_MousePointerBitmaps[4][M075_BITMAP_BYTE_COUNT(18,18)]; /* 4 pointers of 18x18 pixels */
int16_t G8064_;
unsigned char G8065_;
int16_t G8066_MousePointerHotspots[4][2];
int16_t G2336_i_MouseStateHistoryCurrent;
int16_t (*G8067_MouseHandler)();
int16_t G8068_ai_Box[4];
int16_t G8069_;
int16_t G8070_MouseStateHistoryCount;
int16_t G8071_;
int16_t G2335_aai_MouseStateHistory[10][3];
int16_t G3103_i_MouseBoundButtonsStatus;
int16_t G8073_FormatedCurrentButtonsStatus;
int16_t G3104_ai_XYZ_MouseBound[4];
int16_t G8075_;
BOOLEAN G3102_B_MouseBounded;
int16_t G8077_;
unsigned int16_t G8078_;
char G8079_Padding[4];
BOOLEAN G8080_;
int16_t G8081_;
int16_t G8082_;
int16_t G8083_[10];
int16_t G8084_;
int16_t G8085_;
char G8086_Padding[8];
unsigned int16_t G8087_;
int16_t G8088_;
int16_t G8089_;
void (*G8090_)();
int16_t G8091_PreviousRawButtonStatus;
int16_t G8092_MousePointerType;


void F8087_(int16_t P3278_i_)
{
        asm     pushf
        asm     cli
        if (G8082_ < 10) {
                G8083_[G8077_] = P3278_i_;
                G8077_ = (G8077_ + 1) % 10;
                G8082_++;
        }
        asm     popf
}

void F8088_(
)
{
        int16_t L2660_i_;
        int16_t L2661_i_;


        G8082_ = 0;
        G8077_ = G8081_ = 0;
        G8062_ = 0;
        G8078_ = 0;
        G8087_ = 0;
        G8080_ = C0_FALSE;
        goto loc_109B9;
        asm     V8088000_ dd 0
        loc_109B9:
        asm     mov     ax, 3509h
        asm     int     21h
        asm     mov     word ptr cs:V8088000_, bx
        asm     mov     word ptr cs:V8088000_+2, es
        asm     push    ds
        asm     mov     dx, seg S8A_Vector
        asm     mov     ds, dx
        asm     mov     dx, offset S8A_Vector
        asm     mov     ax, 2509h
        asm     int     21h
        asm     pop     ds
        goto loc_10D05;
        /* ; DOS - 2+ - GET INTERRUPT VECTOR
           ; AL = interrupt number
           ; Return: ES:BX = value of interrupt vector */
        /* ; DOS - SET INTERRUPT VECTOR
           ; AL = interrupt number
           ; DS:DX = new vector to be used for specified interrupt */
        asm     S8A_Vector:
        asm     push    ax
        asm     push    es
        asm     push    ds
        asm     push    bx
        asm     push    cx
        asm     push    dx
        asm     push    si
        asm     push    di
        asm     push    bp
        asm     push    ss
        asm     mov     ax, cs:V0000000_DataSegment
        asm     mov     ds, ax
        asm     in      al, 60h        /* 8042 keyboard controller data register */
        asm     mov     ah, 0
        asm     mov     G8085_, ax
        if (G8085_ == 224) {
                G8062_ |= 0x1000;
        } else {
                if (G8062_ & 0x0800) {
                        G8080_ = C1_TRUE;
                        switch (G8085_) {
                                case 72:
                                        G8087_ |= 0x01;
                                        break;
                                case 75:
                                        G8087_ |= 0x04;
                                        break;
                                case 77:
                                        G8087_ |= 0x08;
                                        break;
                                case 80:
                                        G8087_ |= 0x02;
                                        break;
                                case 71:
                                        G8087_ |= 0x20;
                                        break;
                                case 73:
                                        G8087_ |= 0x40;
                                        break;
                                case 79:
                                        G8087_ |= 0x80;
                                        break;
                                case 81:
                                        G8087_ |= 0x100;
                                        break;
                                case 78:
                                        G8087_ |= 0x10;
                                        break;
                                case 74:
                                case 76:
                                default:
                                        G8080_ = C0_FALSE;
                        }
                }
                if (!G8080_) {
                        switch (G8085_) {
                                case 42:
                                        G8062_ = G8062_ | 0x8000;
                                        break;
                                case 54:
                                        G8062_ |= 0x4000;
                                        break;
                                case 29:
                                        G8062_ |= 0x0400;
                                        break;
                                case 56:
                                        G8062_ |= 0x0800;
                                        break;
                                case 170:
                                        G8062_ = G8062_ & 0x7FFF;
                                        break;
                                case 182:
                                        G8062_ &= 0xBFFF;
                                        break;
                                case 157:
                                        G8062_ &= 0xFBFF;
                                        break;
                                case 184:
                                        G8062_ &= 0xF7FF;
                                        break;
                                case 200:
                                        G8087_ &= 0xFFFE;
                                        break;
                                case 203:
                                        G8087_ &= 0xFFFB;
                                        break;
                                case 205:
                                        G8087_ &= 0xFFF7;
                                        break;
                                case 208:
                                        G8087_ &= 0xFFFD;
                                        break;
                                case 199:
                                        G8087_ &= 0xFFDF;
                                        break;
                                case 201:
                                        G8087_ &= 0xFFBF;
                                        break;
                                case 207:
                                        G8087_ &= 0xFF7F;
                                        break;
                                case 209:
                                        G8087_ &= 0xFEFF;
                                        break;
                                case 206:
                                        G8087_ &= 0xFFEF;
                                        break;
                                case 202:
                                case 204:
                                default:
                                        if ((G8085_ & 0x80) == 0) {
                                                switch (G8085_) {
                                                        case 59:
                                                                if (G8032_ > 0) {
                                                                        G8032_--;
                                                                }
                                                                G8033_ = G8035_[G8032_];
                                                                G8034_ = G8036_[G8032_];
                                                                break;
                                                        case 60:
                                                                if (G8032_ < 7) {
                                                                        G8032_++;
                                                                }
                                                                G8033_ = G8035_[G8032_];
                                                                G8034_ = G8036_[G8032_];
                                                                break;
                                                        default:
                                                                if ((G8059_[(G8085_ >> 4) & 0x07] & (1 << (G8085_ & 0x0F))) == 0) {
                                                                        F8087_(G8085_ | (G8062_ & 0x1EFF));
                                                                }
                                                }
                                        }
                        }
                        if (G8085_ & 0x80) {
                                G8059_[(G8085_ >> 4) & 0x07] &= ~(1 << (G8085_ & 0x0F));
                        } else {
                                G8059_[(G8085_ >> 4) & 0x07] |= 1 << (G8085_ & 0x0F);
                        }
                        if ((G8062_ & 0x8000) || (G8062_ & 0x4000)) {
                                G8062_ |= 0x0200;
                        } else {
                                G8062_ &= 0xFDFF;
                        }
                }
                if (G8087_ & 0x61) {
                        G8078_ |= 0x0001;
                } else {
                        G8078_ &= 0xFFFE;
                }
                if (G8087_ & 0x182) {
                        G8078_ |= 0x0002;
                } else {
                        G8078_ &= 0xFFFD;
                }
                if (G8087_ & 0x148) {
                        G8078_ |= 0x0008;
                } else {
                        G8078_ &= 0xFFF7;
                }
                if (G8087_ & 0xA4) {
                        G8078_ |= 0x0004;
                } else {
                        G8078_ &= 0xFFFB;
                }
                if (G8087_ & 0x10) {
                        G8078_ |= 0x0010;
                } else {
                        G8078_ &= 0xFFEF;
                }
                G8062_ &= 0xEFFF;
        }
        if (G8028_ == 0) {
                asm     pop     ss
                asm     pop     bp
                asm     pop     di
                asm     pop     si
                asm     pop     dx
                asm     pop     cx
                asm     pop     bx
                asm     pop     ds
                asm     pop     es
                asm     in      al, 61h        /* PC/XT PPI port B bits: */
                                               /* 0: Tmr 2 gate --- OR 03H=spkr ON */
                                               /* 1: Tmr 2 data -+  AND 0fcH=spkr OFF */
                                               /* 3: 1=read high switches */
                                               /* 4: 0=enable RAM parity checking */
                                               /* 5: 0=enable I/O channel check */
                                               /* 6: 0=hold keyboard clock low */
                                               /* 7: 0=enable kbrd */
                asm     mov     ah, al
                asm     or      al, 80h
                asm     out     61h, al        /* PC/XT PPI port B bits: */
                                               /* 0: Tmr 2 gate --- OR 03H=spkr ON */
                                               /* 1: Tmr 2 data -+  AND 0fcH=spkr OFF */
                                               /* 3: 1=read high switches */
                                               /* 4: 0=enable RAM parity checking */
                                               /* 5: 0=enable I/O channel check */
                                               /* 6: 0=hold keyboard clock low */
                                               /* 7: 0=enable kbrd */
                asm     xchg    al, ah
                asm     out     61h, al        /* PC/XT PPI port B bits: */
                                               /* 0: Tmr 2 gate --- OR 03H=spkr ON */
                                               /* 1: Tmr 2 data -+  AND 0fcH=spkr OFF */
                                               /* 3: 1=read high switches */
                                               /* 4: 0=enable RAM parity checking */
                                               /* 5: 0=enable I/O channel check */
                                               /* 6: 0=hold keyboard clock low */
                                               /* 7: 0=enable kbrd */
                asm     mov     al, 20h
                asm     out     20h, al        /* Interrupt controller, 8259A. */
                asm     pop     ax
                asm     iret
        } else {
                asm     pop     ss
                asm     pop     bp
                asm     pop     di
                asm     pop     si
                asm     pop     dx
                asm     pop     cx
                asm     pop     bx
                asm     pop     ds
                asm     pop     es
                asm     pop     ax
                asm     jmp     cs:V8088000_
        }
        loc_10D05:
        G8037_ = 1;
}

void F8089_(
)
{
        if (G8037_) {
                G8037_ = 0;
                asm     push    ds
                asm     mov     dx, word ptr cs:V8088000_+2
                asm     mov     ds, dx
                asm     mov     dx, word ptr cs:V8088000_
                asm     mov     ax, 2509h
                asm     int     21h            /* DOS - SET INTERRUPT VECTOR */
                                               /* AL = interrupt number */
                                               /* DS:DX = new vector to be used for specified interrupt */
                asm     pop     ds
        }
}

int16_t F8090_(
)
{
        int16_t L2662_i_;


        ASM_STUB_PREFIX
        while (!G8082_);
        asm     pushf
        asm     cli
        L2662_i_ = G8083_[G8081_];
        G8081_ = (G8081_ + 1) % 10;
        G8082_--;
        asm     popf
        asm     mov     ax, L2662_i_
        ASM_STUB_SUFFIX
}

void F8091_(
)
{
        int16_t L2663_i_;


        ASM_STUB_PREFIX
        if (G8028_ && G8029_) {
                (*G8090_)();
        }
        if (G8082_) {
                L2663_i_ = 1;
        } else {
                L2663_i_ = 0;
        }
        asm     mov     ax, L2663_i_
        ASM_STUB_SUFFIX
}

int16_t F8092_ConvertScanCodeToASCII(int16_t P3279_i_)
{
        int16_t L2664_i_;


        ASM_STUB_PREFIX
        if (P3279_i_ & 0x0200) {
                L2664_i_ = G8039_ScanCodeToUppercaseASCII[P3279_i_ & 0x7F];
        } else {
                L2664_i_ = G8038_ScanCodeToLowercaseASCII[P3279_i_ & 0x7F];
        }
        ASM_STUB_SUFFIX
        return L2664_i_;
}

void F8093_(
)
{
        int16_t L2665_i_;


        ASM_STUB_PREFIX
        L2665_i_ = F8092_ConvertScanCodeToASCII(F8090_());
        asm     mov     ax, L2665_i_
        ASM_STUB_SUFFIX
}

void F8094_ProcessMouseMovement(
)
{
        int16_t L2666_i_;
        int16_t L2667_i_;


        /* Detect if mouse pointer moved out of specified box */
        if (G3102_B_MouseBounded && G8044_MouseHandlerConfigured && ((G8040_CurrentMouseX < G3104_ai_XYZ_MouseBound[0]) || (G8040_CurrentMouseX > G3104_ai_XYZ_MouseBound[1]) || (G8041_CurrentMouseY < G3104_ai_XYZ_MouseBound[2]) || (G8041_CurrentMouseY > G3104_ai_XYZ_MouseBound[3]))) {
                G3102_B_MouseBounded = C0_FALSE;
                if ((G8061_TemporaryValue = (*G8067_MouseHandler)(G8040_CurrentMouseX, G8041_CurrentMouseY, G3103_i_MouseBoundButtonsStatus)) >= 0) { /* If mouse pointer is not a champion icon */
                        G8092_MousePointerType = G8061_TemporaryValue;
                }
        }
        L2666_i_ = G8040_CurrentMouseX - G8066_MousePointerHotspots[G8092_MousePointerType][0];
        L2667_i_ = G8041_CurrentMouseY - G8066_MousePointerHotspots[G8092_MousePointerType][1];
        G8088_ = 0;
        G8089_ = 0;
        if (L2666_i_ < 0) {
                G8088_ = 0 - L2666_i_;
                L2666_i_ = 0;
        }
        if (L2667_i_ < 0) {
                G8089_ = 0 - L2667_i_;
                L2667_i_ = 0;
        }
        if (L2666_i_ >= 320) {
                return;
        }
        if (L2667_i_ >= 200) {
                return;
        }
        asm     pushf
        asm     cli
        if (!G8071_) {
                G8071_++;
                asm     popf
                M768_BOX_LEFT(G8068_ai_Box) = L2666_i_;
                M769_BOX_RIGHT(G8068_ai_Box) = L2666_i_ + 17 - G8088_;
                if (M769_BOX_RIGHT(G8068_ai_Box) > 319) {
                        M769_BOX_RIGHT(G8068_ai_Box) = 319;
                }
                M770_BOX_TOP(G8068_ai_Box) = L2667_i_;
                M771_BOX_BOTTOM(G8068_ai_Box) = L2667_i_ + 17 - G8089_;
                if (M771_BOX_BOTTOM(G8068_ai_Box) > 199) {
                        M771_BOX_BOTTOM(G8068_ai_Box) = 199;
                }
                (*(G2156_VideoDriver->VIDRV_03_BlitMousePointerPrefixedBitmapFromScreen))(L2666_i_, L2667_i_);
                (*(G2156_VideoDriver->VIDRV_02_Blit))(&G8063_MousePointerBitmaps[G8092_MousePointerType], NULL, G8068_ai_Box, G8088_, G8089_, 18, 320, 12, 0, 0, 0);
                return;
        }
        asm     popf
}

void F8095_(
)
{
        if (G8071_) {
                (*(G2156_VideoDriver->VIDRV_04_BlitMousePointerPrefixedBitmapToScreen))();
                G8071_--;
        }
}

void F8096_ProcessMouseState(register int16_t P3280_i_MouseX, register int16_t P3281_i_MouseY, int16_t P3282_i_RawButtonStatus) /* Corresponds to F0076_MOUSE_OnMouseButtonsStatusChange */
/*
Comments by Jean-Claude:
After a XOR between current and previous status, returns these following status:
          00              01               10            11                    Current status
00  00-Impossible  01-0004h       10-0001h       11-Improbable
01  01-0004h       00-Impossible  11-0004h       10-Improbable
10  10-0008h       11-0001h       00-Impossible  01-Improbable
11  11-Improbable  10-Improbable  01-Improbable  00-Impossible
Previous Status

Right button is examined only if bit 0 left button of XOR result is 0.
Improbable is a simultaneous click on both buttons.
Impossible: there cannot be two successive identical statues. Summary:
0001h : Current Right Click.
0002h : Current Left Click.
0004h : Previous Left Click. No corresponding mask but triggers command C254_COMMAND_STOP_PRESSING_EYE_MOUTH_WALL ("Global Event for Quit Mouth or Eye") in "F0359_COMMAND_ProcessClick_CPSC".
0008h : Previous Right Click. Ignored because no corresponding mask
*/
{
        G8040_CurrentMouseX = P3280_i_MouseX;
        G8041_CurrentMouseY = P3281_i_MouseY;
        if (((P3280_i_MouseX != G8042_MouseX) || (P3281_i_MouseY != G8043_MouseY)) && (G8069_ <= 0)) {
                F8095_();
                F8094_ProcessMouseMovement();
                G8042_MouseX = P3280_i_MouseX;
                G8043_MouseY = P3281_i_MouseY;
        }
        G8073_FormatedCurrentButtonsStatus = (M007_GET((P3282_i_RawButtonStatus >> 1), MASK0x0001_MOUSE_RIGHT_BUTTON)) | (M007_GET((P3282_i_RawButtonStatus << 1), MASK0x0002_MOUSE_LEFT_BUTTON));
        if (((G8061_TemporaryValue = P3282_i_RawButtonStatus ^ G8091_PreviousRawButtonStatus) != 0) && G8044_MouseHandlerConfigured) {
                if (G8061_TemporaryValue & 1) {
                        (*G8067_MouseHandler)(P3280_i_MouseX, P3281_i_MouseY, (P3282_i_RawButtonStatus & 1) ? C02_MOUSE_EVENT_LEFT_BUTTON_DOWN : C04_MOUSE_EVENT_LEFT_BUTTON_UP);
                }
                if (G8061_TemporaryValue & 2) {
                        (*G8067_MouseHandler)(P3280_i_MouseX, P3281_i_MouseY, (P3282_i_RawButtonStatus & 2) ? C01_MOUSE_EVENT_RIGHT_BUTTON_DOWN : C08_MOUSE_EVENT_RIGHT_BUTTON_UP);
                }
                G8091_PreviousRawButtonStatus = P3282_i_RawButtonStatus;
        }
}

void F8097_(
)
{
        ASM_STUB_PREFIX
        asm     pushf
        asm     cli
        G8060_++;
        asm     popf
        ASM_STUB_SUFFIX
}

void F8098_ProcessMouseStateHistory(
)
{
        int16_t L2668_i_MouseY;
        int16_t L2669_i_ButtonsStatus;
        int16_t L2670_i_MouseX;


        ASM_STUB_PREFIX
        asm     pushf
        asm     cli
        while (G8070_MouseStateHistoryCount > 0) {
                G8070_MouseStateHistoryCount--;
                G2336_i_MouseStateHistoryCurrent = (G2336_i_MouseStateHistoryCurrent + 1) % 10; /* Wrap to index 0 when above 10 */
                L2670_i_MouseX = G2335_aai_MouseStateHistory[G2336_i_MouseStateHistoryCurrent][0];  /* Element size = 6 */
                L2668_i_MouseY = G2335_aai_MouseStateHistory[G2336_i_MouseStateHistoryCurrent][1];  /* Element size = 6 */
                L2669_i_ButtonsStatus = G2335_aai_MouseStateHistory[G2336_i_MouseStateHistoryCurrent][2];  /* Element size = 6 */
                asm     popf
                F8096_ProcessMouseState(L2668_i_MouseY, L2669_i_ButtonsStatus, L2670_i_MouseX);
                asm     pushf
                asm     cli
        }
        G8060_--;
        asm     popf
        ASM_STUB_SUFFIX
}

void F8099_LockMouse(
)
{
        ASM_STUB_PREFIX
        asm     pushf
        asm     cli
        G8058_++;
        asm     popf
        ASM_STUB_SUFFIX
}

void F8100_UnlockMouse(
)
{
        ASM_STUB_PREFIX
        asm     pushf
        asm     cli
        if (G8075_ == 1) {
                asm     mov     cx, G8040_CurrentMouseX
                asm     shl     cx, 1
                asm     mov     dx, G8041_CurrentMouseY
                asm     mov     ax, 4
                asm     int     33h            /* - MS MOUSE - POSITION MOUSE CURSOR */
                asm                            /* CX = column, DX = row */
        }
        G8058_--;
        asm     popf
        ASM_STUB_SUFFIX
}

void F8101_SetMouseHandler(int16_t (*P3283_pfi_)())
{
        asm     push    ds
        asm     mov     ax, cs:V0000000_DataSegment
        asm     pushf
        asm     cli
        asm     mov     ds, ax
        G8067_MouseHandler = P3283_pfi_;
        G8044_MouseHandlerConfigured = C1_TRUE;
        asm     popf
        asm     pop     ds
}

void F8102_(
)
{
        asm     pushf
        asm     cli
        G8069_ = 1;
        G8044_MouseHandlerConfigured = C0_FALSE;
        G8071_ = 0;
        G3102_B_MouseBounded = C0_FALSE;
        G8058_ = 0;
        G8060_ = 0;
        G8057_ = G2336_i_MouseStateHistoryCurrent = 0;
        G8070_MouseStateHistoryCount = 0;
        G8091_PreviousRawButtonStatus = 0;
        G8092_MousePointerType = 0;
        asm     popf
}

void F8103_(
)
{
        int16_t L2672_i_;
        int16_t L2673_i_;


        if (G8075_ == 0) {
                return;
                asm     V8103000_ dw 0
                asm     V8103001_ dw 0
                asm     V8103002_ dw 0
        }
        asm     pushf
        asm     cli
        asm     mov     cx, G8040_CurrentMouseX
        asm     shl     cx, 1
        asm     mov     dx, G8041_CurrentMouseY
        asm     mov     ax, 4
        asm     int     33h            /* - MS MOUSE - POSITION MOUSE CURSOR */
                                       /* CX = column, DX = row */
        asm     mov     ax, 3
        asm     int     33h            /* - MS MOUSE - RETURN POSITION AND BUTTON STATUS */
                                       /* Return: BX = button status, CX = column, DX = row */
        asm     shr     cx, 1
        asm     mov     G8040_CurrentMouseX, cx
        asm     mov     G8041_CurrentMouseY, dx
        asm     mov     ax, 0Fh
        asm     mov     cx, 10h
        asm     mov     dx, 20h
        asm     int     33h            /* - MS MOUSE - DEFINE MICKEY/PIXEL RATIO */
                                       /* CX = number of mickeys per 8 pixels horizontally (default 8) */
                                       /* DX = number of mickeys per 8 pixels vertically (default 16) */
        asm     mov     dx, seg S87C_Vector
        asm     mov     es, dx
        asm     mov     dx, offset S87C_Vector
        asm     mov     cx, 1Fh
        asm     mov     ax, 14h
        asm     int     33h            /* - MS MOUSE - EXCHANGE INTERRUPT SUBROUTINES */
                                       /* CX = call mask, ES:DX -> FAR routine */
                                       /* Return: CX = call mask of previous interrupt routine */
                                       /* ES:DX = FAR address of previous interrupt routine */
        asm     mov     cs:V8103002_, cx
        asm     mov     cs:V8103000_, dx
        asm     mov     dx, es
        asm     mov     cs:V8103001_, dx
        asm     popf
        asm     jmp     loc_1126C
        asm     S87C_Vector:
        asm     push    ss
        asm     push    es
        asm     push    ds
        asm     push    ax
        asm     push    bx
        asm     push    cx
        asm     push    dx
        asm     push    si
        asm     push    di
        asm     push    bp
        asm     shr     cx, 1
        asm     mov     ax, cs:V0000000_DataSegment
        asm     mov     ds, ax
        asm     and     bx, 3
        asm     cmp     G8058_, 0
        asm     jz      loc_111F0
        asm     mov     cx, G8040_CurrentMouseX
        asm     mov     dx, G8041_CurrentMouseY
        loc_111F0:
        asm     pushf
        asm     cli
        asm     cmp     G8060_, 0
        asm     jz      loc_111FB
        asm     jmp     loc_11209
        loc_111FB:
        asm     popf
        asm     push    bx
        asm     push    dx
        asm     push    cx
        asm     push    cs
        asm     call    near ptr F8096_ProcessMouseState
        asm     add     sp, 6
        asm     jmp     loc_11261
        loc_11209:
        asm     cmp     G8070_MouseStateHistoryCount, 10
        asm     jge     loc_11260
        asm     cmp     G8070_MouseStateHistoryCount, 0
        asm     jz      loc_11234
        asm     mov     di, G8057_
        asm     mov     ax, di
        asm     add     di, ax
        asm     add     di, ax
        asm     add     di, di
        asm     cmp     [di+G2335_aai_MouseStateHistory], bx
        asm     jnz     loc_11234
        asm     mov     [di+G2335_aai_MouseStateHistory+2], cx
        asm     mov     [di+G2335_aai_MouseStateHistory+4], dx
        asm     popf
        asm     jmp     loc_11261
        loc_11234:
        asm     inc     G8070_MouseStateHistoryCount
        asm     mov     di, G8057_
        asm     inc     di
        asm     cmp     di, 0Ah
        asm     jnz     loc_11245
        asm     mov     di, 0
        loc_11245:
        asm     mov     G8057_, di
        asm     mov     ax, di
        asm     add     di, ax
        asm     add     di, ax
        asm     add     di, di
        asm     mov     [di+G2335_aai_MouseStateHistory], bx
        asm     mov     [di+G2335_aai_MouseStateHistory+2], cx
        asm     mov     [di+G2335_aai_MouseStateHistory+4], dx
        asm     popf
        asm     jmp     loc_11261
        loc_11260:
        asm     popf
        loc_11261:
        asm     pop     bp
        asm     pop     di
        asm     pop     si
        asm     pop     dx
        asm     pop     cx
        asm     pop     bx
        asm     pop     ax
        asm     pop     ds
        asm     pop     es
        asm     pop     ss
        asm     retf
        loc_1126C:
        G8051_ = 1;
}

void F8104_(
)
{
        asm     pushf
        asm     cli
        if (G8051_) {
                G8051_ = 0;
                G8044_MouseHandlerConfigured = C0_FALSE;
                asm     mov     dx, cs:V8103001_
                asm     mov     es, dx
                asm     mov     dx, cs:V8103000_
                asm     mov     cx, cs:V8103002_
                asm     mov     ax, 14h
                asm     int     33h     /* - MS MOUSE - EXCHANGE INTERRUPT SUBROUTINES */
                                        /* CX = call mask, ES:DX -> FAR routine */
                                        /* Return: CX = call mask of previous interrupt routine */
                                        /* ES:DX = FAR address of previous interrupt routine */
        }
        asm     popf
}

int16_t F8105_(
)
{
        asm     pushf
        asm     cli
        asm     mov     ax, 0
        asm     int     33h            /* - MS MOUSE - RESET DRIVER AND READ STATUS */
                                       /* Return: AX = status */
                                       /* BX = number of buttons */
        asm     and     ax, 1
        asm     mov     G8075_, ax
        if (G8075_ == 1) {
                asm     mov     cx, 0
                asm     mov     dx, 0
                asm     mov     ax, 4
                asm     int     33h            /* - MS MOUSE - POSITION MOUSE CURSOR */
                                               /* CX = column, DX = row */
                asm     mov     cx, 0
                asm     mov     dx, 27Fh
                asm     mov     ax, 7
                asm     int     33h            /* - MS MOUSE - DEFINE HORIZONTAL CURSOR RANGE */
                                               /* CX = minimum column, DX = maximum column */
                asm     mov     cx, 0
                asm     mov     dx, 0C7h
                asm     mov     ax, 8
                asm     int     33h            /* - MS MOUSE - DEFINE VERTICAL CURSOR RANGE */
                                               /* CX = minimum row, DX = maximum row */
        }
        asm     popf
        return G8075_;
}

void F8106_(
)
{
        ASM_STUB_PREFIX
        asm     pushf
        asm     cli
        if (G8069_-- == 1) {
                F8097_();
                F8094_ProcessMouseMovement();
                G8042_MouseX = G8040_CurrentMouseX;
                G8043_MouseY = G8041_CurrentMouseY;
                F8098_ProcessMouseStateHistory();
        }
        asm     popf
        ASM_STUB_SUFFIX
}

void F8107_(
)
{
        ASM_STUB_PREFIX
        asm     pushf
        asm     cli
        if (G8069_++ == 0) {
                F8097_();
                F8095_();
                F8098_ProcessMouseStateHistory();
        }
        asm     popf
        ASM_STUB_SUFFIX
}

void F8108_RegisterMousePointerBitmap(int16_t P3284_i_PointerIndex, char huge* P3285_pc_PointerBitmap, int16_t P3286_i_HotspotX, int16_t P3287_i_HotspotY)
{
        int16_t L2674_i_ByteIndex;


        ASM_STUB_PREFIX
        asm     pushf
        asm     cli
        if ((P3284_i_PointerIndex >= 0) && (P3284_i_PointerIndex < 4)) {
                F8097_();
                for (L2674_i_ByteIndex = 0; L2674_i_ByteIndex < M075_BITMAP_BYTE_COUNT(18,18); L2674_i_ByteIndex++) {
                        G8063_MousePointerBitmaps[P3284_i_PointerIndex][L2674_i_ByteIndex] = P3285_pc_PointerBitmap[L2674_i_ByteIndex];
                }
                G8066_MousePointerHotspots[P3284_i_PointerIndex][0] = P3286_i_HotspotX;
                G8066_MousePointerHotspots[P3284_i_PointerIndex][1] = P3287_i_HotspotY;
                F8098_ProcessMouseStateHistory();
        }
        asm     popf
        ASM_STUB_SUFFIX
}

void F8109_SetMousePointer(int16_t P3288_i_)
{
        ASM_STUB_PREFIX
        asm     pushf
        asm     cli
        F8097_();
        if (G8071_) {
                F8095_();
                G8092_MousePointerType = P3288_i_;
                F8094_ProcessMouseMovement();
        } else {
                G8092_MousePointerType = P3288_i_;
        }
        F8098_ProcessMouseStateHistory();
        asm     popf
        ASM_STUB_SUFFIX
}

void F1040_SetMouseBoundEvent(int16_t* P2777_pi_XYZ, int16_t P2778_i_ButtonsStatus)
{
        int16_t L2675_i_;


        ASM_STUB_PREFIX
        asm     pushf
        asm     cli
        F8097_();
        G3102_B_MouseBounded = C0_FALSE;
        for (L2675_i_ = 0; L2675_i_ < 4; L2675_i_++) {
                G3104_ai_XYZ_MouseBound[L2675_i_] = P2777_pi_XYZ[L2675_i_];
        }
        G3103_i_MouseBoundButtonsStatus = P2778_i_ButtonsStatus;
        G3102_B_MouseBounded = C1_TRUE;
        F8098_ProcessMouseStateHistory();
        asm     popf
        ASM_STUB_SUFFIX
}

void F8111_SetMousePointerCoordinates(int16_t P3291_i_, int16_t P3292_i_)
{
        ASM_STUB_PREFIX
        asm     pushf
        asm     cli
        F8099_LockMouse();
        G8040_CurrentMouseX = G8045_ = P3291_i_;
        G8041_CurrentMouseY = G8046_ = P3292_i_;
        if (G8075_ == 1) {
                asm     mov     cx, P3291_i_
                asm     shl     cx, 1
                asm     mov     dx, P3292_i_
                asm     mov     ax, 4
                asm     int     33h            /* - MS MOUSE - POSITION MOUSE CURSOR */
                                               /* CX = column, DX = row */
        }
        if (G8071_) {
                F8095_();
                F8094_ProcessMouseMovement();
        }
        F8100_UnlockMouse();
        asm     popf
        ASM_STUB_SUFFIX
}

void F8112_GetMouseState(int16_t* P3293_pi_, int16_t* P3294_pi_, int16_t* P3295_pi_)
{
        ASM_STUB_PREFIX
        asm     pushf
        asm     cli
        *P3293_pi_ = G8040_CurrentMouseX;
        *P3294_pi_ = G8041_CurrentMouseY;
        *P3295_pi_ = G8073_FormatedCurrentButtonsStatus;
        asm     popf
        ASM_STUB_SUFFIX
}

int16_t F8113_(char P3296_c_)
{
        asm     jmp     loc_114C6
        asm     loc_114B1:
        asm     mov     al, 80h
        asm     out     43h, al        /* Timer 8253-5 (AT: 8254.2). */
        asm     jmp     $+2
        asm     jmp     $+2
        asm     in      al, 42h        /* Timer 8253-5 (AT: 8254.2). */
        asm     xchg    al, ah
        asm     jmp     $+2
        asm     jmp     $+2
        asm     in      al, 42h        /* Timer 8253-5 (AT: 8254.2). */
        asm     xchg    al, ah
        asm     retn
        loc_114C6:
        asm     mov     dx, 201h
        asm     in      al, dx         /* Game I/O port */
                                       /* bits 0-3: Coordinates (resistive, time-dependent inputs) */
                                       /* bits 4-7: Buttons/Triggers (digital inputs) */
        asm     and     al, 3
        asm     jnz     loc_114C6
        asm     mov     bl, P3296_c_
        asm     call    loc_114B1
        asm     out     dx, al
        asm     jmp     $+2
        asm     jmp     $+2
        asm     jmp     $+2
        asm     jmp     $+2
        asm     push    ax
        asm     mov     ah, bl
        loc_114E0:
        asm     in      al, dx
        asm     test    al, ah
        asm     jz      loc_114E7
        asm     jmp     loc_114E0
        loc_114E7:
        asm     pop     ax
        asm     jb      loc_114FE
        asm     mov     cx, ax
        asm     call    loc_114B1
        asm     cmp     cx, ax
        asm     jnb     loc_114FC
        asm     mov     dx, 0FFFFh
        asm     sub     dx, ax
        asm     add     cx, dx
        asm     jmp     loc_114FE
        loc_114FC:
        asm     sub     cx, ax
        loc_114FE:
        asm     mov     ax, cx
}

int16_t F8114_(void (*P3297_pfv_)())
{
        ASM_STUB_PREFIX
        asm     pushf
        asm     cli
        G8090_ = P3297_pfv_;
        G8029_ = 1;
        asm     popf
        ASM_STUB_SUFFIX
        return 3;
}

void F8115_(char P3298_c_, char P3299_c_)
{
        asm     mov     dx, G8056_
        asm     mov     al, P3298_c_
        asm     out     dx, al
        asm     mov     cx, 0Ah
        loc_11536:
        asm     in      al, dx
        asm     loop    loc_11536
        asm     inc     dx
        asm     mov     al, P3299_c_
        asm     out     dx, al
        asm     mov     cx, 28h
        loc_11541:
        asm     in      al, dx
        asm     loop    loc_11541
}

void F8116_(int16_t P3300_i_)
{
        char L2675_c_;
        char L3686_ac_[4] = { 0xFE, 0xFB, 0xF6, 0xE1 };


        L2675_c_ = L3686_ac_[P3300_i_];
        F8115_(0x20, 0x21);
        F8115_(0x60, 0xF0);
        F8115_(0x80, 0xF0);
        F8115_(0xC0, 0x01);
        F8115_(0xE0, 0x00);
        F8115_(0x43, 0x3F);
        F8115_(0xB0, 0x01);
        asm     pushf
        asm     cli
        F8115_(0x04, 0x60);
        F8115_(0x04, 0x80);
        F8115_(0x02, L2675_c_);
        F8115_(0xA0, 0x0F);
        F8115_(0xB0, 0x2A);
        F8115_(0x04, 0x21);
        asm     mov     dx, 388h
        loc_1161B:
        asm     in      al, dx
        asm     and     al, 40h
        asm     jz      loc_1161B
        asm     popf
        F8115_(0xB0, 0x20);
        F8115_(0xA0, 0x00);
}

/* 202   char[4] = { 0xFE, 0xFB, 0xF6, 0xE1 }; /* L3686_ac_ in F8116_ */
char G8093_[230] = { 0x3F, 0x3E, 0x36, 0x32, 0x2E, 0x2C, 0x2A, 0x28, 0x26, 0x25, 0x24, 0x23, 0x22, 0x21, 0x20, 0x1F, 0x1E, 0x1E, 0x1D, 0x1C, 0x1C, 0x1B, 0x1B, 0x1A, 0x1A, 0x19, 0x19, 0x18, 0x18, 0x17, 0x17, 0x17, 0x16, 0x16, 0x16, 0x15, 0x15, 0x15, 0x14, 0x14, 0x14, 0x13, 0x13, 0x13, 0x13, 0x12, 0x12, 0x12, 0x12, 0x11, 0x11, 0x11, 0x11, 0x11, 0x10, 0x10, 0x10, 0x10, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 0x0E, 0x0E, 0x0E, 0x0E, 0x0E, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; /* only in F8120_ */
int16_t G8094_i_SoundDevice = 0; /* first in F8117_ */
int16_t G8095_ = -1;
int16_t G8096_ = -1;
int16_t G8097_ = 1;
int16_t G8098_[4] = { 1, 2, 4, 7 };


void F8117_(
)
{
        int16_t L2676_i_;
        int16_t L2677_i_;


        if (G8030_ == 1) {
                asm     mov     al, 0B6h
                asm     out     43h, al        /* Timer 8253-5 (AT: 8254.2). */
                asm     mov     al, 0
                asm     out     42h, al        /* Timer 8253-5 (AT: 8254.2). */
                asm     out     42h, al        /* Timer 8253-5 (AT: 8254.2). */
                asm     in      al, 61h        /* PC/XT PPI port B bits: */
                                               /* 0: Tmr 2 gate --- OR 03H=spkr ON */
                                               /* 1: Tmr 2 data -+  AND 0fcH=spkr OFF */
                                               /* 3: 1=read high switches */
                                               /* 4: 0=enable RAM parity checking */
                                               /* 5: 0=enable I/O channel check */
                                               /* 6: 0=hold keyboard clock low */
                                               /* 7: 0=enable kbrd */
                asm     or      al, 1
                asm     out     61h, al        /* PC/XT PPI port B bits: */
                                               /* 0: Tmr 2 gate --- OR 03H=spkr ON */
                                               /* 1: Tmr 2 data -+  AND 0fcH=spkr OFF */
                                               /* 3: 1=read high switches */
                                               /* 4: 0=enable RAM parity checking */
                                               /* 5: 0=enable I/O channel check */
                                               /* 6: 0=hold keyboard clock low */
                                               /* 7: 0=enable kbrd */
        } else {
                if ((G8030_ == 2) && G8052_) {
                        asm     mov     dx, G8052_
                        asm     add     dx, 2
                        asm     mov     al, 4
                        asm     out     dx, al
                }
        }
        asm     mov     dx, G8052_
        asm     mov     cs:V8117010_, dx
        if (G8052_ && ((G8094_i_SoundDevice == C3_FTL_SOUND_ADAPTER) || (G8094_i_SoundDevice == C5_DISNEY_SOUND_SOURCE))) {
                for (;;) { /*_Infinite loop_*/
                        asm     mov     ax, 500
                        loc_11696:
                        asm     dec     ax
                        asm     jnz     loc_11696
                        asm     in      al, dx
                        asm     cmp     al, 80h
                        asm     jz      loc_116A9
                        asm     mov     ah, 0FFh
                        asm     jnb     loc_116A4
                        asm     mov     ah, 1
                        loc_116A4:
                        asm     add     al, ah
                        asm     out     dx, al
                }
        }
        loc_116A9:
        asm     mov     ax, 3508h
        asm     int     21h            /* DOS - 2+ - GET INTERRUPT VECTOR */
                                       /* AL = interrupt number */
                                       /* Return: ES:BX = value of interrupt vector */
        asm     mov     word ptr cs:V8117000_, bx
        asm     mov     word ptr cs:V8117000_+2, es
        asm     push    ds
        asm     mov     dx, seg SE91_Vector
        asm     mov     ds, dx
        asm     mov     dx, offset SE91_Vector
        asm     mov     ax, 2508h
        asm     int     21h            /* DOS - SET INTERRUPT VECTOR */
                                       /* AL = interrupt number */
                                       /* DS:DX = new vector to be used for specified interrupt */
        asm     pop     ds
        return;
        asm     V8117000_  dd 0
        asm     V8117001_  dw offset loc_11994
        asm     V8117002_  dw 0
        asm     V8117003_  dw 6000
        asm     V8117004_ db 2 dup (0)
        asm     V8117005_  dd 0
        asm     V8117006_  dw 0
        asm     V8117007_  db 0
        asm                db 255 dup (0)
        asm     V8117008_ db 0
        asm     V8117009_  dw 0
        asm     V8117010_  dw 0
        asm     SE91_Vector:
        asm     jmp     cs:V8117001_
        asm     loc_117E6:
        asm     push    ax
        asm     mov     ax, cs:V8117002_
        asm     out     42h, al        /* Timer 8253-5 (AT: 8254.2). */
        asm     dec     ah
        asm     jz      loc_117FB
        asm     mov     cs:V8117002_, ax
        asm     mov     al, 20h
        asm     out     20h, al        /* Interrupt controller, 8259A. */
        asm     pop     ax
        asm     iret
        loc_117FB:
        asm     mov     ax, cs:V8117006_
        asm     or      ax, ax
        asm     jz      loc_11831
        asm     dec     cs:V8117006_
        asm     push    ds
        asm     push    si
        asm     lds     si, cs:V8117005_
        asm     cld
        asm     lodsb
        asm     add     si, cs:V8117009_
        asm     mov     word ptr cs:V8117005_, si
        asm     xor     ah, ah
        asm     mov     si, ax
        asm     mov     al, cs:[si+V8117007_]
        asm     mov     ah, 4
        asm     mov     cs:V8117002_, ax
        asm     pop     si
        asm     pop     ds
        asm     mov     al, 20h
        asm     out     20h, al        /* Interrupt controller, 8259A. */
        asm     sti
        loc_11831:
        asm     mov     ax, cs:V8117003_
        asm     add     word ptr cs:V8117004_, ax
        asm     jb      loc_11842
        asm     mov     al, 20h
        asm     out     20h, al        /* Interrupt controller, 8259A. */
        asm     pop     ax
        asm     iret
        loc_11842:
        asm     pushf
        asm     cli
        asm     cmp     cs:V8117006_, 0
        asm     jz      loc_1184F
        asm     jmp     loc_11992
        loc_1184F:
        asm     mov     al, 0B6h
        asm     out     43h, al        /* Timer 8253-5 (AT: 8254.2). */
        asm     mov     al, 8
        asm     out     42h, al        /* Timer 8253-5 (AT: 8254.2). */
        asm     mov     al, 0
        asm     out     42h, al        /* Timer 8253-5 (AT: 8254.2). */
        asm     jmp     loc_1197B
        asm     loc_1185E:
        asm     push    ax
        asm     mov     ax, cs:V8117006_
        asm     or      ax, ax
        asm     jnz     loc_1186A
        asm     jmp     loc_11960
        loc_1186A:
        asm     dec     cs:V8117006_
        asm     push    ds
        asm     push    si
        asm     lds     si, cs:V8117005_
        asm     cld
        asm     lodsb
        asm     add     si, cs:V8117009_
        asm     mov     word ptr cs:V8117005_, si
        asm     push    dx
        asm     xor     ah, ah
        asm     mov     si, ax
        asm     mov     al, cs:[si+V8117007_]
        asm     mov     dx, cs:V8117010_
        asm     out     dx, al
        asm     add     dx, 2
        asm     in      al, dx
        asm     mov     ah, al
        asm     or      al, 8
        asm     out     dx, al
        asm     jmp     $+2
        asm     jmp     $+2
        asm     mov     al, ah
        asm     and     al, 0F7h
        asm     out     dx, al
        asm     pop     dx
        asm     pop     si
        asm     pop     ds
        asm     jmp     loc_11960
        asm     loc_118AA:
        asm     push    ax
        asm     mov     ax, cs:V8117006_
        asm     or      ax, ax
        asm     jnz     loc_118B6
        asm     jmp     loc_11960
        loc_118B6:
        asm     dec     cs:V8117006_
        asm     push    ds
        asm     push    si
        asm     lds     si, cs:V8117005_
        asm     cld
        asm     lodsb
        asm     add     si, cs:V8117009_
        asm     mov     word ptr cs:V8117005_, si
        asm     push    dx
        asm     xor     ah, ah
        asm     mov     si, ax
        asm     mov     dx, cs:V8117010_
        loc_118D8:
        asm     in      al, dx
        asm     or      al, al
        asm     js      loc_118D8
        asm     mov     al, 10h
        asm     out     dx, al
        loc_118E0:
        asm     in      al, dx
        asm     or      al, al
        asm     js      loc_118E0
        asm     mov     al, cs:[si+V8117007_]
        asm     out     dx, al
        asm     pop     dx
        asm     pop     si
        asm     pop     ds
        asm     jmp     loc_11960
        asm     loc_118F1:
        asm     push    ax
        asm     mov     ax, cs:V8117006_
        asm     or      ax, ax
        asm     jnz     loc_118FD
        asm     jmp     loc_11960
        loc_118FD:
        asm     dec     cs:V8117006_
        asm     push    ds
        asm     push    si
        asm     lds     si, cs:V8117005_
        asm     cld
        asm     lodsb
        asm     add     si, cs:V8117009_
        asm     mov     word ptr cs:V8117005_, si
        asm     push    dx
        asm     xor     ah, ah
        asm     mov     si, ax
        asm     mov     al, cs:[si+V8117007_]
        asm     mov     dx, cs:V8117010_
        asm     inc     dx
        asm     out     dx, al
        asm     pop     dx
        asm     pop     si
        asm     pop     ds
        asm     jmp     loc_11960
        asm     loc_1192C:
        asm     push    ax
        asm     mov     ax, cs:V8117006_
        asm     or      ax, ax
        asm     jz      loc_11960
        asm     dec     cs:V8117006_
        asm     push    ds
        asm     push    si
        asm     lds     si, cs:V8117005_
        asm     cld
        asm     lodsb
        asm     add     si, cs:V8117009_
        asm     mov     word ptr cs:V8117005_, si
        asm     push    dx
        asm     xor     ah, ah
        asm     mov     si, ax
        asm     mov     al, cs:[si+V8117007_]
        asm     mov     dx, cs:V8117010_
        asm     out     dx, al
        asm     pop     dx
        asm     pop     si
        asm     pop     ds
        loc_11960:
        asm     mov     ax, cs:V8117003_
        asm     add     word ptr cs:V8117004_, ax
        asm     jb      loc_11971
        asm     mov     al, 20h
        asm     out     20h, al        /* Interrupt controller, 8259A. */
        asm     pop     ax
        asm     iret
        loc_11971:
        asm     pushf
        asm     cli
        asm     cmp     cs:V8117006_, 0
        asm     jnz     loc_11992
        loc_1197B:
        asm     mov     al, 36h
        asm     out     43h, al        /* Timer 8253-5 (AT: 8254.2). */
        asm     mov     al, 0
        asm     out     40h, al        /* Timer 8253-5 (AT: 8254.2). */
        asm     out     40h, al        /* Timer 8253-5 (AT: 8254.2). */
        asm     mov     cs:V8117001_, offset loc_11994
        asm     mov     cs:V8117008_, 0
        loc_11992:
        asm     popf
        asm     pop     ax
        asm     loc_11994:
        asm     push    es
        asm     push    ds
        asm     push    ax
        asm     push    bx
        asm     push    cx
        asm     push    dx
        asm     push    si
        asm     push    di
        asm     push    bp
        asm     push    ss
        asm     mov     ax, cs:V0000000_DataSegment
        asm     mov     ds, ax
        if ((G8028_ == 0) && (G8029_ != 0)) {
                (*G8090_)();
        }
        if ((G8030_ == 1) && (G8058_ == 0) && (G8031_ == 0)) {
                G8031_ = 1;
                asm     mov     al, 20h
                asm     out     20h, al        /* Interrupt controller, 8259A. */
                asm     sti
                if (G8055_++ & 1) {
                        G8064_ = (F8113_(1) - 100) / G8033_;
                } else {
                        G8045_ = G8064_;
                        if (G8045_ > 319) {
                                G8045_ = 319;
                        } else {
                                if (G8045_ < 0) {
                                        G8045_ = 0;
                                }
                        }
                        G8046_ = (F8113_(2) - 100) / G8034_;
                        if (G8046_ > 199) {
                                G8046_ = 199;
                        } else {
                                if (G8046_ < 0) {
                                        G8046_ = 0;
                                }
                        }
                }
                asm     mov     dx, 201h
                asm     in      al, dx         /* Game I/O port */
                                               /* bits 0-3: Coordinates (resistive, time-dependent inputs) */
                                               /* bits 4-7: Buttons/Triggers (digital inputs) */
                G8049_ = _AX;
                G8049_ = ((G8049_ >> 4) ^ 3) & 3;
                G8031_ = 0;
        } else {
                if ((G8030_ != 2) && (G8030_ != 3)) {
                        asm     jmp     loc_11D20
                }
                if (G8052_ && (G8030_ == 2)) {
                        asm     mov     dx, cs:20C0h
                        asm     add     dx, 1
                        asm     in      al, dx
                        G8065_ = _AL;
                } else {
                        G8065_ = 120;
                }
                if (G8050_ == 1) {
                        if ((G8065_ & 0x80) == 0) {
                                G8050_ = 0;
                        } else {
                                if ((G8065_ ^ G8053_) & 0x78) {
                                        if ((G8065_ & 0x08) == 0) {
                                                F8087_(72);
                                        } else {
                                                if ((G8065_ & 0x10) == 0) {
                                                        F8087_(80);
                                                } else {
                                                        if ((G8065_ & 0x20) == 0) {
                                                                F8087_(71);
                                                        } else {
                                                                if ((G8065_ & 0x40) == 0) {
                                                                        F8087_(73);
                                                                }
                                                        }
                                                }
                                        }
                                }
                        }
                }
                if (!G8050_) {
                        if (!G8058_) {
                                if (((G8065_ & 0x78) != 0x78) || ((G8078_ & 0x0F) != 0)) {
                                        if (((G8065_ & 0x08) == 0) || (G8078_ & 1)) {
                                                G8046_ -= ((++G8048_ + 1) / 3) + 1;
                                        }
                                        if (((G8065_ & 0x10) == 0) || (G8078_ & 2)) {
                                                G8046_ += ((++G8048_ + 1) / 3) + 1;
                                        }
                                        if (((G8065_ & 0x40) == 0) || (G8078_ & 8)) {
                                                G8045_ += ((++G8047_ + 1) / 3) + 1;
                                        }
                                        if (((G8065_ & 0x20) == 0) || (G8078_ & 4)) {
                                                G8045_ -= ((++G8047_ + 1) / 3) + 1;
                                        }
                                }
                                if (G8047_ > 100) {
                                        G8047_ = 100;
                                }
                                if (G8048_ > 100) {
                                        G8048_ = 100;
                                }
                                if (G8045_ < 0) {
                                        G8045_ = 0;
                                }
                                if (G8045_ > 319) {
                                        G8045_ = 319;
                                }
                                if (G8046_ < 0) {
                                        G8046_ = 0;
                                }
                                if (G8046_ > 199) {
                                        G8046_ = 199;
                                }
                        }
                        if ((G8065_ ^ G8053_) & 0x18) {
                                G8048_ = 0;
                        }
                        if ((G8065_ ^ G8053_) & 0x60) {
                                G8047_ = 0;
                        }
                        if ((G8078_ ^ G8084_) & 0x03) {
                                G8048_ = 0;
                        }
                        if ((G8078_ ^ G8084_) & 0x0C) {
                                G8047_ = 0;
                        }
                        G8049_ = ((G8065_ >> 7) & 1) | (((int16_t)G8078_ >> 4) & 1);
                        if ((G8065_ & 0x80) && (((G8045_ >= 232) && (G8045_ <= 319) && (G8046_ >= 123) && (G8046_ <= 168)) || (G8046_ > 168))) {
                                G8050_ = 1;
                        }
                }
                G8053_ = G8065_;
                G8084_ = G8078_;
        }
        asm     mov     cx, G8045_
        asm     mov     dx, G8046_
        asm     mov     bx, G8049_
        asm     pushf
        asm     cli
        asm     cmp     G8060_, 0
        asm     jz      loc_11CBA
        asm     jmp     loc_11CC8
        loc_11CBA:
        asm     popf
        asm     push    bx
        asm     push    dx
        asm     push    cx
        asm     push    cs
        asm     call    near ptr F8096_ProcessMouseState
        asm     add     sp, 6
        asm     jmp     loc_11D20
        loc_11CC8:
        asm     cmp     G8070_MouseStateHistoryCount, 10
        asm     jge     loc_11D1F
        if (G8070_MouseStateHistoryCount) {
                asm     mov     di, G8057_
                asm     mov     ax, di
                asm     add     di, ax
                asm     add     di, ax
                asm     add     di, di
                asm     cmp     [di+G2335_aai_MouseStateHistory], bx
                asm     jnz     loc_11CF3
                asm     mov     [di+G2335_aai_MouseStateHistory+2], cx
                asm     mov     [di+G2335_aai_MouseStateHistory+4], dx
                asm     popf
                asm     jmp     loc_11D20
        }
        loc_11CF3:
        G8070_MouseStateHistoryCount++;
        asm     mov     di, G8057_
        asm     inc     di
        asm     cmp     di, 0Ah
        asm     jnz     loc_11D04
        asm     mov     di, 0
        loc_11D04:
        asm     mov     G8057_, di
        asm     mov     ax, di
        asm     add     di, ax
        asm     add     di, ax
        asm     add     di, di
        asm     mov     [di+G2335_aai_MouseStateHistory], bx
        asm     mov     [di+G2335_aai_MouseStateHistory+2], cx
        asm     mov     [di+G2335_aai_MouseStateHistory+4], dx
        asm     popf
        asm     jmp     loc_11D20
        loc_11D1F:
        asm     popf
        loc_11D20:
        asm     pop     ss
        asm     pop     bp
        asm     pop     di
        asm     pop     si
        asm     pop     dx
        asm     pop     cx
        asm     pop     bx
        asm     pop     ax
        asm     pop     ds
        asm     pop     es
        asm     jmp     cs:V8117000_
}

void F8118_(
)
{
        G8029_ = 0;
        loc_11D3C:
        asm     cmp     cs:V8117008_, 0
        asm     jnz     loc_11D3C
        asm     push    ds
        asm     mov     dx, word ptr cs:V8117000_+2
        asm     mov     ds, dx
        asm     mov     dx, word ptr cs:V8117000_
        asm     mov     ax, 2508h
        asm     int     21h            /* DOS - SET INTERRUPT VECTOR */
                                       /* AL = interrupt number */
                                       /* DS:DX = new vector to be used for specified interrupt */
        asm     pop     ds
        asm     in      al, 61h        /* PC/XT PPI port B bits: */
                                       /* 0: Tmr 2 gate --- OR 03H=spkr ON */
                                       /* 1: Tmr 2 data -+  AND 0fcH=spkr OFF */
                                       /* 3: 1=read high switches */
                                       /* 4: 0=enable RAM parity checking */
                                       /* 5: 0=enable I/O channel check */
                                       /* 6: 0=hold keyboard clock low */
                                       /* 7: 0=enable kbrd */
        asm     and     al, 0FCh
        asm     out     61h, al        /* PC/XT PPI port B bits: */
                                       /* 0: Tmr 2 gate --- OR 03H=spkr ON */
                                       /* 1: Tmr 2 data -+  AND 0fcH=spkr OFF */
                                       /* 3: 1=read high switches */
                                       /* 4: 0=enable RAM parity checking */
                                       /* 5: 0=enable I/O channel check */
                                       /* 6: 0=hold keyboard clock low */
                                       /* 7: 0=enable kbrd */
}

void F8119_(char* P3301_pc_, unsigned int16_t P3302_ui_, int16_t P3303_i_, unsigned int16_t P3304_ui_)
{
        unsigned int16_t L2678_ui_;
        int16_t L2679_i_;
        unsigned char L2680_uc_;


        if (P3304_ui_ > 8000) {
                P3304_ui_ = P3304_ui_ >> 1;
                P3302_ui_ = P3302_ui_ >> 1;
                asm     mov     cs:V8117009_, 1
        } else {
                asm     mov     cs:V8117009_, 0
        }
        L2679_i_ = (unsigned long)1193180 / P3304_ui_;
        asm     pushf
        asm     cli
        if (P3303_i_ != G8095_) {
                for (L2678_ui_ = 0; L2678_ui_ < 256; L2678_ui_++) {
                        L2680_uc_ = (L2679_i_ * L2678_ui_) >> (13 - P3303_i_);
                        if (L2680_uc_ == 0) {
                                L2680_uc_++;
                        }
                        asm     mov     al, L2680_uc_
                        asm     mov     bx, L2678_ui_
                        asm     mov     cs:[bx+V8117007_], al
                }
                G8095_ = P3303_i_;
        }
        asm     cmp     cs:V8117006_, 0
        asm     pushf
        asm     les     bx, P3301_pc_
        asm     mov     word ptr cs:V8117005_, bx
        asm     mov     ax, es
        asm     mov     word ptr cs:V8117005_+2, ax
        asm     mov     ax, P3302_ui_
        asm     mov     cs:V8117006_, ax
        asm     mov     cs:V8117008_, 1
        asm     mov     cs:V8117002_, 120h
        asm     popf
        asm     jnz     loc_11E39
        asm     mov     al, 36h
        asm     out     43h, al        /* Timer 8253-5 (AT: 8254.2). */
        asm     mov     ax, L2679_i_
        asm     mov     cs:V8117003_, ax
        asm     shr     ax, 1
        asm     shr     ax, 1
        asm     out     40h, al        /* Timer 8253-5 (AT: 8254.2). */
        asm     mov     al, ah
        asm     out     40h, al        /* Timer 8253-5 (AT: 8254.2). */
        asm     mov     al, 90h
        asm     out     43h, al        /* Timer 8253-5 (AT: 8254.2). */
        asm     in      al, 61h        /* PC/XT PPI port B bits: */
                                       /* 0: Tmr 2 gate --- OR 03H=spkr ON */
                                       /* 1: Tmr 2 data -+  AND 0fcH=spkr OFF */
                                       /* 3: 1=read high switches */
                                       /* 4: 0=enable RAM parity checking */
                                       /* 5: 0=enable I/O channel check */
                                       /* 6: 0=hold keyboard clock low */
                                       /* 7: 0=enable kbrd */
        asm     or      al, 3
        asm     out     61h, al        /* PC/XT PPI port B bits: */
                                       /* 0: Tmr 2 gate --- OR 03H=spkr ON */
                                       /* 1: Tmr 2 data -+  AND 0fcH=spkr OFF */
                                       /* 3: 1=read high switches */
                                       /* 4: 0=enable RAM parity checking */
                                       /* 5: 0=enable I/O channel check */
                                       /* 6: 0=hold keyboard clock low */
                                       /* 7: 0=enable kbrd */
        asm     mov     cs:V8117001_, offset loc_117E6
        loc_11E39:
        asm     popf
}

void F8120_(char* P3305_pc_, unsigned int16_t P3306_ui_, int16_t P3307_i_, unsigned int16_t P3308_ui_, int16_t P3309_i_, int16_t P3310_i_)
{
        unsigned int16_t L2681_ui_;
        int16_t L2682_i_;
        unsigned char L2683_uc_;


        if ((P3308_ui_ > 8000) && P3310_i_) {
                P3308_ui_ = P3308_ui_ >> 1;
                P3306_ui_ = P3306_ui_ >> 1;
                asm     mov     cs:V8117009_, 1
        } else {
                asm     mov     cs:V8117009_, 0
        }
        L2682_i_ = (unsigned long)1193180 / P3308_ui_;
        if (!G8052_) {
                return;
        }
        asm     pushf
        asm     cli
        if (G8096_ != P3307_i_) {
                if (G8097_) {
                        for (L2681_ui_ = 0; L2681_ui_ < 256; L2681_ui_++) {
                                if (P3309_i_ == 7) {
                                        L2683_uc_ = G8093_[(L2681_ui_ * 220) >> 8];
                                } else {
                                        L2683_uc_ = ((char)(L2681_ui_ + 128) >> (3 - P3307_i_)) + 128;
                                }
                                asm     mov     al, L2683_uc_
                                asm     mov     bx, L2681_ui_
                                asm     mov     cs:[bx+V8117007_], al
                        }
                }
                G8096_ = P3307_i_;
                if (P3309_i_ == 7) {
                        F8116_(P3307_i_);
                        G8097_ = 0;
                }
        }
        asm     cmp     cs:V8117006_, 0
        asm     pushf
        asm     les     bx, P3305_pc_
        asm     mov     word ptr cs:V8117005_, bx
        asm     mov     ax, es
        asm     mov     word ptr cs:V8117005_+2, ax
        asm     mov     ax, P3306_ui_
        asm     mov     cs:V8117006_, ax
        asm     mov     cs:V8117008_, 1
        asm     popf
        asm     jnz     loc_11F78
        asm     mov     al, 36h
        asm     out     43h, al        /* Timer 8253-5 (AT: 8254.2). */
        asm     mov     ax, L2682_i_
        asm     mov     cs:V8117003_, ax
        asm     out     40h, al        /* Timer 8253-5 (AT: 8254.2). */
        asm     mov     al, ah
        asm     out     40h, al        /* Timer 8253-5 (AT: 8254.2). */
        switch (P3309_i_) {
                case 5:
                        asm     mov     cs:V8117001_, offset loc_1185E
                        break;
                case 3:
                        asm     mov     cs:V8117001_, offset loc_1192C
                        break;
                case 7:
                        asm     mov     dx, cs:V8117010_
                        asm     mov     al, 40h
                        asm     out     dx, al
                        asm     mov     cs:V8117001_, offset loc_118F1
                        break;
                case 6:
                        asm     mov     cs:V8117001_, offset loc_118AA
                        break;
                case 4: ;
        }
        loc_11F78:
        asm     popf
}

void F8121_(char* P3311_pc_, int16_t P3312_i_, int16_t P3313_i_, unsigned int16_t P3314_ui_)
{
        int16_t L2684_i_;


        P3314_ui_ = (unsigned long)3579545 / P3314_ui_;
        P3313_i_ = G8098_[P3313_i_];
        asm     mov     ah, 81h
        asm     int     1Ah
        asm     jnb     loc_11FBF
        asm     mov     ah, 84h
        asm     int     1Ah
        loc_11FB9:
        asm     mov     ah, 81h
        asm     int     1Ah
        asm     jb      loc_11FB9
        loc_11FBF:
        asm     les     di, P3311_pc_
        asm     mov     bx, di
        asm     mov     cx, P3312_i_
        asm     mov     dx, P3314_ui_
        asm     mov     ax, P3313_i_
        asm     mov     ah, 83h
        asm     int     1Ah
}

void F8122_(char* P3315_pc_, int16_t P3316_i_, int16_t P3317_i_, int16_t P3318_i_)
{
        ASM_STUB_PREFIX
        switch (G8094_i_SoundDevice) {
                case C2_PC_SPKR_SOUND:
                        F8119_(P3315_pc_, P3316_i_, P3317_i_, P3318_i_);
                        break;
                case C3_FTL_SOUND_ADAPTER:
                        F8120_(P3315_pc_, P3316_i_, P3317_i_, P3318_i_, 3, 0);
                        break;
                case C4_TANDY_1000_TLSL_SOUND:
                        F8121_(P3315_pc_, P3316_i_, P3317_i_, P3318_i_);
                        break;
                case C5_DISNEY_SOUND_SOURCE:
                        F8120_(P3315_pc_, P3316_i_, P3317_i_, P3318_i_, 5, 1);
                        break;
                case C6_SOUND_BLASTER:
                        F8120_(P3315_pc_, P3316_i_, P3317_i_, P3318_i_, 6, 0);
                        break;
                case C7_ADLIB_SOUND:
                        F8120_(P3315_pc_, P3316_i_, P3317_i_, P3318_i_, 7, 1);
        }
        ASM_STUB_SUFFIX
}

void F8123_PlayAudioCDTrack(
)
{
}

int16_t F8124_IsSoundPlayComplete(
)
{
        switch (G8094_i_SoundDevice) {
                case C2_PC_SPKR_SOUND:
                case C3_FTL_SOUND_ADAPTER:
                case C5_DISNEY_SOUND_SOURCE:
                case C7_ADLIB_SOUND:
                        asm     mov     ax, cs:V8117006_
                        asm     jmp     loc_12097
                case C6_SOUND_BLASTER:
                        asm     mov     ax, cs:V8117006_
                        asm     jmp     loc_12097
                case C4_TANDY_1000_TLSL_SOUND:
                        asm     mov     ah, 81h
                        asm     int     1Ah
                        asm     mov     ax, 0
                        asm     rcl     ax, 1
                        asm     jmp     loc_12097
        }
        return 0;
        loc_12097: ;
}

int16_t F8125_(char* P3319_pc_, int16_t P3320_i_, int16_t P3321_i_, int16_t P3322_i_)
{
        int16_t L2685_i_ = 0;


        ASM_STUB_PREFIX
        switch (G8094_i_SoundDevice) {
                case C2_PC_SPKR_SOUND:
                case C3_FTL_SOUND_ADAPTER:
                case C4_TANDY_1000_TLSL_SOUND:
                case C5_DISNEY_SOUND_SOURCE:
                case C6_SOUND_BLASTER:
                case C7_ADLIB_SOUND:
                        if (!F8124_IsSoundPlayComplete()) {
                                F8122_(P3319_pc_, P3320_i_, P3321_i_, P3322_i_);
                                L2685_i_ = 1;
                        }
        }
        ASM_STUB_SUFFIX
        return L2685_i_;
}

int16_t F8126_(
)
{
        return 0;
}

void F8127_(
)
{
        char L2686_ac_[1] = { 0x80 };


        F8122_(L2686_ac_, 1, 0, 6000);
}

void F8128_WaitSoundPlayComplete(
)
{
        ASM_STUB_PREFIX
        switch (G8094_i_SoundDevice) {
                case C1_NO_SOUND:
                case C2_PC_SPKR_SOUND:
                case C3_FTL_SOUND_ADAPTER:
                case C5_DISNEY_SOUND_SOURCE:
                        loc_1214B:
                        asm     mov     al, cs:V8117008_
                        asm     cmp     al, 0
                        asm     jnz     loc_1214B
                        break;
                case C4_TANDY_1000_TLSL_SOUND:
                default:
                        while (F8124_IsSoundPlayComplete());
        }
        ASM_STUB_SUFFIX
}

int16_t G8099_ai_ConvertedDeviceType[8] = {
        16,     /* 00h 320/360k disk              */
        17,     /* 01h 1.2M 5.25 inch disk        */
        18,     /* 02h 720K 3.5 inch disk         */
        0,      /* 03h single density 8-inch disk */
        0,      /* 04h double-density 8-inch disk */
        1,      /* 05h fixed disk                 */
        0,      /* 06h tape drive                 */
        19 };   /* 07h 1.44M 3.5 inch disk        */

int16_t F8129_GetConvertedDeviceType(int16_t P3323_i_DriveNumber)
{
        unsigned char L2687_auc_[64];
        unsigned char* L2688_puc_ = L2687_auc_;
        int16_t L2689_i_;


        ASM_STUB_PREFIX
        L2687_auc_[0] = 0;
        asm     mov     ax, 440Dh      /* INT 21,44,D / IOCTL,D - Generic I/O for Block Devices */
        asm     mov     bx, P3323_i_DriveNumber
        asm     mov     cx, 860h       /* 08 for disk drive (block device) / 60 get device parameters */
        asm     push    ds
        asm     lds     dx, L2688_puc_      /* DS:DX pointer to parameter block */
        asm     int     21h            /* DOS - 2+ - IOCTL - */
        asm     pop     ds
        L2689_i_ = G8099_ai_ConvertedDeviceType[L2687_auc_[1]]; /* BUGX_XX: G8099_ai_ConvertedDeviceType only contains 8 bytes, no boundary check on the value of L2687_auc_[1]. For example, with a 2.88MB floppy disk drive on DOS 5.0, this would return 9 and read a byte outside of the array */
        /* The value of L2687_auc_[1] is the device type:
        00h     320/360k disk
        01h     1.2M 5.25 inch disk
        02h     720K 3.5 inch disk
        03h     single density 8-inch disk
        04h     double-density 8-inch disk
        05h     fixed disk
        06h     tape drive
        07h     1.44M 3.5 inch disk
        08h     other type of block device
        09h     2.88M 3.5 inch disk */
        ASM_STUB_SUFFIX
        return L2689_i_;
}

int16_t F8130_GetReadFirstSectorResult(int16_t P3324_i_DriveOrdinal)  /* Can only return 0 or 1. The PC implementation does not check for write-protection of the floppy disk and does not identify the reason of a read failure */
{
        char L2690_ac_SectorData[512];
        char* L2691_pc_SectorAddress = L2690_ac_SectorData;
        int16_t L2692_i_;


        ASM_STUB_PREFIX
        P3324_i_DriveOrdinal--;
        for (L2692_i_ = 0; L2692_i_ < 3; L2692_i_++) {
                asm     mov     ah, 2
                asm     mov     al, 1   /* Read 1 sector */
                asm     mov     ch, 0   /* on track 0 */
                asm     mov     cl, 1   /* from sector #1 */
                asm     mov     dx, P3324_i_DriveOrdinal
                asm     mov     dh, 0   /* Head 0 */
                asm     les     bx, L2691_pc_SectorAddress
                asm     int     13h            /* DISK - READ SECTORS INTO MEMORY */
                                               /* AL = number of sectors to read, CH = track, CL = sector */
                                               /* DH = head, DL = drive, ES:BX -> buffer to fill */
                                               /* Return: CF set on error, AH = status, AL = number of sectors read */
                asm     mov     ax, 1
                asm     jnb     loc_121F1
                asm     mov     ah, 0
                asm     mov     dx, P3324_i_DriveOrdinal
                asm     int     13h            /* DISK - RESET DISK SYSTEM */
                                               /* DL = drive (if bit 7 is set both hard disks and floppy disks reset) */
        }
        asm     mov     ax, 0
        loc_121F1:
        ASM_STUB_SUFFIX
}

struct xfcb G8100_ExtendedFCB = {
        0xFF,
        "",
        8, /* Volume label */
        {
                0,
                "????????",     /* File name */
                "???",          /* Extension */
                0,
                0,
                0,
                0,
                "",
                0,
                0
        } };

void F8131_GetVolumeName(char P3325_c_Drive, char* P3326_pc_VolumeName)
{
        int16_t L2693_i_;


        ASM_STUB_PREFIX
        /* Search for volume name in FAT. G8100_ExtendedFCB already contains the searched criteria: Name=any, Extension=any, Attributes=Volume Name */
        *P3326_pc_VolumeName = 0;
        G8100_ExtendedFCB.xfcb_fcb.fcb_drive = P3325_c_Drive;
        asm     mov     dx, offset G8100_ExtendedFCB
        asm     mov     ah, 11h
        asm     int     21h            /* DOS - SEARCH FIRST USING FCB */
                                       /* DS:DX -> FCB */
        asm     test    al, al
        asm     jnz     loc_12240
        asm     mov     ah, 2Fh
        asm     int     21h            /* DOS - GET DISK TRANSFER AREA ADDRESS */
                                       /* Return: ES:BX -> DTA */
        asm     mov     cx, 11         /* File name character count */
        /* Copy volume name to P3326_pc_VolumeName, except ' ' and '.'  */
        asm     push    ds
        asm     lds     si, P3326_pc_VolumeName
        loc_12225:
        asm     mov     al, es:[bx+8]  /* Filename is at offset 8 in FCB stored in DTA */
        asm     cmp     al, 20h
        asm     jz      loc_12234
        asm     cmp     al, 2Eh
        asm     jz      loc_12234
        asm     mov     [si], al
        asm     inc     si
        loc_12234:
        asm     inc     bx
        asm     or      al, al
        asm     jz      loc_1223C
        asm     dec     cx
        asm     jnz     loc_12225
        loc_1223C:
        /* Mark end of P3326_pc_VolumeName string */
        asm     mov     byte ptr [si], 0
        asm     pop     ds
        loc_12240:
        ASM_STUB_SUFFIX
}

void F8132_GetRandomSeed(
)
{
        asm     mov     ah, 2Ch
        asm     int     21h            /* DOS - GET CURRENT TIME */
                                       /* Return: CH = hours, CL = minutes, DH = seconds */
                                       /* DL = hundredths of seconds */
        asm     mov     ax, dx
}

void F8133_ReadFloppySector(
)
{
}

int16_t F8134_ExecuteProgramWithParameters(char* P3327_pc_Filename, char* P3328_pc_)
{
        char* L2694_pc_;
        unsigned char L2695_auc_[80];


        L2694_pc_ = L2695_auc_;
        strcpy(&L2695_auc_[1], P3328_pc_);
        L2695_auc_[(L2695_auc_[0] = strlen(P3328_pc_)) + 1] = '\r';
        goto loc_122CD;
        asm     V8134000_    dw 0
        asm     V8134001_   dd 0
        asm     dd V8134002_
        asm     dd V8134002_
        asm     V8134002_    db 0, 0Bh dup(20h), 19h dup(0)
        asm     V8134003_   dd 0
        loc_122CD:
        asm     les     ax, L2694_pc_
        asm     mov     word ptr cs:V8134001_, ax
        asm     mov     ax, es
        asm     mov     word ptr cs:V8134001_+2, ax
        asm     push    ds
        asm     mov     bx, offset V8134000_
        asm     mov     ax, cs
        asm     mov     es, ax
        asm     lds     dx, P3327_pc_Filename
        asm     mov     ax, 4B00h
        asm     mov     word ptr cs:V8134003_, sp
        asm     mov     word ptr cs:V8134003_+2, ss
        asm     cld
        asm     int     21h
        asm     mov     ss, word ptr cs:V8134003_+2
        asm     mov     sp, word ptr cs:V8134003_
        asm     pop     ds
        asm     mov     ah, 4Dh
        asm     int     21h
        asm     cmp     ah, 0
        asm     mov     ah, 0
        asm     jz      loc_1230E
        asm     mov     ax, 0FFFFh
        loc_1230E: ;
        /* ; DOS - 2+ - LOAD OR EXECUTE (EXEC)
           ; DS:DX -> ASCIZ filename
           ; ES:BX -> parameter block
           ; AL = subfunc: load & execute program */
        /* ; DOS - 2+ - GET EXIT CODE OF SUBPROGRAM (WAIT) */
}

int16_t F8135_(
)
{
        return 0;
}

void F8136_(
)
{
}


char* G8101_apc_IOInterruptVector[31] = {
        (char*)F8090_, /*  0 */
        (char*)F8091_, /*  1 */
        (char*)F8101_SetMouseHandler, /*  2 */
        (char*)F8097_, /*  3 */
        (char*)F8098_ProcessMouseStateHistory, /*  4 */
        (char*)F8099_LockMouse, /*  5 */
        (char*)F8100_UnlockMouse, /*  6 */
        (char*)F8106_, /*  7 */
        (char*)F8107_, /*  8 */
        (char*)F8108_RegisterMousePointerBitmap, /*  9 */
        (char*)F8109_SetMousePointer, /* 10 */
        (char*)F1040_SetMouseBoundEvent, /* 11 */
        (char*)F8111_SetMousePointerCoordinates, /* 12 */
        (char*)F8112_GetMouseState, /* 13 */
        (char*)F8114_, /* 14 */
        (char*)F8122_, /* 15 */
        (char*)F8128_WaitSoundPlayComplete, /* 16 */
        (char*)F8126_, /* 17 */
        (char*)F8130_GetReadFirstSectorResult, /* 18 */
        (char*)F8131_GetVolumeName, /* 19 */
        (char*)F8129_GetConvertedDeviceType, /* 20 */
        (char*)F8132_GetRandomSeed, /* 21 */
        (char*)F8133_ReadFloppySector, /* 22 */
        (char*)F8123_PlayAudioCDTrack, /* 23 */
        (char*)F8125_, /* 24 */
        (char*)F8093_, /* 25 */
        (char*)F8092_ConvertScanCodeToASCII, /* 26 */
        (char*)F8135_, /* 27 */
        (char*)F8136_, /* 28 */
        (char*)F8136_, /* 29 */
        (char*)F8136_  /* 30 */
};
COMMAND_LINE G8102_CommandLines[6] = {
        { "swoosh",   "",              0, { 2, 0, 0, 0 } },
        { "anim",     "title -ah -as", 0, { 3, 0, 0, 0 } },
        { "selector", "",              3, { 4, 0, 4, 5 } },
        { "@1",       "",              1, { 0, 6, 0, 0 } },
        { "@1",       "-x",            1, { 0, 6, 0, 0 } },
        { "anim",     "end -as -ae",   0, { 0, 0, 0, 0 } } };
int16_t G8103_ = 1;
int16_t G8104_ = 0;


void main(int16_t argc, unsigned char* argv[])
{
        char L2696_c_;
        int16_t L2697_i_;
        int16_t L2698_i_;
        int16_t L2699_i_;
        char L2700_ac_[80] = "";
        char L2701_ac_[80];
        static int16_t G2361_LPTPorts[3] = { 0x3BC, 0x378, 0x278 };
        int16_t L2702_i_;
        int16_t L2703_i_;


        for (L2702_i_ = 1; L2702_i_ < argc; L2702_i_++) {
                if (argv[L2702_i_][0] == '-') {
                        switch(toupper(argv[L2702_i_][1])) {
                                case 'S':
                                        switch(toupper(argv[L2702_i_][2])) {
                                                case 'I':
                                                        G8094_i_SoundDevice = C2_PC_SPKR_SOUND;
                                                        break;
                                                case 'N':
                                                        G8094_i_SoundDevice = C1_NO_SOUND;
                                                        break;
                                                case 'T':
                                                        G8094_i_SoundDevice = C4_TANDY_1000_TLSL_SOUND;
                                                        break;
                                                case 'D':
                                                        G8094_i_SoundDevice = C5_DISNEY_SOUND_SOURCE;
                                                        L2698_i_ = toupper(argv[L2702_i_][3]);
                                                        if ((L2698_i_ >= '1') && (L2698_i_ <= '3')) {
                                                                G8052_ = G2361_LPTPorts[L2698_i_ - '0' - 1];
                                                        }
                                                        asm     mov     dx, G8052_
                                                        asm     add     dx, 2
                                                        asm     in      al, dx
                                                        asm     and     al, 0F7h
                                                        asm     out     dx, al
                                                        break;
                                                case 'B':
                                                        G8094_i_SoundDevice = C6_SOUND_BLASTER;
                                                        L2698_i_ = toupper(argv[L2702_i_][3]);
                                                        if ((L2698_i_ >= '1') && (L2698_i_ <= '6')) {
                                                                G8000_ = 0x200 + ((L2698_i_ - '0') << 4);
                                                        }
                                                        G8052_ = G8000_ + 12;
                                                        break;
                                                case 'A':
                                                        G8056_ = G8052_ = 0x388;
                                                        G8094_i_SoundDevice = C7_ADLIB_SOUND;
                                                        break;
                                                case 'F':
                                                        G8094_i_SoundDevice = C3_FTL_SOUND_ADAPTER;
                                                        L2698_i_ = toupper(argv[L2702_i_][3]);
                                                        if ((L2698_i_ >= '1') && (L2698_i_ <= '3')) {
                                                                G8052_ = G2361_LPTPorts[L2698_i_ - '0' - 1];
                                                        }
                                                        break;
                                        }
                                        break;
                                case 'P':
                                        switch(toupper(argv[L2702_i_][2])) {
                                                case 'P':
                                                        G8030_ = 2;
                                                        break;
                                                case 'A':
                                                        G8030_ = 1;
                                                        if (argv[L2702_i_][3] != '\0') {
                                                                G8032_ = argv[L2702_i_][3] - '0';
                                                                if ((G8032_ >= 0) && (G8032_ <= 7)) {
                                                                        G8033_ = G8035_[G8032_];
                                                                        G8034_ = G8036_[G8032_];
                                                                } else {
                                                                        G8032_ = 0;
                                                                }
                                                        }
                                                        break;
                                                case 'K':
                                                        G8030_ = 3;
                                                        break;
                                                case 'M':
                                                        G8030_ = 4;
                                        }
                                case 'M':
                                        switch(toupper(argv[L2702_i_][2])) {
                                        }
                                        break;
                                case 'Z':
                                        G8103_ = 0;
                                        break;
                                case 'D':
                                        G8028_ = 1;
                                        break;
                        }
                }
        }
        G2156_VideoDriver = (VIDEO_DRIVER*)getvect(C255_DM_VIDEO_INTERRUPT);
        asm     mov     ax, ds
        asm     mov     cs:V0000000_DataSegment, ax
        for (L2702_i_ = 2, L2703_i_ = 0; L2702_i_ < argc; L2702_i_++) {
                if (L2703_i_ > 1) {
                        L2700_ac_[L2703_i_++] = ' ';
                }
                for (L2697_i_ = 0; L2697_i_ < 80; L2697_i_++) {
                        if ((L2696_c_ = argv[L2702_i_][L2697_i_]) == '\0') {
                                break;
                        }
                        L2700_ac_[L2703_i_++] = L2696_c_;
                }
                L2700_ac_[L2703_i_] = '\0';
        }
        if (G8094_i_SoundDevice == C6_SOUND_BLASTER) {
                if (F8022_IsSoundBlasterPresent()) {
                        F8017_();
                        if (G8001_ == 0) {
                                G8094_i_SoundDevice = C1_NO_SOUND;
                        }
                } else {
                        G8094_i_SoundDevice = C1_NO_SOUND;
                }
        }
        if ((G8030_ == 0) || (G8030_ == 4)) {
                if ((L2699_i_ = F8105_()) != 0) {
                        G8030_ = 4;
                } else {
                        G8030_ = 3;
                }
        }
        setvect(C254_DM_IO_INTERRUPT, (void interrupt (*)())&G8101_apc_IOInterruptVector);
        do {
                F8088_();
                F8102_();
                if ((G8030_ == 4) && (L2699_i_ != 0)) {
                        F8103_();
                }
                F8117_();
                if (G8103_) {
                        strcpy(L2701_ac_, G8102_CommandLines[G8104_].Parameters);
                        strcat(L2701_ac_, " ");
                        strcat(L2701_ac_, L2700_ac_);
                        if (G8102_CommandLines[G8104_].Program[0] == '@') {
                                L2702_i_ = F8134_ExecuteProgramWithParameters(argv[G8102_CommandLines[G8104_].Program[1] - '0'], L2701_ac_);
                        } else {
                                L2702_i_ = F8134_ExecuteProgramWithParameters(G8102_CommandLines[G8104_].Program, L2701_ac_);
                        }
                        if (G8102_CommandLines[G8104_].Value1 < L2702_i_) {
                                L2702_i_ = 0;
                        }
                        G8104_ = G8102_CommandLines[G8104_].Value3[L2702_i_] - 1;
                } else {
                        F8134_ExecuteProgramWithParameters(argv[1], L2700_ac_);
                }
                F8127_();
                if (G8094_i_SoundDevice == C5_DISNEY_SOUND_SOURCE) {
                        asm     mov     dx, G8052_
                        asm     add     dx, 2
                        asm     in      al, dx
                        asm     or      al, 8
                        asm     out     dx, al
                }
                F8118_();
                if ((G8030_ == 4) && L2699_i_) {
                        F8104_();
                }
                F8089_();
        } while (G8104_ > 0);
        return;
        asm     V0000000_DataSegment      dw 0
}
#endif
