+ 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;
+ }