Category: Programming

ROM Checksums and Headers

NES ROM header

Lately I’ve been futzing around with classic game ROMs a bit more. Since nearly day one of Nesticle hitting the Internet, I’ve been obsessed with emulation of classic computer systems. I love playing old video games, and I love learning more about the internals of the systems I cut my teeth on back in the day.

But this post isn’t about nostalgia; it’s about organizing games, specifically ROM files. While I’m fairly certain I’ve got several discs (and old HDDs) filled with variously-complete ROM sets for various platforms, these were mostly collected from newsgroups waaay back in the day and as a result have a wide variety of headers, possible trainers, and intros. Nowadays, even the Internet Archive maintains full sets of “no-intro” ROMs donated by people who stayed in the scene far longer than I did.

If you intend to organize such a non-trivial amount of games, you’re gonna need some ROM utilities. The most well-known of these are clrmamepro, RomCenter, and RomVault. I’m sure there are others, but these are the big players. I’m not really going to speak about their various strengths/weaknesses, as that’s a little outside the scope of this post.

What I actually want to discuss is how checksums are calculated using the “datfiles” provided by the No-Intro site’s users. I had a hard time finding this information initially, so I’m putting it here for anyone else. Also, if I’m wrong, I’d love to be called out and told what I’m doing wrong.

I’m using the following:

I only found the clrmamepro iNES header config far later than the rest of this info. This specific file is fairly sparse, and only has the following:

<detector>
<name>No-Intro NES Dat iNES Header Skipper</name>
<author>Yakushi~Kabuto</author>
<version>20070321</version>
<rule start_offset="10">
<data offset="0" value="4E4553"/>
</rule>
</detector>

Basically, take this to mean we’re starting at offset 0x10 and reading to EOF (NES files aren’t larger than 0x4e4553 bytes). Once I did this, my CRC32 checks started working. I’d normally stop there, but it looks like my MD5 and SHA-1 hashes are wrong. Adding the entire file back in fixes this, so…I’m not really sure why we’re bothering to trim the header for only one check.

To sum up:

CRC32 – 0x10 through EOF
MD5 – entire file
SHA-1 – entire file

Comments

Let’s Get Cuddly! (or not, I’m not judging)

As a personal preference, I’m a fan of cuddly braces. It’s the way I learned, but I feel like it leads to more concise and readable code in most cases. I could go on, but as a topic it’s been beaten to death, and there are arguments with merit on both sides.

That being said, at work we use newline braces, and I don’t like it. A good programmer follows the in-place coding style, so that’s what I’ve been doing. It doesn’t mean I have to like it, though. While I use a separate installation of Visual Studio on an entirely different computer for coding my personal projects, there are times where I’d like to not have to completely switch machines to bang out some lines of code.

After reading that you can export and import Visual Studio settings, I created two settings files trimmed down to only include indentation and newline settings, so now I can simply import a settings file and all the rules I want changed are changed.

Feel free to edit the below files to your needs:

VS_Personal.vssettings (3.6k) – Cuddly style
VS_Work.vssettings (3.6k) – Non-cuddly style (braces on newlines)

These are only for Visual Studio, though. I’ve got nothing to offer for other editors, but feel free to contribute settings files for any other IDE.

Comments

PHP PDF Libraries

PDFs are easy! Like riding a...oh.

PDFs are easy! Like riding a…oh.

I wanted to do something I figured would be relatively simple. After all, we’re doing it in .Net with a third-party library: Create a PDF with text from a database with vector graphics incorporated in the page. Turns out, it’s pretty easy if you want a paid solution; numerous libraries exist for PHP that are non-free. If you insist on going free-only though, be warned: here be dragons (maybe).

Continue reading this entry ▶

Comments

SimpLESS: An Easier Way of Getting LESS Done

LESS

When I first took a look at LESS as a CSS replacement, I wasn’t too interested in having even a command-line compiler. The idea of having my stylesheet loaded and parsed by Javascript didn’t sound that great either, but tolerable if it saved me enough time and effort writing CSS.

SimpLESSWhile testing LESS on my local server, I used less.js to process my .less stylesheet on the client side. It worked well, and on modern browsers the processing time is minimal, but I decided to look around for LESS compilers anyway. I discovered SimpLESS nearly immediately, and it looked perfect.

