diff options
Diffstat (limited to 'src/emu/attotime.cpp')
-rw-r--r-- | src/emu/attotime.cpp | 43 |
1 files changed, 30 insertions, 13 deletions
diff --git a/src/emu/attotime.cpp b/src/emu/attotime.cpp index bda9a5b7a24..030c3193551 100644 --- a/src/emu/attotime.cpp +++ b/src/emu/attotime.cpp @@ -2,7 +2,7 @@ // copyright-holders:Aaron Giles /*************************************************************************** - attotime.c + attotime.cpp Support functions for working with attotime data. @@ -40,17 +40,17 @@ attotime &attotime::operator*=(u32 factor) // split attoseconds into upper and lower halves which fit into 32 bits u32 attolo; - u32 attohi = divu_64x32_rem(m_attoseconds, ATTOSECONDS_PER_SECOND_SQRT, &attolo); + u32 attohi = divu_64x32_rem(m_attoseconds, ATTOSECONDS_PER_SECOND_SQRT, attolo); // scale the lower half, then split into high/low parts u64 temp = mulu_32x32(attolo, factor); u32 reslo; - temp = divu_64x32_rem(temp, ATTOSECONDS_PER_SECOND_SQRT, &reslo); + temp = divu_64x32_rem(temp, ATTOSECONDS_PER_SECOND_SQRT, reslo); // scale the upper half, then split into high/low parts temp += mulu_32x32(attohi, factor); u32 reshi; - temp = divu_64x32_rem(temp, ATTOSECONDS_PER_SECOND_SQRT, &reshi); + temp = divu_64x32_rem(temp, ATTOSECONDS_PER_SECOND_SQRT, reshi); // scale the seconds temp += mulu_32x32(m_seconds, factor); @@ -80,19 +80,19 @@ attotime &attotime::operator/=(u32 factor) // split attoseconds into upper and lower halves which fit into 32 bits u32 attolo; - u32 attohi = divu_64x32_rem(m_attoseconds, ATTOSECONDS_PER_SECOND_SQRT, &attolo); + u32 attohi = divu_64x32_rem(m_attoseconds, ATTOSECONDS_PER_SECOND_SQRT, attolo); // divide the seconds and get the remainder u32 remainder; - m_seconds = divu_64x32_rem(m_seconds, factor, &remainder); + m_seconds = divu_64x32_rem(m_seconds, factor, remainder); // combine the upper half of attoseconds with the remainder and divide that u64 temp = s64(attohi) + mulu_32x32(remainder, ATTOSECONDS_PER_SECOND_SQRT); - u32 reshi = divu_64x32_rem(temp, factor, &remainder); + u32 reshi = divu_64x32_rem(temp, factor, remainder); // combine the lower half of attoseconds with the remainder and divide that temp = attolo + mulu_32x32(remainder, ATTOSECONDS_PER_SECOND_SQRT); - u32 reslo = divu_64x32_rem(temp, factor, &remainder); + u32 reslo = divu_64x32_rem(temp, factor, remainder); // round based on the remainder m_attoseconds = (attoseconds_t)reslo + mulu_32x32(reshi, ATTOSECONDS_PER_SECOND_SQRT); @@ -119,11 +119,11 @@ const char *attotime::as_string(int precision) const // special case: never if (*this == never) - sprintf(buffer, "%-*s", precision, "(never)"); + snprintf(buffer, 30, "%-*s", precision, "(never)"); // case 1: we want no precision; seconds only else if (precision == 0) - sprintf(buffer, "%d", m_seconds); + snprintf(buffer, 30, "%d", m_seconds); // case 2: we want 9 or fewer digits of precision else if (precision <= 9) @@ -135,21 +135,38 @@ const char *attotime::as_string(int precision) const upper /= 10; temp++; } - sprintf(buffer, "%d.%0*d", m_seconds, precision, upper); + snprintf(buffer, 30, "%d.%0*d", m_seconds, precision, upper); } // case 3: more than 9 digits of precision else { u32 lower; - u32 upper = divu_64x32_rem(m_attoseconds, ATTOSECONDS_PER_SECOND_SQRT, &lower); + u32 upper = divu_64x32_rem(m_attoseconds, ATTOSECONDS_PER_SECOND_SQRT, lower); int temp = precision; while (temp < 18) { lower /= 10; temp++; } - sprintf(buffer, "%d.%09d%0*d", m_seconds, upper, precision - 9, lower); + snprintf(buffer, 30, "%d.%09d%0*d", m_seconds, upper, precision - 9, lower); } return buffer; } + +//------------------------------------------------- +// to_string - return a human-readable string +// describing an attotime for use in logs +//------------------------------------------------- + +std::string attotime::to_string() const +{ + attotime t = *this; + const char *sign = ""; + if(t.seconds() < 0) { + t = attotime::zero-t; + sign = "-"; + } + int nsec = t.attoseconds() / ATTOSECONDS_PER_NANOSECOND; + return util::string_format("%s%04d.%03d,%03d,%03d", sign, int(t.seconds()), nsec/1000000, (nsec/1000)%1000, nsec % 1000); +} |