+ patch pt;
+ int array_len = PicoPatchCount;
+ char codeCopy[256];
+ char *buff;
+ bool multiline=0;
+
+ strcpy(codeCopy,code);
+
+ if (strstr(code,"+")){
+ multiline=1;
+ buff = strtok(codeCopy,"+");
+ } else {
+ buff=codeCopy;
+ }
+
+ while (buff != NULL)
+ {
+ log_cb(RETRO_LOG_INFO,"Buff: %s\n",buff);
+ decode(buff, &pt);
+ if (pt.addr == (uint32_t) -1 || pt.data == (uint16_t) -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].active = enabled;
+ PicoPatches[PicoPatchCount].addr = pt.addr;
+ PicoPatches[PicoPatchCount].data = pt.data;
+ if (PicoPatches[PicoPatchCount].addr < Pico.romsize)
+ PicoPatches[PicoPatchCount].data_old = *(uint16_t *)(Pico.rom + PicoPatches[PicoPatchCount].addr);
+ else
+ PicoPatches[PicoPatchCount].data_old = (uint16_t) m68k_read16(PicoPatches[PicoPatchCount].addr);
+ PicoPatchCount++;
+
+ if (!multiline)
+ break;
+ buff = strtok(NULL,"+");
+ }