asm script works when placed at address 0x861C0, but not at address 0x7CC6C0
Users browsing this thread: 1 Guest(s)

When I began working on custom asm scripting, I followed the moonjump sample script, which overwrites an unused function at ROM address 0x861C0. This worked excellently. I'm now working on a more complex mario behavior, and cannot fit the script in the unused space at address 0x861C0. According to LexAsm, there is a tremendous amount of unused space starting at address 0x7CC6C0. However, if I store my mario behavior at address 0x7CC6C0, it doesn't function, despite LexAsm verifying that it has indeed been written there. I know this is a simple question, but for the sake of my understanding, why does the behavior work at address 0x861C0, but not at address 0x7CC6C0? How can I take advantage of all that free space starting at address 0x7CC6C0? Is there another address I should be writing custom asm to?
Thank you!

Code on the N64 runs from RAM, so the code must be first copied from ROM to RAM. The boot code automatically copies 1MB of ROM starting at offset 0x1000 at startup to RAM address defined by the word at offset 8 in the N64 ROM header (0x80246000 in the case of SM64). There are two more sections of ROM code in SM64 that are copied to RAM by code. These are enumerated in the table below. If you want to add new code, the easiest way is to overwrite unused functions as you have found. If you need more space, you'll need to find an unused portion of RAM and DMA the code from ROM to that area manually before calling it.

There are many unused functions in ROM that you can overwrite if you want. 0x80246050-0x8024616F (ROM 0x001050-0x00116F) and the one immediately after it are pretty good. If you need more space, then the usual route is to start using an unused portion of ROM (like 0x7CC6C0 as you have found) and use DMA to copy it to expansion RAM.

Code:
​ RAM start,    RAM end, RAM-to-ROM, ROM start,  ROM end, length
0x8016F000, 0x801B99DF, 0x7FF4FB40,  0x21F4C0, 0x269E9F, 0x4A9E0
0x80246000, 0x8033A57F, 0x80245000,  0x001000, 0x0F557F, 0xF4580
0x80378800, 0x8038BC8F, 0x80283280,  0x0F5580, 0x108A0F, 0x13490

(18-02-2018, 01:36 AM)queueRAM Wrote: Code on the N64 runs from RAM, so the code must be first copied from ROM to RAM. The boot code automatically copies 1MB of ROM starting at offset 0x1000 at startup to RAM address defined by the word at offset 8 in the N64 ROM header (0x80246000 in the case of SM64). There are two more sections of ROM code in SM64 that are copied to RAM by code. These are enumerated in the table below. If you want to add new code, the easiest way is to overwrite unused functions as you have found. If you need more space, you'll need to find an unused portion of RAM and DMA the code from ROM to that area manually before calling it.

There are many unused functions in ROM that you can overwrite if you want. 0x80246050-0x8024616F (ROM 0x001050-0x00116F) and the one immediately after it are pretty good. If you need more space, then the usual route is to start using an unused portion of ROM (like 0x7CC6C0 as you have found) and use DMA to copy it to expansion RAM.

Code:
​ RAM start,    RAM end, RAM-to-ROM, ROM start,  ROM end, length
0x8016F000, 0x801B99DF, 0x7FF4FB40,  0x21F4C0, 0x269E9F, 0x4A9E0
0x80246000, 0x8033A57F, 0x80245000,  0x001000, 0x0F557F, 0xF4580
0x80378800, 0x8038BC8F, 0x80283280,  0x0F5580, 0x108A0F, 0x13490


I see. Thank you for the detailed information. I'll do my best to follow your advice. Would you be able to point me towards any examples which copy custom code from ROM to expansion RAM? I'm not sure how I would go about that.

(18-02-2018, 02:08 AM)rystills Wrote: Would you be able to point me towards any examples which copy custom code from ROM to expansion RAM? I'm not sure how I would go about that.


I have an example written using armips and, but it is catered towards inserting new C code. The code to actually do the DMA copy is in MIPS assembly though. You can find this example here:
https://queueram.com/n64/armips/armips_sm64_importobj_expram.zip

David also has an example provided with his Simple Armips GUI tool called "04_DmaCopy.asm" which does something very similar (and perhaps better than my example).

Brilliant, I had entirely forgotten about the DmaCopy example. As expected, that was exactly what I needed to load my asm code over from ROM to RAM and execute it (essentially all I did was replace the call to func_printXY with a JAL to the location in RAM to which I copied the bytes from ROM). Thanks for the help!

asm script works when placed at address 0x861C0, but not at address 0x7CC6C0
Users browsing this thread: 1 Guest(s)