« on: December 13, 2010, 02:00:22 am »
Thanks to the users and documents here, I've been successfully adding my own code and modifications to Ninja Gaiden.
All the code I've been adding is related to player movement and conditions, and response to controller input. It all has been in the fixed bank (Ninja Gaiden uses mapper MMC1). But I'm out of space there and need more. I've expanded the ROM using KingMike's Nflate program (thanks KingMike!), so I now have oodles of space.
Disch's documents about mappers are thorough and helpful (thanks Disch!), but I don't understand how to move code execution from the fixed bank to a particular page in the swappable bank, which is what I think I want to do. Is that even possible? Can I read from the MMC what page it's currently on, push that on the stack, then jump to one of my newly added pages, execute my code, pull the previous page number off the stack and switch back to it? That would be all too easy, and I've seen nothing in the documents discussing "reading" values from the MMC.
I presume the logical method is to find some code in the swappable bank that executes "often" (since I am adding code that will need to execute in all levels of the game, not just particular places like level data or story text), figure what page that's on, insert code to swap to the page where I've added more code, and then at the end of its execution, swap back to the page the game ordinarily expects. Do I have that right? One problem is that all of the code I've seen and poked around with so far (sprite movement, powerups, player status, score, etc.) lives in the fixed bank. So I would have to jump from the fixed bank to a subroutine in the swappable bank, then swap in the new page, right? And be certain before the switch that that exact page would always be the one swapped in when jumping to it from the fixed bank.
...And that's my question, assuming I have everything correct so far. How can I find a suitable page to perform the swap from, when I need the code to be ready to execute at any moment during gameplay throughout the entire game, and all the code I see doing that lives in the fixed bank?