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

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

Small changes. 1) Changes biosdrvs.com to output CR+LF instead of LF+CR, consistent with DOS/Windows, but I did not update the Assembly Library as this would break the Configurator; 2) Put a C/C++ section in Version.inc for the serial server; 3) Configurator defaults the EEPROM address after scanning for a EEPROM in memory (as it does for loading the BIOS from ROM); 4) Added a command to the Configurator main menu to save chages to the file from which it was loaded (if it was loaded form a file), which is symmetric with the Load command and more discoverable than exiting DOS and then being prompted (which is still there too, if changes are unsaved).

File size: 7.4 KB
RevLine 
[209]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
[371]19#include "../../XTIDE_Universal_BIOS/inc/version.inc"
20
[369]21char *bannerStrings[] = {
22 "SerDrive - XTIDE Universal BIOS Serial Drive Server",
23 "Copyright (C) 2012 by XTIDE Universal BIOS Team",
24 "Released under GNU GPL v2, with ABSOLUTELY NO WARRANTY",
[371]25 ROM_VERSION_STRING,
[369]26 "",
27 NULL };
28
29char *usageStrings[] = {
30 "This is free software, and you are welcome to redistribute it under certain",
31 "conditions. For more license details, see the LICENSE.TXT file included with",
32 "this distribution, visit the XTIDE Universal BIOS wiki (address below), or",
33 "http://www.gnu.org/licenses/gpl-2.0.html",
34 "",
35 "Visit the wiki on http://code.google.com/p/xtideuniversalbios for detailed",
36 "serial drive usage directions.",
37 "",
38 "Usage: SerDrive [options] imagefile [[slave-options] slave-imagefile]",
39 "",
40 " -g [cyl:head:sect] Geometry in cylinders, sectors per cylinder, and heads",
41 " -g also implies CHS addressing mode (default is LBA28)",
42 "",
43 " -n [megabytes] Create new disk with given size or use -g geometry",
44 " Maximum size is " USAGE_MAXSECTORS,
45 " Floppy images can also be created, such as \"360K\"",
46 " (default is a 32 MB disk, with CHS geometry 65:16:63)",
47 "",
48 " -p [pipename] Named Pipe mode for emulators",
49 " (must begin with \"\\\\\", default is \"" PIPENAME "\")",
50 "",
51 " -c COMPortNumber COM Port to use (default is first found)",
52 " Available COM ports on this system are:",
53 "COM ",
54 "",
55 " -b BaudRate Baud rate to use on the COM port, with client machine",
56 " rate multiplier in effect:",
57 " None: 2400, 4800, 9600, 28.8K, 57.6K, 115.2K",
58 " 2x: 4800, 9600, 19200, 57.6K, 115.2K, 230.4K",
59 " 4x: 9600, 19200, 38400, 115.2K, 230.4K, 460.8K",
60 " and for completeness: 76.8K, 153.6K",
61 " (default is 9600, 115.2K when in named pipe mode)",
62 "",
63 " -t Disable timeout, useful for long delays when debugging",
64 "",
65 " -r Read Only disk, do not allow writes",
66 "",
67 " -v [level] Reporting level 1-6, with increasing information",
68 "",
69 "On the client computer, a serial port can be configured for use as a hard disk",
70 "with xtidecfg.com. Or one can hold down the ALT key at the end of the normal",
71 "IDE hard disk scan and the XTIDE Universal BIOS will scan COM1-7, at each of",
72 "the six speeds given above for BaudRate. Note that hardware rate multipliers",
73 "must be taken into account on the server end, but are invisible on the client.",
74 "",
75 "Floppy images may also be used. Image size must be exactly the same size",
76 "as a 2.88MB, 1.44MB, 1.2MB, 720KB, 360KB, 320KB, 180KB, or 160KB disk.",
77 "Floppy images must be the last disks discovered by the BIOS, and only",
78 "two floppy drives are supported by the BIOS at a time.",
79 NULL };
80
81void usagePrint( char *strings[] )
[209]82{
[369]83 for( int t = 0; strings[t]; t++ )
[258]84 {
[369]85 if( !strncmp( strings[t], "COM", 3 ) )
[258]86 {
87 char logbuff[ 1024 ];
[209]88
[258]89 SerialAccess::EnumerateCOMPorts( logbuff, 1024 );
[369]90 fprintf( stderr, "%s%s\n", strings[t]+3, logbuff );
[258]91 }
92 else
[369]93 fprintf( stderr, "%s\n", strings[t] );
[258]94 }
[209]95}
96
[369]97#define usage() { usagePrint( usageStrings ); exit(1); }
98
[211]99int verbose = 0;
[209]100
101int main(int argc, char* argv[])
102{
103 DWORD len;
104
105 unsigned long check;
106 unsigned char w;
107
108 unsigned short wbuff[256];
109
[219]110 SerialAccess serial;
[209]111 Image *img;
[215]112 struct baudRate *baudRate = NULL;
[209]113
114 int timeoutEnabled = 1;
115
116 char *ComPort = NULL, ComPortBuff[20];
117
118 _fmode = _O_BINARY;
119
120 unsigned long cyl = 0, sect = 0, head = 0;
[217]121 int readOnly = 0, createFile = 0;
122 int useCHS = 0;
[209]123
124 int imagecount = 0;
125 Image *images[2] = { NULL, NULL };
126
[369]127 usagePrint( bannerStrings );
128
[209]129 for( int t = 1; t < argc; t++ )
130 {
[369]131 char *next = (t+1 < argc ? argv[t+1] : NULL );
132
[209]133 if( argv[t][0] == '/' || argv[t][0] == '-' )
134 {
135 char *c;
136 unsigned long a;
137 for( c = &argv[t][1]; *c && !isdigit( *c ); c++ )
138 ;
139 a = atol(c);
140
141 switch( argv[t][1] )
142 {
143 case 'c': case 'C':
[369]144 if( !next )
145 usage();
146 t++;
147 a = atol( next );
[209]148 if( a < 1 )
149 usage();
150 sprintf( ComPortBuff, "COM%d", a );
151 ComPort = &ComPortBuff[0];
152 break;
153 case 'v': case 'V':
[369]154 if( next && atol(next) != 0 )
155 {
156 t++;
157 verbose = atol(next);
158 }
[209]159 else
[213]160 verbose = 1;
[209]161 break;
162 case 'r': case 'R':
163 readOnly = 1;
164 break;
165 case 'p': case 'P':
[369]166 if( next && next[0] == '\\' && next[1] == '\\' )
167 {
168 t++;
169 ComPort = next;
170 }
[258]171 else
172 ComPort = PIPENAME;
[215]173 if( !baudRate )
174 baudRate = baudRateMatchString( "115200" );
[209]175 break;
176 case 'g': case 'G':
[369]177 if( next && atol(next) != 0 )
[217]178 {
[369]179 t++;
180 if( !Image::parseGeometry( next, &cyl, &head, &sect ) )
[217]181 usage();
182 }
183 useCHS = 1;
[209]184 break;
185 case 'h': case 'H': case '?':
186 usage();
187 break;
188 case 'n': case 'N':
189 createFile = 1;
[369]190 if( next && atol(next) != 0 )
[209]191 {
[369]192 double size = atof(next);
[259]193 struct floppyInfo *fi;
194 char *c;
195
[369]196 t++;
197
[259]198 size *= 2;
199 for( c = argv[t]; *c && *c != 'k' && *c != 'K'; c++ ) ;
200 if( !(*c) )
201 size *= 1000;
202
203 if( (fi = FindFloppyInfoBySize( size )) )
204 {
205 sect = fi->sectors;
206 head = fi->heads;
207 cyl = fi->cylinders;
208 }
209 else
210 {
211 sect = 63;
212 head = 16;
213 cyl = size / (16*63);
214 }
[209]215 }
216 break;
217 case 't': case 'T':
218 timeoutEnabled = 0;
219 break;
220 case 'b': case 'B':
[369]221 if( !next )
222 usage();
223 t++;
224 if( !(baudRate = baudRateMatchString( next )) || !baudRate->rate )
225 log( -2, "Unknown Baud Rate \"%s\"", next );
[209]226 break;
227 default:
[233]228 log( -2, "Unknown Option: \"%s\"", argv[t] );
[209]229 }
230 }
231 else if( imagecount < 2 )
232 {
[225]233 if( createFile && cyl == 0 )
234 {
235 cyl = 65;
236 sect = 63;
237 head = 16;
238 }
[217]239 images[imagecount] = new FlatImage( argv[t], readOnly, imagecount, createFile, cyl, head, sect, useCHS );
[209]240 imagecount++;
[217]241 createFile = readOnly = cyl = sect = head = useCHS = 0;
[209]242 }
243 else
244 usage();
245 }
246
247 if( imagecount == 0 )
248 usage();
249
[215]250 if( !baudRate )
[233]251 baudRate = baudRateMatchString( "9600" );
[215]252
[209]253 do
254 {
[219]255 serial.Connect( ComPort, baudRate );
[209]256
[219]257 processRequests( &serial, images[0], images[1], timeoutEnabled, verbose );
[209]258
[219]259 serial.Disconnect();
[209]260
[219]261 if( serial.resetConnection )
262 log( 0, "Serial Connection closed, reset..." );
[209]263 }
[219]264 while( serial.resetConnection );
[209]265}
266
267void log( int level, char *message, ... )
268{
269 va_list args;
270
271 va_start( args, message );
272
[211]273 if( level < 0 )
[209]274 {
[211]275 fprintf( stderr, "ERROR: " );
276 vfprintf( stderr, message, args );
277 fprintf( stderr, "\n" );
[233]278 if( level < -1 )
279 {
280 fprintf( stderr, "\n" );
281 usage();
282 }
[211]283 exit( 1 );
[209]284 }
285 else if( verbose >= level )
286 {
[211]287 vprintf( message, args );
288 printf( "\n" );
[209]289 }
290
291 va_end( args );
292}
293
294unsigned long GetTime(void)
295{
296 return( GetTickCount() );
297}
298
299unsigned long GetTime_Timeout(void)
300{
301 return( 1000 );
302}
Note: See TracBrowser for help on using the repository browser.