/* This file has been generated by the Hex-Rays decompiler.
   Copyright (c) 2007-2017 Hex-Rays <info@hex-rays.com>

   Detected compiler: Borland C++
*/

#include <defs.h>


//-------------------------------------------------------------------------
// Function declarations

// int __usercall Sub_0@<eax>(int a1@<ecx>, _WORD *a2@<edi>, _WORD *a3@<esi>);
int __fastcall nullsub_2(_DWORD, _DWORD); // weak
int __far nullsub_1(); // weak
// int __usercall Sub_200@<eax>(__int16 a1@<dx>, int a2@<ecx>, int a3@<ebx>, _BYTE *a4@<edi>);
// int __usercall Sub_209@<eax>(__int16 a1@<ax>, int a2@<ecx>, int a3@<ebx>, _BYTE *a4@<edi>);
// int __usercall Sub_287@<eax>(__int16 a1@<dx>, int a2@<ecx>, int a3@<ebx>, _BYTE *a4@<edi>, __int16 a5@<si>);
// void __usercall Sub_45E(_BYTE *a1@<edi>, __int16 *a2@<esi>);
// int __usercall Sub_52A@<eax>(int a1@<ecx>, _BYTE *a2@<esi>);
// void __usercall Sub_567(int a1@<ecx>, _BYTE *a2@<esi>);
// int __usercall Sub_57E@<eax>(int a1@<edx>, int a2@<ebx>);
// void __usercall Sub_5D6(int a1@<ecx>, int a2@<ebx>, _WORD *a3@<edi>, _BYTE *a4@<esi>);
// void __usercall Sub_61A(int a1@<ecx>, _BYTE *a2@<edi>, unsigned __int8 *a3@<esi>);
int Sub_699();
int Sub_6CC();
int __fastcall Sub_7C7(int a1, int a2, int a3);
// int __usercall Sub_81B@<eax>(int a1@<ecx>, _BYTE *a2@<edi>, _BYTE *a3@<esi>);
// void __usercall Sub_837(int a1@<ecx>, _BYTE *a2@<edi>, _BYTE *a3@<esi>);
// void __usercall Sub_8BF(int a1@<ecx>, _BYTE *a2@<edi>, _BYTE *a3@<esi>);
// int __usercall Sub_8E7@<eax>(int a1@<ecx>, _WORD *a2@<edi>, char *a3@<esi>, char a4@<efl>);
// int __usercall Sub_B9D@<eax>(__int16 a1@<bx>, char *a2@<edi>, char *a3@<esi>);
// int __usercall Sub_C5F@<eax>(char a1@<al>, unsigned __int16 a2@<dx>, __int16 a3@<bp>, _BYTE *a4@<edi>);
// int __usercall Sub_D75@<eax>(int a1@<ecx>, _BYTE *a2@<edi>, int a3@<esi>);
__int16 Sub_DDB();
// int __usercall Sub_DE9@<eax>(int a1@<ecx>, int a2@<edi>, _BYTE *a3@<esi>);
__int16 Sub_E55();
int Sub_E8B();
int Sub_EC3();
// int __usercall Sub_F0A@<eax>(unsigned int a1@<ecx>, char *a2@<edi>, char *a3@<esi>);
int Sub_1026();
// int __usercall Sub_111C@<eax>(int a1@<ecx>, int a2@<ebx>, _WORD *a3@<edi>, _WORD *a4@<esi>);
// int __usercall Sub_1C72@<eax>(unsigned int a1@<ecx>, char *a2@<edi>, char *a3@<esi>);
int Sub_1D88();
// int __usercall Sub_1D9F@<eax>(int a1@<ecx>, _WORD *a2@<edi>, _WORD *a3@<esi>);

//-------------------------------------------------------------------------
// Data declarations

char byte_10020; // weak
char byte_10021; // weak
char byte_10022; // weak
__int16 word_10023; // weak
__int16 word_10025; // weak
__int16 word_10027; // weak
__int16 word_10029; // weak
char byte_1002B; // weak
char byte_1002D; // weak
char byte_1002E; // weak
_UNKNOWN loc_10032; // weak
_UNKNOWN loc_10036; // weak
_UNKNOWN loc_10038; // weak
_UNKNOWN loc_1003A; // weak
_UNKNOWN loc_1003F; // weak
_UNKNOWN loc_10040; // weak
_UNKNOWN loc_10045; // weak
_UNKNOWN loc_1004A; // weak
_UNKNOWN loc_10068; // weak
_UNKNOWN loc_10077; // weak
_UNKNOWN loc_10081; // weak
_UNKNOWN loc_1008E; // weak
_UNKNOWN loc_100A4; // weak
__int16 word_11654 = 7871; // weak


//----- (00010030) --------------------------------------------------------
// write access to const memory has been detected, the output may be wrong!
int __usercall Sub_0@<eax>(int a1@<ecx>, _WORD *a2@<edi>, _WORD *a3@<esi>)
{
  __int16 v3; // sp
  __int16 v4; // sp
  unsigned __int16 v5; // ax
  __int16 v6; // ax
  int v7; // edi
  _WORD *v8; // edi
  unsigned __int8 v9; // al
  unsigned __int8 v10; // al
  __int16 v11; // ax
  __int16 v12; // si
  unsigned __int8 v13; // cf
  __int16 v14; // ax
  __int16 v16; // [esp-4h] [ebp-4h]
  void *retaddr[2]; // [esp+2h] [ebp+2h]

  v16 = __DS__;
  LOWORD(a2) = (_WORD)Sub_0 + 525;
  LOWORD(a3) = *(_WORD _ds *)(v3 + 8);
  __DS__ = *(_WORD _ds *)(v3 + 10);
  LOWORD(a1) = 38;
  while ( a1 )
  {
    *a2 = *a3;
    ++a3;
    ++a2;
    --a1;
  }
  v5 = *(_WORD _ds *)(v4 + 6);
  *(_WORD *)((char *)Sub_0 + 363) = v5;
  v6 = v16 + (v5 >> 4);
  *(_WORD *)((char *)Sub_0 + 361) = v6;
  __DS__ = v6;
  LOWORD(a2) = 5734;
  *MK_FP(v6, a2) = (_WORD)Sub_0 + 1759;
  v7 = (int)(a2 + 1);
  *MK_FP(v6, v7) = __CS__;
  v8 = (_WORD *)(v7 + 2);
  *(&loc_10040 + 1) = -1;
  ++loc_1003F;
  __asm { int     10h; - VIDEO - SET VIDEO MODE }
  __outbyte(0x3C4u, 4u);
  LOBYTE(v6) = __inbyte(0x3C5u);
  __outbyte(0x3C5u, v6 & 0xF7 | 4);
  __outbyte(0x3CEu, 5u);
  LOBYTE(v6) = __inbyte(0x3CFu);
  __outbyte(0x3CEu, 6u);
  LOBYTE(v6) = __inbyte(0x3CFu);
  __outbyte(0x3CFu, v6 & 0xFD);
  __outword(0x3C4u, 0xF02u);
  LOWORD(a1) = -32768;
  LOWORD(v8) = 0;
  while ( a1 )
  {
    *MK_FP(-24576, v8) = 0;
    ++v8;
    --a1;
  }
  __outbyte(0x3D4u, 0x14u);
  v9 = __inbyte(0x3D5u);
  __outbyte(0x3D5u, v9 & 0xBF);
  __outbyte(0x3D4u, 0x17u);
  v10 = __inbyte(0x3D5u);
  __outbyte(0x3D5u, v10 | 0x40);
  __outbyte(0x3CEu, 5u);
  __outbyte(0x3CFu, 0x40u);
  __outword(0x3CEu, 1u);
  __outbyte(0x3CEu, 8u);
  __outbyte(0x3CFu, 0xFFu);
  *(&loc_10032 + 1) = -24576;
  loc_10032 = *(&loc_10032 + 1) + 1024;
  *(_WORD *)Sub_0 = *(&loc_10032 + 1) + 2048;
  v11 = 0;
  v12 = 0;
  LOWORD(a1) = 256;
  do
  {
    *(_WORD _ds *)(v12 + 3764) = v11;
    *(_WORD _ds *)(v12 + 4404) = v11;
    *(_WORD _ds *)(v12 + 5044) = v11;
    v13 = __CFADD__(v11, 257);
    v11 += 257;
    if ( v13 )
      v11 = 0;
    v12 += 2;
    --a1;
  }
  while ( a1 );
  LOWORD(a1) = 200;
  LOWORD(v8) = 2078;
  v14 = 0;
  do
  {
    *v8 = v14;
    ++v8;
    v14 += 80;
    --a1;
  }
  while ( a1 );
  LOBYTE(v14) = 8;
  *(&loc_1003A + 3) = 8;
  return MK_FP(retaddr[0], retaddr[0])(v14, __CS__);
}
// 10093: write access to const memory at 10041 has been detected
// 1009A: write access to const memory at 1003F has been detected
// 10126: write access to const memory at 10034 has been detected
// 10130: write access to const memory at 10032 has been detected
// 1013A: write access to const memory at 10030 has been detected
// 1018E: write access to const memory at 1003D has been detected

//----- (00010297) --------------------------------------------------------
// write access to const memory has been detected, the output may be wrong!
int __usercall Sub_200@<eax>(__int16 a1@<dx>, int a2@<ecx>, int a3@<ebx>, _BYTE *a4@<edi>)
{
  loc_1004A ^= 1u;
  JUMPOUT(loc_1004A, 0, Sub_209);
  return Sub_209(a1, a2, a3, a4);
}
// 10297: write access to const memory at 1004A has been detected

//----- (000102A4) --------------------------------------------------------
int __usercall Sub_209@<eax>(__int16 a1@<ax>, int a2@<ecx>, int a3@<ebx>, _BYTE *a4@<edi>)
{
  __int16 v4; // dx
  char v5; // al
  char v6; // cl
  unsigned __int16 v7; // ax
  int result; // eax
  unsigned __int16 v9; // cx
  unsigned __int16 v10; // ax
  _WORD *v11; // edi
  __int16 v12; // ax
  char v13; // cf
  void *retaddr[2]; // [esp+0h] [ebp+0h]

  JUMPOUT(a2, 0, nullsub_1);
  v4 = a1;
  if ( ((unsigned __int16)a3 ^ (unsigned __int16)(a2 + a3 - 1)) & 0xFFC )
  {
    LOWORD(a4) = ((unsigned __int16)a3 >> 2) + (_WORD)a4;
    LOWORD(a3) = a3 & 3;
    v9 = a3 + a2 - 4;
    HIBYTE(v10) = *((_BYTE *)Sub_0 + a3 + 602);
    LOBYTE(v10) = 2;
    __outword(0x3C4u, v10);
    HIBYTE(v12) = HIBYTE(v4);
    *a4 = v4;
    v11 = a4 + 1;
    __outbyte(0x3C5u, 0xFu);
    LOBYTE(v12) = HIBYTE(v4);
    LOBYTE(a3) = v9;
    v9 >>= 2;
    v13 = v9 & 1;
    LOWORD(a2) = v9 >> 1;
    if ( v13 )
    {
      *(_BYTE *)v11 = HIBYTE(v4);
      v11 = (_WORD *)((char *)v11 + 1);
    }
    while ( a2 )
    {
      *v11 = v12;
      ++v11;
      --a2;
    }
    LOWORD(a3) = a3 & 3;
    __outbyte(0x3C5u, *((_BYTE *)Sub_0 + a3 + 610));
    *(_BYTE *)v11 = HIBYTE(v4);
    result = MK_FP(retaddr[0], retaddr[0])();
  }
  else
  {
    LOWORD(a4) = ((unsigned __int16)a3 >> 2) + (_WORD)a4;
    v5 = a3;
    LOWORD(a3) = ((_BYTE)a2 + (_BYTE)a3) & 3;
    v6 = v5 & 3;
    LOBYTE(v7) = 2;
    HIBYTE(v7) = *((_BYTE *)Sub_0 + a3 + 606) & (-1 << v6);
    __outword(0x3C4u, v7);
    *a4 = v4;
    result = MK_FP(retaddr[0], retaddr[0])();
  }
  return result;
}
// 10296: using guessed type int __far nullsub_1();

