X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=pico%2Fpatch.c;h=0240cb0d7dde2ac729454a636b794789531a31f7;hb=d4089d9b8e132e796dca0382bd237b8efeeeac3d;hp=99632dda8ef029163299e0a1a605086ffb1006d4;hpb=af37bca858874b5cbd5ab126eaba1fad6ff7ab72;p=picodrive.git diff --git a/pico/patch.c b/pico/patch.c index 99632dd..0240cb0 100644 --- a/pico/patch.c +++ b/pico/patch.c @@ -142,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; @@ -213,12 +213,6 @@ unsigned int PicoRead16(unsigned int a); void PicoWrite16(unsigned int a, unsigned short d); -/* avoid dependency on newer glibc */ -static int isspace_(int c) -{ - return (0x09 <= c && c <= 0x0d) || c == ' '; -} - void PicoPatchUnload(void) { if (PicoPatches != NULL) @@ -305,6 +299,8 @@ void PicoPatchPrepare(void) PicoPatches[i].addr &= ~1; 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; } @@ -334,7 +330,15 @@ void PicoPatchApply(void) } else { - /* TODO? */ + if (PicoPatches[i].active) + 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); + } } } }