.8086

.MODEL large

public int2d_handler_
public _multiplex_number
public _old_multiplex_handler
public _multiplex_signature

_TEXT               SEGMENT BYTE PUBLIC USE16 'CODE'
                ASSUME CS:_TEXT                               

_multiplex_signature: db "lEEt/OS", 0
_multiplex_number: dw 0

; dont allow any new TSRs when lEEt/OS is loaded...
int2d_handler_ proc far
  ; installation check
  test al, al
  jnz int2d_handler_j1

  uninstall_failed:
  cmp ah, byte ptr cs:_multiplex_number
  jmp test_other_multiplex

  return_used:
  dec al
  mov dx, cs
  mov si, offset _multiplex_signature

  iret

  int2d_handler_j1:

  cmp ah, byte ptr cs:_multiplex_number
  jne jump_old_handler

  cmp al, 2
  jne int2d_handler_j2
  jmp uninstall_failed
  

  int2d_handler_j2:
  cmp al, 4
  jne jump_old_handler

  mov al, 0xFF
  iret
  
  jump_old_handler:
  db 0xEA
  _old_multiplex_handler: dd 0

  test_other_multiplex:
  pushf
  push cs
  sub sp, 2
  xchg bp, sp
  mov [bp], offset test_other_mul_ret
  xchg bp, sp
  jmp jump_old_handler

  test_other_mul_ret:
  cmp al, 0x00
  je return_used

  iret
int2d_handler_ endp

_TEXT ENDS

END
