From 931add050ea929e67a45242fbff758464e8ef3c7 Mon Sep 17 00:00:00 2001 From: uz Date: Mon, 27 Jul 2009 18:44:37 +0000 Subject: [PATCH] Added a systime implementation by Stefan Haubenthal with a few changes. The routine reads the TOD clock of CIA1 on the C64 and C128. Since systime was a dummy routine common for all CBMs before, this change adds an individual dummy routine for all other CBM systems. CBM510/610 do also have a TOD clock, so a similar function as in the C64 could be used ... git-svn-id: svn://svn.cc65.org/cc65/trunk@3974 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- libsrc/c128/Makefile | 1 + libsrc/c128/c128.inc | 8 +++++ libsrc/c128/systime.s | 64 +++++++++++++++++++++++++++++++++++ libsrc/c16/Makefile | 1 + libsrc/{cbm => c16}/systime.s | 0 libsrc/c64/Makefile | 1 + libsrc/c64/c64.inc | 8 +++++ libsrc/c64/systime.s | 64 +++++++++++++++++++++++++++++++++++ libsrc/cbm/Makefile | 1 - libsrc/cbm510/Makefile | 1 + libsrc/cbm510/systime.s | 28 +++++++++++++++ libsrc/cbm610/Makefile | 1 + libsrc/cbm610/systime.s | 28 +++++++++++++++ libsrc/plus4/Makefile | 1 + libsrc/plus4/systime.s | 28 +++++++++++++++ 15 files changed, 234 insertions(+), 1 deletion(-) create mode 100644 libsrc/c128/systime.s rename libsrc/{cbm => c16}/systime.s (100%) create mode 100644 libsrc/c64/systime.s create mode 100644 libsrc/cbm510/systime.s create mode 100644 libsrc/cbm610/systime.s create mode 100644 libsrc/plus4/systime.s diff --git a/libsrc/c128/Makefile b/libsrc/c128/Makefile index 87df0f76e..95b739ecd 100644 --- a/libsrc/c128/Makefile +++ b/libsrc/c128/Makefile @@ -63,6 +63,7 @@ OBJS = _scrsize.o \ randomize.o \ revers.o \ slow.o \ + systime.o \ sysuname.o \ tgi_mode_table.o \ toggle_videomode.o diff --git a/libsrc/c128/c128.inc b/libsrc/c128/c128.inc index 65d269868..ffe531b49 100644 --- a/libsrc/c128/c128.inc +++ b/libsrc/c128/c128.inc @@ -171,6 +171,10 @@ CIA1_PRA := $DC00 CIA1_PRB := $DC01 CIA1_DDRA := $DC02 CIA1_DDRB := $DC03 +CIA1_TOD10 := $DC08 +CIA1_TODSEC := $DC09 +CIA1_TODMIN := $DC0A +CIA1_TODHR := $DC0B CIA1_ICR := $DC0D CIA1_CRA := $DC0E CIA1_CRB := $DC0F @@ -180,6 +184,10 @@ CIA2_PRA := $DD00 CIA2_PRB := $DD01 CIA2_DDRA := $DD02 CIA2_DDRB := $DD03 +CIA2_TOD10 := $DD08 +CIA2_TODSEC := $DD09 +CIA2_TODMIN := $DD0A +CIA2_TODHR := $DD0B CIA2_ICR := $DD0D CIA2_CRA := $DD0E CIA2_CRB := $DD0F diff --git a/libsrc/c128/systime.s b/libsrc/c128/systime.s new file mode 100644 index 000000000..eb1950906 --- /dev/null +++ b/libsrc/c128/systime.s @@ -0,0 +1,64 @@ +; +; 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" + + .importzp tmp1, tmp2 + +.code + +; Jan 1st 1970, CIA #1 TOD +.proc __systime + + lda #70 + sta TM + tm::tm_year + lda #1 + sta TM + tm::tm_mday + 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 + 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 + +.bss + +TM: .tag tm diff --git a/libsrc/c16/Makefile b/libsrc/c16/Makefile index a9bffbbf7..f8f4bf017 100644 --- a/libsrc/c16/Makefile +++ b/libsrc/c16/Makefile @@ -57,6 +57,7 @@ OBJS = _scrsize.o \ mainargs.o \ randomize.o \ revers.o \ + systime.o \ sysuname.o #-------------------------------------------------------------------------- diff --git a/libsrc/cbm/systime.s b/libsrc/c16/systime.s similarity index 100% rename from libsrc/cbm/systime.s rename to libsrc/c16/systime.s diff --git a/libsrc/c64/Makefile b/libsrc/c64/Makefile index 90b5c3ebb..7da971384 100644 --- a/libsrc/c64/Makefile +++ b/libsrc/c64/Makefile @@ -62,6 +62,7 @@ OBJS = _scrsize.o \ mcbdefault.o \ randomize.o \ revers.o \ + systime.o \ sysuname.o \ tgi_mode_table.o diff --git a/libsrc/c64/c64.inc b/libsrc/c64/c64.inc index 2e56beed7..715e11d81 100644 --- a/libsrc/c64/c64.inc +++ b/libsrc/c64/c64.inc @@ -164,6 +164,10 @@ CIA1_PRA := $DC00 CIA1_PRB := $DC01 CIA1_DDRA := $DC02 CIA1_DDRB := $DC03 +CIA1_TOD10 := $DC08 +CIA1_TODSEC := $DC09 +CIA1_TODMIN := $DC0A +CIA1_TODHR := $DC0B CIA1_ICR := $DC0D CIA1_CRA := $DC0E CIA1_CRB := $DC0F @@ -173,6 +177,10 @@ CIA2_PRA := $DD00 CIA2_PRB := $DD01 CIA2_DDRA := $DD02 CIA2_DDRB := $DD03 +CIA2_TOD10 := $DD08 +CIA2_TODSEC := $DD09 +CIA2_TODMIN := $DD0A +CIA2_TODHR := $DD0B CIA2_ICR := $DD0D CIA2_CRA := $DD0E CIA2_CRB := $DD0F diff --git a/libsrc/c64/systime.s b/libsrc/c64/systime.s new file mode 100644 index 000000000..6654e8508 --- /dev/null +++ b/libsrc/c64/systime.s @@ -0,0 +1,64 @@ +; +; 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 "c64.inc" + + .importzp tmp1, tmp2 + +.code + +; Jan 1st 1970, CIA #1 TOD +.proc __systime + + lda #70 + sta TM + tm::tm_year + lda #1 + sta TM + tm::tm_mday + 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 + 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 + +.bss + +TM: .tag tm diff --git a/libsrc/cbm/Makefile b/libsrc/cbm/Makefile index daf86d6d7..4fd88a2a9 100644 --- a/libsrc/cbm/Makefile +++ b/libsrc/cbm/Makefile @@ -79,7 +79,6 @@ S_OBJS = c_acptr.o \ scratch.o \ sysremove.o \ sysrename.o \ - systime.o \ wherex.o \ wherey.o \ write.o diff --git a/libsrc/cbm510/Makefile b/libsrc/cbm510/Makefile index cd25dbc75..2d1f36c06 100644 --- a/libsrc/cbm510/Makefile +++ b/libsrc/cbm510/Makefile @@ -72,6 +72,7 @@ OBJS = _scrsize.o \ pokesys.o \ randomize.o \ revers.o \ + systime.o \ sysuname.o \ tgi_mode_table.o diff --git a/libsrc/cbm510/systime.s b/libsrc/cbm510/systime.s new file mode 100644 index 000000000..1d039e80e --- /dev/null +++ b/libsrc/cbm510/systime.s @@ -0,0 +1,28 @@ +; +; Ullrich von Bassewitz, 12.11.2002 +; +; 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 +; */ +; + + .export __systime + + .importzp sreg + +.code + +.proc __systime + + lda #$FF + tax + sta sreg + sta sreg+1 + rts ; Return -1 + +.endproc + + diff --git a/libsrc/cbm610/Makefile b/libsrc/cbm610/Makefile index 578350474..22f516c62 100644 --- a/libsrc/cbm610/Makefile +++ b/libsrc/cbm610/Makefile @@ -65,6 +65,7 @@ OBJS = _scrsize.o \ pokesys.o \ randomize.o \ revers.o \ + systime.o \ sysuname.o #-------------------------------------------------------------------------- diff --git a/libsrc/cbm610/systime.s b/libsrc/cbm610/systime.s new file mode 100644 index 000000000..1d039e80e --- /dev/null +++ b/libsrc/cbm610/systime.s @@ -0,0 +1,28 @@ +; +; Ullrich von Bassewitz, 12.11.2002 +; +; 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 +; */ +; + + .export __systime + + .importzp sreg + +.code + +.proc __systime + + lda #$FF + tax + sta sreg + sta sreg+1 + rts ; Return -1 + +.endproc + + diff --git a/libsrc/plus4/Makefile b/libsrc/plus4/Makefile index 00a63c4d0..e2bedca37 100644 --- a/libsrc/plus4/Makefile +++ b/libsrc/plus4/Makefile @@ -78,6 +78,7 @@ OBJS = _scrsize.o \ mainargs.o \ randomize.o \ revers.o \ + systime.o \ sysuname.o \ tgi_mode_table.o diff --git a/libsrc/plus4/systime.s b/libsrc/plus4/systime.s new file mode 100644 index 000000000..1d039e80e --- /dev/null +++ b/libsrc/plus4/systime.s @@ -0,0 +1,28 @@ +; +; Ullrich von Bassewitz, 12.11.2002 +; +; 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 +; */ +; + + .export __systime + + .importzp sreg + +.code + +.proc __systime + + lda #$FF + tax + sta sreg + sta sreg+1 + rts ; Return -1 + +.endproc + + -- 2.39.5