Odd and even byte files merge software needed

Are you new to 6502, NES, or even programming in general? Post any of your questions here. Remember - the only dumb question is the question that remains unasked.

Moderator: Moderators

Post Reply
User avatar
jpx72
Posts: 178
Joined: Tue Sep 28, 2010 3:27 am
Location: Slovakia
Contact:

Odd and even byte files merge software needed

Post by jpx72 »

Can anyone help with fiding a software that can combine two files that were dumped from two eproms that contained one even and the other odd bytes? Thanks!
lidnariq
Posts: 10677
Joined: Sun Apr 13, 2008 11:12 am
Location: Seattle

Re: Odd and even byte files merge software needed

Post by lidnariq »

jpx72 wrote:Can anyone help with fiding a software that can combine two files that were dumped from two eproms that contained one even and the other odd bytes? Thanks!
http://www.lucasforums.com/showpost.php?p=2794290 mentions that WinHex can do this (context: interleaving the MT32 control program from its two 8-bit ROMs) It's also a perl one-liner or C two-liner.
User avatar
thefox
Posts: 3139
Joined: Mon Jan 03, 2005 10:36 am
Location: Tampere, Finland
Contact:

Re: Odd and even byte files merge software needed

Post by thefox »

In Python:

Code: Select all

import io
even = io.open( "even.bin", "rb" ).read()
odd = io.open( "odd.bin", "rb" ).read()
interleaved = "".join( i for j in zip( even, odd ) for i in j )
io.open( "interleaved.bin", "wb" ).write( interleaved )
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: fo.aspekt.fi
User avatar
jpx72
Posts: 178
Joined: Tue Sep 28, 2010 3:27 am
Location: Slovakia
Contact:

Re: Odd and even byte files merge software needed

Post by jpx72 »

Thank you guys! The Winhex (winhex.com) did it (Tools > File tools -> Unify -> Bytewise)!
User avatar
qbradq
Posts: 952
Joined: Wed Oct 15, 2008 11:50 am

Re: Odd and even byte files merge software needed

Post by qbradq »

Python FTW :D
User avatar
koitsu
Posts: 4203
Joined: Sun Sep 19, 2004 9:28 pm
Location: A world gone mad

Re: Odd and even byte files merge software needed

Post by koitsu »

qbradq wrote:Python FTW :D

Code: Select all

interleaved = "".join( i for j in zip( even, odd ) for i in j )
i for j in zip() for i in j

Surely I can't be the only one looking at that going "what the fuck?" So the next time someone tells me Perl is hard to read, I'm going to point them to that line there. I had a discussion with a fellow programmer last night about that line; he broke it down for me (which helped make more sense out of it), and stated boldly in agreement that yes the syntax is utterly retarded. For those still unable to comprehend the clusterfuck, quoting my peer:
you have to read it kind of funny. it's equivalent to

Code: Select all

for j in zip(even, odd):
     for i in j:
         i
the return values get built up into an unnamed list, which becomes the argument to join. the syntax is dumb but the concept is really simple
http://wemeantwell.com/blog/wp-content/ ... up_ass.jpg
tepples
Posts: 22345
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Odd and even byte files merge software needed

Post by tepples »

It's not that Python has no warts; it just has far fewer than, say, PHP.
User avatar
thefox
Posts: 3139
Joined: Mon Jan 03, 2005 10:36 am
Location: Tampere, Finland
Contact:

Re: Odd and even byte files merge software needed

Post by thefox »

I actually agree, most of the time I'd write it in a more verbose way.
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: fo.aspekt.fi
Post Reply