Metropoli BBS
VIEWER: delay.asm MODE: TEXT (ASCII)
include qlib.inc
include stdlib.inc

.code
delay proc,d:word
  pushad
  mov bx,d
@@:
  .if bx>4290
    mov ecx,284388   ;4290 ms => 15.085 us
    call delay61h
    sub bx,4290
    jmp @b
  .endif
  .if !bx
    jmp done
  .endif
  xor eax,eax
  mov ax,bx           ;ms
  imul eax,1000*1000  ;ns
  xor edx,edx
  mov ebx,15085
  div ebx             ;# of 15us to use
  mov ecx,eax
  call delay61h
done:
  popad
  xor eax,eax
  ret
delay endp

sleep proc,s:word
  pushad
  xor ebx,ebx
  mov bx,s
  .if !ebx
    jmp done
  .endif
@@:
  mov ecx,66291   ;1sec
  call delay61h
  dec ebx
  jnz @b
done:
  popad
  xor eax,eax
  ret
sleep endp

delay61h proc private
  ; in : ECX = # 15.085 u sec to wait
  in al,61h
  mov dl,al
  and dl,10000b
@@:
  in al,61h
  and al,10000b
  xor al,dl
  jz @b
  xor dl,10000b
  dec ecx
  jnz @b
  ret
delay61h endp

end
[ RETURN TO DIRECTORY ]