home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / emulate / systems / apple / timer.asm < prev    next >
Assembly Source File  |  1990-03-30  |  6KB  |  187 lines

  1.     Page    58,132
  2.     Title    TIMER.ASM    Apple Emulator Timer Routines
  3. ;******************************************************************************
  4. ;
  5. ;   Name:    TIMER.ASM    Apple Emulator Timer Routines
  6. ;
  7. ;   Group:    Emulator
  8. ;
  9. ;   Revision:    1.00
  10. ;
  11. ;   Date:    January 30, 1988
  12. ;
  13. ;   Author:    Randy W. Spurlock
  14. ;
  15. ;******************************************************************************
  16. ;
  17. ;  Module Functional Description:
  18. ;
  19. ;        This module contains all the code for the Apple timer
  20. ;    routines.
  21. ;
  22. ;******************************************************************************
  23. ;
  24. ;  Changes:
  25. ;
  26. ;    DATE     REVISION                DESCRIPTION
  27. ;  --------   --------    -------------------------------------------------------
  28. ;   1/30/88    1.00    Original
  29. ;
  30. ;******************************************************************************
  31.     Page
  32. ;
  33. ;  Public Declarations
  34. ;
  35.     Public    Timer_Init        ; Timer initialization routine
  36.     Public    Timer_Reset        ; Timer reset routine
  37.     Public    Timer_Int        ; Timer interrupt routine
  38. ;
  39. ;  External Declarations
  40. ;
  41.     Extrn    Int_Update:Near     ; Interrupt update routine      (INT)
  42.     Extrn    Joystick_Update:Near    ; Joystick update routine    (JOYSTICK)
  43.     Extrn    Original_Int_8:Dword    ; Original interrupt 8 vector     (DATA)
  44. ;
  45. ;  LOCAL Equates
  46. ;
  47. INT_PORT    Equ    20h        ; Interrupt controller port
  48. INT_ACK     Equ    20h        ; Interrupt acknowledge value
  49. TIMER_PORT    Equ    40h        ; Timer control port address
  50. NEW_DIVIDER    Equ    2468h        ; New timer divider (128 ticks/sec)
  51. OLD_DIVIDER    Equ    0000h        ; Old timer divider (18.2 ticks/sec)
  52. FRAC_COUNT    Equ    0708h        ; Fractional counter (7.03125)
  53. FRAC_ONE    Equ    0100h        ; Fractional constant one (1.00)
  54. ;
  55. ;  Define any include files needed
  56. ;
  57.     Include     Macros.inc    ; Include the macro definitions
  58.     Include     Equates.inc    ; Include the equate definitions
  59.     .286c                ; Include 80286 instructions
  60.     Page
  61. ;
  62. ;  Define the emulator code segment
  63. ;
  64. Emulate Segment Word Public 'EMULATE'   ; Emulator code segment
  65.     Assume    cs:Emulate, ds:Nothing, es:Nothing
  66.     Subttl    Timer_Init    Timer Initialization Routine
  67.     Page    +
  68. ;******************************************************************************
  69. ;
  70. ;    Timer_Init()
  71. ;
  72. ;        Save the required registers
  73. ;        Output the new divider value
  74. ;        Restore the required registers
  75. ;        Return to the caller
  76. ;
  77. ;    Registers on Entry:
  78. ;
  79. ;        None
  80. ;
  81. ;    Registers on Exit:
  82. ;
  83. ;        None
  84. ;
  85. ;******************************************************************************
  86.         Even            ; Force procedure to even address
  87. Timer_Init    Proc    Near        ; Timer initialization procedure
  88.     Save    ax            ; Save the required registers
  89.     mov    al,LOW NEW_DIVIDER    ; Get the LSB of the new divider
  90.     out    TIMER_PORT,al        ; Output LSB of the new divider
  91.     mov    al,HIGH NEW_DIVIDER    ; Get the MSB of the new divider
  92.     out    TIMER_PORT,al        ; Output MSB of the new divider
  93.     Restore ax            ; Restore the required registers
  94.     ret                ; Return to the caller
  95. Timer_Init    Endp            ; End of the Timer_Init procedure
  96.     Subttl    Timer_Reset    Timer Reset Routine
  97.     Page    +
  98. ;******************************************************************************
  99. ;
  100. ;    Timer_Reset()
  101. ;
  102. ;        Save the required registers
  103. ;        Reset the timer divider value
  104. ;        Restore the required registers
  105. ;        Return to the caller
  106. ;
  107. ;    Registers on Entry:
  108. ;
  109. ;        None
  110. ;
  111. ;    Registers on Exit:
  112. ;
  113. ;        None
  114. ;
  115. ;******************************************************************************
  116.         Even            ; Force procedure to even address
  117. Timer_Reset    Proc    Near        ; Timer reset procedure
  118.     Save    ax            ; Save the required registers
  119.     mov    al,LOW OLD_DIVIDER    ; Get the LSB of the old divider
  120.     out    TIMER_PORT,al        ; Output LSB of the old divider
  121.     mov    al,HIGH OLD_DIVIDER    ; Get the MSB of the old divider
  122.     out    TIMER_PORT,al        ; Output MSB of the old divider
  123.     Restore ax            ; Restore the required registers
  124.     ret                ; Return to the caller
  125. Timer_Reset    Endp            ; End of the Timer_Reset procedure
  126.     Subttl    Timer_Int    Timer Interrupt Routine
  127.     Page    +
  128. ;******************************************************************************
  129. ;
  130. ;    Timer_Int()
  131. ;
  132. ;        Save the required registers
  133. ;        Call the emulator interrupt update routine
  134. ;        Call the joystick update routine
  135. ;        Decrement the time counter (Fractional one)
  136. ;        If time to call the original interrupt
  137. ;            Update the time counter (Fractional)
  138. ;            Restore the required registers
  139. ;            Jump to the original routine (Will return to caller)
  140. ;        Else NOT time to call original interrupt
  141. ;            Acknowledge the interrupt controller
  142. ;            Restore the required registers
  143. ;            Return to the caller (Interrupt Return)
  144. ;        Endif
  145. ;
  146. ;    Registers on Entry:
  147. ;
  148. ;        None
  149. ;
  150. ;    Registers on Exit:
  151. ;
  152. ;        None
  153. ;
  154. ;******************************************************************************
  155.         Even            ; Force procedure to even address
  156. Timer_Int    Proc    Near        ; Timer interrupt procedure
  157.     Save    ax            ; Save the required registers
  158.     call    Int_Update        ; Call emulator interrupt update routine
  159.     call    Joystick_Update     ; Call the joystick update routine
  160.     mov    ax,cs:[Time_Count]    ; Get the current time counter value
  161.     sub    ax,FRAC_ONE        ; Decrement the time counter value
  162.     jnc    Timer_Finish        ; Jump if NOT time for original int. 8
  163.     add    ax,FRAC_COUNT        ; Update the time counter value
  164.     mov    cs:[Time_Count],ax    ; Save the new time counter value
  165.     Restore ax            ; Restore the required registers
  166.     jmp    cs:[Original_Int_8]    ; Do original interrupt 8 (Never return)
  167. Timer_Finish:
  168.     mov    cs:[Time_Count],ax    ; Save the new time counter value
  169.     mov    al,INT_ACK        ; Get interrupt acknowledge value
  170.     out    INT_PORT,al        ; Send acknowledgement to controller
  171.     Restore ax            ; Restore the required registers
  172.     iret                ; Return to the caller (Interrupt)
  173. Timer_Int    Endp            ; End of the Timer_Int procedure
  174. ;******************************************************************************
  175. ;
  176. ;    Define any timer variables
  177. ;
  178. ;******************************************************************************
  179. Time_Count    Dw    FRAC_COUNT    ; Original rate timer counter
  180. ;******************************************************************************
  181. ;
  182. ;    Define the end of the Emulator Code Segment
  183. ;
  184. ;******************************************************************************
  185. Emulate Ends
  186.     End                ; End of the Timer module
  187.