Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Branch: master
Fetching contributors…

Cannot retrieve contributors at this time

executable file 69 lines (54 sloc) 1.935 kB
#!/usr/bin/env python
# Author: Bryan Cain
# Date: January 22, 2011
# Description: Converts Virtual Console N64 saves to Mupen64Plus N64 saves.
# The save formats used by N64 Virtual Console games were reverse engineered by Bryan Cain.
import os, shutil, struct
# Converts (byte-swaps) Nintendo N64 SRAM and/or Flash RAM saves to little endian
# SRAM and/or Flash RAM saves that can be used by Mupen64Plus and other emulators.
def convert_sram(src, name, size):
# determine output extensions
if size == 32*1024:
ext = '.sra'
elif size == 128*1024:
ext = '.fla'
# copy original file as a big-endian save file
shutil.copy2(src, name+'.be'+ext)
# open files
infile = open(src, 'rb')
outfile = open(name+'.le'+ext, 'wb')
# byte-swap file
while True:
data = infile.read(8192)
if len(data) != 8192:
if len(data) != 0: raise ValueError('SRAM save file size should be a multiple of 8 KB')
break
intdata = struct.unpack('>2048I', data)
outfile.write(struct.pack('<2048I', *intdata))
outfile.close()
infile.close()
# Converts (truncates) Nintendo N64 EEPROM saves to the appropriate size so they
# can be used with Mupen64Plus and other N64 emulators.
def convert_eeprom(src, name):
infile = open(src, 'rb')
outfile = open(name + '.eep', 'wb')
data = infile.read(2048)
if len(data) != 2048: raise ValueError('EEPROM save file size should be at least 2 KB')
outfile.write(data)
outfile.close()
infile.close()
def convert(src, name):
f = open(src, 'rb')
f.seek(0, os.SEEK_END)
size = f.tell()
f.close()
if size in (4*1024, 16*1024): convert_eeprom(src, name)
elif size in (32*1024, 128*1024): convert_sram(src, name, size)
else: raise ValueError('unknown save type (size=%d bytes)' % size)
if __name__ == '__main__':
import sys
if len(sys.argv) != 3:
sys.stderr.write('Usage: %s infile outfile\n' % sys.argv[0])
sys.exit(1)
convert(sys.argv[1], sys.argv[2])
print 'Done'
Jump to Line
Something went wrong with that request. Please try again.