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

Function Format_ProDOS_Disk

source/ProDOS_Utils.cpp:899–962  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

897}
898
899void Format_ProDOS_Disk( const std::string & pathname, FrameBase *pFrame )
900{
901 FILE *hFile = fopen( pathname.c_str(), "r+b" );
902 if (hFile)
903 {
904 fseek( hFile, 0, SEEK_END );
905 size_t nDiskSize = ftell( hFile );
906 fseek( hFile, 0, SEEK_SET );
907
908 size_t nMaxDiskSize = HARDDISK_32M_SIZE;
909
910 if (nDiskSize > nMaxDiskSize)
911 {
912 std::string sMessage(StrFormat(
913 "ERROR: Disk Image Size (%zu bytes) > maximum ProDOS volume size (%zu bytes)"
914 , nDiskSize
915 , nMaxDiskSize
916 ));
917 pFrame->FrameMessageBox( sMessage.c_str(), "Format", MB_ICONWARNING | MB_OK);
918 }
919 else
920 {
921 std::vector<uint8_t> pDiskBytes(nDiskSize);
922 size_t nReadSize = fread( pDiskBytes.data(), 1, nDiskSize, hFile );
923 assert( nReadSize == nDiskSize );
924
925 // We can have DOS or ProDOS sector interleaving
926 // Extension Interleave
927 // .bin Unknown, assume DOS
928 // .dsk DOS
929 // .po ProDOS
930 // .hdv ProDOS
931 SectorOrder_e eSectorOrder = Util_Disk_CalculateSectorOrder( pathname );
932 if (eSectorOrder == INTERLEAVE_AUTO_DETECT)
933 {
934 int res = pFrame->FrameMessageBox(
935 "Unable to auto-detect the disk image sector order!\n"
936 "\n"
937 "Is this image using a ProDOS sector order?\n"
938 "(No will use DOS 3.3 sector order)"
939 , "Format", MB_ICONWARNING|MB_YESNO);
940 eSectorOrder = (res == IDYES)
941 ? INTERLEAVE_PRODOS_ORDER
942 : INTERLEAVE_DOS33_ORDER
943 ;
944 }
945 assert (eSectorOrder != INTERLEAVE_AUTO_DETECT);
946
947 const char *pVolumeName = "BLANK";
948 Util_ProDOS_ForwardSectorInterleave( pDiskBytes.data(), nDiskSize, eSectorOrder );
949 Util_ProDOS_FormatFileSystem ( pDiskBytes.data(), nDiskSize, pVolumeName );
950 Util_ProDOS_ReverseSectorInterleave( pDiskBytes.data(), nDiskSize, eSectorOrder );
951
952 fseek( hFile, 0, SEEK_SET );
953 size_t nWroteSize = fwrite( pDiskBytes.data(), 1, nReadSize, hFile );
954 if (nWroteSize != nDiskSize)
955 {
956 pFrame->FrameMessageBox( "ERROR: Unable to write ProDOS File System", "Format", MB_ICONWARNING | MB_OK);

Callers 1

ProcessDiskPopupMenuMethod · 0.85

Tested by

no test coverage detected