//----- (0001034E) --------------------------------------------------------
// write access to const memory has been detected, the output may be wrong!
int __usercall Sub_287@<eax>(__int16 a1@<dx>, int a2@<ecx>, int a3@<ebx>, _BYTE *a4@<edi>, __int16 a5@<si>)
{
  unsigned __int16 v5; // ax
  unsigned __int16 v6; // ax
  unsigned __int8 v7; // of
  __int16 v8; // si
  unsigned __int16 v9; // si
  char v10; // ah
  signed __int16 v11; // bp
  unsigned __int16 v12; // dx
  unsigned __int16 v13; // si
  __int16 v14; // ST04_2
  __int16 v15; // ST02_2
  char v16; // ah
  __int16 v17; // si
  __int16 v18; // bp
  __int16 v19; // ST04_2
  __int16 v20; // ST02_2
  char v21; // ah
  int v22; // edi
  __int16 v23; // dx
  __int16 v24; // ST04_2
  __int16 v25; // ST02_2
  char v26; // ah
  signed __int16 v27; // ax
  __int16 v28; // si
  __int16 v29; // bp
  __int16 v30; // ST04_2
  signed __int16 v31; // ST02_2
  char v32; // ah
  int v33; // edi
  __int16 v34; // dx
  __int16 v35; // ST04_2
  __int16 v36; // ST02_2
  char v37; // ah
  void *retaddr[2]; // [esp+0h] [ebp+0h]

  __DS__ = *(_WORD *)((char *)Sub_0 + 361);
  word_11654 = *(_WORD _ds *)(2 * (unsigned __int8)byte_1002E + 3764);
  LOWORD(a4) = a3 + 4 * *(_WORD _ds *)(2 * a2 + 2078);
  if ( (_WORD)a3 == a1 )
  {
    if ( (_WORD)a2 == a5 )
    {
      LOWORD(a4) = (unsigned __int16)a4 >> 2;
      LOWORD(a3) = a3 & 3;
      HIBYTE(v5) = *((_BYTE *)Sub_0 + a3 + 794);
      LOBYTE(v5) = 2;
      __outword(0x3C4u, v5);
      HIBYTE(v5) = *a4;
      *a4 = -65;
    }
    else
    {
      LOWORD(a4) = (unsigned __int16)a4 >> 2;
      LOWORD(a3) = a3 & 3;
      HIBYTE(v6) = *((_BYTE *)Sub_0 + a3 + 794);
      LOBYTE(v6) = 2;
      __outword(0x3C4u, v6);
      v7 = __OFSUB__(a5, (_WORD)a2);
      v8 = a5 - a2;
      if ( (unsigned __int8)((v8 < 0) ^ v7) | (v8 == 0) )
      {
        v9 = -2 * v8;
        LOWORD(a4) = (_WORD)a4 - *(_WORD _ds *)(v9 + 2078);
        v8 = v9 >> 1;
      }
      LOWORD(a2) = v8 + 1;
      do
      {
        v10 = *a4;
        *a4++ = -65;
        LOWORD(a4) = (_WORD)a4 + 79;
        --a2;
      }
      while ( a2 );
    }
  }
  else if ( (_WORD)a2 == a5 )
  {
    LOWORD(a4) = (unsigned __int16)(4 * *(_WORD _ds *)(2 * a2 + 2078)) >> 2;
    LOWORD(a2) = a1 - a3 + 1;
    Sub_209(7871, a2, a3, a4);
  }
  else
  {
    v11 = 320;
    v12 = a1 - a3;
    v7 = __OFSUB__(a5, (_WORD)a2);
    v13 = a5 - a2;
    if ( (unsigned __int8)(((v13 & 0x8000u) != 0) ^ v7) | (v13 == 0) )
    {
      v13 = -v13;
      v11 = -320;
    }
    LOWORD(a2) = v13;
    if ( v13 == v12 )
    {
      LOWORD(a2) = v12 + 1;
      __outbyte(0x3C4u, 2u);
      do
      {
        v14 = (signed __int16)a4;
        v15 = a3;
        LOWORD(a3) = (unsigned __int8)a4 & 3;
        __outbyte(0x3C5u, *((_BYTE *)Sub_0 + a3 + 794));
        LOWORD(a4) = (unsigned __int16)a4 >> 2;
        v16 = *a4;
        *a4++ = word_11654;
        LOWORD(a3) = v15;
        LOWORD(a4) = v11 + v14 + 1;
        --a2;
      }
      while ( a2 );
    }
    else if ( v13 >= v12 )
    {
      v27 = 1;
      if ( v11 < 0 )
      {
        LOWORD(a4) = v12 + (_WORD)a4 - 320 * v13;
        v27 = -1;
      }
      v28 = 2 * v12;
      v29 = 2 * v12 - a2 - a2;
      v30 = (signed __int16)a4;
      v31 = v27;
      LOWORD(a3) = (unsigned __int8)a4 & 3;
      __outbyte(0x3C5u, *((_BYTE *)Sub_0 + a3 + 794));
      LOWORD(a4) = (unsigned __int16)a4 >> 2;
      v32 = *a4;
      *a4 = word_11654;
      v33 = (int)(a4 + 1);
      LOWORD(a3) = v31;
      LOWORD(v33) = v30 + 1;
      v34 = 2 * v12 - a2;
      do
      {
        LOWORD(v33) = v33 + 319;
        if ( v34 < 0 )
        {
          v34 += v28;
        }
        else
        {
          LOWORD(v33) = a3 + v33;
          v34 += v29;
        }
        v35 = v33;
        v36 = a3;
        LOWORD(a3) = v33 & 3;
        __outbyte(0x3C5u, *((_BYTE *)Sub_0 + a3 + 794));
        LOWORD(v33) = (unsigned __int16)v33 >> 2;
        v37 = *(_BYTE _ds *)v33;
        *(_BYTE *)v33++ = word_11654;
        LOWORD(a3) = v36;
        LOWORD(v33) = v35 + 1;
        --a2;
      }
      while ( a2 );
    }
    else
    {
      __outbyte(0x3C4u, 2u);
      LOWORD(a2) = v12;
      v17 = 2 * v13;
      LOWORD(a3) = v11;
      v18 = v17 - v12 - v12;
      v19 = (signed __int16)a4;
      v20 = a3;
      LOWORD(a3) = (unsigned __int8)a4 & 3;
      __outbyte(0x3C5u, *((_BYTE *)Sub_0 + a3 + 794));
      LOWORD(a4) = (unsigned __int16)a4 >> 2;
      v21 = *a4;
      *a4 = word_11654;
      v22 = (int)(a4 + 1);
      LOWORD(a3) = v20;
      LOWORD(v22) = v19 + 1;
      v23 = v17 - v12;
      do
      {
        if ( v23 < 0 )
        {
          v23 += v17;
        }
        else
        {
          LOWORD(v22) = a3 + v22;
          v23 += v18;
        }
        v24 = v22;
        v25 = a3;
        LOWORD(a3) = v22 & 3;
        __outbyte(0x3C5u, *((_BYTE *)Sub_0 + a3 + 794));
        LOWORD(v22) = (unsigned __int16)v22 >> 2;
        v26 = *(_BYTE _ds *)v22;
        *(_BYTE *)v22++ = word_11654;
        LOWORD(a3) = v25;
        LOWORD(v22) = v24 + 1;
        --a2;
      }
      while ( a2 );
    }
  }
  return MK_FP(retaddr[0], retaddr[0])();
}
// 1036A: write access to const memory at 11654 has been detected
// 1002E: using guessed type char byte_1002E;
// 11654: using guessed type __int16 word_11654;

//----- (00010603) --------------------------------------------------------
// write access to const memory has been detected, the output may be wrong!
void __usercall Sub_45E(_BYTE *a1@<edi>, __int16 *a2@<esi>)
{
  __int16 v2; // ax
  __int16 *v3; // esi
  unsigned __int16 v4; // bp
  __int16 v5; // ax
  __int16 *v6; // esi
  __int16 v7; // bx
  __int16 v8; // ax
  __int16 *v9; // esi
  __int16 v10; // bx
  __int16 v11; // ax
  unsigned __int8 v12; // of
  __int16 v13; // ax
  __int16 v14; // ax
  __int16 *v15; // esi
  __int16 v16; // bx
  __int16 v17; // ax
  __int16 v18; // ax
  __int16 v19; // ax
  __int16 *v20; // esi
  __int16 v21; // bx
  __int16 v22; // ax
  __int16 v23; // ax
  int v24; // [esp-4h] [ebp-4h]

  v24 = (unsigned __int16)__DS__;
  __DS__ = *(_WORD *)((char *)Sub_0 + 361);
  LOWORD(a2) = (_WORD)a2 - *(_WORD *)((char *)Sub_0 + 363);
  v2 = *a2;
  v3 = a2 + 1;
  v4 = 2 * v2;
  v5 = *v3;
  v6 = v3 + 1;
  word_11654 = v5;
  v7 = 2 * (unsigned __int8)byte_1002D;
  *(&loc_10040 + 2) = *(_WORD _ds *)(v7 + 3764);
  if ( *(_WORD _ds *)(v7 + 4404) == *(&loc_10040 + 2) )
  {
    while ( 1 )
    {
      v8 = *v6;
      v9 = v6 + 1;
      v10 = v8;
      v11 = *v9;
      v6 = v9 + 1;
      v12 = __OFSUB__(v11, v10);
      v13 = v11 - v10;
      if ( !((v13 < 0) ^ v12) )
      {
        LOWORD(a1) = *(_WORD _ds *)(v4 + 2078);
        Sub_209(*(&loc_10040 + 2), v13 + 1, v10, a1);
      }
      word_11654 = 7870;
      v4 += 2;
    }
  }
  *(_WORD *)((char *)&loc_10045 + 1) = *(_WORD _ds *)(v7 + 4404);
  if ( __SETP__(v4 >> 1, 0) )
    goto LABEL_9;
  while ( 1 )
  {
    v14 = *v6;
    v15 = v6 + 1;
    v16 = v14;
    v17 = *v15;
    v6 = v15 + 1;
    v12 = __OFSUB__(v17, v16);
    v18 = v17 - v16;
    if ( !((v18 < 0) ^ v12) )
    {
      LOWORD(a1) = *(_WORD _ds *)(v4 + 2078);
      Sub_209(*(&loc_10040 + 2), v18 + 1, v16, a1);
    }
    word_11654 = 7870;
    v4 += 2;
LABEL_9:
    v19 = *v6;
    v20 = v6 + 1;
    v21 = v19;
    v22 = *v20;
    v6 = v20 + 1;
    v12 = __OFSUB__(v22, v21);
    v23 = v22 - v21;
    if ( !((v23 < 0) ^ v12) )
    {
      LOWORD(a1) = *(_WORD _ds *)(v4 + 2078);
      Sub_209(*(__int16 *)((char *)&loc_10045 + 1), v23 + 1, v21, a1);
    }
    word_11654 = 7870;
    v4 += 2;
  }
}
// 1061E: write access to const memory at 11654 has been detected
// 10640: write access to const memory at 10044 has been detected
// 1067E: write access to const memory at 11654 has been detected
// 10690: write access to const memory at 10046 has been detected
// 106C8: write access to const memory at 11654 has been detected
// 106FE: write access to const memory at 11654 has been detected
// 1002D: using guessed type char byte_1002D;
// 11654: using guessed type __int16 word_11654;

