2023-12-08 22:56:35 +01:00
|
|
|
|
.include "system.h65"
|
2023-11-09 12:07:37 +01:00
|
|
|
|
|
2023-12-16 02:41:19 +01:00
|
|
|
|
.export sleep
|
|
|
|
|
|
|
|
|
|
.code
|
2024-08-08 20:15:50 +02:00
|
|
|
|
;;********************************************************************************
|
|
|
|
|
;; @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
|
|
|
|
|
;;********************************************************************************
|
2023-11-09 12:07:37 +01:00
|
|
|
|
.proc sleep
|
2023-12-08 22:56:35 +01:00
|
|
|
|
_VAR_1 = ARG15
|
2023-11-11 12:13:47 +01:00
|
|
|
|
stz _VAR_1
|
2023-11-09 12:07:37 +01:00
|
|
|
|
@loop:
|
|
|
|
|
.repeat 17
|
|
|
|
|
nop ; 2 - i
|
|
|
|
|
.endrepeat
|
2023-11-11 12:13:47 +01:00
|
|
|
|
inc _VAR_1 ; 3 - zp
|
2023-11-09 12:07:37 +01:00
|
|
|
|
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,010 239 s
|
|
|
|
|
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,010 244 s
|
|
|
|
|
rts
|
|
|
|
|
; so T = N * 0,010 244 s - (1(last bne) + 4(jsr) + 6(rts)) * (1/1MHz)
|
|
|
|
|
.endproc
|