MCPcopy Create free account
hub / github.com/AppleWin/AppleWin / Format_DOS33_Disk

Function Format_DOS33_Disk

source/ProDOS_Utils.cpp:964–1012  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

962}
963
964void Format_DOS33_Disk( const std::string & pathname, FrameBase *pFrame )
965{
966 FILE *hFile = fopen( pathname.c_str(), "r+b" );
967 if (hFile)
968 {
969 fseek( hFile, 0, SEEK_END );
970 size_t nDiskSize = ftell( hFile );
971 fseek( hFile, 0, SEEK_SET );
972
973 // Verify floppy size is <= 160KB (max 40 tracks) since that is the largest supported by DOS 3.3
974 // TODO: Maybe use CImageBase::IsValidImageSize() ?
975 size_t nMinDiskSize = 34 * TRACK_DENIBBLIZED_SIZE;
976 size_t nMaxDiskSize = TRACKS_MAX * TRACK_DENIBBLIZED_SIZE;
977
978 std::string sMessage;
979 if (nDiskSize < nMinDiskSize)
980 {
981 sMessage = StrFormat( "ERROR: Disk image size (%zu bytes) < minimum DOS 3.3 image size (%zu bytes)", nDiskSize, nMinDiskSize );
982 pFrame->FrameMessageBox( sMessage.c_str(), "Format", MB_ICONERROR | MB_OK);
983 }
984 else
985 if (nDiskSize > nMaxDiskSize)
986 {
987 sMessage = StrFormat( "ERROR: Disk image size (%zu bytes) > maximum DOS 3.3 image size (%zu bytes)", nDiskSize, nMaxDiskSize );
988 pFrame->FrameMessageBox( sMessage.c_str(), "Format", MB_ICONERROR | MB_OK);
989 }
990 else
991 {
992 std::vector<uint8_t> pDiskBytes(nDiskSize);
993 size_t nReadSize = fread( pDiskBytes.data(), 1, nDiskSize, hFile );
994 assert( nReadSize == nDiskSize );
995
996 int VTOC_TRACK = 0x11; // TODO: Allow user to over-ride via command-line argument? --vtoc 17
997 Util_DOS33_FormatFileSystem( pDiskBytes.data(), nDiskSize, VTOC_TRACK );
998
999 fseek( hFile, 0, SEEK_SET );
1000 size_t nWroteSize = fwrite( pDiskBytes.data(), 1, nReadSize, hFile );
1001 if (nWroteSize != nDiskSize)
1002 {
1003 pFrame->FrameMessageBox( "ERROR: Unable to write DOS 3.3 file system", "Format", MB_ICONWARNING | MB_OK);
1004 }
1005 }
1006 fclose( hFile );
1007 }
1008 else
1009 {
1010 pFrame->FrameMessageBox( "ERROR: Unable to open disk image for writing DOS 3.3 file system", "Format", MB_ICONWARNING | MB_OK);
1011 }
1012}

Callers 1

ProcessDiskPopupMenuMethod · 0.85

Calls 3

StrFormatFunction · 0.85
FrameMessageBoxMethod · 0.80

Tested by

no test coverage detected