NDS ROM File Format

Discussion in 'NDS - Flashcarts and Accessories' started by pekalicious, Jan 12, 2010.

Jan 12, 2010

NDS ROM File Format by pekalicious at 10:57 PM (9,705 Views / 0 Likes) 20 replies

  1. pekalicious
    OP

    Newcomer pekalicious Member

    Joined:
    Jan 12, 2010
    Messages:
    21
    Country:
    Greece
    Hello again,

    Continuing on my quest to create a ROM Manager I am trying to find a good specification of the .nds ROM format.

    What I found up until now is the following sites:

    http://dsibrew.org/wiki/NDS_Format
    http://www.bottledlight.com/ds/index.php/F...rmats/NDSFormat
    http://imrannazar.com/The-Smallest-NDS-File

    Although I had some luck reading the game title and some other data (which I verified using NDS Header Tool 2.0), I have problems of what type of data I am expecting to read, what are they for etc.

    I also looked through the DeSMuME source code but had little luck on that.

    Any ideas of where can I find more information about the format? Anyone here knows?

    Thanks again!
     


  2. Gryphon93

    Member Gryphon93 GBAtemp Regular

    Joined:
    Nov 30, 2008
    Messages:
    145
    Country:
    Sweden
    You can get the NDSTool-source and see what types DarkFader (and the devkitPro-team) used to read the data from .nds-files. You'll find the source over at their SVN-repository. Link: SVN-devkitPro-NDSTool
     
  3. pekalicious
    OP

    Newcomer pekalicious Member

    Joined:
    Jan 12, 2010
    Messages:
    21
    Country:
    Greece
    Thank you. I'm right on it. Although I have finally figured out the most of it.
     
  4. FAST6191

    Reporter FAST6191 Techromancer

    pip
    Joined:
    Nov 21, 2005
    Messages:
    21,716
    Country:
    United Kingdom
  5. Gryphon93

    Member Gryphon93 GBAtemp Regular

    Joined:
    Nov 30, 2008
    Messages:
    145
    Country:
    Sweden
    Wow! Why didn't I think of that? Of course the GBATek has all that information. Thanks a lot, FAST6191! (If you're wondering, I was also looking for this...)
     
  6. pekalicious
    OP

    Newcomer pekalicious Member

    Joined:
    Jan 12, 2010
    Messages:
    21
    Country:
    Greece
  7. pekalicious
    OP

    Newcomer pekalicious Member

    Joined:
    Jan 12, 2010
    Messages:
    21
    Country:
    Greece
    I am really having trouble reading the icon....

    The specification at http://nocash.emubase.de/gbatek.htm#dscart...ryptionfirmware states:

    Can somebody help me understand this line? I'm kinda confused...
     
  8. jceggbert5

    Member jceggbert5 Check out my hack, New Retro Mario Bros.

    Joined:
    Dec 1, 2008
    Messages:
    989
    Location:
    USA, Earth, MilkyWay
    Country:
    United States
    I am not exactly sure, but RomeR is a icon viewer/replacer and I believe it's open-source... You may be able to check the code to use on your project...
     
  9. pekalicious
    OP

    Newcomer pekalicious Member

    Joined:
    Jan 12, 2010
    Messages:
    21
    Country:
    Greece
    Having a hard time finding the source code... :/
     
  10. FAST6191

    Reporter FAST6191 Techromancer

    pip
    Joined:
    Nov 21, 2005
    Messages:
    21,716
    Country:
    United Kingdom
  11. pekalicious
    OP

    Newcomer pekalicious Member

    Joined:
    Jan 12, 2010
    Messages:
    21
    Country:
    Greece
  12. DanTheManMS

    Member DanTheManMS aka Ricochet Otter

    Joined:
    Jun 2, 2007
    Messages:
    4,325
    Location:
    Georgia
    Country:
    United States
    I had to draw a picture to figure it out, but I think I understand it. Okay, so let's just take a look at a single tile first. This tile is defined by a block of bytes, 4 wide by 8 tall. If you write this out as a series of bits, at 8 bits to a byte this gives you a block that is 8 rows of 32 bits each. At 4 bits to a pixel ("4bit depth") this gives you 8 rows of 8 pixels, or in other words, an 8x8 block of pixels (a "tile"). You then have a 4x4 arrangement of these tiles, which gives you a 32x32 pixel image.

    This diagram I whipped together might help explain what I'm trying to say here:

    Code:
    Here's the 4x8 arrangement of bytes for a single tile:
    
    B B B B
    B B B B
    B B B B
    B B B B
    B B B B
    B B B B
    B B B B
    B B B B
    
    If we expand that out into bits, we get something like:
    
    11110000 11110000 11110000 11110000
    00001111 00001111 00001111 00001111
    11110000 11110000 11110000 11110000
    00001111 00001111 00001111 00001111
    11110000 11110000 11110000 11110000
    00001111 00001111 00001111 00001111
    11110000 11110000 11110000 11110000
    00001111 00001111 00001111 00001111
    
    Then space it out into pixels, 4 bits per pixel:
    
    1111 0000 1111 0000 1111 0000 1111 0000
    0000 1111 0000 1111 0000 1111 0000 1111
    1111 0000 1111 0000 1111 0000 1111 0000
    0000 1111 0000 1111 0000 1111 0000 1111
    1111 0000 1111 0000 1111 0000 1111 0000
    0000 1111 0000 1111 0000 1111 0000 1111
    1111 0000 1111 0000 1111 0000 1111 0000
    0000 1111 0000 1111 0000 1111 0000 1111
    
    Which turns into pixels of various colors:
    
    Pixl Pixl Pixl Pixl Pixl Pixl Pixl Pixl
    Pixl Pixl Pixl Pixl Pixl Pixl Pixl Pixl
    Pixl Pixl Pixl Pixl Pixl Pixl Pixl Pixl
    Pixl Pixl Pixl Pixl Pixl Pixl Pixl Pixl
    Pixl Pixl Pixl Pixl Pixl Pixl Pixl Pixl
    Pixl Pixl Pixl Pixl Pixl Pixl Pixl Pixl
    Pixl Pixl Pixl Pixl Pixl Pixl Pixl Pixl
    Pixl Pixl Pixl Pixl Pixl Pixl Pixl Pixl
    
    So then a single tile looks like this in the end, 8x8 pixels:
    
    - - - - - - - - 
    - - - - - - - - 
    - - - - - - - - 
    - - - - - - - - 
    - - - - - - - - 
    - - - - - - - - 
    - - - - - - - - 
    - - - - - - - - 
    
    Then a 4x4 grid of those:
    
    - - - - - - - -ÂÂ+ + + + + + + +ÂÂ- - - - - - - -ÂÂ+ + + + + + + + 
    - - - - - - - -ÂÂ+ + + + + + + +ÂÂ- - - - - - - -ÂÂ+ + + + + + + +
    - - - - - - - -ÂÂ+ + + + + + + +ÂÂ- - - - - - - -ÂÂ+ + + + + + + +
    - - - - - - - -ÂÂ+ + + + + + + +ÂÂ- - - - - - - -ÂÂ+ + + + + + + +
    - - - - - - - -ÂÂ+ + + + + + + +ÂÂ- - - - - - - -ÂÂ+ + + + + + + +
    - - - - - - - -ÂÂ+ + + + + + + +ÂÂ- - - - - - - -ÂÂ+ + + + + + + +
    - - - - - - - -ÂÂ+ + + + + + + +ÂÂ- - - - - - - -ÂÂ+ + + + + + + +
    - - - - - - - -ÂÂ+ + + + + + + +ÂÂ- - - - - - - -ÂÂ+ + + + + + + +
    
    + + + + + + + +ÂÂ- - - - - - - -ÂÂ+ + + + + + + +ÂÂ- - - - - - - - 
    + + + + + + + +ÂÂ- - - - - - - -ÂÂ+ + + + + + + +ÂÂ- - - - - - - - 
    + + + + + + + +ÂÂ- - - - - - - -ÂÂ+ + + + + + + +ÂÂ- - - - - - - - 
    + + + + + + + +ÂÂ- - - - - - - -ÂÂ+ + + + + + + +ÂÂ- - - - - - - - 
    + + + + + + + +ÂÂ- - - - - - - -ÂÂ+ + + + + + + +ÂÂ- - - - - - - - 
    + + + + + + + +ÂÂ- - - - - - - -ÂÂ+ + + + + + + +ÂÂ- - - - - - - - 
    + + + + + + + +ÂÂ- - - - - - - -ÂÂ+ + + + + + + +ÂÂ- - - - - - - - 
    + + + + + + + +ÂÂ- - - - - - - -ÂÂ+ + + + + + + +ÂÂ- - - - - - - - 
    
    - - - - - - - -ÂÂ+ + + + + + + +ÂÂ- - - - - - - -ÂÂ+ + + + + + + + 
    - - - - - - - -ÂÂ+ + + + + + + +ÂÂ- - - - - - - -ÂÂ+ + + + + + + +
    - - - - - - - -ÂÂ+ + + + + + + +ÂÂ- - - - - - - -ÂÂ+ + + + + + + +
    - - - - - - - -ÂÂ+ + + + + + + +ÂÂ- - - - - - - -ÂÂ+ + + + + + + +
    - - - - - - - -ÂÂ+ + + + + + + +ÂÂ- - - - - - - -ÂÂ+ + + + + + + +
    - - - - - - - -ÂÂ+ + + + + + + +ÂÂ- - - - - - - -ÂÂ+ + + + + + + +
    - - - - - - - -ÂÂ+ + + + + + + +ÂÂ- - - - - - - -ÂÂ+ + + + + + + +
    - - - - - - - -ÂÂ+ + + + + + + +ÂÂ- - - - - - - -ÂÂ+ + + + + + + +
    
    + + + + + + + +ÂÂ- - - - - - - -ÂÂ+ + + + + + + +ÂÂ- - - - - - - - 
    + + + + + + + +ÂÂ- - - - - - - -ÂÂ+ + + + + + + +ÂÂ- - - - - - - - 
    + + + + + + + +ÂÂ- - - - - - - -ÂÂ+ + + + + + + +ÂÂ- - - - - - - - 
    + + + + + + + +ÂÂ- - - - - - - -ÂÂ+ + + + + + + +ÂÂ- - - - - - - - 
    + + + + + + + +ÂÂ- - - - - - - -ÂÂ+ + + + + + + +ÂÂ- - - - - - - - 
    + + + + + + + +ÂÂ- - - - - - - -ÂÂ+ + + + + + + +ÂÂ- - - - - - - - 
    + + + + + + + +ÂÂ- - - - - - - -ÂÂ+ + + + + + + +ÂÂ- - - - - - - - 
    + + + + + + + +ÂÂ- - - - - - - -ÂÂ+ + + + + + + +ÂÂ- - - - - - - -
    Hope this is correct, and if it is, hope it helped.
     
  13. pekalicious
    OP

    Newcomer pekalicious Member

    Joined:
    Jan 12, 2010
    Messages:
    21
    Country:
    Greece
    ...............

    Wow! I'm absolutely blown away.... Only problem is, I have no idea how to split a byte into bits.. :S I am using Java.... I can do byte manipulation but not bit... I think it has something to do with shifting.... Which means I got a lot of reading to do right now... :/
     
  14. DanTheManMS

    Member DanTheManMS aka Ricochet Otter

    Joined:
    Jun 2, 2007
    Messages:
    4,325
    Location:
    Georgia
    Country:
    United States
    http://www.exampledepot.com/egs/java.util/Bits2Array.html might help. It looks like it takes in a sequence of bytes and returns a byte array of the equivalent bits. There's probably an easier way, but I honestly haven't had enough experience with Java to really know what I'm doing in that regard.
     
  15. pekalicious
    OP

    Newcomer pekalicious Member

    Joined:
    Jan 12, 2010
    Messages:
    21
    Country:
    Greece
    I don't remember how many times I said this in this thread, but, Thank you! [​IMG]
     
  16. DanTheManMS

    Member DanTheManMS aka Ricochet Otter

    Joined:
    Jun 2, 2007
    Messages:
    4,325
    Location:
    Georgia
    Country:
    United States
    More brainstorming here, but if it's 4 bits to a pixel, I doubt each pixel is absolutely defined in RGB (red green blue) terms. Do you happen to know if there's a set palette that all DS icons use or something? Or if the palette is defined elsewhere in the rom? Because with 4 bits you can represent the decimal numbers 0 through 15, so my guess is that there's a 16-entry palette somewhere and every 4-bit pixel merely references a palette index.

    For comparison, the GBA in mode 3 uses 16 bits to represent a single pixel. 5 bits for the red component, 5 for the green, 5 for the blue, and the last one goes unused, giving you 32*32*32 = 32,768 possible color combinations. In mode 4, you only have 8 bits per pixel, so rather than splitting it into 2 red 2 green 2 blue (which would give you 4*4*4 = 64 color combinations) they use the palette method to give you up to 2^8 = 256 possible colors on screen at once.

    If this icon is 4 bits per pixel, if you wanted to use the red/green/blue approach you'd only have 2*2*2 = 8 possible colors (white, black, red, green, blue, and 3 in-between), which is why I'm guessing they use the palette method to get up to 16 colors.

    Again, this is all purely a guess, and I doubt it will help you much, but it's interesting to think about at least.
     
  17. pekalicious
    OP

    Newcomer pekalicious Member

    Joined:
    Jan 12, 2010
    Messages:
    21
    Country:
    Greece
    Actually yes, there is the data of the color palette exactly after the image data. There are 16 colors of 16bit depth (32 bytes in total, 2 bytes each color). The first one is the transparent color.
     
  18. pekalicious
    OP

    Newcomer pekalicious Member

    Joined:
    Jan 12, 2010
    Messages:
    21
    Country:
    Greece
    Now that you mentioned it, does anybody here knows how is the color encoded? Is it the same as the GBA mode 3? 5 bits for each component and the last one is unused?
     
  19. Gryphon93

    Member Gryphon93 GBAtemp Regular

    Joined:
    Nov 30, 2008
    Messages:
    145
    Country:
    Sweden
    I guess (but I'm not sure...) that you'll find an answer to your question in the topic FAST6191 referred to earlier, namely this one: http://gbatemp.net/index.php?showtopic=45360. There's a lot of things mentioned there about how to read the palette and stuff, so I think you better check it out [​IMG].
     
  20. pekalicious
    OP

    Newcomer pekalicious Member

    Joined:
    Jan 12, 2010
    Messages:
    21
    Country:
    Greece
    OK.. After many hours of reading and hacking around I think I have finally found how to do it. My problem is that I am developing in Java and this is the first time I am developing in such low level image and bit manipulations. I am currently waiting from two communities to help me out with this. One in JavaRanch and the other in StackOverflow. If there is someone here that can also help I would be grateful (once again).

    At this stage I have read most header information and made my first steps into decoding the filesystem. Currently my goal is to create a Java library that will decode a ROM. Once this is done I will definitely write a blog post about everything I learned and release the source code. Of course you will be the first to read about this since I own you everything.
     

Share This Page