
;------------------------------------------------------------------------------
;                                 fdelay.s03
;------------------------------------------------------------------------------
; DESCRIPTION:  This module contains a little function to that gives a variable
;               delay with the same resolution as the SYSCLK period (on a
;               single-clocker, that is).  It's called with the number of
;               periods to delay in R7.  It works by jumping into the middle of
;               a big string of NOPs at a position that varies with the input
;               parameter.  There's a RET following the NOPs that returns to
;               the caller.
;
; REVISIONS     13 Sep 06 - RAC - Genesis, after a hint picked up on the
;                                  Silicon Labs user forum.
;------------------------------------------------------------------------------

                RSEG    RCODE

                PUBLIC  do_fine_delay
do_fine_delay:
                MOV     A,R7            ; Get input parameter
                CPL     A               ; Take two's compliment
                INC     A
                MOV     DPTR,#NOPS      ; Point DPTR at the NOP table
                JMP     @A+DPTR         ; Jump into table

;-----  256 NOPs (op code 0) coded in a semi-concise manner

NOPS:
                DB      0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
                DB      0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
                DB      0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
                DB      0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
                DB      0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
                DB      0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
                DB      0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
                DB      0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
                DB      0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
                DB      0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
                DB      0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
                DB      0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
                DB      0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
                DB      0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
                DB      0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
                DB      0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0

                RET

                END
