home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / rec / games / programm / 5212 / retrace.asm
Encoding:
Assembly Source File  |  1992-12-29  |  2.1 KB  |  112 lines

  1. ideal
  2. locals @@
  3.  
  4. model Large
  5.  
  6. codeseg
  7.  
  8. OldInt08    dd    0
  9. RetraceCount    db    0
  10.  
  11. TimerSpeed     equ 16572        ; 1,193,182 div 70  (I think)
  12.  
  13. proc    MyTimer
  14.  
  15. ;Call the old timer interrupt routine here...
  16.  
  17.     push ax dx ds
  18.     inc  [Byte cs:RetraceCount]
  19.  
  20. ;The timer is not 100% accurate, adjust with vertical retrace again
  21. ;Wait for vertical retrace
  22.  
  23.     mov  dx,03DAh              ;DX = CRTC Status Port
  24. @@1:
  25.     in   al,dx              ;Read the port
  26.     and  al,8              ;Is a vertical retrace active?
  27.     jz   short @@1
  28.  
  29. ;Reset the timer
  30.     mov  al,34h
  31.     out  43h,al
  32. ;Write the new speed
  33.     mov  ax,TimerSpeed
  34.     out  40h,al
  35.     mov  al,ah
  36.     out  40h,al
  37.  
  38. ;Signal EOI (end-of-interrupt)
  39.     mov  al,20h              ;AL = 20h (EOI)
  40.     out  20h,al              ;Signal EOI to enable next
  41.                                                             ; interrupt
  42.  
  43.     pop  ds dx ax
  44.     iret
  45. endp    MyTimer
  46.  
  47. ; Enable the vertical retrace timer interrupt
  48.  
  49. proc    Enable_Timer
  50.     cli
  51.     xor    ax,ax
  52.     mov    es,ax            ;ES points to the first segment
  53.     mov    ax,[es:8*4]
  54.     mov    [Word cs:OldInt08],ax
  55.         mov     ax,[es:8*4+2]
  56.     mov    [Word cs:OldInt08+2],ax
  57.         mov     [Word es:8*4],offset MyTimer
  58.     mov    [Word es:8*4+2],cs
  59.  
  60. ;Wait for the beginning of vertical retrace
  61. ;Wait for no vertical retrace
  62. @@1:    mov    dx,03DAh         ;DX = CRTC Status Port
  63.     in    al,dx             ;Read the port
  64.     and    al,8             ;Is a vertical retrace
  65.     jnz    @@1
  66.  
  67. ;Wait for vertical retrace
  68. @@2:
  69.     in    al,dx             ;Read the port
  70.     and    al,8             ;Is a vertical retrace
  71.     jz    Short @@2
  72.  
  73. ;Set the new timer speed
  74.     mov  al,34h              ;AL = 34h
  75.     out  43h,al              ;Write AL to port 43h
  76.  
  77. ;Write the new speed
  78.     mov  ax,TimerSpeed
  79.     out  40h,al
  80.     mov  al,ah
  81.     out  40h,al
  82.  
  83.     sti                  ;Enable interrupts
  84.     ret
  85. endp    Enable_Timer
  86.  
  87. proc    Disable_Timer
  88.     cli                ;Disable interrupts
  89.     xor  ax,ax
  90.     mov  es,ax            ;ES points to the first segment
  91.                                                             ; (interrupt vector table)
  92.     mov    ax,[Word cs:OldInt08]
  93.     mov    [Word es:8*4],ax
  94.     mov    ax,[Word cs:OldInt08+2]
  95.     mov    [Word es:8*4+2],ax
  96.  
  97. ;Reset the timer speed
  98.     mov  al,34h
  99.     out  43h,al              ;Write AL to port 43h
  100.  
  101. ;Write the original speed
  102.     xor  al,al              ;Write 0 to port 40h
  103.     out  40h,al
  104.     out  40h,al
  105.  
  106.     sti
  107.     ret
  108. endp    Disable_Timer
  109.  
  110.     end
  111.  
  112.