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 (71 lines) | stat: -rw-r--r-- 1,699 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
;
; Oliver Schmidt, 15.08.2018
;
; int __fastcall__ clock_settime (clockid_t clk_id, const struct timespec *tp);
;

        .import         __dos_type
        .import         incsp1, return0

        .include        "time.inc"
        .include        "zeropage.inc"
        .include        "errno.inc"
        .include        "mli.inc"

_clock_settime:

        ; Cleanup stack
        jsr     incsp1          ; Preserves A

        ; Check for ProDOS 8
        ldy     __dos_type
        beq     enosys

        ; Check for realtme clock
        tay                     ; Save A
        lda     MACHID
        lsr     a
        bcs     erange
        tya                     ; Restore A

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

        ; Set date
        ldy     #tm::tm_mon
        lda     (ptr1),y
        clc
        adc     #$01            ; Move [0..11] to [1..12]
        asl
        asl
        asl
        asl
        asl
        php                     ; Save month msb
        ldy     #tm::tm_mday
        ora     (ptr1),y
        sta     DATELO
        ldy     #tm::tm_year
        lda     (ptr1),y
        cmp     #100            ; Year since 1900 < 100?
        bcc     :+              ; Yes, leave alone
        sbc     #100            ; Move 20xx to 19xx
:       plp                     ; Restore month msb
        rol
        sta     DATELO+1

        ; Return success
        jmp     return0

        ; Load errno code
enosys: lda     #ENOSYS
        bne     errno           ; Always

        ; Load errno code
erange: lda     #ERANGE

        ; Set __errno
errno:  jmp     __directerrno