mirror of
https://github.com/AppleWin/AppleWin.git
synced 2025-01-22 01:31:25 +00:00
Remove VirtualAlloc, VirtualFree & ZeroMemory. (PR #884)
. Allocation in Memory.cpp: keep VirtualAlloc of size=64KiB (alignment=64KiB) to ease debugging.
This commit is contained in:
parent
86851d86e5
commit
d2a34e1f91
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -462,7 +462,7 @@ bool ConsoleInputBackSpace ()
|
||||
//===========================================================================
|
||||
bool ConsoleInputClear ()
|
||||
{
|
||||
ZeroMemory( g_aConsoleInput, CONSOLE_WIDTH );
|
||||
memset( g_aConsoleInput, 0, CONSOLE_WIDTH );
|
||||
|
||||
if (g_nConsoleInputChars)
|
||||
{
|
||||
|
@ -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() ))
|
||||
{
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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 );
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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,
|
||||
|
@ -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);
|
||||
|
@ -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)
|
||||
{
|
||||
ms_pWorkBuffer = new BYTE[TRACK_DENIBBLIZED_SIZE * 2];
|
||||
}
|
||||
|
||||
CImageBase::~CImageBase()
|
||||
{
|
||||
delete [] ms_pWorkBuffer;
|
||||
ms_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)
|
||||
@ -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;
|
||||
@ -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(ms_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
|
||||
@ -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(ms_pWorkBuffer+TRACK_DENIBBLIZED_SIZE, 0, TRACK_DENIBBLIZED_SIZE);
|
||||
LPBYTE imageptr = trackimagebuffer;
|
||||
BYTE sector = 0;
|
||||
|
||||
@ -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,7 +929,7 @@ public:
|
||||
{
|
||||
ConvertSectorOrder(m_pHeader+14);
|
||||
SetFilePointer(pImageInfo->hFile, track*TRACK_DENIBBLIZED_SIZE+30, NULL, FILE_BEGIN);
|
||||
ZeroMemory(ms_pWorkBuffer, TRACK_DENIBBLIZED_SIZE);
|
||||
memset(ms_pWorkBuffer, 0, TRACK_DENIBBLIZED_SIZE);
|
||||
DWORD bytesread;
|
||||
ReadFile(pImageInfo->hFile, ms_pWorkBuffer, TRACK_DENIBBLIZED_SIZE, &bytesread, NULL);
|
||||
*pNibbles = NibblizeTrack(pTrackImageBuffer, eSIMSYSTEMOrder, track);
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
@ -99,8 +99,9 @@ protected:
|
||||
DWORD NibblizeTrack (LPBYTE trackimagebuffer, SectorOrder_e SectorOrder, int track);
|
||||
void SkewTrack (const int nTrack, const int nNumNibbles, const LPBYTE pTrackImageBuffer);
|
||||
|
||||
LPBYTE ms_pWorkBuffer;
|
||||
|
||||
public:
|
||||
static LPBYTE ms_pWorkBuffer;
|
||||
UINT m_uNumTracksInImage; // Init'd by CDiskImageHelper.Detect()/GetImageForCreation() & possibly updated by IsValidImageSize()
|
||||
|
||||
protected:
|
||||
@ -425,9 +426,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);
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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 use allocate the 64KB of RAM with an aligned memory allocations (0x1000)
|
||||
// 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; i<g_uMaxExPages; i++)
|
||||
{
|
||||
if (RWpages[i])
|
||||
{
|
||||
VirtualFree(RWpages[i], 0, MEM_RELEASE);
|
||||
ALIGNED_FREE(RWpages[i]);
|
||||
RWpages[i] = NULL;
|
||||
}
|
||||
}
|
||||
@ -1279,8 +1297,8 @@ void MemDestroy()
|
||||
|
||||
mem = NULL;
|
||||
|
||||
ZeroMemory(memwrite, sizeof(memwrite));
|
||||
ZeroMemory(memshadow,sizeof(memshadow));
|
||||
memset(memwrite, 0, sizeof(memwrite));
|
||||
memset(memshadow, 0, sizeof(memshadow));
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
@ -1467,14 +1485,15 @@ bool MemIsAddrCodeMemory(const USHORT addr)
|
||||
void MemInitialize()
|
||||
{
|
||||
// ALLOCATE MEMORY FOR THE APPLE MEMORY IMAGE AND ASSOCIATED DATA STRUCTURES
|
||||
memaux = (LPBYTE)VirtualAlloc(NULL,_6502_MEM_END+1,MEM_COMMIT,PAGE_READWRITE);
|
||||
memmain = (LPBYTE)VirtualAlloc(NULL,_6502_MEM_END+1,MEM_COMMIT,PAGE_READWRITE);
|
||||
memdirty = (LPBYTE)VirtualAlloc(NULL,0x100 ,MEM_COMMIT,PAGE_READWRITE);
|
||||
memrom = (LPBYTE)VirtualAlloc(NULL,0x3000 * MaxRomPages ,MEM_COMMIT,PAGE_READWRITE);
|
||||
memimage = (LPBYTE)VirtualAlloc(NULL,_6502_MEM_END+1,MEM_RESERVE,PAGE_NOACCESS);
|
||||
memaux = ALIGNED_ALLOC(_6502_MEM_LEN);
|
||||
memmain = ALIGNED_ALLOC(_6502_MEM_LEN);
|
||||
memimage = ALIGNED_ALLOC(_6502_MEM_LEN);
|
||||
|
||||
pCxRomInternal = (LPBYTE) VirtualAlloc(NULL, CxRomSize, MEM_COMMIT, PAGE_READWRITE);
|
||||
pCxRomPeripheral = (LPBYTE) VirtualAlloc(NULL, CxRomSize, MEM_COMMIT, PAGE_READWRITE);
|
||||
memdirty = new BYTE[0x100];
|
||||
memrom = new BYTE[0x3000 * MaxRomPages];
|
||||
|
||||
pCxRomInternal = new BYTE[CxRomSize];
|
||||
pCxRomPeripheral = new BYTE[CxRomSize];
|
||||
|
||||
if (!memaux || !memdirty || !memimage || !memmain || !memrom || !pCxRomInternal || !pCxRomPeripheral)
|
||||
{
|
||||
@ -1487,25 +1506,6 @@ void MemInitialize()
|
||||
ExitProcess(1);
|
||||
}
|
||||
|
||||
LPVOID newloc = VirtualAlloc(memimage,_6502_MEM_END+1,MEM_COMMIT,PAGE_READWRITE);
|
||||
if (newloc != memimage)
|
||||
MessageBox(
|
||||
GetDesktopWindow(),
|
||||
TEXT("The emulator has detected a bug in your operating ")
|
||||
TEXT("system. While changing the attributes of a memory ")
|
||||
TEXT("object, the operating system also changed its ")
|
||||
TEXT("location."),
|
||||
g_pAppTitle.c_str(),
|
||||
MB_ICONEXCLAMATION | MB_SETFOREGROUND);
|
||||
|
||||
// memimage has been freed
|
||||
// if we have come here we should use newloc
|
||||
//
|
||||
// this happens when running under valgrind
|
||||
memimage = (LPBYTE)newloc;
|
||||
|
||||
//
|
||||
|
||||
RWpages[0] = memaux;
|
||||
|
||||
SetExpansionMemTypeDefault();
|
||||
@ -1517,7 +1517,7 @@ void MemInitialize()
|
||||
g_uActiveBank = 0;
|
||||
|
||||
UINT i = 1;
|
||||
while ((i < g_uMaxExPages) && (RWpages[i] = (LPBYTE) VirtualAlloc(NULL, _6502_MEM_END+1, MEM_COMMIT, PAGE_READWRITE)))
|
||||
while ((i < g_uMaxExPages) && (RWpages[i] = ALIGNED_ALLOC(_6502_MEM_LEN)))
|
||||
i++;
|
||||
while (i < kMaxExMemoryBanks)
|
||||
RWpages[i++] = NULL;
|
||||
@ -1831,12 +1831,12 @@ inline DWORD getRandomTime()
|
||||
void MemReset()
|
||||
{
|
||||
// INITIALIZE THE PAGING TABLES
|
||||
ZeroMemory(memshadow,256*sizeof(LPBYTE));
|
||||
ZeroMemory(memwrite ,256*sizeof(LPBYTE));
|
||||
memset(memshadow, 0, 256*sizeof(LPBYTE));
|
||||
memset(memwrite , 0, 256*sizeof(LPBYTE));
|
||||
|
||||
// INITIALIZE THE RAM IMAGES
|
||||
ZeroMemory(memaux ,0x10000);
|
||||
ZeroMemory(memmain,0x10000);
|
||||
memset(memaux , 0, 0x10000);
|
||||
memset(memmain, 0, 0x10000);
|
||||
|
||||
// Init the I/O ROM vars
|
||||
IO_SELECT = 0;
|
||||
@ -1844,7 +1844,7 @@ void MemReset()
|
||||
g_eExpansionRomType = eExpRomNull;
|
||||
g_uPeripheralRomSlot = 0;
|
||||
|
||||
ZeroMemory(memdirty, 0x100);
|
||||
memset(memdirty, 0, 0x100);
|
||||
|
||||
//
|
||||
|
||||
@ -2368,7 +2368,7 @@ bool MemLoadSnapshot(YamlLoadHelper& yamlLoadHelper, UINT unitVersion)
|
||||
|
||||
memset(memmain+0xC000, 0, LanguageCardSlot0::kMemBankSize); // Clear it, as high 16K may not be in the save-state's "Main Memory" (eg. the case of II+ Saturn replacing //e LC)
|
||||
|
||||
yamlLoadHelper.LoadMemory(memmain, _6502_MEM_END+1);
|
||||
yamlLoadHelper.LoadMemory(memmain, _6502_MEM_LEN);
|
||||
if (unitVersion == 1 && IsApple2PlusOrClone(GetApple2Type()))
|
||||
{
|
||||
// v1 for II/II+ doesn't have a dedicated slot-0 LC, instead the 16K is stored as the top 16K of memmain
|
||||
@ -2473,9 +2473,7 @@ static void MemLoadSnapshotAuxCommon(YamlLoadHelper& yamlLoadHelper, const std::
|
||||
LPBYTE pBank = MemGetBankPtr(uBank);
|
||||
if (!pBank)
|
||||
{
|
||||
pBank = RWpages[uBank-1] = (LPBYTE) VirtualAlloc(NULL, _6502_MEM_END+1, MEM_COMMIT, PAGE_READWRITE);
|
||||
if (!pBank)
|
||||
throw std::string("Card: mem alloc failed");
|
||||
pBank = RWpages[uBank-1] = ALIGNED_ALLOC(_6502_MEM_LEN);
|
||||
}
|
||||
|
||||
// "Auxiliary Memory Bankxx"
|
||||
@ -2486,7 +2484,7 @@ static void MemLoadSnapshotAuxCommon(YamlLoadHelper& yamlLoadHelper, const std::
|
||||
if (!yamlLoadHelper.GetSubMap(auxMemName))
|
||||
throw std::string("Memory: Missing map name: " + auxMemName);
|
||||
|
||||
yamlLoadHelper.LoadMemory(pBank, _6502_MEM_END+1);
|
||||
yamlLoadHelper.LoadMemory(pBank, _6502_MEM_LEN);
|
||||
|
||||
yamlLoadHelper.PopMap();
|
||||
}
|
||||
|
@ -215,7 +215,7 @@ static void V_CreateLookup_DoubleHires ()
|
||||
int coloffs = SIZE * column;
|
||||
for (unsigned byteval = 0; byteval < 256; byteval++) {
|
||||
int color[SIZE];
|
||||
ZeroMemory(color,sizeof(color));
|
||||
memset(color, 0, sizeof(color));
|
||||
unsigned pattern = MAKEWORD(byteval,column);
|
||||
int pixel;
|
||||
for (pixel = 1; pixel < 15; pixel++) {
|
||||
@ -1175,7 +1175,7 @@ static void V_CreateDIBSections(void)
|
||||
g_aSourceStartofLine[ y ] = g_pSourcePixels + SRCOFFS_TOTAL*((MAX_SOURCE_Y-1) - y);
|
||||
|
||||
// DRAW THE SOURCE IMAGE INTO THE SOURCE BIT BUFFER
|
||||
ZeroMemory(g_pSourcePixels, SRCOFFS_TOTAL*MAX_SOURCE_Y);
|
||||
memset(g_pSourcePixels, 0, SRCOFFS_TOTAL*MAX_SOURCE_Y);
|
||||
|
||||
V_CreateLookup_Lores();
|
||||
V_CreateLookup_HiResHalfPixel_Authentic(VT_COLOR_IDEALIZED);
|
||||
|
@ -175,7 +175,7 @@ void CSuperSerialCard::UpdateCommState()
|
||||
return;
|
||||
|
||||
DCB dcb;
|
||||
ZeroMemory(&dcb,sizeof(DCB));
|
||||
memset(&dcb, 0, sizeof(DCB));
|
||||
dcb.DCBlength = sizeof(DCB);
|
||||
GetCommState(m_hCommHandle,&dcb);
|
||||
dcb.BaudRate = m_uBaudRate;
|
||||
@ -280,7 +280,7 @@ bool CSuperSerialCard::CheckComm()
|
||||
// Read operation is to return immediately with the bytes that have already been received,
|
||||
// even if no bytes have been received.
|
||||
COMMTIMEOUTS ct;
|
||||
ZeroMemory(&ct,sizeof(COMMTIMEOUTS));
|
||||
memset(&ct, 0, sizeof(COMMTIMEOUTS));
|
||||
ct.ReadIntervalTimeout = MAXDWORD;
|
||||
SetCommTimeouts(m_hCommHandle,&ct);
|
||||
|
||||
|
@ -530,7 +530,7 @@ bool DSInit()
|
||||
}
|
||||
|
||||
DSCAPS DSCaps;
|
||||
ZeroMemory(&DSCaps, sizeof(DSCAPS));
|
||||
memset(&DSCaps, 0, sizeof(DSCAPS));
|
||||
DSCaps.dwSize = sizeof(DSCAPS);
|
||||
hr = g_lpDS->GetCaps(&DSCaps);
|
||||
if(FAILED(hr))
|
||||
|
@ -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
|
||||
|
@ -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) )
|
||||
{
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user