Thursday, May 31, 2012

Getting closer.

Suspicion confirmed.  SOM is processing 16x16 JPEG blocks one at a time from almost the time you load the ROM.  The Y channel is stored at $1600 (upper left 8x8 block), $1700 (lower left), $1800 (lower right), and $1900 (upper right).  At $1A00 and 1B00 you find the downsampled Cb and Cr, respectively.

I wrote a little MATLAB script to generate an RGB image from data I found at these locations for the first block to test my theory.  Here's the result compared against a zoomed-in screenshot of the game:


The colors are slightly off; I attribute this to one of three possible things.. one, the most likely, I fucked something up.  Two, the game uses an 8-bit palette in the end (haven't gotten that far yet) and these color shifts are an artifact of paletting.  Three, it's a difference between 16-bit and 24-bit color.  I'd call three unlikely.

Anyway, it shouldn't be long before the editor can load this image, because (with minor bugs) the processing up to this point, including the Huffman tree lookup from the ROM data, Quantization matrix processing, and DCT are all implemented.  Dropping a new image in as the title screen background will be interesting to implement.

Oh, could it really be that simple?

http://en.wikipedia.org/wiki/JPEG#Encoding is not something I've ever been especially familiar with, but as I poke further into the code that processes the title screen "tree" image, the two are looking strikingly similar.  Could this entire mess simply be an off-the-shelf JPEG processing algorithm tweaked for SNES? 

It sure would explain the JPEG-like artifacts visible if you zoom into the image.


Wednesday, May 23, 2012

Title screen

Compressed title screen tiles have been loading for a while, but I'm currently working on how they are assembled into the actual title screen and Squaresoft logo.  Looks pretty simple, actually.

See?  See?  I'm doing things.

Edit: I'm also checking out the tree graphic behind the title screen, since it's been somewhat of a mystery for a while now.  Looks like they're doing some sort of peculiar matrix math on 8x8 blocks of data derived (somehow) from around D2E63B in the ROM, which end up becoming the tiles that go off to VRAM.

Funny how slow this loading is - they start doing it while the Squaresoft logo is up, and are still working on it while the little black window opens up and shows part of the background, which loads from the bottom up.  Once it finishes (~20 seconds later), it opens up and shows the rest.  They pass it off as a stylish little window into the background, but it's really just there to allow you to see the part of the image that's been loaded without revealing the part where the little blocks are still being filled in.  Corrupting the data in certain ways will slow the algorithm down enough that I can watch it populate the tiles while they're being shown.

Kind of interesting though, that they managed to set up sort of a "background task" like this in an SNES program, that will sit there and load tiles while the rest of the title screen is running.  I'm betting they tried like hell to make it load real-time before they finally gave up and had to go this route.

Oh, and this code is largely runtime-generated and run off of RAM addresses, which makes it even more fun to follow.

Needless to say, making this thing "editable" should be quite the task.