Monday, September 25, 2006

Texture compression and register hacking

Well, today I'll talk a bit about how the ds texture compression works and what I've accomplished with it (not that much, really). It's actually quite simply, if I understood it correctly (not sure I did). Well, a compressed texture is theorically, quite simple. We use one texture slot (even if not fully) for actual texture data, being it texture slot 0 or slot 2 (there're 4 possible slots in the DS).

For every 4x4 pixels block, we'll use one 32bit number from slot0 or slot2, that'll define the actual pixel data, 8bit a row per 4 columns, makes the total 32bit. So we define every pixel with a 2bit number, that'll use after for palette indexing. Now we need some more data, a 16bit value: the palette offset and a mode how this will be used, that'll will be located in texture slot1.

So, the general idea is quite simple in the end. Read a 32bit value from either slot0 or slot2, read a 16bit value from slot1. Then, use the 16bit value to determine the mode (there 4 possible modes, each filling each row in different manners) and palette index. With this palette index, go through each of the 2bit values, contained in the 32bit, and add each of them (separately, of course, for each colour) to the palette index, to get the final palette index to be used for each pixel. Then, with this value, you can just index in the normal palette data to get the colour. Depending on the mode, colours will be (or not) treated in different manners. Seems it's not that simple :P

My implementation is far from complete, I've severe bugs that just show lots of garbage. I'll try to fix it tomorrow.

I also have been doing some severe register hacking, that is just, that some memory locations are mapped to specific hardware of the DS. So, for example, writing to 4000490h will push a new 10b vertex to the render queue. So, I've just hacked a few of the registers so make games/demos work better, even if it's not correct emulation.

Just a simple screenshot today:




Seems today's posts was a bit complex, anyway, have fun :)

8 comments:

lowlines said...

So are you saying that you are trying to make the garbled stuff display properly??
Nyeh well having a pic at the end I think helps a bit in understanding all this practical/technical lingo :p lol

shash said...

Federelli: almost all the textures of the submarine demo are compressed

Anonymous said...

great work
we give pur support to Normmatt
You are great
Take your time to a release

we will wait
we know your work
take care

shash said...

lukeskyd: Do you mean the save card, or the games bigger than 64mb ?

shash said...

They are supported, they load correctly :P

If some game bigger than 64mb isn't running correctly, it's not due to it's size.

shash said...

umnop: I'll commit when I'm ready. Oh, and it already compiles on visualc, I use it as my main dev tool :)

Oh, thanks to the sucker that posted comments before, I'll moderate comments from now on.

shash said...

luke: I'm not lying, one of the roms that I've tested a lot is way bigger than 64mb (128mb, in fact). Could you be more specific which one is the one not loading, because I didn't have any problems loading 64 or 128 mb roms.

shash said...

luke: you seem to have a bad rom, I tested "Castlevania: Dawn of Sorrow" a while ago, and it loaded and worked (to a certain degree)