6502-OS/programs/sleep.s65

34 lines
1.1 KiB
Plaintext
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

.include "system.h65"
.export sleep
.code
;;********************************************************************************
;; @function sleep
;; @param x: Time to sleep in centiseconds (10^-2s = 10ms) @ 1MHz
;; @details
;; Interrupts might change the actual time to finish
;; To be exact, time_cs is in units of 0.010244s
;; @modifies: ARG15
;; @ingroup applications
;; @clock_dependant
;;********************************************************************************
.proc sleep
_VAR_1 = ARG15
stz _VAR_1
@loop:
.repeat 17
nop ; 2 - i
.endrepeat
inc _VAR_1 ; 3 - zp
bne @loop ; 2/3 - r (2 if not taken, but here most of the time its 3)
; reaching this takes 256 * (X * 2(nop) + 3(inc) + 3(bne)) - 1(last bne) cycles
; with X = 17: T1 = (256×(17×2 + 3 +3) 1) × (1/1MHz) = 0,010239s
dex ; 2 - i
bne @loop ; 2/3 - r
; with T1 = for running through VAR_1, one iteration takes
; T1 + (2(dex) + 3(bne)) × (1/1MHz) = 0,010244s
rts
; so T = N * 0,010244s - (1(last bne) + 4(jsr) + 6(rts)) * (1/1MHz)
.endproc