X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=Pico%2FCart.c;h=1cf8dec79f45963c0fb0d20ef258d2fffe980315;hb=32826a1a22fd3e6203310bba855d8c2b6f3c403a;hp=a84708865fe108aabbad5d62e99999e82bdfaa6e;hpb=6cadc2da0070781cf2d8fcff84265d3ca1f423b9;p=picodrive.git diff --git a/Pico/Cart.c b/Pico/Cart.c index a847088..1cf8dec 100644 --- a/Pico/Cart.c +++ b/Pico/Cart.c @@ -15,6 +15,8 @@ static char *rom_exts[] = { "bin", "gen", "smd", "iso" }; +void (*PicoCartLoadProgressCB)(int percent) = NULL; + pm_file *pm_open(const char *path) { @@ -244,7 +246,7 @@ static unsigned char *PicoCartAlloc(int filesize) int PicoCartLoad(pm_file *f,unsigned char **prom,unsigned int *psize) { - unsigned char *rom=NULL; int size; + unsigned char *rom=NULL; int size, bytes_read; if (f==NULL) return 1; size=f->size; @@ -258,7 +260,30 @@ int PicoCartLoad(pm_file *f,unsigned char **prom,unsigned int *psize) return 1; } - pm_read(rom,size,f); // Load up the rom + if (PicoCartLoadProgressCB != NULL) + { + // read ROM in blocks, just for fun + int ret; + unsigned char *p = rom; + bytes_read=0; + do + { + int todo = size - bytes_read; + if (todo > 256*1024) todo = 256*1024; + ret = pm_read(p,todo,f); + bytes_read += ret; + p += ret; + PicoCartLoadProgressCB(bytes_read * 100 / size); + } + while (ret > 0); + } + else + bytes_read = pm_read(rom,size,f); // Load up the rom + if (bytes_read <= 0) { + printf("read failed\n"); + free(rom); + return 1; + } // maybe we are loading MegaCD BIOS? if (!(PicoMCD&1) && size == 0x20000 && (!strncmp((char *)rom+0x124, "BOOT", 4) || !strncmp((char *)rom+0x128, "BOOT", 4))) {