Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Merge hi/low rom pairs
# Merge a pair of hi/low byte roms into a single file
# Usage: <low_or_even_byte_rom> <high_or_odd_byte_rom> >outputfile.bin
open LO, $ARGV[0] || die $!;
open HI, $ARGV[1] || die $!;
while(!(eof(LO) | eof(HI)))
print $a;
print $a;
Copy link

sf2platinum commented Nov 27, 2019

Use this script to merge a pair of even+odd / low+high roms into a single file. You'll need to do this for games which have 16-bit CPUs which use 8-bit ROMs. Then, once you've merged each high/low pair, concatenate all the merged pairs into one single file to use in your disassembler.

To determine the order of ROMs:

  • Look at the MAME source for your machine driver, e.g. src/mame/drivers/cps1.cpp for CPS1 games
  • run mame name_of_game -listxml and examine the offset

Example sf2ua: Street Fighter 2 World Warrior

From the MAME driver source:

ROM_START( sf2ua )
  ROM_REGION( CODE_SIZE, "maincpu", 0 )      /* 68000 code */
  ROM_LOAD16_BYTE( "sf2u_30a.11e", 0x00000, 0x20000, CRC(08beb861) SHA1(d47f16d0d692dc6405df0aecd7d9fc3f9718c0d1) )
  ROM_LOAD16_BYTE( "sf2u_37a.11f", 0x00001, 0x20000, CRC(b7638d69) SHA1(b615a2e0e8772462fd875b2e8d2ccba82a8b3c47) )
  ROM_LOAD16_BYTE( "sf2u_31a.12e", 0x40000, 0x20000, CRC(0d5394e0) SHA1(e1d88ff3669f1dbe1e3fbdf8aa9e2c63adbbcb48) )
  ROM_LOAD16_BYTE( "sf2u_38a.12f", 0x40001, 0x20000, CRC(42d6a79e) SHA1(5f1e2c176d065325883a60767d05b1a542372b6a) )
  ROM_LOAD16_BYTE( "sf2u_28a.9e",  0x80000, 0x20000, CRC(387a175c) SHA1(2635bb82758cf217cee63b254a537b02275a6838) )
  ROM_LOAD16_BYTE( "sf2u_35a.9f",  0x80001, 0x20000, CRC(a1a5adcc) SHA1(47874e6d403256d828474b29e3d93c92efd9e1ce) )
  ROM_LOAD16_BYTE( "sf2_29b.10e",  0xc0000, 0x20000, CRC(bb4af315) SHA1(75f0827f4f7e9f292add46467f8d4fe19b2514c9) )
  ROM_LOAD16_BYTE( "sf2_36b.10f",  0xc0001, 0x20000, CRC(c02a13eb) SHA1(b807cc495bff3f95d03b061fc629c95f965cb6d8) )

From the output of mame sf2ua -listxml

  <rom name="sf2u_30a.11e" size="131072" crc="08beb861" sha1="d47f16d0d692dc6405df0aecd7d9fc3f9718c0d1" region="maincpu" offset="0"/>
  <rom name="sf2u_37a.11f" size="131072" crc="b7638d69" sha1="b615a2e0e8772462fd875b2e8d2ccba82a8b3c47" region="maincpu" offset="1"/>
  <rom name="sf2u_31a.12e" size="131072" crc="0d5394e0" sha1="e1d88ff3669f1dbe1e3fbdf8aa9e2c63adbbcb48" region="maincpu" offset="40000"/>
  <rom name="sf2u_38a.12f" size="131072" crc="42d6a79e" sha1="5f1e2c176d065325883a60767d05b1a542372b6a" region="maincpu" offset="40001"/>
  <rom name="sf2u_28a.9e" size="131072" crc="387a175c" sha1="2635bb82758cf217cee63b254a537b02275a6838" region="maincpu" offset="80000"/>
  <rom name="sf2u_35a.9f" size="131072" crc="a1a5adcc" sha1="47874e6d403256d828474b29e3d93c92efd9e1ce" region="maincpu" offset="80001"/>
  <rom name="sf2_29b.10e" merge="sf2_29b.10e" size="131072" crc="bb4af315" sha1="75f0827f4f7e9f292add46467f8d4fe19b2514c9" region="maincpu" offset="c0000"/>
  <rom name="sf2_36b.10f" merge="sf2_36b.10f" size="131072" crc="c02a13eb" sha1="b807cc495bff3f95d03b061fc629c95f965cb6d8" region="maincpu" offset="c0001"/>

To merge these together: sf2u_30a.11e sf2u_37a.11f >rom_00000.bin sf2u_31a.12e sf2u_38a.12f >rom_40000.bin sf2u_28a.9e sf2u_35a.9f >rom_80000.bin sf2_29b.10e sf2_36b.10f >rom_c0000.bin
cat rom_* >sf2ua_all.bin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment