This is a repository dedicated to the reverse engineering of the SNES game Donkey Kong Country 2.
Currently supported Game Versions:
- Japan (Revision 0)
- Japan (Revision 1)
- North America (Revision 0)
- North America (Revision 1)
- Germany (Revision 0)
- Germany (Revision 1)
- Europe (Revision 1)
- The disassembly strives for 100% bit for bit accuracy globally with the original game for all supported versions.
- Make sure every byte is covered. Even if bytes are unused, they should be initialized to match the original game.
- Support for assembly in both asar 1.9 and 2.0 should always be verified.
- Use a tab size of 8.
- Always use actual tabs instead of spaces (make sure that your Code/Text Editor isn't replacing your tabs with spaces).
- The address comment section should always maintain the same indentation level (ensure no code lines exceed the length restrictions).
- Strive for descriptive names, ideally under 30 characters but absolutely never exceeding 36. If the data is never referenced in a place where the label clashes then a longer name may be acceptable.
- Anything in the global namespace should be specific to reduce chances of name conflict.
- All labels should adhere to the snake_case format.
- Avoid speculative labeling/commenting wherever possible. If you're not sure about something don't write what you think it is followed by "?" or "probably" / "maybe". Instead make a note of it somewhere outside of the code for later.
- Routines that act like game loops should have names such as
run_<action> - Routines that primarily delegate many related tasks should have names such as
<task>_handler - Routines that are global trampolines for a local routine get a suffix of
<routine>_global - Use sub-labels wherever possible, nesting deeper is okay but should be used sparingly.
- Relative labels should be used minimally when a name wouldn't help the context (Like a spinlock).
- The use of
#should generally be temporary (code actively being documented) or rarely used when it helps routines with multiple entries or similar conditions.
- Data which is local should get a sub-label.
- Palettes should get the
_palettesuffix. - Layer graphics should get the
_tiledatasuffix. - Layer tile maps should get the
_tilemapsuffix. - Collections of sprite graphics should get the
_graphicssuffix. - Single sprite graphics should get the suffix
_frameNwhereNis optional (used for when multiple frames exist). - Game data files that exist externally should have file names as close to their corresponding labels as possible.
- When practical, ROM data should get a struct defined in
structs.asmThis allows for named member access.
- Try to allow comments to flow around the code to cluster related opcodes.
- Comment on what and why something is happening more than how it's happening.
- The hard limit for line length is 120 characters. Do not exceed this with comments.
- If you need a bulk description for some reason place it in a block before the routine.
- Never use the macros as a comment trick.
run_level_logic:
JSL sprite_handler_global ;$808000 \
BRA wait_for_interrupt ;$808004 /
sprite_handler_global:
JSR sprite_handler ;$808006 \
RTL ;$808007 /
;We can talk more about the below routine here
sprite_handler:
LDX #$0004 ;$809000 \ \ <- Note the space before this comment
LDA .this_data_is_local,x ;$809003 |/ And how the data label doesn't touch the address comment
STA some_place_in_RAM ;$809009 |\
STA some_other_place_in_RAM ;$80900C |/
CLC ;$80900F |\
ADC #$0010 ;$809010 | | Note how this comment encompasses multiple lines of code
TAY ;$809013 |/
LDX #$0006 ;$809014 |> This comment only encompasses a single line of code
LDA .this_data_is_local,x ;$809017 |
ASL ;$80901A |
TAX ;$80901B |\ The line below tilts inward, it's the end of the routine
JMP .some_code_table,x ;$80901C /_/ How to deal with comments whenever they're at the end
;We can talk about the data below here.
;Even if we need multiple lines.
;We should add an address comment...
;That way we know where this data is in ROM.
;Try to limit the data to 8 byte per line...
;Unless it makes contextual sense to not do so.
;$80901F
.this_data_is_local
db $00, $01, $02, $03, $04, $05, $06, $07
db $08, $09, $0A, $0B
.some_code_table
dw CODE_808123 ;00 We can comment what the index of this entry is
dw CODE_808456 ;01 We can also comment what it is or does
dw CODE_808789 ;02
DKC2 uses a 32-megabit (4 MB) fast ROM (3.58 MHz) with the HiROM mapping mode. Consequently, it occupies banks $80–$FF.
- Main engine code
- Level/Tileset logic
- Sprite main code
- World map code/data
- Sound engine (CPU side)
- Tileset loading code/data
- Additional engine code
- Boss main code (including boss related sprites)
- Boss sequence data
- Kong-sprite interaction code
- Kong main code
- Player action handling
- Sprite terrain collision logic
- Sprite animation logic
- Additional boss code/data (including boss related sprites)
- Decompression code
- Sprite spawning code
- Additional engine code
- Sprite graphics/hitbox table
- Sprite hitbox data
- Sprite clipping/collision logic
- Additional sprite main code
- Sprite collision interaction logic
- Sprite movement logic
- Sprite graphics data
- Sprite graphics data
- Background graphics data (Mostly compressed)
- Sound engine (SPC side)
- BRR sample table
- BRR sample data
- Sample upload data
- Music sequence data
- Sound effect sequence data
- Background graphics data (Mostly uncompressed and used for animated backgrounds)
- Background graphics data (Mostly uncompressed and used for animated backgrounds)
- Background graphics data (Mostly uncompressed and used for animated backgrounds)
- Background graphics data (Mostly uncompressed and used for animated backgrounds)
- Dialog text data
- Background graphics data
- Sprite animation data
- Background graphics data (Only secret ending layer 2)
- Background graphics data (Mostly uncompressed and used for animated backgrounds)
- Background graphics data (Mostly uncompressed and used for animated backgrounds)
- Tileset collision data
- Miscellaneous graphics data
- Level config data
- Tileset config data
- PPU config data
- VRAM payload data
- Color palette data
- Level banana placement data
- Level camera placement data
- Level sprite placement data
- Demo input playback data
- Sprite constants data
- Sprite spawn initialization data
DKC 2 RAM map
DKC Atlas Forum
Donkey Kong Hacking Portal
DKC SNES Trilogy Resources Repository
Yoshifanatic1's DKC 2 Disassembly, many improvements here are thanks to shared documentation.
DKComp (DKC (de)compressor)
Asar (SNES Assembler)
https://github.com/Yoshifanatic1/Donkey-Kong-Country-1-Disassembly
https://github.com/BlueImp78/DKC3-Disassembly
https://github.com/Yoshifanatic1/Donkey-Kong-Country-3-Disassembly
Mattrizzle for indirectly contributing by parsing the music/sound effect sequences into asm.