home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ddkx86v5.zip / DDKX86 / SRC / PEN / PENTKT / PENBASE / TIMER.ASM < prev    next >
Assembly Source File  |  1995-04-14  |  7KB  |  205 lines

  1. ;*DDK*************************************************************************/
  2. ;
  3. ; COPYRIGHT    Copyright (C) 1995 IBM Corporation
  4. ;
  5. ;    The following IBM OS/2 WARP source code is provided to you solely for
  6. ;    the purpose of assisting you in your development of OS/2 WARP device
  7. ;    drivers. You may use this code in accordance with the IBM License
  8. ;    Agreement provided in the IBM Device Driver Source Kit for OS/2. This
  9. ;    Copyright statement may not be removed.;
  10. ;*****************************************************************************/
  11. ;      /*****************************************************************/
  12. ;      /*                                                               */
  13. ;      /*                                                               */
  14. ;      /*****************************************************************/
  15. ;      /******************* START OF SPECIFICATIONS *********************/
  16. ;      /*                                                               */
  17. ;      /*  SOURCE FILE NAME: TIMER.ASM                                  */
  18. ;      /*                                                               */
  19. ;      /*  DESCRIPTIVE NAME: Timer services                             */
  20. ;      /*                                                               */
  21. ;      /*                                                               */
  22. ;      /*  STATUS:  Version 1.0                                         */
  23. ;      /*                                                               */
  24. ;      /*  NOTES: This module provides timer services to the driver.    */
  25. ;      /*         The device dependent and device type dependent        */
  26. ;      /*         routine is called for each logical device on each     */
  27. ;      /*         timer tick.                                           */
  28. ;      /*                                                               */
  29. ;      /*         A routine is provided to convert milliseconds to      */
  30. ;      /*         timer ticks.                                          */
  31. ;      /*                                                               */
  32. ;      /*  ENTRY POINTS:                                                */
  33. ;      /*      See public statements                                    */
  34. ;      /*  EXTERNAL REFERENCES:                                         */
  35. ;      /*      See extrn statements                                     */
  36. ;      /*                                                               */
  37. ;      /******************* END  OF  SPECIFICATIONS *********************/
  38. .xlist
  39.   include pensegs.inc
  40.   include pen.inc
  41.   include struc.inc
  42.   include devhlp.inc
  43.   include infoseg.inc
  44. .list
  45.  
  46. .286p
  47.  
  48. ;------------------------------------------------------------------------------
  49. ;declare external variables
  50. ;------------------------------------------------------------------------------
  51.  
  52. extrn Device_Help : dword
  53. extrn DCB_Anchor : word
  54. extrn GDTInfoSeg   : word
  55.  
  56. ;------------------------------------------------------------------------------
  57. ;  DOS calls
  58. ;------------------------------------------------------------------------------
  59.  
  60. extrn   DOSGETINFOSEG:far
  61.  
  62. ;------------------------------------------------------------------------------
  63. ;  external routines
  64. ;------------------------------------------------------------------------------
  65.  
  66. extrn Trc_Tick : near
  67.  
  68. ;------------------------------------------------------------------------------
  69. ; local equates
  70. ;------------------------------------------------------------------------------
  71.  
  72. TICK_INTERVAL equ 1 ; n-tick count for  n-tick device help
  73.  
  74. ;------------------------------------------------------------------------------
  75. ; local data declarations
  76. ;------------------------------------------------------------------------------
  77.  
  78. DSEG SEGMENT
  79. public Tim_MsecPerTick
  80.   Tim_MsecPerTick dd 33 ;default, will be updated during init
  81. DSEG ends
  82.  
  83. ;------------------------------------------------------------------------------
  84. ; Initialization data
  85. ;------------------------------------------------------------------------------
  86.  
  87. DSEGI segment
  88. ring3_GIS  dw ?   ; ring 3 selector to global info seg
  89. ring3_LIS  dw ?   ; ring 3 selector to local info seg
  90. DSEGI ends
  91.  
  92. CSEG     SEGMENT
  93.          ASSUME    CS:CGROUP, SS:nothing, ES:nothing, DS:DGROUP
  94. ;------------------------------------------------------------------------------
  95. ; Timer interrupt handler
  96. ;------------------------------------------------------------------------------
  97. public timIntHandler
  98. timIntHandler proc far
  99.   TraceTick
  100.  
  101. ; call all devices that request a timer tick
  102.  
  103.   mov  bx, DCB_Anchor
  104.   .if <nonzero bx>
  105.      .repeat
  106.        CALL_NZ [bx].dcb_@Dev_DDTick
  107.        CALL_NZ [bx].dcb_@Dev_DTTick
  108.        mov  bx,[bx].dcb_link
  109.      .until <zero bx>
  110.   .endif
  111.   xor ax,ax   ; clear carry
  112.   ret
  113. timIntHandler endp
  114.  
  115. ;------------------------------------------------------------------------------
  116. ; convert milliseconds to tick count
  117. ;   eax = milliseconds
  118. ; returns
  119. ;   eax = tick count
  120. ;------------------------------------------------------------------------------
  121. .386p
  122. public Tim_Mill2Tick
  123. Tim_Mill2Tick proc
  124.   push edx
  125.   xor  edx,edx
  126.   idiv Tim_MsecPerTick     ;calculate number of ticks
  127.   .if  <nonzero edx>
  128.      inc eax
  129.   .endif
  130.   pop edx
  131.   ret
  132. Tim_Mill2Tick endp
  133. .286p
  134.  
  135. CSEG ends
  136.  
  137. ;---- INITIALIZATION ROUTINES -------------------------------------------------
  138. ;
  139. ; note: this code is truncated from the driver after the INIT command returns
  140. ;       to OS/2
  141. ;------------------------------------------------------------------------------
  142.  
  143. CSEGI segment
  144.  
  145. ;------------------------------------------------------------------------------
  146. ; Initialize timer
  147. ;  bx = dcb
  148. ;------------------------------------------------------------------------------
  149. public Tim_Init
  150. Tim_Init  proc
  151.   push bx
  152.  
  153. ; call DosGetInfoSeg to get ring3 global info seg
  154.  
  155.   push ds
  156.   push offset ring3_GIS
  157.   push ds
  158.   push offset ring3_LIS
  159.   call DosGetInfoSeg
  160.   jc tim_exit
  161.   .if  <nonzero ax>
  162.     PANIC PANIC_GETINFO
  163.     stc
  164.     jmp short tim_exit
  165.   .endif
  166.   mov     ax, ring3_GIS
  167.  
  168. ; calculate milliseconds per tick
  169.  
  170.   push    es
  171.   mov     es, ax
  172.  
  173.   xor     bx, bx
  174.   mov     ax, es:[bx].SIS_ClkIntrvl
  175.   pop     es
  176.  
  177.   mov     cx, TICK_INTERVAL
  178.   mul     cx
  179.   mov     cx, 10
  180.   div     cx
  181.   .if     <zero ax>
  182.     inc     ax
  183.   .endif
  184.   mov     word ptr Tim_MsecPerTick,ax
  185.  
  186. ; register a tick handler
  187.  
  188.   mov  ax, offset timIntHandler
  189.   mov  bx, TICK_INTERVAL
  190.   mov  dl, DevHlp_TickCount
  191.   call Device_Help
  192.   .if c
  193.     PANIC PANIC_DEVHLP3
  194.   .endif
  195. tim_exit:
  196.   pop bx
  197.   ret
  198. Tim_Init  endp
  199.  
  200.  
  201. CSEGI ends
  202.  
  203. end
  204.  
  205.