source: cmedia/trunk/Drv16/commdbg.c@ 554

Last change on this file since 554 was 554, checked in by rudi, 14 years ago

Update to version 0.2.3

File size: 8.6 KB
Line 
1/* $Id: commdbg.c,v 1.2 2000/07/17 18:32:33 sandervl Exp $ */
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
43#define CR 0x0d
44#define LF 0x0a
45
46#define LEADING_ZEROES 0x8000
47#define SIGNIFICANT_FIELD 0x0007
48
49
50BOOL fLineTerminate = TRUE;
51int dbglevel = 2;
52
53static char hextab[]="0123456789ABCDEF";
54
55
56#ifdef DEBUG
57#define MAGIC_COMM_PORT 0x3f8 // pulled from word ptr 40:0
58//#define MAGIC_COMM_PORT 0x2f8 // pulled from word ptr 40:0
59
60
61#define UART_DATA 0x00 // UART Data port
62#define UART_INT_ENAB 0x01 // UART Interrupt enable
63#define UART_INT_ID 0x02 // interrupt ID
64#define UART_LINE_CTRL 0x03 // line control registers
65#define UART_MODEM_CTRL 0x04 // modem control register
66#define UART_LINE_STAT 0x05 // line status register
67#define UART_MODEM_STAT 0x06 // modem status regiser
68#define UART_DIVISOR_LO 0x00 // divisor latch least sig
69#define UART_DIVISOR_HI 0x01h // divisor latch most sig
70
71#define DELAY nop
72#endif
73
74#ifdef DEBUG //--------------------------- CharOut -
75void CharOut(char c)
76{
77 _asm {
78
79 mov dx, MAGIC_COMM_PORT // address of PS/2's first COM port
80 add dx, UART_LINE_STAT
81
82ReadyCheck:
83 in al, dx // wait for comm port ready signal
84
85 DELAY
86 DELAY
87 DELAY
88
89 test al, 020h
90 jz ReadyCheck
91
92 // Send the character
93
94 add dx, UART_DATA - UART_LINE_STAT
95 mov al,c
96 out dx, al
97
98 DELAY
99 DELAY
100 DELAY
101 }
102}
103#endif
104
105
106#ifdef DEBUG //------------------------- StringOut -
107void StringOut(char far *DbgStr)
108{
109 while (*DbgStr)
110 CharOut(*DbgStr++);
111
112 if (fLineTerminate)
113 {
114 CharOut(CR); // append carriage return,
115 CharOut(LF); // linefeed
116 }
117}
118#endif
119
120 //-------------------- DecWordToASCII -
121char far * cdecl DecWordToASCII(char far *StrPtr, USHORT wDecVal, USHORT Option)
122{
123 USHORT Power;
124 USHORT Digit;
125 USHORT fNonZero = Option & LEADING_ZEROES;
126
127 for( Power = 10000; Power; Power /= 10 )
128 {
129 Digit = 0;
130 while( wDecVal >= Power ) { Digit++; wDecVal -= Power; }
131 fNonZero |= Digit;
132
133 if( fNonZero || Power == 1 ) *StrPtr++ = (char)('0' + Digit);
134 }
135
136 return StrPtr;
137}
138
139
140#ifdef DEBUG //-------------------- DecLongToASCII -
141char far * cdecl DecLongToASCII(char far *StrPtr, ULONG lDecVal, USHORT Option)
142{
143 ULONG Power;
144 USHORT Digit;
145 USHORT fNonZero = Option & LEADING_ZEROES;
146
147 for( Power = 1000000000L; Power; Power /= 10 )
148 {
149 Digit = 0;
150 while( lDecVal >= Power ) { Digit++; lDecVal -= Power; }
151 fNonZero |= Digit;
152
153 if( fNonZero || Power == 1 ) *StrPtr++ = (char)('0' + Digit);
154 }
155
156 return StrPtr;
157}
158#endif
159
160 //-------------------- HexWordToASCII -
161char far * cdecl HexWordToASCII(char far *StrPtr, USHORT wHexVal, USHORT Option)
162{
163 USHORT Digit;
164 SHORT ShiftVal;
165 USHORT fNonZero = Option & LEADING_ZEROES;
166
167 for( ShiftVal = 12; ShiftVal >= 0; ShiftVal -= 4 )
168 {
169 Digit = (wHexVal >> ShiftVal) & 0xf;
170 fNonZero |= Digit;
171
172 if( fNonZero || !ShiftVal ) *StrPtr++ = hextab[Digit];
173 }
174
175 return StrPtr;
176}
177
178
179#ifdef DEBUG //-------------------- HexLongToASCII -
180char far * cdecl HexLongToASCII(char far *StrPtr, ULONG lHexVal, USHORT Option)
181{
182 USHORT Digit;
183 SHORT ShiftVal;
184 USHORT fNonZero = Option & LEADING_ZEROES;
185
186 for( ShiftVal = 28; ShiftVal >= 0; ShiftVal -= 4 )
187 {
188 Digit = (USHORT)(lHexVal >> ShiftVal) & 0xf;
189 fNonZero |= Digit;
190
191 if( fNonZero || !ShiftVal ) *StrPtr++ = hextab[Digit];
192 }
193
194 return StrPtr;
195}
196#endif
197
198
199#ifdef DEBUG //------------------------- PrintfOut -
200void cdecl PrintfOut(char far *DbgStr , ...)
201{
202 static char BuildString[1024];
203 char far *BuildPtr=BuildString;
204 char far *pStr=(char far *) DbgStr;
205 char far *SubStr;
206 union {
207 void far *VoidPtr;
208 USHORT far *WordPtr;
209 ULONG far *LongPtr;
210 ULONG far *StringPtr;
211 } Parm;
212 USHORT wBuildOption;
213
214 Parm.VoidPtr=(void far *) &DbgStr;
215 Parm.StringPtr++; // skip size of string pointer
216
217 while (*pStr)
218 {
219 // don't overflow target
220 if (BuildPtr >= (char far *) &BuildString[1024-2])
221 break;
222
223 switch (*pStr)
224 {
225 case '%':
226 wBuildOption=0;
227 pStr++;
228 if (*pStr=='0')
229 {
230 wBuildOption|=LEADING_ZEROES;
231 pStr++;
232 }
233 if (*pStr=='u') // always unsigned
234 pStr++;
235
236 switch(*pStr)
237 {
238 case 'x':
239 case 'X':
240 BuildPtr=HexWordToASCII(BuildPtr, *Parm.WordPtr++,wBuildOption);
241 pStr++;
242 continue;
243
244 case 'd':
245 BuildPtr=DecWordToASCII(BuildPtr, *Parm.WordPtr++,wBuildOption);
246 pStr++;
247 continue;
248
249 case 's':
250 SubStr=(char far *)*Parm.StringPtr;
251 while (*BuildPtr++ = *SubStr++);
252 Parm.StringPtr++;
253 BuildPtr--; // remove the \0
254 pStr++;
255 continue;
256
257 case 'l':
258 pStr++;
259 switch (*pStr)
260 {
261 case 'x':
262 case 'X':
263 BuildPtr=HexLongToASCII(BuildPtr, *Parm.LongPtr++,wBuildOption);
264 pStr++;
265 continue;
266
267 case 'd':
268 BuildPtr=DecLongToASCII(BuildPtr, *Parm.LongPtr++,wBuildOption);
269 pStr++;
270 continue;
271 } // end switch
272 continue; // dunno what he wants
273
274 case 0:
275 continue;
276 } // end switch
277 break;
278
279 case '\\':
280 pStr++;
281 switch (*pStr)
282 {
283 case 'n':
284 *BuildPtr++=LF;
285 pStr++;
286 continue;
287
288 case 'r':
289 *BuildPtr++=CR;
290 pStr++;
291 continue;
292
293 case 0:
294 continue;
295 break;
296 } // end switch
297
298 break;
299 } // end switch
300
301 *BuildPtr++=*pStr++;
302 } // end while
303
304 *BuildPtr=0; // cauterize the string
305 StringOut((char far *) BuildString); // print to comm port
306}
307#endif //DEBUG
308
309
Note: See TracBrowser for help on using the repository browser.