Python UPS library, v0.1

Announce new emulators, discuss which games run best under each emulator, and much much more.

Moderator: General Mods

Post Reply
Thristian
Hazed
Posts: 76
Joined: Tue Feb 07, 2006 11:02 am

Python UPS library, v0.1

Post by Thristian »

For lack of a general byuu-fanboy board, or a UPS-specific board, I guess I'll post here.

As a Fun Weekend Project, I decided to write an implementation of byuu's UPS patch format in Python.

Download: upspatch-0.1.tar.gz

Currently, the library supports reading patch-files in from disk, writing them out, and applying a patch to a file, with all the CRC-checking and file-validation. It does not yet support creating UPS files, nor does it come with a command-line tool, so for the moment you have to write your own Python code to use it; something like this:

Code: Select all

import upspatch

p = upspatch.patchFromFile('dl-1.02/dl.ups')
p.apply("dl.sfc", "dl-eng.sfc")
I had two goals when writing this code: firstly, to create some UPS code that is simple, readable, and under a widely-accepted open-source licence[1], and secondly, to learn about Python's mmap and array modules and see how fast I could make things. Unfortunately these goals conflicted somewhat - some parts of the code are nicely readable, some parts are strange and confusing for performance reasons.

On the other hand, I can load the Der Langrisser patch, write it out to a new file, patch the original ROM then un-patch the patched ROM all in under 3 seconds on my PowerMac G5 1.6GHz, and my profiler says the single slowest function is the CRC32 function written in C, so I guess I didn't do too badly there.

I've worked on this code about as much as I want to for myself. I'm happy to work on it further if it's of interest or use to other people, but for the moment I'm done.

[1]: Byuu is awesome, but he has a habit of releasing his code under licences he's made up himself with no legal training. For example, in the UPS announcement thread at romhacking.net, he says the reference UPS implementation is public-domain except if your modified code produces different output. Apart from the problems with 'public domain' licensing in general, I guess this means you can't use it in a tool that creates NINJA patches, or puts UPS patches into a ZIP along with the files it patches, or handles creating patches from multiple sources to a target, or anything else interesting...

By contrast, I've written my code without reading (or even downloading) byuu's reference implementation, so it shouldn't be a derivative work for copyright purposes, and I've released it under the well-known MIT licence so nobody should have any problems using it for their own purposes. That said, please don't use this code to create UPS files that the reference implementation can't read - there's already enough broken file formats in the world, we don't need any more.
grinvader
ZSNES Shake Shake Prinny
Posts: 5632
Joined: Wed Jul 28, 2004 4:15 pm
Location: PAL50, dood !

Re: Python UPS library, v0.1

Post by grinvader »

Thristian wrote:For lack of a general byuu-fanboy board
There is such a board, however I don't see why UPS should be byuu-specific. This stays here.
皆黙って俺について来い!!

Code: Select all

<jmr> bsnes has the most accurate wiki page but it takes forever to load (or something)
Pantheon: Gideon Zhi | CaitSith2 | Nach | kode54
mudlord
has wat u liek
Posts: 559
Joined: Tue Sep 11, 2007 2:54 pm
Location: Banland.

Post by mudlord »

So, this UPS format is a complete replacement to IPS?

I suppose then that patches can't be ported between formats?
That said, I'm considering writing a patcher for those on Windows 95/whatever...
grinvader
ZSNES Shake Shake Prinny
Posts: 5632
Joined: Wed Jul 28, 2004 4:15 pm
Location: PAL50, dood !

Post by grinvader »

mudlord wrote:So, this UPS format is a complete replacement to IPS?
Since it IS better... >_>;
I suppose then that patches can't be ported between formats?
Why would that be ?

Anyway, read the bsnes v0.031 thread, since it's all in it.
皆黙って俺について来い!!

Code: Select all

<jmr> bsnes has the most accurate wiki page but it takes forever to load (or something)
Pantheon: Gideon Zhi | CaitSith2 | Nach | kode54
byuu

Post by byuu »

