What I meant is that original games had this thing called Overlay tables (
GBATEK, at the end) which just meant memory could be reused for different pieces of code. It's the principle described here:
GeeksForGeeks article.
I just wanted to know if there was any way to do this with devkitpro toolchains. This would be really useful to reduce the size of the game's binary. For example, the main menu code does not need to be kept in RAM while in game.
This is unnecessarily low-level in my opinion, but I’m sure you could achieve this if you sliced your code accordingly. Realistically, the NDS has ample RAM to store all of your code, it’s the assets that are “chunky” and require streaming or shuffling around. If you had access to Nintendo’s tools you could use NitroROM and NitroARC as described on GBATEK, DevkitPro has its own implementation of Nitro that doesn’t really work in the same way. In theory libnds provides you with 4 DMA channels and pointers to RAM, so if you knew exactly what you wanted to replace and with what, you could do that. I’ve never seen it done personally as I’ve never seen a project that required it. You’re not saving much, if anything, in file size by slicing code like this, it still has to be stored somewhere. You’re not even saving on memory because it’s sectioned, so freeing up space in main RAM won’t give you any additional wiggle room in other areas (see the breakdown of RAM on GBATEK or in my tut.
EDIT: This is what you’re working with, simplified.
If I’m understanding you correctly, you’d want to flush a part of your main RAM and replace it with something else on the fly, yes?
EDIT2: Upon some searching and digging through the Wayback Machine I found some code relevant to your interest. Keep in mind that this likely *will not* work on the current devkit as it’s over a decade old, so you’ll have to do your own debugging. As it says in the thread, on the DS you don’t really have a main ROM, you only have RAM, and that’s where your code and assets are. You should be able to shuffle both as needed, and store them at the end of your binary.
https://web.archive.org/web/20160324225148/https://forum.gbadev.org/viewtopic.php?t=14707
If you actually *need* this and aren’t just optimising for the heck of it, you must be dealing with an ungodly amount of code.