Compiling a .less file is as easy as drag-and-drop, and it monitors the file for changes. When your file is saved, it is nearly immediately compiled into a CSS file. If you’ve made an error in your file, the file highlights red and specifies the line number at which the problem occurred. Output is pure, minified CSS goodness.

SimpLESS, by default, inserts a comment at the top referring to its website. This can easily be disabled if you like.

When I first started using SimpLESS, I was copying and pasting the output into a WordPress template style.css file, which requires a properly-formatted comment at the top to describe the theme. Since SimpLESS performs minification, comments are stripped out. I thought this was the only way to keep my WordPress theme comment intact while still using the features of LESS. This copy-paste tedium was something I specifically wanted to avoid in the first place.

Note: The remainder of this post was written before SimpLESS users complained enough about this very issue, so theme comment preservation is no longer an issue.

I thought that there must be some way to preserve a comment when compiling. Surely that wasn’t an uncommon use case? I checked out the SimpLESS source code to see how it was performing its minification (master/Resources/js/clean_css.js, line 30 if you’re interested), and saw they included a special character to preserve certain comments: the exclamation mark.

To preserve a CSS comment in SimpLESS (not that this will not work using the Javascript version, as WordPress will not find a style.less file), simply put an exclamation point after the initial comment delimiter, like so:

/*!
Theme Name: My Super-Cool Theme
Theme URI: https://www.pixelbath.com/
Description: Blah blah blah...
[cut for length]
*/

The exclamation point is ignored by WordPress, and if you have SimpLESS processing your style.less file, you can continue to upload your theme’s style.css file as usual.

Comments

Generative Art: Google Logo

I’ve been impressed with what the Processing community does with generative art, and Actionscript seems to be at a point where it can be used much like Processing. In that vein, I’ve been watching Mark Knol’s generative art for a while, and while I wanted to do something like it, I’ve never actually bothered to create sit down and start coding it up.

Today, I tried to recreate his work on the Google logo. While mine doesn’t seem to have as much depth or chaos, I think it turned out fairly well. With some tweaking, I could improve it, but for now I just wanted to put something out there.

Hope you like it!

Great Googly Moogly!

Great Googly Moogly!

Comments

Block Windows Live Messenger Ads

All your ads are belong to us

All your ads are belong to us

Earlier, we learned how to block ads at the OS level. Blocking ads through the browser is awesome, but advertising these days is all about making inroads to the desktop. Even though Microsoft claims that their business is software, Live Messenger seems to be an ad vehicle. I quickly became tired of video ads constantly showing up in Live Messenger (especially those insipid Tru dating site ads) that would play as soon as the cursor went over them, so I resolved to do something about it. I fired up Fiddler, a proxy that allows you to view HTTP traffic. I saw several random requests for rad.msn.com, and upon further examination saw that it was serving ad content, which depending on the content type, would be handled appropriately by Live Messenger’s ad box.

I added rad.msn.com to my hosts file, and the ads were now blocked. Since there was now a blank box, I decided to go a step further and replace the image. I tried this before with a program that patched the ad out of the executable, but this isn’t a long-term solution, since any software update will require waiting on a new version of the patcher, and a subsequent re-patching. If I just serve a different image up, it’s fairly future-proof because Messenger is one the wiser. No matter what subdirectory or file is being requested by Messenger, this script will always throw back the custom image.

Using the index.php file we ended up with on our last ad-blocking adventure, we will add the following before the html is sent to the browser:

// if it's live messenger, spit out an image and exit
if ($host == 'rad.msn.com') {
$filename = 'false-ad.jpg';
if (file_exists($filename)) {
$handle = fopen($filename, "r");
$contents = fread($handle, filesize($filename));
header("Content-type: image/jpeg");
echo $contents;
}
exit();
}

The exit() is added so we can bail out early after serving my custom image, and not serve up the normal adblock page (that I see in my browsers). The image size for the Live Messenger ad is 231×60 pixels.

I opted for an image that would blend in with the skin I use for Live Messenger, but wasn’t just a “blank space here” image. The skin shown is Oil Slick for Messenger Plus! Live.

Comments