Untitled
By: a guest | Mar 19th, 2010 | Syntax:
None | Size: 5.14 KB | Hits: 103 | Expires: Never
******************************************************
* Set the timer interrupt
* System clock max is 45MHz
******************************************************
tmr_init
move.l D0, -(A7)
move.w #$ff3d, D0 ;PS=1111_1111, CE=00,OM=1,ORI=1,FRR=1,CLK=10,RST=1, FF3D
move.w D0, TMR0
move.w #10986, D0 ;TMR is set to divide the 45MHz by 16 then by 256, 45000000/16/256=10986.328125
move.w D0, TRR0
move.l #$96, D0 ;AVEC=1,[65]=00,IL=101,IP=10
move.b D0, ICR1 ;set timer0 ICR
move.l #tmr_isr_addonly, D0
move.l D0, ISR_lvl_5
move.l (A7)+, D0
rts
******************************************************
* Timer Mode
* turn off the timer interrupt via TMR[ORI]
******************************************************
tmr_mode
move.l A1, -(A7)
move.l D1, -(A7)
cmp.l #43200, D6
blt tmr_mode_init
lea TMR_MISSING_INIT, A1
bsr out_string
bra tmr_mode_exit
tmr_mode_init
lea TMR_PROMPT, A1
bsr out_string
bsr tmr_out
move.l #tmr_isr_add_print, D1
move.l D1, ISR_lvl_5
tmr_mode_loop
bsr in_char
cmp.l #80, D1
bne tmr_mode_skip_pause
bsr tmr_pause
bra tmr_mode_loop
tmr_mode_skip_pause
cmp.l #83, D1
bne tmr_mode_skip_start
bsr tmr_start
bra tmr_mode_loop
tmr_mode_skip_start
cmp.l #82, D1
bne tmr_mode_skip_reset
move.l #43195, D6
move.l D1, -(A7)
move.l #CR, D1
bsr out_char
move.l (A7)+, D1
bsr tmr_out
bra tmr_mode_loop
tmr_mode_skip_reset
cmp.l #CR, D1
beq tmr_mode_end
cmp.l #LF, D1
bne tmr_mode_loop
tmr_mode_end
move.l #tmr_isr_addonly, D1
move.l D1, ISR_lvl_5
bsr out_crlf
tmr_mode_exit
move.l (A7)+, D1
move.l (A7)+, A1
rts
******************************************************
* Pause the timer
* turn off the timer interrupt via TMR[ORI]
******************************************************
tmr_pause
move.l D0, -(A7)
move.w #$ff2d, D0
move.w D0, TMR0
move.l (A7)+, D0
rts
******************************************************
* Start the timer
* turn on the timer interrupt via TMR[ORI]
******************************************************
tmr_start
move.l D0, -(A7)
move.w #$ff3d, D0
move.w D0, TMR0
move.l (A7)+, D0
rts
******************************************************
* This ISR only increments the timer
******************************************************
tmr_isr_addonly
bsr tmr_clr_interrupt
bsr tmr_increment
rte
******************************************************
* This ISR increments the timer and print the result
* the result will be printed from the beginning of the current line
* it does not start a new line
******************************************************
tmr_isr_add_print
move.l D1, -(A7)
bsr tmr_clr_interrupt
bsr tmr_increment
move.l #CR, D1
bsr out_char
bsr tmr_out
move.l (A7)+, D1
rte
******************************************************
* Clears the timer interrupt
******************************************************
tmr_clr_interrupt
move.l D0, -(A7)
move.l D1, -(A7)
move.b #$02, D0
move.b D0, TER0
move.l (A7)+, D1
move.l (A7)+, D0
rts
******************************************************
* Increments the timer
******************************************************
tmr_increment
addq.l #1, D6
cmp.l #43200, D6
blt tmr_increment_end
clr.l D6
tmr_increment_end
rts
******************************************************
* Outputs the timer
* timer value is stored in D6
* No newline is printed
* it only prints 7 characters using out_char
******************************************************
tmr_out
move.l D0, -(A7)
move.l D1, -(A7)
move.l D2, -(A7)
move.l D6, D0
move.l #3600, D1
divu.l D1, D0 ;HH
bsr tmr_fastprint
move.l #$3A, D1
bsr out_char ;colon
move.l D6, D2
move.l #60, D1
divu.l D1, D2
remu.l D1, D0:D2 ;MM
bsr tmr_fastprint
move.l #$3A, D1
bsr out_char ;colon
move.l #60, D1
remu.l D1, D0:D6 ;SS
bsr tmr_fastprint
move.l (A7)+, D2
move.l (A7)+, D1
move.l (A7)+, D0
rts
******************************************************
* Outputs D0 which should store a 2 digit number
******************************************************
tmr_fastprint
move.l D1, -(A7)
move.l D2, -(A7)
move.l #10, D2
move.l D0, D1
divu D2, D1
add.l #$30, D1
bsr out_char
remu D2, D1:D0
add.l #$30, D1
bsr out_char
move.l (A7)+, D2
move.l (A7)+, D1
rts
******************************************************
* Asks for timer input
******************************************************
tmr_in
move.l A1, -(A7)
bsr tmr_init
clr.l D6
lea TMR_INITIALIZED, A1
bsr out_string
move.l (A7)+, A1
rts