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

Function Util_DOS33_FormatFileSystem

source/ProDOS_Utils.cpp:694–752  ·  view source on GitHub ↗

===========================================================================

Source from the content-addressed store, hash-verified

692
693 //===========================================================================
694 void Util_DOS33_FormatFileSystem ( uint8_t *pDiskBytes, const size_t nDiskSize, const int nVTOC_Track )
695 {
696 const int nTracks = (int)(nDiskSize / TRACK_DENIBBLIZED_SIZE);
697 int nOffset;
698
699 assert (nTracks <= TRACKS_MAX);
700
701 // Update CATALOG next track/sector
702 for( int iSector = 0xF; iSector > 1; iSector-- )
703 {
704 nOffset = Util_GetTrackSectorOffset( nVTOC_Track, iSector );
705 pDiskBytes[ nOffset + 1 ] = nVTOC_Track;
706 pDiskBytes[ nOffset + 2 ] = iSector - 1;
707 }
708
709 // Last sector in CATALOG has no link
710 nOffset = Util_GetTrackSectorOffset( nVTOC_Track, 1 );
711 pDiskBytes[ nOffset + 1 ] = 0;
712 pDiskBytes[ nOffset + 2 ] = 0;
713
714 // FTOC = 256 bytes
715 // - HeaderSize = 0x0C
716 // 0x00 Wasted byte
717 // 0x01 Track Next FTOC
718 // 0x02 Sector Next FTOC
719 // 0x03 Wasted byte
720 // 0x04 Wasted byte
721 // 0x05 Sector offset of file in this T/S
722 // 0x06 Sector offset of file in this T/S
723 // 0x07 Wasted byte
724 // 0x08 Wasted byte
725 // 0x09 Wasted byte
726 // 0x0A Wasted byte
727 // 0x0B Wasted byte
728 // / 2 bytes for next Track/Sector
729 // = 122 entries
730 const uint8_t FTOC_ENTRIES = (256 - 12) / 2;
731
732 nOffset = Util_GetTrackSectorOffset( nVTOC_Track, 0 );
733 pDiskBytes[ nOffset + 0x1 ] = nVTOC_Track; // CATALOG = T11
734 pDiskBytes[ nOffset + 0x2 ] = 0xF; // CATALOG = S0F
735 pDiskBytes[ nOffset + 0x3 ] = 0x3; // DOS 3.3
736 pDiskBytes[ nOffset + 0x6 ] = DEFAULT_VOLUME_NUMBER; // Volume
737 pDiskBytes[ nOffset + 0x27 ] = FTOC_ENTRIES; // TrackSector pairs
738 pDiskBytes[ nOffset + 0x30 ] = nVTOC_Track; // Last Track Allocated
739 pDiskBytes[ nOffset + 0x31 ] = 1; // Direction = +1
740 pDiskBytes[ nOffset + 0x34 ] = nTracks; // Number of Tracks based on image size
741 pDiskBytes[ nOffset + 0x35 ] = 16; // 16 Sectors/Track
742 pDiskBytes[ nOffset + 0x36 ] = 0x00; // 256 Bytes/Sector Lo
743 pDiskBytes[ nOffset + 0x37 ] = 0x01; // 256 Bytes/Sector Hi
744
745 uint8_t *pVTOC = &pDiskBytes[ nOffset ];
746 for( int iTrack = 0; iTrack < nTracks; iTrack++ )
747 {
748 /**/ if (iTrack == 0) Util_DOS33_SetTrackSectorUsage(pVTOC, iTrack, 0x0000); // Track T00 can NEVER be free due to stupid DOS 3.3 design (1 byte bug of `BNE` instead of `BPL`)
749 else if (iTrack == nVTOC_Track) Util_DOS33_SetTrackSectorUsage(pVTOC, iTrack, 0x0000);
750 else /* */ Util_DOS33_SetTrackSectorUsage(pVTOC, iTrack, 0xFFFF); // Tracks T01-T10, T12-T22 are free for use
751 }

Callers 2

New_DOSProDOS_DiskFunction · 0.85
Format_DOS33_DiskFunction · 0.85

Calls 2

Tested by

no test coverage detected