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

Last change on this file since 343 was 259, checked in by gregli@…, 13 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
RevLine 
[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
10class FlatImage : public Image
11{
12private:
[219]13 class FileAccess fp;
[209]14
15public:
[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;
[259]26 char sizeChar;
[219]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
[259]32 sizeChar = 'M';
33 if( sizef < 1 )
34 {
35 sizef *= 1024;
36 sizeChar = 'K';
37 }
[219]38
[225]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 )
[259]46 log( 0, "Created file '%s', size %.2lf %cB", name, sizef, sizeChar );
[225]47 else
[259]48 log( 0, "Created file '%s', geometry %u:%u:%u, size %.2lf %cB", name, p_cyl, p_head, p_sect, sizef, sizeChar );
[225]49 cf.Close();
50 }
[219]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 }
[209]79};
80
Note: See TracBrowser for help on using the repository browser.