git merge --squash GH125-ProDOS-Format. Fix for disk formatting #125, #196, #338:

. .dsk / .nib images
. ProDOS format / DOS 3.3 init
. authentic / enhanced disk access speed

For zero-length files, resize to the complete file size when first opened (#506)
. Support both .dsk and .nib

Created a new class FormatTrack to encapsulate the new track formatting logic

Improved precision of 'authentic' drive mode's spin emulation (#125)

Save-state: (save-state DiskII unit v2)
. support Format Track state
. save DiskLastCycle

DenibblizeTrack(): added some debug asserts and comments

Updated for VS2008/VS2013/2015/2017 projs & remove dependency on ddraw.lib for VS2013/2015

Updated disk logging:
. Moved all LOG_DISK_xx macros to new DiskLog.h (since shared by Disk.cpp and DiskFormatTrack.cpp)
. For write nibble: option to log cycle count & sync byte count
. For written track: option to log gap1/2/3 and track size
. For disk latch r/w: option to log when D5AA96 detected

Other:
. Debugger: Fix CD cmd to support absolute paths (#505)
This commit is contained in:
tomcw
2018-01-14 18:01:22 +00:00
parent efa9ab8aaa
commit 4a69ba8a97
19 changed files with 821 additions and 134 deletions
+47 -7
View File
@@ -413,8 +413,13 @@ void CImageBase::DenibblizeTrack(LPBYTE trackimage, SectorOrder_e SectorOrder, i
// IN THE BUFFER AND WRITE IT INTO THE FIRST PART OF THE WORK BUFFER
// OFFSET BY THE SECTOR NUMBER.
#ifdef _DEBUG
UINT16 bmWrittenSectorAddrFields = 0x0000;
BYTE uWriteDataFieldPrologueCount = 0;
#endif
int offset = 0;
int partsleft = 33;
int partsleft = 33; // TODO-TC: 32 = 16*2 prologues
int sector = 0;
while (partsleft--)
{
@@ -436,20 +441,34 @@ void CImageBase::DenibblizeTrack(LPBYTE trackimage, SectorOrder_e SectorOrder, i
{
int loop = 0;
int tempoffset = offset;
while (loop < 384)
while (loop < 384) // TODO-TC: Why 384? Only need 343 for Decode62()
{
*(ms_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);
#ifdef _DEBUG
_ASSERT( sector <= 15 );
if (partsleft != 0) // Don't need this if partsleft is initialised to 32 (not 33)
{
_ASSERT( (bmWrittenSectorAddrFields & (1<<sector)) == 0 );
bmWrittenSectorAddrFields |= (1<<sector);
}
#endif
}
else if (byteval[2] == 0xAD)
{
#ifdef _DEBUG
uWriteDataFieldPrologueCount++;
_ASSERT(uWriteDataFieldPrologueCount <= 16);
#endif
Decode62(ms_pWorkBuffer+(ms_SectorNumber[SectorOrder][sector] << 8));
sector = 0;
}
@@ -621,7 +640,6 @@ public:
virtual void Write(ImageInfo* pImageInfo, int nTrack, int nQuarterTrack, LPBYTE pTrackImage, int nNibbles)
{
ZeroMemory(ms_pWorkBuffer, TRACK_DENIBBLIZED_SIZE);
DenibblizeTrack(pTrackImage, eDOSOrder, nNibbles);
WriteTrack(pImageInfo, nTrack, ms_pWorkBuffer, TRACK_DENIBBLIZED_SIZE);
}
@@ -688,7 +706,6 @@ public:
virtual void Write(ImageInfo* pImageInfo, int nTrack, int nQuarterTrack, LPBYTE pTrackImage, int nNibbles)
{
ZeroMemory(ms_pWorkBuffer, TRACK_DENIBBLIZED_SIZE);
DenibblizeTrack(pTrackImage, eProDOSOrder, nNibbles);
WriteTrack(pImageInfo, nTrack, ms_pWorkBuffer, TRACK_DENIBBLIZED_SIZE);
}
@@ -1311,7 +1328,7 @@ ImageError_e CImageHelperBase::CheckNormalFile(LPCTSTR pszImageFilename, ImageIn
NULL );
if (hFile != INVALID_HANDLE_VALUE)
pImageInfo->bWriteProtected = 1;
pImageInfo->bWriteProtected = true;
}
if ((hFile == INVALID_HANDLE_VALUE) && bCreateIfNecessary)
@@ -1364,11 +1381,34 @@ ImageError_e CImageHelperBase::CheckNormalFile(LPCTSTR pszImageFilename, ImageIn
}
else // Create (or pre-existing zero-length file)
{
if (pImageInfo->bWriteProtected)
return eIMAGE_ERROR_ZEROLENGTH_WRITEPROTECTED; // Can't be formatted, so return error
pImageType = GetImageForCreation(szExt, &dwSize);
if (pImageType && dwSize)
{
pImageInfo->pImageBuffer = new BYTE [dwSize];
ZeroMemory(pImageInfo->pImageBuffer, dwSize);
if (pImageType->GetType() != eImageNIB1)
{
ZeroMemory(pImageInfo->pImageBuffer, dwSize);
}
else
{
// Fill zero-length image buffer with alternating high-bit-set nibbles (GH#196, GH#338)
for (UINT i=0; i<dwSize; i+=2)
{
pImageInfo->pImageBuffer[i+0] = 0x80; // bit7 set, but 0x80 is an invalid nibble
pImageInfo->pImageBuffer[i+1] = 0x81; // bit7 set, but 0x81 is an invalid nibble
}
}
// As a convenience, resize the file to the complete size (GH#506)
// - this also means that a save-state done mid-way through a format won't reference an image file with a partial size (GH#494)
DWORD dwBytesWritten = 0;
BOOL res = WriteFile(hFile, pImageInfo->pImageBuffer, dwSize, &dwBytesWritten, NULL);
if (!res || dwBytesWritten != dwSize)
return eIMAGE_ERROR_FAILED_TO_INIT_ZEROLENGTH;
}
}