]> git.sur5r.net Git - cc65/blob - libsrc/c64/tmcommon.s
Added clock_settime() for some CBMs.
[cc65] / libsrc / c64 / tmcommon.s
1 ;
2 ; Oliver Schmidt, 16.8.2018
3 ;
4 ; Common stuff for the clock routines
5 ;
6
7         .include        "c64.inc"
8         .include        "get_tv.inc"
9
10         .export         TM, load_tenth
11
12         .constructor    inittime
13         .importzp       sreg
14         .import         _get_tv, _get_ostype
15
16
17 ;----------------------------------------------------------------------------
18 .code
19
20 .proc   load_tenth
21
22         lda     #<(100 * 1000 * 1000 / $10000)
23         ldx     #>(100 * 1000 * 1000 / $10000)
24         sta     sreg
25         stx     sreg+1
26         lda     #<(100 * 1000 * 1000)
27         ldx     #>(100 * 1000 * 1000)
28         rts
29
30 .endproc
31
32 ;----------------------------------------------------------------------------
33 ; Constructor that writes to the 1/10 sec register of the TOD to kick it
34 ; into action. If this is not done, the clock hangs. We will read the register
35 ; and write it again, ignoring a possible change in between.
36 .segment "ONCE"
37
38 .proc   inittime
39
40         lda     CIA1_TOD10
41         sta     CIA1_TOD10
42         jsr     _get_tv
43         cmp     #TV::PAL
44         bne     @60Hz
45         jsr     _get_ostype
46         cmp     #$43
47         beq     @60Hz
48         lda     CIA1_CRA
49         ora     #$80
50         sta     CIA1_CRA
51 @60Hz:  rts
52
53 .endproc
54
55 ;----------------------------------------------------------------------------
56 ; TM struct with date set to 1970-01-01
57 .data
58
59 TM:     .word           0       ; tm_sec
60         .word           0       ; tm_min
61         .word           0       ; tm_hour
62         .word           1       ; tm_mday
63         .word           0       ; tm_mon
64         .word           70      ; tm_year
65         .word           0       ; tm_wday
66         .word           0       ; tm_yday
67         .word           0       ; tm_isdst