Skip to content

Commit

Permalink
hook ^c int on DOS + show build info on DOS
Browse files Browse the repository at this point in the history
  • Loading branch information
davidly committed Oct 18, 2023
1 parent 6b11338 commit 9271bc6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
20 changes: 18 additions & 2 deletions djl_con.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@

#include <conio.h>
#include <graph.h>
#include <dos.h>

class ConsoleConfiguration
{
private:
bool outputEstablished;
void (__interrupt __far * prev_int_23)();
static void __interrupt __far controlc_routine() {}

public:
ConsoleConfiguration() : outputEstablished( false ) {}
ConsoleConfiguration() : outputEstablished( false ), prev_int_23( 0 ) {}
~ConsoleConfiguration() {}

void EstablishConsoleOutput( int16_t width = 80, int16_t height = 24 )
Expand All @@ -20,13 +24,25 @@ class ConsoleConfiguration

outputEstablished = true;
_setvideomode( 3 ); // 80x25 color text

// hook the ^C interrupt so the default handler doesn't terminate the app

prev_int_23 = _dos_getvect( 0x23 );
_dos_setvect( 0x23, controlc_routine );
} //EstablishConsoleOutput

static int portable_kbhit() { return kbhit(); }
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 RestoreConsole( bool clearScreen = true )
{
if ( 0 != prev_int_23 )
{
_dos_setvect( 0x23, prev_int_23 );
prev_int_23 = 0;
}
} //RestoreConsole
bool IsOutputEstablished() { return outputEstablished; }
};

Expand Down
14 changes: 13 additions & 1 deletion djl_os.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,10 @@ inline const char * target_platform()
return "amd64";
#elif defined( _M_ARM64 ) // msft on Windows
return "arm64";
#elif defined( _WIN32 ) // msft on Windows 32-bit
#elif defined( _WIN32 ) // msft on Windows 32-bit
return "x86";
#elif defined( _M_IX86 ) // WATCOM for 8086
return "8086";
#else
return "(other)";
#endif
Expand All @@ -214,6 +216,8 @@ inline const char * compiler_used()
return acver;
#elif defined( __clang__ )
return "clang";
#elif defined( WATCOM )
return "watcom";
#else
return "unknown";
#endif
Expand All @@ -227,6 +231,8 @@ inline const char * build_platform()
return "linux";
#elif defined( _WIN32 )
return "windows";
#elif defined( WATCOM )
return "windows";
#else
return "unknown";
#endif
Expand Down Expand Up @@ -257,9 +263,15 @@ inline const char * build_string()

inline long portable_filelen( int descriptor )
{
#ifdef _WIN32
long current = _lseek( descriptor, 0, SEEK_CUR );
long len = _lseek( descriptor, 0, SEEK_END );
_lseek( descriptor, current, SEEK_SET );
#else
long current = lseek( descriptor, 0, SEEK_CUR );
long len = lseek( descriptor, 0, SEEK_END );
lseek( descriptor, current, SEEK_SET );
#endif
return len;
} //portable_filelen

Expand Down

0 comments on commit 9271bc6

Please sign in to comment.