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

Function New_DOSProDOS_Disk

source/ProDOS_Utils.cpp:758–815  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

756// public functions
757
758void New_DOSProDOS_Disk( const char * pTitle, const std::string & pathname, const size_t nDiskSize,
759 const bool bIsDOS33, const bool bNewDiskCopyBitsyBoot, const bool bNewDiskCopyBitsyBye, const bool bNewDiskCopyBASIC, const bool bNewDiskCopyProDOS,
760 FrameBase *pFrame )
761{
762 FILE *hFile = fopen( pathname.c_str(), "wb");
763 if (hFile)
764 {
765 std::vector<uint8_t> pDiskBytes(nDiskSize, 0);
766
767 if (bIsDOS33)
768 {
769 // File System
770 int VTOC_TRACK = 0x11; // TODO: Allow user to over-ride via command-line argument? --vtoc 17
771 Util_DOS33_FormatFileSystem( pDiskBytes.data(), nDiskSize, VTOC_TRACK );
772
773 // Boot Sector + OS
774 const size_t nDOS33Size = 3 * 16 * 256; // First 3 tracks * 16 sectors/track * 256 bytes/sector
775 const BYTE *pDOS33Data = pFrame->GetResource(IDR_OS_DOS33, "FIRMWARE", nDOS33Size);
776 if (pDOS33Data)
777 {
778 memcpy( pDiskBytes.data(), pDOS33Data, nDOS33Size );
779
780 // DOS 3.3 resides on Track 0, 1, 2
781 // Track 0 was already reserved when the file system was formatted.
782 Util_DOS33_SetTrackUsed( pDiskBytes.data(), VTOC_TRACK, 1 );
783 Util_DOS33_SetTrackUsed( pDiskBytes.data(), VTOC_TRACK, 2 );
784 }
785 else
786 {
787 pFrame->FrameMessageBox( "WARNING: Could't find built-in DOS 3.3 Operating System!\n\nDisk will have no boot sector.", pTitle, MB_OK|MB_ICONINFORMATION);
788 }
789 }
790 else // ProDOS
791 {
792 const size_t nBootSectorsSize = 2 * 512;
793 const uint8_t *pBootSectorsData = (uint8_t*) pFrame->GetResource(IDR_BOOT_SECTOR_PRODOS243, "FIRMWARE", nBootSectorsSize);
794 assert(pBootSectorsData);
795
796 SectorOrder_e eSectorOrder = INTERLEAVE_PRODOS_ORDER;
797 const char *pVolumeName = "BLANK";
798 Util_ProDOS_ForwardSectorInterleave( pDiskBytes.data(), nDiskSize, eSectorOrder );
799 Util_ProDOS_FormatFileSystem ( pDiskBytes.data(), nDiskSize, pVolumeName );
800 memcpy(pDiskBytes.data(), pBootSectorsData, nBootSectorsSize);
801 if (bNewDiskCopyBitsyBoot) Util_ProDOS_CopyBitsyBoot( pDiskBytes.data(), nDiskSize, pVolumeName, pFrame );
802 if (bNewDiskCopyBitsyBye) Util_ProDOS_CopyBitsyBye ( pDiskBytes.data(), nDiskSize, pVolumeName, pFrame );
803 if (bNewDiskCopyBASIC) Util_ProDOS_CopyBASIC ( pDiskBytes.data(), nDiskSize, pVolumeName, pFrame );
804 if (bNewDiskCopyProDOS) Util_ProDOS_CopyDOS ( pDiskBytes.data(), nDiskSize, pVolumeName, pFrame );
805 Util_ProDOS_ReverseSectorInterleave( pDiskBytes.data(), nDiskSize, eSectorOrder );
806 }
807
808 fwrite( pDiskBytes.data(), 1, nDiskSize, hFile );
809 fclose( hFile );
810 }
811 else
812 {
813 pFrame->FrameMessageBox( "ERROR: Couldn't open new disk image.", pTitle, MB_OK );
814 }
815}

Callers 1

ProcessDiskPopupMenuMethod · 0.85

Calls 11

Util_DOS33_SetTrackUsedFunction · 0.85
Util_ProDOS_CopyBitsyByeFunction · 0.85
Util_ProDOS_CopyBASICFunction · 0.85
Util_ProDOS_CopyDOSFunction · 0.85
GetResourceMethod · 0.80
FrameMessageBoxMethod · 0.80

Tested by

no test coverage detected