Whoa, way cool. The more patchers, the better :D
Now we just need some patches, heheh.
As a Fun Weekend Project, I decided to write an implementation of byuu's UPS patch format in Python.
Nach deserves most of the credit for UPS. I just posted a patcher first, which was bad as it had some bugs.

Consequently, didn't realize you were Screwtape from MacScene. Neat.
he has a habit of releasing his code under licences he's made up himself with no legal training. For example, in the UPS announcement thread at romhacking.net, he says the reference UPS implementation is public-domain except if your modified code produces different output. Apart from the problems with 'public domain' licensing in general, I guess this means you can't use it in a tool that creates NINJA patches, or puts UPS patches into a ZIP along with the files it patches, or handles creating patches from multiple sources to a target, or anything else interesting...
Let's be really serious here for a minute. This is the internet. If someone were to take this code, modify it and release it as a UPS patcher, there's absolutely nothing I could do about it. I can't afford to hire a lawyer and sue someone over a file patcher.

The code is public domain through and through, it's really more of a courtesy asking that the file format not be changed. And if it is, hopefully it will be rejected by the community until it is renamed.

As for the public domain "problems", I'm disappointed to see yet another person eschewing that nonsense. If one can create an MIT license and give up all but two of their rights, then one can create another that gives up those last two rights.

Try and name a single court case where a developer posted PD code, someone used it, and was then successfully sued in court for copyright violations.

If multi-million dollar companies use the PD PocketNES in their NES-on-GBA cartridges, then I trust it is safe to use PD code. I trust highly paid lawyers much moreso than a bunch of idealists trying to convince me to use their "free open source" licenses.
mudlord
has wat u liek
Posts: 559
Joined: Tue Sep 11, 2007 2:54 pm
Location: Banland.

Post by mudlord »

Since it IS better... >_>;
Figured as such...

Though since its coming from byuu, shouldn't need to have asked a stupid question.


Why would that be ?
Differences in format?

But bleh, read the thread, explains it all. So all my qualms are sorted,
Thristian
Hazed
Posts: 76
Joined: Tue Feb 07, 2006 11:02 am

Post by Thristian »

byuu wrote:Consequently, didn't realize you were Screwtape from MacScene. Neat.
Yeah, some other crazy had taken my preferred name by the time I got around to registering here. Not that I go to MacScene any more - next time someone says "lots of people are switching from Linux to Mac, but are any switching back?" you can say "Yes, Screwtape did!"... or at least I *will*, once Debian builds a Firefox 3 package. *sigh*
byuu wrote:If one can create an MIT license and give up all but two of their rights, then one can create another that gives up those last two rights.
The page I linked to (the best one I could find) doesn't go into detail about why a 'do what you want' licence is problematic, but I think it gives a clue: "Under basic contract law, a gift cannot be enforced. The donor can retract his gift at any time, for any reason—scant security for someone intending to make long-term use of a piece of software." My (non-lawyerly) understanding is that you can use a licence that exchanges the right to copy and modify the software for the right to warranty, but you can't as easily use a licence that gives away everything.

A more practical objection: the other day I was watching a talk given by the author of SQLite, which is also in the public domain. Apparently, when some European companies wanted to use SQLite, they had to get him to sign a special licence just for them: European copyright law doesn't allow people to give away their automatic copyright, and so it would have been illegal for them to use it without his express permission. If you're going to publish software for everyone to use, you might as well use a universally acceptable licence, instead of one that's only valid for the US.

While licence choice is probably not important in the grand scheme of things... well, I took the time to add comments and internal documentation to help people follow the code, I took the time to tidy up the code and sort it into a sensible structure to help people find the code, I took the time to write a descriptive commit message for each change I made to help people debug the code, and I applied the most well-known licence that matched my intentions, so that people could easily figure out what their rights and responsibilities were. Even if nobody ever uses it but me, I feel those are all part of responsible software craftsmanship.

----

Out of curiosity, how fast does the C++ reference implementation take to apply the Der Langrisser patch, and does it use any fancy tricks like mmap() to speed up file access?
Post Reply