#ifndef COMPILE_H
#include "COMPILE.H"
#endif
#ifdef MEDIA707_I34E_I34M
typedef struct {
        char* Name;
        BOOLEAN Allowed;
        int16_t Index;
} MENU_CHOICE;

#define C3_VIDEO_CHOICE_COUNT    3
#define C7_AUDIO_CHOICE_COUNT    7
#define C4_INPUT_CHOICE_COUNT    4
#define C3_LANGUAGE_CHOICE_COUNT 3

#define C1_VGA_GRAPHICS   1
#define C2_EGA_GRAPHICS   2
#define C3_TANDY_GRAPHICS 3

#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

#define C1_MOUSE                                   1
#define C2_ANALOG_JOYSTICK                         2
#define C3_DIGITAL_JOYSTICK                        3
#define C4_KEYBOARD_SIMULATION_OF_DIGITAL_JOYSTICK 4

#define C1_ENGLISH 1
#define C2_GERMAN  2
#define C3_FRENCH  3

int16_t G8015_ = 0x220; /* Base port for Sound Blaster */
int16_t G8016_VideoChoice = 0;
int16_t G8017_InputChoice = 0;
int16_t G8018_AudioChoice = 0;
#ifdef MEDIA733_I34M
int16_t G8019_LanguageChoice = C1_ENGLISH;
#endif
int16_t G8020_AdLibPort = 0x388;
int16_t G8021_ = 0xFFFF;
char G8022_CommandLineParameters[80] = "";

extern BOOLEAN F8061_(); /* Sound Blaster detection routine */


BOOLEAN F8062_HasLPTInitializationFailed(int16_t P2728_i_LPTPort)
{
/* P2728_i_LPTPort+0: LPT data register
   P2728_i_LPTPort+1: LPT status register
   P2728_i_LPTPort+2: LPT control register */
        if (P2728_i_LPTPort) {
                asm     mov     dx, P2728_i_LPTPort
                asm     add     dx, 2
                asm     mov     al, 4
                asm     out     dx, al          /* Set 'Init' bit in control register */
                asm     mov     cx, 200
                loc_12A73:
                asm     loop    loc_12A73
                asm     mov     dx, P2728_i_LPTPort
                asm     add     dx, 1
                asm     in      al, dx
                asm     and     al, 18h         /* Get 'Device Selected' and 'Device Error' bits in status register */
                asm     cmp     al, 0
                asm     jz      loc_12A84
                return 0;
                loc_12A84:
                return 1;
        } else {
                return 0;
        }
}

int16_t F8063_GetFTLSoundAdapterPort(
)
{
        int16_t L2353_i_;
        unsigned int16_t L2354_ui_;


        for (L2354_ui_ = 8; L2354_ui_ < 14; L2354_ui_ += 2) {
        /*  08h WORD Base I/O address of 1st parallel I/O port, zero if none
            0Ah WORD Base I/O address of 2nd parallel I/O port, zero if none
            0Ch WORD Base I/O address of 3rd parallel I/O port, zero if none */
                asm     mov     ax, 40h
                asm     mov     es, ax
                asm     mov     bx, L2354_ui_
                asm     mov     ax, es:[bx]
                asm     mov     L2353_i_, ax
                if (L2353_i_) {
                        asm     mov     dx, L2353_i_
                        asm     add     dx, 2
                        asm     mov     al, 0Ch
                        asm     out     dx, al
                        asm     mov     cx, 0C8h
                        loc_12ABB:
                        asm     loop    loc_12ABB
                        asm     mov     dx, L2353_i_
                        asm     add     dx, 1
                        asm     in      al, dx
                        asm     test    al, 20h
                        asm     jnz     loc_12AE6
                        asm     mov     dx, L2353_i_
                        asm     add     dx, 2
                        asm     mov     al, 4
                        asm     out     dx, al
                        asm     mov     cx, 0C8h
                        loc_12AD4:
                        asm     loop    loc_12AD4
                        asm     mov     dx, L2353_i_
                        asm     add     dx, 1
                        asm     in      al, dx
                        asm     test    al, 20h
                        asm     jz     loc_12AE6
                        return L2353_i_;
                        loc_12AE6: ;
                }
        }
        return 0;
}

void F8064_OutPort_ForAdLib(int16_t P2729_i_, int16_t P2730_i_)
{
        asm     mov     ax, P2729_i_
        asm     mov     dx, G8020_AdLibPort
        asm     out     dx, al
        asm     mov     cx, 0Ch
        loc_12B06:
        asm     in      al, dx
        asm     loop    loc_12B06
        asm     inc     dx
        asm     mov     ax, P2730_i_
        asm     out     dx, al
        asm     dec     dx
        asm     mov     cx, 54h
        loc_12B12:
        asm     in      al, dx
        asm     loop    loc_12B12
}

int16_t F8065_InPort_ForAdLib(int16_t P2731_i_)
{
        asm     mov     dx, P2731_i_
        asm     in      ax, dx
}

int16_t F8066_IsAdLibSoundDetected(
)
{
        int16_t L2355_i_;
        unsigned int16_t L2356_ui_;
        int16_t L2357_i_;


        F8064_OutPort_ForAdLib(4, 96);
        F8064_OutPort_ForAdLib(4, 128);
        asm     mov     dx, G8020_AdLibPort
        asm     in      al, dx
        asm     mov     ah, 0
        asm     mov     L2355_i_, ax
        F8064_OutPort_ForAdLib(2, 255);
        F8064_OutPort_ForAdLib(4, 33);
        for (L2356_ui_ = 0; L2356_ui_ < 200; L2356_ui_++) {
                F8065_InPort_ForAdLib(G8020_AdLibPort);
        }
        L2357_i_ = F8065_InPort_ForAdLib(G8020_AdLibPort);
        F8064_OutPort_ForAdLib(4, 96);
        F8064_OutPort_ForAdLib(4, 128);
        if (!(L2355_i_ & 0xE0) && ((L2357_i_ & 0xE0) == 0xC0)) {
                return C1_TRUE;
        } else {
                return C0_FALSE;
        }
}

