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

Author Topic: What is the purpose of a pointer table for strings in a (GBA) game?  (Read 2928 times)

thatdude

  • Newbie
  • *
  • Posts: 2
    • View Profile
Hey there,

I just wondered: "Mh ... if someone translates a ROM, how can he change strings to be longer than they actually are without corrupting the memory?", typed some keywords into Google and came to a thread where Ryusui explained the pointer table pointing to the start address of the game's strings (http://www.romhacking.net/forum/index.php?topic=13936.0).
(I originally wanted to send him a PM, but his inbox is full, so I have to slake my desires here :D)

Due to my curiosity, I registered here just to ask a question:
Why do GBA games (and many more platforms, I guess) need this string pointer table? I understand what it does and how ROM hackers benefit from it. But as an original GBA game developer, why would I need this?

For example, in some GBA game, if I talk to someone who says text. Wouldn't it be enough to just load data from the ROM to some RAM? If I knew it's address in the ROM, why would I need to go "the long, indirect way" over a pointer table? The only good reason I can imagine is for official translations.

It may very well be that I misunderstand a lot. To be honest, I don't know much about ROM hacking, but I was just curious :)

Thanks for reading,
thatdude

Gideon Zhi

  • Discord Staff
  • Hero Member
  • *****
  • Posts: 3532
    • View Profile
    • Aeon Genesis
Re: What is the purpose of a pointer table for strings in a (GBA) game?
« Reply #1 on: July 22, 2014, 02:46:38 pm »
Organization. Pointer tables are essentially the values you find at array indexes, and retrieving a value from an array (provided the indexes are contiguous and of constant size) is an O(1) operation. You'd still have O(1) lookups with pointers hardcoded directly into a game's event code or assembly code but you lose the benefit of having all your strings in one place. (It's the difference between saying "Print string 6" and "Print string at address 0x3046B9.")

KaioShin

  • RHDN Patreon Supporter!
  • Hero Member
  • *****
  • Posts: 5698
    • View Profile
    • The Romhacking Aerie
Re: What is the purpose of a pointer table for strings in a (GBA) game?
« Reply #2 on: July 22, 2014, 03:52:52 pm »
The game simply needs to know where the text is.

Your question is like "Why does a house need walls? It would be faster to just build a roof and be done with it."
All my posts are merely personal opinions and not statements of fact, even if they are not explicitly prefixed by "In my opinion", "IMO", "I believe", or similar modifiers. By reading this disclaimer you agree to reply in spirit of these conditions.

Gideon Zhi

  • Discord Staff
  • Hero Member
  • *****
  • Posts: 3532
    • View Profile
    • Aeon Genesis
Re: What is the purpose of a pointer table for strings in a (GBA) game?
« Reply #3 on: July 22, 2014, 04:12:39 pm »
The game simply needs to know where the text is.

This isn't really the question, though. The OP wants to know why one would use a pointer table (strings stored in an array) instead of absolute string addresses hardcoded in the ASM or in event commands (strings as individual constants.) You absolutely can use absolute string addresses in asm/event etc, it just ends up horribly disorganized.

It's the difference between print(strings[6]) and print(constants.strings.bikke_threaten_player) or print("Aye, I am Bikke the Pirate, and surprised I am that you scurvy dogs have the nerve to face me. Mates! Get those landlubbers!").

thatdude

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: What is the purpose of a pointer table for strings in a (GBA) game?
« Reply #4 on: July 22, 2014, 05:13:01 pm »
Ah, that was exactly what I hoped to hear :) I just thought that in times of scarce memory, having the strings saved redundantly (ok, pointers vs. whole strings is not really that redundant) was a no-go and there must have been an other explanation.

Thank you, Gideon Zhi! :)

BlackDog61

  • Hero Member
  • *****
  • Posts: 784
    • View Profile
    • Super Robot Wars A Portable translation thread
Re: What is the purpose of a pointer table for strings in a (GBA) game?
« Reply #5 on: July 22, 2014, 05:26:50 pm »
There's also the fact that games aren't developed with correct nor full text from the get go. They are an iterative piece of work. And it helps developers during iterations to support evolutions with pointer tables (quicker / more flexible).

henke37

  • Hero Member
  • *****
  • Posts: 643
    • View Profile
Re: What is the purpose of a pointer table for strings in a (GBA) game?
« Reply #6 on: July 22, 2014, 05:35:16 pm »
It aids the workflow, they can put all the strings in one place and let the writer edit them all easily.

It is also a requirement for those message debugging options that some games have, can't display all the strings if there isn't a list of them.

Gideon Zhi

  • Discord Staff
  • Hero Member
  • *****
  • Posts: 3532
    • View Profile
    • Aeon Genesis
Re: What is the purpose of a pointer table for strings in a (GBA) game?
« Reply #7 on: July 22, 2014, 05:36:49 pm »
It is also a requirement for those message debugging options that some games have, can't display all the strings if there isn't a list of them.

This is an excellent point! It totally makes sense, and I hadn't even considered this.