X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=gp2x%2Femu.c;h=a90d85031c979779c94d12e772f3a4cb01dd51ef;hb=5111820c3717b5e6879a6d5d13164428230ddb50;hp=14eadeb32314383d877dcd94f0c2c0ddf0c710b8;hpb=1a20dbc8deacc0ad37a9556ada910981d6d97b50;p=libpicofe.git diff --git a/gp2x/emu.c b/gp2x/emu.c index 14eadeb..a90d850 100644 --- a/gp2x/emu.c +++ b/gp2x/emu.c @@ -55,7 +55,6 @@ static int combo_keys = 0, combo_acts = 0; // keys and actions which need button static int gp2x_old_gamma = 100; static unsigned char *movie_data = NULL; static int movie_size = 0; -int frame_count = 0; unsigned char *framebuff = 0; // temporary buffer for alt renderer int state_slot = 0; @@ -80,14 +79,15 @@ static void strlwr(char* string) while ( (*string++ = (char)tolower(*string)) ); } -static int try_rfn_ext(char *ext) +static int try_rfn_cut(void) { FILE *tmp; char *p; - p = romFileName + strlen(romFileName) - 4; - if (p < romFileName) p = romFileName; - strcpy(p, ext); + p = romFileName + strlen(romFileName) - 1; + for (; p > romFileName; p--) + if (*p == '.') break; + *p = 0; if((tmp = fopen(romFileName, "rb"))) { fclose(tmp); @@ -96,21 +96,28 @@ static int try_rfn_ext(char *ext) return 0; } +static void get_ext(char *ext) +{ + char *p; + + p = romFileName + strlen(romFileName) - 4; + if (p < romFileName) p = romFileName; + strncpy(ext, p, 4); + ext[4] = 0; + strlwr(ext); +} + int emu_ReloadRom(void) { unsigned int rom_size = 0; - char ext[5], *p; + char ext[5]; FILE *rom; int ret; printf("emu_ReloadRom(%s)\n", romFileName); - // detect wrong extensions (.srm and .mds) - p = romFileName + strlen(romFileName) - 4; - if (p < romFileName) p = romFileName; - strncpy(ext, p, 4); - ext[4] = 0; - strlwr(ext); + // detect wrong extensions + get_ext(ext); if(!strcmp(ext, ".srm") || !strcmp(ext, "s.gz") || !strcmp(ext, ".mds")) { // s.gz ~ .mds.gz sprintf(menuErrorMsg, "Not a ROM selected."); @@ -150,12 +157,12 @@ int emu_ReloadRom(void) sprintf(menuErrorMsg, "Invalid GMV file."); return 0; } - dummy = try_rfn_ext(".zip") || try_rfn_ext(".bin") || - try_rfn_ext(".smd") || try_rfn_ext(".gen"); + dummy = try_rfn_cut() || try_rfn_cut(); if (!dummy) { sprintf(menuErrorMsg, "Could't find a ROM for movie."); return 0; } + get_ext(ext); } rom = fopen(romFileName, "rb"); @@ -246,7 +253,7 @@ int emu_ReloadRom(void) if(currentConfig.EmuOpt & 1) emu_SaveLoadGame(1, 1); - frame_count = 0; + Pico.m.frame_count = 0; return 1; } @@ -616,6 +623,8 @@ static void RunEvents(unsigned int which) } if (do_it) { blit("", (which & 0x1000) ? "LOADING GAME" : "SAVING GAME"); + if(movie_data) { + } emu_SaveLoadGame(which & 0x1000, 0); } @@ -655,6 +664,35 @@ static void RunEvents(unsigned int which) } +static void updateMovie(void) +{ + int offs = Pico.m.frame_count*3 + 0x40; + if (offs+3 > movie_size) { + free(movie_data); + movie_data = 0; + strcpy(noticeMsg, "END OF MOVIE."); + printf("END OF MOVIE.\n"); + gettimeofday(¬iceMsgTime, 0); + } else { + // MXYZ SACB RLDU + PicoPad[0] = ~movie_data[offs] & 0x8f; // ! SCBA RLDU + if(!(movie_data[offs] & 0x10)) PicoPad[0] |= 0x40; // A + if(!(movie_data[offs] & 0x20)) PicoPad[0] |= 0x10; // B + if(!(movie_data[offs] & 0x40)) PicoPad[0] |= 0x20; // A + PicoPad[1] = ~movie_data[offs+1] & 0x8f; // ! SCBA RLDU + if(!(movie_data[offs+1] & 0x10)) PicoPad[1] |= 0x40; // A + if(!(movie_data[offs+1] & 0x20)) PicoPad[1] |= 0x10; // B + if(!(movie_data[offs+1] & 0x40)) PicoPad[1] |= 0x20; // A + PicoPad[0] |= (~movie_data[offs+2] & 0x0A) << 8; // ! MZYX + if(!(movie_data[offs+2] & 0x01)) PicoPad[0] |= 0x0400; // X + if(!(movie_data[offs+2] & 0x04)) PicoPad[0] |= 0x0100; // Z + PicoPad[1] |= (~movie_data[offs+2] & 0xA0) << 4; // ! MZYX + if(!(movie_data[offs+2] & 0x10)) PicoPad[1] |= 0x0400; // X + if(!(movie_data[offs+2] & 0x40)) PicoPad[1] |= 0x0100; // Z + } +} + + static void updateKeys(void) { unsigned long keys, allActions[2] = { 0, 0 }, events; @@ -711,41 +749,8 @@ static void updateKeys(void) } } - if(movie_data) - { - int offs = frame_count*3 + 0x40; - if (offs+3 > movie_size) { - free(movie_data); - movie_data = 0; - strcpy(noticeMsg, "END OF MOVIE."); - printf("END OF MOVIE.\n"); - gettimeofday(¬iceMsgTime, 0); - } else { - // MXYZ SACB RLDU - PicoPad[0] = ~movie_data[offs] & 0x8f; // ! SCBA RLDU - if(!(movie_data[offs] & 0x10)) PicoPad[0] |= 0x40; // A - if(!(movie_data[offs] & 0x20)) PicoPad[0] |= 0x10; // B - if(!(movie_data[offs] & 0x40)) PicoPad[0] |= 0x20; // A - PicoPad[1] = ~movie_data[offs+1] & 0x8f; // ! SCBA RLDU - if(!(movie_data[offs+1] & 0x10)) PicoPad[1] |= 0x40; // A - if(!(movie_data[offs+1] & 0x20)) PicoPad[1] |= 0x10; // B - if(!(movie_data[offs+1] & 0x40)) PicoPad[1] |= 0x20; // A - PicoPad[0] |= (~movie_data[offs+2] & 0x0A) << 8; // ! MZYX - if(!(movie_data[offs+2] & 0x01)) PicoPad[0] |= 0x0400; // X - if(!(movie_data[offs+2] & 0x04)) PicoPad[0] |= 0x0100; // Z - PicoPad[1] |= (~movie_data[offs+2] & 0xA0) << 4; // ! MZYX - if(!(movie_data[offs+2] & 0x10)) PicoPad[1] |= 0x0400; // X - if(!(movie_data[offs+2] & 0x40)) PicoPad[1] |= 0x0100; // Z - if ((PicoPad[0] & 0x80) || (PicoPad[1] & 0x80)) - printf("%d: start\n", frame_count); - } - } - else - { - PicoPad[0] = (unsigned short) allActions[0]; - PicoPad[1] = (unsigned short) allActions[1]; - } - frame_count++; + PicoPad[0] = (unsigned short) allActions[0]; + PicoPad[1] = (unsigned short) allActions[1]; events = (allActions[0] | allActions[1]) >> 16; @@ -765,6 +770,7 @@ static void updateKeys(void) events &= ~prevEvents; if (events) RunEvents(events); + if (movie_data) updateMovie(); prevEvents = (allActions[0] | allActions[1]) >> 16; } @@ -995,21 +1001,59 @@ void emu_Loop(void) updateKeys(); PicoFrame(); +#if 0 +if (Pico.m.frame_count == 31563) { + FILE *f; + f = fopen("ram_p.bin", "wb"); + if (!f) { printf("!f\n"); exit(1); } + fwrite(Pico.ram, 1, 0x10000, f); + fclose(f); + exit(0); +} +#endif #if 0 // debug { - static unsigned char oldscr[320*240*2]; + #define BYTE unsigned char + #define WORD unsigned short + struct + { + BYTE IDLength; /* 00h Size of Image ID field */ + BYTE ColorMapType; /* 01h Color map type */ + BYTE ImageType; /* 02h Image type code */ + WORD CMapStart; /* 03h Color map origin */ + WORD CMapLength; /* 05h Color map length */ + BYTE CMapDepth; /* 07h Depth of color map entries */ + WORD XOffset; /* 08h X origin of image */ + WORD YOffset; /* 0Ah Y origin of image */ + WORD Width; /* 0Ch Width of image */ + WORD Height; /* 0Eh Height of image */ + BYTE PixelDepth; /* 10h Image pixel size */ + BYTE ImageDescriptor; /* 11h Image descriptor byte */ + } __attribute__((packed)) TGAHEAD; + static unsigned short oldscr[320*240]; FILE *f; char name[128]; int i; - for (i = 0; i < 320*240*2; i++) - if(oldscr[i] != ((unsigned char *)gp2x_screen)[i]) break; - if (i < 320*240*2) + + memset(&TGAHEAD, 0, sizeof(TGAHEAD)); + TGAHEAD.ImageType = 2; + TGAHEAD.Width = 320; + TGAHEAD.Height = 240; + TGAHEAD.PixelDepth = 16; + TGAHEAD.ImageDescriptor = 2<<4; // image starts at top-left + + #define CONV(X) (((X>>1)&0x7fe0)|(X&0x1f)) // 555? + + for (i = 0; i < 320*240; i++) + if(oldscr[i] != CONV(((unsigned short *)gp2x_screen)[i])) break; + if (i < 320*240) { - for (i = 0; i < 320*240*2; i++) - oldscr[i] = ((unsigned char *)gp2x_screen)[i]; - sprintf(name, "%05i.raw", frame_count); + for (i = 0; i < 320*240; i++) + oldscr[i] = CONV(((unsigned short *)gp2x_screen)[i]); + sprintf(name, "%05i.tga", Pico.m.frame_count); f = fopen(name, "wb"); if (!f) { printf("!f\n"); exit(1); } - fwrite(gp2x_screen, 1, 320*240*2, f); + fwrite(&TGAHEAD, 1, sizeof(TGAHEAD), f); + fwrite(oldscr, 1, 320*240*2, f); fclose(f); } }