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
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.
[526]9//
[209]10
[376]11//
[526]12// XTIDE Universal BIOS and Associated Tools
13// Copyright (C) 2009-2010 by Tomi Tilli, 2011-2013 by XTIDE Universal BIOS Team.
[376]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.
[526]19//
[376]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
[526]23// GNU General Public License for more details.
[376]24// Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
25//
26
[209]27#include <stdio.h>
28#include <stdlib.h>
29#include <fcntl.h>
30#include <stdarg.h>
31
[589]32#include "../library/Library.h"
33#include "../library/FlatImage.h"
[209]34
[589]35#include "../../XTIDE_Universal_BIOS/Inc/Version.inc"
[371]36
[369]37char *bannerStrings[] = {
38 "SerDrive - XTIDE Universal BIOS Serial Drive Server",
[592]39 "Copyright (C) 2012-2018 by XTIDE Universal BIOS Team",
[369]40 "Released under GNU GPL v2, with ABSOLUTELY NO WARRANTY",
[371]41 ROM_VERSION_STRING,
[526]42 "",
[369]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 "",
[592]51 "Visit the wiki on http://xtideuniversalbios.org for detailed usage directions.",
[369]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",
[526]59 " Maximum size is " USAGE_MAXSECTORS,
[369]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:",
[488]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",
[369]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[] )
[209]98{
[369]99 for( int t = 0; strings[t]; t++ )
[258]100 {
[369]101 if( !strncmp( strings[t], "COM", 3 ) )
[258]102 {
103 char logbuff[ 1024 ];
[209]104
[258]105 SerialAccess::EnumerateCOMPorts( logbuff, 1024 );
[369]106 fprintf( stderr, "%s%s\n", strings[t]+3, logbuff );
[258]107 }
108 else
[369]109 fprintf( stderr, "%s\n", strings[t] );
[258]110 }
[209]111}
112
[369]113#define usage() { usagePrint( usageStrings ); exit(1); }
114
[211]115int verbose = 0;
[209]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
[219]126 SerialAccess serial;
[209]127 Image *img;
[215]128 struct baudRate *baudRate = NULL;
[209]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;
[217]137 int readOnly = 0, createFile = 0;
138 int useCHS = 0;
[209]139
140 int imagecount = 0;
141 Image *images[2] = { NULL, NULL };
142
[369]143 usagePrint( bannerStrings );
144
[209]145 for( int t = 1; t < argc; t++ )
146 {
[369]147 char *next = (t+1 < argc ? argv[t+1] : NULL );
148
[209]149 if( argv[t][0] == '/' || argv[t][0] == '-' )
150 {
151 char *c;
152 unsigned long a;
[526]153 for( c = &argv[t][1]; *c && !isdigit( *c ); c++ )
[209]154 ;
155 a = atol(c);
156
157 switch( argv[t][1] )
158 {
159 case 'c': case 'C':
[369]160 if( !next )
161 usage();
162 t++;
163 a = atol( next );
[209]164 if( a < 1 )
165 usage();
166 sprintf( ComPortBuff, "COM%d", a );
167 ComPort = &ComPortBuff[0];
168 break;
169 case 'v': case 'V':
[369]170 if( next && atol(next) != 0 )
171 {
172 t++;
173 verbose = atol(next);
174 }
[209]175 else
[213]176 verbose = 1;
[209]177 break;
178 case 'r': case 'R':
179 readOnly = 1;
180 break;
181 case 'p': case 'P':
[369]182 if( next && next[0] == '\\' && next[1] == '\\' )
183 {
184 t++;
185 ComPort = next;
186 }
[258]187 else
188 ComPort = PIPENAME;
[215]189 if( !baudRate )
190 baudRate = baudRateMatchString( "115200" );
[526]191 break;
[209]192 case 'g': case 'G':
[369]193 if( next && atol(next) != 0 )
[217]194 {
[369]195 t++;
196 if( !Image::parseGeometry( next, &cyl, &head, &sect ) )
[217]197 usage();
198 }
199 useCHS = 1;
[209]200 break;
201 case 'h': case 'H': case '?':
202 usage();
203 break;
204 case 'n': case 'N':
205 createFile = 1;
[369]206 if( next && atol(next) != 0 )
[209]207 {
[369]208 double size = atof(next);
[259]209 struct floppyInfo *fi;
210 char *c;
211
[369]212 t++;
213
[259]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 }
[209]231 }
232 break;
233 case 't': case 'T':
234 timeoutEnabled = 0;
235 break;
236 case 'b': case 'B':
[369]237 if( !next )
238 usage();
239 t++;
240 if( !(baudRate = baudRateMatchString( next )) || !baudRate->rate )
241 log( -2, "Unknown Baud Rate \"%s\"", next );
[209]242 break;
243 default:
[233]244 log( -2, "Unknown Option: \"%s\"", argv[t] );
[209]245 }
246 }
247 else if( imagecount < 2 )
248 {
[225]249 if( createFile && cyl == 0 )
250 {
251 cyl = 65;
252 sect = 63;
253 head = 16;
254 }
[217]255 images[imagecount] = new FlatImage( argv[t], readOnly, imagecount, createFile, cyl, head, sect, useCHS );
[209]256 imagecount++;
[217]257 createFile = readOnly = cyl = sect = head = useCHS = 0;
[209]258 }
259 else
260 usage();
261 }
262
263 if( imagecount == 0 )
264 usage();
265
[215]266 if( !baudRate )
[233]267 baudRate = baudRateMatchString( "9600" );
[215]268
[209]269 do
270 {
[219]271 serial.Connect( ComPort, baudRate );
[209]272
[219]273 processRequests( &serial, images[0], images[1], timeoutEnabled, verbose );
[209]274
[219]275 serial.Disconnect();
[209]276
[219]277 if( serial.resetConnection )
278 log( 0, "Serial Connection closed, reset..." );
[209]279 }
[219]280 while( serial.resetConnection );
[209]281}
282
283void log( int level, char *message, ... )
284{
285 va_list args;
286
287 va_start( args, message );
288
[211]289 if( level < 0 )
[209]290 {
[211]291 fprintf( stderr, "ERROR: " );
292 vfprintf( stderr, message, args );
293 fprintf( stderr, "\n" );
[233]294 if( level < -1 )
295 {
296 fprintf( stderr, "\n" );
297 usage();
298 }
[211]299 exit( 1 );
[209]300 }
301 else if( verbose >= level )
302 {
[211]303 vprintf( message, args );
304 printf( "\n" );
[209]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.