//----- (00010725) --------------------------------------------------------
int __usercall Sub_52A@<eax>(int a1@<ecx>, _BYTE *a2@<esi>)
{
  __int16 v2; // sp
  __int16 v3; // bp
  __int16 v4; // sp
  __int16 v5; // bx
  unsigned __int8 v6; // al
  unsigned __int8 v7; // al
  unsigned __int8 v8; // al
  __int16 v9; // ax
  void *retaddr[2]; // [esp+6h] [ebp+2h]

  v3 = v2;
  LOWORD(a2) = *(_WORD _ds *)(v3 + 6);
  LOWORD(a1) = 3 * *(_WORD _ds *)(v3 + 10);
  v5 = *(_WORD _ds *)(v3 + 8);
  do
    v6 = __inbyte(0x3DAu);
  while ( !(v6 & 8) );
  v7 = __inbyte(0x3C7u);
  v8 = v7 & 3;
  if ( v8 != 3 )
    __outbyte(0x3C9u, v8);
  v9 = *(_WORD _ds *)(v4 + 8);
  __outbyte(0x3C8u, v5);
  _disable();
  do
  {
    LOBYTE(v9) = *a2++;
    __outbyte(0x3C9u, v9);
    --a1;
  }
  while ( a1 );
  _enable();
  return MK_FP(retaddr[0], retaddr[0])(v9, 969);
}

//----- (00010778) --------------------------------------------------------
void __usercall Sub_567(int a1@<ecx>, _BYTE *a2@<esi>)
{
  __int16 v2; // sp
  __int16 v3; // bp
  int v4; // [esp-4h] [ebp-6h]

  v3 = v2;
  LOWORD(a2) = v3 + 6;
  HIWORD(v4) = 1;
  LOWORD(v4) = *(_WORD _ds *)(v3 + 10);
  Sub_52A(a1, a2);
  JUMPOUT(v4, v4);
}

//----- (0001079E) --------------------------------------------------------
int __usercall Sub_57E@<eax>(int a1@<edx>, int a2@<ebx>)
{
  __int16 v2; // sp
  __int16 v3; // bp
  int v4; // eax
  __int16 v5; // sp
  __int16 v6; // ST06_2
  __int16 v7; // ax
  void *retaddr[2]; // [esp+8h] [ebp+2h]

  v3 = v2;
  LOWORD(a2) = 2 * *(_WORD _ds *)(v3 + 8);
  LOWORD(v4) = *(_WORD *)((char *)Sub_0 + a2 + 1759);
  if ( (_WORD)v4 || (v4 = (*(int (__fastcall **)(signed __int16, int))((char *)Sub_0 + 573))(768, a1), (_WORD)v4) )
  {
    *(_WORD _ds *)(v5 - 2) = v4;
    v6 = *(_WORD _ds *)(v5 + 6);
    v7 = *(_WORD _ds *)(v5 - 2);
    v4 = (*(int (__fastcall **)(__int16, int))((char *)Sub_0 + 565))(v7, a1);
    LOWORD(a2) = 2 * *(_WORD _ds *)(v5 + 8);
    *(_WORD *)((char *)Sub_0 + a2 + 1759) = *(_WORD _ds *)(v5 - 2);
    LOWORD(v4) = *(_WORD _ds *)(v5 + 8);
  }
  return MK_FP(retaddr[0], retaddr[0])(v4);
}
// 10289: using guessed type int __fastcall nullsub_2(_DWORD, _DWORD);

//----- (00010825) --------------------------------------------------------
void __usercall Sub_5D6(int a1@<ecx>, int a2@<ebx>, _WORD *a3@<edi>, _BYTE *a4@<esi>)
{
  __int16 v4; // sp
  __int16 v5; // bp
  int v6; // ecx
  __int16 v7; // sp
  __int16 v8; // ax
  __int16 savedregs; // [esp+4h] [ebp+0h]

  v5 = v4;
  LOWORD(a2) = 2 * *(_WORD _ds *)(v5 + 6);
  *(_WORD *)((char *)Sub_0 + 1779) = a2;
  LOWORD(a4) = *(_WORD *)((char *)Sub_0 + a2 + 1759);
  if ( (_WORD)a4 )
  {
    Sub_52A(a1, a4);
    LOWORD(a3) = *(_WORD *)((char *)Sub_0 + 1759);
    LOWORD(v6) = 384;
    while ( v6 )
    {
      *a3 = *(_WORD *)a4;
      a4 += 2;
      ++a3;
      --v6;
    }
    LOWORD(a4) = (_WORD)a4 - 768;
    LOWORD(v6) = 384;
    while ( v6 )
    {
      *a3 = *(_WORD *)a4;
      a4 += 2;
      ++a3;
      --v6;
    }
    v8 = *(_WORD _ds *)(v7 + 6);
  }
  JUMPOUT(savedregs, *(_DWORD *)&savedregs);
}

//----- (0001088E) --------------------------------------------------------
void __usercall Sub_61A(int a1@<ecx>, _BYTE *a2@<edi>, unsigned __int8 *a3@<esi>)
{
  __int16 v3; // sp
  __int16 v4; // bp
  unsigned __int8 v5; // dl
  __int16 v6; // bp
  char v7; // bl
  unsigned __int8 v8; // al
  char v9; // bh
  unsigned __int8 v10; // dl
  __int16 vars0; // [esp+0h] [ebp+0h]

  v4 = v3;
  LOWORD(a1) = 3 * *(_WORD _ds *)(v4 + 8);
  v5 = *(_BYTE _ds *)(v4 + 12);
  LOWORD(a2) = 2 * *(_WORD _ds *)(v4 + 6) + *(_WORD _ds *)(v4 + 6) + *(_WORD *)((char *)Sub_0 + 1759);
  LOWORD(a3) = (_WORD)a2 + 768;
  v6 = 2 * *(_WORD _ds *)(v4 + 10) + *(_WORD _ds *)(v4 + 10) + *(_WORD *)((char *)Sub_0 + 1759) + 768;
  v7 = 0;
  while ( 1 )
  {
    v8 = *a3++;
    v9 = (unsigned __int16)(v5 * v8) / 0x3Fu;
    v10 = 63 - v5;
    *a2++ = v9 + (unsigned __int16)(v10 * *(unsigned __int8 *)v6) / 0x3Fu;
    v5 = 63 - v10;
    ++v6;
    if ( ++v7 == 3 )
    {
      v7 = 0;
      v6 -= 3;
    }
    if ( !--a1 )
    {
      Sub_52A(0, a3);
      JUMPOUT(vars0, *(_DWORD *)&vars0);
    }
  }
}

//----- (00010939) --------------------------------------------------------
int Sub_699()
{
  __int16 v0; // sp
  __int16 v1; // bp
  unsigned __int16 v2; // di
  unsigned __int16 v3; // bx
  unsigned __int16 v4; // dx
  __int16 v5; // sp
  void *retaddr[2]; // [esp+6h] [ebp+2h]

  v1 = v0;
  v2 = *(_WORD _ds *)(v1 + 6);
  v3 = 0;
  v4 = 0;
  while ( *(_WORD _ds *)v2 )
  {
    v4 = (__PAIR__(v4, (unsigned __int16)(*(_WORD _ds *)(*(_WORD _ds *)v2 + 8) * *(_WORD _ds *)(*(_WORD _ds *)v2 + 6)))
        + v3) >> 16;
    v3 += *(_WORD _ds *)(*(_WORD _ds *)v2 + 8) * *(_WORD _ds *)(*(_WORD _ds *)v2 + 6);
    v2 += 2;
  }
  **(_WORD _ds **)(v5 + 8) = 0;
  return MK_FP(retaddr[0], retaddr[0])(v3, v4);
}

//----- (00010989) --------------------------------------------------------
int Sub_6CC()
{
  __int16 v0; // sp
  __int16 v1; // bp
  unsigned __int16 v2; // di
  __int16 v3; // sp
  unsigned __int16 v4; // si
  __int16 v5; // ax
  bool v6; // cf
  unsigned __int16 v7; // cx
  __int16 v8; // sp
  __int16 v9; // sp
  __int16 v10; // si
  __int16 v11; // ax
  unsigned __int16 v12; // si
  unsigned __int16 v13; // cx
  __int16 v14; // bx
  __int16 v15; // bx
  unsigned __int16 v16; // si
  __int16 v17; // sp
  __int16 v18; // di
  __int16 v19; // sp
  __int16 v20; // ax
  unsigned __int16 v21; // dx
  __int16 v22; // bx
  __int16 v23; // bx
  __int16 v24; // dx
  __int16 v25; // dx
  unsigned __int16 v26; // di
  unsigned __int16 v27; // cx
  __int16 v28; // ax
  unsigned __int16 v29; // cx
  unsigned __int16 v30; // cx
  __int16 v31; // sp
  __int16 v32; // sp
  __int16 v33; // ax
  void *retaddr[2]; // [esp+6h] [ebp+2h]

  v1 = v0;
  v2 = *(_WORD _ds *)(v1 + 8);
  __ES__ = *(_WORD _ds *)(v1 + 10);
  while ( 1 )
  {
    v4 = **(_WORD _ds **)(v3 + 6);
    if ( !v4 )
      break;
    *(_WORD _ds *)v4 = (v2 >> 4) + __ES__;
    *(_WORD _ds *)(v4 + 2) = v2 & 0xF;
    v5 = *(_WORD _ds *)(v4 + 8) * *(_WORD _ds *)(v4 + 6);
    v6 = __CFADD__(v5, v2);
    v2 += v5;
    v7 = __RCR__(0, v6);
    __ES__ += v7 >> 3;
    *(_WORD _ds *)(v8 + 6) += 2;
  }
  v10 = *(_WORD _ds *)(v9 + 8);
  v11 = *(_WORD _ds *)(v9 + 10);
  v6 = __CFADD__(*(_WORD _ds *)(v9 + 12), v10);
  v12 = *(_WORD _ds *)(v9 + 12) + v10;
  v13 = __RCR__(0, v6);
  HIBYTE(v14) = *(_BYTE _ds *)(v9 + 14);
  LOBYTE(v14) = 0;
  v15 = (v13 >> 3) + 16 * v14;
  v6 = v12 < 1u;
  v16 = v12 - 1;
  if ( v6 )
    v11 -= 4096;
  __DS__ = v15 + v11;
  v18 = *(_WORD _ds *)(v17 + 8);
  v21 = *(_WORD _ds *)(v17 + 12);
  HIBYTE(v22) = *(_BYTE _ds *)(v17 + 14);
  LOBYTE(v22) = 0;
  v23 = 32 * v22;
  v6 = v21 < 1u;
  v24 = v21 - 1;
  if ( v6 )
    v24 -= 4096;
  v6 = __CFSHL__(v24, 1);
  v25 = 2 * v24;
  if ( v6 )
    v23 += 4096;
  v6 = __CFADD__(v25, v18);
  v26 = v25 + v18;
  v27 = __RCR__(0, v6);
  v20 = *(_WORD _ds *)(v19 + 10);
  __ES__ = (v27 >> 3) + v23 + v20;
  do
  {
    LOBYTE(v28) = *(_BYTE _ds *)v16;
    v6 = v16-- < 1u;
    v29 = __RCR__(0, v6);
    __DS__ -= v29 >> 3;
    HIBYTE(v28) = v28;
    LOBYTE(v28) = (unsigned __int8)v28 >> 4;
    *(_WORD _ds *)v26 = v28 & 0xF0F;
    v6 = v26 < 2u;
    v26 -= 2;
    v30 = __RCR__(0, v6);
    __ES__ -= v30 >> 3;
    v6 = (*(_WORD _ds *)(v31 + 12))-- < 1u;
    *(_WORD _ds *)(v31 + 14) -= v6;
  }
  while ( *(_DWORD _ds *)(v31 + 12) );
  v33 = *(_WORD _ds *)(v32 + 14) | *(_WORD _ds *)(v32 + 12);
  return MK_FP(retaddr[0], retaddr[0])(v33);
}

