Rewrite redsfxheaders.py

This commit is contained in:
dannye 2019-08-25 10:55:38 -05:00
parent 92496615f0
commit a28e6f460d
2 changed files with 101 additions and 94 deletions

View File

@ -523,6 +523,8 @@ def dump_all_sfx_in_bank(bank, sfx_names, path):
sfx_file.close() sfx_file.close()
def dump_all_sfx(path): def dump_all_sfx(path):
import os
os.makedirs(path, exist_ok=True)
for bank in sfx_groups: for bank in sfx_groups:
dump_all_sfx_in_bank(bank, sfx_groups[bank], path) dump_all_sfx_in_bank(bank, sfx_groups[bank], path)

View File

@ -1,28 +1,27 @@
from __future__ import absolute_import #!/usr/bin/env python
from . import configuration
config = configuration.Config()
rom = bytearray(open(config.rom_path, "r").read())
sfx_names = [ rom = bytearray(open("baserom.gbc", "rb").read())
"Snare1_1",
"Snare2_1", sfx_names_1 = [
"Snare3_1", "Noise_Instrument01_1",
"Snare4_1", "Noise_Instrument02_1",
"Snare5_1", "Noise_Instrument03_1",
"Triangle1_1", "Noise_Instrument04_1",
"Triangle2_1", "Noise_Instrument05_1",
"Snare6_1", "Noise_Instrument06_1",
"Snare7_1", "Noise_Instrument07_1",
"Snare8_1", "Noise_Instrument08_1",
"Snare9_1", "Noise_Instrument09_1",
"Cymbal1_1", "Noise_Instrument10_1",
"Cymbal2_1", "Noise_Instrument11_1",
"Cymbal3_1", "Noise_Instrument12_1",
"Muted_Snare1_1", "Noise_Instrument13_1",
"Triangle3_1", "Noise_Instrument14_1",
"Muted_Snare2_1", "Noise_Instrument15_1",
"Muted_Snare3_1", "Noise_Instrument16_1",
"Muted_Snare4_1", "Noise_Instrument17_1",
"Noise_Instrument18_1",
"Noise_Instrument19_1",
"Cry00_1", "Cry00_1",
"Cry01_1", "Cry01_1",
"Cry02_1", "Cry02_1",
@ -99,25 +98,28 @@ sfx_names = [
"Save_1", "Save_1",
"Pokeflute", "Pokeflute",
"Safari_Zone_PA", "Safari_Zone_PA",
"Snare1_2", ]
"Snare2_2",
"Snare3_2", sfx_names_2 = [
"Snare4_2", "Noise_Instrument01_2",
"Snare5_2", "Noise_Instrument02_2",
"Triangle1_2", "Noise_Instrument03_2",
"Triangle2_2", "Noise_Instrument04_2",
"Snare6_2", "Noise_Instrument05_2",
"Snare7_2", "Noise_Instrument06_2",
"Snare8_2", "Noise_Instrument07_2",
"Snare9_2", "Noise_Instrument08_2",
"Cymbal1_2", "Noise_Instrument09_2",
"Cymbal2_2", "Noise_Instrument10_2",
"Cymbal3_2", "Noise_Instrument11_2",
"Muted_Snare1_2", "Noise_Instrument12_2",
"Triangle3_2", "Noise_Instrument13_2",
"Muted_Snare2_2", "Noise_Instrument14_2",
"Muted_Snare3_2", "Noise_Instrument15_2",
"Muted_Snare4_2", "Noise_Instrument16_2",
"Noise_Instrument17_2",
"Noise_Instrument18_2",
"Noise_Instrument19_2",
"Cry00_2", "Cry00_2",
"Cry01_2", "Cry01_2",
"Cry02_2", "Cry02_2",
@ -218,25 +220,28 @@ sfx_names = [
"Battle_35", "Battle_35",
"Battle_36", "Battle_36",
"Silph_Scope", "Silph_Scope",
"Snare1_3", ]
"Snare2_3",
"Snare3_3", sfx_names_3 = [
"Snare4_3", "Noise_Instrument01_3",
"Snare5_3", "Noise_Instrument02_3",
"Triangle1_3", "Noise_Instrument03_3",
"Triangle2_3", "Noise_Instrument04_3",
"Snare6_3", "Noise_Instrument05_3",
"Snare7_3", "Noise_Instrument06_3",
"Snare8_3", "Noise_Instrument07_3",
"Snare9_3", "Noise_Instrument08_3",
"Cymbal1_3", "Noise_Instrument09_3",
"Cymbal2_3", "Noise_Instrument10_3",
"Cymbal3_3", "Noise_Instrument11_3",
"Muted_Snare1_3", "Noise_Instrument12_3",
"Triangle3_3", "Noise_Instrument13_3",
"Muted_Snare2_3", "Noise_Instrument14_3",
"Muted_Snare3_3", "Noise_Instrument15_3",
"Muted_Snare4_3", "Noise_Instrument16_3",
"Noise_Instrument17_3",
"Noise_Instrument18_3",
"Noise_Instrument19_3",
"Cry00_3", "Cry00_3",
"Cry01_3", "Cry01_3",
"Cry02_3", "Cry02_3",
@ -321,40 +326,40 @@ sfx_names = [
"Slots_Reward", "Slots_Reward",
"Slots_New_Spin", "Slots_New_Spin",
"Shooting_Star", "Shooting_Star",
] ]
headerlist = ( sfx_banks = [
["sfxheaders02.asm", 0x8003, 0x822e], 0x02,
["sfxheaders08.asm", 0x20003, 0x202be], 0x08,
["sfxheaders1f.asm", 0x7c003, 0x7c249], 0x1f,
) ]
def printsfxheaders(filename, address, end, sfxnum): sfx_groups = {
file = open(filename, 'w') 0x02: sfx_names_1,
bank = address / 0x4000 0x08: sfx_names_2,
byte = rom[address] 0x1f: sfx_names_3,
sfx = 1 }
channel = 1
file.write("SFX_Headers_{:02x}::\n".format(bank)) def dump_all_sfx_headers_in_bank(bank, sfx_names, path, i):
file = open(path + "sfxheaders" + str(i) + ".asm", "w")
file.write("SFX_Headers_{}::\n".format(i))
file.write("\tdb $ff, $ff, $ff ; padding\n") file.write("\tdb $ff, $ff, $ff ; padding\n")
while address != end: address = bank * 0x4000 + 3
left = (byte >> 6) + 1 for sfx_name in sfx_names:
file.write("\nSFX_{}:: ; {:02x} ({:0x}:{:02x})\n".format(sfx_names[sfxnum], address, bank, address % 0x4000 + 0x4000)) file.write("\nSFX_{}::\n".format(sfx_name))
while left != 0: file.write("\taudio_header SFX_{}".format(sfx_name))
pointer = rom[address + 2] * 0x100 + rom[address + 1] num_channels = (rom[address] >> 6) + 1
if byte >> 4 != 0: file.write(" db ( ${:0x}0 | CH{:0x} )\n".format(byte >> 4, byte % 0x10)) for channel in range(num_channels):
else: file.write("\tdb CH{:0x}\n".format(byte)) file.write(", Ch{}".format(rom[address] % 0x10 + 1))
file.write("\tdw SFX_{}_Ch{}\n".format(sfx_names[sfxnum], channel))
address += 3 address += 3
byte = rom[address] file.write("\n")
channel += 1 file.close()
left -= 1
channel = 1
sfx += 1
sfxnum += 1
#file.write("\n; {}".format(hex(address)))
return sfxnum
sfxnum = 0 def dump_all_sfx_headers(path):
for header in headerlist: import os
sfxnum = printsfxheaders(header[0], header[1], header[2], sfxnum) os.makedirs(path, exist_ok=True)
for i, bank in enumerate(sfx_banks):
dump_all_sfx_headers_in_bank(bank, sfx_groups[bank], path, i + 1)
if __name__ == "__main__":
dump_all_sfx_headers("audio/headers/")