mirror of
https://github.com/raphnet/gc_n64_usb-v3
synced 2025-01-30 14:50:10 -05:00
Use gcn64lib_n64_expansionWrite, and support abort from callback
This commit is contained in:
parent
14dab7d12d
commit
2e95867469
@ -202,7 +202,7 @@ int gcn64lib_bootloader(gcn64_hdl_t hdl)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int gcn64lib_expansionWrite(gcn64_hdl_t hdl, unsigned short addr, unsigned char data[32])
|
||||
int gcn64lib_n64_expansionWrite(gcn64_hdl_t hdl, unsigned short addr, unsigned char data[32])
|
||||
{
|
||||
unsigned char cmd[40];
|
||||
int cmdlen;
|
||||
|
@ -157,9 +157,10 @@ struct option longopts[] = {
|
||||
{ },
|
||||
};
|
||||
|
||||
static void mempak_progress_cb(int addr, void *ctx)
|
||||
static int mempak_progress_cb(int addr, void *ctx)
|
||||
{
|
||||
printf("\r%s 0x%04x / 0x%04x ", (char*)ctx, addr, MEMPAK_MEM_SIZE); fflush(stdout);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int listDevices(void)
|
||||
|
@ -133,7 +133,7 @@ int gcn64lib_mempak_detect(gcn64_hdl_t hdl)
|
||||
|
||||
printf("Init 1\n");
|
||||
memset(buf, 0xfe, 32);
|
||||
res = gcn64lib_expansionWrite(hdl, 0x8000, buf);
|
||||
res = gcn64lib_n64_expansionWrite(hdl, 0x8000, buf);
|
||||
if (res != 0xe1) {
|
||||
printf("res: %d\n", res);
|
||||
return 0;
|
||||
@ -141,7 +141,7 @@ int gcn64lib_mempak_detect(gcn64_hdl_t hdl)
|
||||
|
||||
printf("Init 2\n");
|
||||
memset(buf, 0x80, 32);
|
||||
res = gcn64lib_expansionWrite(hdl, 0x8000, buf);
|
||||
res = gcn64lib_n64_expansionWrite(hdl, 0x8000, buf);
|
||||
if (res != 0xe1) {
|
||||
printf("res: %d\n", res);
|
||||
return 0;
|
||||
@ -151,7 +151,7 @@ int gcn64lib_mempak_detect(gcn64_hdl_t hdl)
|
||||
|
||||
int gcn64lib_mempak_writeBlock(gcn64_hdl_t hdl, unsigned short addr, unsigned char data[32])
|
||||
{
|
||||
return gcn64lib_expansionWrite(hdl, __calc_address_crc(addr), data);
|
||||
return gcn64lib_n64_expansionWrite(hdl, __calc_address_crc(addr), data);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -159,10 +159,10 @@ int gcn64lib_mempak_writeBlock(gcn64_hdl_t hdl, unsigned short addr, unsigned ch
|
||||
* \param hdl The Adapter handler
|
||||
* \param channel The adapter channel (for multi-port adapters)
|
||||
* \param pak Pointer to mempak_structure pointer to store the new mempak
|
||||
* \param progressCb Callback to notify read progress (called after each block)
|
||||
* \return 0: Success, -1: No mempak, -2: IO/error, -3: Other errors
|
||||
* \param progressCb Callback to notify read progress (called after each block). The callback can return non-zero to abort.
|
||||
* \return 0: Success, -1: No mempak, -2: IO/error, -3: Other errors, -4: Aborted
|
||||
*/
|
||||
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_download(gcn64_hdl_t hdl, int channel, mempak_structure_t **mempak, int (*progressCb)(int cur_addr, void *ctx), void *ctx)
|
||||
{
|
||||
mempak_structure_t *pak;
|
||||
unsigned short addr;
|
||||
@ -189,7 +189,9 @@ int gcn64lib_mempak_download(gcn64_hdl_t hdl, int channel, mempak_structure_t **
|
||||
return -2;
|
||||
}
|
||||
if (progressCb) {
|
||||
progressCb(addr, ctx);
|
||||
if (progressCb(addr, ctx)) {
|
||||
return -4;
|
||||
}
|
||||
}
|
||||
}
|
||||
*mempak = pak;
|
||||
@ -197,7 +199,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, void *ctx), void *ctx)
|
||||
int gcn64lib_mempak_upload(gcn64_hdl_t hdl, int channel, mempak_structure_t *pak, int (*progressCb)(int cur_addr, void *ctx), void *ctx)
|
||||
{
|
||||
unsigned short addr;
|
||||
unsigned char readback[0x20];
|
||||
@ -230,7 +232,9 @@ int gcn64lib_mempak_upload(gcn64_hdl_t hdl, int channel, mempak_structure_t *pak
|
||||
}
|
||||
|
||||
if (progressCb) {
|
||||
progressCb(addr, ctx);
|
||||
if (progressCb(addr, ctx)) {
|
||||
return -4;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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, 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);
|
||||
int gcn64lib_mempak_download(gcn64_hdl_t hdl, int channel, mempak_structure_t **mempak, int (*progressCb)(int cur_addr, void *ctx), void *ctx);
|
||||
int gcn64lib_mempak_upload(gcn64_hdl_t hdl, int channel, mempak_structure_t *pak, int (*progressCb)(int cur_addr, void *ctx), void *ctx);
|
||||
|
||||
#endif // _mempak_gcn64usb_h__
|
||||
|
Loading…
Reference in New Issue
Block a user