X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=pico%2Fpatch.c;h=40e8372c567f2a9d16c563e8b8bc3e06d44ae9b5;hb=8655fd046255007513449f76cf2d9f5efd84f49e;hp=dc5c91f516e604417e85ca9309d9a3781ee8273f;hpb=ee2a3bdfa5a969ea9446b2d08748f16e29bbd4d5;p=picodrive.git diff --git a/pico/patch.c b/pico/patch.c index dc5c91f..40e8372 100644 --- a/pico/patch.c +++ b/pico/patch.c @@ -22,6 +22,7 @@ */ #include "pico_int.h" +#include "memory.h" #include "patch.h" struct patch @@ -142,7 +143,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 +214,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) @@ -303,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; } @@ -333,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); + } } } }