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
|
||||
" This is an alias for 'catalog'\n"
|
||||
,// FILE_GET
|
||||
" [-boot=<file>] Optional: extract boot sector to file\n"
|
||||
" <path> Path of virtual file to extract\n"
|
||||
" NOTES:\n"
|
||||
" The file remains on the virtual volume\n"
|
||||
" To delete a file see ........: rm\n"
|
||||
" To delete a sub-directory see: rmdir\n"
|
||||
, // 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=800 Format 800 KB (3 1/2\")\n"
|
||||
" -size=32 Format 32 MB (Hard Disk)\n"
|
||||
" <path> Name of virtual volume.\n"
|
||||
, // CAT__NAMES
|
||||
" [<path>] Path to sub-directory to view\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=32 /TEST32M #HardDisk ( 32 MB)\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"
|
||||
"\n"
|
||||
" prodosfs test.dsk ls\n"
|
||||
|
@ -757,16 +765,14 @@ int main( const int nArg, const char *aArg[] )
|
|||
#endif
|
||||
|
||||
if( pBootSectorFileName )
|
||||
{
|
||||
ProDOS_ExtractBootSector( pBootSectorFileName );
|
||||
// loaded = ProDOS_ReplaceBootSector( pBootSectorFileName );
|
||||
// if( loaded ) DskSave();
|
||||
}
|
||||
else
|
||||
ProDOS_FileExtract( gpPath ); // pathname_filename
|
||||
break;
|
||||
}
|
||||
|
||||
case DISK_COMMAND_VOL_INIT:
|
||||
{
|
||||
gnDskSize = DSK_SIZE_312; // TODO: --size=140 --size=800 --size=32
|
||||
if( !DskGetInterleave( gpDskName ) )
|
||||
errorBadInterleave();
|
||||
|
@ -774,6 +780,7 @@ int main( const int nArg, const char *aArg[] )
|
|||
#if DEBUG_MAIN
|
||||
printf( "iArg: %d / %d\n", iArg, nArg );
|
||||
#endif
|
||||
const char *pBootSectorFileName = NULL;
|
||||
|
||||
for( ; iArg < nArg; iArg++ )
|
||||
{
|
||||
|
@ -785,6 +792,14 @@ int main( const int nArg, const char *aArg[] )
|
|||
|
||||
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 )
|
||||
{
|
||||
int size = atoi( pArg + 6 );
|
||||
|
@ -814,12 +829,19 @@ int main( const int nArg, const char *aArg[] )
|
|||
if( gpPath )
|
||||
{
|
||||
ProDOS_Init( gpPath );
|
||||
if( pBootSectorFileName )
|
||||
{
|
||||
bool bReplaced = ProDOS_ReplaceBootSector( pBootSectorFileName );
|
||||
if( !bReplaced )
|
||||
printf( "ERROR: Couldn't replace boot sector\n" );
|
||||
}
|
||||
DskSave();
|
||||
}
|
||||
else
|
||||
return printf( "ERROR: Need virtual volume name. e.g. /TEST\n" );
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
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 );
|
||||
return false;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
switch( kind )
|
||||
{
|
||||
|
@ -1638,7 +1638,24 @@ bool ProDOS_ExtractBootSector( const char *pBootSectorFileName )
|
|||
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 );
|
||||
|
||||
return true;
|
||||
|
@ -1660,22 +1677,53 @@ bool ProDOS_ReplaceBootSector( const char *pBootSectorFileName )
|
|||
|
||||
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" );
|
||||
const size_t BLOCK_0_BEG = 0x0*DSK_SECTOR_SIZE;
|
||||
const size_t BLOCK_0_END = 0x1*DSK_SECTOR_SIZE;
|
||||
|
||||
// size >= 256
|
||||
if( size > 255 )
|
||||
memset( &gaDsk[ BLOCK_0_BEG ], 0, 256 ); // Block 0 Beg = T0S0
|
||||
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" );
|
||||
size = 256;
|
||||
printf( "WARNING: Boot sector > 512 bytes. Truncating to first 512 bytes.\n" );
|
||||
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 );
|
||||
|
||||
// Caller will do: DskSave();
|
||||
// NOTE: Caller will do: DskSave();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue