Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import sys
- def buildRom(bname,fname):
- name,ext=os.path.splitext(os.path.basename(fname))
- # Read Sonic & Knuckles data.
- f=open("%s.md" % bname,"rb")
- data1=f.read()
- f.close()
- # Open locked-on ROM.
- f=open(fname,"rb")
- # Get file size.
- f.seek(0x00,2)
- size=f.tell()
- if size<0x200:
- print("Not a Genesis/Mega Drive ROM")
- return False
- f.seek(0x100)
- testData=f.read(0x10)
- if testData not in [b"SEGA MEGA DRIVE ",b"SEGA GENESIS "]:
- print("Not a Genesis/Mega Drive ROM")
- return False
- # Round the size up to the next power of two to get the true ROM size.
- romSize=1<<(size-1).bit_length()
- # Append the last 2 MiB from locked-on ROM.
- f.seek(max(0x00,romSize-0x200000))
- data2=f.read()
- f.close()
- # Check if it's Sonic 2 and append 256 KiB patch ROM if needed.
- isSonic2=False
- # Lock-on serials:
- # "GM 00001051-00" # Sonic 2 REV00
- # "GM 00001051-01" # Sonic 2 REV01
- # "GM 00001051-02" # Sonic 2 REV02
- # "GM MK-1079 -00" # Sonic 3
- # Blue Spheres unlocking serials:
- # "GM 00001009-0" # Sonic 1 REV00
- # "GM 00004049-0" # Sonic 1 REV01
- if (data2[0x180:0x18e] in [b"GM 00001051-00",b"GM 00001051-01",b"GM 00001051-02"]):
- isSonic2=True
- f=open("Sonic & Knuckles (World) (Lock-on).bin","rb")
- datas2k=f.read()
- f.close()
- f=open("%s + %s.md" % (bname,name),"wb")
- f.write(data1)
- f.write(data2)
- if isSonic2: f.write(datas2k)
- f.close()
- return True
- if __name__=="__main__":
- bname="Sonic & Knuckles (World)"
- fname=sys.argv[1]
- buildRom(bname,fname)
Advertisement
Add Comment
Please, Sign In to add comment