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

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

Initial checkin for the Serial Server code, to be run on a host computer with a hard disk image file. Connected via a serial line, this provides the I/O for the serial port support in the XTIDE bios. At present, this is a Win32 command line program, run without parameters for usage information.

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