extern unsigned __based(__segname("_TEXT")) multiplex_number;
extern void * __based(__segname("_TEXT")) old_multiplex_handler;
void int2d_handler();
extern char __based(__segname("_TEXT")) multiplex_signature[];

char __far *test_multiplex_number(unsigned char);
#pragma aux test_multiplex_number = \
  "xor al, al" \
  "int 0x2D" \
  "cmp al, 0xFF" \
  "je end" \
  "xor si, si" \
  "xor dx, dx" \
  "end:" \
  parm [ah] value [dx si];

int installation_check(void)
{
  unsigned n;
  char *ptr;

  for(n=0;n<0x100;n++)
  {
    ptr = test_multiplex_number(n);
    if(ptr && !strcmp(ptr, multiplex_signature))
      return 1;
  }

  do
  {
    ptr = test_multiplex_number(multiplex_number);
    if(!ptr) break;
  }
  while(++multiplex_number < 0x100);

  if(ptr) return 0; // all multiplex numbers in use...

  old_multiplex_handler = _dos_getvect(0x2d);
  _dos_setvect(0x2d, int2d_handler);

  return 0;
}

void reset_multiplex(void)
{
  if(multiplex_number < 0x100)
    _dos_setvect(0x2d, old_multiplex_handler);
}