//----- (00010AFA) --------------------------------------------------------
int __fastcall Sub_7C7(int a1, int a2, int a3)
{
  __int16 v3; // sp
  __int16 v4; // bp
  unsigned __int16 v5; // si
  unsigned __int16 v6; // di
  __int16 v7; // ax
  unsigned __int8 v8; // cf
  unsigned __int16 v9; // dx
  unsigned __int16 v10; // dx
  void *retaddr[2]; // [esp+6h] [ebp+2h]

  v4 = v3;
  v5 = *(_WORD _ds *)(v4 + 6);
  __DS__ = *(_WORD _ds *)(v4 + 8);
  v6 = *(_WORD _ds *)(v4 + 10);
  __ES__ = *(_WORD _ds *)(v4 + 12);
  LOWORD(a3) = *(_WORD _ds *)(v4 + 14);
  do
  {
    LOBYTE(v7) = *(_BYTE _ds *)v5;
    v8 = __CFADD__(v5++, 1);
    v9 = __RCR__(0, v8);
    __DS__ += v9 >> 3;
    HIBYTE(v7) = 16 * v7;
    *(_WORD _ds *)v6 |= v7 & 0xF0F0;
    v8 = __CFADD__(v6, 2);
    v6 += 2;
    v10 = __RCR__(0, v8);
    __ES__ += v10 >> 3;
    --a3;
  }
  while ( a3 );
  return MK_FP(retaddr[0], retaddr[0])();
}

//----- (00010B75) --------------------------------------------------------
int __usercall Sub_81B@<eax>(int a1@<ecx>, _BYTE *a2@<edi>, _BYTE *a3@<esi>)
{
  __int16 v3; // sp
  __int16 v4; // bp
  __int16 v5; // ax
  void *retaddr[2]; // [esp+4h] [ebp+2h]

  v4 = v3;
  LOWORD(a3) = *(_WORD _ds *)(v4 + 6);
  if ( (_WORD)a3 )
  {
    while ( 1 )
    {
      v5 = *(_WORD *)a3;
      a3 += 2;
      if ( !v5 )
        break;
      Sub_837(a1, a2, a3);
    }
  }
  return MK_FP(retaddr[0], retaddr[0])();
}

//----- (00010B9F) --------------------------------------------------------
void __usercall Sub_837(int a1@<ecx>, _BYTE *a2@<edi>, _BYTE *a3@<esi>)
{
  __int16 v3; // sp
  __int16 v4; // bp
  unsigned __int16 v5; // bp
  unsigned __int16 v6; // ax
  unsigned __int16 v7; // ST18_2
  __int16 v8; // bx
  __int16 v9; // cx
  __int16 v10; // ax
  bool v11; // zf
  unsigned __int16 v12; // cx
  char v13; // cf
  int v14; // ecx
  int v15; // ecx
  int v16; // ecx
  unsigned __int16 v17; // [esp-Ah] [ebp-Eh]
  __int16 v18; // [esp-6h] [ebp-Ah]

  v4 = v3;
  v5 = *(_WORD _ds *)(v4 + 4);
  v6 = *(_WORD _ds *)(v5 + 8) * *(_WORD _ds *)(v5 + 6);
  v7 = v6;
  v10 = (unsigned __int16)(v6 + 15) >> 4;
  v8 = v10;
  v9 = v10;
  HIBYTE(v10) = 72;
  __asm { int     21h; DOS - 2+ - ALLOCATE MEMORY }
  v11 = v8 == v9;
  v12 = v7;
  if ( v11 )
  {
    __DS__ = *(_WORD _ds *)v5;
    LOWORD(a3) = *(_WORD _ds *)(v5 + 2);
    LOWORD(a2) = 0;
    v18 = *(_WORD _ds *)(v5 + 2);
    v13 = v12 & 1;
    LOWORD(a1) = v12 >> 1;
    v17 = a1;
    if ( v13 )
      *MK_FP(v10, a2++) = *a3++;
    while ( a1 )
    {
      *MK_FP(v10, a2) = *(_WORD *)a3;
      a3 += 2;
      a2 += 2;
      --a1;
    }
    LOWORD(a2) = 0;
    LOWORD(a3) = v18;
    Sub_8BF(v17 >> 1, a2, a3);
    LOWORD(v14) = v17 >> 1;
    LOWORD(a3) = (v17 >> 1) + v18;
    LOWORD(a2) = 1;
    Sub_8BF(v14, a2, a3);
    LOWORD(v15) = v17 >> 1;
    LOWORD(a3) = (v17 >> 1) + (_WORD)a3;
    LOWORD(a2) = 2;
    Sub_8BF(v15, a2, a3);
    LOWORD(v16) = v17 >> 1;
    LOWORD(a3) = (v17 >> 1) + (_WORD)a3;
    LOWORD(a2) = 3;
    Sub_8BF(v16, a2, a3);
    __asm { int     21h; DOS - 2+ - FREE MEMORY }
  }
}

//----- (00010C76) --------------------------------------------------------
void __usercall Sub_8BF(int a1@<ecx>, _BYTE *a2@<edi>, _BYTE *a3@<esi>)
{
  __int16 v3; // sp
  __int16 v4; // bp

  v4 = v3;
  LOWORD(a1) = *(_WORD _ds *)(v4 + 4);
  LOWORD(a3) = *(_WORD _ds *)(v4 + 6);
  __DS__ = *(_WORD _ds *)(v4 + 8);
  LOWORD(a2) = *(_WORD _ds *)(v4 + 10);
  __ES__ = *(_WORD _ds *)(v4 + 12);
  do
  {
    *a2++ = *a3++;
    LOWORD(a3) = (_WORD)a3 + 3;
    --a1;
  }
  while ( a1 );
}