BOOLEAN F8067_IsDisneySoundSourceDetected(int16_t P2732_i_)
{
        asm     pushf
        asm     cli
        asm     jmp     loc_12BF5
        asm     loc_12BD2:
        asm     push    dx
        asm     mov     dx, P2732_i_
        asm     add     dl, 2
        asm     out     dx, al
        asm     pop     dx
        asm     jmp     $+2
        asm     retn
        asm     loc_12BDE:
        asm     mov     al, 0Ch
        asm     call    loc_12BD2
        asm     retn
        asm     loc_12BE4:
        asm     mov     al, 4
        asm     call    loc_12BD2
        asm     retn
        asm     loc_12BEA:
        asm     call    loc_12BDE
        asm     call    loc_12BE4
        asm     retn
        asm     loc_12BF1:
        asm     in      al, dx
        asm     test    al, 40h
        asm     retn
        loc_12BF5:
        asm     call    loc_12BDE
        asm     mov     cx, 2000h
        loc_12BFB:
        asm     loop    loc_12BFB
        asm     call    loc_12BE4
        asm     mov     cx, 8000h
        loc_12C03:
        asm     loop    loc_12C03
        asm     mov     cx, 10h
        loc_12C08:
        asm     call    loc_12BEA
        asm     loop    loc_12C08
        asm     mov     dx, P2732_i_
        asm     inc     dx
        asm     mov     cx, 10h
        loc_12C14:
        asm     call    loc_12BF1
        asm     jnz     loc_12C20
        asm     call    loc_12BEA
        asm     loop    loc_12C14
        asm     jmp     loc_12C46
        loc_12C20:
        asm     mov     bx, 3
        loc_12C23:
        asm     mov     cx, 0
        loc_12C26:
        asm     call    loc_12BF1
        asm     jz      loc_12C2F
        asm     loop    loc_12C26
        asm     jmp     loc_12C46
        loc_12C2F:
        asm     mov     cx, 2
        loc_12C32:
        asm     call    loc_12BEA
        asm     call    loc_12BF1
        asm     jnz     loc_12C3E
        asm     loop    loc_12C32
        asm     jmp     loc_12C46
        loc_12C3E:
        asm     dec     bx
        asm     jnz     loc_12C23
        asm     mov     bx, 1
        asm     jmp     loc_12C49
        loc_12C46:
        asm     mov     bx, 0
        loc_12C49:
        asm     call    loc_12BDE
        asm     popf
        asm     mov     ax, bx
}

int16_t F8068_GetDisneySoundSourcePort(
)
{
        int16_t L2358_i_;
        unsigned int16_t L2359_ui_;


        for (L2359_ui_ = 8; L2359_ui_ < 14; L2359_ui_ += 2) {
                asm     mov     ax, 40h
                asm     mov     es, ax
                asm     mov     bx, L2359_ui_
                asm     mov     ax, es:[bx]
                asm     mov     L2358_i_, ax
                if (L2358_i_) {
                        if (F8067_IsDisneySoundSourceDetected(L2358_i_)) {
                                return L2358_i_;
                        }
                }
        }
        return 0;
}

BOOLEAN F8069_IsAnalogJoystickDetected(
)
{
        asm     jmp     loc_12C9B
        asm     V8069000_      dw 0
        loc_12C9B:
        asm     mov     dx, 201h
        asm     mov     bx, 0FA0h
        loc_12CA1:
        asm     add     cs:V8069000_, 5
        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, 0F0h
        asm     cmp     al, 0F0h
        asm     jnz     loc_12CCE
        asm     dec     bx
        asm     jnz     loc_12CA1
        asm     int     11h            /* EQUIPMENT DETERMINATION
                                          Return: AX = equipment flag bits */
        asm     and     ax, 1000h
        asm     jnz     loc_12CCE
        asm     mov     dx, 201h
        asm     out     dx, al         /* Game I/O port
                                          bits 0-3: Coordinates (resistive, time-dependent inputs)
                                          bits 4-7: Buttons/Triggers (digital inputs) */
        asm     mov     bx, 3E8h
        loc_12CBF:
        asm     mov     cx, 64h
        loc_12CC2:
        asm     loop    loc_12CC2
        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, 0Fh
        asm     cmp     al, 0Fh
        asm     jnz     loc_12CD2
        asm     dec     bx
        asm     jnz     loc_12CBF
        loc_12CCE:
        asm     xor     ax, ax
        asm     jmp     loc_12CD5
        loc_12CD2:
        asm     mov     ax, 1
        loc_12CD5: ;
}

BOOLEAN F8070_IsMouseDetected(
)
{
        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
}

unsigned int16_t F8071_Tandy_WritableMemory() /* Test memory is writable */
{
        unsigned int16_t L2360_ui_;
        long L2361_l_;
        long L2362_l_;
        long* L2363_pl_;
        unsigned int16_t L2364_ui_;
        int16_t L2365_i_;


        L2365_i_ = 0;
        asm     mov     ax, 40h
        asm     mov     es, ax
        asm     mov     ax, es:13h
        asm     mov     L2360_ui_, ax
        if (L2360_ui_ >= 640) {
                return 0;
        }
        for (L2364_ui_ = L2360_ui_; L2364_ui_ < 640; L2364_ui_++) {
                L2363_pl_ = MK_FP((L2364_ui_ << 6), 0);
                L2361_l_ = *L2363_pl_;
                L2362_l_ = *(L2363_pl_ + 1);
                *L2363_pl_ = 0x12345678;
                *(L2363_pl_ + 1) = 0x87654321;
                if ((*L2363_pl_ != 0x12345678) || (*(L2363_pl_ + 1) != 0x87654321)) {
                        L2365_i_ = 1;
                }
                *L2363_pl_ = L2361_l_;
                *(L2363_pl_ + 1) = L2362_l_;
                if (L2365_i_) {
                        break;
                }
        }
        return L2364_ui_ - L2360_ui_;
}

