zigg/journal

Saturday, February 7, 2009

Not so much like riding a bicycle

One of the code projects I've wanted to do for a little while now (at least since the release of Daigasso! Band Brothers DX) is a save host for the Nintendo DS. A brief primer, first: unlike with disc- or online-based game systems, software for the DS comes on game cards with the software itself in ROM and some kind of EEPROM or Flash chip for saving. This is tremendously convenient for me, but sometimes I want to either back the save chip's contents up or—more ambitiously—extract and inject parts of the save chip's contents to enable things like content sharing.

I did just this in a fairly roundabout fashion early on in the DS' life with the Daigasso! Band Brothers Save Editor (apologies for the ancient page, there... another one of my someday projects is to update some of that!) But it required you to either use the now-unavailable Action Replay MAX GBA/DS (truly a Frankenstein of devices) or else grab the .sav file from a pirate card—something you can do in at least a morally legitimate fashion if you do own the original game card, though it's still not exactly above-the-level... not to mention I always sort of felt like I was sort of supporting the people who were pirating the game. Plus, if you were using a legitimate game card, you were always rewriting the entire save chip, potentially shortening its life versus the rotating-write strategy that DS games often take with their saves.

My savehost program is going to be a better way of doing this all-around, I think. You still do need to be able to boot my code on your DS, though there are non-piracy-enabling options for getting this done. Once runing, savehost will associate with your local wireless access point, display its IP, and then open up a TCP service. Key this IP address into a PC-side client program, and the client will be able to get details about the onboard chip and read and write portions of it. Barring new and interesting save chips (like we saw with Band Brothers DX, actually), the same savehost should work with all manner of PC-side client applications, allowing people to write tools to deal appropriately with save chips as flexibly as possible.

I did a little bit of this back when Band Brothers DX was new, modifying card.c from devkitPro's libnds to hopefully recognize and be able to work with the new chip. I never finished the server at the time, but recently I decided to jump in and try it again. After a false start a few days back (tip: declaring char buf[65536] is a great way to hang a DS) I stayed up late into the night last night and came up with code that implements at least the "read" portion.

It needs some work, though. I was never particularly good at C, anyway, but not having really used it in about a decade—Python has spoiled me so—I'm very easily tripped up by the little vagaries of being closer to the metal, as it were. I wasted 20 minutes last night on an sscanf call that was missing the s part, for example. Before I turned in, I also posted a plea for help on gbadev in tracking down hangs, and the response I saw this morning is likely absolutely spot-on. I'm just not used to this style of programming anymore; I'm used to code that either does what I ask or throws an exception—not the stuff where I have to check every return.

That said, I'm on the right track, and happy to be there. Recent versions of devkitPro seem to be cleaning up a lot of the really hardware-specific stuff that littered most DS homebrew projects and just served to confuse the heck out of me. Barring any really weird bugs, I think savehost might be something I can formally release before too much longer. I just need to re-learn to pedal this sort of bicycle again.

Labels: ,

posted by zigg 9:32 AM

0 Comments:

Further comments are disabled indefinitely. Here's why.