DKC Hacking - Data Formats Database Topic

Share ROM offsets and general DKC hacking documentation

DKC Hacking - Data Formats Database Topic

Postby Simion32 » January 23rd, 2011, 8:23 am

This topic is a database for all known data formats related to DKC ROM Hacking.
Only staff posts are allowed here. If you want something added, please PM Simion32.
Documentation Credits (All Items): Giangurgolo, Mattrizzle, Gabriel, Simion32, LokiNova

This topic only contains information regarding the actual data formats, and does not list specific ROM addresses.

Each post may contain up to 3 sections: the Data Format itself, any special notes on how to read the data (where applicable), and any applicable C++ code snippets (code is optional and may not be available for all items).

Document Index:
Sage of Discovery
Bananas received 337
Posts: 2746
Joined: 2008

Re: DKC Hacking - Data Formats Database Topic

Postby Simion32 » January 23rd, 2011, 8:28 am

ALL - 8x8 Graphics Tile (16-color, planar):
Documentation Credits: Simion32

ConvertToSNESGraphicsFormat.png
ConvertToSNESGraphicsFormat.png (75.82 KiB) Viewed 72167 times

The 8 "blocks"of data form one 8x8 graphics tile.
Each block of 4 bytes is one 8-pixel line, going downwards in the tile.

The lines of data bytes are in-order from left to right, then second row.
Sage of Discovery
Bananas received 337
Posts: 2746
Joined: 2008

Re: DKC Hacking - Data Formats Database Topic

Postby Simion32 » January 23rd, 2011, 8:29 am

ALL - 8x8 Tile Map [Backgrounds/Foregrounds]:
Documentation Credits: Simion32

(todo)
Sage of Discovery
Bananas received 337
Posts: 2746
Joined: 2008

Re: DKC Hacking - Data Formats Database Topic

Postby Simion32 » January 23rd, 2011, 8:31 am

ALL - 32x32 Tile Set [Tiles]:
Documentation Credits: Simion32

(todo)
Sage of Discovery
Bananas received 337
Posts: 2746
Joined: 2008

Re: DKC Hacking - Data Formats Database Topic

Postby Simion32 » January 23rd, 2011, 8:33 am

ALL - 32x32 Tile Map [Level Layouts]:
Documentation Credits: Giangurgolo, Gabriel

(todo)
Sage of Discovery
Bananas received 337
Posts: 2746
Joined: 2008

Re: DKC Hacking - Data Formats Database Topic

Postby Simion32 » January 23rd, 2011, 8:36 am

ALL - Sprite Graphics:
Documentation Credits: Mattrizzle, Simion32

Data Format:
Byte 0:Number of 16² tiles in Group A
Byte 1:Number of 8² tiles in Group B
Byte 2:Start of Group B 8² tiles relative to start of graphics (Measured in 8² tiles)
Byte 3:Number of 8² tiles in Group C
Byte 4:Start of Group C 8² tiles relative to start of graphics (Measured in 8² tiles)
Byte 5:Start of Group D 8² tiles relative to start of graphics (Measured in 8² tiles)
Byte 6:Where to place Group D in VRAM upon the display of this sprite. (Measured in 8² tiles)
Byte 7:Number of 8² tiles in Group D
Bytes:Group A, B and C position data
Byte:X-coordinate of nth tile (unsigned)
Byte:Y-coordinate of nth tile (unsigned)
(repeat until all coordinates are defined)
Bytes:Sprite graphics for Groups A, B, and C
8x8 Graphics Tiles (see below for details)
Bytes:Group D graphics, if present.
8x8 Graphics Tiles (see below for details)

Notes on how to read this data:
Image
Note: Group D is rarely present and deals with placing the tiles directly into VRAM.
Sage of Discovery
Bananas received 337
Posts: 2746
Joined: 2008

Re: DKC Hacking - Data Formats Database Topic

Postby Simion32 » January 23rd, 2011, 8:41 am

