diff --git a/emu/logging.h b/emu/logging.h index 19ff65df..6e7c0039 100644 --- a/emu/logging.h +++ b/emu/logging.h @@ -1,15 +1,16 @@ #ifndef __EMU_LOGGING_H__ #define __EMU_LOGGING_H__ +#ifdef __cplusplus +extern "C" +{ +#endif + #include "../stdtype.h" #include "../common_def.h" #include "EmuStructs.h" -#ifndef LOGBUF_SIZE -#define LOGBUF_SIZE 0x100 -#endif - typedef struct _device_logger { DEVCB_LOG func; @@ -27,4 +28,8 @@ INLINE void dev_logger_set(DEV_LOGGER* logger, void* source, DEVCB_LOG func, voi void emu_logf(DEV_LOGGER* logger, UINT8 level, const char* format, ...); +#ifdef __cplusplus +} +#endif + #endif // __EMU_LOGGING_H__ diff --git a/player.cpp b/player.cpp index e60de746..b22c4368 100644 --- a/player.cpp +++ b/player.cpp @@ -94,6 +94,7 @@ static UINT32 masterVol = 0x10000; // fixed point 16.16 static UINT8 showTags = 1; static bool showFileInfo = false; +static UINT8 logLevel = DEVLOG_INFO; static PlayerA mainPlr; @@ -503,6 +504,7 @@ Sound Chip ID: D - display configuration T param - show tags (0/D/OFF - off, 1/E/ON - on) FI param - show file information (see above) + LL param - set log level (0..5 = off/error/warn/info/debug/trace, see emu/EmuStructs.h) Q - quit P - player configuration [DRO] @@ -786,7 +788,7 @@ static void DoChipControlMode(PlayerBase* player) char* tokenStr; // Tags / FileInfo - printf("Command [T/FI data]: "); + printf("Command [T/FI/LL data]: "); fgets(line, 0x80, stdin); StripNewline(line); @@ -818,6 +820,12 @@ static void DoChipControlMode(PlayerBase* player) showFileInfo = !!val; } } + else if (! strcmp(line, "LL")) + { + UINT8 newLevel = (UINT8)strtoul(tokenStr, &endPtr, 0); + if (endPtr > tokenStr) + logLevel = newLevel; + } else if (! strcmp(line, "Q")) mode = -1; else @@ -960,8 +968,8 @@ static const char* LogLevel2Str(UINT8 level) static void PlayerLogCallback(void* userParam, PlayerBase* player, UINT8 level, UINT8 srcType, const char* srcTag, const char* message) { - if (level >= PLRLOG_TRACE) - return; // don't print trace logs (debug is okay) + if (level > logLevel) + return; // don't print messages with higher verbosity than current log level if (srcType == PLRLOGSRC_PLR) printf("[%s] %s: %s", LogLevel2Str(level), player->GetPlayerName(), message); else diff --git a/player/CMakeLists.txt b/player/CMakeLists.txt index 00ad6902..308f4442 100644 --- a/player/CMakeLists.txt +++ b/player/CMakeLists.txt @@ -17,7 +17,6 @@ set(PLAYER_FILES set(PLAYER_HEADERS dblk_compr.h helper.h - logging.h playerbase.hpp droplayer.hpp gymplayer.hpp diff --git a/player/dblk_compr.c b/player/dblk_compr.c index c656451f..c9c5a28b 100644 --- a/player/dblk_compr.c +++ b/player/dblk_compr.c @@ -3,7 +3,6 @@ #include "../common_def.h" #include "dblk_compr.h" -#include "logging.h" // integer types for fast integer calculation // The bit number defines how many bits are required, but the types can be larger for increased speed. @@ -145,14 +144,12 @@ static UINT8 Decompress_BitPacking_8(UINT32 outLen, UINT8* outData, UINT32 inLen ent1B = cmpParams->comprTbl->values.d8; if (! cmpParams->comprTbl->valueCount) { - debug("Error loading table-compressed data block! No table loaded!\n"); - return 0x10; + return 0x10; // Error: no table loaded } else if (cmpParams->bitsDec != cmpParams->comprTbl->bitsDec || cmpParams->bitsCmp != cmpParams->comprTbl->bitsCmp) { - debug("Warning! Data block and loaded value table incompatible!\n"); - return 0x11; + return 0x11; // Data block and loaded value table incompatible } } @@ -228,14 +225,12 @@ static UINT8 Decompress_BitPacking_16(UINT32 outLen, UINT8* outData, UINT32 inLe ent2B = cmpParams->comprTbl->values.d16; if (! cmpParams->comprTbl->valueCount) { - debug("Error loading table-compressed data block! No table loaded!\n"); - return 0x10; + return 0x10; // Error: no table loaded } else if (cmpParams->bitsDec != cmpParams->comprTbl->bitsDec || cmpParams->bitsCmp != cmpParams->comprTbl->bitsCmp) { - debug("Warning! Data block and loaded value table incompatible!\n"); - return 0x11; + return 0x11; // Data block and loaded value table incompatible } } @@ -311,14 +306,12 @@ static UINT8 Decompress_DPCM_8(UINT32 outLen, UINT8* outData, UINT32 inLen, cons ent1B = cmpParams->comprTbl->values.d8; if (! cmpParams->comprTbl->valueCount) { - debug("Error loading table-compressed data block! No table loaded!\n"); - return 0x10; + return 0x10; // Error: no table loaded } else if (cmpParams->bitsDec != cmpParams->comprTbl->bitsDec || cmpParams->bitsCmp != cmpParams->comprTbl->bitsCmp) { - debug("Warning! Data block and loaded value table incompatible!\n"); - return 0x11; + return 0x11; // Data block and loaded value table incompatible } outMask = (1 << cmpParams->bitsDec) - 1; @@ -370,14 +363,12 @@ static UINT8 Decompress_DPCM_16(UINT32 outLen, UINT8* outData, UINT32 inLen, con ent2B = cmpParams->comprTbl->values.d16; if (! cmpParams->comprTbl->valueCount) { - debug("Error loading table-compressed data block! No table loaded!\n"); - return 0x10; + return 0x10; // Error: no table loaded } else if (cmpParams->bitsDec != cmpParams->comprTbl->bitsDec || cmpParams->bitsCmp != cmpParams->comprTbl->bitsCmp) { - debug("Warning! Data block and loaded value table incompatible!\n"); - return 0x11; + return 0x11; // Data block and loaded value table incompatible } outMask = (1 << cmpParams->bitsDec) - 1; @@ -436,14 +427,12 @@ static UINT8 Compress_BitPacking_8(UINT32 outLen, UINT8* outData, UINT32 inLen, ent1B = cmpParams->comprTbl->values.d8; if (! cmpParams->comprTbl->valueCount) { - debug("Error storing table-compressed data block! No table loaded!\n"); - return 0x10; + return 0x10; // Error: no table loaded } else if (cmpParams->bitsDec != cmpParams->comprTbl->bitsDec || cmpParams->bitsCmp != cmpParams->comprTbl->bitsCmp) { - debug("Warning! Data block and loaded value table incompatible!\n"); - return 0x11; + return 0x11; // Data block and loaded value table incompatible } ent1B = (UINT8*)malloc(ent1Count * sizeof(UINT8)); GenerateReverseLUT_8(ent1Count, ent1B, cmpParams->comprTbl->valueCount, cmpParams->comprTbl->values.d8); @@ -529,14 +518,12 @@ static UINT8 Compress_BitPacking_16(UINT32 outLen, UINT8* outData, UINT32 inLen, ent2B = cmpParams->comprTbl->values.d16; if (! cmpParams->comprTbl->valueCount) { - debug("Error storing table-compressed data block! No table loaded!\n"); - return 0x10; + return 0x10; // Error: no table loaded } else if (cmpParams->bitsDec != cmpParams->comprTbl->bitsDec || cmpParams->bitsCmp != cmpParams->comprTbl->bitsCmp) { - debug("Warning! Data block and loaded value table incompatible!\n"); - return 0x11; + return 0x11; // Data block and loaded value table incompatible } ent2B = (UINT16*)malloc(ent2Count * sizeof(UINT16)); GenerateReverseLUT_16(ent2Count, ent2B, cmpParams->comprTbl->valueCount, cmpParams->comprTbl->values.d16); @@ -619,8 +606,7 @@ UINT8 ReadComprDataBlkHdr(UINT32 inLen, const UINT8* inData, PCM_CDB_INF* retCdb curPos += 0x05; break; default: - debug("Error: Unknown data block compression!\n"); - return 0x80; + return 0x80; // Error: unknown data block compression } retCdbInf->hdrSize = curPos; @@ -654,8 +640,7 @@ UINT8 WriteComprDataBlkHdr(UINT32 outLen, UINT8* outData, PCM_CDB_INF* cdbInf) curPos += 0x05; break; default: - debug("Error: Unknown data block compression!\n"); - return 0x80; + return 0x80; // Error: unknown data block compression } cdbInf->hdrSize = curPos; @@ -754,7 +739,11 @@ void ReadPCMComprTable(UINT32 dataSize, const UINT8* data, PCM_COMPR_TBL* comprT tblSize = comprTbl->valueCount * valSize; if (dataSize < 0x06 + tblSize) - debug("Warning! Bad PCM Table Length!\n"); + { + //printf("Warning! Bad PCM Table Length!\n"); + tblSize = dataSize - 0x06; + comprTbl->valueCount = tblSize / valSize; + } comprTbl->values.d8 = (UINT8*)realloc(comprTbl->values.d8, tblSize); if (valSize < 0x02) @@ -786,7 +775,7 @@ UINT32 WriteCompressionTable(UINT32 dataSize, UINT8* data, PCM_COMPR_TBL* comprT if (dataSize < 0x06 + tblSize) { - debug("Warning! Bad PCM Table Length!\n"); + //printf("Warning! Bad PCM Table Length!\n"); return (UINT32)-1; } diff --git a/player/dblk_compr.h b/player/dblk_compr.h index 7fcfbf0b..5a305948 100644 --- a/player/dblk_compr.h +++ b/player/dblk_compr.h @@ -7,6 +7,7 @@ extern "C" #endif #include "../stdtype.h" +#include "../common_def.h" typedef struct _pcm_compression_table { @@ -49,13 +50,13 @@ typedef struct _pcm_compr_datablk_info // small functions to help calculating data sizes // Bit Packing/DPCM: -static UINT32 BPACK_SIZE_CMP(UINT32 sizeDec, UINT32 bitsCmp, UINT32 bitsDec) +INLINE UINT32 BPACK_SIZE_CMP(UINT32 sizeDec, UINT32 bitsCmp, UINT32 bitsDec) { UINT32 byteBits = (bitsDec + 7) & ~7; return (UINT32)(((UINT64)sizeDec * bitsCmp + 7) / byteBits); } -static UINT32 BPACK_SIZE_DEC(UINT32 sizeCmp, UINT32 bitsCmp, UINT32 bitsDec) +INLINE UINT32 BPACK_SIZE_DEC(UINT32 sizeCmp, UINT32 bitsCmp, UINT32 bitsDec) { UINT32 byteBits = (bitsDec + 7) & ~7; return (UINT32)((UINT64)sizeCmp * byteBits / bitsCmp); diff --git a/player/droplayer.cpp b/player/droplayer.cpp index 07069b92..0ccae3bf 100644 --- a/player/droplayer.cpp +++ b/player/droplayer.cpp @@ -1,4 +1,3 @@ -// TODO: option to disable DualOPL2 -> OPL3 _realHwType patch #include #include #include @@ -14,7 +13,7 @@ #include "../emu/SoundDevs.h" #include "../emu/EmuCores.h" #include "helper.h" -#include "logging.h" +#include "../emu/logging.h" enum DRO_HWTYPES { @@ -46,6 +45,8 @@ DROPlayer::DROPlayer() : { size_t curDev; + dev_logger_set(&_logger, this, DROPlayer::PlayerLogCB, NULL); + _playOpts.v2opl3Mode = DRO_V2OPL3_DETECT; for (curDev = 0; curDev < 3; curDev ++) @@ -592,6 +593,15 @@ UINT32 DROPlayer::GetLoopTicks(void) const return 0; } +/*static*/ void DROPlayer::PlayerLogCB(void* userParam, void* source, UINT8 level, const char* message) +{ + DROPlayer* player = (DROPlayer*)source; + if (player->_logCbFunc == NULL) + return; + player->_logCbFunc(player->_logCbParam, player, level, PLRLOGSRC_PLR, NULL, message); + return; +} + /*static*/ void DROPlayer::SndEmuLogCB(void* userParam, void* source, UINT8 level, const char* message) { DEVLOG_CB_DATA* cbData = (DEVLOG_CB_DATA*)userParam; @@ -927,7 +937,7 @@ void DROPlayer::DoCommand_v1(void) UINT8 curCmd; - //debug("DRO v1: Ofs %04X, Command %02X data %02X\n", _filePos, _fileData[_filePos], _fileData[_filePos+1]); + //emu_logf(&_logger, PLRLOG_TRACE, "[DRO v1] Ofs %04X, Command %02X data %02X\n", _filePos, _fileData[_filePos], _fileData[_filePos+1]); curCmd = _fileData[_filePos]; _filePos ++; switch(curCmd) @@ -953,7 +963,7 @@ void DROPlayer::DoCommand_v1(void) _selPort = curCmd & 0x01; if (_selPort >= (_devTypes.size() << _portShift)) { - //debug("More chips used than defined in header!\n"); + //emu_logf(&_logger, PLRLOG_WARN, "More chips used than defined in header!\n"); //_shownMsgs[2] = true; } return; @@ -988,7 +998,7 @@ void DROPlayer::DoCommand_v2(void) UINT8 reg; UINT8 data; - //debug("DRO v2: Ofs %04X, Command %02X data %02X\n", _filePos, _fileData[_filePos], _fileData[_filePos+1]); + //emu_logf(&_logger, PLRLOG_TRACE, "[DRO v2] Ofs %04X, Command %02X data %02X\n", _filePos, _fileData[_filePos], _fileData[_filePos+1]); reg = _fileData[_filePos + 0x00]; data = _fileData[_filePos + 0x01]; _filePos += 0x02; diff --git a/player/droplayer.hpp b/player/droplayer.hpp index 0e452e25..46f37a93 100644 --- a/player/droplayer.hpp +++ b/player/droplayer.hpp @@ -7,6 +7,7 @@ #include "helper.h" #include "playerbase.hpp" #include "../utils/DataLoader.h" +#include "../emu/logging.h" #include @@ -137,6 +138,7 @@ class DROPlayer : public PlayerBase void ScanInitBlock(void); + static void PlayerLogCB(void* userParam, void* source, UINT8 level, const char* message); static void SndEmuLogCB(void* userParam, void* source, UINT8 level, const char* message); void GenerateDeviceConfig(void); @@ -148,6 +150,7 @@ class DROPlayer : public PlayerBase void DoFileEnd(void); void WriteReg(UINT8 port, UINT8 reg, UINT8 data); + DEV_LOGGER _logger; DATA_LOADER* _dLoad; const UINT8* _fileData; // data pointer for quick access, equals _dLoad->GetFileData().data() diff --git a/player/gymplayer.cpp b/player/gymplayer.cpp index 6939bb8f..2e8aafbc 100644 --- a/player/gymplayer.cpp +++ b/player/gymplayer.cpp @@ -16,7 +16,7 @@ #include "../emu/cores/sn764intf.h" // for SN76496_CFG #include "../utils/StrUtils.h" #include "helper.h" -#include "logging.h" +#include "../emu/logging.h" INLINE UINT32 ReadLE32(const UINT8* data) { @@ -44,6 +44,8 @@ GYMPlayer::GYMPlayer() : size_t curDev; UINT8 retVal; + dev_logger_set(&_logger, this, GYMPlayer::PlayerLogCB, NULL); + for (curDev = 0; curDev < 2; curDev ++) InitDeviceOptions(_devOpts[curDev]); GenerateDeviceConfig(); @@ -527,6 +529,15 @@ UINT32 GYMPlayer::GetLoopTicks(void) const return _totalTicks - _fileHdr.loopFrame; } +/*static*/ void GYMPlayer::PlayerLogCB(void* userParam, void* source, UINT8 level, const char* message) +{ + GYMPlayer* player = (GYMPlayer*)source; + if (player->_logCbFunc == NULL) + return; + player->_logCbFunc(player->_logCbParam, player, level, PLRLOGSRC_PLR, NULL, message); + return; +} + /*static*/ void GYMPlayer::SndEmuLogCB(void* userParam, void* source, UINT8 level, const char* message) { DEVLOG_CB_DATA* cbData = (DEVLOG_CB_DATA*)userParam; @@ -907,7 +918,7 @@ void GYMPlayer::DoCommand(void) _ymLatch[latchID] = data; if (needPatch) { - //printf("GYM: Fixing missing freq p2: %03X=%02X + [%03X=%02X]\n", + //emu_logf(&_logger, PLRLOG_TRACE, "Fixing missing freq p2: %03X=%02X + [%03X=%02X]\n", // (port << 8) | reg, data, (port << 8) | (reg ^ 0x04), _ymFreqRegs[cacheReg ^ 0x04]); // complete the 2-part write by sending the command for the 2nd part cDev->write(dataPtr, (port << 1) | 0, reg ^ 0x04); @@ -918,7 +929,7 @@ void GYMPlayer::DoCommand(void) { if (_ymLatch[latchID] != _ymFreqRegs[cacheReg ^ 0x04]) { - //printf("GYM: Fixing missing freq p1: [%03X=%02X] + %03X=%02X\n", + //emu_logf(&_logger, PLRLOG_TRACE, "Fixing missing freq p1: [%03X=%02X] + %03X=%02X\n", // (port << 8) | (reg ^ 0x04), _ymFreqRegs[cacheReg ^ 0x04], (port << 8) | reg, data); // make sure to set the latch to the correct value cDev->write(dataPtr, (port << 1) | 0, reg ^ 0x04); @@ -965,7 +976,7 @@ void GYMPlayer::DoFileEnd(void) if (_lastLoopTick == _fileTick) { doLoop = 0; // prevent freezing due to infinite loop - debug("Warning! Ignored Zero-Sample-Loop!\n"); + emu_logf(&_logger, PLRLOG_WARN, "Ignored Zero-Sample-Loop!\n"); } else { diff --git a/player/gymplayer.hpp b/player/gymplayer.hpp index 3e26cf7b..e4b8256f 100644 --- a/player/gymplayer.hpp +++ b/player/gymplayer.hpp @@ -8,6 +8,7 @@ #include "helper.h" #include "playerbase.hpp" #include "../utils/DataLoader.h" +#include "../emu/logging.h" #include #include #include @@ -111,6 +112,7 @@ class GYMPlayer : public PlayerBase void LoadTag(const char* tagName, const void* data, size_t maxlen); std::string GetUTF8String(const char* startPtr, const char* endPtr); + static void PlayerLogCB(void* userParam, void* source, UINT8 level, const char* message); static void SndEmuLogCB(void* userParam, void* source, UINT8 level, const char* message); void GenerateDeviceConfig(void); @@ -121,6 +123,7 @@ class GYMPlayer : public PlayerBase void DoFileEnd(void); CPCONV* _cpc1252; // CP1252 -> UTF-8 codepage conversion + DEV_LOGGER _logger; DATA_LOADER* _dLoad; UINT32 _fileLen; const UINT8* _fileData; // data pointer for quick access, equals _dLoad->GetFileData().data() diff --git a/player/logging.h b/player/logging.h deleted file mode 100644 index a611feb9..00000000 --- a/player/logging.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef __PLAYER_LOGGING_H__ -#define __PLAYER_LOGGING_H__ - -#ifdef _DEBUG -#include - -#if defined(_MSC_VER) && _MSC_VER < 1400 -#define debug printf -#else -#define debug(...) fprintf(stderr, __VA_ARGS__) -#endif - -#else - -#if defined(_MSC_VER) && _MSC_VER < 1400 -// MS VC6 doesn't support the variadic macro syntax -#define debug -#else -#define debug(...) {} -#endif - -#endif - -#endif // __PLAYER_LOGGING_H__ diff --git a/player/s98player.cpp b/player/s98player.cpp index d1b3f082..bf673490 100644 --- a/player/s98player.cpp +++ b/player/s98player.cpp @@ -18,7 +18,7 @@ #include "../emu/cores/ayintf.h" // for AY8910_CFG #include "../utils/StrUtils.h" #include "helper.h" -#include "logging.h" +#include "../emu/logging.h" enum S98_DEVTYPES { @@ -98,6 +98,8 @@ S98Player::S98Player() : UINT16 optChip; UINT8 chipID; + dev_logger_set(&_logger, this, S98Player::PlayerLogCB, NULL); + for (optChip = 0x00; optChip < 0x100; optChip ++) { for (chipID = 0; chipID < 2; chipID ++) @@ -246,13 +248,13 @@ UINT8 S98Player::LoadFile(DATA_LOADER *dataLoader) { if (_fileHdr.loopOfs < _fileHdr.dataOfs || _fileHdr.loopOfs >= DataLoader_GetSize(_dLoad)) { - debug("Invalid VGM loop offset 0x%06X - ignoring!\n", _fileHdr.loopOfs); + emu_logf(&_logger, PLRLOG_WARN, "Invalid loop offset 0x%06X - ignoring!\n", _fileHdr.loopOfs); _fileHdr.loopOfs = 0x00; } if (_fileHdr.loopOfs && _loopTick == _totalTicks) { // 0-Sample-Loops causes the program to hang in the playback routine - debug("Warning! Ignored Zero-Sample-Loop!\n"); + emu_logf(&_logger, PLRLOG_WARN, "Warning! Ignored Zero-Sample-Loop!\n"); _fileHdr.loopOfs = 0x00; } } @@ -335,8 +337,8 @@ UINT8 S98Player::LoadTags(void) // tag offset = PSF tag if (endPtr - startPtr < 5 || memcmp(startPtr, "[S98]", 5)) { - debug("Invalid S98 tag data!\n"); - debug("tagData size: %zu, Signature: %.5s\n", endPtr - startPtr, startPtr); + emu_logf(&_logger, PLRLOG_ERROR, "Invalid S98 tag data!\n"); + emu_logf(&_logger, PLRLOG_DEBUG, "tagData size: %zu, Signature: %.5s\n", endPtr - startPtr, startPtr); return 0xF0; } startPtr += 5; @@ -346,7 +348,7 @@ UINT8 S98Player::LoadTags(void) { tagIsUTF8 = true; startPtr += 3; - debug("Info: Tags are UTF-8 encoded."); + emu_logf(&_logger, PLRLOG_DEBUG, "Note: Tags are UTF-8 encoded."); } } @@ -786,6 +788,15 @@ UINT32 S98Player::GetLoopTicks(void) const return _totalTicks - _loopTick; } +/*static*/ void S98Player::PlayerLogCB(void* userParam, void* source, UINT8 level, const char* message) +{ + S98Player* player = (S98Player*)source; + if (player->_logCbFunc == NULL) + return; + player->_logCbFunc(player->_logCbParam, player, level, PLRLOGSRC_PLR, NULL, message); + return; +} + /*static*/ void S98Player::SndEmuLogCB(void* userParam, void* source, UINT8 level, const char* message) { DEVLOG_CB_DATA* cbData = (DEVLOG_CB_DATA*)userParam; @@ -1176,7 +1187,7 @@ void S98Player::HandleEOF(void) if (_lastLoopTick == _fileTick) { doLoop = 0; // prevent freezing due to infinite loop - debug("Warning! Ignored Zero-Sample-Loop!\n"); + emu_logf(&_logger, PLRLOG_WARN, "Ignored Zero-Sample-Loop!\n"); } else { @@ -1222,7 +1233,7 @@ void S98Player::DoCommand(void) _psTrigger |= PLAYSTATE_END; if (_eventCbFunc != NULL) _eventCbFunc(this, _eventCbParam, PLREVT_END, NULL); - debug("S98 file ends early! (filePos 0x%06X, fileSize 0x%06X)\n", _filePos, DataLoader_GetSize(_dLoad)); + emu_logf(&_logger, PLRLOG_WARN, "S98 file ends early! (filePos 0x%06X, fileSize 0x%06X)\n", _filePos, DataLoader_GetSize(_dLoad)); return; } diff --git a/player/s98player.hpp b/player/s98player.hpp index 2c338c54..c60f84b1 100644 --- a/player/s98player.hpp +++ b/player/s98player.hpp @@ -8,6 +8,7 @@ #include "helper.h" #include "playerbase.hpp" #include "../utils/DataLoader.h" +#include "../emu/logging.h" #include #include #include @@ -115,6 +116,7 @@ class S98Player : public PlayerBase void RefreshTSRates(void); + static void PlayerLogCB(void* userParam, void* source, UINT8 level, const char* message); static void SndEmuLogCB(void* userParam, void* source, UINT8 level, const char* message); void GenerateDeviceConfig(void); @@ -132,6 +134,7 @@ class S98Player : public PlayerBase }; CPCONV* _cpcSJIS; // ShiftJIS -> UTF-8 codepage conversion + DEV_LOGGER _logger; DATA_LOADER *_dLoad; const UINT8* _fileData; // data pointer for quick access, equals _dLoad->GetFileData().data() diff --git a/player/vgmplayer.cpp b/player/vgmplayer.cpp index 84afe2c6..f30c87fc 100644 --- a/player/vgmplayer.cpp +++ b/player/vgmplayer.cpp @@ -29,7 +29,7 @@ #include "dblk_compr.h" #include "../utils/StrUtils.h" #include "helper.h" -#include "logging.h" +#include "../emu/logging.h" #ifdef _MSC_VER #define snprintf _snprintf @@ -149,6 +149,8 @@ VGMPlayer::VGMPlayer() : UINT16 optChip; UINT8 chipID; + dev_logger_set(&_logger, this, VGMPlayer::PlayerLogCB, NULL); + _playOpts.playbackHz = 0; _playOpts.hardStopOld = 0; @@ -261,7 +263,7 @@ UINT8 VGMPlayer::ParseHeader(void) _fileHdr.dataOfs = 0x40; // offset not set - assume v1.00 header size if (_fileHdr.dataOfs < 0x38) { - fprintf(stderr, "Warning! Invalid Data Offset 0x%02X!\n", _fileHdr.dataOfs); + emu_logf(&_logger, PLRLOG_WARN, "Invalid Data Offset 0x%02X!\n", _fileHdr.dataOfs); _fileHdr.dataOfs = 0x38; } _hdrLenFile = _fileHdr.dataOfs; @@ -294,7 +296,7 @@ UINT8 VGMPlayer::ParseHeader(void) if (! _fileHdr.eofOfs || _fileHdr.eofOfs > DataLoader_GetSize(_dLoad)) { - fprintf(stderr, "Warning! Invalid EOF Offset 0x%06X! (should be: 0x%06X)\n", + emu_logf(&_logger, PLRLOG_WARN, "Invalid EOF Offset 0x%06X! (should be: 0x%06X)\n", _fileHdr.eofOfs, DataLoader_GetSize(_dLoad)); _fileHdr.eofOfs = DataLoader_GetSize(_dLoad); // catch invalid EOF values } @@ -317,13 +319,13 @@ UINT8 VGMPlayer::ParseHeader(void) { if (_fileHdr.loopOfs < _fileHdr.dataOfs || _fileHdr.loopOfs >= _fileHdr.dataEnd) { - debug("Invalid VGM loop offset 0x%06X - ignoring!\n", _fileHdr.loopOfs); + emu_logf(&_logger, PLRLOG_WARN, "Invalid loop offset 0x%06X - ignoring!\n", _fileHdr.loopOfs); _fileHdr.loopOfs = 0x00; } if (_fileHdr.loopOfs && _fileHdr.loopTicks == 0) { // 0-Sample-Loops causes the program to hang in the playback routine - debug("Warning! Ignored Zero-Sample-Loop!\n"); + emu_logf(&_logger, PLRLOG_WARN, "Ignored Zero-Sample-Loop!\n"); _fileHdr.loopOfs = 0x00; } } @@ -812,6 +814,15 @@ const std::vector& VGMPlayer::GetStreamDevInfo(void) con return _dacStreams; } +/*static*/ void VGMPlayer::PlayerLogCB(void* userParam, void* source, UINT8 level, const char* message) +{ + VGMPlayer* player = (VGMPlayer*)source; + if (player->_logCbFunc == NULL) + return; + player->_logCbFunc(player->_logCbParam, player, level, PLRLOGSRC_PLR, NULL, message); + return; +} + /*static*/ void VGMPlayer::SndEmuLogCB(void* userParam, void* source, UINT8 level, const char* message) { DEVLOG_CB_DATA* cbData = (DEVLOG_CB_DATA*)userParam; @@ -1661,7 +1672,7 @@ UINT8 VGMPlayer::SeekToFilePos(UINT32 pos) _psTrigger |= PLAYSTATE_END; if (_eventCbFunc != NULL) _eventCbFunc(this, _eventCbParam, PLREVT_END, NULL); - debug("VGM file ends early! (filePos 0x%06X, end at 0x%06X)\n", _filePos, _fileHdr.dataEnd); + emu_logf(&_logger, PLRLOG_WARN, "VGM file ends early! (filePos 0x%06X, end at 0x%06X)\n", _filePos, _fileHdr.dataEnd); } _playState &= ~PLAYSTATE_SEEK; @@ -1758,7 +1769,7 @@ void VGMPlayer::ParseFile(UINT32 ticks) _psTrigger |= PLAYSTATE_END; if (_eventCbFunc != NULL) _eventCbFunc(this, _eventCbParam, PLREVT_END, NULL); - debug("VGM file ends early! (filePos 0x%06X, end at 0x%06X)\n", _filePos, _fileHdr.dataEnd); + emu_logf(&_logger, PLRLOG_WARN, "VGM file ends early! (filePos 0x%06X, end at 0x%06X)\n", _filePos, _fileHdr.dataEnd); } return; diff --git a/player/vgmplayer.hpp b/player/vgmplayer.hpp index ea9c051d..df32d3b5 100644 --- a/player/vgmplayer.hpp +++ b/player/vgmplayer.hpp @@ -8,6 +8,7 @@ #include "helper.h" #include "playerbase.hpp" #include "../utils/DataLoader.h" +#include "../emu/logging.h" #include "dblk_compr.h" #include #include @@ -204,6 +205,7 @@ class VGMPlayer : public PlayerBase void RefreshTSRates(void); + static void PlayerLogCB(void* userParam, void* source, UINT8 level, const char* message); static void SndEmuLogCB(void* userParam, void* source, UINT8 level, const char* message); UINT32 GetHeaderChipClock(UINT8 chipType) const; // returns raw chip clock value from VGM header @@ -269,6 +271,7 @@ class VGMPlayer : public PlayerBase void Cmd_AY_Stereo(void); // command 30 - set AY8910 stereo mask CPCONV* _cpcUTF16; // UTF-16 LE -> UTF-8 codepage conversion + DEV_LOGGER _logger; DATA_LOADER *_dLoad; const UINT8* _fileData; // data pointer for quick access, equals _dLoad->GetFileData().data() std::vector _yrwRom; // cache for OPL4 sample ROM (yrw801.rom) diff --git a/player/vgmplayer_cmdhandler.cpp b/player/vgmplayer_cmdhandler.cpp index a29a3818..cb353acc 100644 --- a/player/vgmplayer_cmdhandler.cpp +++ b/player/vgmplayer_cmdhandler.cpp @@ -532,7 +532,7 @@ void VGMPlayer::Cmd_invalid(void) _psTrigger |= PLAYSTATE_END; if (_eventCbFunc != NULL) _eventCbFunc(this, _eventCbParam, PLREVT_END, NULL); - fprintf(stderr, "Invalid VGM command %02X found! (filePos 0x%06X)\n", fData[0x00], _filePos); + emu_logf(&_logger, PLRLOG_ERROR, "Invalid VGM command %02X found! (filePos 0x%06X)\n", fData[0x00], _filePos); return; } @@ -540,7 +540,7 @@ void VGMPlayer::Cmd_unknown(void) { // The difference between "invalid" and "unknown" is, that there is a command length // defined for "unknown" and thus it is possible to just skip it. - fprintf(stderr, "Unknown VGM command %02X found! (filePos 0x%06X)\n", fData[0x00], _filePos); + emu_logf(&_logger, PLRLOG_WARN, "Unknown VGM command %02X found! (filePos 0x%06X)\n", fData[0x00], _filePos); return; } @@ -556,7 +556,7 @@ void VGMPlayer::Cmd_EndOfData(void) if (_lastLoopTick == _fileTick) { doLoop = 0; // prevent freezing due to infinite loop - fprintf(stderr, "Warning! Ignored Zero-Sample-Loop!\n"); + emu_logf(&_logger, PLRLOG_WARN, "Ignored Zero-Sample-Loop!\n"); } else { @@ -722,8 +722,14 @@ void VGMPlayer::Cmd_DataBlock(void) pcmBnk->data.resize(oldLen + dataLen); if (dblkType & 0x40) { - DecompressDataBlk(dataLen, &pcmBnk->data[oldLen], - dblkLen - dbCI.hdrSize, &dataPtr[dbCI.hdrSize], &dbCI.cmprInfo); + UINT8 retVal = DecompressDataBlk(dataLen, &pcmBnk->data[oldLen], + dblkLen - dbCI.hdrSize, &dataPtr[dbCI.hdrSize], &dbCI.cmprInfo); + if (retVal == 0x10) + emu_logf(&_logger, PLRLOG_ERROR, "Error loading table-compressed data block! No table loaded!\n"); + else if (retVal == 0x11) + emu_logf(&_logger, PLRLOG_ERROR, "Data block and loaded value table incompatible!\n"); + else if (retVal == 0x80) + emu_logf(&_logger, PLRLOG_ERROR, "Unknown data block compression!\n"); } else { @@ -1142,7 +1148,7 @@ void VGMPlayer::Cmd_RF5C_Mem(void) UINT16 memOfs = ReadLE16(&fData[0x01]); if (memOfs & 0xF000) - fprintf(stderr, "Warning: RF5C mem write to out-of-window offset 0x%04X\n", memOfs); + emu_logf(&_logger, PLRLOG_WARN, "RF5C mem write to out-of-window offset 0x%04X\n", memOfs); cDev->writeM8(cDev->base.defInf.dataPtr, memOfs, fData[0x03]); return; } @@ -1327,7 +1333,7 @@ void VGMPlayer::Cmd_OKIM6295_Reg(void) if (data & 0x80) { data &= 0x7F; // remove "pin7" bit (bug in some MAME VGM logs) - //fprintf(stderr, "OKIM6295 Warning: SetClock command (%02X %02X) includes Pin7 bit!\n", + //emu_logf(&_logger, PLRLOG_WARN, "OKIM6295 SetClock command (%02X %02X) includes Pin7 bit!\n", // fData[0x00], fData[0x01]); } }