mirror of
https://github.com/Michaelangel007/apple2_prodos_utils.git
synced 2025-02-16 16:30:31 +00:00
Add: ProDOS_ExtractBootSector() and ProDOS_ReplaceBootSector()
This commit is contained in:
parent
649329c1ef
commit
daaf727106
@ -1545,3 +1545,59 @@ void ProDOS_Init( const char *path )
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
// Read T0S0 and save it to a file on the host
|
||||
// @returns 0 if succes
|
||||
// ========================================================================
|
||||
bool ProDOS_ExtractBootSector( const char *pBootSectorFileName )
|
||||
{
|
||||
FILE *pDstFile = fopen( pBootSectorFileName, "w+b" );
|
||||
|
||||
if( !pDstFile )
|
||||
{
|
||||
printf( "ERROR: Couldn't open boot sector filename for writing: %s\n", pBootSectorFileName );
|
||||
return false;
|
||||
}
|
||||
|
||||
fwrite( &gaDsk[ 0 ], 1, 256, pDstFile );
|
||||
fclose( pDstFile );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// Read a file from the host and replace T0S0
|
||||
// @returns true if sucess, else false on error
|
||||
// ========================================================================
|
||||
bool ProDOS_ReplaceBootSector( const char *pBootSectorFileName )
|
||||
{
|
||||
FILE *pSrcFile = fopen( pBootSectorFileName, "rb" );
|
||||
|
||||
if( !pSrcFile )
|
||||
{
|
||||
printf( "ERROR: Couldn't open boot sector filename for reading: %s\n", pBootSectorFileName );
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t size = File_Size( pSrcFile );
|
||||
|
||||
// size < 256
|
||||
memset( &gaDsk[ 0 ], 0, 256 );
|
||||
if( size < 256 )
|
||||
printf( "INFO.: Boot sector < 256 bytes. Padding boot sector with zeroes.\n" );
|
||||
|
||||
// size >= 256
|
||||
if( size > 255 )
|
||||
{
|
||||
printf( "WARNING: Boot sector > 255 bytes. Truncating to first 256 bytes.\n" );
|
||||
size = 256;
|
||||
}
|
||||
|
||||
fread( &gaDsk[ 0 ], 1, size, pSrcFile );
|
||||
fclose( pSrcFile );
|
||||
|
||||
// Caller will do: DskSave();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user