void F8072_Tandy_MemoryAllocate(
)
{
        unsigned int16_t L2366_ui_;


        L2366_ui_ = F8071_Tandy_WritableMemory();
        if ((L2366_ui_ >= 32) || !L2366_ui_) {
                return;
        }
        asm     mov     ah, 48h
        asm     mov     bx, 0FFFFh
        asm     int     21h
        asm     sub     bx, 402h
        asm     mov     ah, 48h
        asm     int     21h
        asm     push    ax
        asm     mov     ah, 48h
        asm     mov     bx, 0FFFFh
        asm     int     21h
        asm     mov     ah, 48h
        asm     int     21h
        asm     pop     es
        asm     mov     ah, 49h
        asm     int     21h
        /*
                ; DOS - 2+ - ALLOCATE MEMORY
                                        ; BX = number of 16-byte paragraphs desired
                ; DOS - 2+ - ALLOCATE MEMORY
                                        ; BX = number of 16-byte paragraphs desired
                ; DOS - 2+ - ALLOCATE MEMORY
                                        ; BX = number of 16-byte paragraphs desired
                ; DOS - 2+ - ALLOCATE MEMORY
                                        ; BX = number of 16-byte paragraphs desired
                ; DOS - 2+ - FREE MEMORY
                                        ; ES = segment address of area to be freed */
}

BOOLEAN F8073_IsTandy1000ComputerDetected(
)
{
        unsigned char* L2367_puc_;
        unsigned char* L2368_puc_;


        L2368_puc_ = (unsigned char*)0xFC000000;
        L2367_puc_ = (unsigned char*)0xFFFF000E;
        if ((*L2368_puc_ == 0x21) && (*L2367_puc_ == 0xFF)) { /* These two byte values identify all Tandy 1000 computers */
                return C1_TRUE;
        } else {
                return C0_FALSE;
        }
}

BOOLEAN F8074_IsTandy1000TLSLSoundDetected(
)
{
        if (G8021_ > 0) {
                return G8021_;
        }
        if (F8073_IsTandy1000ComputerDetected()) {
                G8021_ = C0_FALSE;
                asm     mov     ah, 83h
                asm     mov     cx, 1
                asm     mov     dx, 0Ah
                asm     int     1Ah
                asm     cmp     ah, 0
                asm     jnz     loc_12E47
                G8021_ = C1_TRUE;
                loc_12E47:
                return G8021_;
        } else {
                return C0_FALSE;
        }
}

BOOLEAN F8075_IsSoundBlasterDetected(
)
{
        if (F8061_()) {
                return C1_TRUE;
        } else {
                return C0_FALSE;
        }
}

BOOLEAN F8076_IsVGAGraphicsDetected(
)
{
        asm     mov     ax, 1A00h
        asm     int     10h            /* - VIDEO - DISPLAY COMBINATION (PS,VGA/MCGA): read display combination code */
        if (_AL == 0x1A) {
                return C1_TRUE;
        } else {
                return C0_FALSE;
        }
}

BOOLEAN F8077_IsEGAGraphicsDetected(
)
{
        char L2369_c_DOSMajorVersion;
        char L2370_c_;


        asm     mov     bl, 10h
        asm     mov     ah, 12h
        asm     int     10h            /* - VIDEO - ALTERNATE FUNCTION SELECT (PS, EGA, VGA, MCGA) - GET EGA INFO
                                          Return: BH = 00h color mode in effect CH = feature bits, CL = switch settings */
        asm     mov     L2369_c_DOSMajorVersion, bl
        asm     mov     L2370_c_, cl
        if (L2369_c_DOSMajorVersion == 0x10) {
                return C0_FALSE;
        } else {
                return C1_TRUE;
        }
}

char* F8078_strcpy(char* P2733_pc_, char* P2734_pc_)
{
        char* L2371_pc_;


        L2371_pc_ = P2733_pc_;
        while ((*P2733_pc_++ = *P2734_pc_++) != 0);
        return L2371_pc_;
}

char* F8079_strcat(char* P2735_pc_, char* P2736_pc_)
{
        char* L2372_pc_;


        L2372_pc_ = P2735_pc_;
        while (*P2735_pc_++);
        P2735_pc_--;
        while ((*P2735_pc_++ = *P2736_pc_++) != 0);
        return L2372_pc_;
}

void F8054_DOS_PrintString(char* P2737_pc_)
{
        char* L2373_pc_;
        char L2374_ac_[80];
        int16_t L2375_i_;


        L2373_pc_ = L2374_ac_;
        for (L2375_i_ = 0; P2737_pc_[L2375_i_] != '\0'; L2375_i_++) {
                L2374_ac_[L2375_i_] = P2737_pc_[L2375_i_];
        }
        L2374_ac_[L2375_i_] = '$';
        asm     push    ds
        asm     lds     dx, L2373_pc_
        asm     mov     ah, 9
        asm     int     21h             /* DOS - PRINT STRING */
                                        /* DS:DX -> string terminated by "$" */
        asm     pop     ds
}

