]> git.sur5r.net Git - cc65/blob - libsrc/apple2/systime.s
Removed (pretty inconsistently used) tab chars from source code base.
[cc65] / libsrc / apple2 / systime.s
1 ;
2 ; Oliver Schmidt, 22.08.2006
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        "zeropage.inc"
14         .include        "mli.inc"
15
16 __systime:
17         ; Update time
18         lda     #GET_TIME_CALL
19         ldx     #GET_TIME_COUNT
20         jsr     callmli
21         bcs     err
22
23         lda     DATELO+1
24         lsr
25         php                     ; Save month msb
26         cmp     #70             ; Year < 70?
27         bcs     :+              ; No, leave alone
28         adc     #100            ; Move 19xx to 20xx
29 :       sta     TM + tm::tm_year
30         lda     DATELO
31         tax                     ; Save day
32         plp                     ; Restore month msb
33         ror
34         lsr
35         lsr
36         lsr
37         lsr
38         beq     err             ; [1..12] allows for validity check
39         tay
40         dey                     ; Move [1..12] to [0..11]
41         sty     TM + tm::tm_mon
42         txa                     ; Restore day
43         and     #%00011111
44         sta     TM + tm::tm_mday
45
46         lda     TIMELO+1
47         sta     TM + tm::tm_hour
48         lda     TIMELO
49         sta     TM + tm::tm_min
50
51         lda     #<TM
52         ldx     #>TM
53         jmp     _mktime
54
55 err:    lda     #$FF
56         tax
57         sta     sreg
58         sta     sreg+1
59         rts                     ; Return -1
60
61         .bss
62
63 TM:     .tag    tm