I'm not a good C programmer and run into problems all the time. This is a difficult one. I'm not sure how to explain. I'm doing a nsf (nes sound file) decoder to xmms2 media player.
xmms2 have the following api for decoder plugins.
Code:
static gboolean xmms_nsf_can_handle (const gchar *mimetype);
static gboolean xmms_nsf_new (xmms_decoder_t *decoder, const gchar *mimetype);
static gboolean xmms_nsf_decode_block (xmms_decoder_t *decoder);
static void xmms_nsf_get_media_info (xmms_decoder_t *decoder);
static void xmms_nsf_destroy (xmms_decoder_t *decoder);
static gboolean xmms_nsf_init (xmms_decoder_t *decoder);
xmms2 can use several decoderplugins concurrently and all global variables will then be shared between the threads. There is a fix for this. All methods sends the argument decoder. It is used to get settings for the plugin. xmms_nsf_new looks something like this.
Code:
static gboolean
xmms_nsf_new (xmms_decoder_t *decoder, const gchar *mimetype)
{
xmms_nsf_data_t *data;
data = g_new0 (xmms_nsf_data_t, 1);
xmms_decoder_private_data_set (decoder, data);
}
xmms_nsf_data_t is a struct containing the data for the plugin. My xmms_nsf_data_t looks like
Code:
typedef struct xmms_nsf_data_St {
NSFHEADER *tHeader;
guint8 uCurrentTrack;
guint8 *pCPU;
guint32 uCartridgeLength;
guint32 uBankswitchingEnabled;
guint8 *pCartridge;
/* user settings */
gint8 nPan[20];
guint8 nOversample;
/* required for 6502 emulation */
guint32 dwElapsedTicks;
guint32 cyclesRemaining;
CONTEXTM6502 m6502;
gboolean inited;
} xmms_nsf_data_t;
When a method need the data is does this
Code:
static gboolean
xmms_nsf_init (xmms_decoder_t *decoder)
{
xmms_nsf_data_t *data;
data = xmms_decoder_private_data_get (decoder);
...
}
This is all well but I use a library called m6502 or make6502 to emulate the 6502 cpu in the nes. I feed it with a function pointer to a function it use to write in the virtual memory like so.
data->m6502.m6502MemoryRead = tNSFRead;
data->m6502.m6502MemoryWrite = tNSFWrite;
The problem is that I need to access my xmms_nsf_data_t in tNSFRead and tNSFWrite to check the nsf header for addon chips. M6502 does not send my xmms_decoder_t along to the read/write functions. How can I access my data?