From fe62271ef968f030639f8738ac2e8c18d1cd71ec Mon Sep 17 00:00:00 2001 From: Andrea Date: Sat, 27 Jun 2020 14:32:09 +0100 Subject: [PATCH 1/2] Some minor c++ correctness changes. (#803) Added const, static forward declaration. Removed some unneeded header files. --- source/AY8910.cpp | 10 ++++------ source/AY8910.h | 8 ++++---- source/Mockingboard.cpp | 4 ++-- source/SoundCore.cpp | 4 ++-- source/SoundCore.h | 4 ++-- 5 files changed, 14 insertions(+), 16 deletions(-) diff --git a/source/AY8910.cpp b/source/AY8910.cpp index 701a958a..686ba78a 100644 --- a/source/AY8910.cpp +++ b/source/AY8910.cpp @@ -26,9 +26,7 @@ #include "StdAfx.h" -#include #include -#include #include "AY8910.h" #include "Applewin.h" // For g_fh @@ -991,7 +989,7 @@ sound_beeper( int is_tape, int on ) #define SS_YAML_KEY_CHANGE "Change" #define SS_YAML_VALUE_CHANGE_FORMAT "%d, %d, 0x%1X, 0x%02X" -void CAY8910::SaveSnapshot(YamlSaveHelper& yamlSaveHelper, std::string& suffix) +void CAY8910::SaveSnapshot(YamlSaveHelper& yamlSaveHelper, const std::string& suffix) { std::string unit = std::string(SS_YAML_KEY_AY8910) + suffix; YamlSaveHelper::Label label(yamlSaveHelper, "%s:\n", unit.c_str()); @@ -1046,7 +1044,7 @@ void CAY8910::SaveSnapshot(YamlSaveHelper& yamlSaveHelper, std::string& suffix) } } -bool CAY8910::LoadSnapshot(YamlLoadHelper& yamlLoadHelper, std::string& suffix) +bool CAY8910::LoadSnapshot(YamlLoadHelper& yamlLoadHelper, const std::string& suffix) { std::string unit = std::string(SS_YAML_KEY_AY8910) + suffix; if (!yamlLoadHelper.GetSubMap(unit)) @@ -1201,7 +1199,7 @@ BYTE* AY8910_GetRegsPtr(UINT uChip) return g_AY8910[uChip].GetAYRegsPtr(); } -UINT AY8910_SaveSnapshot(YamlSaveHelper& yamlSaveHelper, UINT uChip, std::string& suffix) +UINT AY8910_SaveSnapshot(YamlSaveHelper& yamlSaveHelper, UINT uChip, const std::string& suffix) { if (uChip >= MAX_8910) return 0; @@ -1210,7 +1208,7 @@ UINT AY8910_SaveSnapshot(YamlSaveHelper& yamlSaveHelper, UINT uChip, std::string return 1; } -UINT AY8910_LoadSnapshot(YamlLoadHelper& yamlLoadHelper, UINT uChip, std::string& suffix) +UINT AY8910_LoadSnapshot(YamlLoadHelper& yamlLoadHelper, UINT uChip, const std::string& suffix) { if (uChip >= MAX_8910) return 0; diff --git a/source/AY8910.h b/source/AY8910.h index 31ad9a15..42962649 100644 --- a/source/AY8910.h +++ b/source/AY8910.h @@ -17,8 +17,8 @@ BYTE* AY8910_GetRegsPtr(UINT uChip); void AY8910UpdateSetCycles(); -UINT AY8910_SaveSnapshot(class YamlSaveHelper& yamlSaveHelper, UINT uChip, std::string& suffix); -UINT AY8910_LoadSnapshot(class YamlLoadHelper& yamlLoadHelper, UINT uChip, std::string& suffix); +UINT AY8910_SaveSnapshot(class YamlSaveHelper& yamlSaveHelper, UINT uChip, const std::string& suffix); +UINT AY8910_LoadSnapshot(class YamlLoadHelper& yamlLoadHelper, UINT uChip, const std::string& suffix); //------------------------------------- // FUSE stuff @@ -46,8 +46,8 @@ public: void sound_frame( void ); BYTE* GetAYRegsPtr( void ) { return &sound_ay_registers[0]; } static void SetCLK( double CLK ) { m_fCurrentCLK_AY8910 = CLK; } - void SaveSnapshot(class YamlSaveHelper& yamlSaveHelper, std::string& suffix); - bool LoadSnapshot(class YamlLoadHelper& yamlLoadHelper, std::string& suffix); + void SaveSnapshot(class YamlSaveHelper& yamlSaveHelper, const std::string& suffix); + bool LoadSnapshot(class YamlLoadHelper& yamlLoadHelper, const std::string& suffix); private: void init( void ); diff --git a/source/Mockingboard.cpp b/source/Mockingboard.cpp index b71e42d9..3524b39c 100644 --- a/source/Mockingboard.cpp +++ b/source/Mockingboard.cpp @@ -555,7 +555,7 @@ static BYTE SY6522_Read(BYTE nDevice, BYTE nReg) //--------------------------------------------------------------------------- -void SSI263_Play(unsigned int nPhoneme); +static void SSI263_Play(unsigned int nPhoneme); #if 0 typedef struct @@ -1510,7 +1510,7 @@ void MB_Initialize() g_bCritSectionValid = true; } -void MB_SetSoundcardType(SS_CARDTYPE NewSoundcardType); +static void MB_SetSoundcardType(SS_CARDTYPE NewSoundcardType); // NB. Mockingboard voice is *already* muted because showing 'Select Load State file' dialog // . and voice will be demuted when dialog is closed diff --git a/source/SoundCore.cpp b/source/SoundCore.cpp index 6ec6c623..29d66d52 100644 --- a/source/SoundCore.cpp +++ b/source/SoundCore.cpp @@ -224,7 +224,7 @@ void DSReleaseSoundBuffer(VOICE* pVoice) //----------------------------------------------------------------------------- -bool DSZeroVoiceBuffer(PVOICE Voice, char* pszDevName, DWORD dwBufferSize) +bool DSZeroVoiceBuffer(PVOICE Voice, const char* pszDevName, DWORD dwBufferSize) { #ifdef NO_DIRECT_X @@ -273,7 +273,7 @@ bool DSZeroVoiceBuffer(PVOICE Voice, char* pszDevName, DWORD dwBufferSize) //----------------------------------------------------------------------------- -bool DSZeroVoiceWritableBuffer(PVOICE Voice, char* pszDevName, DWORD dwBufferSize) +bool DSZeroVoiceWritableBuffer(PVOICE Voice, const char* pszDevName, DWORD dwBufferSize) { DWORD dwDSLockedBufferSize0=0, dwDSLockedBufferSize1=0; SHORT *pDSLockedBuffer0, *pDSLockedBuffer1; diff --git a/source/SoundCore.h b/source/SoundCore.h index ecc2f2b1..02b129c2 100644 --- a/source/SoundCore.h +++ b/source/SoundCore.h @@ -29,8 +29,8 @@ bool DSGetLock(LPDIRECTSOUNDBUFFER pVoice, DWORD dwOffset, DWORD dwBytes, HRESULT DSGetSoundBuffer(VOICE* pVoice, DWORD dwFlags, DWORD dwBufferSize, DWORD nSampleRate, int nChannels); void DSReleaseSoundBuffer(VOICE* pVoice); -bool DSZeroVoiceBuffer(PVOICE Voice, char* pszDevName, DWORD dwBufferSize); -bool DSZeroVoiceWritableBuffer(PVOICE Voice, char* pszDevName, DWORD dwBufferSize); +bool DSZeroVoiceBuffer(PVOICE Voice, const char* pszDevName, DWORD dwBufferSize); +bool DSZeroVoiceWritableBuffer(PVOICE Voice, const char* pszDevName, DWORD dwBufferSize); enum eFADE {FADE_NONE, FADE_IN, FADE_OUT}; void SoundCore_SetFade(eFADE FadeType); From e48ea095a3eea6d6c58f28bad6ed8502111dd6a1 Mon Sep 17 00:00:00 2001 From: tomcw Date: Sat, 27 Jun 2020 15:46:28 +0100 Subject: [PATCH 2/2] Debugger: PrintGlyph() - removed magic numbers --- source/Debugger/Debugger_Display.cpp | 38 +++++++++++++--------------- source/Debugger/Debugger_Display.h | 7 +++-- 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/source/Debugger/Debugger_Display.cpp b/source/Debugger/Debugger_Display.cpp index 9d087135..621da099 100644 --- a/source/Debugger/Debugger_Display.cpp +++ b/source/Debugger/Debugger_Display.cpp @@ -84,10 +84,9 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA static bgra_t* g_pDebuggerMemFramebits = NULL; HDC g_hConsoleFontDC = NULL; - HBRUSH g_hConsoleFontBrush = NULL; HBITMAP g_hConsoleFontBitmap = NULL; - LPBITMAPINFO g_hConsoleFontFramebufferinfo; - bgra_t* g_hConsoleFontFramebits; + static LPBITMAPINFO g_hConsoleFontFramebufferinfo = NULL; + static bgra_t* g_hConsoleFontFramebits; char g_cConsoleBrushFG_r; char g_cConsoleBrushFG_g; @@ -617,8 +616,8 @@ HDC GetConsoleFontDC(void) ZeroMemory(g_hConsoleFontFramebufferinfo, sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD)); g_hConsoleFontFramebufferinfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); - g_hConsoleFontFramebufferinfo->bmiHeader.biWidth = 112; - g_hConsoleFontFramebufferinfo->bmiHeader.biHeight = 128; + g_hConsoleFontFramebufferinfo->bmiHeader.biWidth = CONSOLE_FONT_BITMAP_WIDTH; + g_hConsoleFontFramebufferinfo->bmiHeader.biHeight = CONSOLE_FONT_BITMAP_HEIGHT; g_hConsoleFontFramebufferinfo->bmiHeader.biPlanes = 1; g_hConsoleFontFramebufferinfo->bmiHeader.biBitCount = 32; g_hConsoleFontFramebufferinfo->bmiHeader.biCompression = BI_RGB; @@ -639,7 +638,7 @@ HDC GetConsoleFontDC(void) // Pre-scaled bitmap HBITMAP tmpFont = LoadBitmap(g_hInstance, TEXT("IDB_DEBUG_FONT_7x8")); // Bitmap must be 112x128 as defined above SelectObject(tmpDC, tmpFont); - BitBlt(g_hConsoleFontDC, 0, 0, 112, 128, + BitBlt(g_hConsoleFontDC, 0, 0, CONSOLE_FONT_BITMAP_WIDTH, CONSOLE_FONT_BITMAP_HEIGHT, tmpDC, 0, 0, SRCCOPY); DeleteDC(tmpDC); @@ -724,31 +723,28 @@ void DebuggerSetColorBG( COLORREF nRGB, bool bTransparent ) // @param glyph Specifies a native glyph from the 16x16 chars Apple Font Texture. //=========================================================================== -void PrintGlyph( const int x, const int y, const int glyph ) +static void PrintGlyph( const int xDst, const int yDst, const int glyph ) { HDC hDstDC = GetDebuggerMemDC(); - int xDst = x; - int yDst = y; - - // 16x8 chars in bitmap - int xSrc = (glyph & 0x0F) *CONSOLE_FONT_GRID_X; - int ySrc = (glyph >> 4) *CONSOLE_FONT_GRID_Y; + int xSrc = (glyph % CONSOLE_FONT_NUM_CHARS_PER_ROW) * CONSOLE_FONT_GRID_X; + int ySrc = (glyph / CONSOLE_FONT_NUM_CHARS_PER_ROW) * CONSOLE_FONT_GRID_Y; + _ASSERT(ySrc < CONSOLE_FONT_BITMAP_HEIGHT); // BUG #239 - (Debugger) Save debugger "text screen" to clipboard / file // if( g_bDebuggerVirtualTextCapture ) // { #if _DEBUG - if ((x < 0) || (y < 0)) + if ((xDst < 0) || (yDst < 0)) MessageBox( g_hFrameWindow, "X or Y out of bounds!", "PrintGlyph()", MB_OK ); #endif - int col = x / CONSOLE_FONT_WIDTH ; - int row = y / CONSOLE_FONT_HEIGHT; + int col = xDst / CONSOLE_FONT_WIDTH ; + int row = yDst / CONSOLE_FONT_HEIGHT; // if( !g_bDebuggerCopyInfoPane ) // if( col < 50 - if (x > DISPLAY_DISASM_RIGHT) // INFO_COL_2 // DISPLAY_CPU_INFO_LEFT_COLUMN + if (xDst > DISPLAY_DISASM_RIGHT) // INFO_COL_2 // DISPLAY_CPU_INFO_LEFT_COLUMN col++; if ((col < DEBUG_VIRTUAL_TEXT_WIDTH) @@ -757,8 +753,8 @@ void PrintGlyph( const int x, const int y, const int glyph ) } // Manual print of character. A lot faster than BitBlt, which must be avoided. - int index_src = (127-ySrc) * 16 * CONSOLE_FONT_GRID_X + xSrc; // font bitmap - int index_dst = (383-yDst) * 80 * CONSOLE_FONT_GRID_X + xDst; // debugger bitmap + int index_src = (CONSOLE_FONT_BITMAP_HEIGHT - 1 - ySrc) * CONSOLE_FONT_NUM_CHARS_PER_ROW * CONSOLE_FONT_GRID_X + xSrc; // font bitmap + int index_dst = (DISPLAY_HEIGHT - 1 - yDst) * DEBUG_VIRTUAL_TEXT_WIDTH * CONSOLE_FONT_GRID_X + xDst; // debugger bitmap for (int yy = 0; yy < CONSOLE_FONT_GRID_Y; yy++) { for (int xx = 0; xx < CONSOLE_FONT_GRID_X; xx++) @@ -768,8 +764,8 @@ void PrintGlyph( const int x, const int y, const int glyph ) g_pDebuggerMemFramebits[index_dst + xx].g = (g_cConsoleBrushBG_g & ~fontpx) | (g_cConsoleBrushFG_g & fontpx); g_pDebuggerMemFramebits[index_dst + xx].b = (g_cConsoleBrushBG_b & ~fontpx) | (g_cConsoleBrushFG_b & fontpx); } - index_src -= 16 * CONSOLE_FONT_GRID_X; - index_dst -= 80 * CONSOLE_FONT_GRID_X; + index_src -= CONSOLE_FONT_NUM_CHARS_PER_ROW * CONSOLE_FONT_GRID_X; + index_dst -= DEBUG_VIRTUAL_TEXT_WIDTH * CONSOLE_FONT_GRID_X; } } diff --git a/source/Debugger/Debugger_Display.h b/source/Debugger/Debugger_Display.h index 3afbe635..a5c6cd99 100644 --- a/source/Debugger/Debugger_Display.h +++ b/source/Debugger/Debugger_Display.h @@ -18,13 +18,17 @@ CONSOLE_FONT_WIDTH = 7, CONSOLE_FONT_HEIGHT = 8, + CONSOLE_FONT_NUM_CHARS_PER_ROW = 16, + CONSOLE_FONT_NUM_ROWS = 16, + + CONSOLE_FONT_BITMAP_WIDTH = CONSOLE_FONT_WIDTH * CONSOLE_FONT_NUM_CHARS_PER_ROW, // 112 pixels + CONSOLE_FONT_BITMAP_HEIGHT = CONSOLE_FONT_HEIGHT * CONSOLE_FONT_NUM_ROWS, // 128 pixels }; extern HBRUSH g_hConsoleBrushFG; extern HBRUSH g_hConsoleBrushBG; extern HDC g_hConsoleFontDC; - extern HBRUSH g_hConsoleFontBrush; extern HBITMAP g_hConsoleFontBitmap; enum @@ -42,7 +46,6 @@ void FillBackground(long left, long top, long right, long bottom); - void PrintGlyph ( const int x, const int y, const int iChar ); int PrintText ( const char * pText, RECT & rRect ); int PrintTextCursorX( const char * pText, RECT & rRect ); int PrintTextCursorY( const char * pText, RECT & rRect );