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

Last change on this file since 629 was 624, checked in by Krister Nordvall, 2 years ago

Changes:

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