]> git.sur5r.net Git - cc65/blob - libsrc/cbm510/systime.s
Removed stray /t char.
[cc65] / libsrc / cbm510 / systime.s
1 ;
2 ; Stefan Haubenthal, 2009-07-27
3 ; Ullrich von Bassewitz, 2009-09-24
4 ;
5 ; time_t _systime (void);
6 ; /* Similar to time(), but:
7 ; **   - Is not ISO C
8 ; **   - Does not take the additional pointer
9 ; **   - Does not set errno when returning -1
10 ; */
11 ;
12
13         .include        "time.inc"
14         .include        "cbm510.inc"
15         .include        "extzp.inc"
16
17         .import         sys_bank, restore_bank
18         .importzp       tmp1, tmp2
19
20
21 ;----------------------------------------------------------------------------
22 .code
23
24 .proc   __systime
25
26 ; Switch to the system bank
27
28         jsr     sys_bank
29
30 ; Read the clock
31
32         ldy     #CIA::TODHR
33         lda     (cia2),y
34         bpl     AM
35         and     #%01111111
36         sed
37         clc
38         adc     #$12
39         cld
40 AM:     jsr     BCD2dec
41         sta     TM + tm::tm_hour
42         ldy     #CIA::TODMIN
43         lda     (cia2),y
44         jsr     BCD2dec
45         sta     TM + tm::tm_min
46         ldy     #CIA::TODSEC
47         lda     (cia2),y
48         jsr     BCD2dec
49         sta     TM + tm::tm_sec
50         ldy     #CIA::TOD10
51         lda     (cia2),y                ; Dummy read to unfreeze
52
53 ; Restore the bank
54
55         jsr     restore_bank
56
57 ; Convert to a time
58
59         lda     #<TM
60         ldx     #>TM
61         jmp     _mktime
62
63 .endproc
64
65 ;----------------------------------------------------------------------------
66 ; dec = (((BCD>>4)*10) + (BCD&0xf))
67
68 .proc   BCD2dec
69
70         tax
71         and     #%00001111
72         sta     tmp1
73         txa
74         and     #%11110000      ; *16
75         lsr                     ; *8
76         sta     tmp2
77         lsr
78         lsr                     ; *2
79         adc     tmp2            ; = *10
80         adc     tmp1
81         rts
82
83 .endproc
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