home *** CD-ROM | disk | FTP | other *** search
/ The Party 1994: Try This At Home / disk_image.bin / source / vexsrc / timer.asm < prev    next >
Assembly Source File  |  1995-03-29  |  3KB  |  161 lines

  1. comment #
  2. /*****************************************************************************
  3.                                   ATTENTION!
  4.                            this source is VOTEWARE,
  5.               you may only use it to the conditions listed below:
  6.  
  7.   -You may modify it, or use parts of it in your own source as long as
  8.     this header stays on top of all files containing this source.
  9.   -You must give proper credit to the author, Niklas Beisert / pascal.
  10.   -You may not use it in commercial productions without the written
  11.     permission of the author.
  12.   -AND MOST IMPORTANT: you have to buy an Assembly '94 CD-ROM
  13.     by Sound Solutions (if you don't have it already) and vote for VEX-InTrO
  14.     in the PC-64k-Intro-Compo! (if you have already sent your voting card,
  15.     buy another one and fill it out CORRECTLY!!!)
  16. *****************************************************************************/
  17. #
  18.  
  19.  
  20.  
  21. ; // a stupid timer, makes the clock go wrong.... ;)
  22.  
  23. .model large,c
  24. .386
  25. locals
  26.  
  27. .code
  28.  
  29. oldtimer dd 0
  30. timerroutine dd 0
  31. routinebusy db 0
  32. timerrate dw 0
  33. ticker dd 0
  34. intcount dw 0
  35. routcount dw 0
  36.  
  37. public tuInstall
  38. public tuClose
  39. public tuDisable
  40. public tuEnable
  41. public tuGetTimer
  42. public tuResetTimer
  43. public tuUpdate
  44.  
  45. timerhandler proc
  46.   push eax
  47.  
  48.   movzx eax,timerrate
  49.   add ticker,eax
  50.  
  51.   add intcount,ax
  52.   jnc @@noint
  53.   pushf
  54.   call oldtimer
  55. @@noint:
  56.  
  57.   mov al,20h
  58.   out 20h,al
  59.  
  60.   add routcount,65535
  61.   jnc @@norout
  62.   cmp routinebusy,0
  63.   jne @@norout
  64.   inc routinebusy
  65.   pushf
  66.   call timerroutine
  67.   dec routinebusy
  68. @@norout:
  69.  
  70.   pop eax
  71.   iret
  72. endp
  73.  
  74. tuInstall proc uses ds
  75.   mov intcount,1
  76.   mov routinebusy,1
  77.   mov ticker,0
  78.   mov timerrate,65535
  79.   mov ax,3508h
  80.   int 21h
  81.   mov word ptr cs:oldtimer,bx
  82.   mov word ptr cs:oldtimer+2,es
  83.   mov cs:ticker,0
  84.   mov al,34h
  85.   out 43h,al
  86.   mov al,0ffh
  87.   out 40h,al
  88.   out 40h,al
  89.   mov ax,2508h
  90.   push cs
  91.   pop ds
  92.   mov dx,offset timerhandler
  93.   int 21h
  94.   ret
  95. endp
  96.  
  97. tuClose proc uses ds
  98.   mov al,34h
  99.   out 43h,al
  100.   mov al,00h
  101.   out 40h,al
  102.   out 40h,al
  103.   mov ax,2508h
  104.   mov dx,word ptr cs:oldtimer
  105.   mov ds,word ptr cs:oldtimer+2
  106.   int 21h
  107.   ret
  108. endp
  109.  
  110. tuDisable proc
  111.   inc routinebusy
  112.   ret
  113. endp
  114.  
  115. tuEnable proc
  116.   dec routinebusy
  117.   ret
  118. endp
  119.  
  120. tuUpdate proc
  121.   cmp routinebusy,0
  122.   jnz @@end
  123.     inc cs:routinebusy
  124.     pushf
  125.     call cs:timerroutine
  126.     dec cs:routinebusy
  127.     mov cs:routcount,0
  128. @@end:
  129.   ret
  130. endp
  131.  
  132. tuGetTimer proc
  133.   mov al,00h
  134.   out 43h,al
  135.   in al,40h
  136.   xchg al,ah
  137.   in al,40h
  138.   xchg al,ah
  139.   movzx eax,ax
  140.   neg eax
  141.   add eax,ticker
  142.   mov edx,3600
  143.   mul edx
  144.   shr eax,16
  145.   ret
  146. endp
  147.  
  148. tuResetTimer proc
  149.   mov al,00h
  150.   out 43h,al
  151.   in al,40h
  152.   xchg al,ah
  153.   in al,40h
  154.   xchg al,ah
  155.   movzx eax,ax
  156.   mov ticker,eax
  157.   ret
  158. endp
  159.  
  160. end
  161.