//----- (00010CB0) --------------------------------------------------------
int __usercall Sub_8E7@<eax>(int a1@<ecx>, _WORD *a2@<edi>, char *a3@<esi>, char a4@<efl>)
{
  __int16 v4; // sp
  __int16 v5; // bp
  __int16 v6; // sp
  unsigned __int16 v7; // ax
  __int16 v8; // sp
  __int16 v9; // dx
  unsigned __int16 v10; // bx
  __int16 v11; // sp
  __int16 v12; // ax
  __int16 v13; // ax
  __int16 v14; // sp
  unsigned __int16 v15; // ax
  __int16 v16; // sp
  __int16 v17; // ax
  __int16 v18; // ax
  __int16 v19; // sp
  __int16 v20; // ax
  __int16 v21; // sp
  __int16 v22; // sp
  __int16 v23; // t1
  unsigned __int16 v24; // ax
  __int16 v25; // sp
  __int16 v26; // di
  __int16 v27; // sp
  char v28; // cl
  unsigned __int8 v29; // ch
  __int16 v30; // bx
  __int16 v31; // bp
  unsigned __int8 v32; // ch
  __int16 v33; // bx
  char v34; // dh
  char v35; // cl
  char v36; // al
  __int16 v37; // si
  __int16 v38; // bp
  unsigned __int8 v39; // cf
  unsigned __int8 v40; // ch
  char v41; // cl
  char v42; // al
  __int16 v43; // si
  __int16 v44; // bp
  unsigned __int8 v45; // cf
  char v46; // ch
  char v47; // cl
  char v48; // al
  __int16 v49; // si
  char v50; // cl
  __int16 v52; // [esp-12h] [ebp-20h]
  __int16 v53; // [esp-12h] [ebp-20h]
  __int16 v54; // [esp-12h] [ebp-20h]
  __int16 v55; // [esp-12h] [ebp-20h]
  __int16 v56; // [esp-10h] [ebp-1Eh]
  __int16 v57; // [esp-10h] [ebp-1Eh]
  __int16 v58; // [esp-10h] [ebp-1Eh]
  __int16 v59; // [esp-Eh] [ebp-1Ch]
  __int16 v60; // [esp-Eh] [ebp-1Ch]
  __int16 v61; // [esp-Eh] [ebp-1Ch]
  __int16 v62; // [esp-Ch] [ebp-1Ah]
  __int16 v63; // [esp-Ah] [ebp-18h]
  unsigned __int8 v64; // [esp-9h] [ebp-17h]
  void *retaddr[2]; // [esp+10h] [ebp+2h]

  v5 = v4;
  LOWORD(a3) = *(_WORD _ds *)(v5 + 6);
  LOWORD(a2) = v5 - 10;
  LOWORD(a1) = 5;
  while ( a1 )
  {
    *a2 = *(_WORD *)a3;
    a3 += 2;
    ++a2;
    --a1;
  }
  __DS__ = *(_WORD *)((char *)Sub_0 + 361);
  *((_WORD *)Sub_0 + 1598) = 0;
  LOWORD(a3) = *(_WORD _ds *)(v6 - 8);
  LOWORD(a2) = *(_WORD _ds *)(2 * *(_WORD _ds *)(v6 + 10) + 2078);
  v7 = *(_WORD _ds *)(v6 + 8);
  *((_WORD *)Sub_0 + 1599) = v7;
  if ( (signed __int16)v7 > 0 )
    LOWORD(a2) = (v7 >> 2) + (_WORD)a2;
  HIBYTE(v9) = *(_BYTE _ds *)(v8 - 4);
  LOBYTE(v9) = *(_BYTE _ds *)(v8 - 2);
  v10 = 0;
  if ( !byte_1002B )
  {
LABEL_23:
    __DS__ = *(_WORD _ds *)(v27 - 10);
    *((_WORD *)Sub_0 + 1597) = (unsigned __int16)(*(unsigned __int8 *)(v27 - 2) * *(unsigned __int8 *)(v27 - 4)) >> 2;
    LOBYTE(v15) = 2;
    HIBYTE(v15) = 1 << (*((_BYTE *)Sub_0 + 3198) & 3);
    __outword(0x3C4u, v15);
    v28 = HIBYTE(v9) & 3;
    if ( !(v9 & 0x300) )
      v28 = 4;
    v29 = __ROL1__(-16, v28);
    HIBYTE(v9) = (unsigned __int8)(HIBYTE(v9) + 3) >> 2;
    v30 = v10 >> 2;
    v31 = *((_WORD *)Sub_0 + 1598) & 3;
    if ( v31 )
    {
      v64 = __ROL1__(-16, v28);
      LOWORD(a1) = *((_WORD *)Sub_0 + 1598) & 3;
      do
      {
        LOWORD(a3) = *((_WORD *)Sub_0 + 1597) + (_WORD)a3;
        --a1;
      }
      while ( a1 );
      LOWORD(a3) = (_WORD)a3 - 1;
      v29 = v64;
    }
    --HIBYTE(v9);
    v63 = v30 + 1;
    v62 = v9;
    v59 = (signed __int16)a2;
    v56 = (signed __int16)a3;
    v39 = v29 & 1;
    v32 = v29 >> 1;
    v33 = v30 + 1 - v39;
    v34 = ((a4 & 1) != 0) + HIBYTE(v9);
    do
    {
      v35 = v34;
      v52 = (signed __int16)a2;
      do
      {
        v36 = *a3++;
        if ( v36 )
        {
          *MK_FP(loc_10038, a2) = v36;
          a2 = (_WORD *)((char *)a2 + 1);
          LOWORD(a2) = (_WORD)a2 - 1;
        }
        LOWORD(a2) = (_WORD)a2 + 1;
        --v35;
      }
      while ( v35 );
      LOWORD(a3) = v33 + (_WORD)a3;
      LOWORD(a2) = v52 + 80;
      LOBYTE(v9) = v9 - 1;
    }
    while ( (_BYTE)v9 );
    v37 = v56;
    v38 = v31 + 1;
    if ( v38 == 4 )
    {
      v38 = 0;
      v37 = v56 - 4 * *((_WORD *)Sub_0 + 1597) + 1;
    }
    LOWORD(a3) = *((_WORD *)Sub_0 + 1597) + v37;
    LOWORD(a2) = v59;
    HIBYTE(v15) *= 2;
    if ( HIBYTE(v15) == 16 )
    {
      LOWORD(a2) = v59 + 1;
      HIBYTE(v15) = 1;
    }
    __outbyte(0x3C5u, HIBYTE(v15));
    LOBYTE(v9) = v62;
    v60 = (signed __int16)a2;
    v57 = (signed __int16)a3;
    v39 = v32 & 1;
    v40 = v32 >> 1;
    HIBYTE(v9) = ((a4 & 1) != 0) + HIBYTE(v62);
    LOBYTE(v15) = a4;
    if ( HIBYTE(v9) )
    {
      do
      {
        v41 = ((a4 & 1) != 0) + HIBYTE(v62);
        v53 = (signed __int16)a2;
        do
        {
          v42 = *a3++;
          if ( v42 )
          {
            *MK_FP(loc_10038, a2) = v42;
            a2 = (_WORD *)((char *)a2 + 1);
            LOWORD(a2) = (_WORD)a2 - 1;
          }
          LOWORD(a2) = (_WORD)a2 + 1;
          --v41;
        }
        while ( v41 );
        LOWORD(a3) = v63 - v39 + (_WORD)a3;
        LOWORD(a2) = v53 + 80;
        LOBYTE(v9) = v9 - 1;
      }
      while ( (_BYTE)v9 );
      v43 = v57;
      v44 = v38 + 1;
      if ( v44 == 4 )
      {
        v44 = 0;
        v43 = v57 - 4 * *((_WORD *)Sub_0 + 1597) + 1;
      }
      LOWORD(a3) = *((_WORD *)Sub_0 + 1597) + v43;
      LOWORD(a2) = v60;
      HIBYTE(v15) *= 2;
      if ( HIBYTE(v15) == 16 )
      {
        LOWORD(a2) = v60 + 1;
        HIBYTE(v15) = 1;
      }
      __outbyte(0x3C5u, HIBYTE(v15));
      LOBYTE(v9) = v62;
      v61 = (signed __int16)a2;
      v58 = (signed __int16)a3;
      v45 = v40 & 1;
      v46 = v40 >> 1;
      HIBYTE(v9) = ((a4 & 1) != 0) + HIBYTE(v62);
      LOBYTE(v15) = a4;
      if ( HIBYTE(v9) )
      {
        do
        {
          v47 = ((a4 & 1) != 0) + HIBYTE(v62);
          v54 = (signed __int16)a2;
          do
          {
            v48 = *a3++;
            if ( v48 )
            {
              *MK_FP(loc_10038, a2) = v48;
              a2 = (_WORD *)((char *)a2 + 1);
              LOWORD(a2) = (_WORD)a2 - 1;
            }
            LOWORD(a2) = (_WORD)a2 + 1;
            --v47;
          }
          while ( v47 );
          LOWORD(a3) = v63 - v45 + (_WORD)a3;
          LOWORD(a2) = v54 + 80;
          LOBYTE(v9) = v9 - 1;
        }
        while ( (_BYTE)v9 );
        v49 = v58;
        if ( v44 == 3 )
          v49 = v58 - 4 * *((_WORD *)Sub_0 + 1597) + 1;
        LOWORD(a3) = *((_WORD *)Sub_0 + 1597) + v49;
        LOWORD(a2) = v61;
        HIBYTE(v15) *= 2;
        if ( HIBYTE(v15) == 16 )
        {
          LOWORD(a2) = v61 + 1;
          HIBYTE(v15) = 1;
        }
        __outbyte(0x3C5u, HIBYTE(v15));
        LOBYTE(v9) = v62;
        HIBYTE(v9) = ((a4 & 1) != 0) + HIBYTE(v62);
        LOBYTE(v15) = a4;
        if ( HIBYTE(v9) )
        {
          do
          {
            v50 = ((a4 & 1) != 0) + HIBYTE(v62);
            v55 = (signed __int16)a2;
            do
            {
              LOBYTE(v15) = *a3++;
              if ( (_BYTE)v15 )
              {
                *MK_FP(loc_10038, a2) = v15;
                a2 = (_WORD *)((char *)a2 + 1);
                LOWORD(a2) = (_WORD)a2 - 1;
              }
              LOWORD(a2) = (_WORD)a2 + 1;
              --v50;
            }
            while ( v50 );
            LOWORD(a3) = v63 - (v46 & 1) + (_WORD)a3;
            LOWORD(a2) = v55 + 80;
            LOBYTE(v9) = v9 - 1;
          }
          while ( (_BYTE)v9 );
        }
      }
    }
    return MK_FP(retaddr[0], retaddr[0])(v15, v9);
  }
  v12 = word_10025 - *(_WORD _ds *)(v11 + 8);
  v13 = v12 - *(unsigned __int8 *)(v11 - 4);
  if ( v13 >= 0
    || (v15 = -v13,
        v10 = v15,
        HIBYTE(v9) -= v15,
        v39 = (unsigned __int8)v15 < *(_BYTE _ds *)(v14 - 4),
        LOBYTE(v15) = v15 - *(_BYTE _ds *)(v14 - 4),
        v39) )
  {
    v17 = word_10029 - *(_WORD _ds *)(v16 + 10);
    v18 = v17 - *(unsigned __int8 *)(v16 - 2);
    if ( v18 >= 0
      || (v15 = -v18 - 1,
          v39 = (unsigned __int8)v9 < (unsigned __int8)v15,
          LOBYTE(v9) = v9 - v15,
          !(v39 | ((_BYTE)v9 == 0))) )
    {
      if ( word_10027 <= *(_WORD _ds *)(v19 + 10) )
        goto LABEL_68;
      v20 = word_10027 - *(_WORD _ds *)(v19 + 10);
      LOBYTE(v20) = v20 - 1;
      LOBYTE(v9) = v9 - v20;
      LOWORD(a3) = ((unsigned __int16)(*(unsigned __int8 *)(v19 - 4) * (unsigned __int8)v20) >> 2) + (_WORD)a3;
      LOWORD(a2) = *(_WORD _ds *)(2 * word_10027 + 2078);
      v15 = *(_WORD _ds *)(v19 + 8);
      if ( (signed __int16)v15 > 0 )
      {
        v15 >>= 2;
        LOWORD(a2) = v15 + (_WORD)a2;
      }
      if ( (_BYTE)v9 && (v9 & 0x80u) == 0 )
      {
LABEL_68:
        if ( word_10023 > *(_WORD _ds *)(v21 + 8) )
        {
          v15 = word_10023 - *(_WORD _ds *)(v21 + 8) - 1;
          v39 = (unsigned __int8)v15 < *(_BYTE _ds *)(v21 - 4);
          if ( !v39 )
            return MK_FP(retaddr[0], retaddr[0])(v15, v9);
          HIBYTE(v9) -= v15;
          v23 = *(_WORD _ds *)(v22 + 8);
          v10 = word_10023 - *(_WORD _ds *)(v22 + 8) - 1;
          *((_WORD *)Sub_0 + 1598) = v15;
          LOWORD(a3) = (v15 >> 2) + (_WORD)a3;
          if ( v15 & 3 )
            LOWORD(a3) = (_WORD)a3 + 1;
          v24 = word_10023;
          *((_WORD *)Sub_0 + 1599) = word_10023;
          v26 = *(_WORD _ds *)(2 * *(_WORD _ds *)(v25 + 10) + 2078);
          LOWORD(a2) = (v24 >> 2) + v26;
        }
        goto LABEL_23;
      }
    }
  }
  return MK_FP(retaddr[0], retaddr[0])(v15, v9);
}
// 10023: using guessed type __int16 word_10023;
// 10025: using guessed type __int16 word_10025;
// 10027: using guessed type __int16 word_10027;
// 10029: using guessed type __int16 word_10029;
// 1002B: using guessed type char byte_1002B;

//----- (0001107A) --------------------------------------------------------
int __usercall Sub_B9D@<eax>(__int16 a1@<bx>, char *a2@<edi>, char *a3@<esi>)
{
  __int16 v3; // sp
  __int16 v4; // bp
  __int16 v5; // si
  char v6; // dl
  __int16 v7; // ax
  int v8; // edx
  unsigned __int16 v9; // si
  unsigned __int16 v10; // ax
  __int16 v11; // t2
  __int16 v12; // sp
  __int16 v13; // ST06_2
  int v14; // eax
  __int16 v15; // sp
  unsigned int v16; // ecx
  __int16 v18; // ST02_2
  __int16 v19; // sp
  int v20; // eax
  unsigned int v21; // ecx
  __int16 v23; // [esp-6h] [ebp-Ah]
  void *retaddr[2]; // [esp+6h] [ebp+2h]

  v4 = v3;
  v5 = *(_WORD _ds *)(v4 + 8);
  __DS__ = *(_WORD *)((char *)Sub_0 + 361);
  v6 = *(_BYTE _ds *)(v5 + 52) >> 3;
  if ( *(_BYTE _ds *)(v5 + 52) & 7 )
    ++v6;
  v7 = *(unsigned __int8 *)(v5 + 112) * (unsigned __int8)(v6 * *(_BYTE _ds *)(v5 + 72));
  *((_WORD *)Sub_0 + 2084) = v7;
  LOBYTE(v7) = v7 & 0xF;
  LOWORD(v8) = a1;
  HIBYTE(v7) = 72;
  __asm { int     21h; DOS - 2+ - ALLOCATE MEMORY }
  v9 = 2 * v5;
  *(_WORD _ds *)(v9 + 132) = v7;
  v23 = v9 >> 1;
  *((_WORD *)Sub_0 + 2083) = v7;
  LOWORD(a2) = 0;
  v10 = *((_WORD *)Sub_0 + 2084);
  v11 = v10 % 0x50u;
  LOBYTE(v10) = v10 / 0x50u;
  HIBYTE(v10) = v11;
  *((_WORD *)Sub_0 + 2084) = v10;
  v13 = *(_WORD _ds *)(v12 + 6);
  LOWORD(v14) = *(_WORD _ds *)(v12 + 10);
  do
  {
    v14 = (*(int (__fastcall **)(_WORD, _WORD))((char *)Sub_0 + 565))(v14, v8);
    __ES__ = *((_WORD *)Sub_0 + 2083);
    LOWORD(a3) = *(_WORD _ds *)(v15 + 10);
    LOWORD(v16) = 80;
    qmemcpy(a2, a3, v16);
    a3 += v16;
    a2 += v16;
  }
  while ( (*((_BYTE *)Sub_0 + 4168))-- != 1 );
  v18 = *((unsigned __int8 *)Sub_0 + 4169);
  LOWORD(v14) = *(_WORD _ds *)(v19 + 10);
  v20 = (*(int (__fastcall **)(int, int))((char *)Sub_0 + 565))(v14, v8);
  LOWORD(v21) = v18;
  __ES__ = *((_WORD *)Sub_0 + 2083);
  LOWORD(a3) = *(_WORD _ds *)(v19 + 10);
  qmemcpy(a2, a3, v21);
  LOWORD(v20) = v23;
  return MK_FP(retaddr[0], retaddr[0])(v20);
}
// 10289: using guessed type int __fastcall nullsub_2(_DWORD, _DWORD);