ALL - Object Map [Level Objects]:
Documentation Credits: Giangurgolo, Gabriel

(todo)
Sage of Discovery
Bananas received 337
Posts: 2746
Joined: 2008

Re: DKC Hacking - Data Formats Database Topic

Postby Simion32 » January 23rd, 2011, 8:49 am

DKC - Compressed 8x8 Graphics:
Documentation Credits: Simion32

C++ Code:
Giving credits is required for this code. If used, you must credit Simion32.
Spoiler!
void DecompressGFX( vector<char>& DKC1, vector<char>& out_gfx )
{
// This is a DKC graphics decompression routine.
// Coded by Simion32. Give credit if used.
// Note: This was modified slightly from DKCRE's version, for simplicity.


// Get the address of the compressed graphics.
unsigned long int cgfx = get_level_graphics_offset();

// Get the archetype (needed to handle a known exception).
unsigned long int archetype = get_archetype();

if(archetype == ARCHETYPE_GANGPLANK)
{
// The Gangplank Galleon data is not compressed, copy verbatim.
for(int i = 0; i != 0x84A0; i++)
{
out_gfx.push_back(DKC1[i + cgfx] & 0xFF);
}
}
else
{
unsigned long int a = 0;
while(true)
{
int v = DKC1[a + 0x80 + cgfx];
if((v & 0xFF) == 0x00) break;
a++;
switch(v & 0xC0)
{
case 0x00:
{
for(int i = (v & 0xFF); i != 0; --i)
{
out_gfx.push_back(DKC1[a + 0x80 + cgfx] & 0xFF);
a++;
}
}
break;
case 0x80:
{
for(int i = (v & 0x3F),
j = ( (DKC1[a + 0x80 + cgfx] & 0xFF) +
((DKC1[a + 0x80 + cgfx + 1] & 0xFF) << 8))
; i != 0; --i, ++j)
{
out_gfx.push_back(out_gfx[j]);
}
a += 2;
}
break;
case 0xC0:
{
out_gfx.push_back(DKC1[((v & 0x3F) << 1) + cgfx ] & 0xFF);
out_gfx.push_back(DKC1[((v & 0x3F) << 1) + cgfx + 1] & 0xFF);
}
break;
case 0x40:
{
for(int i = (v & 0x3F); i != 0; --i)
{
out_gfx.push_back(DKC1[a + 0x80 + cgfx] & 0xFF);
}
a++;
}
break;
}
}
}
}
Sage of Discovery
Bananas received 337
Posts: 2746
Joined: 2008

Re: DKC Hacking - Data Formats Database Topic

Postby Simion32 » January 23rd, 2011, 8:58 am

DKC - Focus Map [Level Camera Bounds]:
Documentation Credits: Giangurgolo, Simion32

(todo)
Sage of Discovery
Bananas received 337
Posts: 2746
Joined: 2008

Re: DKC Hacking - Data Formats Database Topic

Postby Simion32 » January 23rd, 2011, 9:02 am

DKC - Banana Group [Banana Formations]:
Documentation Credits: Simion32

(todo)
Sage of Discovery
Bananas received 337
Posts: 2746
Joined: 2008

Re: DKC Hacking - Data Formats Database Topic

Postby Simion32 » January 23rd, 2011, 9:02 am

DKC - Banana Map [Level Bananas]:
Documentation Credits: Giangurgolo, Gabriel, Simion32

Updated FEB 25th: Three of the Y bits were misidentified as X bits.
This format document now works properly for vertical levels.


Updated APR 21st 2024: rainbowsprinklez reports that bit zero is a hidden banana group flag, used in the animal bonuses.
I've updated the documentation to reflect this technical find.


