X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=platform%2Flibretro%2Flibretro.c;h=0f060e6b7e275670b39a731b67c4e055542ec14e;hb=d4089d9b8e132e796dca0382bd237b8efeeeac3d;hp=332cf65150c68afcbb8f584f7c61ca11fea11d8c;hpb=f0a3d0dc4bd9060eb6bfdb16fb20dbb80a9e6ae9;p=picodrive.git diff --git a/platform/libretro/libretro.c b/platform/libretro/libretro.c index 332cf65..0f060e6 100644 --- a/platform/libretro/libretro.c +++ b/platform/libretro/libretro.c @@ -53,6 +53,7 @@ int _newlib_vm_size_user = 1 << TARGET_SIZE_2; #include #include +#include #include "../common/input_pico.h" #include "../common/version.h" #include "libretro.h" @@ -692,12 +693,82 @@ bool retro_unserialize(const void *data, size_t size) } /* cheats - TODO */ + void retro_cheat_reset(void) { + int i=0; + unsigned int addr; + + for (i = 0; i < PicoPatchCount; i++) + { + addr = PicoPatches[i].addr; + if (addr < Pico.romsize) + if (PicoPatches[i].active) + *(unsigned short *)(Pico.rom + addr) = PicoPatches[i].data_old; + else + if (PicoPatches[i].active) + m68k_write16(PicoPatches[i].addr,PicoPatches[i].data_old); + } + + PicoPatchUnload(); } void retro_cheat_set(unsigned index, bool enabled, const char *code) { + struct patch + { + unsigned int addr; + unsigned short data; + } pt; + int array_len = 0; + char *buff; + bool multiline=0; + + //TODO: Split multi-line codes properly + if (strstr(code,"+")){ + multiline=1; + buff = strtok(code,"+"); + } else { + buff=code; + } + + while (buff != NULL) + { + decode(buff, &pt); + if (pt.addr == (unsigned int)-1 || pt.data == (unsigned short)-1) + { + log_cb(RETRO_LOG_ERROR,"CHEATS: Invalid code: %s\n",buff); + return; + } + + /* code was good, add it */ + if (array_len < PicoPatchCount + 1) + { + void *ptr; + array_len *= 2; + array_len++; + ptr = realloc(PicoPatches, array_len * sizeof(PicoPatches[0])); + if (ptr == NULL) { + log_cb(RETRO_LOG_ERROR,"CHEATS: Failed to allocate memory for: %s\n",buff); + return; + } + PicoPatches = ptr; + } + strcpy(PicoPatches[PicoPatchCount].code, buff); + + PicoPatches[PicoPatchCount].name[51] = ""; + PicoPatches[PicoPatchCount].active = enabled; + PicoPatches[PicoPatchCount].addr = pt.addr; + PicoPatches[PicoPatchCount].data = pt.data; + if (PicoPatches[PicoPatchCount].addr < Pico.romsize) + PicoPatches[PicoPatchCount].data_old = *(unsigned short *)(Pico.rom + PicoPatches[PicoPatchCount].addr); + else + PicoPatches[PicoPatchCount].data_old = (unsigned short) m68k_read16(PicoPatches[PicoPatchCount].addr); + PicoPatchCount++; + + if (!multiline) + break; + } } /* multidisk support */ @@ -1270,6 +1341,7 @@ void retro_run(void) if (input_state_cb(pad, RETRO_DEVICE_JOYPAD, 0, i)) PicoPad[pad] |= retro_pico_map[i]; + PicoPatchApply(); PicoFrame(); video_cb((short *)vout_buf + vout_offset,