How to create an overlay ?

Discussion in 'NDS - ROM Hacking and Translations' started by hackotedelaplaqu, Jun 2, 2013.

  1. hackotedelaplaqu
    OP

    hackotedelaplaqu GBAtemp Advanced Fan

    Member
    543
    161
    Jan 10, 2009
    France
    Hi,

    For a translation project, I need to create a new overlay.
    I know how to edit the overlay table (y9.bin) to add the file but how do I tell the game to load my new overlay in memory on boot ?

    I searched the web but din't find anything about this.
    Thanks for your help.
     
  2. FAST6191

    FAST6191 Techromancer

    pip Reporter
    23,826
    9,719
    Nov 21, 2005
    United Kingdom
    I have never really had cause to investigate overlay loading functions or add new ones for that matter (indeed I would have pegged the annoying part as compiling for the given address) but I will go anyway.

    "load my new overlay in memory on boot "
    I assume that to mean stick it in memory and branch/jump to it rather than just make sure it is in memory.
    You would be doing two things then

    1) Figuring out what commands/info to pass the load overlay function or loading the overlay yourself (it is just a file and so able to be catapulted into memory as you would otherwise do things). GBAtek says that the nitro filesystem can load them by ID much it loads other things by filenames, as it should have all the rest of the data in the table you will hopefully only have to pass the ID to the command. Overlays are nothing special as far as the hardware is concerned/it is all a software/compiler arrangement but few things will break from it (basically nothing does an end run around the filesystem).

    2) Hooking the code to load it and then jump to it. You know what your overlay does and so you know what point is best to hook -- if it is an intro then the earlier the better really but if it is just modding a few things here and there and never being seen again then it could stand to come a bit later (after IO is set up and such) lest you have to make a full program in your overlay. You could try something complex with interrupts but I would probably opt to just change a command and make that a branch to your overlay or a branch to another portion of the binary that sets up your overlay and then branches to that.

    The possible third one is making sure the game returns to the state it left (your overlay gone from memory if it needs to be, the relevant register values/stack popped back in and any overlay that should be there now being there*).

    *the ideal would be if you have some free memory/free memory at the time and stuck your overlay there.

    I am not too sure where you want to go from here/what you might want elaborated upon so I will stop for now.
     
  3. StorMyu

    StorMyu "I'm too old for this"

    Member
    900
    440
    Jan 2, 2010
    France
    Especially since they're just basically bunch of codes so making a function to actually copy paste your own code/file is easier than trying to hook something like this.

    So yeah, like FAST said, what do you especially want to do with an overlay because basically... creating one isn't really needed.
     
  4. hackotedelaplaqu
    OP

    hackotedelaplaqu GBAtemp Advanced Fan

    Member
    543
    161
    Jan 10, 2009
    France
    Thanks both of you.

    In my game, there is text in both arm9 and overlays.
    With overlays, no problem. I'm writing the excess of translated text at the end of file. Works great.

    But with arm9, I can't because just after boot, arm9 from 0x0211D360 until end of file is filed with 00.
    I traced back asm and found the guilty opcodes and fixed them. Now the arm9 loaded in ram is ok (full with my text translated) but game crashes later on.

    I tried to do the same, but writing my excess text at the end of arm7 instead. In the header, liker most (all ?) games, I can see that the arm7 ram offset is 0x02380000.
    It is indeed at boot, but right after, arm7 is erased from 0x02380000 (!!) and I can't find in my dumps (!!)...

    I'm just trying to write text (no code). I figured out I could create an overlay and load it in ram, so my text will always be available in the same ram area.
    CAPCOM games hate me....
     
  5. StorMyu

    StorMyu "I'm too old for this"

    Member
    900
    440
    Jan 2, 2010
    France
    No need to create an overlay then, I basically did this for Tales of Rebirth. I took all the space from the Japanese font (which was quite a lot) to put all of my code / added text.
    I'm basically just repointing everything. Same goes for code, everything is just scrambled there since I have all the space needed.
     
  6. hackotedelaplaqu
    OP

    hackotedelaplaqu GBAtemp Advanced Fan

    Member
    543
    161
    Jan 10, 2009
    France
    Saddly the game is US (no room in font nor other parts of arm...).
     
  7. StorMyu

    StorMyu "I'm too old for this"

    Member
    900
    440
    Jan 2, 2010
    France
    then just find a free place in ram and launch a file there (just need to hook the function that opens the files and uses it, it shouldn't be a long code to add)
     
  8. hackotedelaplaqu
    OP

    hackotedelaplaqu GBAtemp Advanced Fan

    Member
    543
    161
    Jan 10, 2009
    France
    Yes, I'm going that way. I'll place this little code at the end of arm7 and change arm7 execution adress to jump there.

    Thanks again.
     
  9. hackotedelaplaqu
    OP

    hackotedelaplaqu GBAtemp Advanced Fan

    Member
    543
    161
    Jan 10, 2009
    France
    Just to report that it worked like a charm. :grog:
    Thank you very much StorMyu.