Program request: program that interleaves bytes from 2 files

You can talk about almost anything that you want to on this board.

Moderator: Moderators

Post Reply
User avatar
Drew Sebastino
Formerly Espozo
Posts: 3503
Joined: Mon Sep 15, 2014 4:35 pm
Location: Richmond, Virginia

Program request: program that interleaves bytes from 2 files

Post by Drew Sebastino » Wed Jan 24, 2018 4:47 pm

Basically the title. I had somebody make me a program to separate a file into two files byte by byte for the purpose of working with the Irem M92. I'm curious about looking into Gunforce II with IDA Pro, which is why I need to interleave files, because I was looking into the game's cut 4 player mode. What's interesting is that there's actually blank space in ram the size of that used by player 1 and 2. In addition, writing to what would be the x and y values of each character copies the value into memory near it as to store last frame's x and y position, just like what is done with player 1 and 2. It appears they got pretty far into implementing a 3rd and 4th player before dropping them.

I'd like to be trying to see if I can get sprites to work on the system, but I still haven't found a good deal on eBay so I won't be able to test it in on real hardware. :| Major Title 2 going for over $300 is simply insane.

Unrelated, but I have gotten a lot of my old SNES code to work with an object table being offset by direct page, so there's that. I also got a github for something unrelated, but it might encourage me to work a little harder on the SNES so I can post something presentable. :lol:

User avatar
freem
Posts: 163
Joined: Mon Oct 01, 2012 3:47 pm
Location: freemland (NTSC-U)
Contact:

Re: Program request: program that interleaves bytes from 2 f

Post by freem » Wed Jan 24, 2018 5:20 pm

Seems like romwak can do what you're asking for. The "Byte Merge Two Files (/m)" option in particular.

User avatar
Drew Sebastino
Formerly Espozo
Posts: 3503
Joined: Mon Sep 15, 2014 4:35 pm
Location: Richmond, Virginia

Re: Program request: program that interleaves bytes from 2 f

Post by Drew Sebastino » Wed Jan 24, 2018 7:35 pm

Thanks; it worked. :) I figured there might already be a program like this.

User avatar
Zutano
Posts: 38
Joined: Tue Apr 04, 2017 1:22 pm
Location: Ohio, USA
Contact:

Re: Program request: program that interleaves bytes from 2 f

Post by Zutano » Wed Jan 24, 2018 8:51 pm

I know a lot of people here like to use Python as a general-purpose tool for things like this.

Here's just a few lines that will accomplish the task:

Code: Select all

with open('first_file_name.bin', 'rb') as infile1, open('second_file_name.bin', 'rb') as infile2, open('output_file_name.bin', 'wb') as outfile:
	
	interleave = zip(infile1.read(), infile2.read())
	
	for byte1, byte2 in interleave:
		
		outfile.write(byte1)
		outfile.write(byte2)
http://zutanogames.com/ <-- my dev blog

User avatar
Drew Sebastino
Formerly Espozo
Posts: 3503
Joined: Mon Sep 15, 2014 4:35 pm
Location: Richmond, Virginia

Re: Program request: program that interleaves bytes from 2 f

Post by Drew Sebastino » Wed Jan 24, 2018 9:58 pm

@Zutano The only programming languages I know are 65816 and 80186 assembly. I'm not very interested in high level programming and haven't run into enough situations were learning a high level programming language would help me. I don't plan on making this my profession.

I don't know if any of you are familiar with IDA Pro, but for whatever reason, it's refusing to run what MAME debugger is clearly showing as code; the reset vector points straight to here.
MAME debugger.jpg
You can see I'm at the same spot in the hex viewer; that whole section is highlighted because it thinks that information should be grouped for some reason.
IDA Pro hex view.jpg
Here's the code file if anyone wants to figure out how to get it to work:
Gunforce II code.bin
(512 KiB) Downloaded 82 times
Edit: I fixed it; All I had to do was uncheck "load as code segment" upon opening the file to make it stop grouping everything, which let it start at 0xE734 and disassemble correctly. There's only a handful of routines it found; I'm guessing it couldn't find any of the object routines because they aren't exactly trivial to find, in that you don't access them in an "if/else" way.

93143
Posts: 1146
Joined: Fri Jul 04, 2014 9:31 pm

Re: Program request: program that interleaves bytes from 2 f

Post by 93143 » Wed Jan 24, 2018 11:45 pm

Espozo wrote:I'm not very interested in high level programming and haven't run into enough situations were learning a high level programming language would help me.
I have. Graphics and data preparation for SNES programs. It's extremely useful to be able to use (say) Matlab to convert graphics, compile HDMA tables, optimize tricks like HDMA palette expansion and lossy packed-pixel Mode 7 that take a substantial amount of compute time on a Pentium 4... Even for audio, every now and then I encounter something my collection of audio processing tools doesn't do, and it's Matlab to the rescue. If you don't want to pay for Matlab, NumPy (an offshoot of Python) may offer similar capabilities. Octave is basically free Matlab, but it's not quite the same and I've had trouble with colour depth support...

The task you started the thread over would be utterly trivial in Matlab or a similar language, and they tend to be far more user-friendly and OS-independent than C and its relatives.

