X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=pico%2Fpatch.c;h=558658c3f03a2b9e50bc5e2edf05d6cd9ca45b18;hb=6bf654d0e2fc12b5cbb8bd82ec5136c9ef5ea568;hp=42c6a4eb0f9c4c063ae18958049a48b8ed71a8ef;hpb=1cfc5cc4ce06642b9bc45ca3b9d32793718e9455;p=picodrive.git diff --git a/pico/patch.c b/pico/patch.c index 42c6a4e..558658c 100644 --- a/pico/patch.c +++ b/pico/patch.c @@ -21,10 +21,6 @@ * (of course, that's handled by a different source file :) */ -//#include -//#include -#include - #include "pico_int.h" #include "patch.h" @@ -146,7 +142,7 @@ static void hex_decode(const char *code, struct patch *result) /* THIS is the function you call from the MegaDrive or whatever. This figures * out whether it's a genie or hex code, depunctuates it, and calls the proper * decoder. */ -static void decode(const char* code, struct patch* result) +void decode(const char* code, struct patch* result) { int len = strlen(code), i, j; char code_to_pass[16], *x; @@ -215,7 +211,8 @@ bad_code: unsigned int PicoRead16(unsigned int a); void PicoWrite16(unsigned int a, unsigned short d); - +extern unsigned short m68k_read16(unsigned int a); +extern void m68k_write16(int a, unsigned short d); void PicoPatchUnload(void) { @@ -248,7 +245,8 @@ int PicoPatchLoad(const char *fname) llen = strlen(buff); for (clen = 0; clen < llen; clen++) - if (isspace(buff[clen])) break; + if (isspace_(buff[clen])) + break; buff[clen] = 0; if (clen > 11 || clen < 8) @@ -271,9 +269,11 @@ int PicoPatchLoad(const char *fname) strcpy(PicoPatches[PicoPatchCount].code, buff); /* strip */ for (clen++; clen < llen; clen++) - if (!isspace(buff[clen])) break; + if (!isspace_(buff[clen])) + break; for (llen--; llen > 0; llen--) - if (!isspace(buff[llen])) break; + if (!isspace_(buff[llen])) + break; buff[llen+1] = 0; strncpy(PicoPatches[PicoPatchCount].name, buff + clen, 51); PicoPatches[PicoPatchCount].name[51] = 0; @@ -298,7 +298,10 @@ void PicoPatchPrepare(void) for (i = 0; i < PicoPatchCount; i++) { PicoPatches[i].addr &= ~1; - PicoPatches[i].data_old = PicoRead16(PicoPatches[i].addr); + if (PicoPatches[i].addr < Pico.romsize) + PicoPatches[i].data_old = *(unsigned short *)(Pico.rom + PicoPatches[i].addr); + else + PicoPatches[i].data_old = (unsigned short) m68k_read16(PicoPatches[i].addr); if (strstr(PicoPatches[i].name, "AUTO")) PicoPatches[i].active = 1; } @@ -328,9 +331,15 @@ void PicoPatchApply(void) } else { - /* RAM or some other weird patch */ if (PicoPatches[i].active) - PicoWrite16(addr, PicoPatches[i].data); + m68k_write16(PicoPatches[i].addr,PicoPatches[i].data); + else { + // if current addr is not patched by older patch, write back original val + for (u = 0; u < i; u++) + if (PicoPatches[u].addr == addr) break; + if (u == i) + m68k_write16(PicoPatches[i].addr,PicoPatches[i].data_old); + } } } }