Improve logging and fix asserts for DOS 3.2 INIT (#537)

This commit is contained in:
tomcw 2018-02-15 21:54:15 +00:00
parent 82fdf1ab6a
commit a07d087467
4 changed files with 53 additions and 16 deletions

View File

@ -70,7 +70,6 @@ static unsigned __int64 g_uDiskLastCycle = 0;
static FormatTrack g_formatTrack;
static void CheckSpinning(const ULONG nCyclesLeft);
static Disk_Status_e GetDriveLightStatus( const int iDrive );
static bool IsDriveValid( const int iDrive );
static void ReadTrack (int drive);
static void RemoveDisk (int drive);
@ -886,7 +885,13 @@ static void __stdcall DiskReadWrite(WORD pc, WORD addr, BYTE bWrite, BYTE d, ULO
*(fptr->trackimage + fptr->byte) = floppylatch;
fptr->trackimagedirty = 1;
g_formatTrack.DecodeLatchNibbleWrite(floppylatch, uSpinNibbleCount, fptr); // GH#125
bool bIsSyncFF = false;
#if LOG_DISK_NIBBLES_WRITE
ULONG uCycleDelta = 0;
bIsSyncFF = LogWriteCheckSyncFF(floppylatch, uCycleDelta);
#endif
g_formatTrack.DecodeLatchNibbleWrite(floppylatch, uSpinNibbleCount, fptr, bIsSyncFF); // GH#125
#if LOG_DISK_NIBBLES_WRITE
#if LOG_DISK_NIBBLES_USE_RUNTIME_VAR
@ -894,7 +899,7 @@ static void __stdcall DiskReadWrite(WORD pc, WORD addr, BYTE bWrite, BYTE d, ULO
#endif
{
ULONG uCycleDelta = 0;
if (!LogWriteCheckSyncFF(floppylatch, uCycleDelta))
if (!bIsSyncFF)
LOG_DISK("write %04X = %02X (cy=+%d)\r\n", fptr->byte, floppylatch, uCycleDelta);
else
LOG_DISK("write %04X = %02X (cy=+%d) sync #%d\r\n", fptr->byte, floppylatch, uCycleDelta, g_uSyncFFCount);

View File

@ -26,6 +26,22 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* Author: Various
*/
/*
DOS 3.2 notes
-------------
Writes the following: (in 1 continuous write operation)
. 0x26A0 x 36-cycle (9-bit) sync FFs - wraps track
. Address Field (Prologue=D5AAB5, Epilogue=DEAAEB)
. NB. this trailing EB gets overwritten when sector is written to
. Sector order: {0,A,7,4,1,B,8,5,2,C,9,6,3}
. 432 x 32-cycle FFs
. Gap2: 10
. Data Field:3+410+1+3=417
. NB. no Data Field pro/epilogue written during track format
. 79 x 36-cycle (9-bit) sync FFs (gap3?)
. Address Field (Prologue=D5AAB5, ...), etc.
*/
#include "StdAfx.h"
#include "Disk.h"
@ -59,6 +75,7 @@ void FormatTrack::DriveNotWritingTrack(void)
m_WriteTrackStartIndex = 0;
m_WriteTrackHasWrapped = false;
m_WriteDataFieldPrologueCount = 0;
m_bAddressPrologueIsDOS3_2 = false;
#if LOG_DISK_NIBBLES_WRITE_TRACK_GAPS
m_DbgGap1Size = 0;
@ -113,8 +130,16 @@ void FormatTrack::UpdateOnWriteLatch(UINT uSpinNibbleCount, const Disk_t* const
void FormatTrack::DriveSwitchedToReadMode(Disk_t* const fptr)
{
if (m_bmWrittenSectorAddrFields != 0xFFFF || m_WriteDataFieldPrologueCount != 16) // written all 16 sectors?
return;
if (m_bAddressPrologueIsDOS3_2)
{
if (m_bmWrittenSectorAddrFields != 0x1FFF) // written all 13 sectors? (NB. data field not written by formatter)
return;
}
else
{
if (m_bmWrittenSectorAddrFields != 0xFFFF || m_WriteDataFieldPrologueCount != 16) // written all 16 sectors?
return;
}
// Zero-fill the remainder of the track buffer:
// Either up to 0x18F0 (if less than 0x18F0) or up to 0x1A00 (for .nib).
@ -188,16 +213,16 @@ void FormatTrack::DriveSwitchedToWriteMode(UINT uTrackIndex)
// This is just for debug/logging: used to output when a new Address Field has been read
void FormatTrack::DecodeLatchNibbleRead(BYTE floppylatch)
{
DecodeLatchNibble(floppylatch, false);
DecodeLatchNibble(floppylatch, false, false);
}
void FormatTrack::DecodeLatchNibbleWrite(BYTE floppylatch, UINT uSpinNibbleCount, const Disk_t* const fptr)
void FormatTrack::DecodeLatchNibbleWrite(BYTE floppylatch, UINT uSpinNibbleCount, const Disk_t* const fptr, bool bIsSyncFF)
{
DecodeLatchNibble(floppylatch, true);
DecodeLatchNibble(floppylatch, true, bIsSyncFF);
UpdateOnWriteLatch(uSpinNibbleCount, fptr);
}
void FormatTrack::DecodeLatchNibble(BYTE floppylatch, BOOL bIsWrite)
void FormatTrack::DecodeLatchNibble(BYTE floppylatch, bool bIsWrite, bool bIsSyncFF)
{
m_uLast3Bytes <<= 8;
m_uLast3Bytes |= floppylatch;
@ -207,7 +232,7 @@ void FormatTrack::DecodeLatchNibble(BYTE floppylatch, BOOL bIsWrite)
m_trackState = TS_GAP2;
#if LOG_DISK_NIBBLES_WRITE_TRACK_GAPS
if (floppylatch == 0xFF && bIsWrite && (m_trackState == TS_GAP1 || m_trackState == TS_GAP2 || m_trackState == TS_GAP3))
if (bIsSyncFF && (m_trackState == TS_GAP1 || m_trackState == TS_GAP2 || m_trackState == TS_GAP3))
{
if (m_bmWrittenSectorAddrFields == 0x0000 && m_trackState == TS_GAP1)
m_DbgGap1Size++;
@ -220,8 +245,11 @@ void FormatTrack::DecodeLatchNibble(BYTE floppylatch, BOOL bIsWrite)
#endif
// Beneath Apple ProDOS 3-14: NB. $D5 and $AA are reserved (never written as data)
if (m_uLast3Bytes == 0xD5AA96)
const UINT32 kADDR_PROLOGUE_DOS3_3 = 0xD5AA96; // D5AA96 is used by DOS3.3/ProDOS
const UINT32 kADDR_PROLOGUE_DOS3_2 = 0xD5AAB5; // D5AAB5 is used by DOS3.2/3.2.1
if (m_uLast3Bytes == kADDR_PROLOGUE_DOS3_3 || m_uLast3Bytes == kADDR_PROLOGUE_DOS3_2)
{
m_bAddressPrologueIsDOS3_2 = (m_uLast3Bytes == kADDR_PROLOGUE_DOS3_2);
m_trackState = TS_ADDRFIELD;
m_4and4idx = 0;
return;
@ -240,13 +268,15 @@ void FormatTrack::DecodeLatchNibble(BYTE floppylatch, BOOL bIsWrite)
#if LOG_DISK_NIBBLES_READ
if (!bIsWrite)
{
LOG_DISK("read D5AA96 detected - Vol:%02X Trk:%02X Sec:%02X Chk:%02X\r\n", m_VolTrkSecChk[0], m_VolTrkSecChk[1], m_VolTrkSecChk[2], m_VolTrkSecChk[3]);
BYTE addrPrologue = m_bAddressPrologueIsDOS3_2 ? (BYTE)kADDR_PROLOGUE_DOS3_2 : (BYTE)kADDR_PROLOGUE_DOS3_3;
LOG_DISK("read D5AA%02X detected - Vol:%02X Trk:%02X Sec:%02X Chk:%02X\r\n", addrPrologue, m_VolTrkSecChk[0], m_VolTrkSecChk[1], m_VolTrkSecChk[2], m_VolTrkSecChk[3]);
}
#endif
#if LOG_DISK_NIBBLES_WRITE
if (bIsWrite)
{
LOG_DISK("write D5AA96 detected - Vol:%02X Trk:%02X Sec:%02X Chk:%02X\r\n", m_VolTrkSecChk[0], m_VolTrkSecChk[1], m_VolTrkSecChk[2], m_VolTrkSecChk[3]);
BYTE addrPrologue = m_bAddressPrologueIsDOS3_2 ? (BYTE)kADDR_PROLOGUE_DOS3_2 : (BYTE)kADDR_PROLOGUE_DOS3_3;
LOG_DISK("write D5AA%02X detected - Vol:%02X Trk:%02X Sec:%02X Chk:%02X\r\n", addrPrologue, m_VolTrkSecChk[0], m_VolTrkSecChk[1], m_VolTrkSecChk[2], m_VolTrkSecChk[3]);
}
#endif
@ -331,6 +361,7 @@ void FormatTrack::LoadSnapshot(class YamlLoadHelper& yamlLoadHelper)
m_uLast3Bytes = yamlLoadHelper.LoadUint(SS_YAML_KEY_LAST3BYTES);
*(UINT64*)m_VolTrkSecChk4and4 = yamlLoadHelper.LoadUint64(SS_YAML_KEY_VTSC_4AND4);
m_4and4idx = yamlLoadHelper.LoadUint(SS_YAML_KEY_VTSC_4AND4_IDX);
m_bAddressPrologueIsDOS3_2 = false; // Doesn't matter if this is wrong - for DOS 3.2 INIT, will just get a long (non-truncated) track-0
yamlLoadHelper.PopMap();
}

View File

@ -38,13 +38,13 @@ public:
void DriveSwitchedToReadMode(Disk_t* const fptr);
void DriveSwitchedToWriteMode(UINT uTrackIndex);
void DecodeLatchNibbleRead(BYTE floppylatch);
void DecodeLatchNibbleWrite(BYTE floppylatch, UINT uSpinNibbleCount, const Disk_t* const fptr);
void DecodeLatchNibbleWrite(BYTE floppylatch, UINT uSpinNibbleCount, const Disk_t* const fptr, bool bIsSyncFF);
void SaveSnapshot(class YamlSaveHelper& yamlSaveHelper);
void LoadSnapshot(class YamlLoadHelper& yamlLoadHelper);
private:
void UpdateOnWriteLatch(UINT uSpinNibbleCount, const Disk_t* const fptr);
void DecodeLatchNibble(BYTE floppylatch, BOOL bIsWrite);
void DecodeLatchNibble(BYTE floppylatch, bool bIsWrite, bool bIsSyncFF);
BYTE m_VolTrkSecChk[4];
@ -52,6 +52,7 @@ private:
UINT m_WriteTrackStartIndex;
bool m_WriteTrackHasWrapped;
BYTE m_WriteDataFieldPrologueCount;
bool m_bAddressPrologueIsDOS3_2;
enum TRACKSTATE_e {TS_GAP1, TS_ADDRFIELD, TS_GAP2_START, TS_GAP2, TS_DATAFIELD, TS_GAP3}; // Take care: value written to save-state
TRACKSTATE_e m_trackState;

View File

@ -2,7 +2,7 @@
#define LOG_DISK_TRACKS 1
#define LOG_DISK_MOTOR 1
#define LOG_DISK_PHASES 0
#define LOG_DISK_PHASES 1
#define LOG_DISK_RW_MODE 1
#define LOG_DISK_ENABLE_DRIVE 1
#define LOG_DISK_NIBBLES_SPIN 1