]> git.sur5r.net Git - cc65/blob - libsrc/cbm610/gettime.s
30226213d2df163c7afb059bac4179044cefa785
[cc65] / libsrc / cbm610 / gettime.s
1 ;
2 ; Stefan Haubenthal, 2009-07-27
3 ; Ullrich von Bassewitz, 2009-09-24
4 ; Oliver Schmidt, 2018-08-14
5 ;
6 ; int clock_gettime (clockid_t clk_id, struct timespec *tp);
7 ;
8
9         .include        "time.inc"
10         .include        "cbm610.inc"
11         .include        "extzp.inc"
12
13         .import         pushax, pusheax, tosmul0ax, steaxspidx, incsp1
14         .import         sys_bank, restore_bank
15         .importzp       sreg, tmp1, tmp2
16
17
18 ;----------------------------------------------------------------------------
19 .code
20
21 .proc   _clock_gettime
22
23         jsr     sys_bank
24         jsr     pushax
25         jsr     pushax
26
27         ldy     #CIA::TODHR
28         lda     (cia),y
29         bpl     AM
30         and     #%01111111
31         sed
32         clc
33         adc     #$12
34         cld
35 AM:     jsr     BCD2dec
36         sta     TM + tm::tm_hour
37         ldy     #CIA::TODMIN
38         lda     (cia),y
39         jsr     BCD2dec
40         sta     TM + tm::tm_min
41         ldy     #CIA::TODSEC
42         lda     (cia),y
43         jsr     BCD2dec
44         sta     TM + tm::tm_sec
45         lda     #<TM
46         ldx     #>TM
47         jsr     _mktime
48
49         ldy     #timespec::tv_sec
50         jsr     steaxspidx      ; Pops address pushed by 2. pushax
51
52         lda     #<(100 * 1000 * 1000 / $10000)
53         ldx     #>(100 * 1000 * 1000 / $10000)
54         sta     sreg
55         stx     sreg+1
56         lda     #<(100 * 1000 * 1000)
57         ldx     #>(100 * 1000 * 1000)
58         jsr     pusheax
59         ldy     #CIA::TOD10
60         lda     (cia),y
61         ldx     #>$0000
62         jsr     tosmul0ax
63
64         ldy     #timespec::tv_nsec
65         jsr     steaxspidx      ; Pops address pushed by 1. pushax
66
67         jsr     incsp1
68
69         lda     #0
70         tax
71         jmp     restore_bank
72
73 .endproc
74
75 ;----------------------------------------------------------------------------
76 ; dec = (((BCD>>4)*10) + (BCD&0xf))
77
78 .proc   BCD2dec
79
80         tax
81         and     #%00001111
82         sta     tmp1
83         txa
84         and     #%11110000      ; *16
85         lsr                     ; *8
86         sta     tmp2
87         lsr
88         lsr                     ; *2
89         adc     tmp2            ; = *10
90         adc     tmp1
91         rts
92
93 .endproc
94
95 ;----------------------------------------------------------------------------
96 ; TM struct with date set to 1970-01-01
97 .data
98
99 TM:     .word           0       ; tm_sec
100         .word           0       ; tm_min
101         .word           0       ; tm_hour
102         .word           1       ; tm_mday
103         .word           0       ; tm_mon
104         .word           70      ; tm_year
105         .word           0       ; tm_wday
106         .word           0       ; tm_yday
107         .word           0       ; tm_isdst
108