]> git.sur5r.net Git - cc65/blob - libsrc/c128/systime.s
remove superfluous ".code" line
[cc65] / libsrc / c128 / 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        "c128.inc"
14
15         .constructor    initsystime
16         .importzp       tmp1, tmp2
17
18
19 ;----------------------------------------------------------------------------
20 .code
21
22 .proc   __systime
23
24         lda     CIA1_TODHR
25         bpl     AM
26         and     #%01111111
27         sed
28         clc
29         adc     #$12
30         cld
31 AM:     jsr     BCD2dec
32         sta     TM + tm::tm_hour
33         lda     CIA1_TODMIN
34         jsr     BCD2dec
35         sta     TM + tm::tm_min
36         lda     CIA1_TODSEC
37         jsr     BCD2dec
38         sta     TM + tm::tm_sec
39         lda     CIA1_TOD10              ; Dummy read to unfreeze
40         lda     #<TM
41         ldx     #>TM
42         jmp     _mktime
43
44 ; dec = (((BCD>>4)*10) + (BCD&0xf))
45 BCD2dec:tax
46         and     #%00001111
47         sta     tmp1
48         txa
49         and     #%11110000      ; *16
50         lsr                     ; *8
51         sta     tmp2
52         lsr
53         lsr                     ; *2
54         adc     tmp2            ; = *10
55         adc     tmp1
56         rts
57
58 .endproc
59
60 ;----------------------------------------------------------------------------
61 ; Constructor that writes to the 1/10 sec register of the TOD to kick it
62 ; into action. If this is not done, the clock hangs. We will read the register
63 ; and write it again, ignoring a possible change in between.
64
65 .proc   initsystime
66
67         lda     CIA1_TOD10
68         sta     CIA1_TOD10
69         rts
70
71 .endproc
72
73
74 ;----------------------------------------------------------------------------
75 ; TM struct with date set to 1970-01-01
76 .data
77
78 TM:     .word           0       ; tm_sec
79         .word           0       ; tm_min
80         .word           0       ; tm_hour
81         .word           1       ; tm_mday
82         .word           0       ; tm_mon
83         .word           70      ; tm_year
84         .word           0       ; tm_wday
85         .word           0       ; tm_yday
86         .word           0       ; tm_isdst
87