News: 11 March 2016 - Forum Rules

Author Topic: Extended Duke Nukem 3D rom hack on N64  (Read 4245 times)

piip4

  • Jr. Member
  • **
  • Posts: 4
    • View Profile
Extended Duke Nukem 3D rom hack on N64
« on: July 23, 2014, 08:07:38 am »
Okay, so this would be my first post here (hello!).

I'm working on a DN64 hack. Essentially what it's aimed at being, is a "hard" version as I found the original too simple.
More specifically on co-op but some things will apply to single player as well. There is a bit of code that I would like to add.
For example, lowering the health "roof" after each respawn by -10 (or up to -25hp). You will eventually run out and won't be able to respawn.
That would of course reset to 100hp again as you reach the next level (if you can).
Things like this is what I have in mind and I have mapped out most relevant offsets in rom file to be able to do this, and other crazy stuff,
but it would help if I could extend the rom file and have everdrive accept reading code\data from the added space. 8MB -> 16MB.

Using LemAsm, I have extended the rom, however when trying to read code from the higher offsets, the N64 simply stops in its tracks.
Emulators on the PC as well doesn't like it much. "Error! Executing from non-mapped space" in PJ64.
Maybe it's just down to my "superior" ASM skills? *sarcasm*

I'm new to hacking N64 roms though not hacking in general, so there might be obvious things I've overlooked.
If anyone could shed some light on what needs to be done, I would greatly appreciate it. :)


KingMike

  • Forum Moderator
  • Hero Member
  • *****
  • Posts: 7188
  • *sigh* A changed avatar. Big deal.
    • View Profile
Re: Extended Duke Nukem 3D rom hack on N64
« Reply #1 on: July 23, 2014, 09:05:23 am »
Sorry for the off-topic replay but Project64 updated?!
"My watch says 30 chickens" Google, 2018

piip4

  • Jr. Member
  • **
  • Posts: 4
    • View Profile
Re: Extended Duke Nukem 3D rom hack on N64
« Reply #2 on: July 23, 2014, 09:35:37 am »
Sorry for the off-topic replay but Project64 updated?!
I suppose it has been updated. Can you be more specific?
Version 2.1 has been out for about a year, I assume.
So not updating very fast, but the emulator is good enough as it is for testing/making hacks together with cheat engine 6.4.

Zoinkity

  • Hero Member
  • *****
  • Posts: 565
    • View Profile
Re: Extended Duke Nukem 3D rom hack on N64
« Reply #3 on: July 23, 2014, 12:31:03 pm »
Actual end of the NTSC version is at 0x7E9128.  You shouldn't even need to extend it, but doing so is as easy as just sticking more data on the end.  There's no registered end to ROM images--the console sees them as nothing but bulk media past the bootstrap--although currently no hardware exists that can load an image over 512Mbits.
However, if you're intending to extend rdram to 16MB like certain SM64 hacks do then that won't work on console short of some hardware modification.

There's no issue with reading code from ROM outside of loading it into rdram.  Just send a PI request, or better yet trace one of the loads back to the generic JAL they use to send requests to the PI thead.  However...

Short snippets of code are easy enough to embed in existing space by simplifying the ASM already written.  The only real side-effect is the possibility of clogging the pipeline a bit and eating some cycles, but you'd have to do something rather extreme to even notice the effect.  You'll wind up doing it to some degree to load in new code anyway. 

You can also very technically execute from ROM space with some nasty overhead and the minor caveat of all jumps being local.  Use a JALR with the cached ROM address as target.  You can't do this within the exception handler, but it is completely valid and really bad form. 

Also, this tool supports extracting the remaining, mostly compressed files from the game if you ever need them for a more extensive hack.  Inserting them is your own problem though ;*) 

piip4

  • Jr. Member
  • **
  • Posts: 4
    • View Profile
Re: Extended Duke Nukem 3D rom hack on N64
« Reply #4 on: July 23, 2014, 01:27:58 pm »
Thank you for the reply, Zoinkity. :)

I'm working with the PAL version as I'm situated in Norway, but the end of PAL rom is pretty close to NTSC then. 0x7E9150
Yeah, that does indeed leave plenty of room for own code, however I asked mainly for future reference for possible media injection.
That's not important for this hack but the main problem still persists if I try to load code from beyond 0x7E9150, in the empty space, and with the regular-sized rom.

For the jump, I use (where the player's variables gets rewritten for a "clean" slate for respawning):
JAL $007E9200
NOP delay slot

And at 0x007E9220:
JR R31

Just jumping to and fro- gives me the error "Executing from non-mapped space".
This is what confuzzles me. Is my basic ASM code wrong? Is it PJ64? Though it couldn't be, since it also hangs up the N64.
I tried jumping to different places in the rom where I found some small available space, but then I get breakpoint errors and whathaveyou. Yes, I'm very new to ASM but I'm keen on getting the hang of it. I hope it's just my code, because that can easily be remedied. I'm not familiar with your lingo with PI request.

Thanks for the interest link, too! Worth checking out.

July 23, 2014, 06:41:14 pm - (Auto Merged - Double Posts are not allowed before 7 days.)
Been testing and it seems I can't use jumps at all!
I removed some non-critical code to do with clearing the player's inventory for next spawn, to make room for this simple test.
I wrote a simple "jump" command to jump a few lines down the code, to the highlighted line.
Game locks up with the jump command in there but runs fine if I remove it.

I need jumps to work for my project to ever finish!
Lots of work has gone into mapping out the offsets for everything I want to change.
It would be a shame if my project ends here.  :-\
« Last Edit: July 23, 2014, 06:48:45 pm by piip4 »

Zoinkity

  • Hero Member
  • *****
  • Posts: 565
    • View Profile
Re: Extended Duke Nukem 3D rom hack on N64
« Reply #5 on: July 24, 2014, 12:15:58 pm »
Sorry!  End of PAL is at 0x7E9158.

Jumps don't work that way on the N64.  What's an easy way to put it...when using J and JAL assume the upper nibble is the same as the address the jump is at.  In other words, jumps in rdram space stay in rdram space, jumps in ROM space stay in ROM space, jumps in other address ranges stay there too.
Actually, you can't set the upper nibble of those jumps.  The address mask is 0FFFFFFC, >>2 for the opcode.

So, the code you wrote is actually pointing to 807E9200, and since you're on an emulator with 4MB set as the default size for this ROM that isn't a valid address.  Since emulators initialize memory, even with the 8MB it would be executing NOPs until it ran over 80800000.


You can do what you want by using a JR or JALR though.  This jumps to whatever address you set in the register, regardless where it might be.  You return normally.
Code: [Select]
3C01B07F LUI AT,B07F
24219200 ADDIU AT,AT,9200
0020F809 JALR RA,AT
00000000 NOP
Then return the usual way:
Code: [Select]
03E00008 JR RA
00000000 NOP
(sorry, did the hex by memory and not 100% certain that JALR is written right.)

B0000000 is the uncached ROM range.  Pretty sure on console that's what you'd use, though emulators will permit physical addresses.

piip4

  • Jr. Member
  • **
  • Posts: 4
    • View Profile
Re: Extended Duke Nukem 3D rom hack on N64
« Reply #6 on: July 24, 2014, 01:10:35 pm »
You're absolutely right!
That works! You're very knowledgable of this. I wasn't quite sure if anyone could help with this seemingly peculiar problem as I googled a lot before posting here and found nobody complaining about the same thing. I have some catching up to do.

Thank you!
Work may continue now and that makes me very glad. :)