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

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

More minor changes, improved usage message

File size: 3.7 KB
Line 
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    init( name, p_readOnly, p_drive );
16}
17
18Image::Image( char *name, int p_readOnly, int p_drive, int p_create, unsigned long p_lba )
19{
20    init( name, p_readOnly, p_drive );
21}
22
23Image::Image( char *name, int p_readOnly, int p_drive, int p_create, unsigned long p_cyl, unsigned long p_sect, unsigned long p_head )
24{
25    init( name, p_readOnly, p_drive );
26}
27
28void Image::init( char *name, int p_readOnly, int p_drive )
29{
30    for( char *c = shortFileName = name; *c; c++ )
31        if( *c == '\\' || *c == '/' || *c == ':' )
32            shortFileName = c+1;
33
34    if( *(shortFileName) == 0 )
35    {
36        log( 1, "Can't parse '%s' for short file name\n\n", name );
37        shortFileName = "SerDrive";
38    }
39 
40    readOnly = p_readOnly;
41    drive = p_drive;
42}
43
44int Image::parseGeometry( char *str, unsigned long *p_cyl, unsigned long *p_sect, unsigned long *p_head )
45{
46    char *c, *s, *h;
47    unsigned long cyl, sect, head;
48
49    c = str;
50    for( s = c; *s && *s != ':' && *s != 'x' && *s != 'X'; s++ ) ;
51    if( !*s )
52        return( 0 );
53
54    *s = '\0';
55    s++;
56    for( h = s+1; *h && *h != ':' && *h != 'x' && *h != 'X'; h++ ) ; 
57    if( !*h )
58        return( 0 );
59
60    *h = '\0';
61    h++;
62
63    cyl = atol(c);
64    sect = atol(s);
65    head = atol(h);
66
67    if( cyl == 0 || sect == 0 || head == 0 )
68        return( 0 );
69
70    *p_cyl = cyl;
71    *p_sect = sect;
72    *p_head = head;
73
74    return( 1 );
75}
76
77#define ATA_wGenCfg 0
78#define ATA_wCylCnt 1
79#define ATA_wHeadCnt 3
80#define ATA_wBpTrck 4
81#define ATA_wBpSect 5
82#define ATA_wSPT 6
83#define ATA_strSerial 10
84#define ATA_strFirmware 23
85#define ATA_strModel 27
86#define ATA_wCaps 49
87#define ATA_wCurCyls 54
88#define ATA_wCurHeads 55
89#define ATA_wCurSPT 56
90#define ATA_dwCurSCnt 57
91#define ATA_dwLBACnt 60
92
93#define ATA_VendorSpecific_ReturnPortBaud 158
94
95#define ATA_wCaps_LBA 0x200
96
97#define ATA_wGenCfg_FIXED 0x40
98
99struct comPorts {
100    unsigned long port;
101    unsigned char com;
102};
103struct comPorts supportedComPorts[] = 
104{ 
105  { 0x3f8, '1' }, 
106  { 0x2f8, '2' }, 
107  { 0x3e8, '3' }, 
108  { 0x2e8, '4' }, 
109  { 0x2f0, '5' }, 
110  { 0x3e0, '6' }, 
111  { 0x2e0, '7' }, 
112  { 0x260, '8' },
113  { 0x368, '9' },
114  { 0x268, 'A' },
115  { 0x360, 'B' },
116  { 0x270, 'C' },
117  { 0, 0 } 
118};
119
120void Image::respondInquire( unsigned short *buff, struct baudRate *baudRate, unsigned char portAndBaud )
121{
122    unsigned short comPort = 0;
123    struct comPorts *cp;
124
125    if( portAndBaud )
126    {
127        for( cp = supportedComPorts; cp->port && cp->port != ((portAndBaud << 3) + 0x260); cp++ ) ;
128        if( cp->port )
129            comPort = cp->com;
130    }
131     
132    memset( &buff[0], 0, 514 );
133
134    if( comPort )
135        sprintf( (char *) &buff[ATA_strModel], "%.20s (COM%d/%s)", shortFileName, comPort, baudRate->display );
136    else
137        sprintf( (char *) &buff[ATA_strModel], "%.30s (%s baud)", shortFileName, baudRate->display );
138
139    // strncpy( (char *) &buff[ATA_strModel], img->shortFileName, 40 );
140
141    strncpy( (char *) &buff[ATA_strSerial], "serial", 20 );
142    strncpy( (char *) &buff[ATA_strFirmware], "firmw", 8 );
143
144    for( int t = ATA_strModel; t < ATA_strModel+40; t++ )
145        buff[t] = (buff[t] >> 8) | (buff[t] << 8);
146
147#if 1
148    buff[ ATA_wCylCnt ] = cyl;
149    buff[ ATA_wHeadCnt ] = head;
150    buff[ ATA_wSPT ] = sect;
151#endif
152    buff[ ATA_wGenCfg ] = ATA_wGenCfg_FIXED;
153    //                  buff[ ATA_VendorSpecific_ReturnPortBaud ] = retWord;
154#if 0
155    buff[ ATA_wCaps ] = ATA_wCaps_LBA;
156 
157    buff[ ATA_dwLBACnt ] = (unsigned short) (totallba & 0xffff);
158    buff[ ATA_dwLBACnt+1 ] = (unsigned short) (totallba >> 16);
159#endif
160}
Note: See TracBrowser for help on using the repository browser.