SBSPSS/source/system/dbg.cpp

309 lines
6.8 KiB
C++
Raw Normal View History

2000-09-12 01:40:37 +02:00
/*=========================================================================
dbg.cpp
Author: PKG
Created:
Project:
Purpose:
Copyright (c) 2000 Climax Development Ltd
===========================================================================*/
/*----------------------------------------------------------------------
Includes
-------- */
#include "dbg.h"
#ifdef DBG_ACTIVE
#ifndef __SYSTEM_VSPRINTF_H__
#include "system\vsprintf.h"
#endif
/* Std Lib
------- */
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
/* Data
---- */
/*----------------------------------------------------------------------
Tyepdefs && Defines
------------------- */
2000-09-15 19:20:48 +02:00
/*
Available options are:
DBG_OUTPUT_TO_DEBUGGER Send output to the debug console
DBG_OUTPUT_TO_LOG Send output to an internal log
DBG_MAX_MESSAGE_LENGTH chars Length of entries in this log
DBG_LOG_LINES lines Number of lines in the log buffer
DBG_SHOW_MESSAGE_ORIGIN Prepend file and linenumber to messages
DBG_FILENAME_LENGTH chars This many chars of the filename are shown
DBG_DEFAULT_CHANNEL channelflags Channels to listen to by default
*/
2000-09-12 01:40:37 +02:00
#ifdef __USER_charles__
2000-09-15 19:20:48 +02:00
#define DBG_OUTPUT_TO_DEBUGGER
#define DBG_SHOW_MESSAGE_ORIGIN
#define DBG_FILENAME_LENGTH 16
2000-10-27 23:20:30 +02:00
#define DBG_DEFAULT_CHANNEL DC_CHARLES|DC_SYSTEM|DC_SOUND
2000-09-12 01:40:37 +02:00
#elif __USER_dave__
2000-09-15 19:20:48 +02:00
#define DBG_OUTPUT_TO_DEBUGGER
#define DBG_SHOW_MESSAGE_ORIGIN
#define DBG_FILENAME_LENGTH 16
2000-10-27 23:20:30 +02:00
#define DBG_DEFAULT_CHANNEL DC_DAVE|DC_SYSTEM|DC_SOUND
2000-09-12 01:40:37 +02:00
#elif __USER_paul__
2000-09-15 19:20:48 +02:00
#define DBG_OUTPUT_TO_DEBUGGER
#define DBG_OUTPUT_TO_LOG
#define DBG_MAX_MESSAGE_LENGTH 256
2000-10-16 18:50:26 +02:00
#define DBG_LOG_LINES 8
2000-09-15 19:20:48 +02:00
#define DBG_SHOW_MESSAGE_ORIGIN
2000-10-05 16:12:08 +02:00
#define DBG_FILENAME_LENGTH 10
2000-10-27 23:20:30 +02:00
#define DBG_DEFAULT_CHANNEL DC_PAUL|DC_SYSTEM|DC_SOUND|DC_GUI
2000-09-12 01:40:37 +02:00
#else
2000-09-15 19:20:48 +02:00
#define DBG_OUTPUT_TO_DEBUGGER
#define DBG_DEFAULT_CHANNEL DC_ALL
2000-09-12 01:40:37 +02:00
#endif
/*----------------------------------------------------------------------
Structure defintions
-------------------- */
/*----------------------------------------------------------------------
Function Prototypes
------------------- */
/*----------------------------------------------------------------------
Vars
---- */
static DEBUG_CHANNEL_FLAG s_activeChannelFlags=(DEBUG_CHANNEL_FLAG)(DBG_DEFAULT_CHANNEL);
2000-09-15 19:20:48 +02:00
static int s_dbgTransientChannelFlags=DC_NONE;
static char s_dbgTransientFilename[DBG_FILENAME_LENGTH+1]="\0";
static int s_dbgTransientLine=0;
2000-09-12 01:40:37 +02:00
#ifdef DBG_OUTPUT_TO_LOG
static char s_logLines[DBG_LOG_LINES][DBG_MAX_MESSAGE_LENGTH];
static int s_logLineCount=0;
static int s_logLinePtr=0;
#endif
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void __setActiveDbgChannels(DEBUG_CHANNEL_FLAG _channelFlags)
{
s_activeChannelFlags=_channelFlags;
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
DEBUG_CHANNEL_FLAG __getActiveDbgChannels()
{
return s_activeChannelFlags;
}
/*----------------------------------------------------------------------
Function:
Purpose: Used by the__DBGMSG() macro
Params:
Returns:
---------------------------------------------------------------------- */
void __setDbgChannels(DEBUG_CHANNEL_FLAG _channelFlags)
{
2000-09-15 19:20:48 +02:00
s_dbgTransientChannelFlags=_channelFlags;
2000-09-12 01:40:37 +02:00
}
/*----------------------------------------------------------------------
Function:
Purpose: Used by the__DBGMSG() macro
Params:
Returns:
---------------------------------------------------------------------- */
void __setDbgFilenameAndLine(const char *_filename,int _line)
{
int filenameLength;
int start,len;
filenameLength=strlen(_filename);
if(filenameLength<DBG_FILENAME_LENGTH)
{
for(int i=0;i<DBG_FILENAME_LENGTH-filenameLength;i++)
2000-09-15 19:20:48 +02:00
s_dbgTransientFilename[i]=' ';
2000-09-12 01:40:37 +02:00
start=0;
len=filenameLength;
}
else
{
start=strlen(_filename)-DBG_FILENAME_LENGTH;
len=DBG_FILENAME_LENGTH;
}
2000-09-15 19:20:48 +02:00
strncpy(s_dbgTransientFilename+DBG_FILENAME_LENGTH-len,_filename+start,len);
s_dbgTransientLine=_line;
2000-09-12 01:40:37 +02:00
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void __writeDbgMessage(const char *_format,...)
{
2000-09-15 19:20:48 +02:00
if(s_dbgTransientChannelFlags&s_activeChannelFlags)
2000-09-12 01:40:37 +02:00
{
char messageBuffer[DBG_MAX_MESSAGE_LENGTH+1];
__va_list va;
int start;//,len;
__va_start(va,_format);
#ifdef DBG_SHOW_MESSAGE_ORIGIN
2000-09-15 19:20:48 +02:00
sprintf(messageBuffer,"%s:%04d ",s_dbgTransientFilename,s_dbgTransientLine);
2000-09-12 01:40:37 +02:00
start=strlen(messageBuffer);
// len=DBG_MAX_MESSAGE_LENGTH-start;
#else
start=0;
// len=DBG_MAX_MESSAGE_LENGTH;
#endif
__vsprintf(messageBuffer+start,_format,va);
__va_end(va);
#ifdef DBG_OUTPUT_TO_DEBUGGER
printf("%s\n",messageBuffer);
#endif
#ifdef DBG_OUTPUT_TO_LOG
strncpy(s_logLines[s_logLinePtr],messageBuffer,DBG_MAX_MESSAGE_LENGTH);
s_logLinePtr=(s_logLinePtr+1)%DBG_LOG_LINES;
if(s_logLineCount<DBG_LOG_LINES)s_logLineCount++;
#endif
}
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
int __getNumberOfDbgLinesInLog()
{
#ifdef DBG_OUTPUT_TO_LOG
return s_logLineCount;
#else
return 0;
#endif
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
char *__getDbgLineFromLog(int _line)
{
#ifdef DBG_OUTPUT_TO_LOG
2000-09-29 23:07:43 +02:00
return s_logLines[(s_logLinePtr+_line)%DBG_LOG_LINES];
2000-09-12 01:40:37 +02:00
#else
return "Damn fool..";
#endif
}
2000-09-12 01:50:22 +02:00
#endif /* DBG_ACTIVE */
2000-09-12 01:40:37 +02:00
2000-09-12 01:50:22 +02:00
#ifdef __VERSION_DEBUG__
2000-09-12 01:40:37 +02:00
#define OnScreenDebug
#include "gfx\font.h"
#include "system\vid.h"
#include "gfx\prim.h"
/*****************************************************************************/
void DoAssert( const char * Txt, const char * file, const int line )
{
printf( "%s", Txt );
#ifdef OnScreenDebug
FontBank F;
char Text[2048];
sprintf( Text, "%s\nLine %d in %s", Txt, line, file );
F.initialise( &standardFont );
F.setJustification( FontBank::JUST_CENTRE );
F.setOt( 0 );
ClearNTag(OtPtr, MAX_OT);
F.print( (512 >> 1), (256 >> 1), Text );
VSync(0);
VidSwapDraw();
PrimDisplay();
while(DrawSync(1));
ClearNTag(OtPtr, MAX_OT);
F.print( (512 >> 1), (256 >> 1), Text );
VSync(0);
VidSwapDraw();
PrimDisplay();
while(DrawSync(1));
F.dump();
#endif
PSYQpause();
}
/*****************************************************************************/
void DbgPollHost()
{
#if !defined(__USER_ART__)
#if __FILE_SYSTEM__==PC
pollhost();
#endif
#endif
}
2000-09-12 01:50:22 +02:00
#endif /* __VERSION_DEBUG__ */
2000-09-12 01:40:37 +02:00
/*===========================================================================
end */