source: xtideuniversalbios/trunk/Serial_Server/win32/Win32.cpp@ 221

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

Serial Server, more minor improvements, added support for larger than 2 GB disks under Win32

File size: 5.4 KB
Line 
1//======================================================================
2//
3// Project: XTIDE Universal BIOS, Serial Port Server
4//
5// File: Win32.cpp - Microsoft Windows 32-bit application
6//
7// This file contains the entry point for the Win32 version of the server.
8// It also handles log reporting, timers, and command line parameter parsing.
9//
10
11#include <stdio.h>
12#include <stdlib.h>
13#include <fcntl.h>
14#include <stdarg.h>
15
16#include "../library/library.h"
17#include "../library/flatimage.h"
18
19void usage(void)
20{
21 char *usageStrings[] = {
22 "SerDrive - XTIDE Universal BIOS Serial Drive Server",
23 "Version 1.2.0_wip, Built " __DATE__,
24 "",
25 "usage: SerDrive [options] imagefile [[slave-options] slave-imagefile]",
26 "",
27 " -g [cyl:head:sect] Geometry in cylinders, sectors per cylinder, and heads",
28 " -g without parameters uses CHS mode (default is LBA28)",
29 "",
30 " -n [megabytes] Create new disk with given size or use -g geometry",
31 " Maximum size is " USAGE_MAXSECTORS,
32 " (default is a 32 MB disk, with CHS geometry 65:63:16)",
33 "",
34 " -p Named Pipe mode for emulators (pipe is '" PIPENAME "')",
35 "",
36 " -c COMPortNumber COM Port to use (default is first found)",
37 "",
38 " -b BaudRate Baud rate to use on the COM port ",
39 " Without a rate multiplier: 2400, 9600, 38400, 115200",
40 " With a 2x rate multiplier: 4800, 19200, 76800, 230400",
41 " With a 4x rate multiplier: 9600, 38400, 153600, 460800",
42 " Abbreviations also accepted (ie, '460K', '38.4K', etc)",
43 " (default is 38400, 115200 in named pipe mode)",
44 "",
45 " -t Disable timeout, useful for long delays when debugging",
46 "",
47 " -r Read Only disk, do not allow writes",
48 "",
49 " -v [level] Reporting level 1-6, with increasing information",
50 "",
51 "On the client computer, a serial port can be configured for use as a hard disk",
52 "with xtidecfg.com. Or one can hold down the ALT key at the end of the normal",
53 "IDE hard disk scan and the XTIDE Universal BIOS will scan COM1-7, at each of",
54 "the four speeds given above for BaudRate. Note that hardware rate multipliers",
55 "must be taken into account on the server end, but are invisible on the client.",
56 NULL };
57
58 for( int t = 0; usageStrings[t]; t++ )
59 fprintf( stderr, "%s\n", usageStrings[t] );
60
61 exit( 1 );
62}
63
64int verbose = 0;
65
66int main(int argc, char* argv[])
67{
68 DWORD len;
69
70 unsigned long check;
71 unsigned char w;
72
73 unsigned short wbuff[256];
74
75 SerialAccess serial;
76 Image *img;
77 struct baudRate *baudRate = NULL;
78
79 int timeoutEnabled = 1;
80
81 char *ComPort = NULL, ComPortBuff[20];
82
83 _fmode = _O_BINARY;
84
85 unsigned long cyl = 0, sect = 0, head = 0;
86 int readOnly = 0, createFile = 0;
87 int useCHS = 0;
88
89 int imagecount = 0;
90 Image *images[2] = { NULL, NULL };
91
92 for( int t = 1; t < argc; t++ )
93 {
94 if( argv[t][0] == '/' || argv[t][0] == '-' )
95 {
96 char *c;
97 unsigned long a;
98 for( c = &argv[t][1]; *c && !isdigit( *c ); c++ )
99 ;
100 a = atol(c);
101
102 switch( argv[t][1] )
103 {
104 case 'c': case 'C':
105 a = atol( argv[++t] );
106 if( a < 1 )
107 usage();
108 sprintf( ComPortBuff, "COM%d", a );
109 ComPort = &ComPortBuff[0];
110 break;
111 case 'v': case 'V':
112 if( atol(argv[t+1]) != 0 )
113 verbose = atol(argv[++t]);
114 else
115 verbose = 1;
116 break;
117 case 'r': case 'R':
118 readOnly = 1;
119 break;
120 case 'p': case 'P':
121 ComPort = "PIPE";
122 if( !baudRate )
123 baudRate = baudRateMatchString( "115200" );
124 break;
125 case 'g': case 'G':
126 if( atol(argv[t+1]) != 0 )
127 {
128 if( !Image::parseGeometry( argv[++t], &cyl, &head, &sect ) )
129 usage();
130 }
131 useCHS = 1;
132 break;
133 case 'h': case 'H': case '?':
134 usage();
135 break;
136 case 'n': case 'N':
137 createFile = 1;
138 if( atol(argv[t+1]) != 0 )
139 {
140 unsigned long size = atol(argv[++t]);
141 sect = 63;
142 head = 16;
143 cyl = (size*1024*2) / (16*63);
144 }
145 break;
146 case 't': case 'T':
147 timeoutEnabled = 0;
148 break;
149 case 'b': case 'B':
150 if( !(baudRate = baudRateMatchString( argv[++t] )) )
151 {
152 fprintf( stderr, "Unknown Baud Rate %s\n\n", argv[t] );
153 usage();
154 }
155 break;
156 default:
157 fprintf( stderr, "Unknown Option: %s\n\n", argv[t] );
158 usage();
159 }
160 }
161 else if( imagecount < 2 )
162 {
163 images[imagecount] = new FlatImage( argv[t], readOnly, imagecount, createFile, cyl, head, sect, useCHS );
164 imagecount++;
165 createFile = readOnly = cyl = sect = head = useCHS = 0;
166 }
167 else
168 usage();
169 }
170
171 if( imagecount == 0 )
172 usage();
173
174 if( !baudRate )
175 baudRate = baudRateMatchString( "38400" );
176
177 do
178 {
179 serial.Connect( ComPort, baudRate );
180
181 processRequests( &serial, images[0], images[1], timeoutEnabled, verbose );
182
183 serial.Disconnect();
184
185 if( serial.resetConnection )
186 log( 0, "Serial Connection closed, reset..." );
187 }
188 while( serial.resetConnection );
189}
190
191void log( int level, char *message, ... )
192{
193 va_list args;
194
195 va_start( args, message );
196
197 if( level < 0 )
198 {
199 fprintf( stderr, "ERROR: " );
200 vfprintf( stderr, message, args );
201 fprintf( stderr, "\n" );
202 exit( 1 );
203 }
204 else if( verbose >= level )
205 {
206 vprintf( message, args );
207 printf( "\n" );
208 }
209
210 va_end( args );
211}
212
213unsigned long GetTime(void)
214{
215 return( GetTickCount() );
216}
217
218unsigned long GetTime_Timeout(void)
219{
220 return( 1000 );
221}
Note: See TracBrowser for help on using the repository browser.