def convert_mslugx(input, output):

    # Same ROMs for MVS/AES

    # wrong CRC
    output.createFile(
        "p1.p1",
        getAsymmetricPart(input.regions['P'].data, 0 * KILOBYTE,
                          1024 * KILOBYTE))

    # correct CRC
    output.createFile(
        "p2.ep1",
        getAsymmetricPart(input.regions['P'].data, 1024 * KILOBYTE,
                          4 * 1024 * KILOBYTE))
    output.createFile("m1.m1", input.regions['M'].data)
    output.createFile(
        "v1.v1",
        getAsymmetricPart(input.regions['V1'].data, 0 * 1024 * KILOBYTE,
                          4 * 1024 * KILOBYTE))
    output.createFile(
        "v2.v2",
        getAsymmetricPart(input.regions['V1'].data, 4 * 1024 * KILOBYTE,
                          4 * 1024 * KILOBYTE))
    output.createFile(
        "v3.v3",
        getAsymmetricPart(input.regions['V1'].data, 8 * 1024 * KILOBYTE,
                          2 * 1024 * KILOBYTE))
    output.createFile("s1.s1", input.regions['S'].data)
    convert_common_c(input, output, 3)
def convert_kof98h(input, output):

    # wrong CRC for kof98h (MVS/AES), but works
    # kof98 (MVS) has encrypted code
    # to be able to play this as "kof98" in mame, we would need to encrypt this ROM, reversing: https://github.com/ColumPaget/gngeo-cjp/blob/master/src/neocrypt.c
    output.createFile(
        "pn1.p1",
        getAsymmetricPart(input.regions['P'].data, 0 * KILOBYTE,
                          1024 * KILOBYTE))

    output.createFile(
        "p2.sp2",
        getAsymmetricPart(input.regions['P'].data, 1024 * KILOBYTE,
                          4 * 1024 * KILOBYTE))

    # used for kof98 (MVS), correct CRC!
    # output.createFile("m1.m1", input.regions['M'].data)

    # used for kof98h (MVS/AES). wrong CRC!
    output.createFile("mg1.m1", input.regions['M'].data)

    split_region(input, output, 'V1', ['v1.v1', 'v2.v2', 'v3.v3', 'v4.v4'])

    output.createFile("s1.s1", input.regions['S'].data)

    convert_common_c(input, output, 4)
def convert_shocktr2(input, output):

    # Same ROM for MVS/AES
    # Shipped with AES roms
    # All roms except P2 has correct checksum

    output.createFile(
        "p1.p1",
        getAsymmetricPart(input.regions['P'].data, 0 * KILOBYTE,
                          1024 * KILOBYTE))
    output.createFile(
        "p2.sp2",
        getAsymmetricPart(input.regions['P'].data, 1024 * KILOBYTE,
                          4 * 1024 * KILOBYTE))

    output.createFile("m1.m1", input.regions['M'].data)

    output.createFile(
        "v1.v1",
        getAsymmetricPart(input.regions['V1'].data, 0 * 1024 * KILOBYTE,
                          4 * 1024 * KILOBYTE))
    output.createFile(
        "v2.v2",
        getAsymmetricPart(input.regions['V1'].data, 4 * 1024 * KILOBYTE,
                          4 * 1024 * KILOBYTE))
    output.createFile(
        "v3.v3",
        getAsymmetricPart(input.regions['V1'].data, 8 * 1024 * KILOBYTE,
                          2 * 1024 * KILOBYTE))

    output.createFile("s1.s1", input.regions['S'].data)

    convert_common_c(input, output, 3)
