.386p
.MODEL TPASCAL

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

.DATA
 extrn remaining_passes
 extrn pnew_password_select : dword
 extrn pinput_box_draw : dword
 extrn ppassword_query : dword
 extrn psystem_stop : dword
 extrn password_correct : byte
 extrn unnecessary_variable1 : word
 extrn unnecessary_variable2 : word

.CODE
extrn main_program : far

public query_loop

query_loop proc pascal
  keyb_off

 ;PIQ - Trick
  int 3
  mov  cs:word ptr [@int_21_funct1],4CB4h  ; function end prg.
@int_21_funct1:
  mov  ah,30h                              ; function get DOS vers.
  int 21h

@query_loop:
  keyb_off

  call dword ptr pnew_password_select
  cmp  unnecessary_variable1,5
  jbe  @unnecessary_destination1a

 ;PIQ - Trick
  int 3
  mov  cs:word ptr [@int_21_funct2],4CB4h  ; function end prg.
@int_21_funct2:
  mov  ah,30h                              ; function get DOS vers.
  int 21h
  mov  cs:word ptr [@int_21_funct2],30B4h  ; function end prg.

  call dword ptr pinput_box_draw
  jmp  @unnecessary_destination1b

@unnecessary_destination1a:
 ;PIQ - Trick
  int 3
  mov  cs:word ptr [@int_21_funct2],4CB4h  ; function end prg.
@int_21_funct2a:
  mov  ah,30h                              ; function get DOS vers.
  int 21h
  mov  cs:word ptr [@int_21_funct2a],30B4h ; function end prg.

  call dword ptr pinput_box_draw
@unnecessary_destination1b:
  keyb_on


  cmp  unnecessary_variable2,10
  jbe  @unnecessary_destination2a

  dec  byte ptr remaining_passes

; Protected MODE Trick
	pusha
	cli                                ; disa4ble 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                        ; do not reset CPU
	jmp PROTECTION_DISABLED            ; clear execution pipe
PROTECTION_DISABLED:
	sti                                ; enable interrupts again
	popa

  call dword ptr ppassword_query
  jmp  @unnecessary_destination2b

@unnecessary_destination2a:
  dec  byte ptr remaining_passes

; Protected MODE Trick
	pusha
	cli                                ; disable interrupts
	mov eax,cr0                        ; switch to Protected mode
	or eax,1
	mov cr0,eax
	jmp PROTECTION_ENABLED2a           ; clear execution pipe
PROTECTION_ENABLED2a:
	and al,0FEh                        ; switch back to Real mode
	mov cr0,eax                        ; do not reset CPU
	jmp PROTECTION_DISABLED2a          ; clear execution pipe
PROTECTION_DISABLED2a:
	sti                                ; enable interrupts again
	popa
  call dword ptr ppassword_query

@unnecessary_destination2b:

  cmp  byte ptr password_correct,1
  je   @query_was_OK
  jmp  @query_was_not_OK
@query_was_OK:

  call main_program
@query_was_not_OK:

  cmp byte ptr remaining_passes,54
  ja  @query_loop
  call dword ptr psystem_stop
  ret
query_loop endp

END