void F8080_AddCommandLineParameter(char* P2738_pc_)
{
        F8079_strcat(G8022_CommandLineParameters, " ");
        F8079_strcat(G8022_CommandLineParameters, P2738_pc_);
}

long F8081_(
)
{
        unsigned int16_t L2376_ui_;


        asm     mov     ax, 40h
        asm     mov     es, ax
        asm     mov     ax, es:13h
        asm     mov     L2376_ui_, ax
        /* Base memory size in KB (0-640) from BIOS segment 40h */
        return ((long)L2376_ui_ * 1024) - ((long)_psp * 16);
}

void F8082_ExitBecauseFileNotFound(char* P2739_pc_)
{
        F8054_DOS_PrintString("\n\rCan't locate file ");
        F8054_DOS_PrintString(P2739_pc_);
        F8054_DOS_PrintString(".\n\r");
        exit(0);
}

int16_t F8083_DOS_OpenFile(char* P2740_pc_)
{
        asm     push    ds
        asm     lds     dx, P2740_pc_
        asm     mov     ah, 3Dh
        asm     mov     al, 2
        asm     int     21h
        asm     jnb     loc_12FEF
        asm     mov     ax, 0FFFFh
                /*; DOS - 2+ - OPEN DISK FILE WITH HANDLE
                                        ; DS:DX -> ASCIZ filename
                                        ; AL = access mode
                                        ; 2 - read & write */
        loc_12FEF:
        asm     pop    ds
}

void F8084_DOS_CloseFile(int16_t P2741_i_)
{
        asm     mov     bx, P2741_i_
        asm     mov     ah, 3Eh
        asm     int     21h
                /*; DOS - 2+ - CLOSE A FILE WITH HANDLE
                                        ; BX = file handle*/
}

BOOLEAN F8085_FileExists(char* P2742_pc_)
{
        int16_t L2377_i_;


        if ((L2377_i_ = F8083_DOS_OpenFile(P2742_pc_)) != -1) {
                F8084_DOS_CloseFile(L2377_i_);
                return C1_TRUE;
        } else {
                return C0_FALSE;
        }
}

int16_t F8052_DOS_KeyboardInput(
)
{
        char L2378_ac_[4];
        char* L2379_pc_;


        L2379_pc_ = L2378_ac_;
        L2378_ac_[0] = 2; /* Maximum size the DOS call can use in the specified L2379_pc_ buffer (1 character + the <enter> key) */
        asm     mov     ah, 0Ah
        asm     push    ds
        asm     lds     dx, L2379_pc_
        asm     int     21h             /* DOS - BUFFERED KEYBOARD INPUT */
                                        /* DS:DX -> buffer */
        asm     pop     ds
        if (L2378_ac_[1] != 1) { /* Length of the string returned by DOS in the buffer */
                return 0;
        } else {
                return toupper(L2378_ac_[2]); /* Character returned by DOS */
        }
}

MENU_CHOICE G8023_Video[C3_VIDEO_CHOICE_COUNT] = {
        { "VGA Graphics",   C0_FALSE, C1_VGA_GRAPHICS   },
        { "EGA Graphics",   C0_FALSE, C2_EGA_GRAPHICS   },
        { "Tandy Graphics", C0_FALSE, C3_TANDY_GRAPHICS } };
MENU_CHOICE G8024_Audio[C7_AUDIO_CHOICE_COUNT] = {
        { "No Sound",               C1_TRUE,  C1_NO_SOUND              },
        { "PC Spkr Sound",          C1_TRUE,  C2_PC_SPKR_SOUND         },
        { "FTL Sound Adapter",      C0_FALSE, C3_FTL_SOUND_ADAPTER     },
        { "Tandy 1000 TL/SL Sound", C0_FALSE, C4_TANDY_1000_TLSL_SOUND },
        { "Disney Sound Source",    C0_FALSE, C5_DISNEY_SOUND_SOURCE   },
        { "Sound Blaster",          C0_FALSE, C6_SOUND_BLASTER         },
        { "Adlib Sound",            C0_FALSE, C7_ADLIB_SOUND           } };
MENU_CHOICE G8025_Input[C4_INPUT_CHOICE_COUNT] = {
        { "Mouse",                                   C0_FALSE, C1_MOUSE                                   },
        { "Analog Joystick",                         C0_FALSE, C2_ANALOG_JOYSTICK                         },
        { "Digital Joystick",                        C0_FALSE, C3_DIGITAL_JOYSTICK                        },
        { "Keyboard Simulation of Digital Joystick", C1_TRUE,  C4_KEYBOARD_SIMULATION_OF_DIGITAL_JOYSTICK } };
#ifdef MEDIA733_I34M
MENU_CHOICE G8026_Language[C3_LANGUAGE_CHOICE_COUNT] = {
        { "English", C1_TRUE, C1_ENGLISH },
        { "German",  C1_TRUE, C2_GERMAN  },
        { "French",  C1_TRUE, C3_FRENCH  } };
#endif
char G8027_[20] = "0. [ ] ";

