diff -Naur sidplay-libs-2.1.1-old/libsidplay/include/sidplay/sidplay2.h sidplay-libs-2.1.1/libsidplay/include/sidplay/sidplay2.h --- sidplay-libs-2.1.1-old/libsidplay/include/sidplay/sidplay2.h 2004-06-14 22:08:04.000000000 +0200 +++ sidplay-libs-2.1.1/libsidplay/include/sidplay/sidplay2.h 2008-11-23 19:13:58.000000000 +0100 @@ -50,6 +50,7 @@ sid2_player_t state (void) const; void stop (void); void debug (bool enable, FILE *out); + int cia1_last_ta (void) const; // Timer functions with respect to resolution returned by timebase uint_least32_t timebase (void) const; diff -Naur sidplay-libs-2.1.1-old/libsidplay/src/mos6526/mos6526.cpp sidplay-libs-2.1.1/libsidplay/src/mos6526/mos6526.cpp --- sidplay-libs-2.1.1-old/libsidplay/src/mos6526/mos6526.cpp 2004-06-14 22:08:02.000000000 +0200 +++ sidplay-libs-2.1.1/libsidplay/src/mos6526/mos6526.cpp 2008-11-30 15:26:45.000000000 +0100 @@ -172,6 +172,7 @@ { ta = ta_latch = 0xffff; tb = tb_latch = 0xffff; + last_ta = 0; ta_underflow = tb_underflow = false; cra = crb = sdr_out = 0; sdr_count = 0; @@ -320,9 +321,19 @@ case PRB: case DDRB: portB (); break; - case TAL: endian_16lo8 (ta_latch, data); break; + case TAL: + endian_16lo8 (ta_latch, data); + // store last timer A value to calculate song speed + if (ta_latch != 0) { + last_ta = ta_latch; + } + break; case TAH: endian_16hi8 (ta_latch, data); + // store last timer A value to calculate song speed + if (ta_latch != 0) { + last_ta = ta_latch; + } if (!(cra & 0x01)) // Reload timer if stopped ta = ta_latch; break; diff -Naur sidplay-libs-2.1.1-old/libsidplay/src/mos6526/mos6526.h sidplay-libs-2.1.1/libsidplay/src/mos6526/mos6526.h --- sidplay-libs-2.1.1-old/libsidplay/src/mos6526/mos6526.h 2004-06-14 22:08:02.000000000 +0200 +++ sidplay-libs-2.1.1/libsidplay/src/mos6526/mos6526.h 2008-11-22 19:33:06.000000000 +0100 @@ -92,6 +92,10 @@ private: static const char *credit; +public: + // The last timer A value to calculate song speed. + int last_ta; + protected: uint8_t regs[0x10]; bool cnt_high; diff -Naur sidplay-libs-2.1.1-old/libsidplay/src/player.h sidplay-libs-2.1.1/libsidplay/src/player.h --- sidplay-libs-2.1.1-old/libsidplay/src/player.h 2004-06-14 22:08:02.000000000 +0200 +++ sidplay-libs-2.1.1/libsidplay/src/player.h 2008-11-30 16:02:04.000000000 +0100 @@ -455,6 +455,9 @@ void debug (bool enable, FILE *out) { cpu->debug (enable, out); } const char *error (void) const { return m_errorString; } + int cia1_last_ta (void) { if (m_info.environment == sid2_envR) return cia.last_ta; + else return sid6526.last_ta; + } }; diff -Naur sidplay-libs-2.1.1-old/libsidplay/src/sid6526/sid6526.cpp sidplay-libs-2.1.1/libsidplay/src/sid6526/sid6526.cpp --- sidplay-libs-2.1.1-old/libsidplay/src/sid6526/sid6526.cpp 2004-06-14 22:08:02.000000000 +0200 +++ sidplay-libs-2.1.1/libsidplay/src/sid6526/sid6526.cpp 2008-11-30 16:04:37.000000000 +0100 @@ -80,6 +80,7 @@ { locked = false; ta = ta_latch = m_count; + last_ta = 0; cra = 0; // Initialise random number generator if (seed) @@ -131,9 +132,19 @@ switch (addr) { - case 0x4: endian_16lo8 (ta_latch, data); break; + case 0x4: + endian_16lo8 (ta_latch, data); + // store last timer A value to calculate song speed + if (ta_latch != 0) { + last_ta = ta_latch; + } + break; case 0x5: endian_16hi8 (ta_latch, data); + // store last timer A value to calculate song speed + if (ta_latch != 0) { + last_ta = ta_latch; + } if (!(cra & 0x01)) // Reload timer if stopped ta = ta_latch; break; diff -Naur sidplay-libs-2.1.1-old/libsidplay/src/sid6526/sid6526.h sidplay-libs-2.1.1/libsidplay/src/sid6526/sid6526.h --- sidplay-libs-2.1.1-old/libsidplay/src/sid6526/sid6526.h 2004-06-14 22:08:02.000000000 +0200 +++ sidplay-libs-2.1.1/libsidplay/src/sid6526/sid6526.h 2008-11-30 16:05:38.000000000 +0100 @@ -43,6 +43,9 @@ class SID6526: public component { +public: + // The last timer A value to calculate song speed. + int last_ta; private: static const char * const credit; diff -Naur sidplay-libs-2.1.1-old/libsidplay/src/sidplay2.cpp sidplay-libs-2.1.1/libsidplay/src/sidplay2.cpp --- sidplay-libs-2.1.1-old/libsidplay/src/sidplay2.cpp 2004-06-14 22:08:02.000000000 +0200 +++ sidplay-libs-2.1.1/libsidplay/src/sidplay2.cpp 2008-11-23 19:23:56.000000000 +0100 @@ -146,3 +146,6 @@ uint_least32_t sidplay2::timebase (void) const { return SID2_TIME_BASE; } + +int sidplay2::cia1_last_ta(void) const +{ return sidplayer.cia1_last_ta (); }