- FILE *f;
- char buff[256];
- struct patch pt;
- int array_len = 0;
-
- PicoPatchUnload();
-
- f = fopen(fname, "r");
- if (f == NULL)
- {
- return -1;
- }
-
- while (fgets(buff, sizeof(buff), f))
- {
- int llen, clen;
-
- llen = strlen(buff);
- for (clen = 0; clen < llen; clen++)
- if (isspace_(buff[clen]))
- break;
- buff[clen] = 0;
-
- if (clen > 11 || clen < 8)
- continue;
-
- decode(buff, &pt);
- if (pt.addr == (unsigned int)-1 || pt.data == (unsigned short)-1)
- continue;
-
- /* 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) break;
- PicoPatches = ptr;
- }
- strcpy(PicoPatches[PicoPatchCount].code, buff);
- /* strip */
- for (clen++; clen < llen; clen++)
- if (!isspace_(buff[clen]))
- break;
- for (llen--; llen > 0; llen--)
- if (!isspace_(buff[llen]))
- break;
- buff[llen+1] = 0;
- strncpy(PicoPatches[PicoPatchCount].name, buff + clen, 51);
- PicoPatches[PicoPatchCount].name[51] = 0;
- PicoPatches[PicoPatchCount].active = 0;
- PicoPatches[PicoPatchCount].addr = pt.addr;
- PicoPatches[PicoPatchCount].data = pt.data;
- PicoPatches[PicoPatchCount].data_old = 0;
- PicoPatchCount++;
- // fprintf(stderr, "loaded patch #%i: %06x:%04x \"%s\"\n", PicoPatchCount-1, pt.addr, pt.data,
- // PicoPatches[PicoPatchCount-1].name);
- }
- fclose(f);
-
- return 0;
+ FILE *f;
+ char buff[256];
+ struct patch pt;
+ int array_len = 0;
+
+ PicoPatchUnload();
+
+ f = fopen(fname, "r");
+ if (f == NULL)
+ {
+ return -1;
+ }
+
+ while (fgets(buff, sizeof(buff), f))
+ {
+ int llen, clen;
+
+ llen = strlen(buff);
+ for (clen = 0; clen < llen; clen++)
+ if (isspace_(buff[clen]))
+ break;
+ buff[clen] = 0;
+
+ if (clen > 11 || clen < 8)
+ continue;
+
+ decode(buff, &pt);
+ if (pt.addr == (unsigned int)-1 || pt.data == (unsigned short)-1)
+ continue;
+
+ /* 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) break;
+ PicoPatches = ptr;
+ }
+ strcpy(PicoPatches[PicoPatchCount].code, buff);
+ /* strip */
+ for (clen++; clen < llen; clen++)
+ if (!isspace_(buff[clen]))
+ break;
+ for (llen--; llen > 0; llen--)
+ if (!isspace_(buff[llen]))
+ break;
+ buff[llen+1] = 0;
+ strncpy(PicoPatches[PicoPatchCount].name, buff + clen, 51);
+ PicoPatches[PicoPatchCount].name[51] = 0;
+ PicoPatches[PicoPatchCount].active = 0;
+ PicoPatches[PicoPatchCount].addr = pt.addr;
+ PicoPatches[PicoPatchCount].data = pt.data;
+ PicoPatches[PicoPatchCount].data_old = 0;
+ PicoPatchCount++;
+ // fprintf(stderr, "loaded patch #%i: %06x:%04x \"%s\"\n", PicoPatchCount-1, pt.addr, pt.data,
+ // PicoPatches[PicoPatchCount-1].name);
+ }
+ fclose(f);
+
+ return 0;