From a7215f4921001bb7bfa6377bd2ba22331b9a269a Mon Sep 17 00:00:00 2001 From: Valley Bell Date: Sat, 6 Nov 2021 16:41:38 +0100 Subject: [PATCH] sound emulation: add logging callbacks --- emu/CMakeLists.txt | 1 + emu/EmuStructs.h | 12 ++++++++- emu/cores/2612intf.c | 3 +++ emu/cores/262intf.c | 3 +++ emu/cores/Ootake_PSG.c | 1 + emu/cores/ay8910.c | 32 ++++++++++++++-------- emu/cores/ay8910.h | 1 + emu/cores/c140.c | 1 + emu/cores/c219.c | 1 + emu/cores/c352.c | 1 + emu/cores/c6280_mame.c | 1 + emu/cores/emu2149.c | 1 + emu/cores/emu2413.c | 1 + emu/cores/es5503.c | 1 + emu/cores/fmopl.c | 24 ++++++++++++----- emu/cores/fmopl.h | 1 + emu/cores/fmopn.c | 58 +++++++++++++++++++++++++++++++--------- emu/cores/fmopn.h | 8 ++++++ emu/cores/gb.c | 1 + emu/cores/iremga20.c | 15 +++++++++-- emu/cores/k051649.c | 1 + emu/cores/k053260.c | 25 ++++++++++++----- emu/cores/k054539.c | 21 ++++++++++----- emu/cores/multipcm.c | 1 + emu/cores/nesintf.c | 2 ++ emu/cores/nukedopll.c | 1 + emu/cores/nukedopm.c | 1 + emu/cores/okim6258.c | 15 +++++++++-- emu/cores/okim6295.c | 15 +++++++++-- emu/cores/oplintf.c | 5 ++++ emu/cores/opnintf.c | 4 +++ emu/cores/pokey.c | 1 + emu/cores/pwm.c | 1 + emu/cores/qsound_ctr.c | 1 + emu/cores/qsound_mame.c | 23 +++++++++------- emu/cores/rf5c68.c | 1 + emu/cores/saa1099_mame.c | 17 +++++++++--- emu/cores/saa1099_vb.c | 1 + emu/cores/scd_pcm.c | 1 + emu/cores/scsp.c | 15 +++++++++-- emu/cores/segapcm.c | 1 + emu/cores/sn76489.c | 1 + emu/cores/sn76496.c | 15 +++++++++-- emu/cores/upd7759.c | 38 ++++++++++++++++---------- emu/cores/vsu.c | 1 + emu/cores/ws_audio.c | 1 + emu/cores/x1_010.c | 25 ++++++++++++----- emu/cores/ym2151.c | 1 + emu/cores/ym2413.c | 1 + emu/cores/ym2612.c | 4 +++ emu/cores/ymdeltat.c | 32 +++++++++++----------- emu/cores/ymdeltat.h | 2 ++ emu/cores/ymf262.c | 13 +++++++-- emu/cores/ymf262.h | 1 + emu/cores/ymf271.c | 25 ++++++++++++----- emu/cores/ymf278b.c | 23 +++++++++++----- emu/cores/ymz280b.c | 23 +++++++++++----- emu/dac_control.c | 1 + emu/logging.c | 31 +++++++++++++++++++++ emu/logging.h | 30 +++++++++++++++++++++ emu/panning.h | 6 ++--- 61 files changed, 467 insertions(+), 127 deletions(-) create mode 100644 emu/logging.c create mode 100644 emu/logging.h diff --git a/emu/CMakeLists.txt b/emu/CMakeLists.txt index a1562817..41c7c4a3 100644 --- a/emu/CMakeLists.txt +++ b/emu/CMakeLists.txt @@ -245,6 +245,7 @@ endif() set(EMU_FILES SoundEmu.c Resampler.c + logging.c panning.c dac_control.c ) diff --git a/emu/EmuStructs.h b/emu/EmuStructs.h index 71164b46..9e33d290 100644 --- a/emu/EmuStructs.h +++ b/emu/EmuStructs.h @@ -15,7 +15,8 @@ typedef struct _device_generic_config DEV_GEN_CFG; typedef struct _device_link_info DEVLINK_INFO; -typedef void (*DEVCB_SRATE_CHG)(void* info, UINT32 newSRate); +typedef void (*DEVCB_SRATE_CHG)(void* userParam, UINT32 newSRate); +typedef void (*DEVCB_LOG)(void* userParam, void* source, UINT8 level, const char* message); typedef UINT8 (*DEVFUNC_START)(const DEV_GEN_CFG* cfg, DEV_INFO* retDevInf); typedef void (*DEVFUNC_CTRL)(void* info); @@ -24,6 +25,7 @@ typedef void (*DEVFUNC_OPTMASK)(void* info, UINT32 optionBits); typedef void (*DEVFUNC_PANALL)(void* info, const INT16* channelPanVal); typedef void (*DEVFUNC_SRCCB)(void* info, DEVCB_SRATE_CHG SmpRateChgCallback, void* paramPtr); typedef UINT8 (*DEVFUNC_LINKDEV)(void* info, UINT8 devID, const DEV_INFO* devInfLink); +typedef void (*DEVFUNC_SETLOGCB)(void* info, DEVCB_LOG logFunc, void* userParam); typedef UINT8 (*DEVFUNC_READ_A8D8)(void* info, UINT8 addr); typedef UINT16 (*DEVFUNC_READ_A8D16)(void* info, UINT8 addr); @@ -68,6 +70,13 @@ typedef void (*DEVFUNC_WRITE_VOL_LR)(void* info, INT32 volL, INT32 volR); #define DEVRW_VALUE 0x00 #define DEVRW_ALL 0x01 +#define DEVLOG_OFF 0x00 +#define DEVLOG_ERROR 0x01 +#define DEVLOG_WARN 0x02 +#define DEVLOG_INFO 0x03 +#define DEVLOG_DEBUG 0x04 +#define DEVLOG_TRACE 0x05 + typedef struct _devdef_readwrite_function { UINT8 funcType; // function type, see RWF_ constants @@ -92,6 +101,7 @@ struct _device_definition DEVFUNC_OPTMASK SetMuteMask; DEVFUNC_PANALL SetPanning; // **NOTE: deprecated, moved to rwFuncs** DEVFUNC_SRCCB SetSRateChgCB; // used to set callback function for realtime sample rate changes + DEVFUNC_SETLOGCB SetLogCB; // set callback for logging DEVFUNC_LINKDEV LinkDevice; // used to link multiple devices together const DEVDEF_RWFUNC* rwFuncs; // terminated by (funcPtr == NULL) diff --git a/emu/cores/2612intf.c b/emu/cores/2612intf.c index 89df09df..0399298a 100644 --- a/emu/cores/2612intf.c +++ b/emu/cores/2612intf.c @@ -47,6 +47,7 @@ static DEV_DEF devDef_MAME = ym2612_set_mute_mask, // SetMuteMask NULL, // SetPanning NULL, // SetSampleRateChangeCallback + ym2612_set_log_cb, // SetLoggingCallback NULL, // LinkDevice devFunc_MAME, // rwFuncs @@ -72,6 +73,7 @@ static DEV_DEF devDef_Gens = (DEVFUNC_OPTMASK)YM2612_SetMute, // SetMuteMask NULL, // SetPanning NULL, // SetSampleRateChangeCallback + NULL, // SetLoggingCallback NULL, // LinkDevice devFunc_Gens, // rwFuncs @@ -97,6 +99,7 @@ static DEV_DEF devDef_Nuked = nukedopn2_set_mute_mask, // SetMuteMask NULL, // SetPanning NULL, // SetSampleRateChangeCallback + NULL, // SetLoggingCallback NULL, // LinkDevice devFunc_Nuked, // rwFuncs diff --git a/emu/cores/262intf.c b/emu/cores/262intf.c index 664f8fed..3f4cbbb8 100644 --- a/emu/cores/262intf.c +++ b/emu/cores/262intf.c @@ -47,6 +47,7 @@ static DEV_DEF devDef262_MAME = ymf262_set_mute_mask, NULL, // SetPanning NULL, // SetSampleRateChangeCallback + ymf262_set_log_cb, // SetLoggingCallback NULL, // LinkDevice devFunc262_MAME, // rwFuncs @@ -75,6 +76,7 @@ static DEV_DEF devDef262_AdLibEmu = adlib_OPL3_set_mute_mask, NULL, // SetPanning NULL, // SetSampleRateChangeCallback + NULL, // SetLoggingCallback NULL, // LinkDevice devFunc262_Emu, // rwFuncs @@ -103,6 +105,7 @@ static DEV_DEF devDef262_Nuked = nukedopl3_set_mute_mask, NULL, // SetPanning NULL, // SetSampleRateChangeCallback + NULL, // SetLoggingCallback NULL, // LinkDevice devFunc262_Nuked, // rwFuncs diff --git a/emu/cores/Ootake_PSG.c b/emu/cores/Ootake_PSG.c index 76b6cf1b..87ff3baa 100644 --- a/emu/cores/Ootake_PSG.c +++ b/emu/cores/Ootake_PSG.c @@ -81,6 +81,7 @@ DEV_DEF devDef_C6280_Ootake = OPSG_SetMuteMask, NULL, // SetPanning NULL, // SetSampleRateChangeCallback + NULL, // SetLoggingCallback NULL, // LinkDevice devFunc, // rwFuncs diff --git a/emu/cores/ay8910.c b/emu/cores/ay8910.c index 76dc5959..92b03b44 100644 --- a/emu/cores/ay8910.c +++ b/emu/cores/ay8910.c @@ -541,6 +541,7 @@ YM2203 Japanese datasheet contents, translated: http://www.larwe.com/technical/c #include "../EmuStructs.h" #include "../EmuCores.h" #include "../EmuHelper.h" +#include "../logging.h" #include "ayintf.h" #include "ay8910.h" @@ -568,6 +569,7 @@ DEV_DEF devDef_AY8910_MAME = ay8910_set_mute_mask, NULL, // SetPanning ay8910_set_srchg_cb, // SetSampleRateChangeCallback + ay8910_set_log_cb, // SetLoggingCallback NULL, // LinkDevice devFunc, // rwFuncs @@ -647,6 +649,7 @@ typedef struct _mosfet_param struct _ay8910_context { DEV_DATA _devData; + DEV_LOGGER logger; // internal state psg_type_t type; @@ -1079,12 +1082,12 @@ void ay8910_write_reg(ay8910_context *psg, UINT8 r, UINT8 v) //if (psg->port_a_write_cb != NULL) // psg->port_a_write_cb(psg, 0, psg->regs[AY_PORTA]); //else - // logerror("warning: unmapped write %02x to %s Port A\n", v, "AY8910"); + // emu_logf(&psg->logger, DEVLOG_WARN, "unmapped write %02x to Port A\n", v); } else { #if LOG_IGNORED_WRITES - logerror("warning: write %02x to %s Port A set as input - ignored\n", v, "AY8910"); + emu_logf(&psg->logger, DEVLOG_WARN, "write %02x to Port A set as input - ignored\n", v); #endif } break; @@ -1094,12 +1097,12 @@ void ay8910_write_reg(ay8910_context *psg, UINT8 r, UINT8 v) //if (psg->port_b_write_cb != NULL) // psg->port_b_write_cb(psg, 0, psg->regs[AY_PORTB]); //else - // logerror("warning: unmapped write %02x to %s Port B\n", v, "AY8910"); + // emu_logf(&psg->logger, DEVLOG_WARN, "unmapped write %02x to Port B\n", v); } else { #if LOG_IGNORED_WRITES - logerror("warning: write %02x to %s Port B set as input - ignored\n", v, "AY8910"); + emu_logf(&psg->logger, DEVLOG_WARN, "write %02x to Port B set as input - ignored\n", v); #endif } break; @@ -1245,14 +1248,14 @@ static void build_mixer_table(ay8910_context *psg) if ((psg->flags & AY8910_LEGACY_OUTPUT) != 0 || ! psg->flags) { - //logerror("AY-3-8910/YM2149 using legacy output levels!\n"); + //emu_logf(&psg->logger, DEVLOG_INFO, "AY-3-8910/YM2149 using legacy output levels!\n"); normalize = 1; } if ((psg->flags & AY8910_RESISTOR_OUTPUT) != 0) { if (psg->type != PSG_TYPE_AY) - logerror("AY8910_RESISTOR_OUTPUT currently only supported for AY8910 devices."); + emu_logf(&psg->logger, DEVLOG_WARN, "AY8910_RESISTOR_OUTPUT currently only supported for AY8910 devices."); for (chan=0; chan < NUM_CHANNELS; chan++) { @@ -1508,7 +1511,7 @@ void ay8910_write(void *chip, UINT8 addr, UINT8 data) } else { - logerror("warning - %s upper address mismatch\n", "AY8910"); + emu_logf(&psg->logger, DEVLOG_WARN, "upper address mismatch\n"); } } } @@ -1524,7 +1527,7 @@ UINT8 ay8910_read(void *chip, UINT8 addr) { case AY_PORTA: if ((psg->regs[AY_ENABLE] & 0x40) != 0) - logerror("warning: read from %s Port A set as output\n", "AY8910"); + emu_logf(&psg->logger, DEVLOG_WARN, "read from Port A set as output\n"); /* even if the port is set as output, we still need to return the external data. Some games, like kidniki, need this to work. @@ -1538,15 +1541,15 @@ UINT8 ay8910_read(void *chip, UINT8 addr) //if (psg->port_a_read_cb != NULL) // psg->regs[AY_PORTA] = psg->port_a_read_cb(psg, 0); //else - // logerror("Warning - read 8910 Port A\n"); + // emu_logf(&psg->logger, DEVLOG_WARN, "read Port A\n"); break; case AY_PORTB: if ((psg->regs[AY_ENABLE] & 0x80) != 0) - logerror("warning: read from %s Port B set as output\n", "AY8910"); + emu_logf(&psg->logger, DEVLOG_WARN, "read from Port B set as output\n"); //if (psg->port_b_read_cb != NULL) // psg->regs[AY_PORTB] = psg->port_b_read_cb(psg, 0); //else - // logerror("Warning - read 8910 Port B\n"); + // emu_logf(&psg->logger, DEVLOG_WARN, "read Port B\n"); break; } @@ -1610,3 +1613,10 @@ void ay8910_set_srchg_cb(void *chip, DEVCB_SRATE_CHG CallbackFunc, void* DataPtr return; } + +void ay8910_set_log_cb(void* chip, DEVCB_LOG func, void* param) +{ + ay8910_context *info = (ay8910_context *)chip; + dev_logger_set(&info->logger, info, func, param); + return; +} diff --git a/emu/cores/ay8910.h b/emu/cores/ay8910.h index 62b79685..b7440590 100644 --- a/emu/cores/ay8910.h +++ b/emu/cores/ay8910.h @@ -92,5 +92,6 @@ void ay8910_update_one(void *param, UINT32 samples, DEV_SMPL **outputs); void ay8910_set_mute_mask(void *chip, UINT32 MuteMask); void ay8910_set_stereo_mask(void *chip, UINT32 StereoMask); void ay8910_set_srchg_cb(void *chip, DEVCB_SRATE_CHG CallbackFunc, void* DataPtr); +void ay8910_set_log_cb(void* chip, DEVCB_LOG func, void* param); #endif // __AY8910_H__ diff --git a/emu/cores/c140.c b/emu/cores/c140.c index 63860f38..06ac111a 100644 --- a/emu/cores/c140.c +++ b/emu/cores/c140.c @@ -67,6 +67,7 @@ static DEV_DEF devDef = c140_set_mute_mask, NULL, // SetPanning NULL, // SetSampleRateChangeCallback + NULL, // SetLoggingCallback NULL, // LinkDevice devFunc, // rwFuncs diff --git a/emu/cores/c219.c b/emu/cores/c219.c index 960d2b11..aec75f7f 100644 --- a/emu/cores/c219.c +++ b/emu/cores/c219.c @@ -93,6 +93,7 @@ static DEV_DEF devDef = c219_set_mute_mask, NULL, // SetPanning NULL, // SetSampleRateChangeCallback + NULL, // SetLoggingCallback NULL, // LinkDevice devFunc, // rwFuncs diff --git a/emu/cores/c352.c b/emu/cores/c352.c index 9929f9db..7c12fd85 100644 --- a/emu/cores/c352.c +++ b/emu/cores/c352.c @@ -66,6 +66,7 @@ static DEV_DEF devDef = c352_set_mute_mask, NULL, // SetPanning NULL, // SetSampleRateChangeCallback + NULL, // SetLoggingCallback NULL, // LinkDevice devFunc, // rwFuncs diff --git a/emu/cores/c6280_mame.c b/emu/cores/c6280_mame.c index c35ba64b..2abacbb4 100644 --- a/emu/cores/c6280_mame.c +++ b/emu/cores/c6280_mame.c @@ -82,6 +82,7 @@ DEV_DEF devDef_C6280_MAME = c6280mame_set_mute_mask, NULL, // SetPanning NULL, // SetSampleRateChangeCallback + NULL, // SetLoggingCallback NULL, // LinkDevice devFunc, // rwFuncs diff --git a/emu/cores/emu2149.c b/emu/cores/emu2149.c index 18f1b972..57d14fb2 100644 --- a/emu/cores/emu2149.c +++ b/emu/cores/emu2149.c @@ -67,6 +67,7 @@ DEV_DEF devDef_YM2149_Emu = (DEVFUNC_OPTMASK)EPSG_setMuteMask, ay8910_pan_emu, NULL, // SetSampleRateChangeCallback + NULL, // SetLoggingCallback NULL, // LinkDevice devFunc, // rwFuncs diff --git a/emu/cores/emu2413.c b/emu/cores/emu2413.c index d43055cd..a19dbab3 100644 --- a/emu/cores/emu2413.c +++ b/emu/cores/emu2413.c @@ -53,6 +53,7 @@ DEV_DEF devDef_YM2413_Emu = ym2413_set_mute_mask_emu, ym2413_pan_emu, NULL, // SetSampleRateChangeCallback + NULL, // SetLoggingCallback NULL, // LinkDevice devFunc, // rwFuncs diff --git a/emu/cores/es5503.c b/emu/cores/es5503.c index 5cb806a8..6ce440ac 100644 --- a/emu/cores/es5503.c +++ b/emu/cores/es5503.c @@ -81,6 +81,7 @@ static DEV_DEF devDef = es5503_set_mute_mask, NULL, // SetPanning es5503_set_srchg_cb, // SetSampleRateChangeCallback + NULL, // SetLoggingCallback NULL, // LinkDevice devFunc, // rwFuncs diff --git a/emu/cores/fmopl.c b/emu/cores/fmopl.c index 82c05040..4ad03a37 100644 --- a/emu/cores/fmopl.c +++ b/emu/cores/fmopl.c @@ -78,6 +78,7 @@ Revision History: #include "../../stdtype.h" #include "../snddef.h" #include "../EmuHelper.h" +#include "../logging.h" #ifndef SNDDEV_SELECT #define SNDDEV_YM3812 @@ -200,6 +201,7 @@ typedef struct typedef struct fm_opl_f { DEV_DATA _devData; + DEV_LOGGER logger; /* FM channel slots */ OPL_CH P_CH[9]; /* OPL/OPL2 chips have 9 channels*/ @@ -1486,7 +1488,7 @@ static void OPLWriteReg(FM_OPL *OPL, UINT8 r, UINT8 v) if(OPL->keyboardhandler_w) OPL->keyboardhandler_w(OPL->keyboard_param,v); else - logerror("Y8950: write unmapped KEYBOARD port\n"); + emu_logf(&OPL->logger, DEVLOG_DEBUG, "write unmapped KEYBOARD port\n"); } break; case 0x07: /* DELTA-T control 1 : START,REC,MEMDATA,REPT,SPOFF,x,x,RST */ @@ -1520,7 +1522,7 @@ static void OPLWriteReg(FM_OPL *OPL, UINT8 r, UINT8 v) case 0x15: /* DAC data high 8 bits (F7,F6...F2) */ case 0x16: /* DAC data low 2 bits (F1, F0 in bits 7,6) */ case 0x17: /* DAC data shift (S2,S1,S0 in bits 2,1,0) */ - logerror("FMOPL.C: DAC data register written, but not implemented reg=%02x val=%02x\n",r,v); + emu_logf(&OPL->logger, DEVLOG_DEBUG, "DAC data register written, but not implemented reg=%02x val=%02x\n",r,v); break; case 0x18: /* I/O CTRL (Direction) */ @@ -1537,7 +1539,7 @@ static void OPLWriteReg(FM_OPL *OPL, UINT8 r, UINT8 v) break; #endif default: - logerror("FMOPL.C: write to unknown register: %02x\n",r); + emu_logf(&OPL->logger, DEVLOG_DEBUG, "write to unknown register: %02x\n",r); break; } break; @@ -1875,7 +1877,7 @@ static UINT8 OPLRead(FM_OPL *OPL,UINT8 a) if(OPL->keyboardhandler_r) return OPL->keyboardhandler_r(OPL->keyboard_param); else - logerror("Y8950: read unmapped KEYBOARD port\n"); + emu_logf(&OPL->logger, DEVLOG_DEBUG, "read unmapped KEYBOARD port\n"); } return 0; @@ -1885,7 +1887,7 @@ static UINT8 OPLRead(FM_OPL *OPL,UINT8 a) UINT8 val; val = YM_DELTAT_ADPCM_Read(OPL->deltat); - /*logerror("Y8950: read ADPCM value read=%02x\n",val);*/ + /*emu_logf(&OPL->logger, DEVLOG_DEBUG, "read ADPCM value read=%02x\n",val);*/ return val; } return 0; @@ -1896,13 +1898,13 @@ static UINT8 OPLRead(FM_OPL *OPL,UINT8 a) if(OPL->porthandler_r) return OPL->porthandler_r(OPL->port_param); else - logerror("Y8950:read unmapped I/O port\n"); + emu_logf(&OPL->logger, DEVLOG_DEBUG, "read unmapped I/O port\n"); } return 0; case 0x1a: /* PCM-DATA */ if(OPL->type&OPL_TYPE_ADPCM) { - logerror("Y8950 A/D conversion is accessed but not implemented !\n"); + emu_logf(&OPL->logger, DEVLOG_DEBUG, "A/D conversion is accessed but not implemented !\n"); return 0x80; /* 2's complement PCM data - result from A/D conversion */ } return 0; @@ -2245,6 +2247,7 @@ void *y8950_init(UINT32 clock, UINT32 rate) if (Y8950 == NULL) return NULL; + Y8950->deltat->logger = &Y8950->logger; Y8950->deltat->memory = NULL; Y8950->deltat->memory_size = 0x00; Y8950->deltat->memory_mask = 0x00; @@ -2441,3 +2444,10 @@ void opl_set_mute_mask(void *chip, UINT32 MuteMask) return; } + +void opl_set_log_cb(void* chip, DEVCB_LOG func, void* param) +{ + FM_OPL *opl = (FM_OPL *)chip; + dev_logger_set(&opl->logger, opl, func, param); + return; +} diff --git a/emu/cores/fmopl.h b/emu/cores/fmopl.h index 41388170..fcebf0ac 100644 --- a/emu/cores/fmopl.h +++ b/emu/cores/fmopl.h @@ -102,5 +102,6 @@ void y8950_set_update_handler(void *chip, OPL_UPDATEHANDLER UpdateHandler, void #endif // BUILD_Y8950 void opl_set_mute_mask(void *chip, UINT32 MuteMask); +void opl_set_log_cb(void* chip, DEVCB_LOG func, void* param); #endif // __FMOPL_H__ diff --git a/emu/cores/fmopn.c b/emu/cores/fmopn.c index 67f033ff..54f87bf8 100644 --- a/emu/cores/fmopn.c +++ b/emu/cores/fmopn.c @@ -164,6 +164,7 @@ #include "../../stdtype.h" #include "../snddef.h" #include "../EmuHelper.h" +#include "../logging.h" #ifndef SNDDEV_SELECT #define SNDDEV_YM2203 @@ -707,6 +708,7 @@ typedef struct DEVCB_SRATE_CHG smpRateFunc; void* smpRateData; + DEV_LOGGER logger; } FM_OPN; @@ -2659,6 +2661,13 @@ void ym2203_set_mute_mask(void *chip, UINT32 MuteMask) return; } + +void ym2203_set_log_cb(void* chip, DEVCB_LOG func, void* param) +{ + YM2203 *F2203 = (YM2203 *)chip; + dev_logger_set(&F2203->OPN.logger, F2203, func, param); + return; +} #endif /* BUILD_YM2203 */ @@ -2782,9 +2791,9 @@ INLINE void ADPCMA_calc_chan( YM2610 *F2610, ADPCM_CH *ch ) return; } #if 0 - if ( ch->now_addr > (F2610->pcmsizeA<<1) ) + if ( ch->now_addr > (F2610->pcm_size<<1) ) { - LOG(LOG_WAR,("YM2610: Attempting to play past adpcm rom size!\n" )); + emu_logf(&F2610->OPN.logger, DEVLOG_WARN, "YM2610: Attempting to play past adpcm rom size!\n"); return; } #endif @@ -2792,7 +2801,7 @@ INLINE void ADPCMA_calc_chan( YM2610 *F2610, ADPCM_CH *ch ) data = ch->now_data & 0x0f; else { - ch->now_data = *(F2610->pcmbuf+(ch->now_addr>>1)); + ch->now_data = F2610->pcmbuf[ch->now_addr>>1]; data = (ch->now_data >> 4) & 0x0f; } @@ -2849,19 +2858,19 @@ static void FM_ADPCMAWrite(YM2610 *F2610,int r,int v) if(F2610->pcmbuf==NULL) { /* Check ROM Mapped */ - logerror("YM2608-YM2610: ADPCM-A rom not mapped\n"); + emu_logf(&F2610->OPN.logger, DEVLOG_WARN, "ADPCM-A rom not mapped\n"); adpcm[c].flag = 0; } else { if(adpcm[c].end >= F2610->pcm_size) { /* Check End in Range */ - logerror("YM2610: ADPCM-A end out of range: $%08x\n",adpcm[c].end); + emu_logf(&F2610->OPN.logger, DEVLOG_DEBUG, "ADPCM-A end out of range: $%08x\n",adpcm[c].end); /*adpcm[c].end = F2610->pcm_size-1;*/ /* JB: DO NOT uncomment this, otherwise you will break the comparison in the ADPCM_CALC_CHA() */ } if(adpcm[c].start >= F2610->pcm_size) /* Check Start in Range */ { - logerror("YM2608-YM2610: ADPCM-A start out of range: $%08x\n",adpcm[c].start); + emu_logf(&F2610->OPN.logger, DEVLOG_DEBUG, "ADPCM-A start out of range: $%08x\n",adpcm[c].start); adpcm[c].flag = 0; } } @@ -3212,6 +3221,7 @@ void * ym2608_init(void *param, UINT32 clock, UINT32 rate, OPNSetSmplRateChgCallback(&F2608->OPN, NULL, NULL); /* DELTA-T */ + F2608->deltaT.logger = &F2608->OPN.logger; F2608->deltaT.memory = NULL; F2608->deltaT.memory_size = 0x00; F2608->deltaT.memory_mask = 0x00; @@ -3432,7 +3442,7 @@ void ym2608_write(void *chip, UINT8 a,UINT8 v) switch( addr ) { case 0x0e: /* DAC data */ - logerror("YM2608: write to DAC data (unimplemented) value=%02x\n",v); + emu_logf(&F2608->OPN.logger, DEVLOG_TRACE, "write to DAC data (unimplemented) value=%02x\n",v); break; default: /* 0x00-0x0d */ @@ -3483,7 +3493,7 @@ UINT8 ym2608_read(void *chip,UINT8 a) } else if(addr == 0x0f) { - logerror("YM2608 A/D conversion is accessed but not implemented !\n"); + emu_logf(&F2608->OPN.logger, DEVLOG_TRACE, "A/D conversion is accessed but not implemented !\n"); ret = 0x80; /* 2's complement PCM data - result from A/D conversion */ } break; @@ -3569,6 +3579,13 @@ void ym2608_set_mute_mask(void *chip, UINT32 MuteMask) return; } + +void ym2608_set_log_cb(void* chip, DEVCB_LOG func, void* param) +{ + YM2608 *F2608 = (YM2608 *)chip; + dev_logger_set(&F2608->OPN.logger, F2608, func, param); + return; +} #endif /* BUILD_YM2608 */ @@ -3606,16 +3623,16 @@ void ym2610_update_one(void *chip, UINT32 length, DEV_SMPL **buffer) #ifdef YM2610B_WARNING #define FM_KEY_IS(SLOT) ((SLOT)->key) -#define FM_MSG_YM2610B "YM2610-%p.CH%d is playing,Check whether the type of the chip is YM2610B\n" +#define FM_MSG_YM2610B "CH%d is playing,Check whether the type of the chip is YM2610B\n" /* Check YM2610B warning message */ if( FM_KEY_IS(&F2610->CH[0].SLOT[3]) ) { - LOG(LOG_WAR,(FM_MSG_YM2610B,F2610->OPN.ST.param,0)); + emu_logf(&F2610->OPN.logger, DEVLOG_WARN, FM_MSG_YM2610B, 0); FM_KEY_IS(&F2610->CH[0].SLOT[3]) = 0; } if( FM_KEY_IS(&F2610->CH[3].SLOT[3]) ) { - LOG(LOG_WAR,(FM_MSG_YM2610B,F2610->OPN.ST.param,3)); + emu_logf(&F2610->OPN.logger, DEVLOG_WARN, FM_MSG_YM2610B, 3); FM_KEY_IS(&F2610->CH[3].SLOT[3]) = 0; } #endif @@ -3967,6 +3984,7 @@ void *ym2610_init(void *param, UINT32 clock, UINT32 rate, F2610->pcmbuf = NULL; F2610->pcm_size = 0x00; /* DELTA-T */ + F2610->deltaT.logger = &F2610->OPN.logger; F2610->deltaT.memory = NULL; F2610->deltaT.memory_size = 0x00; F2610->deltaT.memory_mask = 0x00; @@ -4147,7 +4165,7 @@ void ym2610_write(void *chip, UINT8 a, UINT8 v) break; default: - logerror("YM2610: write to unknown deltat register %02x val=%02x\n",addr,v); + emu_logf(&F2610->OPN.logger, DEVLOG_WARN, "write to unknown deltat register %02x val=%02x\n",addr,v); break; } @@ -4304,6 +4322,13 @@ void ym2610_set_mute_mask(void *chip, UINT32 MuteMask) return; } + +void ym2610_set_log_cb(void* chip, DEVCB_LOG func, void* param) +{ + YM2610 *F2610 = (YM2610 *)chip; + dev_logger_set(&F2610->OPN.logger, F2610, func, param); + return; +} #endif /* (BUILD_YM2610||BUILD_YM2610B) */ @@ -4724,7 +4749,7 @@ UINT8 ym2612_read(void *chip, UINT8 a) case 1: case 2: case 3: - //LOG(LOG_WAR,("YM2612 #%p:A=%d read unmapped area\n",F2612->OPN.ST.param,a)); + //emu_logf(&F2612->OPN.logger, DEVLOG_WARN, "A=%d read unmapped area\n", a); return FM_STATUS_FLAG(&F2612->OPN.ST); } return 0; @@ -4776,4 +4801,11 @@ void ym2612_set_options(void *chip, UINT32 Flags) return; } + +void ym2612_set_log_cb(void* chip, DEVCB_LOG func, void* param) +{ + YM2612 *F2612 = (YM2612 *)chip; + dev_logger_set(&F2612->OPN.logger, F2612, func, param); + return; +} #endif /* (BUILD_YM2612) */ diff --git a/emu/cores/fmopn.h b/emu/cores/fmopn.h index e5234aab..f270487c 100644 --- a/emu/cores/fmopn.h +++ b/emu/cores/fmopn.h @@ -139,6 +139,11 @@ UINT8 ym2203_timer_over(void *chip, UINT8 c); ** Channel Muting */ void ym2203_set_mute_mask(void *chip, UINT32 MuteMask); + +/* +** logging function +*/ +void ym2203_set_log_cb(void* chip, DEVCB_LOG func, void* param); #endif /* BUILD_YM2203 */ #if BUILD_YM2608 @@ -158,6 +163,7 @@ void ym2608_alloc_pcmromb(void* chip, UINT32 memsize); void ym2608_write_pcmromb(void* chip, UINT32 offset, UINT32 length, const UINT8* data); void ym2608_set_mute_mask(void *chip, UINT32 MuteMask); +void ym2608_set_log_cb(void* chip, DEVCB_LOG func, void* param); #endif /* BUILD_YM2608 */ #if (BUILD_YM2610||BUILD_YM2610B) @@ -182,6 +188,7 @@ void ym2610_alloc_pcmromb(void* chip, UINT32 memsize); void ym2610_write_pcmromb(void* chip, UINT32 offset, UINT32 length, const UINT8* data); void ym2610_set_mute_mask(void *chip, UINT32 MuteMask); +void ym2610_set_log_cb(void* chip, DEVCB_LOG func, void* param); #endif /* (BUILD_YM2610||BUILD_YM2610B) */ #if (BUILD_YM2612||BUILD_YM3438) @@ -197,6 +204,7 @@ UINT8 ym2612_timer_over(void *chip, UINT8 c ); void ym2612_set_mute_mask(void *chip, UINT32 MuteMask); void ym2612_set_options(void *chip, UINT32 Flags); +void ym2612_set_log_cb(void* chip, DEVCB_LOG func, void* param); #endif /* (BUILD_YM2612||BUILD_YM3438) */ #endif // __FMOPN_H__ diff --git a/emu/cores/gb.c b/emu/cores/gb.c index c038cfb8..34e8c3ba 100644 --- a/emu/cores/gb.c +++ b/emu/cores/gb.c @@ -101,6 +101,7 @@ static DEV_DEF devDef = gameboy_sound_set_mute_mask, NULL, // SetPanning NULL, // SetSampleRateChangeCallback + NULL, // SetLoggingCallback NULL, // LinkDevice devFunc, // rwFuncs diff --git a/emu/cores/iremga20.c b/emu/cores/iremga20.c index a8700807..2aa32956 100644 --- a/emu/cores/iremga20.c +++ b/emu/cores/iremga20.c @@ -49,6 +49,7 @@ Irem GA20 PCM Sound Chip #include "../EmuCores.h" #include "../snddef.h" #include "../EmuHelper.h" +#include "../logging.h" #include "iremga20.h" @@ -65,6 +66,7 @@ static void iremga20_write_rom(void *info, UINT32 offset, UINT32 length, const U static void iremga20_set_mute_mask(void *info, UINT32 MuteMask); static void iremga20_set_options(void *chip, UINT32 Flags); +static void iremga20_set_log_cb(void* info, DEVCB_LOG func, void* param); static DEVDEF_RWFUNC devFunc[] = @@ -89,6 +91,7 @@ static DEV_DEF devDef = iremga20_set_mute_mask, NULL, // SetPanning NULL, // SetSampleRateChangeCallback + iremga20_set_log_cb, // SetLoggingCallback NULL, // LinkDevice devFunc, // rwFuncs @@ -125,6 +128,7 @@ typedef struct _ga20_state ga20_state; struct _ga20_state { DEV_DATA _devData; + DEV_LOGGER logger; UINT8 *rom; UINT32 rom_size; @@ -211,7 +215,7 @@ static void irem_ga20_w(void *info, UINT8 offset, UINT8 data) struct IremGA20_channel_def* ch; int channel; - //logerror("GA20: Offset %02x, data %04x\n",offset,data); + //emu_logf(&chip->logger, DEVLOG_DEBUG, Offset %02x, data %04x\n",offset,data); offset &= 0x1F; channel = offset >> 3; @@ -289,7 +293,7 @@ static UINT8 irem_ga20_r(void *info, UINT8 offset) return chip->channel[channel].play; default: - logerror("GA20: read unk. register %d, channel %d\n", offset & 0x7, channel); + emu_logf(&chip->logger, DEVLOG_DEBUG, "read unk. register %d, channel %d\n", offset & 0x7, channel); break; } @@ -395,3 +399,10 @@ static void iremga20_set_options(void *info, UINT32 Flags) return; } + +static void iremga20_set_log_cb(void* info, DEVCB_LOG func, void* param) +{ + ga20_state *chip = (ga20_state *)info; + dev_logger_set(&chip->logger, chip, func, param); + return; +} diff --git a/emu/cores/k051649.c b/emu/cores/k051649.c index d4bf35a5..169a541d 100644 --- a/emu/cores/k051649.c +++ b/emu/cores/k051649.c @@ -79,6 +79,7 @@ static DEV_DEF devDef = k051649_set_mute_mask, NULL, // SetPanning NULL, // SetSampleRateChangeCallback + NULL, // SetLoggingCallback NULL, // LinkDevice devFunc, // rwFuncs diff --git a/emu/cores/k053260.c b/emu/cores/k053260.c index 6d62a614..9fcfe776 100644 --- a/emu/cores/k053260.c +++ b/emu/cores/k053260.c @@ -61,6 +61,7 @@ #include "../EmuCores.h" #include "../snddef.h" #include "../EmuHelper.h" +#include "../logging.h" #include "../RatioCntr.h" #include "k053260.h" @@ -77,6 +78,7 @@ static void k053260_write(void* chip, UINT8 offset, UINT8 data); static void k053260_alloc_rom(void* chip, UINT32 memsize); static void k053260_write_rom(void *chip, UINT32 offset, UINT32 length, const UINT8* data); static void k053260_set_mute_mask(void* chip, UINT32 MuteMask); +static void k053260_set_log_cb(void* chip, DEVCB_LOG func, void* param); static DEVDEF_RWFUNC devFunc[] = @@ -101,6 +103,7 @@ static DEV_DEF devDef = k053260_set_mute_mask, NULL, // SetPanning NULL, // SetSampleRateChangeCallback + k053260_set_log_cb, // SetLoggingCallback NULL, // LinkDevice devFunc, // rwFuncs @@ -166,7 +169,7 @@ INLINE void KDSC_set_register(KDSC_Voice* voice, UINT8 offset, UINT8 data); INLINE void KDSC_set_loop_kadpcm(KDSC_Voice* voice, UINT8 data); INLINE void KDSC_set_pan(KDSC_Voice* voice, UINT8 data); INLINE void KDSC_update_pan_volume(KDSC_Voice* voice); -INLINE void KDSC_key_on(KDSC_Voice* voice); +INLINE void KDSC_key_on(k053260_state* info, KDSC_Voice* voice); INLINE void KDSC_key_off(KDSC_Voice* voice); INLINE void KDSC_play(KDSC_Voice* voice, DEV_SMPL *outputs, UINT16 cycles); INLINE UINT8 KDSC_read_rom(KDSC_Voice* voice); @@ -175,6 +178,7 @@ INLINE UINT8 k053260_rom_data(k053260_state* info, UINT32 offs); struct _k053260_state { DEV_DATA _devData; + DEV_LOGGER logger; // live state UINT8 portdata[4]; @@ -301,11 +305,11 @@ static UINT8 k053260_read(void* chip, UINT8 offset) if (info->mode & 1) ret = KDSC_read_rom(&info->voice[0]); else - logerror("Attempting to read K053260 ROM without mode bit set\n"); + emu_logf(&info->logger, DEVLOG_WARN, "Attempting to read ROM without mode bit set\n"); break; default: - logerror("Read from unknown K053260 register %02x\n", offset); + emu_logf(&info->logger, DEVLOG_DEBUG, "Read from unknown register %02x\n", offset); } return ret; } @@ -343,7 +347,7 @@ static void k053260_write(void* chip, UINT8 offset, UINT8 data) for (i = 0; i < 4; i++) { if (rising_edge & (1 << i)) - KDSC_key_on(&info->voice[i]); + KDSC_key_on(info, &info->voice[i]); else if (!(data & (1 << i))) KDSC_key_off(&info->voice[i]); } @@ -387,7 +391,7 @@ static void k053260_write(void* chip, UINT8 offset, UINT8 data) break; default: - logerror("Write to unknown K053260 register %02x (data = %02x)\n", + emu_logf(&info->logger, DEVLOG_DEBUG, "Write to unknown register %02x (data = %02x)\n", offset, data); } } @@ -509,13 +513,13 @@ INLINE void KDSC_update_pan_volume(KDSC_Voice* voice) voice->pan_volume[1] = voice->volume * pan_mul[voice->pan][1]; } -INLINE void KDSC_key_on(KDSC_Voice* voice) +INLINE void KDSC_key_on(k053260_state* info, KDSC_Voice* voice) { voice->position = voice->kadpcm ? 1 : 0; // for kadpcm low bit is nybble offset, so must start at 1 due to preincrement voice->counter = 0xFFFF; // force update on next sound_stream_update voice->output = 0; voice->playing = 1; - if (LOG) logerror("K053260: start = %06x, length = %06x, pitch = %04x, vol = %02x:%x, loop = %s, %s\n", + if (LOG) emu_logf(&info->logger, DEVLOG_TRACE, "start = %06x, length = %06x, pitch = %04x, vol = %02x:%x, loop = %s, %s\n", voice->start, voice->length, voice->pitch, voice->volume, voice->pan, voice->loop ? "yes" : "no", voice->kadpcm ? "KADPCM" : "PCM" ); } @@ -636,3 +640,10 @@ static void k053260_set_mute_mask(void* chip, UINT32 MuteMask) return; } + +static void k053260_set_log_cb(void* chip, DEVCB_LOG func, void* param) +{ + k053260_state *info = (k053260_state *)chip; + dev_logger_set(&info->logger, info, func, param); + return; +} diff --git a/emu/cores/k054539.c b/emu/cores/k054539.c index 2118380c..6673f17e 100644 --- a/emu/cores/k054539.c +++ b/emu/cores/k054539.c @@ -19,6 +19,7 @@ #include "../EmuCores.h" #include "../snddef.h" #include "../EmuHelper.h" +#include "../logging.h" #include "k054539.h" static void k054539_update(void *param, UINT32 samples, DEV_SMPL **outputs); @@ -36,6 +37,7 @@ static void k054539_alloc_rom(void* chip, UINT32 memsize); static void k054539_write_rom(void *chip, UINT32 offset, UINT32 length, const UINT8* data); static void k054539_set_mute_mask(void *chip, UINT32 MuteMask); +static void k054539_set_log_cb(void* chip, DEVCB_LOG func, void* param); static DEVDEF_RWFUNC devFunc[] = @@ -60,6 +62,7 @@ static DEV_DEF devDef = k054539_set_mute_mask, NULL, // SetPanning NULL, // SetSampleRateChangeCallback + k054539_set_log_cb, // SetLoggingCallback NULL, // LinkDevice devFunc, // rwFuncs @@ -71,9 +74,6 @@ const DEV_DEF* devDefList_K054539[] = }; -#define VERBOSE 0 -#define LOG(x) do { if (VERBOSE) logerror x; } while (0) - /* Registers: 00..ff: 20 bytes/channel, 8 channels 00..02: pitch (lsb, mid, msb) @@ -124,6 +124,7 @@ struct _k054539_channel { typedef struct _k054539_state k054539_state; struct _k054539_state { DEV_DATA _devData; + DEV_LOGGER logger; double voltab[256]; double pantab[0xf]; @@ -367,7 +368,8 @@ static void k054539_update(void *param, UINT32 samples, DEV_SMPL **outputs) break; } default: - LOG(("Unknown sample type %x for channel %d\n", base2[0] & 0xc, ch)); + emu_logf(&info->logger, DEVLOG_DEBUG, "Unknown sample type %x for channel %d\n", base2[0] & 0xc, ch); + info->regs[0x22c] &= ~(1<= 0x200) && (offset <= 0x210))) break; - logerror("K054539 %03x = %02x\n", offset, data); + emu_logf(&info->logger, DEVLOG_TRACE, "%03x = %02x\n", offset, data); } #endif break; @@ -561,7 +563,7 @@ static UINT8 k054539_r(void *chip, UINT16 offset) case 0x22c: break; default: - LOG(("K054539 read %03x\n", offset)); + emu_logf(&info->logger, DEVLOG_TRACE, "read %03x\n", offset); break; } return info->regs[offset]; @@ -694,3 +696,10 @@ static void k054539_set_mute_mask(void *chip, UINT32 MuteMask) return; } + +static void k054539_set_log_cb(void* chip, DEVCB_LOG func, void* param) +{ + k054539_state *info = (k054539_state *)chip; + dev_logger_set(&info->logger, info, func, param); + return; +} diff --git a/emu/cores/multipcm.c b/emu/cores/multipcm.c index 803ea2ac..07411e4b 100644 --- a/emu/cores/multipcm.c +++ b/emu/cores/multipcm.c @@ -84,6 +84,7 @@ static DEV_DEF devDef = multipcm_set_mute_mask, NULL, // SetPanning NULL, // SetSampleRateChangeCallback + NULL, // SetLoggingCallback NULL, // LinkDevice devFunc, // rwFuncs diff --git a/emu/cores/nesintf.c b/emu/cores/nesintf.c index 0f7955f9..ce0d2b67 100644 --- a/emu/cores/nesintf.c +++ b/emu/cores/nesintf.c @@ -73,6 +73,7 @@ static DEV_DEF devDef_MAME = nes_set_mute_mask_mame, NULL, // SetPanning NULL, // SetSampleRateChangeCallback + NULL, // SetLoggingCallback NULL, // LinkDevice devFunc_MAME, // rwFuncs @@ -100,6 +101,7 @@ static DEV_DEF devDef_NSFPlay = nes_set_mute_mask_nsfplay, NULL, // SetPanning NULL, // SetSampleRateChangeCallback + NULL, // SetLoggingCallback NULL, // LinkDevice devFunc_NSFPlay, // rwFuncs diff --git a/emu/cores/nukedopll.c b/emu/cores/nukedopll.c index 92c4d0ce..2d72f16e 100644 --- a/emu/cores/nukedopll.c +++ b/emu/cores/nukedopll.c @@ -58,6 +58,7 @@ DEV_DEF devDef_YM2413_Nuked = nukedopll_set_mute_mask, NULL, NULL, // SetSampleRateChangeCallback + NULL, // SetLoggingCallback NULL, // LinkDevice devFunc, // rwFuncs diff --git a/emu/cores/nukedopm.c b/emu/cores/nukedopm.c index b6cade88..ae7d9e52 100644 --- a/emu/cores/nukedopm.c +++ b/emu/cores/nukedopm.c @@ -61,6 +61,7 @@ DEV_DEF devDef_YM2151_Nuked = nukedopm_set_mute_mask, NULL, NULL, // SetSampleRateChangeCallback + NULL, // SetLoggingCallback NULL, // LinkDevice devFunc, // rwFuncs diff --git a/emu/cores/okim6258.c b/emu/cores/okim6258.c index 19275d6c..16336f8c 100644 --- a/emu/cores/okim6258.c +++ b/emu/cores/okim6258.c @@ -19,6 +19,7 @@ #include "../snddef.h" #include "../EmuHelper.h" #include "../EmuCores.h" +#include "../logging.h" #include "okim6258.h" @@ -40,6 +41,7 @@ static void okim6258_write(void *chip, UINT8 offset, UINT8 data); static void okim6258_set_options(void *chip, UINT32 Options); static void okim6258_set_srchg_cb(void *chip, DEVCB_SRATE_CHG CallbackFunc, void* DataPtr); static void okim6258_set_mute_mask(void *chip, UINT32 MuteMask); +static void okim6258_set_log_cb(void* chip, DEVCB_LOG func, void* param); static DEVDEF_RWFUNC devFunc[] = @@ -64,6 +66,7 @@ static DEV_DEF devDef = okim6258_set_mute_mask, NULL, // SetPanning okim6258_set_srchg_cb, // SetSampleRateChangeCallback + okim6258_set_log_cb, // SetLoggingCallback NULL, // LinkDevice devFunc, // rwFuncs @@ -88,6 +91,7 @@ typedef struct _okim6258_state okim6258_state; struct _okim6258_state { DEV_DATA _devData; + DEV_LOGGER logger; UINT8 status; @@ -481,7 +485,7 @@ static void okim6258_data_w(void *chip, UINT8 data) info->data_buf_pos &= 0xF7; if ((info->data_buf_pos >> 4) == (info->data_buf_pos & 0x0F)) { - logerror("Warning: FIFO full!\n"); + emu_logf(&info->logger, DEVLOG_WARN, "FIFO full!\n"); info->data_buf_pos = (info->data_buf_pos & 0xF0) | ((info->data_buf_pos-1) & 0x07); } info->data_empty = 0x00; @@ -529,7 +533,7 @@ static void okim6258_ctrl_w(void *chip, UINT8 data) if (data & COMMAND_RECORD) { - logerror("M6258: Record enabled\n"); + emu_logf(&info->logger, DEVLOG_ERROR, "Record enabled\n"); info->status |= STATUS_RECORDING; } else @@ -612,3 +616,10 @@ static void okim6258_set_mute_mask(void *chip, UINT32 MuteMask) return; } + +static void okim6258_set_log_cb(void* chip, DEVCB_LOG func, void* param) +{ + okim6258_state *info = (okim6258_state *)chip; + dev_logger_set(&info->logger, info, func, param); + return; +} diff --git a/emu/cores/okim6295.c b/emu/cores/okim6295.c index 72ee8a19..2721e661 100644 --- a/emu/cores/okim6295.c +++ b/emu/cores/okim6295.c @@ -57,6 +57,7 @@ #include "../snddef.h" #include "../EmuHelper.h" #include "../EmuCores.h" +#include "../logging.h" #include "okim6295.h" #include "okiadpcm.h" @@ -80,6 +81,7 @@ static void okim6295_alloc_rom(void* info, UINT32 memsize); static void okim6295_write_rom(void* info, UINT32 offset, UINT32 length, const UINT8* data); static void okim6295_set_mute_mask(void *info, UINT32 MuteMask); static void okim6295_set_srchg_cb(void* chip, DEVCB_SRATE_CHG CallbackFunc, void* DataPtr); +static void okim6295_set_log_cb(void* chip, DEVCB_LOG func, void* param); static DEVDEF_RWFUNC devFunc[] = @@ -106,6 +108,7 @@ static DEV_DEF devDef = okim6295_set_mute_mask, NULL, // SetPanning okim6295_set_srchg_cb, // SetSampleRateChangeCallback + okim6295_set_log_cb, // SetLoggingCallback NULL, // LinkDevice devFunc, // rwFuncs @@ -134,6 +137,7 @@ typedef struct _okim_voice struct _okim6295_state { DEV_DATA _devData; + DEV_LOGGER logger; // internal state #define OKIM6295_VOICES 4 @@ -510,14 +514,14 @@ static void okim6295_write_command(okim6295_state *info, UINT8 data) // invalid samples go here else { - logerror("OKIM6295: Voice %u requested to play invalid sample %02x\n",voicenum,info->command); + emu_logf(&info->logger, DEVLOG_DEBUG, "Voice %u requested to play invalid sample %02x\n",voicenum,info->command); voice->playing = 0; } } else { // just displays warnings when seeking - //logerror("OKIM6295: Voice %u requested to play sample %02x on non-stopped voice\n",voicenum,info->command); + //emu_logf(&info->logger, DEVLOG_DEBUG, "Voice %u requested to play sample %02x on non-stopped voice\n",voicenum,info->command); } } @@ -633,3 +637,10 @@ static void okim6295_set_srchg_cb(void* chip, DEVCB_SRATE_CHG CallbackFunc, void return; } + +static void okim6295_set_log_cb(void* chip, DEVCB_LOG func, void* param) +{ + okim6295_state *info = (okim6295_state *)chip; + dev_logger_set(&info->logger, info, func, param); + return; +} diff --git a/emu/cores/oplintf.c b/emu/cores/oplintf.c index da5d5077..e96fc6df 100644 --- a/emu/cores/oplintf.c +++ b/emu/cores/oplintf.c @@ -54,6 +54,7 @@ static DEV_DEF devDef3812_MAME = opl_set_mute_mask, NULL, // SetPanning NULL, // SetSampleRateChangeCallback + opl_set_log_cb, // SetLoggingCallback NULL, // LinkDevice devFunc3812_MAME, // rwFuncs @@ -80,6 +81,7 @@ static DEV_DEF devDef3812_AdLibEmu = adlib_OPL2_set_mute_mask, NULL, // SetPanning NULL, // SetSampleRateChangeCallback + NULL, // SetLoggingCallback NULL, // LinkDevice devFunc3812_Emu, // rwFuncs @@ -106,6 +108,7 @@ static DEV_DEF devDef3812_Nuked = nukedopl3_set_mute_mask, NULL, // SetPanning NULL, // SetSampleRateChangeCallback + NULL, // SetLoggingCallback NULL, // LinkDevice devFunc3812_Nuked, // rwFuncs @@ -150,6 +153,7 @@ static DEV_DEF devDef3526_MAME = opl_set_mute_mask, NULL, // SetPanning NULL, // SetSampleRateChangeCallback + opl_set_log_cb, // SetLoggingCallback NULL, // LinkDevice devFunc3526_MAME, // rwFuncs @@ -186,6 +190,7 @@ static DEV_DEF devDef8950_MAME = opl_set_mute_mask, NULL, // SetPanning NULL, // SetSampleRateChangeCallback + opl_set_log_cb, // SetLoggingCallback NULL, // LinkDevice devFunc8950_MAME, // rwFuncs diff --git a/emu/cores/opnintf.c b/emu/cores/opnintf.c index 00d865b6..79b0201c 100644 --- a/emu/cores/opnintf.c +++ b/emu/cores/opnintf.c @@ -66,6 +66,7 @@ static DEV_DEF devDef_MAME_2203 = ym2203_set_mute_mask, // SetMuteMask NULL, // SetPanning ym2203_set_srchg_cb, // SetSampleRateChangeCallback + ym2203_set_log_cb, // SetLoggingCallback device_ym2203_link_ssg, // LinkDevice devFunc_MAME_2203, // rwFuncs @@ -101,6 +102,7 @@ static DEV_DEF devDef_MAME_2608 = ym2608_set_mute_mask, // SetMuteMask NULL, // SetPanning ym2608_set_srchg_cb, // SetSampleRateChangeCallback + ym2608_set_log_cb, // SetLoggingCallback device_ym2608_link_ssg, // LinkDevice devFunc_MAME_2608, // rwFuncs @@ -138,6 +140,7 @@ static DEV_DEF devDef_MAME_2610 = ym2610_set_mute_mask, // SetMuteMask NULL, // SetPanning NULL, // SetSampleRateChangeCallback (not required, the YM2610 lacks the "prescaler" register) + ym2610_set_log_cb, // SetLoggingCallback device_ym2610_link_ssg, // LinkDevice devFunc_MAME_2610, // rwFuncs @@ -155,6 +158,7 @@ static DEV_DEF devDef_MAME_2610B = ym2610_set_mute_mask, // SetMuteMask NULL, // SetPanning NULL, // SetSampleRateChangeCallback (not required, the YM2610 lacks the "prescaler" register) + ym2610_set_log_cb, // SetLoggingCallback device_ym2610_link_ssg, // LinkDevice devFunc_MAME_2610, // rwFuncs diff --git a/emu/cores/pokey.c b/emu/cores/pokey.c index 1c66e904..9aecb26d 100644 --- a/emu/cores/pokey.c +++ b/emu/cores/pokey.c @@ -108,6 +108,7 @@ static DEV_DEF devDef = pokey_device_set_mute_mask, NULL, // SetPanning NULL, // SetSampleRateChangeCallback + NULL, // SetLoggingCallback NULL, // LinkDevice devFunc, // rwFuncs diff --git a/emu/cores/pwm.c b/emu/cores/pwm.c index ec81ab20..30f6501e 100644 --- a/emu/cores/pwm.c +++ b/emu/cores/pwm.c @@ -67,6 +67,7 @@ static DEV_DEF devDef = pwm_set_mute_mask, NULL, // SetPanning NULL, // SetSampleRateChangeCallback + NULL, // SetLoggingCallback NULL, // LinkDevice devFunc, // rwFuncs diff --git a/emu/cores/qsound_ctr.c b/emu/cores/qsound_ctr.c index 3aa8f5cb..2f218589 100644 --- a/emu/cores/qsound_ctr.c +++ b/emu/cores/qsound_ctr.c @@ -173,6 +173,7 @@ DEV_DEF devDef_QSound_ctr = qsoundc_set_mute_mask, NULL, // SetPanning NULL, // SetSampleRateChangeCallback + NULL, // SetLoggingCallback NULL, // LinkDevice devFunc, // rwFuncs diff --git a/emu/cores/qsound_mame.c b/emu/cores/qsound_mame.c index 055987dc..51373bf6 100644 --- a/emu/cores/qsound_mame.c +++ b/emu/cores/qsound_mame.c @@ -36,6 +36,7 @@ #include "../EmuCores.h" #include "../snddef.h" #include "../EmuHelper.h" +#include "../logging.h" #include "qsound_mame.h" @@ -52,6 +53,7 @@ static void qsound_alloc_rom(void* info, UINT32 memsize); static void qsound_write_rom(void *info, UINT32 offset, UINT32 length, const UINT8* data); static void qsound_set_mute_mask(void *info, UINT32 MuteMask); static UINT32 qsound_get_mute_mask(void *info); +static void qsound_set_log_cb(void* info, DEVCB_LOG func, void* param); static DEVDEF_RWFUNC devFunc[] = @@ -77,19 +79,13 @@ DEV_DEF devDef_QSound_MAME = qsound_set_mute_mask, NULL, // SetPanning NULL, // SetSampleRateChangeCallback + qsound_set_log_cb, // SetLoggingCallback NULL, // LinkDevice devFunc, // rwFuncs }; -/* -Debug defines -*/ -#define VERBOSE 0 -#define LOG(x) do { if (VERBOSE) logerror x; } while (0) - - #define QSOUND_CLOCK 60000000 /* default 60MHz clock */ #define QSOUND_CLOCKDIV (2*1248) /* /2/1248 clock divider */ #define QSOUND_CHANNELS 16 @@ -116,6 +112,7 @@ typedef struct _qsound_state qsound_state; struct _qsound_state { DEV_DATA _devData; + DEV_LOGGER logger; qsound_channel channel[QSOUND_CHANNELS]; @@ -199,8 +196,7 @@ static void qsound_w(void *info, UINT8 offset, UINT8 data) break; default: - //logerror("%s: qsound_w %d = %02x\n", machine().describe_context(), offset, data); - logerror("QSound: unexpected qsound write to offset %d == %02X\n", offset, data); + emu_logf(&chip->logger, DEVLOG_DEBUG, "unexpected qsound write to offset %d == %02X\n", offset, data); break; } } @@ -311,7 +307,7 @@ static void qsound_write_data(void *info, UINT8 address, UINT16 data) break; default: - //logerror("%s: write_data %02x = %04x\n", machine().describe_context(), address, data); + //emu_logf(&chip->logger, DEVLOG_DEBUG, "write_data %02x = %04x\n", address, data); break; } } @@ -428,3 +424,10 @@ static UINT32 qsound_get_mute_mask(void *info) return muteMask; } + +static void qsound_set_log_cb(void* info, DEVCB_LOG func, void* param) +{ + qsound_state* chip = (qsound_state *)info; + dev_logger_set(&chip->logger, chip, func, param); + return; +} diff --git a/emu/cores/rf5c68.c b/emu/cores/rf5c68.c index a0d16b44..ac37309d 100644 --- a/emu/cores/rf5c68.c +++ b/emu/cores/rf5c68.c @@ -57,6 +57,7 @@ DEV_DEF devDef_RF5C68_MAME = rf5c68_set_mute_mask, NULL, // SetPanning NULL, // SetSampleRateChangeCallback + NULL, // SetLoggingCallback NULL, // LinkDevice devFunc, // rwFuncs diff --git a/emu/cores/saa1099_mame.c b/emu/cores/saa1099_mame.c index 1b0b0595..61efee55 100644 --- a/emu/cores/saa1099_mame.c +++ b/emu/cores/saa1099_mame.c @@ -75,6 +75,7 @@ #include "../EmuStructs.h" #include "../EmuCores.h" #include "../EmuHelper.h" +#include "../logging.h" #include "saa1099_mame.h" @@ -89,6 +90,7 @@ static void saa1099m_destroy(void *info); static void saa1099m_reset(void *info); static void saa1099m_set_mute_mask(void *info, UINT32 MuteMask); +static void saa1099m_set_log_cb(void* info, DEVCB_LOG func, void* param); static DEVDEF_RWFUNC devFunc[] = @@ -110,6 +112,7 @@ DEV_DEF devDef_SAA1099_MAME = saa1099m_set_mute_mask, NULL, // SetPanning NULL, // SetSampleRateChangeCallback + saa1099m_set_log_cb, // SetLoggingCallback NULL, // LinkDevice devFunc, // rwFuncs @@ -147,6 +150,7 @@ typedef struct _saa1099_state saa1099_state; struct _saa1099_state { DEV_DATA _devData; + DEV_LOGGER logger; UINT8 noise_params[2]; /* noise generators parameters */ UINT8 env_enable[2]; /* envelope generators enable */ @@ -478,7 +482,7 @@ static void saa1099_control_w(void *info, UINT8 data) if ((data & 0xff) > 0x1c) { /* Error! */ - logerror("SAA1099: Unknown register selected\n"); + emu_logf(&saa->logger, DEVLOG_DEBUG, "Unknown register selected\n"); } saa->selected_reg = data & 0x1f; @@ -560,7 +564,7 @@ static void saa1099_data_w(void *info, UINT8 data) int i; /* Synch & Reset generators */ - logerror("SAA1099: -reg 0x1c- Chip reset\n"); + emu_logf(&saa->logger, DEVLOG_DEBUG, "-reg 0x1c- Chip reset\n"); for (i = 0; i < 6; i++) { saa->channels[i].level = 0; @@ -570,7 +574,7 @@ static void saa1099_data_w(void *info, UINT8 data) break; default: /* Error! */ if (data != 0) - logerror("SAA1099: Unknown operation (reg:%02x, data:%02x)\n", reg, data); + emu_logf(&saa->logger, DEVLOG_DEBUG, "Unknown operation (reg:%02x, data:%02x)\n", reg, data); } } @@ -585,3 +589,10 @@ static void saa1099m_set_mute_mask(void *info, UINT32 MuteMask) return; } + +static void saa1099m_set_log_cb(void* info, DEVCB_LOG func, void* param) +{ + saa1099_state *saa = (saa1099_state *)info; + dev_logger_set(&saa->logger, saa, func, param); + return; +} diff --git a/emu/cores/saa1099_vb.c b/emu/cores/saa1099_vb.c index bda7c659..65d9b6b5 100644 --- a/emu/cores/saa1099_vb.c +++ b/emu/cores/saa1099_vb.c @@ -72,6 +72,7 @@ DEV_DEF devDef_SAA1099_VB = saa1099v_set_mute_mask, NULL, // SetPanning NULL, // SetSampleRateChangeCallback + NULL, // SetLoggingCallback NULL, // LinkDevice devFunc, // rwFuncs diff --git a/emu/cores/scd_pcm.c b/emu/cores/scd_pcm.c index 28e4d523..c4267c5f 100644 --- a/emu/cores/scd_pcm.c +++ b/emu/cores/scd_pcm.c @@ -56,6 +56,7 @@ DEV_DEF devDef_RF5C68_Gens = SCD_PCM_SetMuteMask, NULL, // SetPanning NULL, // SetSampleRateChangeCallback + NULL, // SetLoggingCallback NULL, // LinkDevice devFunc, // rwFuncs diff --git a/emu/cores/scsp.c b/emu/cores/scsp.c index 5c3f0451..d99f14d7 100644 --- a/emu/cores/scsp.c +++ b/emu/cores/scsp.c @@ -39,6 +39,7 @@ #include "../EmuCores.h" #include "../snddef.h" #include "../EmuHelper.h" +#include "../logging.h" #include "scsp.h" #include "scspdsp.h" @@ -61,6 +62,7 @@ static UINT8 scsp_midi_out_r(void* info, UINT8 offset); static void scsp_write_ram(void* info, UINT32 offset, UINT32 length, const UINT8* data); static void scsp_set_mute_mask(void* info, UINT32 MuteMask); static void scsp_set_options(void* info, UINT32 Flags); +static void scsp_set_log_cb(void* info, DEVCB_LOG func, void* param); static DEVDEF_RWFUNC devFunc[] = @@ -86,6 +88,7 @@ static DEV_DEF devDef = scsp_set_mute_mask, NULL, // SetPanning NULL, // SetSampleRateChangeCallback + scsp_set_log_cb, // SetLoggingCallback NULL, // LinkDevice devFunc, // rwFuncs @@ -248,6 +251,7 @@ typedef struct _scsp_state scsp_state; struct _scsp_state { DEV_DATA _devData; + DEV_LOGGER logger; //int m_roffset; /* offset in the region */ //devcb_write8 m_irq_cb; /* irq callback */ @@ -892,7 +896,7 @@ static UINT16 SCSP_r16(void* info, UINT16 addr) @todo Kyuutenkai reads from 0xee0/0xee2, it's tied with EXTS register(s) also used for CD-Rom Player equalizer. This port is actually an external parallel port, directly connected from the CD Block device, hence code is a bit of an hack. */ - logerror("SCSP: Reading from EXTS register %08x\n",addr); + emu_logf(&scsp->logger, DEVLOG_DEBUG, "Reading from EXTS register %08x\n",addr); if(addr<0xEE4) v = *((UINT16 *) (scsp->DSP.EXTS+(addr-0xee0)/2)); } @@ -914,7 +918,7 @@ INLINE INT32 SCSP_UpdateSlot(scsp_state *scsp, SCSP_SLOT *slot) if (SSCTL(slot) == 3) // manual says cannot be used { - logerror("SCSP: Invaild SSCTL setting at slot %02x\n", slot->slot); + emu_logf(&scsp->logger, DEVLOG_WARN, "Invaild SSCTL setting at slot %02x\n", slot->slot); return 0; } @@ -1310,3 +1314,10 @@ static void scsp_set_options(void* info, UINT32 Flags) return; } + +static void scsp_set_log_cb(void* info, DEVCB_LOG func, void* param) +{ + scsp_state *scsp = (scsp_state *)info; + dev_logger_set(&scsp->logger, scsp, func, param); + return; +} diff --git a/emu/cores/segapcm.c b/emu/cores/segapcm.c index b1f04676..aeb1e28c 100644 --- a/emu/cores/segapcm.c +++ b/emu/cores/segapcm.c @@ -54,6 +54,7 @@ static DEV_DEF devDef = segapcm_set_mute_mask, NULL, // SetPanning NULL, // SetSampleRateChangeCallback + NULL, // SetLoggingCallback NULL, // LinkDevice devFunc, // rwFuncs diff --git a/emu/cores/sn76489.c b/emu/cores/sn76489.c index c13e5f39..fad2d52d 100644 --- a/emu/cores/sn76489.c +++ b/emu/cores/sn76489.c @@ -54,6 +54,7 @@ DEV_DEF devDef_SN76489_Maxim = (DEVFUNC_OPTMASK)sn76489_mute_maxim, (DEVFUNC_PANALL)sn76489_pan_maxim, NULL, // SetSampleRateChangeCallback + NULL, // SetLoggingCallback NULL, // LinkDevice devFunc, // rwFuncs diff --git a/emu/cores/sn76496.c b/emu/cores/sn76496.c index e2ca6863..2ca88a43 100644 --- a/emu/cores/sn76496.c +++ b/emu/cores/sn76496.c @@ -144,6 +144,7 @@ #include "../EmuStructs.h" #include "../EmuCores.h" #include "../EmuHelper.h" +#include "../logging.h" #include "sn764intf.h" #include "sn76496.h" @@ -158,6 +159,7 @@ static void sn76496_shutdown(void *chip); static void sn76496_reset(void *chip); static void sn76496_freq_limiter(void* chip, UINT32 sample_rate); static void sn76496_set_mute_mask(void *chip, UINT32 MuteMask); +static void sn76496_set_log_cb(void *info, DEVCB_LOG func, void* param); static UINT8 device_start_sn76496_mame(const SN76496_CFG* cfg, DEV_INFO* retDevInf); static void sn76496_w_mame(void *chip, UINT8 reg, UINT8 data); @@ -182,6 +184,7 @@ DEV_DEF devDef_SN76496_MAME = sn76496_set_mute_mask, NULL, // SetPanning NULL, // SetSampleRateChangeCallback + sn76496_set_log_cb, // SetLoggingCallback NULL, // LinkDevice devFunc, // rwFuncs @@ -195,6 +198,7 @@ typedef struct _sn76496_state sn76496_state; struct _sn76496_state { DEV_DATA _devData; + DEV_LOGGER logger; SN76496_CFG cfg; UINT32 clock; @@ -238,7 +242,7 @@ static void sn76496_stereo_w(void *chip, UINT8 offset, UINT8 data) { sn76496_state *R = (sn76496_state*)chip; if (R->stereo) R->stereo_mask = data; - else logerror("sn76496_base_device: Call to stereo write with mono chip!\n"); + else emu_logf(&R->logger, DEVLOG_WARN, "Call to stereo write with mono chip!\n"); } static void sn76496_write_reg(void *chip, UINT8 offset, UINT8 data) @@ -288,7 +292,7 @@ static void sn76496_write_reg(void *chip, UINT8 offset, UINT8 data) break; case 6: // noise: frequency, mode { - //if ((data & 0x80) == 0) logerror("sn76496_base_device: write to reg 6 with bit 7 clear; data was %03x, new write is %02x! report this to LN!\n", R->Register[6], data); + //if ((data & 0x80) == 0) emu_logf(&R->logger, DEVLOG_DEBUG, "write to reg 6 with bit 7 clear; data was %03x, new write is %02x! report this to LN!\n", R->Register[6], data); if ((data & 0x80) == 0) R->Register[r] = (R->Register[r] & 0x3f0) | (data & 0x0f); n = R->Register[6]&3; // N/512,N/1024,N/2048,Tone #3 output @@ -609,6 +613,13 @@ static void sn76496_set_mute_mask(void *chip, UINT32 MuteMask) return; } +static void sn76496_set_log_cb(void *chip, DEVCB_LOG func, void* param) +{ + sn76496_state *R = (sn76496_state*)chip; + dev_logger_set(&R->logger, R, func, param); + return; +} + static UINT8 device_start_sn76496_mame(const SN76496_CFG* cfg, DEV_INFO* retDevInf) { sn76496_state* chip; diff --git a/emu/cores/upd7759.c b/emu/cores/upd7759.c index 09ebc3b7..967b906a 100644 --- a/emu/cores/upd7759.c +++ b/emu/cores/upd7759.c @@ -131,6 +131,7 @@ #include "../snddef.h" #include "../EmuHelper.h" #include "../EmuCores.h" +#include "../logging.h" #include "upd7759.h" @@ -155,6 +156,7 @@ static void upd7759_alloc_rom(void* info, UINT32 memsize); static void upd7759_write_rom(void* info, UINT32 offset, UINT32 length, const UINT8* data); static void upd7759_set_mute_mask(void *info, UINT32 MuteMask); +static void upd7759_set_log_cb(void* info, DEVCB_LOG func, void* param); static DEVDEF_RWFUNC devFunc[] = @@ -179,6 +181,7 @@ static DEV_DEF devDef = upd7759_set_mute_mask, NULL, // SetPanning NULL, // SetSampleRateChangeCallback + upd7759_set_log_cb, // SetLoggingCallback NULL, // LinkDevice devFunc, // rwFuncs @@ -203,7 +206,6 @@ const DEV_DEF* devDefList_uPD7759[] = #define DEBUG_STATES (0) -#define DEBUG_METHOD logerror @@ -248,6 +250,7 @@ typedef struct _upd7759_state upd7759_state; struct _upd7759_state { DEV_DATA _devData; + DEV_LOGGER logger; /* chip configuration */ UINT8 sample_offset_shift; /* header sample address shift (access data > 0xffff) */ @@ -367,7 +370,7 @@ static void get_fifo_data(upd7759_state *chip) { if (chip->dbuf_pos_read == chip->dbuf_pos_write) { - logerror("Warning: UPD7759 reading empty FIFO!\n"); + emu_logf(&chip->logger, DEVLOG_WARN, "reading empty FIFO!\n"); return; } @@ -400,7 +403,7 @@ static void advance_state(upd7759_state *chip) /* Start state: we begin here as soon as a sample is triggered */ case STATE_START: chip->req_sample = chip->rom ? chip->fifo_in : 0x10; - if (DEBUG_STATES) DEBUG_METHOD("UPD7759: req_sample = %02X\n", chip->req_sample); + if (DEBUG_STATES) emu_logf(&chip->logger, DEVLOG_TRACE, "req_sample = %02X\n", chip->req_sample); /* 35+ cycles after we get here, the /DRQ goes low * (first byte (number of samples in ROM) should be sent in response) @@ -416,7 +419,7 @@ static void advance_state(upd7759_state *chip) /* First request state: issue a request for the first byte */ /* The expected response will be the index of the last sample */ case STATE_FIRST_REQ: - if (DEBUG_STATES) DEBUG_METHOD("UPD7759: first data request\n"); + if (DEBUG_STATES) emu_logf(&chip->logger, DEVLOG_TRACE, "first data request\n"); chip->drq = 1; /* 44 cycles later, we will latch this value and request another byte */ @@ -428,7 +431,7 @@ static void advance_state(upd7759_state *chip) /* The second byte read will be just a dummy */ case STATE_LAST_SAMPLE: chip->last_sample = chip->rom ? chip->rom[0] : chip->fifo_in; - if (DEBUG_STATES) DEBUG_METHOD("UPD7759: last_sample = %02X, requesting dummy 1\n", chip->last_sample); + if (DEBUG_STATES) emu_logf(&chip->logger, DEVLOG_TRACE, "last_sample = %02X, requesting dummy 1\n", chip->last_sample); chip->drq = 1; /* 28 cycles later, we will latch this value and request another byte */ @@ -439,7 +442,7 @@ static void advance_state(upd7759_state *chip) /* First dummy state: ignore any data here and issue a request for the third byte */ /* The expected response will be the MSB of the sample address */ case STATE_DUMMY1: - if (DEBUG_STATES) DEBUG_METHOD("UPD7759: dummy1, requesting offset_hi\n"); + if (DEBUG_STATES) emu_logf(&chip->logger, DEVLOG_TRACE, "dummy1, requesting offset_hi\n"); chip->drq = 1; /* 32 cycles later, we will latch this value and request another byte */ @@ -451,7 +454,7 @@ static void advance_state(upd7759_state *chip) /* The expected response will be the LSB of the sample address */ case STATE_ADDR_MSB: chip->offset = (chip->rom ? chip->rom[chip->req_sample * 2 + 5] : chip->fifo_in) << (8 + chip->sample_offset_shift); - if (DEBUG_STATES) DEBUG_METHOD("UPD7759: offset_hi = %02X, requesting offset_lo\n", chip->offset >> (8 + chip->sample_offset_shift)); + if (DEBUG_STATES) emu_logf(&chip->logger, DEVLOG_TRACE, "offset_hi = %02X, requesting offset_lo\n", chip->offset >> (8 + chip->sample_offset_shift)); chip->drq = 1; /* 44 cycles later, we will latch this value and request another byte */ @@ -463,8 +466,8 @@ static void advance_state(upd7759_state *chip) /* The expected response will be just a dummy */ case STATE_ADDR_LSB: chip->offset |= (chip->rom ? chip->rom[chip->req_sample * 2 + 6] : chip->fifo_in) << chip->sample_offset_shift; - if (DEBUG_STATES) DEBUG_METHOD("UPD7759: offset_lo = %02X, requesting dummy 2\n", (chip->offset >> chip->sample_offset_shift) & 0xff); - if (chip->offset > chip->rommask) logerror("uPD7759 offset %X > rommask %X\n",chip->offset, chip->rommask); + if (DEBUG_STATES) emu_logf(&chip->logger, DEVLOG_TRACE, "offset_lo = %02X, requesting dummy 2\n", (chip->offset >> chip->sample_offset_shift) & 0xff); + if (chip->offset > chip->rommask) emu_logf(&chip->logger, DEVLOG_DEBUG, "offset %X > rommask %X\n",chip->offset, chip->rommask); chip->drq = 1; /* 36 cycles later, we will latch this value and request another byte */ @@ -477,7 +480,7 @@ static void advance_state(upd7759_state *chip) case STATE_DUMMY2: chip->offset++; chip->first_valid_header = 0; - if (DEBUG_STATES) DEBUG_METHOD("UPD7759: dummy2, requesting block header\n"); + if (DEBUG_STATES) emu_logf(&chip->logger, DEVLOG_TRACE, "dummy2, requesting block header\n"); chip->drq = 1; /* 36?? cycles later, we will latch this value and request another byte */ @@ -495,7 +498,7 @@ static void advance_state(upd7759_state *chip) chip->offset = chip->repeat_offset; } chip->block_header = chip->rom ? chip->rom[chip->offset++ & chip->rommask] : chip->fifo_in; - if (DEBUG_STATES) DEBUG_METHOD("UPD7759: header (@%05X) = %02X, requesting next byte\n", chip->offset, chip->block_header); + if (DEBUG_STATES) emu_logf(&chip->logger, DEVLOG_TRACE, "header (@%05X) = %02X, requesting next byte\n", chip->offset, chip->block_header); chip->drq = 1; /* our next step depends on the top two bits */ @@ -538,7 +541,7 @@ static void advance_state(upd7759_state *chip) /* The expected response will be the first data byte */ case STATE_NIBBLE_COUNT: chip->nibbles_left = (chip->rom ? chip->rom[chip->offset++ & chip->rommask] : chip->fifo_in) + 1; - if (DEBUG_STATES) DEBUG_METHOD("UPD7759: nibble_count = %u, requesting next byte\n", (unsigned)chip->nibbles_left); + if (DEBUG_STATES) emu_logf(&chip->logger, DEVLOG_TRACE, "nibble_count = %u, requesting next byte\n", (unsigned)chip->nibbles_left); chip->drq = 1; /* 36?? cycles later, we will latch this value and request another byte */ @@ -683,7 +686,7 @@ static void upd7759_slave_update(void *ptr) advance_state(chip); // if the DRQ changed, update it - //logerror("upd7759_slave_update: DRQ %d->%d\n", olddrq, chip->drq); + //emu_logf(&chip->logger, DEVLOG_DEBUG, "slave_update: DRQ %d->%d\n", olddrq, chip->drq); if (olddrq != chip->drq && chip->drqcallback != NULL) (*chip->drqcallback)(chip, chip->drq); @@ -823,7 +826,7 @@ static void upd7759_start_w(void *info, UINT8 state) UINT8 oldstart = chip->start; chip->start = (state != 0); - //logerror("upd7759_start_w: %d->%d\n", oldstart, chip->start); + //emu_logf(&chip->logger, DEVLOG_DEBUG, "start_w: %d->%d\n", oldstart, chip->start); /* on the rising edge, if we're idle, start going, but not if we're held in reset */ if (chip->state == STATE_IDLE && !oldstart && chip->start && chip->reset) @@ -948,3 +951,10 @@ static void upd7759_set_mute_mask(void *info, UINT32 MuteMask) return; } + +static void upd7759_set_log_cb(void* info, DEVCB_LOG func, void* param) +{ + upd7759_state *chip = (upd7759_state *)info; + dev_logger_set(&chip->logger, chip, func, param); + return; +} diff --git a/emu/cores/vsu.c b/emu/cores/vsu.c index c5dd3398..331db155 100644 --- a/emu/cores/vsu.c +++ b/emu/cores/vsu.c @@ -57,6 +57,7 @@ static DEV_DEF devDef = vsu_set_mute_mask, NULL, // SetPanning NULL, // SetSampleRateChangeCallback + NULL, // SetLoggingCallback NULL, // LinkDevice devFunc, // rwFuncs diff --git a/emu/cores/ws_audio.c b/emu/cores/ws_audio.c index dc5bf39b..244f4ab8 100644 --- a/emu/cores/ws_audio.c +++ b/emu/cores/ws_audio.c @@ -50,6 +50,7 @@ static DEV_DEF devDef = ws_set_mute_mask, NULL, // SetPanning NULL, // SetSampleRateChangeCallback + NULL, // SetLoggingCallback NULL, // LinkDevice devFunc, // rwFuncs diff --git a/emu/cores/x1_010.c b/emu/cores/x1_010.c index b1cf816a..40a4341b 100644 --- a/emu/cores/x1_010.c +++ b/emu/cores/x1_010.c @@ -61,6 +61,7 @@ #include "../EmuCores.h" #include "../snddef.h" #include "../EmuHelper.h" +#include "../logging.h" #include "x1_010.h" @@ -76,6 +77,7 @@ static void x1_010_alloc_rom(void* info, UINT32 memsize); static void x1_010_write_rom(void *chip, UINT32 offset, UINT32 length, const UINT8* data); static void x1_010_set_mute_mask(void *chip, UINT32 MuteMask); +static void x1_010_set_log_cb(void *chip, DEVCB_LOG func, void* param); static DEVDEF_RWFUNC devFunc[] = @@ -100,6 +102,7 @@ static DEV_DEF devDef = x1_010_set_mute_mask, NULL, // SetPanning NULL, // SetSampleRateChangeCallback + x1_010_set_log_cb, // SetLoggingCallback NULL, // LinkDevice devFunc, // rwFuncs @@ -116,7 +119,7 @@ const DEV_DEF* devDefList_X1_010[] = #define VERBOSE_REGISTER_WRITE 0 #define VERBOSE_REGISTER_READ 0 -#define LOG_SOUND(x) do { if (VERBOSE_SOUND) logerror x; } while (0) +//#define LOG_SOUND(x) do { if (VERBOSE_SOUND) logerror x; } while (0) #define LOG_REGISTER_WRITE(x) do { if (VERBOSE_REGISTER_WRITE) logerror x; } while (0) #define LOG_REGISTER_READ(x) do { if (VERBOSE_REGISTER_READ) logerror x; } while (0) @@ -142,6 +145,7 @@ typedef struct _x1_010_state x1_010_state; struct _x1_010_state { DEV_DATA _devData; + DEV_LOGGER logger; /* Variables only used here */ UINT32 ROMSize; @@ -200,9 +204,9 @@ static void seta_update(void *param, UINT32 samples, DEV_SMPL **outputs) if( freq == 0 ) freq = 4; smp_step = (UINT32)((float)info->base_clock/8192.0f *freq*(1<rate+0.5f); - if( smp_offs == 0 ) { - LOG_SOUND(( "Play sample %p - %p, channel %X volume %d:%d freq %X step %X offset %X\n", - start, end, ch, volL, volR, freq, smp_step, smp_offs )); + if( smp_offs == 0 && VERBOSE_SOUND ) { + emu_logf(&info->logger, DEVLOG_TRACE, "Play sample %p - %p, channel %X volume %d:%d freq %X step %X offset %X\n", + start, end, ch, volL, volR, freq, smp_step, smp_offs ); } for( i = 0; i < samples; i++ ) { delta = smp_offs>>FREQ_BASE_BITS; @@ -227,9 +231,9 @@ static void seta_update(void *param, UINT32 samples, DEV_SMPL **outputs) env_offs = info->env_offset[ch]; env_step = (UINT32)((float)info->base_clock/128.0/1024.0/4.0*reg->start*(1<rate+0.5f); /* Print some more debug info */ - if( smp_offs == 0 ) { - LOG_SOUND(( "Play waveform %X, channel %X volume %X freq %4X step %X offset %X\n", - reg->volume, ch, reg->end, freq, smp_step, smp_offs )); + if( smp_offs == 0 && VERBOSE_SOUND ) { + emu_logf(&info->logger, DEVLOG_TRACE, "Play waveform %X, channel %X volume %X freq %4X step %X offset %X\n", + reg->volume, ch, reg->end, freq, smp_step, smp_offs ); } for( i = 0; i < samples; i++ ) { int vol; @@ -378,3 +382,10 @@ static void x1_010_set_mute_mask(void *chip, UINT32 MuteMask) return; } + +static void x1_010_set_log_cb(void *chip, DEVCB_LOG func, void* param) +{ + x1_010_state *info = (x1_010_state *)chip; + dev_logger_set(&info->logger, info, func, param); + return; +} diff --git a/emu/cores/ym2151.c b/emu/cores/ym2151.c index 1053cfc2..b46ea32a 100644 --- a/emu/cores/ym2151.c +++ b/emu/cores/ym2151.c @@ -80,6 +80,7 @@ DEV_DEF devDef_YM2151_MAME = ym2151_set_mute_mask, NULL, // SetPanning NULL, // SetSampleRateChangeCallback + NULL, // SetLoggingCallback NULL, // LinkDevice devFunc_MAME, // rwFuncs diff --git a/emu/cores/ym2413.c b/emu/cores/ym2413.c index 72c99815..8a684fe1 100644 --- a/emu/cores/ym2413.c +++ b/emu/cores/ym2413.c @@ -90,6 +90,7 @@ DEV_DEF devDef_YM2413_MAME = ym2413_set_mute_mask, NULL, // SetPanning NULL, // SetSampleRateChangeCallback + NULL, // SetLoggingCallback NULL, // LinkDevice devFunc, // rwFuncs diff --git a/emu/cores/ym2612.c b/emu/cores/ym2612.c index 07a4fdf7..2fdab93b 100644 --- a/emu/cores/ym2612.c +++ b/emu/cores/ym2612.c @@ -44,6 +44,10 @@ #define YM_DEBUG_LEVEL 0 +#if YM_DEBUG_LEVEL > 0 +#include +#endif + #ifndef M_PI #define M_PI 3.14159265358979323846 #endif diff --git a/emu/cores/ymdeltat.c b/emu/cores/ymdeltat.c index ed775b10..45f4ca9e 100644 --- a/emu/cores/ymdeltat.c +++ b/emu/cores/ymdeltat.c @@ -66,6 +66,7 @@ #include "../../stdtype.h" #include "../snddef.h" #include "../EmuHelper.h" +#include "../logging.h" #include "ymdeltat.h" #define YM_DELTAT_DELTA_MAX (24576) @@ -93,7 +94,7 @@ static const INT32 ym_deltat_decode_tableB2[16] = { #if 0 void YM_DELTAT_BRDY_callback(YM_DELTAT *DELTAT) { - logerror("BRDY_callback reached (flag set) !\n"); + emu_logf(DELTAT->logger, DEVLOG_TRACE, "BRDY_callback reached (flag set) !\n"); /* set BRDY bit in status register */ if(DELTAT->status_set_handler != NULL && DELTAT->status_change_BRDY_bit) @@ -121,7 +122,7 @@ UINT8 YM_DELTAT_ADPCM_Read(YM_DELTAT *DELTAT) { v = DELTAT->memory[(DELTAT->now_addr>>1)&DELTAT->memory_mask]; - /*logerror("YM Delta-T memory read $%08x, v=$%02x\n", DELTAT->now_addr >> 1, v);*/ + /*emu_logf(DELTAT->logger, DEVLOG_TRACE, "YM Delta-T memory read $%08x, v=$%02x\n", DELTAT->now_addr >> 1, v);*/ DELTAT->now_addr+=2; /* two nibbles at a time */ @@ -215,8 +216,10 @@ value: START, REC, MEMDAT, REPEAT, SPOFF, x,x,RESET meaning: DELTAT->adpcmd = YM_DELTAT_DELTA_DEF; DELTAT->now_data = 0; if (DELTAT->start > DELTAT->end) - //logerror("DeltaT-Warning: Start: %06X, End: %06X\n", DELTAT->start, DELTAT->end); - logerror("DeltaT-Warning: Start: %06X, End: %06X, Limit %06X, MemMask %06X\n", DELTAT->start, DELTAT->end, DELTAT->limit, DELTAT->memory_mask); + { + emu_logf(DELTAT->logger, DEVLOG_WARN, "DeltaT: Start: %06X, End: %06X, Limit %06X, MemMask %06X\n", + DELTAT->start, DELTAT->end, DELTAT->limit, DELTAT->memory_mask); + } } if( DELTAT->portstate&0x20 ) /* do we access external memory? */ @@ -227,7 +230,7 @@ value: START, REC, MEMDAT, REPEAT, SPOFF, x,x,RESET meaning: /* if yes, then let's check if ADPCM memory is mapped and big enough */ if(DELTAT->memory == NULL) { - logerror("YM Delta-T ADPCM rom not mapped\n"); + emu_logf(DELTAT->logger, DEVLOG_WARN, "Delta-T ADPCM rom not mapped\n"); DELTAT->portstate = 0x00; DELTAT->PCM_BSY = 0; } @@ -235,13 +238,12 @@ value: START, REC, MEMDAT, REPEAT, SPOFF, x,x,RESET meaning: { if( (DELTAT->end & DELTAT->memory_mask) >= DELTAT->memory_size ) /* Check End in Range */ { - //logerror("YM Delta-T ADPCM end out of range: $%08x\n", DELTAT->end); - logerror("YM Delta-T ADPCM end out of range: %06X >= %06X\n", DELTAT->end, DELTAT->memory_size); + emu_logf(DELTAT->logger, DEVLOG_DEBUG, "Delta-T ADPCM end out of range: %06X >= %06X\n", DELTAT->end, DELTAT->memory_size); DELTAT->end = (DELTAT->end & ~DELTAT->memory_mask) | (DELTAT->memory_size - 1); } if( (DELTAT->start & DELTAT->memory_mask) >= DELTAT->memory_size ) /* Check Start in Range */ { - logerror("YM Delta-T ADPCM start out of range: $%08x\n", DELTAT->start); + emu_logf(DELTAT->logger, DEVLOG_DEBUG, "Delta-T ADPCM start out of range: $%08x\n", DELTAT->start); DELTAT->portstate = 0x00; DELTAT->PCM_BSY = 0; } @@ -302,13 +304,13 @@ value: START, REC, MEMDAT, REPEAT, SPOFF, x,x,RESET meaning: case 0x02: /* Start Address L */ case 0x03: /* Start Address H */ DELTAT->start = (DELTAT->reg[0x3]*0x0100 | DELTAT->reg[0x2]) << DELTAT->now_portshift; - /*logerror("DELTAT start: 02=%2x 03=%2x addr=%8x\n",DELTAT->reg[0x2], DELTAT->reg[0x3],DELTAT->start );*/ + /*emu_logf(DELTAT->logger, DEVLOG_DEBUG, "DELTAT start: 02=%2x 03=%2x addr=%8x\n",DELTAT->reg[0x2], DELTAT->reg[0x3],DELTAT->start );*/ break; case 0x04: /* Stop Address L */ case 0x05: /* Stop Address H */ DELTAT->end = (DELTAT->reg[0x5]*0x0100 | DELTAT->reg[0x4]) << DELTAT->now_portshift; DELTAT->end |= (1 << DELTAT->now_portshift ) - 1; - /*logerror("DELTAT end : 04=%2x 05=%2x addr=%8x\n",DELTAT->reg[0x4], DELTAT->reg[0x5],DELTAT->end );*/ + /*emu_logf(DELTAT->logger, DEVLOG_DEBUG, "DELTAT end : 04=%2x 05=%2x addr=%8x\n",DELTAT->reg[0x4], DELTAT->reg[0x5],DELTAT->end );*/ break; case 0x06: /* Prescale L (ADPCM and Record frq) */ case 0x07: /* Prescale H */ @@ -337,7 +339,7 @@ value: START, REC, MEMDAT, REPEAT, SPOFF, x,x,RESET meaning: DELTAT->memread = 0; } - /*logerror("YM Delta-T memory write $%08x, v=$%02x\n", DELTAT->now_addr >> 1, v);*/ + /*emu_logf(DELTAT->logger, DEVLOG_DEBUG, "Delta-T memory write $%08x, v=$%02x\n", DELTAT->now_addr >> 1, v);*/ if ( DELTAT->now_addr != (DELTAT->end<<1) ) { @@ -383,7 +385,7 @@ value: START, REC, MEMDAT, REPEAT, SPOFF, x,x,RESET meaning: case 0x0a: /* DELTA-N H */ DELTAT->delta = (DELTAT->reg[0xa]*0x0100 | DELTAT->reg[0x9]); DELTAT->step = (UINT32)( (double)(DELTAT->delta /* *(1<<(YM_DELTAT_SHIFT-16)) */ ) * (DELTAT->freqbase) ); - /*logerror("DELTAT deltan:09=%2x 0a=%2x\n",DELTAT->reg[0x9], DELTAT->reg[0xa]);*/ + /*emu_logf(DELTAT->logger, DEVLOG_DEBUG, "DELTAT deltan:09=%2x 0a=%2x\n",DELTAT->reg[0x9], DELTAT->reg[0xa]);*/ break; case 0x0b: /* Output level control (volume, linear) */ { @@ -395,7 +397,7 @@ value: START, REC, MEMDAT, REPEAT, SPOFF, x,x,RESET meaning: * v * ((1<<23)>>8) >> 15; * v * (1<<15) >> 15; */ - /*logerror("DELTAT vol = %2x\n",v&0xff);*/ + /*emu_logf(DELTAT->logger, DEVLOG_DEBUG, "DELTAT vol = %2x\n",v&0xff);*/ if (oldvol != 0) { DELTAT->adpcml = (int)((double)DELTAT->adpcml / (double)oldvol * (double)DELTAT->volume); @@ -407,9 +409,9 @@ value: START, REC, MEMDAT, REPEAT, SPOFF, x,x,RESET meaning: { UINT32 oldLimit = DELTAT->limit; DELTAT->limit = (DELTAT->reg[0xd]*0x0100 | DELTAT->reg[0xc]) << DELTAT->now_portshift; - /*logerror("DELTAT limit: 0c=%2x 0d=%2x addr=%8x\n",DELTAT->reg[0xc], DELTAT->reg[0xd],DELTAT->limit );*/ + /*emu_logf(DELTAT->logger, DEVLOG_DEBUG, "DELTAT limit: 0c=%2x 0d=%2x addr=%8x\n",DELTAT->reg[0xc], DELTAT->reg[0xd],DELTAT->limit );*/ if (oldLimit != DELTAT->limit) - logerror("DELTAT limit: %02x=%02x addr=%06x\n",r, DELTAT->reg[r],DELTAT->limit ); + emu_logf(DELTAT->logger, DEVLOG_DEBUG, "DELTAT limit: %02x=%02x addr=%06x\n",r, DELTAT->reg[r],DELTAT->limit ); } break; } diff --git a/emu/cores/ymdeltat.h b/emu/cores/ymdeltat.h index 7674d8eb..6df12cb0 100644 --- a/emu/cores/ymdeltat.h +++ b/emu/cores/ymdeltat.h @@ -2,6 +2,7 @@ #define __YMDELTAT_H__ #include "../../stdtype.h" +#include "../logging.h" #define YM_DELTAT_SHIFT (16) @@ -14,6 +15,7 @@ typedef void (*STATUS_CHANGE_HANDLER)(void *chip, UINT8 status_bits); /* DELTA-T (adpcm type B) struct */ typedef struct deltat_adpcm_state { /* AT: rearranged and tightened structure */ + DEV_LOGGER* logger; UINT8 *memory; INT32 *output_pointer;/* pointer of output pointers */ INT32 *pan; /* pan : &output_pointer[pan] */ diff --git a/emu/cores/ymf262.c b/emu/cores/ymf262.c index 270aa8ba..b7e74ea1 100644 --- a/emu/cores/ymf262.c +++ b/emu/cores/ymf262.c @@ -64,6 +64,7 @@ differences between OPL2 and OPL3 shown in datasheets: #include "../../stdtype.h" #include "../snddef.h" #include "../EmuHelper.h" +#include "../logging.h" #include "ymf262.h" #ifdef _MSC_VER @@ -191,6 +192,7 @@ typedef struct typedef struct { DEV_DATA _devData; + DEV_LOGGER logger; OPL3_CH P_CH[18]; /* OPL3 chips have 18 channels */ @@ -1658,7 +1660,7 @@ static void OPL3WriteReg(OPL3 *chip, int r, int v) default: if (r < 0x120) - logerror("YMF262: write to unknown register (set#2): %03x value=%02x\n",r,v); + emu_logf(&chip->logger, DEVLOG_DEBUG, "write to unknown register (set#2): %03x value=%02x\n",r,v); break; } @@ -1718,7 +1720,7 @@ static void OPL3WriteReg(OPL3 *chip, int r, int v) break; default: - logerror("YMF262: write to unknown register: %02x value=%02x\n",r,v); + emu_logf(&chip->logger, DEVLOG_DEBUG, "write to unknown register: %02x value=%02x\n",r,v); break; } break; @@ -2624,3 +2626,10 @@ void ymf262_update_one(void *_chip, UINT32 length, DEV_SMPL **buffers) } } + +void ymf262_set_log_cb(void* chip, DEVCB_LOG func, void* param) +{ + OPL3 *opl3 = (OPL3 *)chip; + dev_logger_set(&opl3->logger, opl3, func, param); + return; +} diff --git a/emu/cores/ymf262.h b/emu/cores/ymf262.h index 18204da3..77270cc9 100644 --- a/emu/cores/ymf262.h +++ b/emu/cores/ymf262.h @@ -23,5 +23,6 @@ void ymf262_set_update_handler(void *chip, OPL3_UPDATEHANDLER UpdateHandler, voi void ymf262_set_mute_mask(void *chip, UINT32 MuteMask); void ymf262_set_volume(void *chip, INT32 volume); void ymf262_set_vol_lr(void *chip, INT32 volLeft, INT32 volRight); +void ymf262_set_log_cb(void* chip, DEVCB_LOG func, void* param); #endif // __YMF262_H__ diff --git a/emu/cores/ymf271.c b/emu/cores/ymf271.c index b0df0e8f..779f5df1 100644 --- a/emu/cores/ymf271.c +++ b/emu/cores/ymf271.c @@ -34,6 +34,7 @@ #include "../EmuCores.h" #include "../snddef.h" #include "../EmuHelper.h" +#include "../logging.h" #include "ymf271.h" #ifdef _MSC_VER @@ -52,6 +53,7 @@ static void ymf271_alloc_rom(void* info, UINT32 memsize); static void ymf271_write_rom(void *info, UINT32 offset, UINT32 length, const UINT8* data); static void ymf271_set_mute_mask(void *info, UINT32 MuteMask); +static void ymf271_set_log_cb(void *info, DEVCB_LOG func, void* param); static DEVDEF_RWFUNC devFunc[] = @@ -76,6 +78,7 @@ static DEV_DEF devDef = ymf271_set_mute_mask, NULL, // SetPanning NULL, // SetSampleRateChangeCallback + ymf271_set_log_cb, // SetLoggingCallback NULL, // LinkDevice devFunc, // rwFuncs @@ -326,6 +329,7 @@ typedef struct typedef struct { DEV_DATA _devData; + DEV_LOGGER logger; // lookup tables INT16 *lut_waves[8]; @@ -641,7 +645,9 @@ static void update_pcm(YMF271Chip *chip, int slotnum, INT32 *mixp, UINT32 length if (slot->waveform != 7) { - logerror("Waveform %d in update_pcm !!!\n", slot->waveform); +#ifdef _DEBUG // include only in Debug mode, as this may spam a lot + emu_logf(&chip->logger, DEVLOG_DEBUG, "Waveform %d in update_pcm !!!\n", slot->waveform); +#endif } for (i = 0; i < length; i++) @@ -766,7 +772,7 @@ static void ymf271_update(void *info, UINT32 samples, DEV_SMPL** outputs) if (slot_group->pfm && slot_group->sync != 3) { //popmessage("ymf271 PFM, contact MAMEdev"); - logerror("ymf271 Group %d: PFM, Sync = %d, Waveform Slot1 = %d, Slot2 = %d, Slot3 = %d, Slot4 = %d\n", + emu_logf(&chip->logger, DEVLOG_WARN, "ymf271 Group %d: PFM, Sync = %d, Waveform Slot1 = %d, Slot2 = %d, Slot3 = %d, Slot4 = %d\n", j, slot_group->sync, chip->slots[j+0].waveform, chip->slots[j+12].waveform, chip->slots[j+24].waveform, chip->slots[j+36].waveform); } @@ -1308,7 +1314,7 @@ static void ymf271_write_fm(YMF271Chip *chip, int bank, UINT8 address, UINT8 dat if (groupnum == -1) { - logerror("ymf271_write_fm invalid group %02X %02X\n", address, data); + emu_logf(&chip->logger, DEVLOG_DEBUG, "ymf271_write_fm invalid group %02X %02X\n", address, data); return; } @@ -1405,7 +1411,7 @@ static void ymf271_write_pcm(YMF271Chip *chip, UINT8 address, UINT8 data) YMF271Slot *slot; if (slotnum == -1) { - logerror("ymf271_write_pcm invalid slot %02X %02X\n", address, data); + emu_logf(&chip->logger, DEVLOG_DEBUG, "ymf271_write_pcm invalid slot %02X %02X\n", address, data); return; } slot = &chip->slots[slotnum]; @@ -1522,7 +1528,7 @@ static void ymf271_write_timer(YMF271Chip *chip, UINT8 address, UINT8 data) YMF271Group *group; if (groupnum == -1) { - logerror("ymf271_write_timer invalid group %02X %02X\n", address, data); + emu_logf(&chip->logger, DEVLOG_DEBUG, "ymf271_write_timer invalid group %02X %02X\n", address, data); return; } group = &chip->groups[groupnum]; @@ -1930,7 +1936,7 @@ static void ymf271_write_rom(void *info, UINT32 offset, UINT32 length, const UIN return; } -void ymf271_set_mute_mask(void *info, UINT32 MuteMask) +static void ymf271_set_mute_mask(void *info, UINT32 MuteMask) { YMF271Chip *chip = (YMF271Chip *)info; UINT8 CurChn; @@ -1940,3 +1946,10 @@ void ymf271_set_mute_mask(void *info, UINT32 MuteMask) return; } + +static void ymf271_set_log_cb(void *info, DEVCB_LOG func, void* param) +{ + YMF271Chip *chip = (YMF271Chip *)info; + dev_logger_set(&chip->logger, chip, func, param); + return; +} diff --git a/emu/cores/ymf278b.c b/emu/cores/ymf278b.c index 8410a714..a705714d 100644 --- a/emu/cores/ymf278b.c +++ b/emu/cores/ymf278b.c @@ -104,6 +104,7 @@ #include "../SoundDevs.h" #include "../SoundEmu.h" #include "../EmuHelper.h" +#include "../logging.h" #include "ymf278b.h" @@ -127,6 +128,7 @@ static void ymf278b_write_rom(void *info, UINT32 offset, UINT32 length, const UI static void ymf278b_write_ram(void *info, UINT32 offset, UINT32 length, const UINT8* data); static void ymf278b_set_mute_mask(void *info, UINT32 MuteMask); +static void ymf278b_set_log_cb(void *info, DEVCB_LOG func, void* param); static DEVDEF_RWFUNC devFunc[] = @@ -153,6 +155,7 @@ static DEV_DEF devDef = ymf278b_set_mute_mask, NULL, // SetPanning NULL, // SetSampleRateChangeCallback + ymf278b_set_log_cb, // SetLoggingCallback device_ymf278b_link_opl3, // LinkDevice devFunc, // rwFuncs @@ -218,6 +221,7 @@ typedef struct struct _YMF278BChip { DEV_DATA _devData; + DEV_LOGGER logger; YMF278BSlot slots[24]; @@ -883,7 +887,7 @@ static void ymf278b_A_w(YMF278BChip *chip, UINT8 reg, UINT8 data) ymf278b_irq_check(chip);*/ break; default: -// logerror("YMF278B: Port A write %02x, %02x\n", reg, data); +// emu_logf(&chip->logger, DEVLOG_DEBUG, "Port A write %02x, %02x\n", reg, data); break; } } @@ -1176,7 +1180,7 @@ static UINT8 ymf278b_r(void *info, UINT8 offset) break; default: - logerror("YMF278B: unexpected read at offset %X from ymf278b\n", offset); + emu_logf(&chip->logger, DEVLOG_DEBUG, "unexpected read at offset %X from ymf278b\n", offset); break; } @@ -1219,7 +1223,7 @@ static void ymf278b_w(void *info, UINT8 offset, UINT8 data) break; default: - logerror("YMF278B: unexpected write at offset %X to ymf278b = %02X\n", offset, data); + emu_logf(&chip->logger, DEVLOG_DEBUG, "unexpected write at offset %X to ymf278b = %02X\n", offset, data); break; } } @@ -1491,7 +1495,7 @@ static void device_reset_ymf278b(void *info) refresh_opl3_volume(chip); } -static UINT8 get_opl3_funcs(const DEV_DEF* devDef, OPL3FM* retFuncs) +static UINT8 get_opl3_funcs(const DEV_DEF* devDef, OPL3FM* retFuncs, DEV_LOGGER* logger) { UINT8 retVal; @@ -1503,7 +1507,7 @@ static UINT8 get_opl3_funcs(const DEV_DEF* devDef, OPL3FM* retFuncs) if (retVal) { retFuncs->setVol = NULL; - logerror("YMF278B Warning: Unable to control OPL3 volume.\n"); + emu_logf(logger, DEVLOG_WARN, "Unable to control OPL3 volume.\n"); } if (devDef->Reset == NULL) @@ -1530,7 +1534,7 @@ static UINT8 device_ymf278b_link_opl3(void* param, UINT8 devID, const DEV_INFO* } else { - retVal = get_opl3_funcs(defInfOPL3->devDef, &chip->fm); + retVal = get_opl3_funcs(defInfOPL3->devDef, &chip->fm, &chip->logger); if (! retVal) chip->fm.chip = defInfOPL3->dataPtr; refresh_opl3_volume(chip); @@ -1605,3 +1609,10 @@ static void ymf278b_set_mute_mask(void *info, UINT32 MuteMask) return; } + +static void ymf278b_set_log_cb(void *info, DEVCB_LOG func, void* param) +{ + YMF278BChip *chip = (YMF278BChip *)info; + dev_logger_set(&chip->logger, chip, func, param); + return; +} diff --git a/emu/cores/ymz280b.c b/emu/cores/ymz280b.c index 522be0fc..17a725a6 100644 --- a/emu/cores/ymz280b.c +++ b/emu/cores/ymz280b.c @@ -39,6 +39,7 @@ #include "../EmuCores.h" #include "../snddef.h" #include "../EmuHelper.h" +#include "../logging.h" #include "ymz280b.h" static void update_irq_state_timer_common(void *param, int voicenum); @@ -53,6 +54,7 @@ static void ymz280b_alloc_rom(void* info, UINT32 memsize); static void ymz280b_write_rom(void *info, UINT32 offset, UINT32 length, const UINT8* data); static void ymz280b_set_mute_mask(void *info, UINT32 MuteMask); +static void ymz280b_set_log_cb(void *info, DEVCB_LOG func, void* param); static DEVDEF_RWFUNC devFunc[] = @@ -77,6 +79,7 @@ static DEV_DEF devDef = ymz280b_set_mute_mask, NULL, // SetPanning NULL, // SetSampleRateChangeCallback + ymz280b_set_log_cb, // SetLoggingCallback NULL, // LinkDevice devFunc, // rwFuncs @@ -140,6 +143,7 @@ typedef struct _ymz280b_state ymz280b_state; struct _ymz280b_state { DEV_DATA _devData; + DEV_LOGGER logger; struct YMZ280BVoice voice[8]; /* the 8 voices */ UINT8 current_register; /* currently accessible register */ @@ -208,14 +212,14 @@ INLINE void update_irq_state(ymz280b_state *chip) chip->irq_state = 1; if (chip->irq_handler != NULL) chip->irq_handler(chip->irq_param, 1); - //else logerror("YMZ280B: IRQ generated, but no callback specified!"); + //else emu_logf(&chip->logger, DEVLOG_TRACE, "IRQ generated, but no callback specified!"); } else if (!irq_bits && chip->irq_state) { chip->irq_state = 0; if (chip->irq_handler != NULL) chip->irq_handler(chip->irq_param, 0); - //else logerror("YMZ280B: IRQ generated, but no callback specified!"); + //else emu_logf(&chip->logger, DEVLOG_TRACE, "IRQ generated, but no callback specified!"); } } @@ -889,7 +893,7 @@ static void write_to_register(ymz280b_state *chip, UINT8 data) break; default: - logerror("YMZ280B: unknown register write %02X = %02X\n", chip->current_register, data); + emu_logf(&chip->logger, DEVLOG_DEBUG, "unknown register write %02X = %02X\n", chip->current_register, data); break; } } @@ -903,7 +907,7 @@ static void write_to_register(ymz280b_state *chip, UINT8 data) case 0x80: // d0-2: DSP Rch, d3: enable Rch (0: yes, 1: no), d4-6: DSP Lch, d7: enable Lch (0: yes, 1: no) case 0x81: // d0: enable control of $82 (0: yes, 1: no) case 0x82: // DSP data - logerror("YMZ280B: DSP register write %02X = %02X\n", chip->current_register, data); + emu_logf(&chip->logger, DEVLOG_DEBUG, "DSP register write %02X = %02X\n", chip->current_register, data); break; case 0x84: /* ROM readback / RAM write (high) */ @@ -926,7 +930,7 @@ static void write_to_register(ymz280b_state *chip, UINT8 data) if (chip->ext_write_handler != NULL) chip->ext_write_handler(chip->ext_param, chip->ext_mem_address, data); //else - // logerror("YMZ280B attempted RAM write to %X\n", chip->ext_mem_address); + // emu_logf(&chip->logger, DEVLOG_TRACE, "attempted RAM write to %X\n", chip->ext_mem_address); chip->ext_mem_address = (chip->ext_mem_address + 1) & 0xffffff; } break; @@ -963,7 +967,7 @@ static void write_to_register(ymz280b_state *chip, UINT8 data) break; default: - logerror("YMZ280B: unknown register write %02X = %02X\n", chip->current_register, data); + emu_logf(&chip->logger, DEVLOG_DEBUG, "unknown register write %02X = %02X\n", chip->current_register, data); break; } } @@ -1069,3 +1073,10 @@ static void ymz280b_set_mute_mask(void *info, UINT32 MuteMask) return; } + +static void ymz280b_set_log_cb(void *info, DEVCB_LOG func, void* param) +{ + ymz280b_state *chip = (ymz280b_state *)info; + dev_logger_set(&chip->logger, chip, func, param); + return; +} diff --git a/emu/dac_control.c b/emu/dac_control.c index 91102a9f..24f3a9f4 100644 --- a/emu/dac_control.c +++ b/emu/dac_control.c @@ -39,6 +39,7 @@ static DEV_DEF devDef_DAC = NULL, NULL, // SetPanning NULL, // SetSampleRateChangeCallback + NULL, // SetLoggingCallback NULL, // LinkDevice NULL, // rwFuncs diff --git a/emu/logging.c b/emu/logging.c new file mode 100644 index 00000000..31ac2ee9 --- /dev/null +++ b/emu/logging.c @@ -0,0 +1,31 @@ +#include // for vsnprintf() +#include + +#include "../stdtype.h" +#include "logging.h" + +#ifdef _WIN32 +#define vsnprintf _vsnprintf +#endif + +#define LOGBUF_SIZE 0x100 + +// formatted logging +void emu_logf(DEV_LOGGER* logger, UINT8 level, const char* format, ...) +{ + va_list arg_list; + int retVal; + char buffer[LOGBUF_SIZE]; + + if (logger->func == NULL) + return; + + va_start(arg_list, format); + retVal = _vsnprintf(buffer, LOGBUF_SIZE, format, arg_list); + va_end(arg_list); + if (retVal < 0 || retVal >= LOGBUF_SIZE) + buffer[LOGBUF_SIZE - 1] = '\0'; // for older MSVC version and glibc <= 2.0.6 + + logger->func(logger->param, logger->source, level, buffer); + return; +} diff --git a/emu/logging.h b/emu/logging.h new file mode 100644 index 00000000..19ff65df --- /dev/null +++ b/emu/logging.h @@ -0,0 +1,30 @@ +#ifndef __EMU_LOGGING_H__ +#define __EMU_LOGGING_H__ + +#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; + void* source; + void* param; +} DEV_LOGGER; + +INLINE void dev_logger_set(DEV_LOGGER* logger, void* source, DEVCB_LOG func, void* param) +{ + logger->func = func; + logger->source = source; + logger->param = param; + return; +} + +void emu_logf(DEV_LOGGER* logger, UINT8 level, const char* format, ...); + +#endif // __EMU_LOGGING_H__ diff --git a/emu/panning.h b/emu/panning.h index 1c5fd58d..666c8a21 100644 --- a/emu/panning.h +++ b/emu/panning.h @@ -1,5 +1,5 @@ -#ifndef __PANNING_H__ -#define __PANNING_H__ +#ifndef __EMU_PANNING_H__ +#define __EMU_PANNING_H__ #ifdef __cplusplus extern "C" @@ -23,4 +23,4 @@ void Panning_Centre(INT32 channels[2]); } #endif -#endif // __PANNING_H__ +#endif // __EMU_PANNING_H__