def convert_shocktro(input, output):

    # Shipped with AES BIOS
    # All file except pg1.p1 has correct CRC.
    # The AES and MVS original has different P1s, the VC version matches none of them,
    # so not sure if the VC version is based of the MVS or AES version.

    output.createFile(
        "pg1.p1",
        getAsymmetricPart(input.regions['P'].data, 0, 1 * 1024 * KILOBYTE))

    output.createFile(
        "p2.sp2",
        getAsymmetricPart(input.regions['P'].data, 1024 * KILOBYTE,
                          4 * 1024 * KILOBYTE))

    output.createFile("m1.m1", input.regions['M'].data)

    output.createFile(
        "v1.v1",
        getAsymmetricPart(input.regions['V1'].data, 0 * KILOBYTE,
                          4 * 1024 * KILOBYTE))
    output.createFile(
        "v2.v2",
        getAsymmetricPart(input.regions['V1'].data, 4 * 1024 * KILOBYTE,
                          2 * 1024 * KILOBYTE))

    output.createFile("s1.s1", input.regions['S'].data)

    convert_common_c(input, output, 4)
def convert_mslug3(input, output):

    # Comes with AES bios

    # TODO:
    # - The original game's C rom is encrypted, the Virtual Console version is not encrypted. Do we have to encrypt the bugger to get it playable in mame??
    # - The P roms are different (9 MB in Wii version, 4 MB + 4 MB + 256 KB in arcade versions, 1 MB + 4 MB in home version)

    # TODO: mame does not use this.
    output.createFile("p1.p1", input.regions['P'].data)

    # TODO: mame does not use this
    output.createFile("s1.s1", input.regions['S'].data)

    #v1 and m1 hash matches mslug3, mslug3a, mslug3h.
    output.createFile("m1.m1", input.regions['M'].data)
    split_region(input, output, 'V1', ['v1.v1', 'v2.v2', 'v3.v3', 'v4.v4'])

    #correct checksum for a rom only found in "mslug3", file not used in home version
    output.createFile(
        "green.neo-sma",
        getAsymmetricPart(input.regions['P'].data, 3 * 256 * KILOBYTE,
                          256 * KILOBYTE), None, False)

    # not correct - game does not run, bad crcs. probably mame wants the encrypted file, the VC versions are decrypted
    output.createFile(
        "pg1.p1",
        getAsymmetricPart(input.regions['P'].data, 1 * 1024 * KILOBYTE,
                          4 * 1024 * KILOBYTE))
    output.createFile(
        "pg2.p2",
        getAsymmetricPart(input.regions['P'].data, 5 * 1024 * KILOBYTE,
                          4 * 1024 * KILOBYTE))

    # if ran as mslug3h (home version), the game kind of starts, but reboots after main menu. home version
    # Note, home version only has 1+4MB P, while arcade has 4+4 mb + the green file. The VC version has 9 MB P ROM.
    output.createFile(
        "ph1.p1",
        getAsymmetricPart(input.regions['P'].data, 1 * 1024 * KILOBYTE,
                          1 * 1024 * KILOBYTE))
    output.createFile(
        "ph2.sp2",
        getAsymmetricPart(input.regions['P'].data, 5 * 1024 * KILOBYTE,
                          4 * 1024 * KILOBYTE))

    # C files are not correct, they are decrypted but mame expects encrypted version.
    convert_common_c(input, output, 4)

    print("This game is NOT correctly exported yet")
def convert_mslug4(input, output):

    # wrong checksum for both MVS and AES, but seems to work
    output.createFile(
        "p1.p1",
        getAsymmetricPart(input.regions['P'].data, 0 * KILOBYTE,
                          1024 * KILOBYTE))

    # correct CRC for MVS version, not for AES version
    output.createFile(
        "p2.sp2",
        getAsymmetricPart(input.regions['P'].data, 1024 * KILOBYTE,
                          4 * 1024 * KILOBYTE))

    split_region(input, output, 'V1', ['v1.v1', 'v2.v2'])

    # Original hardware has decryption hardware for S, M and C, which MAME emulates.
    # Hence MAME and original hardware expects encrypted ROMs.
    # Wii comes with decrypted ROMs.
    # We need to encrypt them to make them playable with MAME.

    # C ROM (includes S ROM)
    if input.regions['C'].data[0:3] == b'ACM':
        data = neogeo_acm.decompressAcm(input.regions['C'].data)
    else:
        data = input.regions['C'].data

    # key found in https://github.com/mamedev/mame/blob/master/src/devices/bus/neogeo/prot_cmc.h
    convert_c(neogeo_cmc.encrypt_cmc50_gfx(data, 0x31), output, 3,
              [[0, 2], [1, 3]])

    # Note: MAME does additional unscrambling of the S part at the end of the C ROM.
    # We do not have to scramble it, because the decrypted Wii C ROM version already contains the
    # scrambled S portion. (The Wii version ALSO contains this as an separate unscrambled S ROM, which
    # we ignore)

    # TODO: M is not decrypted yet. No audio and probably cause crash during early gameplay
    output.createFile("m1.m1", input.regions['M'].data)

    # TODO: SFIX, maybe other roms are missing or have wrong CRC

    print("This game is NOT correctly exported yet")
