| 1 | /* $Id: log.c,v 1.2 2000-09-02 21:08:13 bird Exp $ | 
|---|
| 2 | * | 
|---|
| 3 | * log - C-style logging - kprintf. | 
|---|
| 4 | * | 
|---|
| 5 | * Copyright (c) 1998-1999 knut st. osmundsen | 
|---|
| 6 | * | 
|---|
| 7 | */ | 
|---|
| 8 |  | 
|---|
| 9 |  | 
|---|
| 10 | /*@Const************************************************************************ | 
|---|
| 11 | *   Defined Constants                                                          * | 
|---|
| 12 | *******************************************************************************/ | 
|---|
| 13 | #define INCL_DOSERRORS | 
|---|
| 14 | #define INCL_NOPMAPI | 
|---|
| 15 |  | 
|---|
| 16 | /*@Header*********************************************************************** | 
|---|
| 17 | *   Header Files                                                               * | 
|---|
| 18 | *******************************************************************************/ | 
|---|
| 19 | #include <os2.h> | 
|---|
| 20 |  | 
|---|
| 21 | #include <string.h> | 
|---|
| 22 | #include <stdarg.h> | 
|---|
| 23 | #include <builtin.h> | 
|---|
| 24 |  | 
|---|
| 25 | #include "devSegDf.h"                   /* Win32k segment definitions. */ | 
|---|
| 26 | #include "dev32.h" | 
|---|
| 27 | #include "options.h" | 
|---|
| 28 | #include "log.h" | 
|---|
| 29 | #include "sprintf.h" | 
|---|
| 30 | #include "yield.h" | 
|---|
| 31 |  | 
|---|
| 32 |  | 
|---|
| 33 | /******************************************************************************* | 
|---|
| 34 | *   Global Variables                                                           * | 
|---|
| 35 | *******************************************************************************/ | 
|---|
| 36 | static char  achBuffer[512]; /* buffer for kprintf */ | 
|---|
| 37 |  | 
|---|
| 38 |  | 
|---|
| 39 | /******************************************************************************* | 
|---|
| 40 | *   Internal Functions                                                         * | 
|---|
| 41 | *******************************************************************************/ | 
|---|
| 42 | static void write(char *psz); | 
|---|
| 43 |  | 
|---|
| 44 |  | 
|---|
| 45 | /** | 
|---|
| 46 | * Writes a string to logBuffer and to comport. | 
|---|
| 47 | * @param     psz   Pointer to zero-string to be put to com-port. | 
|---|
| 48 | * @param     Port  Port number of the com-port. | 
|---|
| 49 | * @remark    A lonely '\n' will result in a '\r\n' sequence. | 
|---|
| 50 | */ | 
|---|
| 51 | static void write(char *psz) | 
|---|
| 52 | { | 
|---|
| 53 | /* if logging (to com port) enabled - log to COM-port */ | 
|---|
| 54 | if (options.fLogging) | 
|---|
| 55 | { | 
|---|
| 56 | ULONG ulPort = options.usCom; | 
|---|
| 57 | int   cch = 0; | 
|---|
| 58 |  | 
|---|
| 59 | while (*psz != '\0') | 
|---|
| 60 | { | 
|---|
| 61 | while (!(_inp(ulPort + 5) & 0x20));  /* waits for port To Be ready */ | 
|---|
| 62 | _outp(ulPort, *psz);                 /* put char and inc pointer */ | 
|---|
| 63 |  | 
|---|
| 64 | /* new line fix */ | 
|---|
| 65 | if (psz[1] == '\n' && psz[0] != '\r') | 
|---|
| 66 | { | 
|---|
| 67 | while (!(_inp(ulPort + 5) & 0x20));  /* waits for port To Be ready */ | 
|---|
| 68 | _outp(ulPort, '\r');                 /* put char and inc pointer */ | 
|---|
| 69 | cch++; | 
|---|
| 70 | } | 
|---|
| 71 | psz++; | 
|---|
| 72 | if ((++cch % 3) == 0) /* 9600 bit/s -> 1066 bytes (9bit) -> 3 chars takes 3.2 ms to send */ | 
|---|
| 73 | Yield(); | 
|---|
| 74 | } | 
|---|
| 75 | } | 
|---|
| 76 | } | 
|---|
| 77 |  | 
|---|
| 78 |  | 
|---|
| 79 | /** | 
|---|
| 80 | * printf to log. | 
|---|
| 81 | * @param   pFormat  Formatstring | 
|---|
| 82 | * @param   ...      Other stuff used in pFormat. | 
|---|
| 83 | * @remark  This functions may yield the CPU! | 
|---|
| 84 | */ | 
|---|
| 85 | void _kprintf(const char *pszFormat, ...) | 
|---|
| 86 | { | 
|---|
| 87 | va_list arg; | 
|---|
| 88 |  | 
|---|
| 89 | /* check pFormat */ | 
|---|
| 90 | if (pszFormat == NULL) | 
|---|
| 91 | { | 
|---|
| 92 | write("\nWarning: Null pointer detected in kprint\n"); | 
|---|
| 93 | return; | 
|---|
| 94 | } | 
|---|
| 95 |  | 
|---|
| 96 | /* build string */ | 
|---|
| 97 | va_start(arg, pszFormat); | 
|---|
| 98 | vsprintf(achBuffer, pszFormat, arg); | 
|---|
| 99 | va_end(arg); | 
|---|
| 100 |  | 
|---|
| 101 | /* write string */ | 
|---|
| 102 | write(achBuffer); | 
|---|
| 103 | } | 
|---|