Skip to content

Commit

Permalink
minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
davidly committed Feb 25, 2024
1 parent dfcea4b commit 1b5995d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 31 deletions.
36 changes: 36 additions & 0 deletions djltrace.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,42 @@ class CDJLTrace
{
ShowBinaryData( pData, length, indent, false );
} //PrintBinaryData

static char * RenderNumberWithCommas( long long n, char * pc )
{
char actmp[ 32 ];
long long orig = n;

if ( 0 == n )
{
strcpy( pc, "0" );
return pc;
}
else if ( n < 0 )
n = -n;

pc[ 0 ] = 0;

while ( 0 != n )
{
strcpy( actmp, pc );
if ( n >= 1000 )
sprintf( pc, ",%03lld", n % 1000 );
else
sprintf( pc, "%lld", n );
strcat( pc, actmp );
n /= 1000;
}

if ( orig < 0 )
{
strcpy( actmp, pc );
strcpy( pc, "-" );
strcat( pc, actmp );
}

return pc;
} //RenderNumberWithCommas
}; //CDJLTrace

extern CDJLTrace tracer;
Expand Down
35 changes: 4 additions & 31 deletions ntvao.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -790,33 +790,6 @@ uint64_t invoke_command( char const * pcFile, uint64_t clockrate )

#endif

static void RenderNumber( long long n, char * ac )
{
if ( n < 0 )
{
strcat( ac, "-" );
RenderNumber( -n, ac );
return;
}

if ( n < 1000 )
{
sprintf( ac + strlen( ac ), "%lld", n );
return;
}

RenderNumber( n / 1000, ac );
sprintf( ac + strlen( ac ), ",%03lld", n % 1000 );
return;
} //RenderNumber

static char * RenderNumberWithCommas( long long n, char * ac )
{
ac[ 0 ] = 0;
RenderNumber( n, ac );
return ac;
} //RenderNumberWithCommas

static int ends_with( const char * str, const char * end )
{
size_t len = strlen( str );
Expand Down Expand Up @@ -955,14 +928,14 @@ int main( int argc, char * argv[] )
high_resolution_clock::time_point tDone = high_resolution_clock::now();
uint32_t elapsedMS = (uint32_t) duration_cast<std::chrono::milliseconds>( tDone - tStart ).count();
#endif
printf( "elapsed milliseconds: %16s\n", RenderNumberWithCommas( elapsedMS, ac ) );
printf( "6502 cycles: %25s\n", RenderNumberWithCommas( total_cycles, ac ) );
printf( "elapsed milliseconds: %16s\n", CDJLTrace::RenderNumberWithCommas( elapsedMS, ac ) );
printf( "6502 cycles: %25s\n", CDJLTrace::RenderNumberWithCommas( total_cycles, ac ) );
printf( "clock rate: " );
if ( 0 == clockrate )
{
printf( " %20s\n", "unbounded" );
uint64_t total_ms = total_cycles * 1000 / 1022727;
printf( "ms at 1.022727 Mhz: %18s == ", RenderNumberWithCommas( total_ms, ac ) );
printf( "ms at 1.022727 Mhz: %18s == ", CDJLTrace::RenderNumberWithCommas( total_ms, ac ) );

uint16_t days = (uint16_t) ( total_ms / 1000 / 60 / 60 / 24 );
uint16_t hours = (uint16_t) ( ( total_ms % ( (uint32_t) 1000 * 60 * 60 * 24 ) ) / 1000 / 60 / 60 );
Expand All @@ -972,7 +945,7 @@ int main( int argc, char * argv[] )
printf( "%u days, %u hours, %u minutes, %u seconds, %llu milliseconds\n", days, hours, minutes, seconds, milliseconds );
}
else
printf( " %20s Hz\n", RenderNumberWithCommas( clockrate, ac ) );
printf( " %20s Hz\n", CDJLTrace::RenderNumberWithCommas( clockrate, ac ) );
}
}
catch ( bad_alloc & e )
Expand Down

0 comments on commit 1b5995d

Please sign in to comment.