From 933b7f57d045cc21ee236b9cee491e6d35f99a03 Mon Sep 17 00:00:00 2001 From: sorgelig Date: Mon, 16 Nov 2020 19:22:27 +0800 Subject: [PATCH] mra: support xor mode in patches. --- support/arcade/mra_loader.cpp | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/support/arcade/mra_loader.cpp b/support/arcade/mra_loader.cpp index fbe62ff..0eb89cc 100644 --- a/support/arcade/mra_loader.cpp +++ b/support/arcade/mra_loader.cpp @@ -31,6 +31,7 @@ struct arc_struct { int repeat; int insiderom; int patchaddr; + int dataop; int validrom0; int insidesw; int insideinterleave; @@ -222,10 +223,18 @@ static int rom_file(const char *name, uint32_t crc32, int start, int len, int ma return 1; } -static int rom_patch(const uint8_t *buf, int offset, uint16_t len) +static int rom_patch(const uint8_t *buf, int offset, uint16_t len, int dataop) { if ((offset + len) > romlen[0]) return 0; - memcpy(romdata + offset, buf, len); + if (!dataop) + { + memcpy(romdata + offset, buf, len); + } + else + { + for (int i = 0; i < len; i++) romdata[offset + i] ^= buf[i]; + } + return 1; } @@ -426,7 +435,11 @@ static int xml_send_rom(XMLEvent evt, const XMLNode* node, SXML_CHAR* text, cons arc_info->imap = 0; } - if (!strcasecmp(node->tag, "patch")) arc_info->patchaddr = 0; + if (!strcasecmp(node->tag, "patch")) + { + arc_info->patchaddr = 0; + arc_info->dataop = 0; + } //printf("XML_EVENT_START_NODE: tag [%s]\n",node->tag); // walk the attributes and save them in the data structure as appropriate @@ -504,6 +517,10 @@ static int xml_send_rom(XMLEvent evt, const XMLNode* node, SXML_CHAR* text, cons { arc_info->patchaddr = strtoul(node->attributes[i].value, NULL, 0); } + if (!strcasecmp(node->attributes[i].name, "operation") && !strcasecmp(node->tag, "patch")) + { + if(!strcasecmp(node->attributes[i].value, "xor")) arc_info->dataop = 1; + } if (!strcasecmp(node->attributes[i].name, "map") && !strcasecmp(node->tag, "part")) { arc_info->imap = strtoul(node->attributes[i].value, NULL, 16); @@ -806,7 +823,7 @@ static int xml_send_rom(XMLEvent evt, const XMLNode* node, SXML_CHAR* text, cons unsigned char* binary = hexstr_to_char(arc_info->data->content, &len); if (binary) { - rom_patch(binary, arc_info->patchaddr, len); + rom_patch(binary, arc_info->patchaddr, len, arc_info->dataop); free(binary); } }