...

On the other hand, I've been familiar with high-level programming for nearly two decades now, and with Matlab specifically for most of that time, so it's easy to just whip up a routine. If what you want to do can be done well enough with existing tools, the entry barrier might be too high to be worth it. (I haven't gotten far enough in SNES programming to have a good idea of what can be accomplished without custom tools. The M92 situation is probably worse, but without a baseline, that doesn't mean much.)

User avatar
mikejmoffitt
Posts: 1349
Joined: Sun May 27, 2012 8:43 pm

Re: Program request: program that interleaves bytes from 2 f

Post by mikejmoffitt » Thu Jan 25, 2018 2:38 pm

https://github.com/Mikejmoffitt/romtools

bsplit does exactly this (splits / combines odd/even files)

Build it:

Code: Select all

gcc bsplit.c -o bsplit -O3
Combining / interleaving two files:

Code: Select all

bsplit c in.even in.odd out.full
Splitting one into two files:

Code: Select all

bsplit c in.full out.even out.odd
If you are working with patching a game and trying it in MAME, I recommend you make a makefile and do the work using a simple build system to make iterative testing easier. Here is an example.

User avatar
Drew Sebastino
Formerly Espozo
Posts: 3503
Joined: Mon Sep 15, 2014 4:35 pm
Location: Richmond, Virginia

Re: Program request: program that interleaves bytes from 2 f

Post by Drew Sebastino » Thu Jan 25, 2018 5:16 pm

mikejmoffitt wrote:bsplit does exactly this (splits / combines odd/even files)
Romawk is working fine for me though; I've already made a number of batch files for using it.
mikejmoffitt wrote:If you are working with patching a game and trying it in MAME, I recommend you make a makefile and do the work using a simple build system to make iterative testing easier. Here is an example.
What does this do?

I opened up the file in IDA Pro, but it didn't really find shit, so I've tried to set watchpoints for the controller inputs in MAME debugger, but I can't figure out how to set them for the read port address space, which is where the controller registers are located.

User avatar
mikejmoffitt
Posts: 1349
Joined: Sun May 27, 2012 8:43 pm

Re: Program request: program that interleaves bytes from 2 f

Post by mikejmoffitt » Fri Jan 26, 2018 12:42 pm

Espozo wrote:
mikejmoffitt wrote:bsplit does exactly this (splits / combines odd/even files)
Romawk is working fine for me though; I've already made a number of batch files for using it.
mikejmoffitt wrote:If you are working with patching a game and trying it in MAME, I recommend you make a makefile and do the work using a simple build system to make iterative testing easier. Here is an example.
What does this do?

I opened up the file in IDA Pro, but it didn't really find shit, so I've tried to set watchpoints for the controller inputs in MAME debugger, but I can't figure out how to set them for the read port address space, which is where the controller registers are located.
If IDA can't find anything, first make sure you've given it the right entry point. If it can't make any sense of that code, then you should make sure you haven't incorrectly interleaved your files.

You want

Code: Select all

wpiset
for the IO port address space.

If you are making any changes, you are going to get tired of using a hex editor and hand assembling, or manually writing over sections to patch. You should use an assembler, binclude the original program file, and use org to set your location to patch over. That is exactly what the project I linked you to does. The readme is detailed in describing the intent, and the patch file is commented.

User avatar
Drew Sebastino
Formerly Espozo
Posts: 3503
Joined: Mon Sep 15, 2014 4:35 pm
Location: Richmond, Virginia

Re: Program request: program that interleaves bytes from 2 f

Post by Drew Sebastino » Mon Jan 29, 2018 1:34 am

Sorry for the late reply; school work got in the way.
mikejmoffitt wrote:If IDA can't find anything, first make sure you've given it the right entry point. If it can't make any sense of that code, then you should make sure you haven't incorrectly interleaved your files.
They're interleaved correctly, and I did find the correct entry point by using the MAME disassembler. It's just that for some reason, with some games I've opened up, IDA is innable to find more than four routines for whatever reason. There are some routines that I have no idea how it could find them; for example, ones where the CPU jumps to a memory address defined by somewhere in ram, like what I'm doing in my object routine for my SNES game engine.
mikejmoffitt wrote:for the IO port address space.
Thanks! :) However, I did now realize that I could have just set a watchpoint for values in ram that I know are being used by the different players... :roll:

User avatar
Drew Sebastino
Formerly Espozo
Posts: 3503
Joined: Mon Sep 15, 2014 4:35 pm
Location: Richmond, Virginia

Re: Program request: program that interleaves bytes from 2 f

Post by Drew Sebastino » Sun Feb 04, 2018 3:30 pm

Do you know if there is a way to have MAME use more controllers for a game than it normally does? I don't know why I'm asking this just now... (The registers are 0x06 and 0x07 of the IO address space)

Something that's bizarre, is that for whatever reason, the game reads the value for each controller register, and then copies it to five non-continuous areas in ram, which makes debugging a lot more annoying. The two guns that you carry count as separate objects, and the relationship between them and the body is also really bizarre, which is also unfortunate. :|

I did find how to freeze the time though, so I don't have to worry about it running out. :lol:

Post Reply