source: xtideuniversalbios/trunk/Serial_Server/library/FlatImage.h @ 259

Last change on this file since 259 was 259, checked in by gregli@…, 11 years ago

For function int13/0h, restored the code to only reset the floppy drives if a floppy drive was passed in for reset. Other minor optimizations. Better create new floppy support in Serial Server.

File size: 1.8 KB
Line 
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
10class FlatImage : public Image
11{
12private:
13    class FileAccess fp;
14
15public:
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;
19
20        if( p_create )
21        {
22            char buff[512];
23            unsigned long size;
24            double sizef;
25            FileAccess cf;
26            char sizeChar;
27
28            size = (unsigned long) p_cyl * (unsigned long) p_sect * (unsigned long) p_head;
29            if( size > cf.MaxSectors )
30                log( -1, "'%s', can't create flat file with size greater than %lu 512-byte sectors", name, cf.MaxSectors );
31            sizef = size / 2048.0;   // 512 byte sectors -> MB
32            sizeChar = 'M';
33            if( sizef < 1 ) 
34            {
35                sizef *= 1024;
36                sizeChar = 'K';
37            }
38
39            if( cf.Create( name ) )
40            {
41                memset( &buff[0], 0, 512 );
42                while( size-- )
43                    cf.Write( &buff[0], 512 );
44               
45                if( p_cyl > 1024 )
46                    log( 0, "Created file '%s', size %.2lf %cB", name, sizef, sizeChar );
47                else
48                    log( 0, "Created file '%s', geometry %u:%u:%u, size %.2lf %cB", name, p_cyl, p_head, p_sect, sizef, sizeChar );
49                cf.Close();
50            }
51        }
52
53        fp.Open( name );
54
55        totallba = fp.SizeSectors();
56
57        init( name, p_readOnly, p_drive, p_cyl, p_head, p_sect, p_useCHS );
58    }
59
60    FlatImage::~FlatImage()
61    {
62        fp.Close();
63    }
64
65    void seekSector( unsigned long lba )
66    {
67        fp.SeekSectors( lba );
68    }
69
70    void writeSector( void *buff )
71    {
72        fp.Write( buff, 512 );
73    }
74
75    void readSector( void *buff )
76    {
77        fp.Read( buff, 512 );
78    }
79};
80
Note: See TracBrowser for help on using the repository browser.