source: xtideuniversalbios/trunk/Serial_Server/library/Image.cpp@ 218

Last change on this file since 218 was 217, checked in by gregli@…, 13 years ago

Serial Server: various improvements, turned on LBA28 support by default.

File size: 5.1 KB
RevLine 
[209]1//======================================================================
2//
3// Project: XTIDE Universal BIOS, Serial Port Server
4//
5// File: image.cpp - Abstract base class for disk image support
6//
7
8#include "library.h"
9#include <memory.h>
10#include <stdlib.h>
11#include <string.h>
12
13Image::Image( char *name, int p_readOnly, int p_drive )
14{
15}
16
17Image::Image( char *name, int p_readOnly, int p_drive, int p_create, unsigned long p_lba )
18{
19}
20
[217]21Image::Image( 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 )
[209]22{
23}
24
[217]25void Image::init( char *name, int p_readOnly, int p_drive, unsigned long p_cyl, unsigned long p_head, unsigned long p_sect, int p_useCHS )
[209]26{
[217]27 double sizef;
28
[209]29 for( char *c = shortFileName = name; *c; c++ )
30 if( *c == '\\' || *c == '/' || *c == ':' )
31 shortFileName = c+1;
32
33 if( *(shortFileName) == 0 )
[211]34 {
35 log( 1, "Can't parse '%s' for short file name\n\n", name );
36 shortFileName = "SerDrive";
37 }
[209]38
39 readOnly = p_readOnly;
40 drive = p_drive;
[217]41
42 if( totallba > 0xfffffff ) // lba28 limit - 28 bits
43 log( -1, "'%s', Image size larger than LBA28 maximum of 137,438,952,960 bytes, %lu", name, totallba );
44
45 if( totallba == 0 )
46 log( -1, "'%s', Image size zero?" );
47
48 if( p_useCHS )
49 {
50 if( p_cyl )
51 {
52 if( p_sect > 63 || (p_head > 16 || p_head < 1) || (p_cyl > 1024 || p_cyl < 1) )
53 log( -1, "'%s', parts of the CHS geometry (%lu:%lu:%lu) are out of the range (1-1024:1-16:1-63)", name, p_cyl, p_head, p_sect );
54 else if( totallba != (p_sect * p_head * p_cyl) )
55 log( -1, "'%s', file size does not match geometry", name );
56 sect = p_sect;
57 head = p_head;
58 cyl = p_cyl;
59 }
60 else
61 {
62 if( (totallba % 16) != 0 || ((totallba/16) % 63) != 0 )
63 log( -1, "'%s', file size does not match standard CHS geometry (x:16:63), please specify geometry explicitly with -g", name );
64 else
65 {
66 sect = 63;
67 head = 16;
68 cyl = (totallba / sect / head);
69 if( cyl > 1024 )
70 log( -1, "'%s', CHS geometry of %lu:%lu:%lu is larger than maximum values 1024:16:63", name, cyl, head, sect );
71 }
72 }
73 }
74 else
75 {
76 sect = 0;
77 head = 0;
78 cyl = 0;
79 }
80 useCHS = p_useCHS;
81
82 sizef = totallba/2048.0;
83 if( useCHS )
84 log( 0, "Opening '%s', CHS geometry %u:%u:%u, total size %.1lf MB", name, cyl, sect, head, sizef );
85 else
86 log( 0, "Opening '%s', total lba %lu, total size %.1lf MB", name, totallba, sizef );
[209]87}
88
[217]89int Image::parseGeometry( char *str, unsigned long *p_cyl, unsigned long *p_head, unsigned long *p_sect )
[209]90{
91 char *c, *s, *h;
92 unsigned long cyl, sect, head;
93
94 c = str;
[217]95 for( h = c; *h && *h != ':' && *h != 'x' && *h != 'X'; h++ ) ;
96 if( !*h )
97 return( 0 );
98
99 *h = '\0';
100 h++;
101 for( s = h+1; *s && *s != ':' && *s != 'x' && *s != 'X'; s++ ) ;
[209]102 if( !*s )
103 return( 0 );
104
105 *s = '\0';
106 s++;
107
108 cyl = atol(c);
[217]109 head = atol(h);
[209]110 sect = atol(s);
111
112 if( cyl == 0 || sect == 0 || head == 0 )
113 return( 0 );
114
115 *p_cyl = cyl;
[217]116 *p_head = head;
[209]117 *p_sect = sect;
118
119 return( 1 );
120}
121
122#define ATA_wGenCfg 0
123#define ATA_wCylCnt 1
124#define ATA_wHeadCnt 3
125#define ATA_wBpTrck 4
126#define ATA_wBpSect 5
127#define ATA_wSPT 6
128#define ATA_strSerial 10
129#define ATA_strFirmware 23
130#define ATA_strModel 27
131#define ATA_wCaps 49
132#define ATA_wCurCyls 54
133#define ATA_wCurHeads 55
134#define ATA_wCurSPT 56
135#define ATA_dwCurSCnt 57
136#define ATA_dwLBACnt 60
137
138#define ATA_VendorSpecific_ReturnPortBaud 158
139
140#define ATA_wCaps_LBA 0x200
141
142#define ATA_wGenCfg_FIXED 0x40
143
144struct comPorts {
145 unsigned long port;
146 unsigned char com;
147};
148struct comPorts supportedComPorts[] =
149{
150 { 0x3f8, '1' },
151 { 0x2f8, '2' },
152 { 0x3e8, '3' },
153 { 0x2e8, '4' },
154 { 0x2f0, '5' },
155 { 0x3e0, '6' },
156 { 0x2e0, '7' },
157 { 0x260, '8' },
158 { 0x368, '9' },
159 { 0x268, 'A' },
160 { 0x360, 'B' },
161 { 0x270, 'C' },
162 { 0, 0 }
163};
164
165void Image::respondInquire( unsigned short *buff, struct baudRate *baudRate, unsigned char portAndBaud )
166{
167 unsigned short comPort = 0;
168 struct comPorts *cp;
169
170 if( portAndBaud )
171 {
172 for( cp = supportedComPorts; cp->port && cp->port != ((portAndBaud << 3) + 0x260); cp++ ) ;
173 if( cp->port )
174 comPort = cp->com;
175 }
176
177 memset( &buff[0], 0, 514 );
178
179 if( comPort )
180 sprintf( (char *) &buff[ATA_strModel], "%.20s (COM%d/%s)", shortFileName, comPort, baudRate->display );
181 else
182 sprintf( (char *) &buff[ATA_strModel], "%.30s (%s baud)", shortFileName, baudRate->display );
183
184 // strncpy( (char *) &buff[ATA_strModel], img->shortFileName, 40 );
185
186 strncpy( (char *) &buff[ATA_strSerial], "serial", 20 );
187 strncpy( (char *) &buff[ATA_strFirmware], "firmw", 8 );
188
189 for( int t = ATA_strModel; t < ATA_strModel+40; t++ )
190 buff[t] = (buff[t] >> 8) | (buff[t] << 8);
191
[217]192 if( useCHS )
193 {
194 buff[ ATA_wCylCnt ] = cyl;
195 buff[ ATA_wHeadCnt ] = head;
196 buff[ ATA_wSPT ] = sect;
197 }
198 else
199 {
200 buff[ ATA_wCaps ] = ATA_wCaps_LBA;
201 buff[ ATA_dwLBACnt ] = (unsigned short) (totallba & 0xffff);
202 buff[ ATA_dwLBACnt+1 ] = (unsigned short) (totallba >> 16);
203 }
204
[209]205 buff[ ATA_wGenCfg ] = ATA_wGenCfg_FIXED;
206 // buff[ ATA_VendorSpecific_ReturnPortBaud ] = retWord;
207}
Note: See TracBrowser for help on using the repository browser.