File: settime.s

package info (click to toggle)
cc65 2.19-2
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 20,268 kB
  • sloc: ansic: 117,151; asm: 66,339; pascal: 4,248; makefile: 1,009; perl: 607
file content (55 lines) | stat: -rw-r--r-- 1,359 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
;
; 2019-12-27, Greg King
;
; int __fastcall__ clock_settime (clockid_t clk_id, const struct timespec *tp);
;

        .include        "time.inc"
        .include        "cx16.inc"

        .importzp       ptr1
        .import         pushax, pusheax, ldax0sp, ldeaxidx
        .import         tosdiveax, incsp3, return0
        .import         load_jiffy
        .import         CLOCK_SET_DATE_TIME


.macro  COPY    reg, offset
        ldy     #offset
        lda     (ptr1),y
        sta     gREG::reg
.endmac

;----------------------------------------------------------------------------

.proc   _clock_settime

        jsr     pushax

        .assert timespec::tv_sec = 0, error
        jsr     _localtime
        sta     ptr1
        stx     ptr1+1

        COPY    r0L, tm::tm_year
        COPY    r0H, tm::tm_mon
        inc     gREG::r0H
        COPY    r1L, tm::tm_mday
        COPY    r1H, tm::tm_hour
        COPY    r2L, tm::tm_min
        COPY    r2H, tm::tm_sec

        jsr     ldax0sp                 ; Get tp
        ldy     #timespec::tv_nsec+3
        jsr     ldeaxidx                ; Get nanoseconds
        jsr     pusheax
        jsr     load_jiffy
        jsr     tosdiveax
        sta     gREG::r3L               ; Put number of jiffies

        jsr     CLOCK_SET_DATE_TIME

        jsr     incsp3
        jmp     return0

.endproc