]> git.sur5r.net Git - cc65/blob - libsrc/c64/systime.s
Replaced whole bunch for Makefiles with a single generic Makefile.
[cc65] / libsrc / c64 / systime.s
1 ;
2 ; Stefan Haubenthal, 27.7.2009
3 ;
4 ; time_t _systime (void);
5 ; /* Similar to time(), but:
6 ;  *   - Is not ISO C
7 ;  *   - Does not take the additional pointer
8 ;  *   - Does not set errno when returning -1
9 ;  */
10 ;
11
12         .include        "time.inc"
13         .include        "c64.inc"
14         .include        "get_tv.inc"
15
16         .constructor    initsystime
17         .importzp       tmp1, tmp2
18         .import         _get_tv, _get_ostype
19
20
21 ;----------------------------------------------------------------------------
22 .code
23
24 .proc   __systime
25
26         lda     CIA1_TODHR
27         bpl     AM
28         and     #%01111111
29         sed
30         clc
31         adc     #$12
32         cld
33 AM:     jsr     BCD2dec
34         sta     TM + tm::tm_hour
35         lda     CIA1_TODMIN
36         jsr     BCD2dec
37         sta     TM + tm::tm_min
38         lda     CIA1_TODSEC
39         jsr     BCD2dec
40         sta     TM + tm::tm_sec
41         lda     CIA1_TOD10              ; Dummy read to unfreeze
42         lda     #<TM
43         ldx     #>TM
44         jmp     _mktime
45
46 ; dec = (((BCD>>4)*10) + (BCD&0xf))
47 BCD2dec:tax
48         and     #%00001111
49         sta     tmp1
50         txa
51         and     #%11110000      ; *16
52         lsr                     ; *8
53         sta     tmp2
54         lsr
55         lsr                     ; *2
56         adc     tmp2            ; = *10
57         adc     tmp1
58         rts
59
60 .endproc
61
62 ;----------------------------------------------------------------------------
63 ; Constructor that writes to the 1/10 sec register of the TOD to kick it
64 ; into action. If this is not done, the clock hangs. We will read the register
65 ; and write it again, ignoring a possible change in between.
66
67 .proc   initsystime
68
69         lda     CIA1_TOD10
70         sta     CIA1_TOD10
71         jsr     _get_tv
72         cmp     #TV::PAL
73         bne     @60Hz
74         jsr     _get_ostype
75         cmp     #$43
76         beq     @60Hz
77         lda     CIA1_CRA
78         ora     #$80
79         sta     CIA1_CRA
80 @60Hz:  rts
81
82 .endproc
83
84
85 ;----------------------------------------------------------------------------
86 ; TM struct with date set to 1970-01-01
87 .data
88
89 TM:     .word           0       ; tm_sec
90         .word           0       ; tm_min
91         .word           0       ; tm_hour
92         .word           1       ; tm_mday
93         .word           0       ; tm_mon
94         .word           70      ; tm_year
95         .word           0       ; tm_wday
96         .word           0       ; tm_yday
97         .word           0       ; tm_isdst
98