Created
August 25, 2023 21:41
-
-
Save mimura1133/02138c25a7276d809564aeca6f9122d0 to your computer and use it in GitHub Desktop.
This file contains 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
import struct | |
""" | |
FILE STRUCTURE: | |
[GLOBALHEADER] | |
-PADDING with 0xFF- | |
[MUSIC HEADER 01] | |
-PADDING with 0xFF- | |
[MUSIC DATA 01] | |
-PADDING with 0xFF- | |
[MUSIC HEADER 02] | |
-PADDING with 0xFF- | |
[MUSIC DATA 02] | |
-PADDING with 0xFF- | |
EOF. | |
GLOBAL HEADER STRUCTURE: | |
[MAGIC, 4bytes] : AA 55 01 00 | |
[UNKNOWN DATA, 12bytes] : 00 01 64 00 00 00 00 00 01 00 02 00 | |
[ADDRESS OF MUSIC HEADER 01, 4bytes, LITTLE] | |
[ADDRESS OF MUSIC HEADER 02, 4bytes, LITTLE] | |
MUSIC HEADER STRUCTURE: | |
[MAGIC, 4bytes] : 55 AA 01 00 | |
[UNKNOWN DATA, 4bytes] : 00 80 FF FF | |
[ADDRESS OF MUSIC DATA, 4bytes, LITTLE] | |
[LAST ADDRESS OF MUSIC DATA, 4bytes, LITTLE] | |
HOW TO MAKE MUSIC DATA: | |
# ffmpeg -i sound1.wav -acodec adpcm_ima_ssi -f s8 sound1.vox | |
""" | |
def make_globalheader(ptr_music01, ptr_music02): | |
data = b'\xAA\x55\x01\x00' # MAGIC | |
data += b'\x00\x01\x64\x00\x00\x00\x00\x00\x01\x00\x02\x00' # UNKNOWN DATA | |
data += struct.pack("<l",ptr_music01) | |
data += struct.pack("<l",ptr_music02) | |
return data | |
def make_musicdata(baseaddr, musicdata): | |
padding = 0x200 | |
data = b'\x55\xAA\x01\x00' # MAGIC | |
data += b'\x00\x80\xFF\xFF' # UNKNOWN DATA | |
data += struct.pack("<l",baseaddr + padding) # ADDRESS | |
data += struct.pack("<l",baseaddr + padding + len(musicdata)) # LAST ADDRESS | |
data += b'\xFF' * (padding - 0x10) | |
data += musicdata | |
return data | |
def main(): | |
padding = 0x200 | |
baseaddr = 0x100 | |
with open("sound1.vox", "rb") as f: | |
music01 = make_musicdata(baseaddr,f.read()) | |
with open("sound2.vox", "rb") as f: | |
music02 = make_musicdata(baseaddr + padding + len(music01),f.read()) | |
global_header = make_globalheader(baseaddr,baseaddr + padding + len(music01)) | |
data = global_header | |
data += b"\xFF" * (baseaddr - len(global_header)) | |
data += music01 | |
data += b'\xFF' * padding | |
data += music02 | |
data += b'\xFF' * padding | |
with open("firmdata.bin","wb") as f: | |
f.write(data) | |
f.flush() | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment