.386p
.MODEL TPASCAL
.DATA
 oldint3 dd ?
 old_interrupt3 dd ?

.CODE

  public PIQ_Stop_System
  public Keyboard_off
  public Keyboard_on
  public No_Stepping


keyb_off macro
  push ax
  in  al,21h
  or  al,02
  out 21h,al
  pop ax
endm

keyb_on macro
  push ax
  in  al,21h
  and al,0Fdh
  out 21h,al
  pop ax
endm

PIQ_Stop_System proc near
  push ds
  push ax
  push bx
  push cs
  pop  ds                             ; CS to DS
  mov  cs:word ptr [@int_21_funct],4CB4h  ; End function Prg.
@int_21_funct:
  mov  ah,30h                         ; Function Get DOS-Vers.
  int  21h
  pop  bx
  pop  ax
  pop  ds
  ret
PIQ_Stop_System endp

Keyboard_off proc near
   keyb_off
   ret
Keyboard_off endp

Keyboard_on proc near
   keyb_on
   ret
Keyboard_on endp

No_Stepping proc near
  push ax
  jmp @Nostep+2
@Nostep:
  mov ds:byte ptr [06EBh],00
  mov ax,4C01h
  int 21h
  pop ax
  ret
No_Stepping endp

public protected_stopping
protected_stopping proc pascal
	pusha
	cli                         ; disable interrupts
	mov eax,cr0                 ; switch to protected mode
	or eax,1
	mov cr0,eax
	jmp PROTECTION_ENABLED      ; clear execution pipe
PROTECTION_ENABLED:

	and al,0FEh                 ; switch back to real mode
	mov cr0,eax                 ; don't reset CPU
	jmp PROTECTION_DISABLED     ; clear execution pipe
PROTECTION_DISABLED:
	sti                         ; enable interrupts again
	popa
  ret
protected_stopping endp

public Check_for_vector
Check_for_vector proc pascal check : dword;
  mov bx,0
  mov es,bx
  mov bx,18
  mov eax,es:[bx]
  mov oldint3,eax
  mov eax,check
  mov es:[bx],eax
  ret
Check_for_vector endp

public Vector_ok
Vector_ok proc pascal check : dword;
  mov bx,0
  mov es,bx
  mov bx,18
  mov eax,es:[bx]
  cmp eax,check
  je  @check_ok
  mov al,0
  jmp @check_end
@check_ok:
  mov al,1
@check_end:
  ret
Vector_ok endp

public restore_Checkvector
restore_Checkvector proc pascal
  mov bx,0
  mov es,bx
  mov bx,18
  mov eax,oldint3
  mov es:[bx],eax
  ret
restore_Checkvector endp

public Copy_int21_int3
Copy_int21_int3 proc pascal
  mov bx,0
  mov es,bx
  mov bx,18
  mov eax,es:[bx]
  mov old_interrupt3,eax              ; store old int3
  mov bx,84                             ; load int 21
  mov eax,es:[bx]
  mov bx,18                             ; store in int3
  mov es:[bx],eax
  ret
Copy_int21_int3 endp



end
