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