diff --git a/AppleWinExpress2008.vcproj b/AppleWinExpress2008.vcproj
index 0b147836..c5dc60dc 100644
--- a/AppleWinExpress2008.vcproj
+++ b/AppleWinExpress2008.vcproj
@@ -294,6 +294,14 @@
RelativePath=".\source\StdAfx.h"
>
+
+
+
+
diff --git a/AppleWinExpress2019.vcxproj b/AppleWinExpress2019.vcxproj
index 566fbf0e..4269f693 100644
--- a/AppleWinExpress2019.vcxproj
+++ b/AppleWinExpress2019.vcxproj
@@ -111,6 +111,7 @@
+
@@ -214,6 +215,7 @@
Create
Create
+
diff --git a/AppleWinExpress2019.vcxproj.filters b/AppleWinExpress2019.vcxproj.filters
index 629ad823..e025ed4f 100644
--- a/AppleWinExpress2019.vcxproj.filters
+++ b/AppleWinExpress2019.vcxproj.filters
@@ -247,6 +247,9 @@
Source Files\Emulator
+
+ Source Files
+
@@ -567,6 +570,9 @@
Source Files\Emulator
+
+ Source Files
+
diff --git a/source/CPU.cpp b/source/CPU.cpp
index 9e6358c4..9c97a544 100644
--- a/source/CPU.cpp
+++ b/source/CPU.cpp
@@ -339,9 +339,7 @@ static void DebugHddEntrypoint(const USHORT PC)
if (!bOldPCAtC7xx /*&& PC != 0xc70a*/)
{
Count++;
- char szDebug[100];
- sprintf(szDebug, "HDD Entrypoint: $%04X\n", PC);
- OutputDebugString(szDebug);
+ LogOutput("HDD Entrypoint: $%04X\n", PC);
}
bOldPCAtC7xx = true;
diff --git a/source/Core.h b/source/Core.h
index 439c1b22..bfeeb898 100644
--- a/source/Core.h
+++ b/source/Core.h
@@ -2,6 +2,8 @@
#include "Card.h"
#include "Common.h"
+#include "StrFormat.h"
+#include "Log.h"
void LogFileTimeUntilFirstKeyReadReset(void);
void LogFileTimeUntilFirstKeyRead(void);
diff --git a/source/Debugger/Debug.cpp b/source/Debugger/Debug.cpp
index 6e05af2f..ac69d763 100644
--- a/source/Debugger/Debug.cpp
+++ b/source/Debugger/Debug.cpp
@@ -3820,11 +3820,10 @@ Update_t CmdConfigSetDebugDir (int nArgs)
while ((iPathSeparator = sNewPath.find( PATH_SEPARATOR, iPrevSeparator )) != std::string::npos)
{
#if _DEBUG
- char zDebug[128];
- sprintf( zDebug, "Prev: %d\n", iPrevSeparator ); OutputDebugStringA( zDebug );
- sprintf( zDebug, "Next: %d\n", iPathSeparator ); OutputDebugStringA( zDebug );
- sprintf( zDebug, "%s\n", sNewPath.c_str() ); OutputDebugStringA( zDebug );
- sprintf( zDebug, "%*s%s\n", iPathSeparator, "", "^"); OutputDebugStringA( zDebug );
+ LogOutput( "Prev: %" SIZE_T_FMT "\n", iPrevSeparator );
+ LogOutput( "Next: %" SIZE_T_FMT "\n", iPathSeparator );
+ LogOutput( "%s\n", sNewPath.c_str() );
+ LogOutput( "%*s%s\n", int(iPathSeparator), "", "^" );
#endif
std::string sSubDir = sNewPath.substr( iPrevSeparator, iPathSeparator - iPrevSeparator + 1 );
@@ -3843,9 +3842,9 @@ Update_t CmdConfigSetDebugDir (int nArgs)
if (nLastSeperator != std::string::npos)
{
#if _DEBUG
- sprintf( zDebug, "Last: %d\n", nLastSeperator ); OutputDebugStringA( zDebug );
- sprintf( zDebug, "%s\n", g_sCurrentDir.c_str() ); OutputDebugStringA( zDebug );
- sprintf( zDebug, "%*s%s\n", nLastSeperator, "", "^"); OutputDebugStringA( zDebug );
+ LogOutput( "Last: %" SIZE_T_FMT "\n", nLastSeperator );
+ LogOutput( "%s\n", g_sCurrentDir.c_str() );
+ LogOutput( "%*s%s\n", int(nLastSeperator), "", "^" );
#endif
std::string sCurrentDir = g_sCurrentDir.substr( 0, nLastSeperator + 1 ); // Path always has trailing slash so include it
g_sCurrentDir = sCurrentDir;
@@ -4741,7 +4740,7 @@ Update_t CmdNTSC (int nArgs)
public:
static void update( const char *pPrefixText )
{
- TCHAR text[ CONSOLE_WIDTH*2 ] = TEXT("");
+ char text[ CONSOLE_WIDTH*2 ] = "";
size_t len1 = strlen( pPrefixText );
size_t len2 = sPaletteFilePath.size();
@@ -4752,11 +4751,9 @@ Update_t CmdNTSC (int nArgs)
ConsoleBufferPush( pPrefixText ); // TODO: Add a ": " separator
#if _DEBUG
- sprintf( text, "Filename.length.1: %d\n", len1 );
- OutputDebugString( text );
- sprintf( text, "Filename.length.2: %d\n", len2 );
- OutputDebugString( text );
- OutputDebugString( sPaletteFilePath.c_str() );
+ LogOutput( "Filename.length.1: %d\n", len1 );
+ LogOutput( "Filename.length.2: %d\n", len2 );
+ OutputDebugStringA( sPaletteFilePath.c_str() );
#endif
// File path is too long
// TODO: Need to split very long path names
@@ -4892,9 +4889,7 @@ Update_t CmdNTSC (int nArgs)
if (iDstX == 15)
iSrcX = 15;
#if 0 // _DEBUG
- char text[ 128 ];
- sprintf( text, "[ %X ] = [ %X ]\n", iDstX, iSrcX );
- OutputDebugStringA( text );
+ LogOutput( "[ %X ] = [ %X ]\n", iDstX, iSrcX );
#endif
pTmp[ iDstX + 16*iPhase ] = pPhase0[ iSrcX ];
}
@@ -6205,11 +6200,9 @@ int FindSourceLine( WORD nAddress )
// iSourceLine = g_aSourceDebug.find( nAddress );
#if 0 // _DEBUG
{
- TCHAR sText[ CONSOLE_WIDTH ];
for (int i = 0; i < g_vSourceLines.size(); i++ )
{
- wsprintf( sText, "%d: %s\n", i, g_vSourceLines[ i ] );
- OutputDebugString( sText );
+ LogOutput( "%d: %s\n", i, g_vSourceLines[ i ] );
}
}
#endif
@@ -6221,9 +6214,7 @@ int FindSourceLine( WORD nAddress )
iLine = iSource->second;
#if 0 // _DEBUG
- TCHAR sText[ CONSOLE_WIDTH ];
- wsprintf( sText, "%04X -> %d line\n", iAddress, iLine );
- OutputDebugString( sText );
+ LogOutput( "%04X -> %d line\n", iAddress, iLine );
#endif
if (iAddress == nAddress)
diff --git a/source/Debugger/Debugger_Assembler.cpp b/source/Debugger/Debugger_Assembler.cpp
index 6578ec98..a974b66a 100644
--- a/source/Debugger/Debugger_Assembler.cpp
+++ b/source/Debugger/Debugger_Assembler.cpp
@@ -911,10 +911,10 @@ void AssemblerHashOpcodes ()
nMnemonicHash = AssemblerHashMnemonic( pMnemonic );
g_aOpcodesHash[ iOpcode ] = nMnemonicHash;
#if DEBUG_ASSEMBLER
- //OutputDebugString( "" );
- char sText[ 128 ];
- ConsolePrintFormat( sText, "%s : %08X ", pMnemonic, nMnemonicHash );
- // CLC: 002B864
+ //OutputDebugString( "" );
+ char sText[ 128 ];
+ ConsolePrintFormat( sText, "%s : %08X ", pMnemonic, nMnemonicHash );
+ // CLC: 002B864
#endif
}
ConsoleUpdate();
diff --git a/source/Debugger/Debugger_Color.cpp b/source/Debugger/Debugger_Color.cpp
index 3db6714b..42715be4 100644
--- a/source/Debugger/Debugger_Color.cpp
+++ b/source/Debugger/Debugger_Color.cpp
@@ -183,9 +183,9 @@ bool DebuggerSetColor( const int iScheme, const int iColor, const COLORREF nColo
//===========================================================================
static void _SetupColorRamp(const int iPrimary, int & iColor_)
{
- TCHAR sRamp[CONSOLE_WIDTH * 2] = TEXT("");
+ std::string strRamp;
#if DEBUG_COLOR_RAMP
- TCHAR sText[CONSOLE_WIDTH];
+ char sText[CONSOLE_WIDTH];
#endif
bool bR = (iPrimary & 1) ? true : false;
@@ -202,16 +202,15 @@ static void _SetupColorRamp(const int iPrimary, int & iColor_)
DWORD nColor = RGB(nR, nG, nB);
g_aColorPalette[iColor_] = nColor;
#if DEBUG_COLOR_RAMP
- wsprintf(sText, TEXT("RGB(%3d,%3d,%3d), "), nR, nG, nB);
- strcat(sRamp, sText);
+ int len = snprintf_s(sText, _TRUNCATE, "RGB(%3d,%3d,%3d), ", nR, nG, nB);
+ strRamp.append(sText, len);
#endif
iColor_++;
}
#if DEBUG_COLOR_RAMP
- wsprintf(sText, TEXT(" // %d%d%d\n"), bB, bG, bR);
- strcat(sRamp, sText);
- OutputDebugString(sRamp);
- sRamp[0] = 0;
+ int len = snprintf_s(sText, _TRUNCATE, " // %d%d%d\n", bB, bG, bR);
+ strRamp.append(sText, len);
+ OutputDebugStringA(strRamp.c_str());
#endif
}
#endif // _DEBUG
diff --git a/source/Debugger/Debugger_Disassembler.cpp b/source/Debugger/Debugger_Disassembler.cpp
index 6c8e1298..3ea1983a 100644
--- a/source/Debugger/Debugger_Disassembler.cpp
+++ b/source/Debugger/Debugger_Disassembler.cpp
@@ -733,9 +733,7 @@ void DisasmCalcTopFromCurAddress(bool bUpdateTop)
// .20 Fixed: DisasmCalcTopFromCurAddress()
//if ((eMode >= AM_1) && (eMode <= AM_3))
#if 0 // _DEBUG
- TCHAR sText[CONSOLE_WIDTH];
- wsprintf(sText, "%04X : %d bytes\n", iAddress, nOpbytes);
- OutputDebugString(sText);
+ LogOutput("%04X : %d bytes\n", iAddress, nOpbytes);
#endif
iAddress += nOpbytes;
}
diff --git a/source/Disk.cpp b/source/Disk.cpp
index ea0f88b8..c8b43396 100644
--- a/source/Disk.cpp
+++ b/source/Disk.cpp
@@ -1449,15 +1449,13 @@ void Disk2InterfaceCard::DumpTrackWOZ(FloppyDisk floppy) // pass a copy of m_flo
floppy.m_bitMask = 1 << remainder;
bool newLine = true;
- TCHAR str[20];
while (1)
{
if (newLine)
{
newLine = false;
- StringCbPrintf(str, sizeof(str), "%04X:", floppy.m_bitOffset & 0xffff);
- OutputDebugString(str);
+ LogOutput("%04X:", floppy.m_bitOffset & 0xffff);
}
BYTE n = floppy.m_trackimage[floppy.m_byte];
@@ -1483,9 +1481,8 @@ void Disk2InterfaceCard::DumpTrackWOZ(FloppyDisk floppy) // pass a copy of m_flo
nibbleCount++;
char syncBits = zeroCount <= 9 ? '0'+zeroCount : '+';
- if (zeroCount == 0) StringCbPrintf(str, sizeof(str), " %02X", shiftReg);
- else StringCbPrintf(str, sizeof(str), "(%c)%02X", syncBits, shiftReg);
- OutputDebugString(str);
+ if (zeroCount == 0) LogOutput(" %02X", shiftReg);
+ else LogOutput("(%c)%02X", syncBits, shiftReg);
formatTrack.DecodeLatchNibbleRead(shiftReg);
@@ -1509,15 +1506,13 @@ void Disk2InterfaceCard::DumpTrackWOZ(FloppyDisk floppy) // pass a copy of m_flo
if (zeroCount)
{
char syncBits = zeroCount <= 9 ? '0'+zeroCount : '+';
- StringCbPrintf(str, sizeof(str), "(%c)", syncBits);
- OutputDebugString(str);
+ LogOutput("(%c)", syncBits);
}
// Output any partial nibble
if (shiftReg)
{
- StringCbPrintf(str, sizeof(str), "%02X/Partial Nibble", shiftReg);
- OutputDebugString(str);
+ LogOutput("%02X/Partial Nibble", shiftReg);
}
// Output any remaining "read D5AAxx detected"
diff --git a/source/Log.cpp b/source/Log.cpp
index 652a0395..cd94f2c8 100644
--- a/source/Log.cpp
+++ b/source/Log.cpp
@@ -29,6 +29,9 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#include "StdAfx.h"
#include "Log.h"
+
+#include
+
FILE* g_fh = NULL;
#ifdef _MSC_VER
@@ -42,6 +45,20 @@ FILE* g_fh = NULL;
//---------------------------------------------------------------------------
+inline std::string GetTimeStamp()
+{
+ time_t ltime;
+ time(<ime);
+#ifdef _MSC_VER
+ char ct[32];
+ ctime_s(ct, sizeof(ct), <ime);
+#else
+ char ctbuf[32];
+ const char* ct = ctime_r(<ime, ctbuf);
+#endif
+ return std::string(ct, 24);
+}
+
void LogInit(void)
{
if (g_fh)
@@ -55,10 +72,8 @@ void LogInit(void)
}
setvbuf(g_fh, NULL, _IONBF, 0); // No buffering (so implicit fflush after every fprintf)
- CHAR aDateStr[80], aTimeStr[80];
- GetDateFormat(LOCALE_SYSTEM_DEFAULT, 0, NULL, NULL, (LPTSTR)aDateStr, sizeof(aDateStr));
- GetTimeFormat(LOCALE_SYSTEM_DEFAULT, 0, NULL, NULL, (LPTSTR)aTimeStr, sizeof(aTimeStr));
- fprintf(g_fh, "*** Logging started: %s %s\n", aDateStr, aTimeStr);
+
+ fprintf(g_fh, "*** Logging started: %s\n", GetTimeStamp().c_str());
}
void LogDone(void)
@@ -73,31 +88,27 @@ void LogDone(void)
//---------------------------------------------------------------------------
-void LogOutput(LPCTSTR format, ...)
+void LogOutput(const char* format, ...)
{
- TCHAR output[256];
-
va_list args;
va_start(args, format);
- _vsntprintf(output, sizeof(output) - 1, format, args);
- output[sizeof(output) - 1] = 0;
- OutputDebugString(output);
+ OutputDebugStringA(StrFormat(format, args).c_str());
+
+ va_end(args);
}
//---------------------------------------------------------------------------
-void LogFileOutput(LPCTSTR format, ...)
+void LogFileOutput(const char* format, ...)
{
if (!g_fh)
return;
- TCHAR output[256];
-
va_list args;
va_start(args, format);
- _vsntprintf(output, sizeof(output) - 1, format, args);
- output[sizeof(output) - 1] = 0;
- fprintf(g_fh, "%s", output);
+ vfprintf(g_fh, format, args);
+
+ va_end(args);
}
diff --git a/source/Log.h b/source/Log.h
index 82935a6a..e58285b4 100644
--- a/source/Log.h
+++ b/source/Log.h
@@ -1,5 +1,9 @@
#pragma once
+#include
+
+#include "StrFormat.h"
+
#ifndef _VC71 // __VA_ARGS__ not supported on MSVC++ .NET 7.x
#ifdef _DEBUG
#define LOG(format, ...) LogOutput(format, __VA_ARGS__)
@@ -8,15 +12,10 @@
#endif
#endif
-extern FILE* g_fh; // Filehandle for log file
+extern FILE* g_fh; // File handle for log file
void LogInit(void);
void LogDone(void);
-#ifdef _MSC_VER
-void LogOutput(LPCTSTR format, ...);
-void LogFileOutput(LPCTSTR format, ...);
-#else
-void LogOutput(LPCTSTR format, ...) __attribute__ ((format (printf, 1, 2)));
-void LogFileOutput(LPCTSTR format, ...) __attribute__ ((format (printf, 1, 2)));
-#endif
+void LogOutput(const char* format, ...) ATTRIBUTE_FORMAT_PRINTF(1, 2);
+void LogFileOutput(const char* format, ...) ATTRIBUTE_FORMAT_PRINTF(1, 2);
diff --git a/source/Memory.cpp b/source/Memory.cpp
index 83db7f01..a2ec8a47 100644
--- a/source/Memory.cpp
+++ b/source/Memory.cpp
@@ -1095,7 +1095,7 @@ void SetMemMode(DWORD uNewMemMode)
psz += sprintf(psz, "CX=%d " , SW_INTCXROM ? 1 : 0);
psz += sprintf(psz, "WRAM=%d " , SW_WRITERAM ? 1 : 0);
psz += sprintf(psz, "\n");
- OutputDebugString(szStr);
+ OutputDebugStringA(szStr);
}
#endif
memmode = uNewMemMode;
@@ -1978,9 +1978,7 @@ static void DebugFlip(WORD address, ULONG nExecutedCycles)
const double fFreq = CLK_6502 / (double)uCyclesBetweenFlips;
- char szStr[100];
- sprintf(szStr, "Cycles between flips = %d (%f Hz)\n", uCyclesBetweenFlips, fFreq);
- OutputDebugString(szStr);
+ LogOutput("Cycles between flips = %d (%f Hz)\n", uCyclesBetweenFlips, fFreq);
}
#endif
diff --git a/source/MouseInterface.cpp b/source/MouseInterface.cpp
index ecffe888..141eaa37 100644
--- a/source/MouseInterface.cpp
+++ b/source/MouseInterface.cpp
@@ -325,7 +325,6 @@ void CMouseInterface::OnCommand()
{
#ifdef _DEBUG_SPURIOUS_IRQ
static UINT uSpuriousIrqCount = 0;
- char szDbg[200];
BYTE byOldState = m_byState;
#endif
@@ -353,7 +352,7 @@ void CMouseInterface::OnCommand()
m_byBuff[5] = m_byState; // button 0/1 interrupt status
m_byState &= ~STAT_MOVEMENT_SINCE_READMOUSE;
#ifdef _DEBUG_SPURIOUS_IRQ
- sprintf(szDbg, "[MOUSE_READ] Old=%02X New=%02X\n", byOldState, m_byState); OutputDebugString(szDbg);
+ LogOutput("[MOUSE_READ] Old=%02X New=%02X\n", byOldState, m_byState);
#endif
break;
case MOUSE_SERV:
@@ -363,11 +362,11 @@ void CMouseInterface::OnCommand()
if ((m_byMode & MODE_INT_ALL) && (m_byBuff[1] & MODE_INT_ALL) == 0)
{
uSpuriousIrqCount++;
- sprintf(szDbg, "[MOUSE_SERV] 0x%04X Buff[1]=0x%02X, ***\n", uSpuriousIrqCount, m_byBuff[1]); OutputDebugString(szDbg);
+ LogOutput("[MOUSE_SERV] 0x%04X Buff[1]=0x%02X, ***\n", uSpuriousIrqCount, m_byBuff[1]);
}
else
{
- sprintf(szDbg, "[MOUSE_SERV] ------ Buff[1]=0x%02X\n", m_byBuff[1]); OutputDebugString(szDbg);
+ LogOutput("[MOUSE_SERV] ------ Buff[1]=0x%02X\n", m_byBuff[1]);
}
#endif
CpuIrqDeassert(IS_MOUSE);
@@ -472,7 +471,7 @@ void CMouseInterface::OnMouseEvent(bool bEventVBL)
m_byState |= byState;
CpuIrqAssert(IS_MOUSE);
#ifdef _DEBUG_SPURIOUS_IRQ
- char szDbg[200]; sprintf(szDbg, "[MOUSE EVNT] 0x%02X Mode=0x%02X\n", m_byState, m_byMode); OutputDebugString(szDbg);
+ LogOutput("[MOUSE EVNT] 0x%02X Mode=0x%02X\n", m_byState, m_byMode);
#endif
}
}
diff --git a/source/NTSC.cpp b/source/NTSC.cpp
index 65d0672c..04a15880 100644
--- a/source/NTSC.cpp
+++ b/source/NTSC.cpp
@@ -2438,9 +2438,7 @@ static bool CheckVideoTables2( eApple2Type type, uint32_t mode )
_ASSERT(addr1 == addr2);
if (addr1 != addr2)
{
- char str[80];
- sprintf(str, "vpos=%04X, hpos=%02X, Video_adr=$%04X, NTSC_adr=$%04X\n", g_nVideoClockVert, g_nVideoClockHorz, addr1, addr2);
- OutputDebugString(str);
+ LogOutput("vpos=%04X, hpos=%02X, Video_adr=$%04X, NTSC_adr=$%04X\n", g_nVideoClockVert, g_nVideoClockHorz, addr1, addr2);
return false;
}
diff --git a/source/SerialComms.cpp b/source/SerialComms.cpp
index 2df721f6..9c23fe37 100644
--- a/source/SerialComms.cpp
+++ b/source/SerialComms.cpp
@@ -1112,14 +1112,12 @@ void CSuperSerialCard::CheckCommEvent(DWORD dwEvtMask)
DWORD WINAPI CSuperSerialCard::CommThread(LPVOID lpParameter)
{
CSuperSerialCard* pSSC = (CSuperSerialCard*) lpParameter;
- char szDbg[100];
BOOL bRes = SetCommMask(pSSC->m_hCommHandle, EV_RLSD | EV_DSR | EV_CTS | EV_TXEMPTY | EV_RXCHAR);
if (!bRes)
{
- sprintf(szDbg, "SSC: CommThread(): SetCommMask() failed\n");
- LogOutput("%s", szDbg);
- LogFileOutput("%s", szDbg);
+ LogOutput("SSC: CommThread(): SetCommMask() failed\n");
+ LogFileOutput("SSC: CommThread(): SetCommMask() failed\n");
return -1;
}
@@ -1145,11 +1143,15 @@ DWORD WINAPI CSuperSerialCard::CommThread(LPVOID lpParameter)
COMSTAT Stat;
ClearCommError(pSSC->m_hCommHandle, &dwErrors, &Stat);
if (dwErrors & CE_RXOVER)
- sprintf(szDbg, "SSC: CommThread(): LastError=0x%08X, CommError=CE_RXOVER (0x%08X): InQueue=0x%08X\n", dwRet, dwErrors, Stat.cbInQue);
+ {
+ LogOutput("SSC: CommThread(): LastError=0x%08X, CommError=CE_RXOVER (0x%08X): InQueue=0x%08X\n", dwRet, dwErrors, Stat.cbInQue);
+ LogFileOutput("SSC: CommThread(): LastError=0x%08X, CommError=CE_RXOVER (0x%08X): InQueue=0x%08X\n", dwRet, dwErrors, Stat.cbInQue);
+ }
else
- sprintf(szDbg, "SSC: CommThread(): LastError=0x%08X, CommError=Other (0x%08X): InQueue=0x%08X, OutQueue=0x%08X\n", dwRet, dwErrors, Stat.cbInQue, Stat.cbOutQue);
- LogOutput("%s", szDbg);
- LogFileOutput("%s", szDbg);
+ {
+ LogOutput("SSC: CommThread(): LastError=0x%08X, CommError=Other (0x%08X): InQueue=0x%08X, OutQueue=0x%08X\n", dwRet, dwErrors, Stat.cbInQue, Stat.cbOutQue);
+ LogFileOutput("SSC: CommThread(): LastError=0x%08X, CommError=Other (0x%08X): InQueue=0x%08X, OutQueue=0x%08X\n", dwRet, dwErrors, Stat.cbInQue, Stat.cbOutQue);
+ }
return -1;
}
@@ -1175,7 +1177,7 @@ DWORD WINAPI CSuperSerialCard::CommThread(LPVOID lpParameter)
}
dwWaitResult -= WAIT_OBJECT_0; // Determine event # that signaled
- //sprintf(szDbg, "CommThread: GotEvent1: %d\n", dwWaitResult); OutputDebugString(szDbg);
+ //LogOutput("CommThread: GotEvent1: %d\n", dwWaitResult);
if (dwWaitResult == (nNumEvents-1))
break; // Termination event
diff --git a/source/Speaker.cpp b/source/Speaker.cpp
index e13ed33c..3603a52d 100644
--- a/source/Speaker.cpp
+++ b/source/Speaker.cpp
@@ -488,7 +488,6 @@ static int nDbgSpkrCnt = 0;
static ULONG Spkr_SubmitWaveBuffer_FullSpeed(short* pSpeakerBuffer, ULONG nNumSamples)
{
- //char szDbg[200];
nDbgSpkrCnt++;
if(!SpeakerVoice.bActive)
@@ -514,7 +513,7 @@ static ULONG Spkr_SubmitWaveBuffer_FullSpeed(short* pSpeakerBuffer, ULONG nNumSa
dwByteOffset = dwCurrentPlayCursor + (g_dwDSSpkrBufferSize/8)*3; // Ideal: 0.375 is between 0.25 & 0.50 full
dwByteOffset %= g_dwDSSpkrBufferSize;
- //sprintf(szDbg, "[Submit_FS] PC=%08X, WC=%08X, Diff=%08X, Off=%08X, NS=%08X [REINIT]\n", dwCurrentPlayCursor, dwCurrentWriteCursor, dwCurrentWriteCursor-dwCurrentPlayCursor, dwByteOffset, nNumSamples); OutputDebugString(szDbg);
+ //LogOutput("[Submit_FS] PC=%08X, WC=%08X, Diff=%08X, Off=%08X, NS=%08X [REINIT]\n", dwCurrentPlayCursor, dwCurrentWriteCursor, dwCurrentWriteCursor-dwCurrentPlayCursor, dwByteOffset, nNumSamples);
}
else
{
@@ -525,7 +524,7 @@ static ULONG Spkr_SubmitWaveBuffer_FullSpeed(short* pSpeakerBuffer, ULONG nNumSa
// |-----PxxxxxW-----|
if((dwByteOffset > dwCurrentPlayCursor) && (dwByteOffset < dwCurrentWriteCursor))
{
- //sprintf(szDbg, "[Submit_FS] PC=%08X, WC=%08X, Diff=%08X, Off=%08X, NS=%08X xxx\n", dwCurrentPlayCursor, dwCurrentWriteCursor, dwCurrentWriteCursor-dwCurrentPlayCursor, dwByteOffset, nNumSamples); OutputDebugString(szDbg);
+ //LogOutput("[Submit_FS] PC=%08X, WC=%08X, Diff=%08X, Off=%08X, NS=%08X xxx\n", dwCurrentPlayCursor, dwCurrentWriteCursor, dwCurrentWriteCursor-dwCurrentPlayCursor, dwByteOffset, nNumSamples);
dwByteOffset = dwCurrentWriteCursor;
}
}
@@ -534,7 +533,7 @@ static ULONG Spkr_SubmitWaveBuffer_FullSpeed(short* pSpeakerBuffer, ULONG nNumSa
// |xxW----------Pxxx|
if((dwByteOffset > dwCurrentPlayCursor) || (dwByteOffset < dwCurrentWriteCursor))
{
- //sprintf(szDbg, "[Submit_FS] PC=%08X, WC=%08X, Diff=%08X, Off=%08X, NS=%08X XXX\n", dwCurrentPlayCursor, dwCurrentWriteCursor, dwCurrentWriteCursor-dwCurrentPlayCursor, dwByteOffset, nNumSamples); OutputDebugString(szDbg);
+ //LogOutput("[Submit_FS] PC=%08X, WC=%08X, Diff=%08X, Off=%08X, NS=%08X XXX\n", dwCurrentPlayCursor, dwCurrentWriteCursor, dwCurrentWriteCursor-dwCurrentPlayCursor, dwByteOffset, nNumSamples);
dwByteOffset = dwCurrentWriteCursor;
}
}
@@ -590,7 +589,7 @@ static ULONG Spkr_SubmitWaveBuffer_FullSpeed(short* pSpeakerBuffer, ULONG nNumSa
if(nNumSamples)
{
- //sprintf(szDbg, "[Submit_FS] C=%08X, PC=%08X, WC=%08X, Diff=%08X, Off=%08X, NS=%08X ***\n", nDbgSpkrCnt, dwCurrentPlayCursor, dwCurrentWriteCursor, dwCurrentWriteCursor-dwCurrentPlayCursor, dwByteOffset, nNumSamples); OutputDebugString(szDbg);
+ //LogOutput("[Submit_FS] C=%08X, PC=%08X, WC=%08X, Diff=%08X, Off=%08X, NS=%08X ***\n", nDbgSpkrCnt, dwCurrentPlayCursor, dwCurrentWriteCursor, dwCurrentWriteCursor-dwCurrentPlayCursor, dwByteOffset, nNumSamples);
if(nNumSamples*sizeof(short) <= dwDSLockedBufferSize0)
{
@@ -624,7 +623,7 @@ static ULONG Spkr_SubmitWaveBuffer_FullSpeed(short* pSpeakerBuffer, ULONG nNumSa
if(nNumPadSamples)
{
- //sprintf(szDbg, "[Submit_FS] C=%08X, PC=%08X, WC=%08X, Diff=%08X, Off=%08X, PS=%08X, Data=%04X\n", nDbgSpkrCnt, dwCurrentPlayCursor, dwCurrentWriteCursor, dwCurrentWriteCursor-dwCurrentPlayCursor, dwByteOffset, nNumPadSamples, g_nSpeakerData); OutputDebugString(szDbg);
+ //LogOutput("[Submit_FS] C=%08X, PC=%08X, WC=%08X, Diff=%08X, Off=%08X, PS=%08X, Data=%04X\n", nDbgSpkrCnt, dwCurrentPlayCursor, dwCurrentWriteCursor, dwCurrentWriteCursor-dwCurrentPlayCursor, dwByteOffset, nNumPadSamples, g_nSpeakerData);
dwBufferSize0 = dwDSLockedBufferSize0 - dwBufferSize0;
dwBufferSize1 = dwDSLockedBufferSize1 - dwBufferSize1;
@@ -662,7 +661,6 @@ static ULONG Spkr_SubmitWaveBuffer_FullSpeed(short* pSpeakerBuffer, ULONG nNumSa
static ULONG Spkr_SubmitWaveBuffer(short* pSpeakerBuffer, ULONG nNumSamples)
{
- //char szDbg[200];
nDbgSpkrCnt++;
if(!SpeakerVoice.bActive)
@@ -702,7 +700,7 @@ static ULONG Spkr_SubmitWaveBuffer(short* pSpeakerBuffer, ULONG nNumSamples)
dwByteOffset = dwCurrentPlayCursor + (g_dwDSSpkrBufferSize/8)*3; // Ideal: 0.375 is between 0.25 & 0.50 full
dwByteOffset %= g_dwDSSpkrBufferSize;
- //sprintf(szDbg, "[Submit] PC=%08X, WC=%08X, Diff=%08X, Off=%08X [REINIT]\n", dwCurrentPlayCursor, dwCurrentWriteCursor, dwCurrentWriteCursor-dwCurrentPlayCursor, dwByteOffset); OutputDebugString(szDbg);
+ //LogOutput("[Submit] PC=%08X, WC=%08X, Diff=%08X, Off=%08X [REINIT]\n", dwCurrentPlayCursor, dwCurrentWriteCursor, dwCurrentWriteCursor-dwCurrentPlayCursor, dwByteOffset);
}
else
{
@@ -714,9 +712,8 @@ static ULONG Spkr_SubmitWaveBuffer(short* pSpeakerBuffer, ULONG nNumSamples)
if((dwByteOffset > dwCurrentPlayCursor) && (dwByteOffset < dwCurrentWriteCursor))
{
double fTicksSecs = (double)GetTickCount() / 1000.0;
- //sprintf(szDbg, "%010.3f: [Submit] PC=%08X, WC=%08X, Diff=%08X, Off=%08X, NS=%08X xxx\n", fTicksSecs, dwCurrentPlayCursor, dwCurrentWriteCursor, dwCurrentWriteCursor-dwCurrentPlayCursor, dwByteOffset, nNumSamples);
- //OutputDebugString(szDbg);
- //if (g_fh) fprintf(g_fh, szDbg);
+ //LogOutput("%010.3f: [Submit] PC=%08X, WC=%08X, Diff=%08X, Off=%08X, NS=%08X xxx\n", fTicksSecs, dwCurrentPlayCursor, dwCurrentWriteCursor, dwCurrentWriteCursor-dwCurrentPlayCursor, dwByteOffset, nNumSamples);
+ //LogFileOutput("%010.3f: [Submit] PC=%08X, WC=%08X, Diff=%08X, Off=%08X, NS=%08X xxx\n", fTicksSecs, dwCurrentPlayCursor, dwCurrentWriteCursor, dwCurrentWriteCursor-dwCurrentPlayCursor, dwByteOffset, nNumSamples);
dwByteOffset = dwCurrentWriteCursor;
nNumSamplesError = 0;
@@ -729,9 +726,8 @@ static ULONG Spkr_SubmitWaveBuffer(short* pSpeakerBuffer, ULONG nNumSamples)
if((dwByteOffset > dwCurrentPlayCursor) || (dwByteOffset < dwCurrentWriteCursor))
{
double fTicksSecs = (double)GetTickCount() / 1000.0;
- //sprintf(szDbg, "%010.3f: [Submit] PC=%08X, WC=%08X, Diff=%08X, Off=%08X, NS=%08X XXX\n", fTicksSecs, dwCurrentPlayCursor, dwCurrentWriteCursor, dwCurrentWriteCursor-dwCurrentPlayCursor, dwByteOffset, nNumSamples);
- //OutputDebugString(szDbg);
- //if (g_fh) fprintf(g_fh, "%s", szDbg);
+ //LogOutput("%010.3f: [Submit] PC=%08X, WC=%08X, Diff=%08X, Off=%08X, NS=%08X XXX\n", fTicksSecs, dwCurrentPlayCursor, dwCurrentWriteCursor, dwCurrentWriteCursor-dwCurrentPlayCursor, dwByteOffset, nNumSamples);
+ //LogFileOutput("%010.3f: [Submit] PC=%08X, WC=%08X, Diff=%08X, Off=%08X, NS=%08X XXX\n", fTicksSecs, dwCurrentPlayCursor, dwCurrentWriteCursor, dwCurrentWriteCursor-dwCurrentPlayCursor, dwByteOffset, nNumSamples);
dwByteOffset = dwCurrentWriteCursor;
nNumSamplesError = 0;
@@ -776,7 +772,7 @@ static ULONG Spkr_SubmitWaveBuffer(short* pSpeakerBuffer, ULONG nNumSamples)
if(nNumSamplesToUse)
{
- //sprintf(szDbg, "[Submit] C=%08X, PC=%08X, WC=%08X, Diff=%08X, Off=%08X, NS=%08X +++\n", nDbgSpkrCnt, dwCurrentPlayCursor, dwCurrentWriteCursor, dwCurrentWriteCursor-dwCurrentPlayCursor, dwByteOffset, nNumSamplesToUse); OutputDebugString(szDbg);
+ //LogOutput("[Submit] C=%08X, PC=%08X, WC=%08X, Diff=%08X, Off=%08X, NS=%08X +++\n", nDbgSpkrCnt, dwCurrentPlayCursor, dwCurrentWriteCursor, dwCurrentWriteCursor-dwCurrentPlayCursor, dwByteOffset, nNumSamplesToUse);
hr = DSGetLock(SpeakerVoice.lpDSBvoice,
dwByteOffset, (DWORD)nNumSamplesToUse * sizeof(short),
@@ -941,8 +937,7 @@ bool Spkr_DSInit()
hr = SpeakerVoice.lpDSBvoice->GetCurrentPosition(&dwCurrentPlayCursor, &dwCurrentWriteCursor);
LogFileOutput("Spkr_DSInit: GetCurrentPosition kludge (%08X)\n", hr);
- char szDbg[100];
- sprintf(szDbg, "[DSInit] PC=%08X, WC=%08X, Diff=%08X\n", dwCurrentPlayCursor, dwCurrentWriteCursor, dwCurrentWriteCursor-dwCurrentPlayCursor); OutputDebugString(szDbg);
+ LogOutput("[DSInit] PC=%08X, WC=%08X, Diff=%08X\n", dwCurrentPlayCursor, dwCurrentWriteCursor, dwCurrentWriteCursor-dwCurrentPlayCursor);
}
return true;
diff --git a/source/StdAfx.h b/source/StdAfx.h
index 5db7e2bd..7d4db036 100644
--- a/source/StdAfx.h
+++ b/source/StdAfx.h
@@ -35,6 +35,7 @@ typedef UINT64 uint64_t;
#include
#include
#include
+#include
// SM_CXPADDEDBORDER is not supported on 2000 & XP:
// http://msdn.microsoft.com/en-nz/library/windows/desktop/ms724385(v=vs.85).aspx
@@ -43,3 +44,17 @@ typedef UINT64 uint64_t;
#endif
#define USE_SPEECH_API
+
+#if (defined(_MSC_VER) && (_MSC_VER < 1900)) || \
+ (!defined(_MSC_VER) && (!defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L))
+#ifdef _WIN64
+#define SIZE_T_FMT "llu"
+#define PTRDIFF_T_FMT "lld"
+#else
+#define SIZE_T_FMT "lu"
+#define PTRDIFF_T_FMT "ld"
+#endif
+#else
+#define SIZE_T_FMT "zu"
+#define PTRDIFF_T_FMT "td"
+#endif
diff --git a/source/StrFormat.cpp b/source/StrFormat.cpp
new file mode 100644
index 00000000..0ee841f6
--- /dev/null
+++ b/source/StrFormat.cpp
@@ -0,0 +1,67 @@
+#include "StdAfx.h"
+
+#include "StrFormat.h"
+
+#include
+
+std::string StrFormat(const char* format, ...)
+{
+ va_list va;
+ va_start(va, format);
+ std::string s = StrFormatV(format, va);
+ va_end(va);
+ return s;
+}
+
+std::string StrFormatV(const char* format, va_list va)
+{
+ size_t const bufsz_base = 2048; // Big enough for most cases.
+ char buf[bufsz_base];
+#if defined(_MSC_VER) && _MSC_VER < 1900
+#pragma warning(push)
+#pragma warning(disable: 4996) // warning _vsnprintf() is unsafe.
+ // VS2013 or before, _vsnprintf() cannot return required buffer size in case of overflow.
+ // MSVC seems fine not needing va_copy(), otherwise va_copy() may need to be called twice
+ // to be accurate. Not calling va_copy() here to keep things simpler.
+ int len = _vsnprintf(buf, sizeof(buf), format, va);
+ if (len >= 0 && size_t(len) <= sizeof(buf))
+ {
+ // _vsnprintf() can fill up the full buffer without nul termination.
+ return std::string(buf, size_t(len)); // No overflow.
+ }
+ else
+ {
+ // Overflow, need bigger buffer.
+ len = _vsnprintf(NULL, 0, format, va); // Get required buffer size.
+ std::string s(size_t(len), '\0');
+ len = _vsnprintf(&(*s.begin()), s.length() + 1, format, va);
+ assert(size_t(len) == s.length());
+ return s;
+ }
+#pragma warning(pop)
+#else
+ // Need to call va_copy() so va can be used potentially for a second time.
+ // glibc on Linux *certainly* needs this while MSVC is fine without it though.
+ va_list va_copied;
+ va_copy(va_copied, va);
+ int len = vsnprintf(buf, sizeof(buf), format, va_copied);
+ va_end(va_copied);
+
+ if (len < 0)
+ {
+ return std::string(); // Error.
+ }
+ else if (size_t(len) < sizeof(buf))
+ {
+ return std::string(buf, size_t(len)); // No overflow.
+ }
+ else
+ {
+ // Overflow, need bigger buffer.
+ std::string s(size_t(len), '\0');
+ len = vsnprintf(&(*s.begin()), s.length() + 1, format, va);
+ assert(size_t(len) == s.length());
+ return s;
+ }
+#endif
+}
diff --git a/source/StrFormat.h b/source/StrFormat.h
new file mode 100644
index 00000000..022fea28
--- /dev/null
+++ b/source/StrFormat.h
@@ -0,0 +1,13 @@
+#pragma once
+
+#include
+#include
+
+#ifdef _MSC_VER
+#define ATTRIBUTE_FORMAT_PRINTF(a, b)
+#else
+#define ATTRIBUTE_FORMAT_PRINTF(a, b) __attribute__((format(printf, a, b)))
+#endif
+
+std::string StrFormat(const char* format, ...) ATTRIBUTE_FORMAT_PRINTF(1, 2);
+std::string StrFormatV(const char* format, va_list va);
diff --git a/source/Tfe/tfearch.cpp b/source/Tfe/tfearch.cpp
index 986f8b88..8120b025 100644
--- a/source/Tfe/tfearch.cpp
+++ b/source/Tfe/tfearch.cpp
@@ -194,8 +194,7 @@ void debug_output( const char *text, BYTE *what, int count )
int len1 = count;
int i;
- sprintf(buffer, "\n%s: length = %u\n", text, len1);
- OutputDebugString(buffer);
+ LogOutput("\n%s: length = %u\n", text, len1);
do {
p = buffer;
for (i=0; (i<8) && len1>0; len1--, i++) {
@@ -203,7 +202,7 @@ void debug_output( const char *text, BYTE *what, int count )
p += 3;
}
*(p-1) = '\n'; *p = 0;
- OutputDebugString(buffer);
+ OutputDebugStringA(buffer);
} while (len1>0);
}
#endif // #ifdef TFE_DEBUG_PKTDUMP
diff --git a/source/Windows/WinFrame.cpp b/source/Windows/WinFrame.cpp
index e78abbea..f51af7e4 100644
--- a/source/Windows/WinFrame.cpp
+++ b/source/Windows/WinFrame.cpp
@@ -623,9 +623,7 @@ void Win32Frame::FrameDrawDiskStatus( HDC passdc )
#if _DEBUG && 0
if (nDOS33track != nDisk1Track)
{
- char text[128];
- sprintf( text, "\n\n\nWARNING: DOS33Track: %d (%02X) != nDisk1Track: %d (%02X)\n\n\n", nDOS33track, nDOS33track, nDisk1Track, nDisk1Track );
- OutputDebugString( text );
+ LogOutput( "\n\n\nWARNING: DOS33Track: %d (%02X) != nDisk1Track: %d (%02X)\n\n\n", nDOS33track, nDOS33track, nDisk1Track, nDisk1Track );
}
#endif // _DEBUG
@@ -1648,9 +1646,9 @@ LRESULT Win32Frame::WndProc(
case WM_SYSCOLORCHANGE:
#if DEBUG_DD_PALETTE
if( g_bIsFullScreen )
- OutputDebugString( "WM_SYSCOLORCHANGE: Full Screen\n" );
+ OutputDebugStringA( "WM_SYSCOLORCHANGE: Full Screen\n" );
else
- OutputDebugString( "WM_SYSCOLORCHANGE: Windowed\n" );
+ OutputDebugStringA( "WM_SYSCOLORCHANGE: Windowed\n" );
#endif
DeleteGdiObjects();
@@ -1841,9 +1839,7 @@ void Win32Frame::ProcessButtonClick(int button, bool bFromButtonUI /*=false*/)
bool bAllowFadeIn = true;
#if DEBUG_DD_PALETTE
- char _text[ 80 ];
- sprintf( _text, "Button: F%d Full Screen: %d\n", button+1, g_bIsFullScreen );
- OutputDebugString( _text );
+ LogOutput( "Button: F%d Full Screen: %d\n", button+1, g_bIsFullScreen );
#endif
switch (button) {
@@ -2552,14 +2548,13 @@ void Win32Frame::FrameSetCursorPosByMousePos()
SetCursorPos(Point.x+iWindowX-VIEWPORTX, Point.y+iWindowY-VIEWPORTY);
#if defined(_DEBUG) && 0 // OutputDebugString() when cursor position changes since last time
- static int OldX=0, OldY=0;
- char szDbg[200];
- int X=Point.x+iWindowX-VIEWPORTX;
- int Y=Point.y+iWindowY-VIEWPORTY;
+ static int OldX = 0, OldY = 0;
+ int X = Point.x + iWindowX - VIEWPORTX;
+ int Y = Point.y + iWindowY - VIEWPORTY;
if (X != OldX || Y != OldY)
{
- sprintf(szDbg, "[FrameSetCursorPosByMousePos] x,y=%d,%d (MaxX,Y=%d,%d)\n", X,Y, iMaxX,iMaxY); OutputDebugString(szDbg);
- OldX=X; OldY=Y;
+ LogOutput("[FrameSetCursorPosByMousePos] x,y=%d,%d (MaxX,Y=%d,%d)\n", X, Y, iMaxX, iMaxY);
+ OldX = X; OldY = Y;
}
#endif
}
@@ -2573,7 +2568,6 @@ void Win32Frame::FrameSetCursorPosByMousePos(int x, int y, int dx, int dy, bool
if (!GetCardMgr().IsMouseCardInstalled())
return;
-// char szDbg[200];
if (!g_hFrameWindow || (g_bShowingCursor && bLeavingAppleScreen) || (!g_bShowingCursor && !bLeavingAppleScreen))
return;
@@ -2598,11 +2592,11 @@ void Win32Frame::FrameSetCursorPosByMousePos(int x, int y, int dx, int dy, bool
POINT Point = {viewportx+2, viewporty+2}; // top-left
ClientToScreen(g_hFrameWindow, &Point);
SetCursorPos(Point.x+iWindowX-VIEWPORTX, Point.y+iWindowY-VIEWPORTY);
-// sprintf(szDbg, "[MOUSE_LEAVING ] x=%d, y=%d (Scale: x,y=%f,%f; iX,iY=%d,%d)\n", iWindowX, iWindowY, fScaleX, fScaleY, iX, iY); OutputDebugString(szDbg);
+ //LogOutput("[MOUSE_LEAVING ] x=%d, y=%d (Scale: x,y=%f,%f; iX,iY=%d,%d)\n", iWindowX, iWindowY, fScaleX, fScaleY, iX, iY);
}
else // Mouse entering Apple screen area
{
-// sprintf(szDbg, "[MOUSE_ENTERING] x=%d, y=%d\n", x, y); OutputDebugString(szDbg);
+ //LogOutput("[MOUSE_ENTERING] x=%d, y=%d\n", x, y);
if (!g_bIsFullScreen) // GH#464
{
x -= (viewportx+2-VIEWPORTX); if (x < 0) x = 0;