1
0
mirror of https://github.com/cc65/cc65.git synced 2024-10-30 12:28:25 +00:00
cc65/libsrc/c128/systime.s
uz 83be732983 The CIA TOD needs a write to the 1/10 sec register to start. Shortened the
code by using initialized data.


git-svn-id: svn://svn.cc65.org/cc65/trunk@4224 b7a2c559-68d2-44c3-8de9-860c34a00d81
2009-09-24 19:40:36 +00:00

88 lines
1.9 KiB
ArmAsm

;
; Stefan Haubenthal, 27.7.2009
;
; time_t _systime (void);
; /* Similar to time(), but:
; * - Is not ISO C
; * - Does not take the additional pointer
; * - Does not set errno when returning -1
; */
;
.include "time.inc"
.include "c128.inc"
.constructor initsystime
.importzp tmp1, tmp2
;----------------------------------------------------------------------------
.code
.proc __systime
lda CIA1_TODHR
bpl AM
and #%01111111
sed
clc
adc #$12
cld
AM: jsr BCD2dec
sta TM + tm::tm_hour
lda CIA1_TODMIN
jsr BCD2dec
sta TM + tm::tm_min
lda CIA1_TODSEC
jsr BCD2dec
sta TM + tm::tm_sec
lda CIA1_TOD10 ; Dummy read to unfreeze
lda #<TM
ldx #>TM
jmp _mktime
; dec = (((BCD>>4)*10) + (BCD&0xf))
BCD2dec:tax
and #%00001111
sta tmp1
txa
and #%11110000 ; *16
lsr ; *8
sta tmp2
lsr
lsr ; *2
adc tmp2 ; = *10
adc tmp1
rts
.endproc
;----------------------------------------------------------------------------
; Constructor that writes to the 1/10 sec register of the TOD to kick it
; into action. If this is not done, the clock hangs. We will read the register
; and write it again, ignoring a possible change in between.
.proc initsystime
lda CIA1_TOD10
sta CIA1_TOD10
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