home *** CD-ROM | disk | FTP | other *** search
/ Black Box 4 / BlackBox.cdr / progbas / hptimer.arj / HPTIMER.ASM < prev    next >
Encoding:
Assembly Source File  |  1992-04-23  |  3.9 KB  |  260 lines

  1. ;HPTIMER v1.00 for QuickBASIC 4.5
  2. ;By Rich Geldreich April 19th, 1992
  3. ;Any questions/suggestions:
  4.  
  5. ;Rich Geldreich
  6. ;410 Market St.
  7. ;Gloucester City, NJ 08030
  8.  
  9. ;to make a .qlb, use:
  10. ;link /q hptimer.obj,hptimer.qlb,,bqlb45.lib
  11.  
  12. PUBLIC InitTimer,GetTimer,SetTimer,DetachTimer
  13. PUBLIC SetAlarm,GetAlarm,AlarmOn,AlarmOff
  14.  
  15. EXTRN SETUEVENT
  16.  
  17. P1 EQU [ss:bp+6]
  18. P2 EQU [ss:bp+8]
  19. P3 EQU [ss:bp+10]
  20.  
  21. Code segment 'CODE'
  22. Assume cs: Code
  23.  
  24. Old_Offset             dw 0
  25. Old_Segment             dw 0
  26.  
  27. Already_Changed         dw 0
  28.  
  29. Number_Clicks_low        dw 0
  30. Number_Clicks_high        dw 0
  31.  
  32. Clicks                      dw 0
  33. Delay                       dw 0
  34.  
  35. Alarm_Low                  dw 0
  36. Alarm_High                 dw 0
  37.  
  38. Delay_Low                  dw 0
  39. Delay_High                 dw 0
  40.  
  41. Alarm_On                   dw 0
  42. Delay_On                   dw 0
  43.  
  44. Qb_data_seg                dw 0
  45.  
  46. InitTimer proc far
  47.     push bp
  48.     mov bp, sp
  49.     
  50.     cmp [cs:Already_Changed], 1
  51.     je exit1
  52.     mov [cs:Already_Changed], 1
  53.  
  54.     mov cx, P1
  55.     and cx, cx
  56.     jz exit1
  57.  
  58.     mov [cs:Qb_data_seg], ds
  59.     
  60.     mov ax, 3200
  61.     mul cx
  62.     mov bx, 65535
  63.     div bx
  64.     cmp dx, 1599
  65.     jna @@10
  66.     inc ax
  67. @@10:
  68.     mov [cs:Delay], ax
  69.     mov [cs:Clicks], 0
  70.  
  71.     push es
  72.         mov ax, 3508h
  73.         int 21h
  74.         mov [cs:Old_Segment], es
  75.         mov [cs:Old_Offset], bx
  76.         pop es
  77.      
  78.     mov dx, offset NewInterrupt
  79.     push ds
  80.         mov ax, 2508h
  81.         push cs
  82.         pop ds
  83.         int 21h
  84.         pop ds
  85.  
  86.     mov al, 00110100b
  87.         out 043h, al
  88.                         
  89.         mov ax, cx
  90.         out 040h, al
  91.         mov al, ah
  92.         out 040h, al
  93.         
  94. exit1:
  95.     pop bp
  96.     retf 2            
  97. InitTimer endp
  98.  
  99. NewInterrupt proc far
  100.     push ax
  101.     push bx
  102.  
  103.     mov ax, [cs:Number_Clicks_Low]
  104.     add ax, 1
  105.     jnc @@05
  106.     inc [cs:Number_Clicks_High]
  107. @@05:
  108.     mov [cs:Number_Clicks_Low], ax
  109.     
  110.     cmp byte ptr [cs:Alarm_On], -1
  111.     jne @@06
  112.     cmp ax, [cs:Alarm_Low]
  113.     jne @@06
  114.     mov bx, [cs:Number_Clicks_High]
  115.     cmp bx, [cs:Alarm_High]
  116.     jne @@06
  117.  
  118.     push cx
  119.     push dx
  120.     push si
  121.     push di
  122.     push bp
  123.     push es
  124.     push ds
  125.     mov ds, [cs:Qb_data_seg]
  126.     call far ptr SETUEVENT
  127.     pop ds
  128.     pop es
  129.     pop bp
  130.     pop di
  131.     pop si
  132.     pop dx
  133.     pop cx
  134.  
  135. @@06:
  136.     mov ax, [cs:Clicks]
  137.     add ax, [cs:Delay]
  138.     cmp ax, 3199
  139.     jna @@11
  140.     sub ax, 3200
  141.     mov [cs:Clicks], ax
  142.     pop bx
  143.     pop ax
  144.     jmp dword ptr [Old_Offset]
  145. @@11:
  146.     mov [cs:Clicks], ax
  147.     mov al, 20h
  148.     out 20h, al
  149.     pop bx
  150.     pop ax
  151.     sti
  152.     iret
  153. NewInterrupt endp
  154.  
  155. GetTimer proc far
  156.     push bp
  157.     mov bp, sp
  158.     mov si, P1
  159.     mov ax, [cs:Number_Clicks_low]
  160.     mov [ds:si], ax
  161.     mov ax, [cs:Number_Clicks_High]
  162.     mov [ds:si+2], ax
  163.         
  164.     pop bp
  165.     retf 2    
  166. GetTimer endp
  167.  
  168. SetTimer proc far
  169.     push bp
  170.     mov bp, sp
  171.     push si
  172.     push ax
  173.     mov si, P1
  174.     mov ax, [ds:si]
  175.     mov [cs:Number_Clicks_Low], ax
  176.     mov ax, [ds:si+2]
  177.     mov [cs:Number_Clicks_High], ax
  178.     pop ax
  179.     pop si
  180.     pop bp
  181.     retf 2    
  182. SetTimer endp
  183.  
  184. DetachTimer proc far
  185.     cmp [cs:Already_changed], 0
  186.     je @@exit
  187.     mov [cs:Already_Changed], 0
  188.     
  189.     push es
  190.         mov ax, 3508h
  191.         int 21h
  192.         mov ax, cs
  193.         mov cx, es
  194.         pop es
  195.         cmp ax, cx
  196.         jne @@exit
  197.         cmp bx, offset NewInterrupt
  198.         jne @@exit
  199.     
  200.     in al, 043h
  201.     mov dl, al
  202.     mov al, 00110100b
  203.         out 043h, al
  204.        mov al, 0FFh
  205.         out 040h, al
  206.         out 040h, al
  207.     mov al, dl
  208.     out 043h, al
  209.     
  210.     mov dx, [cs:Old_Offset]
  211.     push ds
  212.         mov ax, [cs:Old_Segment]
  213.         mov ds, ax
  214.         mov ax, 2508h
  215.         int 21h
  216.         pop ds
  217.     
  218. @@exit:
  219.     retf 0
  220. DetachTimer    endp
  221. SetAlarm proc far
  222.     push bp
  223.     mov bp, sp
  224.         
  225.     mov si, P1
  226.     mov ax, [ds:si]
  227.     mov [cs:Alarm_Low], ax
  228.     mov ax, [ds:si+2]
  229.     mov [cs:Alarm_High], ax
  230.      
  231.     pop bp
  232.     retf 2
  233. SetAlarm endp 
  234.  
  235. GetAlarm proc far
  236.     push bp
  237.     mov bp, sp
  238.     
  239.     mov si, P1
  240.     mov ax, [cs:Alarm_Low]
  241.     mov [ds:si], ax
  242.     mov ax, [cs:Alarm_High]
  243.     mov [ds:si+2], ax
  244.     
  245.     pop bp
  246.     retf 2
  247. GetAlarm endp
  248. AlarmOff proc far
  249.     mov byte ptr [cs:Alarm_On], 0 
  250.     retf 0
  251. AlarmOff endp
  252. AlarmOn proc far
  253.     mov byte ptr[cs:Alarm_On],-1
  254.     retf 0
  255. AlarmOn endp
  256. ends
  257. END
  258.  
  259.                 
  260.