]> git.sur5r.net Git - cc65/commitdiff
Systime implementation derived from the cbm610.
authoruz <uz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Thu, 24 Sep 2009 21:09:45 +0000 (21:09 +0000)
committeruz <uz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Thu, 24 Sep 2009 21:09:45 +0000 (21:09 +0000)
git-svn-id: svn://svn.cc65.org/cc65/trunk@4227 b7a2c559-68d2-44c3-8de9-860c34a00d81

libsrc/cbm510/systime.s

index 1d039e80e0ac43fc79e4baa583a12bc17b8894a3..69e60e7e659b05bf2e245f3eff6d9b5257244c75 100644 (file)
@@ -1,5 +1,6 @@
 ;
-; Ullrich von Bassewitz, 12.11.2002
+; Stefan Haubenthal, 2009-07-27
+; Ullrich von Bassewitz, 2009-09-24
 ;
 ; time_t _systime (void);
 ; /* Similar to time(), but:
 ;  */
 ;
 
-       .export         __systime
+        .include        "time.inc"
+        .include        "cbm510.inc"
+       .include        "extzp.inc"
 
-        .importzp       sreg
+       .import         sys_bank, restore_bank
+       .importzp       tmp1, tmp2
 
+
+;----------------------------------------------------------------------------
 .code
 
-.proc   __systime
+.proc  __systime
+
+; Switch to the system bank
+
+       jsr     sys_bank
+
+; Read the clock
+
+       ldy     #CIA::TODHR
+               lda     (cia2),y
+       bpl     AM
+       and     #%01111111
+       sed
+       clc
+       adc     #$12
+       cld
+AM:    jsr     BCD2dec
+       sta     TM + tm::tm_hour
+       ldy     #CIA::TODMIN
+       lda     (cia2),y
+       jsr     BCD2dec
+       sta     TM + tm::tm_min
+       ldy     #CIA::TODSEC
+       lda     (cia2),y
+       jsr     BCD2dec
+       sta     TM + tm::tm_sec
+       ldy     #CIA::TOD10
+       lda     (cia2),y                ; Dummy read to unfreeze
+
+; Restore the bank
+
+       jsr     restore_bank
 
-        lda     #$FF
-        tax
-        sta     sreg
-        sta     sreg+1
-        rts                     ; Return -1
+; Convert to a time
+
+       lda     #<TM
+       ldx     #>TM
+       jmp     _mktime
 
 .endproc
 
+;----------------------------------------------------------------------------
+; dec = (((BCD>>4)*10) + (BCD&0xf))
+
+.proc  BCD2dec
+
+       tax
+       and     #%00001111
+       sta     tmp1
+       txa
+        and     #%11110000      ; *16
+        lsr                     ; *8
+        sta     tmp2
+        lsr
+        lsr                     ; *2
+        adc     tmp2            ; = *10
+        adc     tmp1
+        rts
+
+.endproc
+
+;----------------------------------------------------------------------------
+; TM struct with date set to 1970-01-01
+.data
+
+TM:            .word           0       ; tm_sec
+        .word           0       ; tm_min
+        .word           0       ; tm_hour
+        .word           1       ; tm_mday
+        .word           0       ; tm_mon
+        .word           70      ; tm_year
+        .word           0       ; tm_wday
+        .word           0       ; tm_yday
+        .word           0       ; tm_isdst