int16_t F8086_GetMenuChoice(MENU_CHOICE* P2743_ps_MenuChoice, int16_t P2744_i_ChoiceCount)
{
        int16_t L2380_i_ChoiceIndex;
        int16_t L2381_i_SelectedChoice;


        F8054_DOS_PrintString("\n\r");
        do {
                F8054_DOS_PrintString("\n\rPlease select from '*'ed options\n\r");
                for (L2380_i_ChoiceIndex = 0; L2380_i_ChoiceIndex < P2744_i_ChoiceCount; L2380_i_ChoiceIndex++) {
                        G8027_[0] = '0' + P2743_ps_MenuChoice[L2380_i_ChoiceIndex].Index;
                        if (P2743_ps_MenuChoice[L2380_i_ChoiceIndex].Allowed) {
                                G8027_[4] = '*';
                        } else {
                                G8027_[4] = ' ';
                        }
                        F8054_DOS_PrintString(G8027_);
                        F8054_DOS_PrintString(P2743_ps_MenuChoice[L2380_i_ChoiceIndex].Name);
                        F8054_DOS_PrintString("\n\r");
                }
                F8054_DOS_PrintString("Q. [*] Quit\n\r\n\r? ");
                L2381_i_SelectedChoice = toupper(F8052_DOS_KeyboardInput());
                if (L2381_i_SelectedChoice == 'Q') {
                        exit(0);
                }
                L2381_i_SelectedChoice = L2381_i_SelectedChoice - '0';
                if ((L2381_i_SelectedChoice < 1) || (L2381_i_SelectedChoice > P2744_i_ChoiceCount)) {
                        L2381_i_SelectedChoice = -1;
                        F8054_DOS_PrintString("\n\rInvalid selection.");
                } else {
                        if (!P2743_ps_MenuChoice[L2381_i_SelectedChoice - 1].Allowed) {
                                L2381_i_SelectedChoice = -1;
                                F8054_DOS_PrintString("\n\rThat option is not available.");
                        }
                }
        } while (L2381_i_SelectedChoice < 0);
        return P2743_ps_MenuChoice[L2381_i_SelectedChoice - 1].Index;
}