def convert_rbffspec(input, output):

    # Same ROM for MVS/AES
    # p1 rom has wrong checksum, all others have correct checksum

    output.createFile(
        "p1.p1",
        getAsymmetricPart(input.regions['P'].data, 0 * KILOBYTE,
                          1024 * KILOBYTE))
    output.createFile(
        "p2.sp2",
        getAsymmetricPart(input.regions['P'].data, 1024 * KILOBYTE,
                          4 * 1024 * KILOBYTE))

    output.createFile("m1.m1", input.regions['M'].data)

    split_region(input, output, 'V1', ['v1.v1', 'v2.v2', 'v3.v3'])

    output.createFile("s1.s1", input.regions['S'].data)

    convert_common_c(input, output, 4)
def convert_mslug2(input, output):

    # Same ROM for MVS/AES
    # CRC is incorrect for p*, otherwise all CRCs match
    # Shipped with MVS BIOS

    output.createFile(
        "p1.p1",
        getAsymmetricPart(input.regions['P'].data, 0 * KILOBYTE,
                          1024 * KILOBYTE))
    output.createFile(
        "p2.sp2",
        getAsymmetricPart(input.regions['P'].data, 1024 * KILOBYTE,
                          2 * 1024 * KILOBYTE))

    output.createFile("m1.m1", input.regions['M'].data)

    split_region(input, output, 'V1', ['v1.v1', 'v2.v2'])

    output.createFile("s1.s1", input.regions['S'].data)

    convert_common_c(input, output, 2)
def convert_lastbld2(input, output):

    # Same ROM for MVS/AES
    # Shipped with AES BIOS

    # All roms except PG1 have correct checksums

    output.createFile(
        "pg1.p1",
        getAsymmetricPart(input.regions['P'].data, 0 * KILOBYTE,
                          1024 * KILOBYTE))
    output.createFile(
        "pg2.sp2",
        getAsymmetricPart(input.regions['P'].data, 1024 * KILOBYTE,
                          4 * 1024 * KILOBYTE))

    output.createFile("m1.m1", input.regions['M'].data)

    split_region(input, output, 'V1', ['v1.v1', 'v2.v2', 'v3.v3', 'v4.v4'])

    output.createFile("s1.s1", input.regions['S'].data)

    convert_common_c(input, output, 3)
def convert_kotm(input, output):

    #Not 100% sure this is the MVS version (kotm) or AES version (kotmh).
    #P1 ROM has wrong checksom for both kotm (p1.p1) and kotmh (hp1.p1). All other files have correct checksum for both.
    #Shipped with MVS BIOS, so assuming it is the MVS version.

    output.createFile(
        "p1.p1",
        getAsymmetricPart(input.regions['P'].data, 0 * KILOBYTE,
                          512 * KILOBYTE))
    output.createFile(
        "p2.p2",
        pad(
            getAsymmetricPart(input.regions['P'].data, 512 * KILOBYTE,
                              64 * KILOBYTE), 128 * KILOBYTE))

    output.createFile("m1.m1", input.regions['M'].data)

    split_region(input, output, 'V1', ['v1.v1', 'v2.v2'])

    output.createFile("s1.s1", input.regions['S'].data)

    convert_common_c(input, output, 2)