SBSPSS/source/system/dbg.cpp

315 lines
6.9 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-11-24 22:08:03 +01:00
#define DBG_DEFAULT_CHANNEL DC_CHARLES|DC_SYSTEM
2000-12-01 22:39:09 +01:00
#elif __USER_daveo__
2000-09-15 19:20:48 +02:00
#define DBG_OUTPUT_TO_DEBUGGER
#define DBG_SHOW_MESSAGE_ORIGIN
#define DBG_FILENAME_LENGTH 16
2000-11-24 22:08:03 +01:00
#define DBG_DEFAULT_CHANNEL DC_DAVE|DC_SYSTEM
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-11-24 20:46:36 +01:00
#define DBG_FILENAME_LENGTH 12
2001-01-03 17:20:58 +01:00
#define DBG_DEFAULT_CHANNEL DC_PAUL|DC_SYSTEM|DC_SOUND|DC_GUI|DC_MEMCARD
2000-09-12 01:40:37 +02:00
#else
2000-09-15 19:20:48 +02:00
#define DBG_OUTPUT_TO_DEBUGGER
2000-12-01 22:39:09 +01:00
#define DBG_FILENAME_LENGTH 16
2001-05-08 20:47:36 +02:00
#define DBG_DEFAULT_CHANNEL DC_SYSTEM
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
{
2000-12-01 22:43:30 +01:00
char messageBuffer[256];
2000-09-12 01:40:37 +02:00
__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];
2001-04-25 22:20:34 +02:00
ClearScreenImage();
2000-09-12 01:40:37 +02:00
sprintf( Text, "%s\nLine %d in %s", Txt, line, file );
F.initialise( &standardFont );
F.setJustification( FontBank::JUST_CENTRE );
F.setOt( 0 );
2001-04-19 01:04:03 +02:00
InitOTag(OtPtr, MAX_OT);
2000-09-12 01:40:37 +02:00
F.print( (512 >> 1), (256 >> 1), Text );
VSync(0);
VidSwapDraw();
2001-05-18 18:44:51 +02:00
// PrimDisplay();
DrawOTag(OtPtr);
2000-09-12 01:40:37 +02:00
while(DrawSync(1));
2001-04-19 01:04:03 +02:00
InitOTag(OtPtr, MAX_OT);
2000-09-12 01:40:37 +02:00
F.print( (512 >> 1), (256 >> 1), Text );
VSync(0);
VidSwapDraw();
2001-05-18 18:44:51 +02:00
// PrimDisplay();
DrawOTag(OtPtr);
2000-09-12 01:40:37 +02:00
while(DrawSync(1));
F.dump();
#endif
PSYQpause();
}
/*****************************************************************************/
void DbgPollHost()
{
2001-03-21 21:00:22 +01:00
#ifndef __CLIMAX_DEVKIT__
2000-09-12 01:40:37 +02:00
#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 */