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

Last change on this file since 601 was 592, checked in by Krister Nordvall, 6 years ago

Changes:

  • The problem with NASM in the previous revision (r591) has been fixed.
  • The colors used by the boot menu and hotkey bar can now be customized by selecting one of a number of pre-defined color themes. Suggestions for additional themes are more than welcome!
  • Large builds are now 10 KB. Small builds are still 8 KB with the exception of the Tiny build which is now 4 KB. In other words, builds are now as small as possible to make it easier to combine them with other BIOSes.
  • Added code to the library to improve drive error handling. XTIDECFG can now handle "Drive Not Ready" errors.
  • Fixed a couple of potential bugs in AtaID.asm (AtaID_GetMaxPioModeToAXandMinCycleTimeToCX); 1) ATA1.bPioMode was treated as a WORD variable. 2) ATA2.bPIOSupp was assumed to be non-zero which would result in PIO mode 3 being returned if the assumption was wrong.
  • Made the same changes in the equivalent function used by BIOSDRVS (DisplayPioModeInformationUsingAtaInfoFromDSBX in AtaInfo.asm).
  • Fixed a bug from r587 in PDC20x30.asm in PDC20x30_GetMaxPioModeToALandMinPioCycleTimeToBX.
  • Fixed a bug from r523 in XTIDECFG where Auto Configure would only set the IRQ on one IDE interface on AT-builds.
  • XTIDECFG will now restore the default settings for the "Serial port virtual device" when reselecting it in the list of device types. This makes it behave consistently for all device types.
  • The eAAM macro is now used regardless if USE_UNDOC_INTEL is defined or not because it is apparently supported on all processors including the NEC V20/V30 CPUs.
  • Renamed the EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS define to EXCLUDE_FROM_XUB.
  • Added a define to exclude unused library code from BIOSDRVS (EXCLUDE_FROM_BIOSDRVS). This makes it a lot smaller than in previous revisions.
  • All unnecessary CLD-instructions are now under a new define 'CLD_NEEDED' which is only enabled for the BIOS. It is disabled for XTIDECFG and BIOSDRVS but can be enabled if needed by adding this define to the respective makefile. This change was made because these unnecessary instructions are wasteful and should never be needed. In fact, they only serve to hide bugs (in other peoples code) which I strongly believe should be avoided. I recommend people making their own BIOSes from source to not use this define as it's extremely unlikely to be needed.
  • Updated the copyright info in SerDrive and changed an URL to point to the new site.
  • Updated the copyright info and version number in BIOSDRVS.
  • Updated the copyright info in XTIDECFG.
  • Optimizations in general.
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
35#include "../../XTIDE_Universal_BIOS/Inc/Version.inc"
36
37char *bannerStrings[] = {
38 "SerDrive - XTIDE Universal BIOS Serial Drive Server",
39 "Copyright (C) 2012-2018 by XTIDE Universal BIOS Team",
40 "Released under GNU GPL v2, with ABSOLUTELY NO WARRANTY",
41 ROM_VERSION_STRING,
42 "",
43 NULL };
44
45char *usageStrings[] = {
46 "This is free software, and you are welcome to redistribute it under certain",
47 "conditions. For more license details, see the LICENSE.TXT file included with",
48 "this distribution, visit the XTIDE Universal BIOS wiki (address below), or",
49 "http://www.gnu.org/licenses/gpl-2.0.html",
50 "",
51 "Visit the wiki on http://xtideuniversalbios.org for detailed usage directions.",
52 "",
53 "Usage: SerDrive [options] imagefile [[slave-options] slave-imagefile]",
54 "",
55 " -g [cyl:head:sect] Geometry in cylinders, sectors per cylinder, and heads",
56 " -g also implies CHS addressing mode (default is LBA28)",
57 "",
58 " -n [megabytes] Create new disk with given size or use -g geometry",
59 " Maximum size is " USAGE_MAXSECTORS,
60 " Floppy images can also be created, such as \"360K\"",
61 " (default is a 32 MB disk, with CHS geometry 65:16:63)",
62 "",
63 " -p [pipename] Named Pipe mode for emulators",
64 " (must begin with \"\\\\\", default is \"" PIPENAME "\")",
65 "",
66 " -c COMPortNumber COM Port to use (default is first found)",
67 " Available COM ports on this system are:",
68 "COM ",
69 "",
70 " -b BaudRate Baud rate to use on the COM port, with client machine",
71 " rate multiplier in effect:",
72 " None: 2400, 4800, 9600, 28.8K, 57.6K, 115.2K",
73 " 2x: 4800, 9600, 19200, 57.6K, 115.2K, 230.4K",
74 " 4x: 9600, 19200, 38400, 115.2K, 230.4K, 460.8K",
75 " 8x: 19200, 38400, 115.2K, 230.4K, 460.8K, 921.6K",
76 " and for completeness: 76.8K, 153.6K",
77 " (default is 9600, 115.2K when in named pipe mode)",
78 "",
79 " -t Disable timeout, useful for long delays when debugging",
80 "",
81 " -r Read Only disk, do not allow writes",
82 "",
83 " -v [level] Reporting level 1-6, with increasing information",
84 "",
85 "On the client computer, a serial port can be configured for use as a hard disk",
86 "with xtidecfg.com. Or one can hold down the ALT key at the end of the normal",
87 "IDE hard disk scan and the XTIDE Universal BIOS will scan COM1-7, at each of",
88 "the six speeds given above for BaudRate. Note that hardware rate multipliers",
89 "must be taken into account on the server end, but are invisible on the client.",
90 "",
91 "Floppy images may also be used. Image size must be exactly the same size",
92 "as a 2.88MB, 1.44MB, 1.2MB, 720KB, 360KB, 320KB, 180KB, or 160KB disk.",
93 "Floppy images must be the last disks discovered by the BIOS, and only",
94 "two floppy drives are supported by the BIOS at a time.",
95 NULL };
96
97void usagePrint( char *strings[] )
98{
99 for( int t = 0; strings[t]; t++ )
100 {
101 if( !strncmp( strings[t], "COM", 3 ) )
102 {
103 char logbuff[ 1024 ];
104
105 SerialAccess::EnumerateCOMPorts( logbuff, 1024 );
106 fprintf( stderr, "%s%s\n", strings[t]+3, logbuff );
107 }
108 else
109 fprintf( stderr, "%s\n", strings[t] );
110 }
111}
112
113#define usage() { usagePrint( usageStrings ); exit(1); }
114
115int verbose = 0;
116
117int main(int argc, char* argv[])
118{
119 DWORD len;
120
121 unsigned long check;
122 unsigned char w;
123
124 unsigned short wbuff[256];
125
126 SerialAccess serial;
127 Image *img;
128 struct baudRate *baudRate = NULL;
129
130 int timeoutEnabled = 1;
131
132 char *ComPort = NULL, ComPortBuff[20];
133
134 _fmode = _O_BINARY;
135
136 unsigned long cyl = 0, sect = 0, head = 0;
137 int readOnly = 0, createFile = 0;
138 int useCHS = 0;
139
140 int imagecount = 0;
141 Image *images[2] = { NULL, NULL };
142
143 usagePrint( bannerStrings );
144
145 for( int t = 1; t < argc; t++ )
146 {
147 char *next = (t+1 < argc ? argv[t+1] : NULL );
148
149 if( argv[t][0] == '/' || argv[t][0] == '-' )
150 {
151 char *c;
152 unsigned long a;
153 for( c = &argv[t][1]; *c && !isdigit( *c ); c++ )
154 ;
155 a = atol(c);
156
157 switch( argv[t][1] )
158 {
159 case 'c': case 'C':
160 if( !next )
161 usage();
162 t++;
163 a = atol( next );
164 if( a < 1 )
165 usage();
166 sprintf( ComPortBuff, "COM%d", a );
167 ComPort = &ComPortBuff[0];
168 break;
169 case 'v': case 'V':
170 if( next && atol(next) != 0 )
171 {
172 t++;
173 verbose = atol(next);
174 }
175 else
176 verbose = 1;
177 break;
178 case 'r': case 'R':
179 readOnly = 1;
180 break;
181 case 'p': case 'P':
182 if( next && next[0] == '\\' && next[1] == '\\' )
183 {
184 t++;
185 ComPort = next;
186 }
187 else
188 ComPort = PIPENAME;
189 if( !baudRate )
190 baudRate = baudRateMatchString( "115200" );
191 break;
192 case 'g': case 'G':
193 if( next && atol(next) != 0 )
194 {
195 t++;
196 if( !Image::parseGeometry( next, &cyl, &head, &sect ) )
197 usage();
198 }
199 useCHS = 1;
200 break;
201 case 'h': case 'H': case '?':
202 usage();
203 break;
204 case 'n': case 'N':
205 createFile = 1;
206 if( next && atol(next) != 0 )
207 {
208 double size = atof(next);
209 struct floppyInfo *fi;
210 char *c;
211
212 t++;
213
214 size *= 2;
215 for( c = argv[t]; *c && *c != 'k' && *c != 'K'; c++ ) ;
216 if( !(*c) )
217 size *= 1000;
218
219 if( (fi = FindFloppyInfoBySize( size )) )
220 {
221 sect = fi->sectors;
222 head = fi->heads;
223 cyl = fi->cylinders;
224 }
225 else
226 {
227 sect = 63;
228 head = 16;
229 cyl = size / (16*63);
230 }
231 }
232 break;
233 case 't': case 'T':
234 timeoutEnabled = 0;
235 break;
236 case 'b': case 'B':
237 if( !next )
238 usage();
239 t++;
240 if( !(baudRate = baudRateMatchString( next )) || !baudRate->rate )
241 log( -2, "Unknown Baud Rate \"%s\"", next );
242 break;
243 default:
244 log( -2, "Unknown Option: \"%s\"", argv[t] );
245 }
246 }
247 else if( imagecount < 2 )
248 {
249 if( createFile && cyl == 0 )
250 {
251 cyl = 65;
252 sect = 63;
253 head = 16;
254 }
255 images[imagecount] = new FlatImage( argv[t], readOnly, imagecount, createFile, cyl, head, sect, useCHS );
256 imagecount++;
257 createFile = readOnly = cyl = sect = head = useCHS = 0;
258 }
259 else
260 usage();
261 }
262
263 if( imagecount == 0 )
264 usage();
265
266 if( !baudRate )
267 baudRate = baudRateMatchString( "9600" );
268
269 do
270 {
271 serial.Connect( ComPort, baudRate );
272
273 processRequests( &serial, images[0], images[1], timeoutEnabled, verbose );
274
275 serial.Disconnect();
276
277 if( serial.resetConnection )
278 log( 0, "Serial Connection closed, reset..." );
279 }
280 while( serial.resetConnection );
281}
282
283void log( int level, char *message, ... )
284{
285 va_list args;
286
287 va_start( args, message );
288
289 if( level < 0 )
290 {
291 fprintf( stderr, "ERROR: " );
292 vfprintf( stderr, message, args );
293 fprintf( stderr, "\n" );
294 if( level < -1 )
295 {
296 fprintf( stderr, "\n" );
297 usage();
298 }
299 exit( 1 );
300 }
301 else if( verbose >= level )
302 {
303 vprintf( message, args );
304 printf( "\n" );
305 }
306
307 va_end( args );
308}
309
310unsigned long GetTime(void)
311{
312 return( GetTickCount() );
313}
314
315unsigned long GetTime_Timeout(void)
316{
317 return( 1000 );
318}
Note: See TracBrowser for help on using the repository browser.