mirror of
https://github.com/raphnet/gc_n64_usb-v3
synced 2024-11-13 20:55:03 -05:00
Add context for callbacks
This commit is contained in:
parent
e033576104
commit
5a698b7f57
13
tool/main.c
13
tool/main.c
@ -157,14 +157,9 @@ struct option longopts[] = {
|
||||
{ },
|
||||
};
|
||||
|
||||
static void mempak_read_progress_cb(int addr)
|
||||
static void mempak_progress_cb(int addr, void *ctx)
|
||||
{
|
||||
printf("\rReading address 0x%04x / 0x%04x ", addr, MEMPAK_MEM_SIZE); fflush(stdout);
|
||||
}
|
||||
|
||||
static void mempak_write_progress_cb(int addr)
|
||||
{
|
||||
printf("\rWriting address 0x%04x / 0x%04x ", addr, MEMPAK_MEM_SIZE); fflush(stdout);
|
||||
printf("\r%s 0x%04x / 0x%04x ", (char*)ctx, addr, MEMPAK_MEM_SIZE); fflush(stdout);
|
||||
}
|
||||
|
||||
static int listDevices(void)
|
||||
@ -384,7 +379,7 @@ int main(int argc, char **argv)
|
||||
int res;
|
||||
|
||||
printf("Reading mempak...\n");
|
||||
res = gcn64lib_mempak_download(hdl, 0, &pak, mempak_read_progress_cb);
|
||||
res = gcn64lib_mempak_download(hdl, 0, &pak, mempak_progress_cb, "Reading address");
|
||||
printf("\n");
|
||||
switch (res)
|
||||
{
|
||||
@ -436,7 +431,7 @@ int main(int argc, char **argv)
|
||||
}
|
||||
|
||||
printf("Writing to mempak...\n");
|
||||
res = gcn64lib_mempak_upload(hdl, 0, pak, mempak_write_progress_cb);
|
||||
res = gcn64lib_mempak_upload(hdl, 0, pak, mempak_progress_cb, "Writing address");
|
||||
printf("\n");
|
||||
if (res) {
|
||||
switch(res)
|
||||
|
@ -162,7 +162,7 @@ int gcn64lib_mempak_writeBlock(gcn64_hdl_t hdl, unsigned short addr, unsigned ch
|
||||
* \param progressCb Callback to notify read progress (called after each block)
|
||||
* \return 0: Success, -1: No mempak, -2: IO/error, -3: Other errors
|
||||
*/
|
||||
int gcn64lib_mempak_download(gcn64_hdl_t hdl, int channel, mempak_structure_t **mempak, void (*progressCb)(int cur_addr))
|
||||
int gcn64lib_mempak_download(gcn64_hdl_t hdl, int channel, mempak_structure_t **mempak, void (*progressCb)(int cur_addr, void *ctx), void *ctx)
|
||||
{
|
||||
mempak_structure_t *pak;
|
||||
unsigned short addr;
|
||||
@ -189,7 +189,7 @@ int gcn64lib_mempak_download(gcn64_hdl_t hdl, int channel, mempak_structure_t **
|
||||
return -2;
|
||||
}
|
||||
if (progressCb) {
|
||||
progressCb(addr);
|
||||
progressCb(addr, ctx);
|
||||
}
|
||||
}
|
||||
*mempak = pak;
|
||||
@ -197,7 +197,7 @@ int gcn64lib_mempak_download(gcn64_hdl_t hdl, int channel, mempak_structure_t **
|
||||
return 0;
|
||||
}
|
||||
|
||||
int gcn64lib_mempak_upload(gcn64_hdl_t hdl, int channel, mempak_structure_t *pak, void (*progressCb)(int cur_addr))
|
||||
int gcn64lib_mempak_upload(gcn64_hdl_t hdl, int channel, mempak_structure_t *pak, void (*progressCb)(int cur_addr, void *ctx), void *ctx)
|
||||
{
|
||||
unsigned short addr;
|
||||
unsigned char readback[0x20];
|
||||
@ -230,7 +230,7 @@ int gcn64lib_mempak_upload(gcn64_hdl_t hdl, int channel, mempak_structure_t *pak
|
||||
}
|
||||
|
||||
if (progressCb) {
|
||||
progressCb(addr);
|
||||
progressCb(addr, ctx);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,7 @@ int gcn64lib_mempak_detect(gcn64_hdl_t hdl);
|
||||
int gcn64lib_mempak_readBlock(gcn64_hdl_t hdl, unsigned short addr, unsigned char dst[32]);
|
||||
int gcn64lib_mempak_writeBlock(gcn64_hdl_t hdl, unsigned short addr, unsigned char data[32]);
|
||||
|
||||
int gcn64lib_mempak_download(gcn64_hdl_t hdl, int channel, mempak_structure_t **mempak, void (*progressCb)(int cur_addr));
|
||||
int gcn64lib_mempak_upload(gcn64_hdl_t hdl, int channel, mempak_structure_t *pak, void (*progressCb)(int cur_addr));
|
||||
int gcn64lib_mempak_download(gcn64_hdl_t hdl, int channel, mempak_structure_t **mempak, void (*progressCb)(int cur_addr, void *ctx), void *ctx);
|
||||
int gcn64lib_mempak_upload(gcn64_hdl_t hdl, int channel, mempak_structure_t *pak, void (*progressCb)(int cur_addr, void *ctx), void *ctx);
|
||||
|
||||
#endif // _mempak_gcn64usb_h__
|
||||
|
Loading…
Reference in New Issue
Block a user