Package Timer

Uses KbdCRT,Error

Interface

Const
     CountTicks,UserSignal
Var
   TimerMutEx as Boolean \Si True, le handler est inactif, actif sinon\
   UserTimerHandler as Func
   ClockTicks as LongWord

Sub GetTimerControl(Mode as Word)
Sub RestoreTimerControl

Implementation

OldTimerIt as Func

Sub TimerIt1
Enter
\ (AX,BX,CX,DX,SI,DI,DS,ES,BP) \
  InLine(&H50,&H53,&H51,&H52,&H56,&H57,&H1E,&H06,&H55)
\ BPSP \
  InLine(&H89,&HE5)
\ AXDSEG(Module):DSAX \
  InLine(&HB8,&H1234,&H8E,&HD8)
\ User \
  If Not TimerMutEx Then ClockTicks+=1;
\ SPBP \
  InLine(&H89,&HEC)
\ (BP,ES,DS,DI,SI,DX,CX,BX,AX) \
  InLine(&H5D,&H07,&H1F,&H5F,&H5E,&H5A,&H59,&H5B,&H58)
\ IRET \
  InLine(&HCF)
Leave

Sub TimerIt2
Enter
\ (AX,BX,CX,DX,SI,DI,DS,ES,BP) \
  InLine(&H50,&H53,&H51,&H52,&H56,&H57,&H1E,&H06,&H55)
\ BPSP \
  InLine(&H89,&HE5)
\ AXDSEG(Module):DSAX \
  InLine(&HB8,&H1234,&H8E,&HD8)
\ User \
  If Not TimerMutEx Then CallProcWord(UserTimerHandler,0);
\ SPBP \
  InLine(&H89,&HEC)
\ (BP,ES,DS,DI,SI,DX,CX,BX,AX) \
  InLine(&H5D,&H07,&H1F,&H5F,&H5E,&H5A,&H59,&H5B,&H58)
\ IRET \
  InLine(&HCF)
Leave

Sub GetTimerControl(Mode as Word)
Type
    WordPtr is ^Word
Var
   W,NewHandler as WordPtr
Enter
  Case Mode Of
    CountTicks: NewHandler=WordPtr(@TimerIt1);
    UserSignal: NewHandler=WordPtr(@TimerIt2);
    Else
      Error("GetTimerControl : bad Mode");
  End
  GetIntVec &H1C,OldTimerIt
  W=NewHandler
  Low(W)+=15
  W^=DS
  W=NewHandler
  Low(W)+=3
  SetIntVec &H1C,Pointer(W)
Leave

Sub RestoreTimerControl
Enter
  SetIntVec &H1C,OldTimerIt
Leave

Enter
  TimerMutEx=True
  ClockTicks=0
Leave