Data Format:
bbbbbbbhyyyyyybbxxxyyyyyxxxxxxxx (base 2)
h - Hidden Banana Group?
b - Banana Group ID, Low Bits
b - Banana Group ID, High Bits (MSB is always 0)
x - Placement X co-ordinate Low Bits
x - Placement X co-ordinate High Bits
y - Placement Y co-ordinate Low Bits
y - Placement Y co-ordinate High Bits (only nonzero in vertical levels)
y - Placement Y co-ordinate Very High Bits (only nonzero in vertical levels)

Notes on how to read this data:
Note: A Group ID of zero indicates the end of the level's Banana Map.
Note: The entire data segment is actually a little-endian dword. If needed, flip the bytes around:
xxxxxxxxxxxyyyyyyyyyyybbbbbbbbbh
Note: The Group ID is stored multiplied by 2, for use as a table index where the table entries are 2 bytes.
Note: The X and Y offsets are stored with the first three bits truncated. Multiply the resulting value by 8 to fix this.

C++ Code:
// Theoretical function call to read in the data from the ROM.
int data = read_little_endian(offset, 4);

// Convert the data into a more workable format...
int typeID = ((data & 0x000003FE) >> 1);
int groupX = (((data & 0xFFE00000) >> 21) << 3);
int groupY = (((data & 0x001FFC00) >> 10) << 3);
Sage of Discovery
Bananas received 337
Posts: 2746
Joined: 2008

Re: DKC Hacking - Data Formats Database Topic

Postby Simion32 » January 23rd, 2011, 9:22 am

DKC - Physics Tile Set [Surfaces]:
Documentation Credits: Simion32

(todo - lacking advanced details, this is ASM code)
Sage of Discovery
Bananas received 337
Posts: 2746
Joined: 2008

Re: DKC Hacking - Data Formats Database Topic

Postby Simion32 » January 23rd, 2011, 9:23 am

DKC - Physics Tile Map [Level Tiles; Surface Mapping]:
Documentation Credits: Simion32

(todo)
Sage of Discovery
Bananas received 337
Posts: 2746
Joined: 2008

Re: DKC Hacking - Data Formats Database Topic

Postby Simion32 » January 23rd, 2011, 9:25 am

DKC - Sprite Bounding Box [Hit Boxes]:
Documentation Credits: Mattrizzle

(todo)
Sage of Discovery
Bananas received 337
Posts: 2746
Joined: 2008

Re: DKC Hacking - Data Formats Database Topic

Postby Simion32 » January 23rd, 2011, 9:28 am

DKC - Animation Sequence [Sprite Animations]:
Documentation Credits: Mattrizzle

(todo)
Sage of Discovery
Bananas received 337
Posts: 2746
Joined: 2008

Re: DKC Hacking - Data Formats Database Topic

Postby Simion32 » January 23rd, 2011, 9:30 am

DKC - Object Code [Objects]:
Documentation Credits: Mattrizzle

(todo)
Sage of Discovery
Bananas received 337
Posts: 2746
Joined: 2008

Re: DKC Hacking - Data Formats Database Topic

Postby Simion32 » January 23rd, 2011, 11:37 am

DKC2 - Compressed Data:
Documentation Credits: Simion32, LokiNova

There's not really much to actually say about this format other than it's really confusing stuff. :ugeek:

Both Lokinova and I were developing a routine at the same time, so I've kept Lokinova in the credits of this post.

C++ Code:
Giving credits is required for this code. If used, you must credit Simion32.
DOWNLOAD THE C++ CODE FILE HERE
Sage of Discovery
Bananas received 337
Posts: 2746
Joined: 2008

Re: DKC Hacking - Data Formats Database Topic

Postby Simion32 » January 23rd, 2011, 11:39 am

DKC3 - Compressed Data:
Documentation Credits: <NULL>

(todo - still needs to be researched)
(todo - c++ code)
Giving credits is required for this code. If used, you must credit <NULL>.
Sage of Discovery
Bananas received 337
Posts: 2746
Joined: 2008


Return to Documentation

Who is online

Users browsing this forum: No registered users and 1 guest