void main(int16_t argc, char* argv[])
{
        unsigned char L2382_uc_DOSMajorVersion;
        char L2383_ac_String[256];
        char L2384_ac_VideoProgramName[32] = "";
        char L2385_ac_IOProgramName[32] = "";
        char L2386_ac_GameProgramName[32] = "FIRES";
        char L2387_ac_SoundBlasterPortString[2] = "";
        char L2388_ac_AnalogJoystickParameter[6] = "-pa3";
        static int16_t G2360_LPTPorts[3] = { 0x3BC, 0x378, 0x278 };
        int16_t L2389_i_Index;
        int16_t L2390_i_;
        int16_t L2391_i_SoundBlasterPort;
        BOOLEAN L2392_B_DisneySoundSourcePort;
        BOOLEAN L2393_B_;
        BOOLEAN L2394_B_ProgramNameSpecified;
        char* L2395_pc_Path;
        BOOLEAN L2396_B_PrintCommandLineOnly;
        BOOLEAN L2397_B_VGAGraphicsDetected;
        BOOLEAN L2398_B_EGAGraphicsDetected;
        BOOLEAN L2399_B_TandyGraphicsDetected;
        BOOLEAN L2400_B_Tandy1000TLSLSoundDetected;
        BOOLEAN L2401_B_SoundBlasterDetected;
        BOOLEAN L2402_B_AdLibSoundDetected;
        BOOLEAN L2403_B_AnalogJoystickDetected;
        BOOLEAN L2404_B_MouseDetected;
        BOOLEAN L2405_B_DigitalJoystickDetected;
        FILE* L2406_dmset_FileHandle;
        BOOLEAN L2407_B_GetMenuChoices;
        int16_t L2408_i_LPTPortIndex;
        int16_t L2409_i_FTLSoundAdapterPort;


        L2409_i_FTLSoundAdapterPort = 0;
        L2392_B_DisneySoundSourcePort = 0;
        L2393_B_ = C0_FALSE;
        L2394_B_ProgramNameSpecified = C0_FALSE;
        L2396_B_PrintCommandLineOnly = C0_FALSE;
        L2405_B_DigitalJoystickDetected = C0_FALSE;
        L2407_B_GetMenuChoices = C1_TRUE;
        asm     mov     ah, 30h
        asm     int     21h            /* DOS - GET DOS VERSION
                                          Return: AL = major version number (00h for DOS 1.x) */
        asm     mov     L2382_uc_DOSMajorVersion, al
        if (L2382_uc_DOSMajorVersion < 2) {
                F8054_DOS_PrintString("\nDOS 2.0 or later required.\n\r");
                exit(0);
        }
        if (argv[0]) { /* Process first command line argument: the command used to run dm.exe itself. If run with a drive letter AND path, then change disk and directory so that other files may be opened in the current directory (VGA, dmset, etc.) */
                L2390_i_ = 0;
                if (argv[0][1] == ':') {
                        L2389_i_Index = toupper(argv[0][0]) - 'A';
                        asm     mov     dl, byte ptr L2389_i_Index
                        asm     mov     ah, 0Eh
                        asm     int     21h            /* DOS - SELECT DISK
                                                          DL = new default drive number (0 = A, 1 = B, etc.)
                                                          Return: AL = number of logical drives */
                        L2390_i_ = 2;
                }
                for (L2389_i_Index = strlen(argv[0]); L2389_i_Index >= L2390_i_; L2389_i_Index--) {
                        if (argv[0][L2389_i_Index] == '\\') {
                                break;
                        }
                }
                argv[0][L2389_i_Index] = '\0';
                L2395_pc_Path = argv[0] + 2;
                asm     push    ds
                asm     lds     dx, L2395_pc_Path
                asm     mov     ah, 3Bh
                asm     int     21h            /* DOS - 2+ - CHANGE THE CURRENT DIRECTORY (CHDIR)
                                                  DS:DX -> ASCIZ directory name (may include drive) */
                asm     pop     ds
        }
        /* Detect hardware and enable corresponding choices in menus */
        G8023_Video[C1_VGA_GRAPHICS - 1].Allowed = L2397_B_VGAGraphicsDetected = F8076_IsVGAGraphicsDetected();
        G8023_Video[C2_EGA_GRAPHICS - 1].Allowed = L2398_B_EGAGraphicsDetected = F8077_IsEGAGraphicsDetected();
        G8023_Video[C3_TANDY_GRAPHICS - 1].Allowed = L2399_B_TandyGraphicsDetected = F8073_IsTandy1000ComputerDetected();
        if ((L2409_i_FTLSoundAdapterPort = F8063_GetFTLSoundAdapterPort()) != 0) {
                G8025_Input[C3_DIGITAL_JOYSTICK - 1].Allowed = L2405_B_DigitalJoystickDetected = C1_TRUE;
        }
        G8025_Input[C2_ANALOG_JOYSTICK - 1].Allowed = L2403_B_AnalogJoystickDetected = F8069_IsAnalogJoystickDetected();
        G8025_Input[C1_MOUSE - 1].Allowed = L2404_B_MouseDetected = F8070_IsMouseDetected();
        G8024_Audio[C4_TANDY_1000_TLSL_SOUND - 1].Allowed = L2400_B_Tandy1000TLSLSoundDetected = F8074_IsTandy1000TLSLSoundDetected();
        G8024_Audio[C6_SOUND_BLASTER - 1].Allowed = L2401_B_SoundBlasterDetected = F8075_IsSoundBlasterDetected();
        if (L2409_i_FTLSoundAdapterPort) {
                G8024_Audio[C3_FTL_SOUND_ADAPTER - 1].Allowed = C1_TRUE;
        }
        L2393_B_ = F8062_HasLPTInitializationFailed(L2409_i_FTLSoundAdapterPort);
        if ((L2392_B_DisneySoundSourcePort = F8068_GetDisneySoundSourcePort()) != 0) {
                G8024_Audio[C5_DISNEY_SOUND_SOURCE - 1].Allowed = C1_TRUE;
        }
        G8024_Audio[C7_ADLIB_SOUND - 1].Allowed = L2402_B_AdLibSoundDetected = F8066_IsAdLibSoundDetected();
        if (argc > 1) { /* Process other command line arguments and set variables */
                for (L2389_i_Index = 1; L2389_i_Index < argc; L2389_i_Index++) {
                        if (argv[L2389_i_Index][0] == '-') {
                                L2407_B_GetMenuChoices = C0_FALSE;
                                switch(toupper(argv[L2389_i_Index][1])) {
                                        case 'M':
                                                if (toupper(argv[L2389_i_Index][2]) != 'C') {
                                                        continue;
                                                }
                                                L2393_B_ = C1_TRUE;
                                                continue;
                                        case 'R':
                                                L2396_B_PrintCommandLineOnly = C1_TRUE;
                                                continue;
                                        case 'V':
                                                switch(toupper(argv[L2389_i_Index][2])) {
                                                        case 'V':
                                                                G8016_VideoChoice = C1_VGA_GRAPHICS;
                                                                break;
                                                        case 'E':
                                                                G8016_VideoChoice = C2_EGA_GRAPHICS;
                                                                break;
                                                        case 'T':
                                                                G8016_VideoChoice = C3_TANDY_GRAPHICS;
                                                }
                                                break;
                                        case 'P':
                                                switch(toupper(argv[L2389_i_Index][2])) {
                                                        case 'J':
                                                                G8017_InputChoice = C3_DIGITAL_JOYSTICK;
                                                                break;
                                                        case 'K':
                                                                G8017_InputChoice = C4_KEYBOARD_SIMULATION_OF_DIGITAL_JOYSTICK;
                                                                break;
                                                        case 'A':
                                                                G8017_InputChoice = C2_ANALOG_JOYSTICK;
                                                                F8078_strcpy(L2388_ac_AnalogJoystickParameter, argv[L2389_i_Index]);
                                                                break;
                                                        case 'M':
                                                                G8017_InputChoice = C1_MOUSE;
                                                }
                                                continue;
                                        case 'S':
                                                switch(toupper(argv[L2389_i_Index][2])) {
                                                        /* 20 cases */
                                                        case 'I':
                                                                G8018_AudioChoice = C2_PC_SPKR_SOUND;
                                                                break;
                                                        case 'N':
                                                                G8018_AudioChoice = C1_NO_SOUND;
                                                                break;
                                                        case 'T':
                                                                G8018_AudioChoice = C4_TANDY_1000_TLSL_SOUND;
                                                                break;
                                                        case 'F':
                                                                G8018_AudioChoice = C3_FTL_SOUND_ADAPTER;
                                                                L2408_i_LPTPortIndex = toupper(argv[L2389_i_Index][3]);
                                                                if ((L2408_i_LPTPortIndex >= '1') && (L2408_i_LPTPortIndex <= '3')) {
                                                                        L2409_i_FTLSoundAdapterPort = G2360_LPTPorts[L2408_i_LPTPortIndex - '1'];
                                                                }
                                                                break;
                                                        case 'D':
                                                                G8018_AudioChoice = C5_DISNEY_SOUND_SOURCE;
                                                                L2408_i_LPTPortIndex = toupper(argv[L2389_i_Index][3]);
                                                                if ((L2408_i_LPTPortIndex >= '1') && (L2408_i_LPTPortIndex <= '3')) {
                                                                        L2392_B_DisneySoundSourcePort = G2360_LPTPorts[L2408_i_LPTPortIndex - '1'];
                                                                }
                                                                break;
                                                        case 'B':
                                                                G8018_AudioChoice = C6_SOUND_BLASTER;
                                                                L2391_i_SoundBlasterPort = (int16_t)argv[L2389_i_Index][3];
                                                                if ((L2391_i_SoundBlasterPort >= '1') && (L2391_i_SoundBlasterPort <= '6')) {
                                                                        L2387_ac_SoundBlasterPortString[0] = L2391_i_SoundBlasterPort;
                                                                }
                                                                break;
                                                        case 'A':
                                                                G8018_AudioChoice = C7_ADLIB_SOUND;
                                                }
                                                continue;
                                        case 'O':
                                                L2407_B_GetMenuChoices = C1_TRUE;
                                                continue;
#ifdef MEDIA733_I34M
                                        case '*':
                                                switch(toupper(argv[L2389_i_Index][2])) {
                                                        case 'E':
                                                                G8019_LanguageChoice = C1_ENGLISH;
                                                                break;
                                                        case 'F':
                                                                G8019_LanguageChoice = C3_FRENCH;
                                                                break;
                                                        case 'G':
                                                                G8019_LanguageChoice = C2_GERMAN;
                                                }
                                                continue;
#endif
                                        default:
                                                F8080_AddCommandLineParameter(argv[L2389_i_Index]);
                                }
                                continue;
                        } else {
                                if (L2394_B_ProgramNameSpecified == C0_FALSE) {
                                        strcpy(L2386_ac_GameProgramName, argv[L2389_i_Index]);
                                        L2394_B_ProgramNameSpecified = C1_TRUE;
                                } else {
                                        F8080_AddCommandLineParameter(argv[L2389_i_Index]);
                                }
                        }
                }
        }
        if (L2407_B_GetMenuChoices) {
#ifdef MEDIA733_I34M
                G8019_LanguageChoice = F8086_GetMenuChoice(G8026_Language, C3_LANGUAGE_CHOICE_COUNT);
#endif
                G8016_VideoChoice = F8086_GetMenuChoice(G8023_Video, C3_VIDEO_CHOICE_COUNT);
                G8018_AudioChoice = F8086_GetMenuChoice(G8024_Audio, C7_AUDIO_CHOICE_COUNT);
                G8017_InputChoice = F8086_GetMenuChoice(G8025_Input, C4_INPUT_CHOICE_COUNT);
        }
        if (L2393_B_ && (G8017_InputChoice != C3_DIGITAL_JOYSTICK)) {
                switch (L2409_i_FTLSoundAdapterPort) {
                        case 0x3BC:
                                F8080_AddCommandLineParameter("-mc1");
                                break;
                        case 0x378:
                                F8080_AddCommandLineParameter("-mc2");
                                break;
                        case 0x278:
                                F8080_AddCommandLineParameter("-mc3");
                }
        }
        if (G8017_InputChoice == 0) {
                if (L2404_B_MouseDetected) {
                        F8080_AddCommandLineParameter("-pm");
                } else {
                        if (!L2400_B_Tandy1000TLSLSoundDetected && (L2403_B_AnalogJoystickDetected || L2399_B_TandyGraphicsDetected) && (G8018_AudioChoice != C2_PC_SPKR_SOUND)) {
                                F8080_AddCommandLineParameter("-pa3");
                        } else {
                                if (L2405_B_DigitalJoystickDetected && !L2393_B_) {
                                        F8080_AddCommandLineParameter("-pj");
                                } else {
                                        F8080_AddCommandLineParameter("-pk");
                                }
                        }
                }
        } else {
                switch (G8017_InputChoice) {
                        case C3_DIGITAL_JOYSTICK:
                                F8080_AddCommandLineParameter("-pj");
                                break;
                        case C4_KEYBOARD_SIMULATION_OF_DIGITAL_JOYSTICK:
                                F8080_AddCommandLineParameter("-pk");
                                break;
                        case C2_ANALOG_JOYSTICK:
                                F8080_AddCommandLineParameter(L2388_ac_AnalogJoystickParameter);
                                break;
                        case C1_MOUSE:
                                F8080_AddCommandLineParameter("-pm");
                }
        }
        if (G8018_AudioChoice == 0) {
                if (L2400_B_Tandy1000TLSLSoundDetected && (G8017_InputChoice != C2_ANALOG_JOYSTICK)) {
                        F8080_AddCommandLineParameter("-st");
                } else {
                        if (L2409_i_FTLSoundAdapterPort) {
                                switch (L2409_i_FTLSoundAdapterPort) {
                                        case 0x3BC:
                                                F8080_AddCommandLineParameter("-sf1");
                                                break;
                                        case 0x378:
                                                F8080_AddCommandLineParameter("-sf2");
                                                break;
                                        case 0x278:
                                                F8080_AddCommandLineParameter("-sf3");
                                                break;
                                }
                        } else {
                                if (L2401_B_SoundBlasterDetected) {
                                        F8080_AddCommandLineParameter("-sb");
                                } else {
                                        if (L2402_B_AdLibSoundDetected) {
                                                F8080_AddCommandLineParameter("-sa");
                                        } else {
                                                F8080_AddCommandLineParameter("-si");
                                        }
                                }
                        }
                }
        } else {
                switch (G8018_AudioChoice) {
                        case C6_SOUND_BLASTER:
                                F8080_AddCommandLineParameter("-sb");
                                F8079_strcat(G8022_CommandLineParameters, L2387_ac_SoundBlasterPortString);
                                break;
                        case C4_TANDY_1000_TLSL_SOUND:
                                F8080_AddCommandLineParameter("-st");
                                break;
                        case C1_NO_SOUND:
                                F8080_AddCommandLineParameter("-sn");
                                break;
                        case C2_PC_SPKR_SOUND:
                                F8080_AddCommandLineParameter("-si");
                                break;
                        case C3_FTL_SOUND_ADAPTER:
                                if (L2409_i_FTLSoundAdapterPort) {
                                        switch (L2409_i_FTLSoundAdapterPort) {
                                                case 0x3BC:
                                                        F8080_AddCommandLineParameter("-sf1");
                                                        break;
                                                case 0x378:
                                                        F8080_AddCommandLineParameter("-sf2");
                                                        break;
                                                case 0x278:
                                                        F8080_AddCommandLineParameter("-sf3");
                                                        break;
                                        }
                                }
                                break;
                        case C5_DISNEY_SOUND_SOURCE:
                                if (L2392_B_DisneySoundSourcePort) {
                                        switch (L2392_B_DisneySoundSourcePort) {
                                                case 0x3BC:
                                                        F8080_AddCommandLineParameter("-sd1");
                                                        break;
                                                case 0x378:
                                                        F8080_AddCommandLineParameter("-sd2");
                                                        break;
                                                case 0x278:
                                                        F8080_AddCommandLineParameter("-sd3");
                                                        break;
                                        }
                                }
                                break;
                        case C7_ADLIB_SOUND:
                                F8080_AddCommandLineParameter("-sa");
                }
        }
#ifdef MEDIA733_I34M
        switch (G8019_LanguageChoice) {
                case C1_ENGLISH:
                        F8080_AddCommandLineParameter("-*e");
                        break;
                case C2_GERMAN:
                        F8080_AddCommandLineParameter("-*g");
                        break;
                case C3_FRENCH:
                        F8080_AddCommandLineParameter("-*f");
        }
#endif
        if (G8016_VideoChoice == 0) {
                if (L2397_B_VGAGraphicsDetected != 0) {
                        G8016_VideoChoice = C1_VGA_GRAPHICS;
                } else {
                        if (L2398_B_EGAGraphicsDetected != 0) {
                                G8016_VideoChoice = C2_EGA_GRAPHICS;
                        } else {
                                if (L2399_B_TandyGraphicsDetected != 0) {
                                        G8016_VideoChoice = C3_TANDY_GRAPHICS;
                                }
                        }
                }
        }
        switch (G8016_VideoChoice) {
                case C1_VGA_GRAPHICS:
                        if (L2397_B_VGAGraphicsDetected) {
                                F8078_strcpy(L2384_ac_VideoProgramName, "VGA");
                        } else {
                                G8016_VideoChoice = 0;
                        }
                        break;
                case C2_EGA_GRAPHICS:
                        if (L2398_B_EGAGraphicsDetected) {
                                F8078_strcpy(L2384_ac_VideoProgramName, "EGA");
                        } else {
                                G8016_VideoChoice = 0;
                        }
                        break;
                case C3_TANDY_GRAPHICS:
                        if (L2399_B_TandyGraphicsDetected) {
                                F8078_strcpy(L2384_ac_VideoProgramName, "TANDY");
                        } else {
                                G8016_VideoChoice = 0;
                        }
        }
        if (!F8085_FileExists(L2384_ac_VideoProgramName)) {
                F8079_strcat(L2384_ac_VideoProgramName, ".EXE");
        }
        if (!F8085_FileExists(L2384_ac_VideoProgramName)) {
                F8082_ExitBecauseFileNotFound(L2384_ac_VideoProgramName);
        }
        if (!L2393_B_) {
                goto loc_139FD;
        }
        F8078_strcpy(L2385_ac_IOProgramName, "IBMIOCD");
        if (!F8085_FileExists(L2385_ac_IOProgramName)) {
                F8079_strcat(L2385_ac_IOProgramName, ".EXE");
        }
        if (!F8085_FileExists(L2385_ac_IOProgramName)) {
                loc_139FD:
                F8078_strcpy(L2385_ac_IOProgramName, "IBMIO");
                if (!F8085_FileExists(L2385_ac_IOProgramName)) {
                        F8079_strcat(L2385_ac_IOProgramName, ".EXE");
                }
                if (!F8085_FileExists(L2385_ac_IOProgramName)) {
                        F8082_ExitBecauseFileNotFound(L2385_ac_IOProgramName);
                }
        }
        if (!F8085_FileExists(L2386_ac_GameProgramName)) {
                F8079_strcat(L2386_ac_GameProgramName, ".EXE");
        }
        if (!F8085_FileExists(L2386_ac_GameProgramName)) {
                F8082_ExitBecauseFileNotFound(L2386_ac_GameProgramName);
        }
        if ((L2406_dmset_FileHandle = fopen("dmset", "r")) != 0) {
                if ((int16_t)strlen(fgets(L2383_ac_String, 20, L2406_dmset_FileHandle)) > 1) {
                        F8080_AddCommandLineParameter(L2383_ac_String);
                }
        }
        if (L2396_B_PrintCommandLineOnly) {
                F8078_strcpy(L2383_ac_String, L2384_ac_VideoProgramName);
                F8079_strcat(L2383_ac_String, " ");
                F8079_strcat(L2383_ac_String, L2385_ac_IOProgramName);
                F8079_strcat(L2383_ac_String, " ");
                F8079_strcat(L2383_ac_String, L2386_ac_GameProgramName);
                F8079_strcat(L2383_ac_String, G8022_CommandLineParameters);
                F8054_DOS_PrintString(L2383_ac_String);
        } else {
                if (G8016_VideoChoice) {
                        if (G8016_VideoChoice == C3_TANDY_GRAPHICS) {
                                F8072_Tandy_MemoryAllocate();
                        }
                        execl(L2384_ac_VideoProgramName, L2384_ac_VideoProgramName, L2385_ac_IOProgramName, L2386_ac_GameProgramName, G8022_CommandLineParameters, NULL);
                        /* executes child process from file name in L2384_ac_VideoProgramName (search in current directory only) with one additional argument for each command line argument passed to the called program, ending with a NULL */
                } else {
                        F8054_DOS_PrintString("\nNo compatible graphics adapter found.\n\r");
                        F8054_DOS_PrintString("\nUnable to run.\n\r");
                }
        }
}
#endif
