Skip to content

Commit

Permalink
minor cleanup + binary data trace fix
Browse files Browse the repository at this point in the history
  • Loading branch information
davidly committed Feb 14, 2024
1 parent c77dc78 commit cc017b7
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 13 deletions.
26 changes: 22 additions & 4 deletions djl_con.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,27 @@ class ConsoleConfiguration
static int throttled_kbhit() { return kbhit(); }
static int portable_getch() { return getch(); }
static char * portable_gets_s( char * buf, size_t bufsize ) { return gets( buf ); }
void RestoreConsole( bool clearScreen = true )

void RestoreConsoleInput()
{
if ( 0 != prev_int_23 )
{
_dos_setvect( 0x23, prev_int_23 );
prev_int_23 = 0;
}
} //RestoreConsoleInput

void RestoreConsoleOutput( bool clearScreen = true )
{
outputEstablished = false;
} //RestoreConsoleOutput

void RestoreConsole( bool clearScreen = true )
{
RestoreConsoleInput();
RestoreConsoleOutput( clearScreen );
} //RestoreConsole

bool IsOutputEstablished() { return outputEstablished; }
};

Expand Down Expand Up @@ -383,6 +396,7 @@ class ConsoleConfiguration

void EstablishConsoleOutput( int16_t width = 80, int16_t height = 24 )
{
tracer.Trace( " EstablishConsoleOutput width %u height %u, outputEstablished %d\n", width, height, outputEstablished );
if ( outputEstablished )
return;

Expand Down Expand Up @@ -470,10 +484,8 @@ class ConsoleConfiguration
}
} //RestoreConsoleInput

void RestoreConsole( bool clearScreen = true )
void RestoreConsoleOutput( bool clearScreen = true )
{
RestoreConsoleInput();

if ( outputEstablished )
{
#ifndef _WIN32
Expand Down Expand Up @@ -502,6 +514,12 @@ class ConsoleConfiguration

outputEstablished = false;
}
} //RestoreConsoleOutput

void RestoreConsole( bool clearScreen = true )
{
RestoreConsoleInput();
RestoreConsoleOutput( clearScreen );
} //RestoreConsole

void SendClsSequence()
Expand Down
10 changes: 10 additions & 0 deletions djl_cycle.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,19 @@

#include <time.h>
using namespace std;

#ifndef WATCOM
using namespace std::chrono;
#endif

class CPUCycleDelay
{
#ifdef WATCOM // no implementation on DOS
public:
CPUCycleDelay( uint64_t clockRate ) {}
void Reset() {}
void Delay( uint64_t cycles_total ) {}
#else
private:
high_resolution_clock::time_point start_execution;
uint64_t clock_rate;
Expand Down Expand Up @@ -48,4 +57,5 @@ class CPUCycleDelay
} while ( true );
}
} //Delay
#endif //WATCOM
}; //CPUCycleDelay
5 changes: 4 additions & 1 deletion djltrace.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ class CDJLTrace
int64_t toread = ( ( offset + bytesPerRow ) > beyond ) ? ( length % bytesPerRow ) : bytesPerRow;

memcpy( buf, pData + offset, toread );

uint64_t extraSpace = 2;

for ( int64_t o = offset; o < cap; o++ )
{
Expand All @@ -93,10 +95,11 @@ class CDJLTrace
{
*pline++ = ':';
*pline++ = ' ';
extraSpace = 0;
}
}

uint64_t spaceNeeded = ( bytesPerRow - ( cap - offset ) ) * 3;
uint64_t spaceNeeded = extraSpace + ( ( bytesPerRow - ( cap - offset ) ) * 3 );

for ( uint64_t sp = 0; sp < ( 1 + spaceNeeded ); sp++ )
*pline++ = ' ';
Expand Down
4 changes: 2 additions & 2 deletions mr.bat
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
rem with RSS
cl /W4 /wd4706 /wd4996 /nologo ntvcm.cxx x80.cxx /DNDEBUG /DNTVCM_RSS_SUPPORT /openmp /I. /Oti2 /Ob3 /Qpar /Fa /FAsc /EHac /Zi /jumptablerdata /D_AMD64_ /link user32.lib /OPT:REF
cl /W4 /wd4706 /wd4996 /nologo ntvcm.cxx x80.cxx /DNDEBUG /DNTVCM_RSS_SUPPORT /openmp /I. /GS- /GL /Oti2 /Ob3 /Qpar /Fa /FAsc /EHac /Zi /jumptablerdata /D_AMD64_ /link user32.lib /OPT:REF

rem without RSS
rem cl /W4 /wd4706 /wd4996 /nologo ntvcm.cxx x80.cxx /DNDEBUG /I. /Oti2 /Ob3 /Qpar /Fa /FAsc /EHac /Zi /jumptablerdata /D_AMD64_ /link user32.lib ntdll.lib /OPT:REF
rem cl /W4 /wd4706 /wd4996 /nologo ntvcm.cxx x80.cxx /DNDEBUG /I. /GS- /GL /Oti2 /Ob3 /Qpar /Fa /FAsc /EHac /Zi /jumptablerdata /D_AMD64_ /link user32.lib ntdll.lib /OPT:REF

8 changes: 2 additions & 6 deletions ntvcm.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@
#include <djl_os.hxx>
#include <djltrace.hxx>
#include <djl_con.hxx>

#ifndef WATCOM
#include <djl_cycle.hxx>
#endif

// On non-Windows platforms djl_rssrdr.hxx has a dependency on:
// httplib.h from https://github.com/yhirose/cpp-httplib
Expand Down Expand Up @@ -2971,10 +2968,11 @@ int main( int argc, char * argv[] )
if ( force80x24 )
g_consoleConfig.EstablishConsoleOutput( 80, 24 );

CPUCycleDelay delay( clockrate );

#ifdef WATCOM
uint32_t tStart = DosTimeInMS();
#else
CPUCycleDelay delay( clockrate );
high_resolution_clock::time_point tStart = high_resolution_clock::now();
#endif

Expand All @@ -2986,9 +2984,7 @@ int main( int argc, char * argv[] )
if ( g_haltExecuted )
break;

#ifndef WATCOM
delay.Delay( total_cycles );
#endif
} while ( true );

#ifdef WATCOM
Expand Down

0 comments on commit cc017b7

Please sign in to comment.