;---------------------------------------------------------
; file:         delay.s
; description:  This file contains the millisecond delay
;               subroutine test software.
;
; C Interface: Use delay.h
; Assemble this file with the ICC11 compiler. 
;---------------------------------------------------------
        .area   text
;---------------------------------------------------------
; subroutine:   DelayMilliSec
; description:  This subroutine delays the number of 
;               milliseconds specified in B.
; input:        B = #milliseconds
; output:       B = 0
; uses:         X used as counter, stack saved/restored
;
; Notes:        Loop multiplier is .001sec/InnerLoopTime
;               InnerLoopTime = 8 cycles/2mhz = 4 usec
;               Loop multiplier = .001/.000004 = 250
;---------------------------------------------------------
_DelayMilliSec::        ; Define as global with double colon
        pshx            ; 4 * Save X register
dm1:    ldx     #250    ; 3 * Set loop multiplier
dm0:    dex             ; 3 * Decrement the loop counter
        nop             ; 2 * Use time so loop counter is integer
        bne     dm0     ; 3 * Branch if loop counter not 0
        decb            ; 2 * Decrement the millisecond counter
        bne     dm1     ; 3 * Branch if not 0
        pulx            ; 4 * Restore X register
        rts             ; 5 * Return from subroutine
;---------------------------------------------------------
; subroutine:   Delay50usec
; description:  This subroutine delays 50 microseconds.
; input:        B = #milliseconds
; output:       B = 0
; uses:         X used as counter, stack saved/restored
;---------------------------------------------------------
_Delay50usec::          ; Define as global with double colon
        pshx            ; 4 * Save X register
dm51:   ldx     #5      ; 3 * Set loop multiplier
dm50:   dex             ; 3 * Decrement the loop counter
        nop             ; 2 * Use time so loop counter is integer
        nop             ; 2 * Use time so loop counter is integer
        bne     dm50    ; 3 * Branch if loop counter not 0
        pulx            ; 4 * Restore X register
        rts             ; 5 * Return from subroutine
