From a9b3ffd3cce011d42652d22f15a4a13dff29b0d7 Mon Sep 17 00:00:00 2001 From: notaz Date: Thu, 23 Aug 2007 13:24:11 +0000 Subject: [PATCH] ROM load progress bar git-svn-id: file:///home/notaz/opt/svn/PicoDrive@224 be3aeb3a-fb24-0410-a615-afba39da0efa --- Pico/Cart.c | 29 +++++++++++++++++++++++++++-- Pico/Pico.h | 1 + platform/gp2x/Makefile | 2 +- platform/gp2x/emu.c | 4 ++++ platform/gp2x/gp2x.c | 9 +++++---- platform/gp2x/menu.c | 34 +++++++++++++++++++++++++++++++++- platform/gp2x/menu.h | 2 ++ 7 files changed, 73 insertions(+), 8 deletions(-) diff --git a/Pico/Cart.c b/Pico/Cart.c index a8470886..1cf8dec7 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))) { diff --git a/Pico/Pico.h b/Pico/Pico.h index 8e5d6423..ec5148bd 100644 --- a/Pico/Pico.h +++ b/Pico/Pico.h @@ -92,6 +92,7 @@ int PicoCartInsert(unsigned char *rom,unsigned int romsize); void Byteswap(unsigned char *data,int len); // anotherguest int PicoUnloadCart(unsigned char* romdata); +extern void (*PicoCartLoadProgressCB)(int percent); // Draw.c void PicoDrawSetColorFormat(int which); // 0=BGR444, 1=RGB555, 2=8bit(HighPal pal) diff --git a/platform/gp2x/Makefile b/platform/gp2x/Makefile index d9c40bb3..489d62f3 100644 --- a/platform/gp2x/Makefile +++ b/platform/gp2x/Makefile @@ -210,7 +210,7 @@ $(error need VER) endif endif -rel: PicoDrive.gpe code940/code940.bin ../readme.txt config.txt PicoDrive.man.txt PicoDrive.png +rel: PicoDrive.gpe code940/pico940.bin ../readme.txt config.txt PicoDrive.man.txt PicoDrive.png zip -9 -j ../../PicoDrive_$(VER).zip $^ mmuhack.o code940/code940.bin: diff --git a/platform/gp2x/emu.c b/platform/gp2x/emu.c index cb924c34..bfbc0c11 100644 --- a/platform/gp2x/emu.c +++ b/platform/gp2x/emu.c @@ -287,6 +287,8 @@ int emu_ReloadRom(void) return 0; } + menu_romload_prepare(used_rom_name); + if(rom_data) { free(rom_data); rom_data = 0; @@ -297,9 +299,11 @@ int emu_ReloadRom(void) sprintf(menuErrorMsg, "PicoCartLoad() failed."); printf("%s\n", menuErrorMsg); pm_close(rom); + menu_romload_end(); return 0; } pm_close(rom); + menu_romload_end(); // detect wrong files (Pico crashes on very small files), also see if ROM EP is good if(rom_size <= 0x200 || strncmp((char *)rom_data, "Pico", 4) == 0 || diff --git a/platform/gp2x/gp2x.c b/platform/gp2x/gp2x.c index d6a701c9..c0396d9d 100644 --- a/platform/gp2x/gp2x.c +++ b/platform/gp2x/gp2x.c @@ -159,10 +159,11 @@ void gp2x_video_wait_vsync(void) void gp2x_memcpy_buffers(int buffers, void *data, int offset, int len) { - if (buffers & (1<<0)) memcpy((char *)gp2x_screens[0] + offset, data, len); - if (buffers & (1<<1)) memcpy((char *)gp2x_screens[1] + offset, data, len); - if (buffers & (1<<2)) memcpy((char *)gp2x_screens[2] + offset, data, len); - if (buffers & (1<<3)) memcpy((char *)gp2x_screens[3] + offset, data, len); + char *dst; + if (buffers & (1<<0)) { dst = (char *)gp2x_screens[0] + offset; if (dst != data) memcpy(dst, data, len); } + if (buffers & (1<<1)) { dst = (char *)gp2x_screens[1] + offset; if (dst != data) memcpy(dst, data, len); } + if (buffers & (1<<2)) { dst = (char *)gp2x_screens[2] + offset; if (dst != data) memcpy(dst, data, len); } + if (buffers & (1<<3)) { dst = (char *)gp2x_screens[3] + offset; if (dst != data) memcpy(dst, data, len); } } diff --git a/platform/gp2x/menu.c b/platform/gp2x/menu.c index 9b51d7c0..06a3e3df 100644 --- a/platform/gp2x/menu.c +++ b/platform/gp2x/menu.c @@ -420,6 +420,39 @@ static unsigned long wait_for_input_usbjoy(unsigned long interesting, int *joy) +// --------- loading ROM screen ---------- + +static void load_progress_cb(int percent) +{ + int ln, len = percent * 320 / 100; + unsigned char *dst = (unsigned char *)gp2x_screen + 320*20; + + if (len > 320) len = 320; + for (ln = 10; ln > 0; ln--, dst += 320) + memset(dst, 0xf0, len); + gp2x_video_flip2(); +} + +void menu_romload_prepare(const char *rom_name) +{ + const char *p = rom_name + strlen(rom_name); + while (p > rom_name && *p != '/') p--; + + gp2x_pd_clone_buffer2(); + gp2x_smalltext8(1, 1, "Loading"); + gp2x_smalltext8_lim(1, 10, p, 53); + gp2x_memcpy_buffers(3, gp2x_screen, 0, 320*240); + gp2x_video_flip2(); + PicoCartLoadProgressCB = load_progress_cb; +} + +void menu_romload_end(void) +{ + PicoCartLoadProgressCB = NULL; + gp2x_smalltext8(1, 30, "Starting emulation..."); + gp2x_video_flip2(); +} + // -------------- ROM selector -------------- static void draw_dirlist(char *curdir, struct dirent **namelist, int n, int sel) @@ -429,7 +462,6 @@ static void draw_dirlist(char *curdir, struct dirent **namelist, int n, int sel) start = 12 - sel; n--; // exclude current dir (".") - //memset(gp2x_screen, 0, 320*240); gp2x_pd_clone_buffer2(); if(start - 2 >= 0) diff --git a/platform/gp2x/menu.h b/platform/gp2x/menu.h index 87c51b54..8c9e29b3 100644 --- a/platform/gp2x/menu.h +++ b/platform/gp2x/menu.h @@ -10,6 +10,8 @@ void gp2x_text_out15 (int x, int y, const char *text); void gp2x_text_out8_2(int x, int y, const char *texto, int color); void menu_loop(void); int menu_loop_tray(void); +void menu_romload_prepare(const char *rom_name); +void menu_romload_end(void); #define CONFIGURABLE_KEYS \ (GP2X_UP|GP2X_DOWN|GP2X_LEFT|GP2X_RIGHT|GP2X_A|GP2X_B|GP2X_X|GP2X_Y| \ -- 2.39.5