diff --git a/source/CardManager.cpp b/source/CardManager.cpp index 2cb25465..a3181d7f 100644 --- a/source/CardManager.cpp +++ b/source/CardManager.cpp @@ -120,12 +120,6 @@ void CardManager::RemoveInternal(UINT slot) m_slot[slot] = NULL; } -void CardManager::RemoveAuxInternal() -{ - delete m_aux; - m_aux = NULL; -} - void CardManager::Remove(UINT slot) { RemoveInternal(slot); @@ -159,6 +153,12 @@ void CardManager::InsertAux(SS_CARDTYPE type) _ASSERT(m_aux != NULL); } +void CardManager::RemoveAuxInternal() +{ + delete m_aux; + m_aux = NULL; +} + void CardManager::RemoveAux(void) { RemoveAuxInternal(); diff --git a/source/CardManager.h b/source/CardManager.h index 367cafae..e152f645 100644 --- a/source/CardManager.h +++ b/source/CardManager.h @@ -53,7 +53,7 @@ public: private: void RemoveInternal(UINT slot); - void RemoveAuxInternal(); + void RemoveAuxInternal(void); Card* m_slot[NUM_SLOTS]; Card* m_aux; diff --git a/source/Configuration/PropertySheetHelper.cpp b/source/Configuration/PropertySheetHelper.cpp index 97bb0fa7..5a4249f9 100644 --- a/source/Configuration/PropertySheetHelper.cpp +++ b/source/Configuration/PropertySheetHelper.cpp @@ -158,7 +158,7 @@ std::string CPropertySheetHelper::BrowseToFile(HWND hWindow, TCHAR* pszTitle, TC std::string pathname = szFilename; OPENFILENAME ofn; - ZeroMemory(&ofn,sizeof(OPENFILENAME)); + memset(&ofn, 0, sizeof(OPENFILENAME)); ofn.lStructSize = sizeof(OPENFILENAME); ofn.hwndOwner = hWindow; @@ -205,7 +205,7 @@ int CPropertySheetHelper::SaveStateSelectImage(HWND hWindow, TCHAR* pszTitle, bo // OPENFILENAME ofn; - ZeroMemory(&ofn,sizeof(OPENFILENAME)); + memset(&ofn, 0, sizeof(OPENFILENAME)); ofn.lStructSize = sizeof(OPENFILENAME); ofn.hwndOwner = hWindow; diff --git a/source/Debugger/Debug.cpp b/source/Debugger/Debug.cpp index 4819a5a3..e92cb623 100644 --- a/source/Debugger/Debug.cpp +++ b/source/Debugger/Debug.cpp @@ -8831,7 +8831,7 @@ void DebugInitialize () GetConsoleFontDC(); // Load font - ZeroMemory( g_aConsoleDisplay, sizeof( g_aConsoleDisplay ) ); // CONSOLE_WIDTH * CONSOLE_HEIGHT ); + memset( g_aConsoleDisplay, 0, sizeof( g_aConsoleDisplay ) ); // CONSOLE_WIDTH * CONSOLE_HEIGHT ); ConsoleInputReset(); for( int iWindow = 0; iWindow < NUM_WINDOWS; iWindow++ ) @@ -8853,9 +8853,9 @@ void DebugInitialize () WindowUpdateConsoleDisplayedSize(); // CLEAR THE BREAKPOINT AND WATCH TABLES - ZeroMemory( g_aBreakpoints , MAX_BREAKPOINTS * sizeof(Breakpoint_t)); - ZeroMemory( g_aWatches , MAX_WATCHES * sizeof(Watches_t) ); - ZeroMemory( g_aZeroPagePointers, MAX_ZEROPAGE_POINTERS * sizeof(ZeroPagePointers_t)); + memset( g_aBreakpoints , 0, MAX_BREAKPOINTS * sizeof(Breakpoint_t)); + memset( g_aWatches , 0, MAX_WATCHES * sizeof(Watches_t) ); + memset( g_aZeroPagePointers, 0, MAX_ZEROPAGE_POINTERS * sizeof(ZeroPagePointers_t)); // Load Main, Applesoft, and User Symbols extern bool g_bSymbolsDisplayMissingFile; diff --git a/source/Debugger/Debugger_Console.cpp b/source/Debugger/Debugger_Console.cpp index c291d510..4c38d320 100644 --- a/source/Debugger/Debugger_Console.cpp +++ b/source/Debugger/Debugger_Console.cpp @@ -462,7 +462,7 @@ bool ConsoleInputBackSpace () //=========================================================================== bool ConsoleInputClear () { - ZeroMemory( g_aConsoleInput, CONSOLE_WIDTH ); + memset( g_aConsoleInput, 0, CONSOLE_WIDTH ); if (g_nConsoleInputChars) { diff --git a/source/Debugger/Debugger_Display.cpp b/source/Debugger/Debugger_Display.cpp index f2ac73f4..1977f5bb 100644 --- a/source/Debugger/Debugger_Display.cpp +++ b/source/Debugger/Debugger_Display.cpp @@ -557,13 +557,9 @@ HDC GetDebuggerMemDC(void) g_hDebuggerMemDC = CreateCompatibleDC(hFrameDC); // CREATE A BITMAPINFO STRUCTURE FOR THE FRAME BUFFER - g_pDebuggerMemFramebufferinfo = (LPBITMAPINFO)VirtualAlloc( - NULL, - sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD), - MEM_COMMIT, - PAGE_READWRITE); + g_pDebuggerMemFramebufferinfo = (LPBITMAPINFO) new BYTE[sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD)]; - ZeroMemory(g_pDebuggerMemFramebufferinfo, sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD)); + memset(g_pDebuggerMemFramebufferinfo, 0, sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD)); g_pDebuggerMemFramebufferinfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); g_pDebuggerMemFramebufferinfo->bmiHeader.biWidth = 560; g_pDebuggerMemFramebufferinfo->bmiHeader.biHeight = 384; @@ -598,7 +594,7 @@ void ReleaseDebuggerMemDC(void) FrameReleaseDC(); - VirtualFree(g_pDebuggerMemFramebufferinfo, 0, MEM_RELEASE); + delete [] g_pDebuggerMemFramebufferinfo; g_pDebuggerMemFramebufferinfo = NULL; g_pDebuggerMemFramebits = NULL; } @@ -613,13 +609,9 @@ HDC GetConsoleFontDC(void) g_hConsoleFontDC = CreateCompatibleDC(hFrameDC); // CREATE A BITMAPINFO STRUCTURE FOR THE FRAME BUFFER - g_hConsoleFontFramebufferinfo = (LPBITMAPINFO)VirtualAlloc( - NULL, - sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD), - MEM_COMMIT, - PAGE_READWRITE); + g_hConsoleFontFramebufferinfo = (LPBITMAPINFO) new BYTE[sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD)]; - ZeroMemory(g_hConsoleFontFramebufferinfo, sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD)); + memset(g_hConsoleFontFramebufferinfo, 0, sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD)); g_hConsoleFontFramebufferinfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); g_hConsoleFontFramebufferinfo->bmiHeader.biWidth = CONSOLE_FONT_BITMAP_WIDTH; g_hConsoleFontFramebufferinfo->bmiHeader.biHeight = CONSOLE_FONT_BITMAP_HEIGHT; @@ -664,7 +656,7 @@ void ReleaseConsoleFontDC(void) DeleteObject( g_hConsoleFontBitmap ); g_hConsoleFontBitmap = NULL; - VirtualFree(g_hConsoleFontFramebufferinfo, 0, MEM_RELEASE); + delete [] g_hConsoleFontFramebufferinfo; g_hConsoleFontFramebufferinfo = NULL; g_hConsoleFontFramebits = NULL; } @@ -3204,7 +3196,7 @@ void DrawSoftSwitches( int iSoftSwitch ) void DrawSourceLine( int iSourceLine, RECT &rect ) { char sLine[ CONSOLE_WIDTH ]; - ZeroMemory( sLine, CONSOLE_WIDTH ); + memset( sLine, 0, CONSOLE_WIDTH ); if ((iSourceLine >=0) && (iSourceLine < g_AssemblerSourceBuffer.GetNumLines() )) { diff --git a/source/Debugger/Debugger_Help.cpp b/source/Debugger/Debugger_Help.cpp index 97e097bb..c1d281ea 100644 --- a/source/Debugger/Debugger_Help.cpp +++ b/source/Debugger/Debugger_Help.cpp @@ -571,8 +571,8 @@ Update_t CmdHelpSpecific (int nArgs) int iArg; char sText[ CONSOLE_WIDTH * 2 ]; char sTemp[ CONSOLE_WIDTH * 2 ]; - ZeroMemory( sText, CONSOLE_WIDTH*2 ); - ZeroMemory( sTemp, CONSOLE_WIDTH*2 ); + memset( sText, 0, CONSOLE_WIDTH*2 ); + memset( sTemp, 0, CONSOLE_WIDTH*2 ); if (! nArgs) { diff --git a/source/Debugger/Util_MemoryTextFile.cpp b/source/Debugger/Util_MemoryTextFile.cpp index 94ee4f2d..980d29c5 100644 --- a/source/Debugger/Util_MemoryTextFile.cpp +++ b/source/Debugger/Util_MemoryTextFile.cpp @@ -67,7 +67,7 @@ void MemoryTextFile_t::GetLine( const int iLine, char *pLine, const int nMaxLine GetLinePointers(); } - ZeroMemory( pLine, nMaxLineChars ); + memset( pLine, 0, nMaxLineChars ); strncpy( pLine, m_vLines[ iLine ], nMaxLineChars-1 ); } diff --git a/source/Disk.cpp b/source/Disk.cpp index cb00bca8..c1772c0e 100644 --- a/source/Disk.cpp +++ b/source/Disk.cpp @@ -1540,7 +1540,7 @@ bool Disk2InterfaceCard::UserSelectNewDiskImage(const int drive, LPCSTR pszFilen _ASSERT(sizeof(OPENFILENAME) == sizeof(OPENFILENAME_NT4)); // Required for Win98/ME support (selected by _WIN32_WINNT=0x0400 in stdafx.h) OPENFILENAME ofn; - ZeroMemory(&ofn,sizeof(OPENFILENAME)); + memset(&ofn, 0, sizeof(OPENFILENAME)); ofn.lStructSize = sizeof(OPENFILENAME); ofn.hwndOwner = g_hFrameWindow; ofn.hInstance = g_hInstance; diff --git a/source/DiskImage.cpp b/source/DiskImage.cpp index e3832c98..4ccc160c 100644 --- a/source/DiskImage.cpp +++ b/source/DiskImage.cpp @@ -46,9 +46,6 @@ ImageError_e ImageOpen( const std::string & pszImageFilename, std::string& strFilenameInZip, const bool bExpectFloppy /*=true*/) { - if (bExpectFloppy && sg_DiskImageHelper.GetWorkBuffer() == NULL) - return eIMAGE_ERROR_BAD_POINTER; - if (!(!pszImageFilename.empty() && ppImageInfo && pWriteProtected)) return eIMAGE_ERROR_BAD_POINTER; @@ -114,22 +111,6 @@ BOOL ImageBoot(ImageInfo* const pImageInfo) //=========================================================================== -void ImageDestroy(void) -{ - VirtualFree(sg_DiskImageHelper.GetWorkBuffer(), 0, MEM_RELEASE); - sg_DiskImageHelper.SetWorkBuffer(NULL); -} - -//=========================================================================== - -void ImageInitialize(void) -{ - LPBYTE pBuffer = (LPBYTE) VirtualAlloc(NULL, TRACK_DENIBBLIZED_SIZE*2, MEM_COMMIT, PAGE_READWRITE); - sg_DiskImageHelper.SetWorkBuffer(pBuffer); -} - -//=========================================================================== - void ImageReadTrack( ImageInfo* const pImageInfo, float phase, // phase [0..79] +/- 0.5 LPBYTE pTrackImageBuffer, diff --git a/source/DiskImage.h b/source/DiskImage.h index 3390527e..1d6a30e1 100644 --- a/source/DiskImage.h +++ b/source/DiskImage.h @@ -79,8 +79,6 @@ struct ImageInfo; ImageError_e ImageOpen(const std::string & pszImageFilename, ImageInfo** ppImageInfo, bool* pWriteProtected, const bool bCreateIfNecessary, std::string& strFilenameInZip, const bool bExpectFloppy=true); void ImageClose(ImageInfo* const pImageInfo); BOOL ImageBoot(ImageInfo* const pImageInfo); -void ImageDestroy(void); -void ImageInitialize(void); void ImageReadTrack(ImageInfo* const pImageInfo, float phase, LPBYTE pTrackImageBuffer, int* pNibbles, UINT* pBitCount, bool enhanceDisk); void ImageWriteTrack(ImageInfo* const pImageInfo, float phase, LPBYTE pTrackImageBuffer, int nNibbles); diff --git a/source/DiskImageHelper.cpp b/source/DiskImageHelper.cpp index 202725d7..66f3c061 100644 --- a/source/DiskImageHelper.cpp +++ b/source/DiskImageHelper.cpp @@ -52,7 +52,7 @@ ImageInfo::ImageInfo() uOffset = 0; bWriteProtected = false; uImageSize = 0; - ZeroMemory(&zipFileInfo, sizeof(zipFileInfo)); + memset(&zipFileInfo, 0, sizeof(zipFileInfo)); uNumEntriesInZip = 0; uNumValidImagesInZip = 0; uNumTracks = 0; @@ -63,6 +63,20 @@ ImageInfo::ImageInfo() maxNibblesPerTrack = 0; } +CImageBase::CImageBase() + : m_uNumTracksInImage(0) + , m_uVolumeNumber(DEFAULT_VOLUME_NUMBER) +{ + m_pWorkBuffer = new BYTE[TRACK_DENIBBLIZED_SIZE * 2]; +} + +CImageBase::~CImageBase() +{ + delete [] m_pWorkBuffer; + m_pWorkBuffer = NULL; +} + + /* DO logical order 0 1 2 3 4 5 6 7 8 9 A B C D E F */ /* physical order 0 D B 9 7 5 3 1 E C A 8 6 4 2 F */ @@ -88,8 +102,6 @@ BYTE CImageBase::ms_SectorNumber[NUM_SECTOR_ORDERS][0x10] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00} }; -LPBYTE CImageBase::ms_pWorkBuffer = NULL; - //----------------------------------------------------------------------------- bool CImageBase::WriteImageHeader(ImageInfo* pImageInfo, LPBYTE pHdr, const UINT hdrSize) @@ -287,8 +299,8 @@ LPBYTE CImageBase::Code62(int sector) // CONVERT THE 256 8-BIT BYTES INTO 342 6-BIT BYTES, WHICH WE STORE // STARTING AT 4K INTO THE WORK BUFFER. { - LPBYTE sectorbase = ms_pWorkBuffer+(sector << 8); - LPBYTE resultptr = ms_pWorkBuffer+TRACK_DENIBBLIZED_SIZE; + LPBYTE sectorbase = m_pWorkBuffer+(sector << 8); + LPBYTE resultptr = m_pWorkBuffer+TRACK_DENIBBLIZED_SIZE; BYTE offset = 0xAC; while (offset != 0x02) { @@ -314,8 +326,8 @@ LPBYTE CImageBase::Code62(int sector) // BLOCK OF 343 BYTES STARTING AT 5K INTO THE WORK BUFFER. { BYTE savedval = 0; - LPBYTE sourceptr = ms_pWorkBuffer+TRACK_DENIBBLIZED_SIZE; - LPBYTE resultptr = ms_pWorkBuffer+TRACK_DENIBBLIZED_SIZE+0x400; + LPBYTE sourceptr = m_pWorkBuffer+TRACK_DENIBBLIZED_SIZE; + LPBYTE resultptr = m_pWorkBuffer+TRACK_DENIBBLIZED_SIZE+0x400; int loop = 342; while (loop--) { @@ -331,14 +343,14 @@ LPBYTE CImageBase::Code62(int sector) // ZERO BITS. THE CONVERTED BLOCK OF 343 BYTES IS STORED STARTING AT 4K // INTO THE WORK BUFFER. { - LPBYTE sourceptr = ms_pWorkBuffer+TRACK_DENIBBLIZED_SIZE+0x400; - LPBYTE resultptr = ms_pWorkBuffer+TRACK_DENIBBLIZED_SIZE; + LPBYTE sourceptr = m_pWorkBuffer+TRACK_DENIBBLIZED_SIZE+0x400; + LPBYTE resultptr = m_pWorkBuffer+TRACK_DENIBBLIZED_SIZE; int loop = 343; while (loop--) *(resultptr++) = ms_DiskByte[(*(sourceptr++)) >> 2]; } - return ms_pWorkBuffer+TRACK_DENIBBLIZED_SIZE; + return m_pWorkBuffer+TRACK_DENIBBLIZED_SIZE; } //------------------------------------- @@ -351,7 +363,7 @@ void CImageBase::Decode62(LPBYTE imageptr) static BYTE sixbitbyte[0x80]; if (!tablegenerated) { - ZeroMemory(sixbitbyte,0x80); + memset(sixbitbyte, 0, 0x80); int loop = 0; while (loop < 0x40) { sixbitbyte[ms_DiskByte[loop]-0x80] = loop << 2; @@ -362,8 +374,8 @@ void CImageBase::Decode62(LPBYTE imageptr) // USING OUR TABLE, CONVERT THE DISK BYTES BACK INTO 6-BIT BYTES { - LPBYTE sourceptr = ms_pWorkBuffer+TRACK_DENIBBLIZED_SIZE; - LPBYTE resultptr = ms_pWorkBuffer+TRACK_DENIBBLIZED_SIZE+0x400; + LPBYTE sourceptr = m_pWorkBuffer+TRACK_DENIBBLIZED_SIZE; + LPBYTE resultptr = m_pWorkBuffer+TRACK_DENIBBLIZED_SIZE+0x400; int loop = 343; while (loop--) *(resultptr++) = sixbitbyte[*(sourceptr++) & 0x7F]; @@ -373,8 +385,8 @@ void CImageBase::Decode62(LPBYTE imageptr) // TO UNDO THE EFFECTS OF THE CHECKSUMMING PROCESS { BYTE savedval = 0; - LPBYTE sourceptr = ms_pWorkBuffer+TRACK_DENIBBLIZED_SIZE+0x400; - LPBYTE resultptr = ms_pWorkBuffer+TRACK_DENIBBLIZED_SIZE; + LPBYTE sourceptr = m_pWorkBuffer+TRACK_DENIBBLIZED_SIZE+0x400; + LPBYTE resultptr = m_pWorkBuffer+TRACK_DENIBBLIZED_SIZE; int loop = 342; while (loop--) { @@ -385,8 +397,8 @@ void CImageBase::Decode62(LPBYTE imageptr) // CONVERT THE 342 6-BIT BYTES INTO 256 8-BIT BYTES { - LPBYTE lowbitsptr = ms_pWorkBuffer+TRACK_DENIBBLIZED_SIZE; - LPBYTE sectorbase = ms_pWorkBuffer+TRACK_DENIBBLIZED_SIZE+0x56; + LPBYTE lowbitsptr = m_pWorkBuffer+TRACK_DENIBBLIZED_SIZE; + LPBYTE sectorbase = m_pWorkBuffer+TRACK_DENIBBLIZED_SIZE+0x56; BYTE offset = 0xAC; while (offset != 0x02) { @@ -417,7 +429,7 @@ void CImageBase::Decode62(LPBYTE imageptr) void CImageBase::DenibblizeTrack(LPBYTE trackimage, SectorOrder_e SectorOrder, int nibbles) { - ZeroMemory(ms_pWorkBuffer, TRACK_DENIBBLIZED_SIZE); + memset(m_pWorkBuffer, 0, TRACK_DENIBBLIZED_SIZE); // SEARCH THROUGH THE TRACK IMAGE FOR EACH SECTOR. FOR EVERY SECTOR // WE FIND, COPY THE NIBBLIZED DATA FOR THAT SECTOR INTO THE WORK @@ -455,15 +467,15 @@ void CImageBase::DenibblizeTrack(LPBYTE trackimage, SectorOrder_e SectorOrder, i int tempoffset = offset; while (loop < 384) // TODO-TC: Why 384? Only need 343 for Decode62() { - *(ms_pWorkBuffer+TRACK_DENIBBLIZED_SIZE+loop++) = *(trackimage+tempoffset++); + *(m_pWorkBuffer+TRACK_DENIBBLIZED_SIZE+loop++) = *(trackimage+tempoffset++); if (tempoffset >= nibbles) tempoffset = 0; } if (byteval[2] == 0x96) { - sector = ((*(ms_pWorkBuffer+TRACK_DENIBBLIZED_SIZE+4) & 0x55) << 1) - | (*(ms_pWorkBuffer+TRACK_DENIBBLIZED_SIZE+5) & 0x55); + sector = ((*(m_pWorkBuffer+TRACK_DENIBBLIZED_SIZE+4) & 0x55) << 1) + | (*(m_pWorkBuffer+TRACK_DENIBBLIZED_SIZE+5) & 0x55); #ifdef _DEBUG _ASSERT( sector < NUM_SECTORS ); @@ -482,7 +494,7 @@ void CImageBase::DenibblizeTrack(LPBYTE trackimage, SectorOrder_e SectorOrder, i uWriteDataFieldPrologueCount++; _ASSERT(uWriteDataFieldPrologueCount <= NUM_SECTORS); #endif - Decode62(ms_pWorkBuffer+(ms_SectorNumber[SectorOrder][sector] << 8)); + Decode62(m_pWorkBuffer+(ms_SectorNumber[SectorOrder][sector] << 8)); } sector = 0; } @@ -494,7 +506,7 @@ void CImageBase::DenibblizeTrack(LPBYTE trackimage, SectorOrder_e SectorOrder, i DWORD CImageBase::NibblizeTrack(LPBYTE trackimagebuffer, SectorOrder_e SectorOrder, int track) { - ZeroMemory(ms_pWorkBuffer+TRACK_DENIBBLIZED_SIZE, TRACK_DENIBBLIZED_SIZE); + memset(m_pWorkBuffer+TRACK_DENIBBLIZED_SIZE, 0, TRACK_DENIBBLIZED_SIZE); LPBYTE imageptr = trackimagebuffer; BYTE sector = 0; @@ -563,9 +575,9 @@ DWORD CImageBase::NibblizeTrack(LPBYTE trackimagebuffer, SectorOrder_e SectorOrd void CImageBase::SkewTrack(const int nTrack, const int nNumNibbles, const LPBYTE pTrackImageBuffer) { int nSkewBytes = (nTrack*768) % nNumNibbles; - CopyMemory(ms_pWorkBuffer, pTrackImageBuffer, nNumNibbles); - CopyMemory(pTrackImageBuffer, ms_pWorkBuffer+nSkewBytes, nNumNibbles-nSkewBytes); - CopyMemory(pTrackImageBuffer+nNumNibbles-nSkewBytes, ms_pWorkBuffer, nSkewBytes); + CopyMemory(m_pWorkBuffer, pTrackImageBuffer, nNumNibbles); + CopyMemory(pTrackImageBuffer, m_pWorkBuffer+nSkewBytes, nNumNibbles-nSkewBytes); + CopyMemory(pTrackImageBuffer+nNumNibbles-nSkewBytes, m_pWorkBuffer, nSkewBytes); } //------------------------------------- @@ -647,7 +659,7 @@ public: virtual void Read(ImageInfo* pImageInfo, const float phase, LPBYTE pTrackImageBuffer, int* pNibbles, UINT* pBitCount, bool enhanceDisk) { const UINT track = PhaseToTrack(phase); - ReadTrack(pImageInfo, track, ms_pWorkBuffer, TRACK_DENIBBLIZED_SIZE); + ReadTrack(pImageInfo, track, m_pWorkBuffer, TRACK_DENIBBLIZED_SIZE); *pNibbles = NibblizeTrack(pTrackImageBuffer, eDOSOrder, track); if (!enhanceDisk) SkewTrack(track, *pNibbles, pTrackImageBuffer); @@ -657,7 +669,7 @@ public: { const UINT track = PhaseToTrack(phase); DenibblizeTrack(pTrackImageBuffer, eDOSOrder, nNibbles); - WriteTrack(pImageInfo, track, ms_pWorkBuffer, TRACK_DENIBBLIZED_SIZE); + WriteTrack(pImageInfo, track, m_pWorkBuffer, TRACK_DENIBBLIZED_SIZE); } virtual bool AllowCreate(void) { return true; } @@ -715,7 +727,7 @@ public: virtual void Read(ImageInfo* pImageInfo, const float phase, LPBYTE pTrackImageBuffer, int* pNibbles, UINT* pBitCount, bool enhanceDisk) { const UINT track = PhaseToTrack(phase); - ReadTrack(pImageInfo, track, ms_pWorkBuffer, TRACK_DENIBBLIZED_SIZE); + ReadTrack(pImageInfo, track, m_pWorkBuffer, TRACK_DENIBBLIZED_SIZE); *pNibbles = NibblizeTrack(pTrackImageBuffer, eProDOSOrder, track); if (!enhanceDisk) SkewTrack(track, *pNibbles, pTrackImageBuffer); @@ -725,7 +737,7 @@ public: { const UINT track = PhaseToTrack(phase); DenibblizeTrack(pTrackImageBuffer, eProDOSOrder, nNibbles); - WriteTrack(pImageInfo, track, ms_pWorkBuffer, TRACK_DENIBBLIZED_SIZE); + WriteTrack(pImageInfo, track, m_pWorkBuffer, TRACK_DENIBBLIZED_SIZE); } virtual eImageType GetType(void) { return eImagePO; } @@ -905,13 +917,8 @@ public: // IF WE HAVEN'T ALREADY DONE SO, READ THE IMAGE FILE HEADER if (!m_pHeader) { - m_pHeader = (LPBYTE) VirtualAlloc(NULL, 88, MEM_COMMIT, PAGE_READWRITE); - if (!m_pHeader) - { - *pNibbles = 0; - return; - } - ZeroMemory(m_pHeader, 88); + m_pHeader = new BYTE[88]; + memset(m_pHeader, 0, 88); DWORD dwBytesRead; SetFilePointer(pImageInfo->hFile, 0, NULL,FILE_BEGIN); ReadFile(pImageInfo->hFile, m_pHeader, 88, &dwBytesRead, NULL); @@ -922,9 +929,9 @@ public: { ConvertSectorOrder(m_pHeader+14); SetFilePointer(pImageInfo->hFile, track*TRACK_DENIBBLIZED_SIZE+30, NULL, FILE_BEGIN); - ZeroMemory(ms_pWorkBuffer, TRACK_DENIBBLIZED_SIZE); + memset(m_pWorkBuffer, 0, TRACK_DENIBBLIZED_SIZE); DWORD bytesread; - ReadFile(pImageInfo->hFile, ms_pWorkBuffer, TRACK_DENIBBLIZED_SIZE, &bytesread, NULL); + ReadFile(pImageInfo->hFile, m_pWorkBuffer, TRACK_DENIBBLIZED_SIZE, &bytesread, NULL); *pNibbles = NibblizeTrack(pTrackImageBuffer, eSIMSYSTEMOrder, track); } // OTHERWISE, IF THIS IMAGE CONTAINS NIBBLE INFORMATION, READ IT DIRECTLY INTO THE TRACK BUFFER @@ -935,7 +942,7 @@ public: while (track--) Offset += *(LPWORD)(m_pHeader+track*2+14); SetFilePointer(pImageInfo->hFile, Offset, NULL,FILE_BEGIN); - ZeroMemory(pTrackImageBuffer, *pNibbles); + memset(pTrackImageBuffer, 0, *pNibbles); DWORD dwBytesRead; ReadFile(pImageInfo->hFile, pTrackImageBuffer, *pNibbles, &dwBytesRead, NULL); } @@ -1855,7 +1862,7 @@ ImageError_e CImageHelperBase::CheckNormalFile(LPCTSTR pszImageFilename, ImageIn } else { - ZeroMemory(pImageInfo->pImageBuffer, dwSize); + memset(pImageInfo->pImageBuffer, 0, dwSize); } } diff --git a/source/DiskImageHelper.h b/source/DiskImageHelper.h index 5576858b..38ecddbf 100644 --- a/source/DiskImageHelper.h +++ b/source/DiskImageHelper.h @@ -56,8 +56,8 @@ struct ImageInfo class CImageBase { public: - CImageBase(void) : m_uNumTracksInImage(0), m_uVolumeNumber(DEFAULT_VOLUME_NUMBER) {} - virtual ~CImageBase(void) {} + CImageBase(void); + virtual ~CImageBase(void); virtual bool Boot(ImageInfo* pImageInfo) { return false; } virtual eDetectResult Detect(const LPBYTE pImage, const DWORD dwImageSize, const TCHAR* pszExt) = 0; @@ -100,13 +100,13 @@ protected: void SkewTrack (const int nTrack, const int nNumNibbles, const LPBYTE pTrackImageBuffer); public: - static LPBYTE ms_pWorkBuffer; UINT m_uNumTracksInImage; // Init'd by CDiskImageHelper.Detect()/GetImageForCreation() & possibly updated by IsValidImageSize() protected: static BYTE ms_DiskByte[0x40]; static BYTE ms_SectorNumber[NUM_SECTOR_ORDERS][NUM_SECTORS]; BYTE m_uVolumeNumber; + LPBYTE m_pWorkBuffer; }; //------------------------------------- @@ -425,9 +425,6 @@ public: UINT GetNumTracksInImage(CImageBase* pImageType) { return pImageType->m_uNumTracksInImage; } void SetNumTracksInImage(CImageBase* pImageType, UINT uNumTracks) { pImageType->m_uNumTracksInImage = uNumTracks; } - LPBYTE GetWorkBuffer(void) { return CImageBase::ms_pWorkBuffer; } - void SetWorkBuffer(LPBYTE pBuffer) { CImageBase::ms_pWorkBuffer = pBuffer; } - private: void SkipMacBinaryHdr(LPBYTE& pImage, DWORD& dwSize, DWORD& dwOffset); diff --git a/source/Harddisk.cpp b/source/Harddisk.cpp index 774afd1b..6b3a7067 100644 --- a/source/Harddisk.cpp +++ b/source/Harddisk.cpp @@ -125,7 +125,7 @@ struct HDD void clear() { // This is not a POD (there is a std::string) - // ZeroMemory does not work + // memset(0) does not work imagename.clear(); fullname.clear(); strFilenameInZip.clear(); @@ -136,7 +136,7 @@ struct HDD hd_diskblock = 0; hd_buf_ptr = 0; hd_imageloaded = false; - ZeroMemory(hd_buf, sizeof(hd_buf)); + memset(hd_buf, 0, sizeof(hd_buf)); #if HD_LED hd_status_next = DISK_STATUS_OFF; hd_status_prev = DISK_STATUS_OFF; @@ -463,7 +463,7 @@ static bool HD_SelectImage(const int drive, LPCSTR pszFilename) _ASSERT(sizeof(OPENFILENAME) == sizeof(OPENFILENAME_NT4)); // Required for Win98/ME support (selected by _WIN32_WINNT=0x0400 in stdafx.h) OPENFILENAME ofn; - ZeroMemory(&ofn,sizeof(OPENFILENAME)); + memset(&ofn, 0, sizeof(OPENFILENAME)); ofn.lStructSize = sizeof(OPENFILENAME); ofn.hwndOwner = g_hFrameWindow; ofn.hInstance = g_hInstance; @@ -584,7 +584,7 @@ static BYTE __stdcall HD_IO_EMUL(WORD pc, WORD addr, BYTE bWrite, BYTE d, ULONG if (bAppendBlocks) { - ZeroMemory(pHDD->hd_buf, HD_BLOCK_SIZE); + memset(pHDD->hd_buf, 0, HD_BLOCK_SIZE); // Inefficient (especially for gzip/zip files!) UINT uBlock = ImageGetImageSize(pHDD->imagehandle) / HD_BLOCK_SIZE; diff --git a/source/LanguageCard.cpp b/source/LanguageCard.cpp index a362e8df..6dbf1ed8 100644 --- a/source/LanguageCard.cpp +++ b/source/LanguageCard.cpp @@ -139,13 +139,13 @@ bool LanguageCardUnit::IsOpcodeRMWabs(WORD addr) LanguageCardSlot0::LanguageCardSlot0(SS_CARDTYPE type/*=CT_LanguageCard*/) : LanguageCardUnit(type) { - m_pMemory = (LPBYTE)VirtualAlloc(NULL, kMemBankSize, MEM_COMMIT, PAGE_READWRITE); + m_pMemory = new BYTE[kMemBankSize]; SetMemMainLanguageCard(m_pMemory); } LanguageCardSlot0::~LanguageCardSlot0(void) { - VirtualFree(m_pMemory, 0, MEM_RELEASE); + delete [] m_pMemory; m_pMemory = NULL; } @@ -218,9 +218,7 @@ bool LanguageCardSlot0::LoadSnapshot(YamlLoadHelper& yamlLoadHelper, UINT slot, if (!m_pMemory) { - m_pMemory = (LPBYTE) VirtualAlloc(NULL, kMemBankSize, MEM_COMMIT, PAGE_READWRITE); - if (!m_pMemory) - throw std::string("Card: mem alloc failed"); + m_pMemory = new BYTE[kMemBankSize]; } if (!yamlLoadHelper.GetSubMap(GetSnapshotMemStructName())) @@ -249,7 +247,7 @@ Saturn128K::Saturn128K(UINT banks) m_aSaturnBanks[0] = m_pMemory; // Reuse memory allocated in base ctor for (UINT i = 1; i < m_uSaturnTotalBanks; i++) - m_aSaturnBanks[i] = (LPBYTE) VirtualAlloc(NULL, kMemBankSize, MEM_COMMIT, PAGE_READWRITE); // Saturn banks are 16K, max 8 banks/card + m_aSaturnBanks[i] = new BYTE[kMemBankSize]; // Saturn banks are 16K, max 8 banks/card SetMemMainLanguageCard( m_aSaturnBanks[ m_uSaturnActiveBank ] ); } @@ -262,7 +260,7 @@ Saturn128K::~Saturn128K(void) { if (m_aSaturnBanks[i]) { - VirtualFree(m_aSaturnBanks[i], 0, MEM_RELEASE); + delete [] m_aSaturnBanks[i]; m_aSaturnBanks[i] = NULL; } } @@ -435,12 +433,9 @@ bool Saturn128K::LoadSnapshot(YamlLoadHelper& yamlLoadHelper, UINT slot, UINT ve for(UINT uBank = 0; uBank < m_uSaturnTotalBanks; uBank++) { - LPBYTE pBank = m_aSaturnBanks[uBank]; - if (!pBank) + if (!m_aSaturnBanks[uBank]) { - pBank = m_aSaturnBanks[uBank] = (LPBYTE) VirtualAlloc(NULL, kMemBankSize, MEM_COMMIT, PAGE_READWRITE); - if (!pBank) - throw std::string("Card: mem alloc failed"); + m_aSaturnBanks[uBank] = new BYTE[kMemBankSize]; } // "Memory Bankxx" @@ -451,7 +446,7 @@ bool Saturn128K::LoadSnapshot(YamlLoadHelper& yamlLoadHelper, UINT slot, UINT ve if (!yamlLoadHelper.GetSubMap(memName)) throw std::string("Memory: Missing map name: " + memName); - yamlLoadHelper.LoadMemory(pBank, kMemBankSize); + yamlLoadHelper.LoadMemory(m_aSaturnBanks[uBank], kMemBankSize); yamlLoadHelper.PopMap(); } diff --git a/source/Memory.cpp b/source/Memory.cpp index aeae07f1..7dd4e556 100644 --- a/source/Memory.cpp +++ b/source/Memory.cpp @@ -61,6 +61,23 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include "Debugger/DebugDefs.h" #include "YamlHelper.h" +// In this file allocate the 64KB of RAM with aligned memory allocations (0x10000) +// to ease mapping between Apple ][ and host memory space (while debugging). + +// this is not available in Visual Studio +// https://en.cppreference.com/w/c/memory/aligned_alloc + +#ifdef _MSC_VER +// VirtualAlloc is aligned +#define ALIGNED_ALLOC(size) (LPBYTE)VirtualAlloc(NULL, size, MEM_COMMIT, PAGE_READWRITE) +#define ALIGNED_FREE(ptr) VirtualFree(ptr, 0, MEM_RELEASE) +#else +// use plain "new" in gcc (where debugging needs are less important) +#define ALIGNED_ALLOC(size) new BYTE[size] +#define ALIGNED_FREE(ptr) delete [] ptr +#endif + + // UTAIIe:5-28 (GH#419) // . Sather uses INTCXROM instead of SLOTCXROM' (used by the Apple//e Tech Ref Manual), so keep to this // convention too since UTAIIe is the reference for most of the logic that we implement in the emulator. @@ -1244,21 +1261,22 @@ static void UpdatePaging(BOOL initialize) void MemDestroy() { - VirtualFree(memaux ,0,MEM_RELEASE); - VirtualFree(memmain ,0,MEM_RELEASE); - VirtualFree(memdirty,0,MEM_RELEASE); - VirtualFree(memrom ,0,MEM_RELEASE); - VirtualFree(memimage,0,MEM_RELEASE); + ALIGNED_FREE(memaux); + ALIGNED_FREE(memmain); + ALIGNED_FREE(memimage); - VirtualFree(pCxRomInternal,0,MEM_RELEASE); - VirtualFree(pCxRomPeripheral,0,MEM_RELEASE); + delete [] memdirty; + delete [] memrom; + + delete [] pCxRomInternal; + delete [] pCxRomPeripheral; #ifdef RAMWORKS for (UINT i=1; iGetCaps(&DSCaps); if(FAILED(hr)) diff --git a/source/Windows/AppleWin.cpp b/source/Windows/AppleWin.cpp index 91a66d7d..a8c52ebe 100644 --- a/source/Windows/AppleWin.cpp +++ b/source/Windows/AppleWin.cpp @@ -770,9 +770,6 @@ static void OneTimeInitialization(HINSTANCE passinstance) FrameRegisterClass(); LogFileOutput("Init: FrameRegisterClass()\n"); - - ImageInitialize(); - LogFileOutput("Init: ImageInitialize()\n"); } // DO INITIALIZATION THAT MUST BE REPEATED FOR A RESTART diff --git a/source/Windows/DirectInput.cpp b/source/Windows/DirectInput.cpp index 86597a67..6a1a3ec7 100644 --- a/source/Windows/DirectInput.cpp +++ b/source/Windows/DirectInput.cpp @@ -222,7 +222,7 @@ namespace DIMouse return S_OK; // Get the input's device state, and put the state in dims - ZeroMemory( &dims2, sizeof(dims2) ); + memset( &dims2, 0, sizeof(dims2) ); hr = g_pMouse->GetDeviceState( sizeof(DIMOUSESTATE2), &dims2 ); if( FAILED(hr) ) { diff --git a/source/Windows/WinFrame.cpp b/source/Windows/WinFrame.cpp index 5922d61a..c774cf53 100644 --- a/source/Windows/WinFrame.cpp +++ b/source/Windows/WinFrame.cpp @@ -284,7 +284,7 @@ static void FullScreenRevealCursor(void) static void CreateGdiObjects(void) { - ZeroMemory(buttonbitmap, BUTTONS*sizeof(HBITMAP)); + memset(buttonbitmap, 0, BUTTONS*sizeof(HBITMAP)); buttonbitmap[BTN_HELP] = (HBITMAP)LOADBUTTONBITMAP(TEXT("HELP_BUTTON")); @@ -1059,7 +1059,6 @@ LRESULT CALLBACK FrameWndProc ( DebugDestroy(); if (!g_bRestart) { GetCardMgr().GetDisk2CardMgr().Destroy(); - ImageDestroy(); HD_Destroy(); } PrintDestroy(); @@ -2584,7 +2583,7 @@ void FrameRefreshStatus (int drawflags, bool bUpdateDiskStatus) { //=========================================================================== void FrameRegisterClass () { WNDCLASSEX wndclass; - ZeroMemory(&wndclass,sizeof(WNDCLASSEX)); + memset(&wndclass, 0, sizeof(WNDCLASSEX)); wndclass.cbSize = sizeof(WNDCLASSEX); wndclass.style = CS_OWNDC | CS_BYTEALIGNCLIENT; wndclass.lpfnWndProc = FrameWndProc; diff --git a/source/Windows/WinVideo.cpp b/source/Windows/WinVideo.cpp index 9fbffa91..c0d4e86e 100644 --- a/source/Windows/WinVideo.cpp +++ b/source/Windows/WinVideo.cpp @@ -73,7 +73,7 @@ static void videoCreateDIBSection() SelectObject(g_hDeviceDC, g_hDeviceBitmap); // DRAW THE SOURCE IMAGE INTO THE SOURCE BIT BUFFER - ZeroMemory(g_pFramebufferbits, GetFrameBufferWidth() * GetFrameBufferHeight() * sizeof(bgra_t)); + memset(g_pFramebufferbits, 0, GetFrameBufferWidth() * GetFrameBufferHeight() * sizeof(bgra_t)); // CREATE THE OFFSET TABLE FOR EACH SCAN LINE IN THE FRAME BUFFER NTSC_VideoInit(g_pFramebufferbits); @@ -92,13 +92,9 @@ void WinVideoInitialize() g_hLogoBitmap = LoadBitmap(g_hInstance, MAKEINTRESOURCE(IDB_APPLEWIN)); // CREATE A BITMAPINFO STRUCTURE FOR THE FRAME BUFFER - g_pFramebufferinfo = (LPBITMAPINFO)VirtualAlloc( - NULL, - sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD), - MEM_COMMIT, - PAGE_READWRITE); + g_pFramebufferinfo = (LPBITMAPINFO) new BYTE[sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD)]; - ZeroMemory(g_pFramebufferinfo, sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD)); + memset(g_pFramebufferinfo, 0, sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD)); g_pFramebufferinfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); g_pFramebufferinfo->bmiHeader.biWidth = GetFrameBufferWidth(); g_pFramebufferinfo->bmiHeader.biHeight = GetFrameBufferHeight(); @@ -114,7 +110,7 @@ void WinVideoDestroy() { // DESTROY BUFFERS - VirtualFree(g_pFramebufferinfo, 0, MEM_RELEASE); + delete [] g_pFramebufferinfo; g_pFramebufferinfo = NULL; // DESTROY FRAME BUFFER @@ -312,7 +308,7 @@ void VideoBenchmark () { void VideoChooseMonochromeColor () { CHOOSECOLOR cc; - ZeroMemory(&cc,sizeof(CHOOSECOLOR)); + memset(&cc, 0, sizeof(CHOOSECOLOR)); cc.lStructSize = sizeof(CHOOSECOLOR); cc.hwndOwner = g_hFrameWindow; cc.rgbResult = g_nMonochromeRGB; diff --git a/source/YamlHelper.cpp b/source/YamlHelper.cpp index 8c819117..f6a4c366 100644 --- a/source/YamlHelper.cpp +++ b/source/YamlHelper.cpp @@ -51,10 +51,14 @@ void YamlHelper::FinaliseParser(void) fclose(m_hFile); m_hFile = NULL; + + yaml_event_delete(&m_newEvent); + yaml_parser_delete(&m_parser); } -void YamlHelper::GetNextEvent(bool bInMap /*= false*/) +void YamlHelper::GetNextEvent(void) { + yaml_event_delete(&m_newEvent); if (!yaml_parser_parse(&m_parser, &m_newEvent)) { std::string error = std::string("Save-state parser error: "); @@ -116,13 +120,13 @@ int YamlHelper::ParseMap(MapYaml& mapYaml) const char*& pValue = (const char*&) m_newEvent.data.scalar.value; bool bKey = true; - char* pKey = NULL; + std::string pKey; int res = 1; bool bDone = false; while (!bDone) { - GetNextEvent(true); + GetNextEvent(); switch(m_newEvent.type) { @@ -135,7 +139,7 @@ int YamlHelper::ParseMap(MapYaml& mapYaml) MapValue mapValue; mapValue.value = ""; mapValue.subMap = new MapYaml; - mapYaml[std::string(pKey)] = mapValue; + mapYaml[pKey] = mapValue; res = ParseMap(*mapValue.subMap); if (!res) throw std::string("ParseMap: premature end of file during map parsing"); @@ -148,15 +152,16 @@ int YamlHelper::ParseMap(MapYaml& mapYaml) case YAML_SCALAR_EVENT: if (bKey) { - pKey = _strdup(pValue); + _ASSERT(pValue); // std::string(NULL) generates AccessViolation + pKey = pValue; } else { MapValue mapValue; mapValue.value = pValue; mapValue.subMap = NULL; - mapYaml[std::string(pKey)] = mapValue; - free(pKey); pKey = NULL; + mapYaml[pKey] = mapValue; + pKey.clear(); } bKey = bKey ? false : true; @@ -167,13 +172,10 @@ int YamlHelper::ParseMap(MapYaml& mapYaml) } } - if (pKey) - free(pKey); - return res; } -std::string YamlHelper::GetMapValue(MapYaml& mapYaml, const std::string key, bool& bFound) +std::string YamlHelper::GetMapValue(MapYaml& mapYaml, const std::string& key, bool& bFound) { MapYaml::const_iterator iter = mapYaml.find(key); if (iter == mapYaml.end() || iter->second.subMap != NULL) @@ -190,7 +192,7 @@ std::string YamlHelper::GetMapValue(MapYaml& mapYaml, const std::string key, boo return value; } -bool YamlHelper::GetSubMap(MapYaml** mapYaml, const std::string key) +bool YamlHelper::GetSubMap(MapYaml** mapYaml, const std::string& key) { MapYaml::const_iterator iter = (*mapYaml)->find(key); if (iter == (*mapYaml)->end() || iter->second.subMap == NULL) @@ -349,7 +351,7 @@ std::string YamlLoadHelper::LoadString(const std::string& key) return value; } -float YamlLoadHelper::LoadFloat(const std::string key) +float YamlLoadHelper::LoadFloat(const std::string& key) { bool bFound; std::string value = m_yamlHelper.GetMapValue(*m_pMapYaml, key, bFound); @@ -365,7 +367,7 @@ float YamlLoadHelper::LoadFloat(const std::string key) #endif } -double YamlLoadHelper::LoadDouble(const std::string key) +double YamlLoadHelper::LoadDouble(const std::string& key) { bool bFound; std::string value = m_yamlHelper.GetMapValue(*m_pMapYaml, key, bFound); @@ -575,7 +577,7 @@ void YamlSaveHelper::FileHdr(UINT version) SaveInt(SS_YAML_KEY_VERSION, version); } -void YamlSaveHelper::UnitHdr(std::string type, UINT version) +void YamlSaveHelper::UnitHdr(const std::string& type, UINT version) { fprintf(m_hFile, "\n%s:\n", SS_YAML_KEY_UNIT); m_indent = 2; diff --git a/source/YamlHelper.h b/source/YamlHelper.h index be5c23c6..69a38d5e 100644 --- a/source/YamlHelper.h +++ b/source/YamlHelper.h @@ -30,13 +30,13 @@ public: m_hFile(NULL) { memset(&m_parser, 0, sizeof(m_parser)); + memset(&m_newEvent, 0, sizeof(m_newEvent)); MakeAsciiToHexTable(); } ~YamlHelper(void) { - if (m_hFile) - fclose(m_hFile); + FinaliseParser(); } int InitParser(const char* pPathname); @@ -46,11 +46,11 @@ public: void GetMapStartEvent(void); private: - void GetNextEvent(bool bInMap = false); + void GetNextEvent(void); int ParseMap(MapYaml& mapYaml); - std::string GetMapValue(MapYaml& mapYaml, const std::string key, bool& bFound); + std::string GetMapValue(MapYaml& mapYaml, const std::string &key, bool& bFound); UINT LoadMemory(MapYaml& mapYaml, const LPBYTE pMemBase, const size_t kAddrSpaceSize); - bool GetSubMap(MapYaml** mapYaml, const std::string key); + bool GetSubMap(MapYaml** mapYaml, const std::string &key); void GetMapRemainder(std::string& mapName, MapYaml& mapYaml); void MakeAsciiToHexTable(void); @@ -98,12 +98,12 @@ public: bool LoadBool(const std::string key); std::string LoadString_NoThrow(const std::string& key, bool& bFound); std::string LoadString(const std::string& key); - float LoadFloat(const std::string key); - double LoadDouble(const std::string key); + float LoadFloat(const std::string & key); + double LoadDouble(const std::string & key); void LoadMemory(const LPBYTE pMemBase, const size_t size); void LoadMemory(std::vector& memory, const size_t size); - bool GetSubMap(const std::string key) + bool GetSubMap(const std::string & key) { YamlStackItem item = {m_pMapYaml, m_currentMapName}; m_stackMap.push(item); @@ -170,7 +170,7 @@ private: class YamlSaveHelper { public: - YamlSaveHelper(std::string pathname) : + YamlSaveHelper(const std::string & pathname) : m_hFile(NULL), m_indent(0), m_pWcStr(NULL), @@ -259,7 +259,7 @@ public: class Slot : public Label { public: - Slot(YamlSaveHelper& rYamlSaveHelper, std::string type, UINT slot, UINT version) : + Slot(YamlSaveHelper& rYamlSaveHelper, const std::string & type, UINT slot, UINT version) : Label(rYamlSaveHelper, "%d:\n", slot) { rYamlSaveHelper.Save("%s: %s\n", SS_YAML_KEY_CARD, type.c_str()); @@ -270,7 +270,7 @@ public: }; void FileHdr(UINT version); - void UnitHdr(std::string type, UINT version); + void UnitHdr(const std::string & type, UINT version); private: FILE* m_hFile; diff --git a/test/TestCPU6502/TestCPU6502.cpp b/test/TestCPU6502/TestCPU6502.cpp index 05289c27..2c3cf3a5 100644 --- a/test/TestCPU6502/TestCPU6502.cpp +++ b/test/TestCPU6502/TestCPU6502.cpp @@ -112,7 +112,8 @@ void NTSC_VideoUpdateCycles( long cycles6502 ) void init(void) { - mem = (LPBYTE)VirtualAlloc(NULL,64*1024,MEM_COMMIT,PAGE_READWRITE); + // memory must be zero initialised like MemInitiaize() does. + mem = (LPBYTE)calloc(64, 1024); for (UINT i=0; i<256; i++) memwrite[i] = mem+i*256;