//----- (00011192) --------------------------------------------------------
int __usercall Sub_C5F@<eax>(char a1@<al>, unsigned __int16 a2@<dx>, __int16 a3@<bp>, _BYTE *a4@<edi>)
{
  __int16 v4; // ax
  __int16 v5; // di
  __int16 v6; // bp
  __int16 v7; // si
  __int16 v8; // ax
  __int16 v9; // cx
  char v10; // ah
  char v11; // ah
  char v12; // ah
  char v13; // ah
  char v14; // ah
  char v15; // ah
  char v16; // ah
  unsigned __int8 v17; // ah
  _BYTE *v18; // edi
  char v19; // ah
  char v20; // ah
  char v21; // ah
  unsigned __int8 v22; // ah
  __int16 v23; // ax
  unsigned __int16 v24; // bx
  __int16 v25; // bx
  unsigned __int8 v26; // cf
  char v27; // ah
  char v28; // ah
  char v29; // ah
  char v30; // ah
  char v31; // ah
  char v32; // ah
  char v33; // ah
  unsigned __int8 v34; // ah
  _BYTE *v35; // edi
  char v36; // ah
  char v37; // ah
  char v38; // ah
  unsigned __int8 v39; // ah
  __int16 v41; // [esp-Ch] [ebp-14h]
  __int16 v42; // [esp-6h] [ebp-Eh]
  void *retaddr[2]; // [esp+8h] [ebp+0h]

  HIBYTE(v4) = *(&loc_10077 + 5);
  LOBYTE(v4) = a1 - *(&loc_10077 + 5);
  if ( (v4 & 0x80u) != 0 )
    return MK_FP(retaddr[0], retaddr[0])(v4);
  HIBYTE(v4) = *(&loc_1008E + 2);
  if ( (unsigned __int8)v4 > *(&loc_1008E + 2) )
    return MK_FP(retaddr[0], retaddr[0])(v4);
  v5 = *MK_FP(*(_WORD *)((char *)Sub_0 + 361), 2 * a3 + 2078);
  v6 = loc_10068;
  v7 = loc_10068 * (unsigned __int8)v4;
  __outbyte(0x3C4u, 2u);
  v8 = a2 >> 2;
  LOWORD(a4) = (a2 >> 2) + v5;
  LOBYTE(v9) = a2 & 3;
  HIBYTE(v9) = byte_10020;
  if ( !byte_10022 )
  {
    v42 = (signed __int16)a4;
    v41 = v9;
    HIBYTE(v9) = byte_10021;
    do
    {
      v10 = __RCR__(HIBYTE(v8), __CFSHL__(0xFF00u >> v9, 1));
      v11 = __RCR__(v10, __CFSHL__(2 * (0xFF00u >> v9), 1));
      v12 = __RCR__(v11, __CFSHL__(4 * (0xFF00u >> v9), 1));
      v13 = __RCR__(v12, __CFSHL__(8 * (0xFF00u >> v9), 1));
      v14 = __RCR__(v13, __CFSHL__(16 * (0xFF00u >> v9), 1));
      v15 = __RCR__(v14, __CFSHL__(32 * (0xFF00u >> v9), 1));
      v16 = __RCR__(v15, __CFSHL__(0xFF00u >> v9 << 6, 1));
      v17 = __RCR__(v16, __CFSHL__(0xFF00u >> v9 << 7, 1));
      __outbyte(0x3C5u, v17);
      *a4 = HIBYTE(v9);
      v18 = a4 + 1;
      v19 = __RCR__(v17, __CFSHL__(0xFF00u >> v9 << 8, 1));
      v20 = __RCR__(v19, __CFSHL__(0xFF00u >> v9 << 9, 1));
      v21 = __RCR__(v20, __CFSHL__(0xFF00u >> v9 << 10, 1));
      v22 = __RCR__(v21, __CFSHL__(0xFF00u >> v9 << 11, 1));
      __outbyte(0x3C5u, v22);
      *v18++ = HIBYTE(v9);
      HIBYTE(v8) = v22 >> 4;
      __outbyte(0x3C5u, HIBYTE(v8));
      *v18 = HIBYTE(v9);
      a4 = v18 + 1;
      LOWORD(a4) = (_WORD)a4 + 77;
      --v6;
    }
    while ( v6 );
    v9 = v41;
    v6 = loc_10068;
    LOWORD(a4) = v42;
  }
  HIBYTE(v23) = *(&loc_100A4 + 1);
  do
  {
    HIBYTE(v24) = *MK_FP(loc_100A4, v7++);
    LOBYTE(v24) = 0;
    v25 = v24 >> v9;
    v26 = __CFSHL__(v25, 1);
    v25 *= 2;
    v27 = __RCR__(HIBYTE(v23), v26);
    v26 = __CFSHL__(v25, 1);
    v25 *= 2;
    v28 = __RCR__(v27, v26);
    v26 = __CFSHL__(v25, 1);
    v25 *= 2;
    v29 = __RCR__(v28, v26);
    v26 = __CFSHL__(v25, 1);
    v25 *= 2;
    v30 = __RCR__(v29, v26);
    v26 = __CFSHL__(v25, 1);
    v25 *= 2;
    v31 = __RCR__(v30, v26);
    v26 = __CFSHL__(v25, 1);
    v25 *= 2;
    v32 = __RCR__(v31, v26);
    v26 = __CFSHL__(v25, 1);
    v25 *= 2;
    v33 = __RCR__(v32, v26);
    v26 = __CFSHL__(v25, 1);
    v25 *= 2;
    v34 = __RCR__(v33, v26);
    __outbyte(0x3C5u, v34);
    *a4 = HIBYTE(v9);
    v35 = a4 + 1;
    v26 = __CFSHL__(v25, 1);
    v25 *= 2;
    v36 = __RCR__(v34, v26);
    v26 = __CFSHL__(v25, 1);
    v25 *= 2;
    v37 = __RCR__(v36, v26);
    v38 = __RCR__(v37, __CFSHL__(v25, 1));
    v39 = __RCR__(v38, __CFSHL__(2 * v25, 1));
    __outbyte(0x3C5u, v39);
    *v35++ = HIBYTE(v9);
    HIBYTE(v23) = v39 >> 4;
    __outbyte(0x3C5u, HIBYTE(v23));
    LOBYTE(v23) = HIBYTE(v9);
    *v35 = HIBYTE(v9);
    a4 = v35 + 1;
    LOWORD(a4) = (_WORD)a4 + 77;
    --v6;
  }
  while ( v6 );
  return MK_FP(retaddr[0], retaddr[0])(v23, 965);
}
// 10020: using guessed type char byte_10020;
// 10021: using guessed type char byte_10021;
// 10022: using guessed type char byte_10022;

//----- (000112F8) --------------------------------------------------------
int __usercall Sub_D75@<eax>(int a1@<ecx>, _BYTE *a2@<edi>, int a3@<esi>)
{
  __int16 v3; // sp
  __int16 v4; // bp
  __int16 v5; // si
  unsigned __int16 v6; // ax
  __int16 v7; // bx
  __int16 v8; // bp
  void *retaddr[2]; // [esp+6h] [ebp+2h]

  v4 = v3;
  v6 = *(_WORD _ds *)(v4 + 10);
  v5 = (v6 >> 2) + *MK_FP(*(_WORD *)((char *)Sub_0 + 361), 2 * *(_WORD _ds *)(v4 + 12) + 2078);
  __outbyte(0x3CEu, 4u);
  *((_WORD *)Sub_0 + 2403) = *(_WORD _ds *)(v4 + 14);
  LOWORD(a2) = *(_WORD _ds *)(v4 + 6);
  __ES__ = *(_WORD _ds *)(v4 + 8);
  HIBYTE(v6) = v6 & 3;
  v7 = *(_WORD _ds *)(v4 + 16);
  v8 = v5;
  do
  {
    LOWORD(a1) = *((_WORD *)Sub_0 + 2403);
    LOBYTE(v6) = HIBYTE(v6);
    LOWORD(a3) = v8;
    do
    {
      __outbyte(0x3CFu, v6);
      *a2++ = *MK_FP(loc_10036, a3++);
      LOBYTE(v6) = v6 + 1;
      if ( (_BYTE)v6 == 4 )
      {
        LOWORD(a3) = a3 + 1;
        LOBYTE(v6) = 0;
      }
      LOWORD(a3) = a3 - 1;
      --a1;
    }
    while ( a1 );
    v8 += 80;
    --v7;
  }
  while ( v7 );
  return MK_FP(retaddr[0], retaddr[0])(v6, 975);
}

//----- (0001138F) --------------------------------------------------------
__int16 Sub_DDB()
{
  __int16 v0; // sp
  __int16 v1; // bp
  int v2; // kr00_4
  void *retaddr[2]; // [esp+2h] [ebp+2h]

  v1 = v0;
  v2 = *(unsigned __int16 *)(v1 + 8) * *(unsigned __int16 *)(v1 + 6);
  return MK_FP(retaddr[0], retaddr[0])(v2, HIWORD(v2));
}

//----- (000113A5) --------------------------------------------------------
int __usercall Sub_DE9@<eax>(int a1@<ecx>, int a2@<edi>, _BYTE *a3@<esi>)
{
  __int16 v3; // sp
  __int16 v4; // bp
  __int16 v5; // di
  __int16 v6; // bx
  unsigned __int16 v7; // ax
  __int16 v8; // bp
  void *retaddr[2]; // [esp+6h] [ebp+2h]

  v4 = v3;
  v7 = *(_WORD _ds *)(v4 + 10);
  v5 = (v7 >> 2) + *MK_FP(*(_WORD *)((char *)Sub_0 + 361), 2 * *(_WORD _ds *)(v4 + 12) + 2078);
  __outbyte(0x3C4u, 2u);
  v6 = *(_WORD _ds *)(v4 + 16);
  *(_WORD *)((char *)Sub_0 + 4979) = *(_WORD _ds *)(v4 + 14);
  LOWORD(a3) = *(_WORD _ds *)(v4 + 6);
  __DS__ = *(_WORD _ds *)(v4 + 8);
  HIBYTE(v7) = 1 << (v7 & 3);
  v8 = v5;
  do
  {
    LOWORD(a1) = *(_WORD *)((char *)Sub_0 + 4979);
    LOBYTE(v7) = HIBYTE(v7);
    LOWORD(a2) = v8;
    do
    {
      __outbyte(0x3C5u, v7);
      *MK_FP(loc_10038, a2++) = *a3++;
      LOBYTE(v7) = 2 * v7;
      if ( (_BYTE)v7 == 16 )
      {
        LOWORD(a2) = a2 + 1;
        LOBYTE(v7) = 1;
      }
      LOWORD(a2) = a2 - 1;
      --a1;
    }
    while ( a1 );
    v8 += 80;
    --v6;
  }
  while ( v6 );
  return MK_FP(retaddr[0], retaddr[0])(v7, 965);
}

//----- (00011443) --------------------------------------------------------
__int16 Sub_E55()
{
  __int16 v0; // sp
  __int16 v1; // bp
  unsigned __int16 v2; // ax
  void *retaddr[2]; // [esp+2h] [ebp+2h]

  v1 = v0;
  v2 = *(_WORD _ds *)(v1 + 6);
  HIBYTE(v2) = v2 & 3;
  LOBYTE(v2) = 4;
  __outword(0x3CEu, v2);
  return MK_FP(retaddr[0], retaddr[0])((unsigned __int8)*MK_FP(
                                                           loc_10038,
                                                           (*(_WORD _ds *)(v1 + 6) >> 2)
                                                         + *MK_FP(
                                                              *(_WORD *)((char *)Sub_0 + 361),
                                                              2 * *(_WORD _ds *)(v1 + 8) + 2078)));
}

//----- (00011493) --------------------------------------------------------
int Sub_E8B()
{
  __int16 v0; // sp
  __int16 v1; // bp
  __int16 v2; // cx
  unsigned __int16 v3; // ax
  void *retaddr[2]; // [esp+2h] [ebp+2h]

  v1 = v0;
  v2 = *(_WORD _ds *)(v1 + 6) & 3;
  LOBYTE(v3) = 2;
  HIBYTE(v3) = 1 << v2;
  __outword(0x3C4u, v3);
  *MK_FP(
     loc_10038,
     (*(_WORD _ds *)(v1 + 6) >> 2) + *MK_FP(*(_WORD *)((char *)Sub_0 + 361), 2 * *(_WORD _ds *)(v1 + 8) + 2078)) = *(_BYTE _ds *)(v1 + 10);
  return MK_FP(retaddr[0], retaddr[0])();
}

