News: 11 March 2016 - Forum Rules
Current Moderators - DarkSol, KingMike, MathOnNapkins, Azkadellia, Danke

Author Topic: Understanding NES text routines  (Read 2773 times)

Psyklax

  • Hero Member
  • *****
  • Posts: 951
    • View Profile
    • Psyklax Translations
Re: Understanding NES text routines
« Reply #40 on: March 01, 2019, 06:27:30 am »
Okay, I thought I'd have an easy time but it's not quite as easy. I thought I could just stick my own routine in there and be done with it, but it crashed the game. A trace log left me with something missing, and I had to step through the code line by line before I realised what was happening.

The game decides to do a JSR and then PULL THE RETURN LOCATION from the stack and put it in RAM to use as a reference for the pointer table that exists there. I can't stand it when games mess with the stack! :( Anyway, these difficulties are why I enjoy ROM hacking, and with a bit more work I'm sure I'll figure something out.

EDIT: I think it's done! :) Apply this patch to a ROM that's been patched with the English patch you gave me:
http://s346165667.websitehome.co.uk/psyktrans/db3-items.ips

If there's any problem, let me know. ;)
« Last Edit: March 01, 2019, 09:06:08 am by Psyklax »

Gyroballer

  • Jr. Member
  • **
  • Posts: 27
    • View Profile
Re: Understanding NES text routines
« Reply #41 on: March 01, 2019, 10:53:14 am »
This is awesome, thank you so much! I had already made some changes to the title screen in the meantime and the patch was compatible with that, so everything is working perfectly.

I'd really like to be at your level someday, but for now, I'm just happy that people will be able to enjoy a more quality translation thanks to you.  :D

KingMike

  • Forum Moderator
  • Hero Member
  • *****
  • Posts: 6810
  • *sigh* A changed avatar. Big deal.
    • View Profile
Re: Understanding NES text routines
« Reply #42 on: March 01, 2019, 10:55:05 am »
One reason I can see a NES game doing a "push the address to the stack and then return" is to effectively jump to anywhere in the ROM.
One other reason is to set up a table of functions to jump to.
Perhaps less space than a IF HEX=00 JUMP FUNC-A ELSE IF HEX=01 JUMP FUNC-B... thing.
"My watch says 30 chickens" Google, 2018

Psyklax

  • Hero Member
  • *****
  • Posts: 951
    • View Profile
    • Psyklax Translations
Re: Understanding NES text routines
« Reply #43 on: March 01, 2019, 02:37:17 pm »
One reason I can see a NES game doing a "push the address to the stack and then return" is to effectively jump to anywhere in the ROM.
One other reason is to set up a table of functions to jump to.
Perhaps less space than a IF HEX=00 JUMP FUNC-A ELSE IF HEX=01 JUMP FUNC-B... thing.

Here's what happens: there's a JSR $803A, and immediately following that command is the pointer table used for the items list. So $9DDA is now sitting on top of the stack, and the code in this "subroutine" pulls that address off the stack and sticks it in $11-12, then does LDA ($11),Y to get the address in the pointer table, which it stores in $13-14, and does JMP ($0013). Then it goes through the weirdest backwards way of putting the text in RAM as described in a previous post, before finally doing an RTS, which takes it to $DB7B instead of $9DDB. As a hacker, messing with the stack like that just drives me nuts, because it's hard to follow what's going on. On the PC-98 I noticed it was more common as there are specific instructions dealing with the stack, but on the NES it doesn't happen that much.