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