diff --git a/source/system/dbg.cpp b/source/system/dbg.cpp new file mode 100644 index 000000000..20bf98dad --- /dev/null +++ b/source/system/dbg.cpp @@ -0,0 +1,300 @@ +/*========================================================================= + + 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 +#include +#include + + +/* Data + ---- */ + +/*---------------------------------------------------------------------- + Tyepdefs && Defines + ------------------- */ + +#ifdef __USER_charles__ + #define DBG_OUTPUT_TO_DEBUGGER // Send output to the debugger console + #define DBG_OUTPUT_TO_LOG // Allow logging of messages + #define DBG_MAX_MESSAGE_LENGTH 256 // Max length of a message in the log + #define DBG_LOG_LINES 10 // Number of lines to log + #define DBG_SHOW_MESSAGE_ORIGIN // Pre-pend filename and line number to messages + #define DBG_FILENAME_LENGTH 16 // This many chars of the filename are used + #define DBG_DEFAULT_CHANNEL DC_CHARLES|DC_ALL_SYSTEM // Default channels to listen to +#elif __USER_dave__ + #define DBG_OUTPUT_TO_DEBUGGER // Send output to the debugger console + #define DBG_OUTPUT_TO_LOG // Allow logging of messages + #define DBG_MAX_MESSAGE_LENGTH 256 // Max length of a message in the log + #define DBG_LOG_LINES 10 // Number of lines to log + #define DBG_SHOW_MESSAGE_ORIGIN // Pre-pend filename and line number to messages + #define DBG_FILENAME_LENGTH 16 // This many chars of the filename are used + #define DBG_DEFAULT_CHANNEL DC_DAVE|DC_ALL_SYSTEM // Default channels to listen to +#elif __USER_paul__ + #define DBG_OUTPUT_TO_DEBUGGER // Send output to the debugger console + #define DBG_OUTPUT_TO_LOG // Allow logging of messages + #define DBG_MAX_MESSAGE_LENGTH 256 // Max length of a message in the log + #define DBG_LOG_LINES 10 // Number of lines to log + #define DBG_SHOW_MESSAGE_ORIGIN // Pre-pend filename and line number to messages + #define DBG_FILENAME_LENGTH 16 // This many chars of the filename are used + #define DBG_DEFAULT_CHANNEL DC_PAUL|DC_ALL_SYSTEM // Default channels to listen to +#else + #define DBG_OUTPUT_TO_DEBUGGER // Send output to the debugger console + #define DBG_DEFAULT_CHANNEL DC_ALL // Default channels to listen to +#endif + + + +/*---------------------------------------------------------------------- + Structure defintions + -------------------- */ + +/*---------------------------------------------------------------------- + Function Prototypes + ------------------- */ + +/*---------------------------------------------------------------------- + Vars + ---- */ + +static DEBUG_CHANNEL_FLAG s_activeChannelFlags=(DEBUG_CHANNEL_FLAG)(DBG_DEFAULT_CHANNEL); + +static int s_dbgChannelFlags=DC_NONE; +static char s_dbgFilename[DBG_FILENAME_LENGTH+1]="\0"; +static int s_dbgLine=0; + +#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) +{ + s_dbgChannelFlags=_channelFlags; +} + + +/*---------------------------------------------------------------------- + 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> 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 +} + + + + +#endif /* DBG_ACTIVE */ + +/*=========================================================================== + end */ + diff --git a/source/system/dbg.h b/source/system/dbg.h new file mode 100644 index 000000000..b4b67a439 --- /dev/null +++ b/source/system/dbg.h @@ -0,0 +1,119 @@ +/*========================================================================= + + dbg.h + + Author: PKG + Created: + Project: + Purpose: + + Copyright (c) 2000 Climax Development Ltd + +===========================================================================*/ + +#ifndef __SYSTEM_DBG_H__ +#define __SYSTEM_DBG_H__ + +/*---------------------------------------------------------------------- + Includes + -------- */ + +/* Std Lib + ------- */ + +/*---------------------------------------------------------------------- + Tyepdefs && Defines + ------------------- */ + +// Allow debug messaging +#if defined(__VERSION_DEBUG__) +#define DBG_ACTIVE +#endif + + +// Available channels +typedef enum +{ + DC_CHARLES =1<<0, + DC_DAVE =1<<1, + DC_PAUL =1<<2, + + DC_SYSTEM =1<<3, + DC_SOUND =1<<4, + + + DC_NONE =0, + DC_ALL =-1, + DC_ALL_SYSTEM =DC_SYSTEM|DC_SOUND, + +} DEBUG_CHANNEL_FLAG; + + +/*---------------------------------------------------------------------- + Structure defintions + -------------------- */ + +/*---------------------------------------------------------------------- + Globals + ------- */ + +/*---------------------------------------------------------------------- + Functions + --------- */ + +#ifdef DBG_ACTIVE + void __setActiveDbgChannels(DEBUG_CHANNEL_FLAG _channelFlags); + DEBUG_CHANNEL_FLAG __getActiveDbgChannels(); + + void __setDbgChannels(DEBUG_CHANNEL_FLAG _channelFlags); + void __setDbgFilenameAndLine(const char *_filename,int _line); + void __writeDbgMessage(const char *_format,...); + + int __getNumberOfDbgLinesInLog(); + char *__getDbgLineFromLog(int _line); + + #define __DBGMSG(channel) __setDbgChannels(channel);__setDbgFilenameAndLine(__FILE__,__LINE__);__writeDbgMessage +#endif + + + + +#ifdef DBG_ACTIVE + #define CHARLES_DBGMSG __DBGMSG(DC_CHARLES) + #define DAVE_DBGMSG __DBGMSG(DC_DAVE) + #define PAUL_DBGMSG __DBGMSG(DC_PAUL) + #define SYSTEM_DBGMSG __DBGMSG(DC_SYSTEM) + #define SOUND_DBGMSG __DBGMSG(DC_SOUND) + + #define setActiveDbgChannels(_channelFlags) __setActiveDbgChannels(_channelFlags) + #define getActiveDbgChannels() __getActiveDbgChannels() + + #define getNumberOfDbgLinesInLog() __getNumberOfDbgLinesInLog() + #define getDbgLineFromLog(_line) __getDbgLineFromLog(_line) + + void DbgPollHost(); + void DoAssert(const char * Txt, const char * file, const int line); + #define ASSERT(x) if (!(x)) DoAssert(#x,__FILE__,__LINE__); +#else + #define CHARLES_DBGMSG ; + #define DAVE_DBGMSG ; + #define PAUL_DBGMSG ; + #define SYSTEM_DBGMSG ; + #define SOUND_DBGMSG ; + + #define setActiveDbgChannels(_channelFlags) ; + #define getActiveDbgChannels() ; + + #define getNumberOfDbgLinesInLog() 0 + #define getDbgLineFromLog(_line) NULL + + #define ASSERT(x) ; +#endif + + +/*---------------------------------------------------------------------- */ + +#endif /* __SYSTEM_DBG_H__ */ + +/*=========================================================================== + end */ \ No newline at end of file