//----- (000114E7) --------------------------------------------------------
// write access to const memory has been detected, the output may be wrong!
int Sub_EC3()
{
  __int16 v0; // sp
  __int16 v1; // bp
  unsigned __int16 v2; // ax
  unsigned __int8 v3; // al
  unsigned __int8 v4; // al
  void *retaddr[2]; // [esp+2h] [ebp+2h]

  v1 = v0;
  __DS__ = *(_WORD *)((char *)Sub_0 + 361);
  *(&loc_10032 + 1) = loc_10032;
  loc_10032 = *(&loc_10032 + 1);
  LOBYTE(v2) = 12;
  HIBYTE(v2) = *(&loc_10032 + 1) >> 4;
  __outword(*(&loc_10081 + 1), v2);
  if ( *(_WORD _ds *)(v1 + 6) )
  {
    do
      v3 = __inbyte(0x3DAu);
    while ( v3 & 8 );
    do
      v4 = __inbyte(0x3DAu);
    while ( !(v4 & 8) );
  }
  return MK_FP(retaddr[0], retaddr[0])();
}
// 114FF: write access to const memory at 10034 has been detected
// 11506: write access to const memory at 10032 has been detected

//----- (0001154C) --------------------------------------------------------
int __usercall Sub_F0A@<eax>(unsigned int a1@<ecx>, char *a2@<edi>, char *a3@<esi>)
{
  __int16 v3; // sp
  __int16 v4; // bp
  __int16 v5; // dx
  __int16 v6; // bx
  __int16 v7; // bp
  void *retaddr[2]; // [esp+6h] [ebp+2h]

  v4 = v3;
  v5 = *(_WORD _ds *)(v4 + 12);
  v6 = (unsigned __int16)((*(_WORD _ds *)(v4 + 6) & 3) + *(_WORD _ds *)(v4 + 10) + (*(_WORD _ds *)(v4 + 6) & 3) + 3) >> 2;
  v7 = (*(_WORD _ds *)(v4 + 6) >> 2) + *MK_FP(*(_WORD *)((char *)Sub_0 + 361), 2 * *(_WORD _ds *)(v4 + 8) + 2078);
  __outword(0x3C4u, 0xF02u);
  __outword(0x3CEu, 0x4105u);
  do
  {
    LOWORD(a3) = v7;
    LOWORD(a2) = v7;
    LOWORD(a1) = v6;
    qmemcpy(a2, a3, a1);
    a3 += a1;
    a2 += a1;
    HIWORD(a1) = 0;
    v7 += 80;
    --v5;
  }
  while ( v5 );
  __outword(0x3CEu, 0x4005u);
  return MK_FP(retaddr[0], retaddr[0])();
}

//----- (000116ED) --------------------------------------------------------
int Sub_1026()
{
  __int16 v0; // sp
  __int16 v1; // bp
  unsigned __int16 v2; // ax
  unsigned __int16 v3; // si
  unsigned __int16 v4; // dx
  __int16 v5; // bx
  __int16 v6; // sp
  __int16 v7; // ax
  _BYTE _ds *v8; // di
  __int16 v9; // cx
  char v10; // bh
  unsigned __int8 v11; // cl
  unsigned __int16 v12; // si
  __int16 v13; // cx
  unsigned __int16 v14; // dx
  __int16 v15; // sp
  __int16 v16; // ax
  void *retaddr[2]; // [esp+Eh] [ebp+Eh]

  v1 = v0;
  *(_WORD _ds *)(v1 + 22) >>= 1;
  v2 = *(_WORD _ds *)(v1 + 14);
  v3 = v2 & 0xF;
  __DS__ = *(_WORD _ds *)(v1 + 16) + (v2 >> 4);
  __ES__ = *(_WORD _ds *)(*(_WORD *)((char *)Sub_0 + 363) + 24);
  __outbyte(0x3CEu, 4u);
  __outbyte(0x3C4u, 2u);
  v4 = 965;
  v5 = *(_WORD _ds *)(v1 + 24);
  do
  {
    v7 = 2 * *(_WORD _ds *)(v6 + 20);
    v8 = (_BYTE _ds *)(*(_WORD _ds *)(v6 + 18) + *(_WORD _ds *)(*(_WORD *)((char *)Sub_0 + 363) + v7 + 2078));
    v9 = *(_WORD _ds *)(v6 + 22) >> 1;
    v10 = v9;
    do
    {
      v11 = *(_BYTE _ds *)v3;
      v12 = v3 + 1;
      v13 = 16 * v11;
      HIBYTE(v13) *= 16;
      __outbyte(v4, 1u);
      v14 = v4 + 10;
      __outbyte(v14, 0);
      v14 -= 10;
      *v8 |= HIBYTE(v13);
      __outbyte(v14, 2u);
      v14 += 10;
      __outbyte(v14, 1u);
      v14 -= 10;
      *v8 |= v13;
      LOBYTE(v13) = *(_BYTE _ds *)v12;
      v3 = v12 + 1;
      v13 *= 16;
      __outbyte(v14, 4u);
      v14 += 10;
      __outbyte(v14, 2u);
      v14 -= 10;
      *v8 |= 16 * HIBYTE(v13);
      __outbyte(v14, 8u);
      v14 += 10;
      __outbyte(v14, 3u);
      v4 = v14 - 10;
      *v8++ |= v13;
      --v10;
    }
    while ( v10 );
    v16 = *(_WORD _ds *)(v15 + 20) + 1;
    *(_WORD _ds *)(v15 + 20) = v16;
    LOBYTE(v5) = v5 - 1;
  }
  while ( (_BYTE)v5 );
  return MK_FP(retaddr[0], retaddr[0])(v16, v4);
}

//----- (0001183E) --------------------------------------------------------
int __usercall Sub_111C@<eax>(int a1@<ecx>, int a2@<ebx>, _WORD *a3@<edi>, _WORD *a4@<esi>)
{
  __int16 v4; // sp
  __int16 v5; // bp
  __int16 v6; // sp
  unsigned __int16 v7; // ax
  __int16 v8; // ax
  unsigned __int16 v9; // si
  __int16 v10; // sp
  __int16 v11; // sp
  __int16 v12; // sp
  unsigned __int16 v13; // di
  __int16 v14; // dx
  unsigned __int16 v15; // bx
  __int16 v16; // sp
  __int16 v17; // ax
  unsigned __int16 v18; // ax
  bool v19; // cf
  unsigned __int16 v20; // ax
  __int16 v21; // sp
  __int16 v22; // ax
  __int16 v23; // ax
  bool v24; // zf
  __int16 v25; // sp
  __int16 v26; // ax
  __int16 v27; // sp
  __int16 v28; // ax
  __int16 v29; // sp
  __int16 v30; // sp
  unsigned __int16 v31; // ax
  __int16 v32; // sp
  unsigned __int16 v33; // ax
  __int16 v34; // sp
  char v35; // al
  __int16 v36; // sp
  __int16 v37; // di
  __int16 v38; // si
  __int16 v39; // sp
  __int16 v40; // sp
  __int16 v41; // ax
  __int16 v42; // si
  __int16 v43; // ax
  __int16 v44; // di
  unsigned __int8 v45; // al
  __int16 v46; // sp
  __int16 v47; // si
  __int16 v48; // si
  void *retaddr[2]; // [esp+10h] [ebp+2h]

  v5 = v4;
  LOWORD(a4) = *(_WORD _ds *)(v5 + 6);
  LOWORD(a3) = v5 - 10;
  LOWORD(a1) = 5;
  while ( a1 )
  {
    *a3 = *a4;
    ++a4;
    ++a3;
    --a1;
  }
  v7 = *(_WORD _ds *)(v6 - 4);
  *((_WORD *)Sub_0 + 3073) = v7;
  v7 >>= 2;
  *(_WORD _ds *)(v6 - 4) = v7;
  v8 = *(_WORD _ds *)(v6 - 2) * v7;
  *((_WORD *)Sub_0 + 3068) = v8;
  __DS__ = *(_WORD *)((char *)Sub_0 + 361);
  v9 = 0;
  if ( *(_BYTE _ds *)(v6 + 12) & 2 )
    v9 = 4 * *(_WORD _ds *)(v10 - 4) - 1;
  if ( *(_BYTE _ds *)(v11 + 12) & 1 )
    v9 += 4 * *((_WORD *)Sub_0 + 3068) - *((_WORD *)Sub_0 + 3073);
  v13 = *(_WORD _ds *)(v12 + 8) + 4 * *(_WORD _ds *)(2 * *(_WORD _ds *)(v12 + 10) + 2078);
  v14 = 4 * *(_WORD _ds *)(v12 - 4);
  *((_WORD *)Sub_0 + 3072) = *(_WORD _ds *)(v12 - 2);
  v15 = 0;
  if ( !byte_1002B )
    goto LABEL_36;
  v17 = word_10025 - *(_WORD _ds *)(v16 + 8) - v14;
  if ( v17 >= 0
    || (v18 = v14 - (word_10025 - *(_WORD _ds *)(v16 + 8)) - 1,
        v15 = v18,
        v14 = 1 - (*(_WORD _ds *)(v16 + 8) - word_10025),
        v18 >>= 2,
        v19 = v18 < *(_WORD _ds *)(v16 - 4),
        v20 = v18 - *(_WORD _ds *)(v16 - 4),
        v19) )
  {
    v22 = word_10029 - *(_WORD _ds *)(v21 + 10);
    v23 = v22 - *((_WORD *)Sub_0 + 3072);
    if ( v23 >= 0
      || (v20 = -v23 - 1,
          v19 = *((_WORD *)Sub_0 + 3072) < v20,
          v24 = *((_WORD *)Sub_0 + 3072) == v20,
          *((_WORD *)Sub_0 + 3072) -= v20,
          !v19 && !v24) )
    {
      v26 = word_10027 - *(_WORD _ds *)(v25 + 10);
      if ( word_10027 <= *(_WORD _ds *)(v25 + 10) )
        goto LABEL_37;
      *((_WORD *)Sub_0 + 3072) -= v26;
      v28 = 4 * *(_WORD _ds *)(v27 - 4) * v26;
      if ( *(_BYTE _ds *)(v27 + 12) & 1 )
        v28 = -v28;
      v9 += v28;
      v13 = *(_WORD _ds *)(v29 + 8) + 4 * *(_WORD _ds *)(2 * word_10027 + 2078);
      v20 = *((_WORD *)Sub_0 + 3072);
      if ( v20 )
      {
        if ( (v20 & 0x8000u) == 0 )
        {
LABEL_37:
          v31 = word_10023 - *(_WORD _ds *)(v30 + 8);
          if ( word_10023 <= *(_WORD _ds *)(v30 + 8) )
            goto LABEL_36;
          v13 += v31;
          v15 += v31;
          if ( *(_BYTE _ds *)(v32 + 12) & 2 )
            v9 = v9 - v31 - v31;
          v14 -= v31;
          v9 += v31;
          v33 = v31 >> 2;
          v19 = v33 < *(_WORD _ds *)(v34 - 4);
          v20 = v33 - *(_WORD _ds *)(v34 - 4);
          if ( v19 )
          {
LABEL_36:
            *((_WORD *)Sub_0 + 3071) = v13 & 3;
            v35 = v9;
            if ( *(_BYTE _ds *)(v36 + 12) & 2 )
              v35 = ~(_BYTE)v9;
            *((_WORD *)Sub_0 + 3070) = v35 & 3;
            v37 = v13 >> 2;
            v38 = v9 >> 2;
            *((_WORD *)Sub_0 + 3067) = v15;
            if ( *(_BYTE _ds *)(v39 + 12) & 2 )
              *((_WORD *)Sub_0 + 3070) ^= 3u;
            v41 = *(_WORD _ds *)(v40 - 10);
            v42 = *(_WORD _ds *)(v40 - 8) + v38;
            *((_WORD *)Sub_0 + 3069) = v42;
            LOWORD(a2) = 2 * *(_WORD _ds *)(v40 + 12);
            v43 = *(_WORD *)((char *)Sub_0 + a2 + 6150);
            *((_WORD *)Sub_0 + 3074) = v37;
            __outbyte(0x3C4u, 2u);
            v44 = *((_WORD *)Sub_0 + 3074);
            v45 = 1 << *((_BYTE *)Sub_0 + 6142);
            ++*((_WORD *)Sub_0 + 3071);
            if ( v45 == 16 )
            {
              *((_WORD *)Sub_0 + 3074) = v44 + 1;
              v45 = 1;
              *((_BYTE *)Sub_0 + 6142) = 1;
            }
            __outbyte(0x3C5u, v45);
            if ( !(*(_BYTE _ds *)(v46 + 12) & 2) )
            {
              v47 = *((_WORD *)Sub_0 + 3068);
              JUMPOUT(__CS__, (_WORD)Sub_0 + 6854 + 2 * (*((_WORD *)Sub_0 + 3070) ^ 3));
            }
            v48 = *((_WORD *)Sub_0 + 3068);
            JUMPOUT(__CS__, (_WORD)Sub_0 + 6938 + 2 * (*((_WORD *)Sub_0 + 3070) ^ 3));
          }
        }
      }
    }
  }
  return MK_FP(retaddr[0], retaddr[0])(v20, v14);
}
// 10023: using guessed type __int16 word_10023;
// 10025: using guessed type __int16 word_10025;
// 10027: using guessed type __int16 word_10027;
// 10029: using guessed type __int16 word_10029;
// 1002B: using guessed type char byte_1002B;

