Last active
July 15, 2020 17:00
-
-
Save infval/baf4261878d88f93c0b4f3ab1f977c66 to your computer and use it in GitHub Desktop.
Fix Zudu-go ROM | 2udu-go, zudugo.bin (Macro Winners / Waixing) | CRC32: 0FA9D9AD | Python 3 | Emulators: NintendulatorNRS, MAME, EmuVT
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
""" | |
Input: zudugo.bin (CRC32: 0FA9D9AD) | |
Usage: | |
script.py zudugo.bin | |
License: Unlicense | |
""" | |
__version__ = '1.0.0' | |
__author__ = "infval" | |
import sys | |
from pathlib import Path | |
def replace(b, bout, inp, out, excluded=(-1,)): | |
count = 0 | |
for p in inp: | |
size = len(p) | |
res = 0 | |
while res != -1: | |
res = b.find(p, res) | |
if res != -1: | |
if count not in excluded: | |
bout[res:res+size] = out[inp.index(b[res:res+size])] | |
res += 1 | |
count += 1 | |
path = Path("zudugo.bin") | |
if len(sys.argv) > 1: | |
path = Path(sys.argv[1]) | |
b = path.read_bytes() | |
bout = bytearray(b) | |
######### | |
# $201x # | |
######### | |
# 2016 > 2015, 2017 > 2014, 2012 > 2013, 2013 > 2012, 2014 > 2017, 2015 > 2016 | |
REG = ("16", "17", "12", "13", "14", "15") | |
REG_INV = ("15", "14", "13", "12", "17", "16") | |
""" | |
8D 1? 20 STA $201? | |
""" | |
inp = list(map(lambda x: bytes.fromhex("8D" + x + "20"), REG)) | |
out = list(map(lambda x: bytes.fromhex("8D" + x + "20"), REG_INV)) | |
replace(b, bout, inp, out) | |
""" | |
8E 1? 20 STX $201? | |
""" | |
inp = list(map(lambda x: bytes.fromhex("8E" + x + "20"), REG)) | |
out = list(map(lambda x: bytes.fromhex("8E" + x + "20"), REG_INV)) | |
replace(b, bout, inp, out) | |
""" | |
A2 1? LDX #$1? | |
9D 00 20 STA $2000,X | |
""" | |
inp = list(map(lambda x: bytes.fromhex("A2" + x + "9D 00 20"), REG)) | |
out = list(map(lambda x: bytes.fromhex("A2" + x + "9D 00 20"), REG_INV)) | |
# Total: 11 | |
# 2: Breaks main menu | |
# 0, 9, 10: For "51 IN 1" menu | |
# Rest: Unknown | |
replace(b, bout, inp, out, excluded=(2, 1,3,4,5,6,7,8)) | |
# Game 2 | |
""" | |
A2 1? LDX #$1? | |
98 TYA | |
9D 00 20 STA $2000,X | |
""" | |
inp = list(map(lambda x: bytes.fromhex("A2" + x + "98 9D 00 20"), REG)) | |
out = list(map(lambda x: bytes.fromhex("A2" + x + "98 9D 00 20"), REG_INV)) | |
replace(b, bout, inp, out) | |
######### | |
# $8000 # | |
######### | |
# Game 1 | |
""" | |
0000 A0 05 LDY #$05 ; A0 00 LDY #$00 | |
0002 8C 00 80 STY $8000 | |
0005 AD F0 07 LDA $07F0 | |
0008 8D 01 80 STA $8001 | |
000B 88 DEY ; C8 INY | |
000C 8C 00 80 STY $8000 | |
000F AD F1 07 LDA $07F1 | |
0012 8D 01 80 STA $8001 | |
0015 88 DEY ; C8 INY | |
0016 8C 00 80 STY $8000 | |
0019 AD F2 07 LDA $07F2 | |
001C 8D 01 80 STA $8001 | |
001F 88 DEY ; C8 INY | |
0020 8C 00 80 STY $8000 | |
0023 AD F3 07 LDA $07F3 | |
0026 8D 01 80 STA $8001 | |
0029 88 DEY ; C8 INY | |
002A 8C 00 80 STY $8000 | |
002D AD F4 07 LDA $07F4 | |
0030 8D 01 80 STA $8001 | |
0033 88 DEY ; C8 INY | |
0034 8C 00 80 STY $8000 | |
0037 AD F5 07 LDA $07F5 | |
003A 8D 01 80 STA $8001 | |
003D 60 RTS | |
""" | |
inp = ( | |
"A0 05 8C 00 80 AD F0 07 8D 01 80" | |
"88 8C 00 80 AD F1 07 8D 01 80" | |
"88 8C 00 80 AD F2 07 8D 01 80" | |
"88 8C 00 80 AD F3 07 8D 01 80" | |
"88 8C 00 80 AD F4 07 8D 01 80" | |
"88 8C 00 80 AD F5 07 8D 01 80 60") | |
out = ( | |
"A0 00 8C 00 80 AD F0 07 8D 01 80" | |
"C8 8C 00 80 AD F1 07 8D 01 80" | |
"C8 8C 00 80 AD F2 07 8D 01 80" | |
"C8 8C 00 80 AD F3 07 8D 01 80" | |
"C8 8C 00 80 AD F4 07 8D 01 80" | |
"C8 8C 00 80 AD F5 07 8D 01 80 60") | |
inp = bytes.fromhex(inp) | |
out = bytes.fromhex(out) | |
replace(b, bout, [inp], [out]) | |
# Title screens 6, 8, 9, 11, 12, 13, 24, 36, 45 | |
# $8000, $8001, $8000, $8001, ... | |
inp = "00 00 01 02 02 04 03 05 04 06 05 07" | |
out = "05 00 04 02 03 04 02 05 01 06 00 07" | |
inp = bytes.fromhex(inp) | |
out = bytes.fromhex(out) | |
# Total: 13 | |
# Included (index - game): | |
# 3 - 45, 4 - 36, 5 - 24, 7 - 13, 8 - 12, 9 - 11, 10 - 9, 11 - 6, 12 - 8 | |
# Excluded: | |
# 6 - 20 (0x317D7B) | |
# 0, 1, 2 - Unknown | |
replace(b, bout, [inp], [out], excluded=(0,1,2, 6)) | |
# Games 5, 14, 17 | |
# $8000, $8001, $8000, $8001, ..., FF, ... | |
inp = "00 00 01 02 02 04 FF 00 08 01 0A 02 0C 03 0D 04 0E 05 0F FF" | |
out = "05 00 04 02 03 04 FF 05 08 04 0A 03 0C 02 0D 01 0E 00 0F FF" | |
inp = bytes.fromhex(inp) | |
out = bytes.fromhex(out) | |
replace(b, bout, [inp], [out]) | |
# Games 6, 8, 9, 11, 12, 13, 24, 36, 45 | |
# $8000, $8001, $8000, $8001, ..., FF, ... | |
inp = "00 08 01 0A 02 0C 03 0D 04 0E 05 0F FF" | |
out = "05 08 04 0A 03 0C 02 0D 01 0E 00 0F FF" | |
inp = bytes.fromhex(inp) | |
out = bytes.fromhex(out) | |
# Total: 15 | |
# Included (index - game): | |
# 1 - 45, 2 - 36, 3 - 24, 7 - 13, 8 - 12, 9 - 11, 10 - 9, 11 - 6, 14 - 8 | |
# Excluded: | |
# 4 - 20 (0x317E7A) | |
# 5 - 5, 6 - 14, 12 - 17 (repeats previous replacement, no effect) | |
# 0, 13 - Unknown | |
replace(b, bout, [inp], [out], excluded=(0,13, 4, 5,6,12)) | |
# Game 42 | |
""" | |
0000 A2 05 LDX #$05 ; A2 00 LDX #$00 | |
0002 8E 00 80 STX $8000 | |
0005 8D 01 80 STA $8001 | |
0008 18 CLC | |
0009 69 02 ADC #$02 | |
000B A2 04 LDX #$04 ; A2 01 LDX #$01 | |
000D 8E 00 80 STX $8000 | |
0010 8D 01 80 STA $8001 | |
0013 60 RTS | |
0014 A0 04 LDY #$04 | |
0016 A2 03 LDX #$03 ; A2 02 LDX #$02 | |
0018 8E 00 80 STX $8000 | |
001B 8C 01 80 STY $8001 | |
001E C8 INY | |
001F A2 02 LDX #$02 ; A2 03 LDX #$03 | |
0021 8E 00 80 STX $8000 | |
0024 8C 01 80 STY $8001 | |
0027 C8 INY | |
0028 A2 01 LDX #$01 ; A2 04 LDX #$04 | |
002A 8E 00 80 STX $8000 | |
002D 8C 01 80 STY $8001 | |
0030 C8 INY | |
0031 A2 00 LDX #$00 ; A2 05 LDX #$05 | |
0033 8E 00 80 STX $8000 | |
""" | |
""" | |
A2 0? LDX #$0? | |
8E 00 80 STX $8000 | |
""" | |
inp = ["00", "01", "02", "03", "04", "05"] | |
out = ["05", "04", "03", "02", "01", "00"] | |
inp = list(map(lambda x: bytes.fromhex("A2" + x + "8E 00 80"), inp)) | |
out = list(map(lambda x: bytes.fromhex("A2" + x + "8E 00 80"), out)) | |
replace(b, bout, inp, out) | |
filename = "{}_fixed{}".format(path.stem, path.suffix) | |
path_out = path.with_name(filename) | |
path_out.write_bytes(bout) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment