mirror of
https://github.com/Michaelangel007/apple2_prodos_utils.git
synced 2024-09-27 00:55:13 +00:00
Add -boot to load/save the boot sector
This commit is contained in:
parent
0839ab0a3e
commit
23ebbf0331
32
prodos.cpp
32
prodos.cpp
@ -122,16 +122,18 @@ Is this still needed?
|
|||||||
, //CAT_LONG2
|
, //CAT_LONG2
|
||||||
" This is an alias for 'catalog'\n"
|
" This is an alias for 'catalog'\n"
|
||||||
,// FILE_GET
|
,// FILE_GET
|
||||||
|
" [-boot=<file>] Optional: extract boot sector to file\n"
|
||||||
" <path> Path of virtual file to extract\n"
|
" <path> Path of virtual file to extract\n"
|
||||||
" NOTES:\n"
|
" NOTES:\n"
|
||||||
" The file remains on the virtual volume\n"
|
" The file remains on the virtual volume\n"
|
||||||
" To delete a file see ........: rm\n"
|
" To delete a file see ........: rm\n"
|
||||||
" To delete a sub-directory see: rmdir\n"
|
" To delete a sub-directory see: rmdir\n"
|
||||||
, // VOL__INIT
|
, // VOL__INIT
|
||||||
" <path> Name of virtual volume.\n"
|
" [-boot=<file>] Optional: replace boot sector with file\n"
|
||||||
" -size=140 Format 140 KB (5 1/4\")\n"
|
" -size=140 Format 140 KB (5 1/4\")\n"
|
||||||
" -size=800 Format 800 KB (3 1/2\")\n"
|
" -size=800 Format 800 KB (3 1/2\")\n"
|
||||||
" -size=32 Format 32 MB (Hard Disk)\n"
|
" -size=32 Format 32 MB (Hard Disk)\n"
|
||||||
|
" <path> Name of virtual volume.\n"
|
||||||
, // CAT__NAMES
|
, // CAT__NAMES
|
||||||
" [<path>] Path to sub-directory to view\n"
|
" [<path>] Path to sub-directory to view\n"
|
||||||
" Defaults to: /\n"
|
" Defaults to: /\n"
|
||||||
@ -207,6 +209,12 @@ int usage()
|
|||||||
" prodosfs test.dsk init -size=800 /TEST312 # 3 1/2\" (800 KB)\n"
|
" prodosfs test.dsk init -size=800 /TEST312 # 3 1/2\" (800 KB)\n"
|
||||||
" prodosfs test.dsk init -size=32 /TEST32M #HardDisk ( 32 MB)\n"
|
" prodosfs test.dsk init -size=32 /TEST32M #HardDisk ( 32 MB)\n"
|
||||||
"\n"
|
"\n"
|
||||||
|
"To put a (512) boot sector file use -boot with the init command:\n"
|
||||||
|
" prodosfs test.dsk init -boot=bootsector.bin -size=140 /TEST514\n"
|
||||||
|
"\n"
|
||||||
|
"To get a (512) boot sector file use -boot with the cp command:\n"
|
||||||
|
" prodosfs test.dsk cp -boot=bootsector.bin /TEST514\n"
|
||||||
|
"\n"
|
||||||
"Examples:\n"
|
"Examples:\n"
|
||||||
"\n"
|
"\n"
|
||||||
" prodosfs test.dsk ls\n"
|
" prodosfs test.dsk ls\n"
|
||||||
@ -757,16 +765,14 @@ int main( const int nArg, const char *aArg[] )
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if( pBootSectorFileName )
|
if( pBootSectorFileName )
|
||||||
{
|
|
||||||
ProDOS_ExtractBootSector( pBootSectorFileName );
|
ProDOS_ExtractBootSector( pBootSectorFileName );
|
||||||
// loaded = ProDOS_ReplaceBootSector( pBootSectorFileName );
|
|
||||||
// if( loaded ) DskSave();
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
ProDOS_FileExtract( gpPath ); // pathname_filename
|
ProDOS_FileExtract( gpPath ); // pathname_filename
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case DISK_COMMAND_VOL_INIT:
|
case DISK_COMMAND_VOL_INIT:
|
||||||
|
{
|
||||||
gnDskSize = DSK_SIZE_312; // TODO: --size=140 --size=800 --size=32
|
gnDskSize = DSK_SIZE_312; // TODO: --size=140 --size=800 --size=32
|
||||||
if( !DskGetInterleave( gpDskName ) )
|
if( !DskGetInterleave( gpDskName ) )
|
||||||
errorBadInterleave();
|
errorBadInterleave();
|
||||||
@ -774,6 +780,7 @@ int main( const int nArg, const char *aArg[] )
|
|||||||
#if DEBUG_MAIN
|
#if DEBUG_MAIN
|
||||||
printf( "iArg: %d / %d\n", iArg, nArg );
|
printf( "iArg: %d / %d\n", iArg, nArg );
|
||||||
#endif
|
#endif
|
||||||
|
const char *pBootSectorFileName = NULL;
|
||||||
|
|
||||||
for( ; iArg < nArg; iArg++ )
|
for( ; iArg < nArg; iArg++ )
|
||||||
{
|
{
|
||||||
@ -785,6 +792,14 @@ int main( const int nArg, const char *aArg[] )
|
|||||||
|
|
||||||
if( pArg[0] == '-' )
|
if( pArg[0] == '-' )
|
||||||
{
|
{
|
||||||
|
if( strncmp( pArg+1,"boot=", 5 ) == 0 )
|
||||||
|
{
|
||||||
|
if( pBootSectorFileName )
|
||||||
|
printf( "ERROR: Already have boot sector filename. Skipping.\n" );
|
||||||
|
else
|
||||||
|
pBootSectorFileName = pArg + 6;
|
||||||
|
}
|
||||||
|
else
|
||||||
if( strncmp( pArg+1,"size=", 5 ) == 0 )
|
if( strncmp( pArg+1,"size=", 5 ) == 0 )
|
||||||
{
|
{
|
||||||
int size = atoi( pArg + 6 );
|
int size = atoi( pArg + 6 );
|
||||||
@ -814,12 +829,19 @@ int main( const int nArg, const char *aArg[] )
|
|||||||
if( gpPath )
|
if( gpPath )
|
||||||
{
|
{
|
||||||
ProDOS_Init( gpPath );
|
ProDOS_Init( gpPath );
|
||||||
|
if( pBootSectorFileName )
|
||||||
|
{
|
||||||
|
bool bReplaced = ProDOS_ReplaceBootSector( pBootSectorFileName );
|
||||||
|
if( !bReplaced )
|
||||||
|
printf( "ERROR: Couldn't replace boot sector\n" );
|
||||||
|
}
|
||||||
DskSave();
|
DskSave();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return printf( "ERROR: Need virtual volume name. e.g. /TEST\n" );
|
return printf( "ERROR: Need virtual volume name. e.g. /TEST\n" );
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if( (nArg < 2) || !pCommand )
|
if( (nArg < 2) || !pCommand )
|
||||||
|
@ -1453,7 +1453,7 @@ bool ProDOS_FileExtract( const char *path )
|
|||||||
printf( "ERROR: Couldn't open data file for writing: %s\n", pEntry->name );
|
printf( "ERROR: Couldn't open data file for writing: %s\n", pEntry->name );
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
switch( kind )
|
switch( kind )
|
||||||
{
|
{
|
||||||
@ -1638,7 +1638,24 @@ bool ProDOS_ExtractBootSector( const char *pBootSectorFileName )
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
fwrite( &gaDsk[ 0 ], 1, 256, pDstFile );
|
const size_t BLOCK_0_BEG = 0x0*DSK_SECTOR_SIZE;
|
||||||
|
const size_t BLOCK_0_END = 0x1*DSK_SECTOR_SIZE;
|
||||||
|
|
||||||
|
fwrite( &gaDsk[ BLOCK_0_BEG ], 1, 256, pDstFile );
|
||||||
|
fwrite( &gaDsk[ BLOCK_0_END ], 1, 256, pDstFile );
|
||||||
|
|
||||||
|
#if _DEBUG
|
||||||
|
for( int sector = 0; sector < 16; ++sector )
|
||||||
|
{
|
||||||
|
printf( "T0S%1X: ", sector );
|
||||||
|
for( int byte = 0; byte < 4; ++byte )
|
||||||
|
{
|
||||||
|
printf( "%02X ", gaDsk[ sector*DSK_SECTOR_SIZE + byte ] );
|
||||||
|
}
|
||||||
|
printf( "\n" );
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
fclose( pDstFile );
|
fclose( pDstFile );
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -1660,22 +1677,53 @@ bool ProDOS_ReplaceBootSector( const char *pBootSectorFileName )
|
|||||||
|
|
||||||
size_t size = File_Size( pSrcFile );
|
size_t size = File_Size( pSrcFile );
|
||||||
|
|
||||||
// size < 256
|
const size_t BLOCK_0_BEG = 0x0*DSK_SECTOR_SIZE;
|
||||||
memset( &gaDsk[ 0 ], 0, 256 );
|
const size_t BLOCK_0_END = 0x1*DSK_SECTOR_SIZE;
|
||||||
if( size < 256 )
|
|
||||||
printf( "INFO.: Boot sector < 256 bytes. Padding boot sector with zeroes.\n" );
|
|
||||||
|
|
||||||
// size >= 256
|
memset( &gaDsk[ BLOCK_0_BEG ], 0, 256 ); // Block 0 Beg = T0S0
|
||||||
if( size > 255 )
|
memset( &gaDsk[ BLOCK_0_END ], 0, 256 ); // Block 0 End = T0SE
|
||||||
|
|
||||||
|
if( size < 512 )
|
||||||
|
printf( "INFO.: Boot sector < 512 bytes. Padding boot sector with zeroes.\n" );
|
||||||
|
|
||||||
|
if( size > 512 )
|
||||||
{
|
{
|
||||||
printf( "WARNING: Boot sector > 255 bytes. Truncating to first 256 bytes.\n" );
|
printf( "WARNING: Boot sector > 512 bytes. Truncating to first 512 bytes.\n" );
|
||||||
size = 256;
|
size = 512;
|
||||||
}
|
}
|
||||||
|
|
||||||
fread( &gaDsk[ 0 ], 1, size, pSrcFile );
|
const size_t prefix = min( size , 256 );
|
||||||
|
const size_t suffix = min( size-256, 256 );
|
||||||
|
|
||||||
|
#if _DEBUG
|
||||||
|
printf( "prefix: $%02X (#%3d)\n", (int) prefix & 0xFF, (int) prefix );
|
||||||
|
printf( "suffix: $%02X (#%3d)\n", (int) prefix & 0xFF, (int) suffix );
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if( prefix ) fread( &gaDsk[ BLOCK_0_BEG ], 1, prefix, pSrcFile );
|
||||||
|
if( suffix ) fread( &gaDsk[ BLOCK_0_END ], 1, suffix, pSrcFile );
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
if (size <= 256)
|
||||||
|
{
|
||||||
|
fread( &gaDsk[ BLOCK_0_BEG ], 1, size, pSrcFile );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// First 256 bytes to T0S0
|
||||||
|
fread( &gaDsk[ BLOCK_0_BEG ], 1, 256, pSrcFile );
|
||||||
|
|
||||||
|
// Second 256 bytes to T0SE
|
||||||
|
if( size < 512 )
|
||||||
|
fread( &gaDsk[ BLOCK_0_END ], 1, size, pSrcFile );
|
||||||
|
else
|
||||||
|
fread( &gaDsk[ BLOCK_0_END ], 1, 512, pSrcFile );
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
fclose( pSrcFile );
|
fclose( pSrcFile );
|
||||||
|
|
||||||
// Caller will do: DskSave();
|
// NOTE: Caller will do: DskSave();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user