Skip to content

Commit

Permalink
player: add logging via callback, part 2
Browse files Browse the repository at this point in the history
We can now finally see VGM parse warnings in Release mode.
  • Loading branch information
ValleyBell committed Nov 6, 2021
1 parent f9eb6a7 commit 0f0b01a
Show file tree
Hide file tree
Showing 15 changed files with 135 additions and 96 deletions.
13 changes: 9 additions & 4 deletions emu/logging.h
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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__
14 changes: 11 additions & 3 deletions player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion player/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ set(PLAYER_FILES
set(PLAYER_HEADERS
dblk_compr.h
helper.h
logging.h
playerbase.hpp
droplayer.hpp
gymplayer.hpp
Expand Down
51 changes: 20 additions & 31 deletions player/dblk_compr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
}
}

Expand Down Expand Up @@ -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
}
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}

Expand Down
5 changes: 3 additions & 2 deletions player/dblk_compr.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ extern "C"
#endif

#include "../stdtype.h"
#include "../common_def.h"

typedef struct _pcm_compression_table
{
Expand Down Expand Up @@ -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);
Expand Down
20 changes: 15 additions & 5 deletions player/droplayer.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// TODO: option to disable DualOPL2 -> OPL3 _realHwType patch
#include <stdlib.h>
#include <string.h>
#include <vector>
Expand All @@ -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
{
Expand Down Expand Up @@ -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 ++)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions player/droplayer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "helper.h"
#include "playerbase.hpp"
#include "../utils/DataLoader.h"
#include "../emu/logging.h"
#include <vector>


Expand Down Expand Up @@ -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);
Expand All @@ -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()

Expand Down
Loading

0 comments on commit 0f0b01a

Please sign in to comment.