source: sbliveos2/trunk/drv16/commdbg.c@ 200

Last change on this file since 200 was 152, checked in by sandervl, 25 years ago

misc updates

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.4 KB
Line 
1/* $Id: commdbg.c 152 2000-07-17 18:37:33Z sandervl $ */
2
3/******************************************************************************
4* Jazz16 Physical Device Driver
5* Production code and toolkit sample
6*
7* (c) Copyright IBM Corporation 1993. All rights reserved
8* (c) Copyright Media Vision Corporation 1993, 1994. All rights reserved
9*
10* DISCLAIMER OF WARRANTIES. The following [enclosed] code is
11* sample code created by IBM Corporation and Media Vision Corporation.
12* It is provided to you solely for the purpose of assisting you in the
13* development of your applications.
14* The code is provided "AS IS", without warranty of any kind.
15* IBM and Media Vision shall not be liable for any damages arising out of
16* your use of the sample code, even if they have been advised of the
17* possibility of such damages.
18*
19*******************************************************************************
20*
21* commdbg.c = debug routines to send data to COM: port
22*
23* This file contains routines to send debug information to COM: ports
24* during execution of device driver.
25* The routines provide 'C' printf like functions that send their output
26* to the serial port rather than stdout.
27* The calls to these routines are only called for debug versions of the
28* driver. See file debug.h for flags to turn on/off different debug options.
29*
30* MODIFICATION HISTORY:
31* DATE CHANGE DESCRIPTION
32* unknown Creation (Media Vision)
33* 07/30/93 Add headers for toolkit
34* 09/21/93 Header modifications
35******************************************************************************/
36
37#define INCL_NOPMAPI
38#define INCL_DOSERRORS // for ERROR_INVALID_FUNCTION
39#include <os2.h>
40#include "dbgos2.h"
41#include "commdbg.h"
42
43BOOL fLineTerminate=TRUE;
44
45#define CR 0x0d
46#define LF 0x0a
47
48
49#define LEADING_ZEROES 0x8000
50#define SIGNIFICANT_FIELD 0x0007
51
52int dbglevel = 2;
53
54char hextab[]="0123456789ABCDEF";
55
56 //-------------------- DecWordToASCII -
57char far * cdecl DecWordToASCII(char far *StrPtr, USHORT wDecVal, USHORT Option)
58{
59 BOOL fNonZero=FALSE;
60 USHORT Digit;
61 USHORT Power=10000;
62
63 while (Power)
64 {
65 Digit=0;
66 while (wDecVal >=Power) //Digit=wDecVal/Power;
67 {
68 Digit++;
69 wDecVal-=Power;
70 }
71
72 if (Digit)
73 fNonZero=TRUE;
74
75 if (Digit ||
76 fNonZero ||
77 (Option & LEADING_ZEROES) ||
78 ((Power==1) && (fNonZero==FALSE)))
79 {
80 *StrPtr=(char)('0'+Digit);
81 StrPtr++;
82 }
83
84 if (Power==10000)
85 Power=1000;
86 else if (Power==1000)
87 Power=100;
88 else if (Power==100)
89 Power=10;
90 else if (Power==10)
91 Power=1;
92 else
93 Power=0;
94 } // end while
95
96 return (StrPtr);
97}
98
99 //-------------------- DecLongToASCII -
100char far * cdecl DecLongToASCII(char far *StrPtr, ULONG lDecVal,USHORT Option)
101{
102 BOOL fNonZero=FALSE;
103 ULONG Digit;
104 ULONG Power=1000000000; // 1 billion
105
106 while (Power)
107 {
108 Digit=0; // Digit=lDecVal/Power
109 while (lDecVal >=Power) // replaced with while loop
110 {
111 Digit++;
112 lDecVal-=Power;
113 }
114
115 if (Digit)
116 fNonZero=TRUE;
117
118 if (Digit ||
119 fNonZero ||
120 (Option & LEADING_ZEROES) ||
121 ((Power==1) && (fNonZero==FALSE)))
122 {
123 *StrPtr=(char)('0'+Digit);
124 StrPtr++;
125 }
126
127 if (Power==1000000000) // 1 billion
128 Power=100000000;
129 else if (Power==100000000)
130 Power=10000000;
131 else if (Power==10000000)
132 Power=1000000;
133 else if (Power==1000000)
134 Power=100000;
135 else if (Power==100000)
136 Power=10000;
137 else if (Power==10000)
138 Power=1000;
139 else if (Power==1000)
140 Power=100;
141 else if (Power==100)
142 Power=10;
143 else if (Power==10)
144 Power=1;
145 else
146 Power=0;
147 }
148 return (StrPtr);
149}
150 //-------------------- HexWordToASCII -
151char far * cdecl HexWordToASCII(char far *StrPtr, USHORT wHexVal, USHORT Option)
152{
153 BOOL fNonZero=FALSE;
154 USHORT Digit;
155 USHORT Power=0xF000;
156 USHORT ShiftVal=12;
157
158 while (Power)
159 {
160 Digit=(wHexVal & Power)>>ShiftVal;
161 if (Digit)
162 fNonZero=TRUE;
163
164 if (Digit ||
165 fNonZero ||
166 (Option & LEADING_ZEROES) ||
167 ((Power==0x0F) && (fNonZero==FALSE)))
168 //*StrPtr++=(char)('0'+Digit);
169 *StrPtr++=hextab[Digit];
170
171 Power>>=4;
172 ShiftVal-=4;
173 } // end while
174
175 return (StrPtr);
176}
177
178 //-------------------- HexLongToASCII -
179char far * cdecl HexLongToASCII(char far *StrPtr, ULONG wHexVal, USHORT Option)
180{
181 BOOL fNonZero=FALSE;
182 ULONG Digit;
183 ULONG Power=0xF0000000;
184 ULONG ShiftVal=28;
185
186 while (Power)
187 {
188 Digit=(wHexVal & Power)>>ShiftVal;
189 if (Digit)
190 fNonZero=TRUE;
191
192 if (Digit ||
193 fNonZero ||
194 (Option & LEADING_ZEROES) ||
195 ((Power==0x0F) && (fNonZero==FALSE)))
196 *StrPtr++=hextab[Digit];
197
198 if (Power==0xF0000000) // 1 billion
199 Power=0xF000000;
200 else if (Power==0xF000000)
201 Power=0xF00000;
202 else if (Power==0xF00000)
203 Power=0xF0000;
204 else if (Power==0xF0000)
205 Power=0xF000;
206 else if (Power==0xF000)
207 Power=0xF00;
208 else if (Power==0xF00)
209 Power=0xF0;
210 else if (Power==0xF0)
211 Power=0xF;
212 else Power=0;
213
214 ShiftVal-=4;
215 } // end while
216
217 return (StrPtr);
218}
219
220#ifdef DEBUG
221char BuildString[1024];
222
223 //------------------------- PrintfOut -
224void cdecl PrintfOut(char far *DbgStr , ...)
225{
226 char far *BuildPtr=BuildString;
227 char far *pStr=(char far *) DbgStr;
228 char far *SubStr;
229 union {
230 void far *VoidPtr;
231 USHORT far *WordPtr;
232 ULONG far *LongPtr;
233 ULONG far *StringPtr;
234 } Parm;
235 USHORT wBuildOption;
236
237 Parm.VoidPtr=(void far *) &DbgStr;
238 Parm.StringPtr++; // skip size of string pointer
239
240 while (*pStr)
241 {
242 // don't overflow target
243 if (BuildPtr >= (char far *) &BuildString[1024-2])
244 break;
245
246 switch (*pStr)
247 {
248 case '%':
249 wBuildOption=0;
250 pStr++;
251 if (*pStr=='0')
252 {
253 wBuildOption|=LEADING_ZEROES;
254 pStr++;
255 }
256 if (*pStr=='u') // always unsigned
257 pStr++;
258
259 switch(*pStr)
260 {
261 case 'x':
262 case 'X':
263 BuildPtr=HexWordToASCII(BuildPtr, *Parm.WordPtr++,wBuildOption);
264 pStr++;
265 continue;
266
267 case 'd':
268 BuildPtr=DecWordToASCII(BuildPtr, *Parm.WordPtr++,wBuildOption);
269 pStr++;
270 continue;
271
272 case 's':
273 SubStr=(char far *)*Parm.StringPtr;
274 while (*BuildPtr++ = *SubStr++);
275 Parm.StringPtr++;
276 BuildPtr--; // remove the \0
277 pStr++;
278 continue;
279
280 case 'l':
281 pStr++;
282 switch (*pStr)
283 {
284 case 'x':
285 case 'X':
286 BuildPtr=HexLongToASCII(BuildPtr, *Parm.LongPtr++,wBuildOption);
287 pStr++;
288 continue;
289
290 case 'd':
291 BuildPtr=DecLongToASCII(BuildPtr, *Parm.LongPtr++,wBuildOption);
292 pStr++;
293 continue;
294 } // end switch
295 continue; // dunno what he wants
296
297 case 0:
298 continue;
299 } // end switch
300 break;
301
302 case '\\':
303 pStr++;
304 switch (*pStr)
305 {
306 case 'n':
307 *BuildPtr++=LF;
308 pStr++;
309 continue;
310
311 case 'r':
312 *BuildPtr++=CR;
313 pStr++;
314 continue;
315
316 case 0:
317 continue;
318 break;
319 } // end switch
320
321 break;
322 } // end switch
323
324 *BuildPtr++=*pStr++;
325 } // end while
326
327 *BuildPtr=0; // cauterize the string
328 StringOut((char far *) BuildString); // print to comm port
329}
330#endif //DEBUG
331
332
333#ifdef DEBUG //------------------------- StringOut -
334void StringOut(char far *DbgStr)
335{
336 while (*DbgStr)
337 CharOut(*DbgStr++);
338
339 if (fLineTerminate)
340 {
341 CharOut(CR); // append carriage return,
342 CharOut(LF); // linefeed
343 }
344}
345#endif
346
347#ifdef DEBUG
348//#define MAGIC_COMM_PORT 0x3f8 // pulled from word ptr 40:0
349#define MAGIC_COMM_PORT 0x2f8 // pulled from word ptr 40:0
350
351
352#define UART_DATA 0x00 // UART Data port
353#define UART_INT_ENAB 0x01 // UART Interrupt enable
354#define UART_INT_ID 0x02 // interrupt ID
355#define UART_LINE_CTRL 0x03 // line control registers
356#define UART_MODEM_CTRL 0x04 // modem control register
357#define UART_LINE_STAT 0x05 // line status register
358#define UART_MODEM_STAT 0x06 // modem status regiser
359#define UART_DIVISOR_LO 0x00 // divisor latch least sig
360#define UART_DIVISOR_HI 0x01h // divisor latch most sig
361
362#define DELAY nop
363#endif
364
365#ifdef DEBUG //--------------------------- CharOut -
366void CharOut(char c)
367{
368 _asm {
369
370 mov dx, MAGIC_COMM_PORT // address of PS/2's first COM port
371 add dx, UART_LINE_STAT
372
373ReadyCheck:
374 in al, dx // wait for comm port ready signal
375
376 DELAY
377 DELAY
378 DELAY
379
380 test al, 020h
381 jz ReadyCheck
382
383 // Send the character
384
385 add dx, UART_DATA - UART_LINE_STAT
386 mov al,c
387 out dx, al
388
389 DELAY
390 DELAY
391 DELAY
392 }
393}
394#endif
Note: See TracBrowser for help on using the repository browser.