//----- (0001292C) --------------------------------------------------------
int __usercall Sub_1C72@<eax>(unsigned int a1@<ecx>, char *a2@<edi>, char *a3@<esi>)
{
  __int16 v3; // sp
  __int16 v4; // bp
  unsigned __int16 v5; // bp
  __int16 v6; // dx
  __int16 v7; // bx
  __int16 v8; // bp
  unsigned int v9; // ecx
  char *v10; // esi
  char *v11; // edi
  __int16 v12; // dx
  unsigned int v13; // ecx
  char *v14; // esi
  char *v15; // edi
  __int16 v16; // dx
  unsigned int v17; // ecx
  char *v18; // esi
  char *v19; // edi
  __int16 v20; // dx
  unsigned int v21; // ecx
  char *v22; // esi
  char *v23; // edi
  __int16 v24; // dx
  unsigned int v25; // ecx
  char *v26; // esi
  char *v27; // edi
  __int16 v28; // dx
  unsigned int v29; // ecx
  char *v30; // esi
  char *v31; // edi
  __int16 v32; // dx
  int v33; // ecx
  char *v34; // esi
  char *v35; // edi
  __int16 v36; // dx
  void *retaddr[2]; // [esp+6h] [ebp+2h]

  v4 = v3;
  LOWORD(a2) = (*(_WORD _ds *)(v4 + 8) >> 2)
             + *MK_FP(*(_WORD *)((char *)Sub_0 + 361), 2 * *(_WORD _ds *)(v4 + 10) + 2078);
  v5 = *(_WORD _ds *)(v4 + 6);
  v6 = *(_WORD _ds *)(v5 + 8);
  v7 = *(_WORD _ds *)(v5 + 6) >> 2;
  LOWORD(a3) = *(_WORD _ds *)(v5 + 2);
  __DS__ = *(_WORD _ds *)v5;
  v8 = 80 - v7;
  do
  {
    LOWORD(a1) = v7;
    qmemcpy(a2, a3, a1);
    v10 = &a3[a1];
    v11 = &a2[a1];
    HIWORD(v9) = 0;
    LOWORD(v11) = v8 + (_WORD)v11;
    v12 = v6 - 1;
    if ( !v12 )
      break;
    LOWORD(v9) = v7;
    qmemcpy(v11, v10, v9);
    v14 = &v10[v9];
    v15 = &v11[v9];
    HIWORD(v13) = 0;
    LOWORD(v15) = v8 + (_WORD)v15;
    v16 = v12 - 1;
    if ( !v16 )
      break;
    LOWORD(v13) = v7;
    qmemcpy(v15, v14, v13);
    v18 = &v14[v13];
    v19 = &v15[v13];
    HIWORD(v17) = 0;
    LOWORD(v19) = v8 + (_WORD)v19;
    v20 = v16 - 1;
    if ( !v20 )
      break;
    LOWORD(v17) = v7;
    qmemcpy(v19, v18, v17);
    v22 = &v18[v17];
    v23 = &v19[v17];
    HIWORD(v21) = 0;
    LOWORD(v23) = v8 + (_WORD)v23;
    v24 = v20 - 1;
    if ( !v24 )
      break;
    LOWORD(v21) = v7;
    qmemcpy(v23, v22, v21);
    v26 = &v22[v21];
    v27 = &v23[v21];
    HIWORD(v25) = 0;
    LOWORD(v27) = v8 + (_WORD)v27;
    v28 = v24 - 1;
    if ( !v28 )
      break;
    LOWORD(v25) = v7;
    qmemcpy(v27, v26, v25);
    v30 = &v26[v25];
    v31 = &v27[v25];
    HIWORD(v29) = 0;
    LOWORD(v31) = v8 + (_WORD)v31;
    v32 = v28 - 1;
    if ( !v32 )
      break;
    LOWORD(v29) = v7;
    qmemcpy(v31, v30, v29);
    v34 = &v30[v29];
    v35 = &v31[v29];
    HIWORD(v33) = 0;
    LOWORD(v35) = v8 + (_WORD)v35;
    v36 = v32 - 1;
    if ( !v36 )
      break;
    LOWORD(a1) = v7;
    qmemcpy(v35, v34, a1);
    a3 = &v34[a1];
    a2 = &v35[a1];
    HIWORD(a1) = 0;
    LOWORD(a2) = v8 + (_WORD)a2;
    v6 = v36 - 1;
  }
  while ( v6 );
  return MK_FP(retaddr[0], retaddr[0])();
}

//----- (000129EF) --------------------------------------------------------
#error "12AD1: positive sp value has been found (funcsize=77)"

//----- (00012AD2) --------------------------------------------------------
int Sub_1D88()
{
  void *retaddr[2]; // [esp+0h] [ebp+0h]

  *((_WORD *)Sub_0 + 5245) = 0;
  return MK_FP(retaddr[0], retaddr[0])();
}

//----- (00012AED) --------------------------------------------------------
int __usercall Sub_1D9F@<eax>(int a1@<ecx>, _WORD *a2@<edi>, _WORD *a3@<esi>)
{
  __int16 v3; // sp
  __int16 v4; // bp
  __int16 v5; // sp
  unsigned __int16 v6; // ax
  unsigned __int16 v7; // si
  unsigned __int16 v8; // di
  __int16 v9; // dx
  unsigned __int16 v10; // bx
  __int16 v11; // sp
  __int16 v12; // ax
  unsigned __int16 v13; // ax
  bool v14; // cf
  unsigned __int16 v15; // ax
  __int16 v16; // sp
  __int16 v17; // ax
  __int16 v18; // ax
  bool v19; // zf
  __int16 v20; // sp
  __int16 v21; // ax
  __int16 v22; // sp
  __int16 v23; // sp
  unsigned __int16 v24; // ax
  unsigned __int16 v25; // ax
  __int16 v26; // sp
  __int16 v27; // sp
  __int16 v28; // ax
  __int16 v29; // si
  __int16 v30; // di
  unsigned __int8 v31; // al
  __int16 v32; // si
  void *retaddr[2]; // [esp+10h] [ebp+2h]

  v4 = v3;
  LOWORD(a3) = *(_WORD _ds *)(v4 + 6);
  LOWORD(a2) = v4 - 10;
  LOWORD(a1) = 5;
  while ( a1 )
  {
    *a2 = *a3;
    ++a3;
    ++a2;
    --a1;
  }
  v6 = *(_WORD _ds *)(v5 - 4);
  *(_WORD *)((char *)Sub_0 + 10937) = v6;
  v6 >>= 2;
  *(_WORD _ds *)(v5 - 4) = v6;
  *(_WORD *)((char *)Sub_0 + 10927) = *(_WORD _ds *)(v5 - 2) * v6;
  __DS__ = *(_WORD *)((char *)Sub_0 + 361);
  v7 = 0;
  v8 = *(_WORD _ds *)(v5 + 8) + 4 * *(_WORD _ds *)(2 * *(_WORD _ds *)(v5 + 10) + 2078);
  v9 = 4 * *(_WORD _ds *)(v5 - 4);
  *(_WORD *)((char *)Sub_0 + 10935) = *(_WORD _ds *)(v5 - 2);
  v10 = 0;
  if ( !byte_1002B )
    goto LABEL_22;
  v12 = word_10025 - *(_WORD _ds *)(v11 + 8) - v9;
  if ( v12 >= 0
    || (v13 = v9 - (word_10025 - *(_WORD _ds *)(v11 + 8)) - 1,
        v10 = v13,
        v9 = 1 - (*(_WORD _ds *)(v11 + 8) - word_10025),
        v13 >>= 2,
        v14 = v13 < *(_WORD _ds *)(v11 - 4),
        v15 = v13 - *(_WORD _ds *)(v11 - 4),
        v14) )
  {
    v17 = word_10029 - *(_WORD _ds *)(v16 + 10);
    v18 = v17 - *(_WORD *)((char *)Sub_0 + 10935);
    if ( v18 >= 0
      || (v15 = -v18 - 1,
          v14 = *(_WORD *)((char *)Sub_0 + 10935) < v15,
          v19 = *(_WORD *)((char *)Sub_0 + 10935) == v15,
          *(_WORD *)((char *)Sub_0 + 10935) -= v15,
          !v14 && !v19) )
    {
      v21 = word_10027 - *(_WORD _ds *)(v20 + 10);
      if ( word_10027 <= *(_WORD _ds *)(v20 + 10)
        || (*(_WORD *)((char *)Sub_0 + 10935) -= v21,
            v7 = 4 * *(_WORD _ds *)(v22 - 4) * (v21 - 1),
            v8 = *(_WORD _ds *)(v22 + 8) + 4 * *(_WORD _ds *)(2 * word_10027 + 2078),
            (v15 = *(_WORD *)((char *)Sub_0 + 10935)) != 0)
        && (v15 & 0x8000u) == 0 )
      {
        v24 = word_10023 - *(_WORD _ds *)(v23 + 8);
        if ( word_10023 <= *(_WORD _ds *)(v23 + 8)
          || (v8 += v24,
              v10 += v24,
              v9 -= v24,
              v7 += v24,
              v25 = v24 >> 2,
              v14 = v25 < *(_WORD _ds *)(v26 - 4),
              v15 = v25 - *(_WORD _ds *)(v26 - 4),
              v14) )
        {
LABEL_22:
          *(_WORD *)((char *)Sub_0 + 10933) = v8 & 3;
          *(_WORD *)((char *)Sub_0 + 10931) = v7 & 3;
          v28 = *(_WORD _ds *)(v27 - 10);
          v29 = *(_WORD _ds *)(v27 - 8) + (v7 >> 2);
          *(_WORD *)((char *)Sub_0 + 10929) = v29;
          *(_WORD *)((char *)Sub_0 + 10925) = v10;
          *(_WORD *)((char *)Sub_0 + 10939) = v8 >> 2;
          __outbyte(0x3C4u, 2u);
          v30 = *(_WORD *)((char *)Sub_0 + 10939);
          v31 = 1 << *((_BYTE *)Sub_0 + 10933);
          ++*(_WORD *)((char *)Sub_0 + 10933);
          if ( v31 == 16 )
          {
            *(_WORD *)((char *)Sub_0 + 10939) = v30 + 1;
            v31 = 1;
            *((_BYTE *)Sub_0 + 10933) = 1;
          }
          __outbyte(0x3C5u, v31);
          v32 = *(_WORD *)((char *)Sub_0 + 10927);
          JUMPOUT(__CS__, (_WORD)Sub_0 + 11514 + 2 * (*(_WORD *)((char *)Sub_0 + 10931) ^ 3));
        }
      }
    }
  }
  return MK_FP(retaddr[0], retaddr[0])(v15, v9);
}
// 10023: using guessed type __int16 word_10023;
// 10025: using guessed type __int16 word_10025;
// 10027: using guessed type __int16 word_10027;
// 10029: using guessed type __int16 word_10029;
// 1002B: using guessed type char byte_1002B;

#error "There were 1 decompilation failure(s) on 32 function(s)"
