Share Pastebin
Guest
Public paste!

Untitled

By: a guest | Mar 19th, 2010 | Syntax: None | Size: 5.14 KB | Hits: 103 | Expires: Never
Copy text to clipboard
  1. ******************************************************
  2. * Set the timer interrupt
  3. * System clock max is 45MHz
  4. ******************************************************
  5. tmr_init
  6.     move.l D0, -(A7)
  7.    
  8.     move.w #$ff3d, D0 ;PS=1111_1111, CE=00,OM=1,ORI=1,FRR=1,CLK=10,RST=1, FF3D
  9.     move.w D0, TMR0
  10.     move.w #10986, D0 ;TMR is set to divide the 45MHz by 16 then by 256, 45000000/16/256=10986.328125
  11.     move.w D0, TRR0
  12.    
  13.     move.l #$96, D0 ;AVEC=1,[65]=00,IL=101,IP=10
  14.     move.b D0, ICR1 ;set timer0 ICR
  15.    
  16.     move.l #tmr_isr_addonly, D0
  17.     move.l D0, ISR_lvl_5
  18.    
  19.     move.l (A7)+, D0
  20.     rts
  21. ******************************************************
  22. * Timer Mode
  23. * turn off the timer interrupt via TMR[ORI]
  24. ******************************************************
  25. tmr_mode
  26.     move.l A1, -(A7)
  27.     move.l D1, -(A7)
  28.    
  29.     cmp.l #43200, D6
  30.     blt tmr_mode_init
  31.     lea TMR_MISSING_INIT, A1
  32.     bsr out_string
  33.     bra tmr_mode_exit
  34.    
  35. tmr_mode_init
  36.     lea TMR_PROMPT, A1
  37.     bsr out_string
  38.    
  39.     bsr tmr_out
  40.     move.l #tmr_isr_add_print, D1
  41.     move.l D1, ISR_lvl_5
  42.    
  43. tmr_mode_loop
  44.     bsr in_char
  45.     cmp.l #80, D1
  46.     bne tmr_mode_skip_pause
  47.     bsr tmr_pause
  48.     bra tmr_mode_loop
  49. tmr_mode_skip_pause
  50.     cmp.l #83, D1
  51.     bne tmr_mode_skip_start
  52.     bsr tmr_start
  53.     bra tmr_mode_loop
  54. tmr_mode_skip_start
  55.     cmp.l #82, D1
  56.     bne tmr_mode_skip_reset
  57.     move.l #43195, D6
  58.     move.l D1, -(A7)
  59.     move.l #CR, D1
  60.     bsr out_char
  61.     move.l (A7)+, D1
  62.     bsr tmr_out
  63.     bra tmr_mode_loop
  64. tmr_mode_skip_reset
  65.     cmp.l #CR, D1
  66.     beq tmr_mode_end
  67.     cmp.l #LF, D1
  68.     bne tmr_mode_loop
  69.  
  70. tmr_mode_end
  71.     move.l #tmr_isr_addonly, D1
  72.     move.l D1, ISR_lvl_5
  73.     bsr out_crlf
  74.  
  75. tmr_mode_exit    
  76.     move.l (A7)+, D1
  77.     move.l (A7)+, A1
  78.     rts
  79. ******************************************************
  80. * Pause the timer
  81. * turn off the timer interrupt via TMR[ORI]
  82. ******************************************************
  83. tmr_pause
  84.     move.l D0, -(A7)
  85.    
  86.     move.w #$ff2d, D0
  87.     move.w D0, TMR0
  88.    
  89.     move.l (A7)+, D0
  90.     rts
  91. ******************************************************
  92. * Start the timer
  93. * turn on the timer interrupt via TMR[ORI]
  94. ******************************************************
  95. tmr_start
  96.     move.l D0, -(A7)
  97.    
  98.     move.w #$ff3d, D0
  99.     move.w D0, TMR0
  100.    
  101.     move.l (A7)+, D0
  102.     rts
  103.  
  104. ******************************************************
  105. * This ISR only increments the timer
  106. ******************************************************
  107. tmr_isr_addonly
  108.  
  109.     bsr tmr_clr_interrupt
  110.     bsr tmr_increment
  111.  
  112.     rte
  113.  
  114. ******************************************************
  115. * This ISR increments the timer and print the result
  116. * the result will be printed from the beginning of the current line
  117. * it does not start a new line
  118. ******************************************************
  119. tmr_isr_add_print    
  120.     move.l D1, -(A7)
  121.    
  122.     bsr tmr_clr_interrupt
  123.     bsr tmr_increment
  124.    
  125.     move.l #CR, D1
  126.     bsr out_char
  127.     bsr tmr_out
  128.    
  129.     move.l (A7)+, D1
  130.     rte
  131. ******************************************************
  132. * Clears the timer interrupt
  133. ******************************************************
  134. tmr_clr_interrupt
  135.     move.l D0, -(A7)
  136.     move.l D1, -(A7)
  137.    
  138.     move.b #$02, D0
  139.     move.b D0, TER0
  140.    
  141.     move.l (A7)+, D1
  142.     move.l (A7)+, D0
  143.     rts
  144. ******************************************************
  145. * Increments the timer
  146. ******************************************************
  147. tmr_increment
  148.    
  149.     addq.l #1, D6
  150.     cmp.l #43200, D6
  151.     blt tmr_increment_end
  152.     clr.l D6
  153.  
  154. tmr_increment_end    
  155.     rts
  156.  
  157. ******************************************************
  158. * Outputs the timer
  159. * timer value is stored in D6
  160. * No newline is printed
  161. * it only prints 7 characters using out_char
  162. ******************************************************
  163. tmr_out
  164.     move.l D0, -(A7)
  165.     move.l D1, -(A7)
  166.     move.l D2, -(A7)
  167.    
  168.     move.l D6, D0
  169.     move.l #3600, D1
  170.     divu.l D1, D0 ;HH
  171.     bsr tmr_fastprint
  172.    
  173.     move.l #$3A, D1
  174.     bsr out_char ;colon
  175.    
  176.     move.l D6, D2
  177.     move.l #60, D1
  178.     divu.l D1, D2
  179.     remu.l D1, D0:D2 ;MM
  180.     bsr tmr_fastprint
  181.    
  182.     move.l #$3A, D1
  183.     bsr out_char ;colon
  184.    
  185.     move.l #60, D1
  186.     remu.l D1, D0:D6 ;SS
  187.     bsr tmr_fastprint
  188.    
  189.     move.l (A7)+, D2
  190.     move.l (A7)+, D1
  191.     move.l (A7)+, D0
  192.     rts
  193.  
  194. ******************************************************
  195. * Outputs D0 which should store a 2 digit number
  196. ******************************************************    
  197. tmr_fastprint
  198.     move.l D1, -(A7)
  199.     move.l D2, -(A7)
  200.    
  201.     move.l #10, D2
  202.    
  203.     move.l D0, D1
  204.     divu D2, D1
  205.     add.l #$30, D1
  206.     bsr out_char
  207.    
  208.     remu D2, D1:D0
  209.     add.l #$30, D1
  210.     bsr out_char
  211.    
  212.     move.l (A7)+, D2
  213.     move.l (A7)+, D1
  214.     rts
  215.    
  216. ******************************************************
  217. * Asks for timer input
  218. ******************************************************  
  219. tmr_in
  220.     move.l A1, -(A7)
  221.    
  222.     bsr tmr_init
  223.     clr.l D6
  224.    
  225.     lea TMR_INITIALIZED, A1
  226.     bsr out_string
  227.    
  228.     move.l (A7)+, A1
  229.     rts