X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=platform%2Flibretro%2Flibretro.c;h=a1cf22c88dae1e0d194bc1856af36bfebc9c981b;hb=fa55ee51c9c1d86311fbd90f055a575e4991ac70;hp=73733fdb21746ff6cc3f36307b9875abe16dadc8;hpb=20563b60d0b9526c133289ca9c7b1ba255991916;p=picodrive.git diff --git a/platform/libretro/libretro.c b/platform/libretro/libretro.c index 73733fd..a1cf22c 100644 --- a/platform/libretro/libretro.c +++ b/platform/libretro/libretro.c @@ -692,7 +692,16 @@ bool retro_unserialize(const void *data, size_t size) return ret == 0; } -/* cheats - TODO */ +typedef struct patch +{ + unsigned int addr; + unsigned short data; + unsigned char comp; +} patch; + +extern void decode(char *buff, patch *dest); +extern uint16_t m68k_read16(uint32_t a); +extern void m68k_write16(uint32_t a, uint16_t d); void retro_cheat_reset(void) { @@ -702,30 +711,34 @@ void retro_cheat_reset(void) for (i = 0; i < PicoPatchCount; i++) { addr = PicoPatches[i].addr; - if (addr < Pico.romsize) + if (addr < Pico.romsize) { if (PicoPatches[i].active) *(unsigned short *)(Pico.rom + addr) = PicoPatches[i].data_old; - else + } 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 *buff) +void retro_cheat_set(unsigned index, bool enabled, const char *code) { - struct patch - { - unsigned int addr; - unsigned short data; - } pt; - int array_len = 0; + patch pt; + int array_len = PicoPatchCount; + char codeCopy[256]; + char *buff; - //TODO: Split multi-line codes properly + if (code=='\0') return; + strcpy(codeCopy,code); + buff = strtok(codeCopy,"+"); + while (buff != NULL) + { decode(buff, &pt); - if (pt.addr == (unsigned int)-1 || pt.data == (unsigned short)-1){ + if (pt.addr == (uint32_t) -1 || pt.data == (uint16_t) -1) + { log_cb(RETRO_LOG_ERROR,"CHEATS: Invalid code: %s\n",buff); return; } @@ -745,15 +758,18 @@ void retro_cheat_set(unsigned index, bool enabled, const char *buff) } strcpy(PicoPatches[PicoPatchCount].code, buff); - PicoPatches[PicoPatchCount].name[51] = ""; PicoPatches[PicoPatchCount].active = enabled; PicoPatches[PicoPatchCount].addr = pt.addr; PicoPatches[PicoPatchCount].data = pt.data; + PicoPatches[PicoPatchCount].comp = pt.comp; if (PicoPatches[PicoPatchCount].addr < Pico.romsize) - PicoPatches[PicoPatchCount].data_old = *(unsigned short *)(Pico.rom + PicoPatches[PicoPatchCount].addr); + PicoPatches[PicoPatchCount].data_old = *(uint16_t *)(Pico.rom + PicoPatches[PicoPatchCount].addr); else - PicoPatches[PicoPatchCount].data_old = (unsigned short) m68k_read16(PicoPatches[PicoPatchCount].addr); + PicoPatches[PicoPatchCount].data_old = (uint16_t) m68k_read16(PicoPatches[PicoPatchCount].addr); PicoPatchCount++; + + buff = strtok(NULL,"+"); + } } /* multidisk support */