[209] | 1 | //======================================================================
|
---|
| 2 | //
|
---|
| 3 | // Project: XTIDE Universal BIOS, Serial Port Server
|
---|
| 4 | //
|
---|
| 5 | // File: FlatImage.h - Header file for basic flat disk image support
|
---|
| 6 | //
|
---|
| 7 |
|
---|
| 8 | #include "library.h"
|
---|
| 9 |
|
---|
| 10 | class FlatImage : public Image
|
---|
| 11 | {
|
---|
| 12 | private:
|
---|
[219] | 13 | class FileAccess fp;
|
---|
[209] | 14 |
|
---|
| 15 | public:
|
---|
[219] | 16 | FlatImage( char *name, int p_readOnly, int p_drive, int p_create, unsigned long p_cyl, unsigned long p_head, unsigned long p_sect, int p_useCHS ) : Image( name, p_readOnly, p_drive, p_create, p_cyl, p_head, p_sect, p_useCHS )
|
---|
| 17 | {
|
---|
| 18 | long filesize;
|
---|
[209] | 19 |
|
---|
[219] | 20 | if( p_create )
|
---|
| 21 | {
|
---|
| 22 | char buff[512];
|
---|
| 23 | unsigned long size;
|
---|
| 24 | double sizef;
|
---|
| 25 | FileAccess cf;
|
---|
| 26 |
|
---|
| 27 | size = (unsigned long) p_cyl * (unsigned long) p_sect * (unsigned long) p_head;
|
---|
| 28 | if( size > cf.MaxSectors )
|
---|
| 29 | log( -1, "'%s', can't create flat file with size greater than %lu 512-byte sectors", name, cf.MaxSectors );
|
---|
| 30 | sizef = size / 2048.0; // 512 byte sectors -> MB
|
---|
| 31 |
|
---|
| 32 | cf.Create( name );
|
---|
| 33 |
|
---|
| 34 | memset( &buff[0], 0, 512 );
|
---|
| 35 | while( size-- )
|
---|
| 36 | cf.Write( &buff[0], 512 );
|
---|
| 37 |
|
---|
| 38 | if( p_cyl > 1024 )
|
---|
| 39 | log( 0, "Created file '%s', size %.1lf MB", name, sizef );
|
---|
| 40 | else
|
---|
| 41 | log( 0, "Created file '%s', geometry %u:%u:%u, size %.1lf MB", name, p_cyl, p_sect, p_head, sizef );
|
---|
| 42 |
|
---|
| 43 | cf.Close();
|
---|
| 44 | }
|
---|
| 45 |
|
---|
| 46 | fp.Open( name );
|
---|
| 47 |
|
---|
| 48 | totallba = fp.SizeSectors();
|
---|
| 49 |
|
---|
| 50 | init( name, p_readOnly, p_drive, p_cyl, p_head, p_sect, p_useCHS );
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 | FlatImage::~FlatImage()
|
---|
| 54 | {
|
---|
| 55 | fp.Close();
|
---|
| 56 | }
|
---|
| 57 |
|
---|
| 58 | void seekSector( unsigned long lba )
|
---|
| 59 | {
|
---|
| 60 | fp.SeekSectors( lba );
|
---|
| 61 | }
|
---|
| 62 |
|
---|
| 63 | void writeSector( void *buff )
|
---|
| 64 | {
|
---|
| 65 | fp.Write( buff, 512 );
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | void readSector( void *buff )
|
---|
| 69 | {
|
---|
| 70 | fp.Read( buff, 512 );
|
---|
| 71 | }
|
---|
[209] | 72 | };
|
---|
| 73 |
|
---|