+ /* Correct the comp */
+ result->comp = ((result->comp >> 2) | ((result->comp << 6) & 0xC0)) ^ 0xBA;
+ }
+}
+
+void ar_decode_ms(const char *code, struct patch *result){
+ char *x;
+ int i;
+ /* 2 digits of padding*/
+ /* 4 digits for address */
+ for(i=2;i<7;++i)
+ {
+ /* 5th character is hyphen and can be skipped*/
+ if (i==4) continue;
+ if(!(x = strchr(hex_chars, code[i])))
+ {
+ result->addr = result->data = -1;
+ return;
+ }
+ result->addr = (result->addr << 4) | ((x - hex_chars) >> 1);
+ }
+ /* 2 digits for data */
+ for(i=7;i<9;++i)
+ {
+ if(!(x = strchr(hex_chars, code[i])))
+ {
+ result->addr = result->data = -1;
+ return;
+ }
+ result->data = (result->data << 4) | ((x - hex_chars) >> 1);
+ }
+}
+
+void fusion_ram_decode(const char *code, struct patch *result){
+ char *x;
+ int i;
+ /* 4 digits for address */
+ for(i=0;i<4;++i)
+ {
+ if(!(x = strchr(hex_chars, code[i])))
+ {
+ result->addr = result->data = -1;
+ return;
+ }
+ result->addr = (result->addr << 4) | ((x - hex_chars) >> 1);
+ }
+ /* Skip the ':' */
+ /* 2 digits for data */
+ for(i=5;i<7;++i)
+ {
+ if(!(x = strchr(hex_chars, code[i])))
+ {
+ result->addr = result->data = -1;
+ return;
+ }
+ result->data = (result->data << 4) | ((x - hex_chars) >> 1);
+ }
+}
+
+void fusion_rom_decode(const char *code, struct patch *result){
+ char *x;
+ int i;
+ /* 2 digits for comp */
+ for(i=0;i<2;++i)
+ {
+ if(!(x = strchr(hex_chars, code[i])))
+ {
+ result->addr = result->data = -1;
+ return;
+ }
+ result->comp = (result->comp << 4) | ((x - hex_chars) >> 1);
+ }
+ /* 4 digits for address */
+ for(i=2;i<6;++i)
+ {
+ if(!(x = strchr(hex_chars, code[i])))
+ {
+ result->addr = result->data = -1;
+ return;
+ }
+ result->addr = (result->addr << 4) | ((x - hex_chars) >> 1);
+ }
+ /* 2 digits for data */
+ for(i=7;i<9;++i)
+ {
+ if(!(x = strchr(hex_chars, code[i])))
+ {
+ result->addr = result->data = -1;
+ return;
+ }
+ result->data = (result->data << 4) | ((x - hex_chars) >> 1);
+ }