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

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

Serial Port: split single byte port and baud into two bytes, taking advantage of the two bytes in DPT_SERIAL, which supports more serial baud rates and in particular fixed a bug where a 4x client machine couldn't talk to a 115.2K server machine. This is a wide change, touching lots of files, but most are shallow changes. DetectPrint.asm took the most significant changes, now it calculates the baud rate to display instead of using characters provided by the Configurator. The Configurator now has a new menu flag, FLG_MENUITEM_CHOICESTRINGS, for specifying that values are not linear and they should be lookedup rather than indexed. Finally, another important bug fixed here is that in some error cases, the serial port code could get into an infinite loop waiting ont the hardware; now it has a timeout.

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