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

Author Topic: PSX - Relocating pointer table  (Read 1254 times)

theflyingzamboni

  • Jr. Member
  • **
  • Posts: 91
    • View Profile
PSX - Relocating pointer table
« on: February 27, 2018, 02:50:44 pm »
So I've run into an issue where the pointer table is located after the text it points to. I would like to be able to expand the text as needed, which means I need to be able to move the pointer table. But to do that, of course, I need to find and alter the commands that indicate the pointer table offset.

I've partially traced what's happening in the disassembler using pSX debugger and PCSXTrace:

Code: [Select]
800161c8 00041400: SLL     00000014 (v0), 140000fe (a0), 10 (16) -> this 140000fe is used to calculated several different offsets
800164b4 8e030008: LW      00000014 (v1), 0008 (800bc070 (s0)) [800bc078] -> load base address
800164b8 00021383: SRA     00fe0000 (v0), 00fe0000 (v0), 0e (14) -> calculate relative offset of pointer table
800164bc 00621821: ADDU    801a6d3c (v1), 801a6d3c (v1), 000003f8 (v0) -> add offset to base address to get pointer table location
800164c0 00081080: SLL     000003f8 (v0), 00000000 (t0), 02 (2)
800164c4 00431021: ADDU    00000000 (v0), 00000000 (v0), 801a7134 (v1)
800164c8 8c420000: LW      801a7134 (v0), 0000 (801a7134 (v0)) [801a7134] -> load first word at pointer table location
800164cc 00000000: NOP   
800164d0 00021080: SLL     ffffff6f (v0), ffffff6f (v0), 02 (2) -> pointer

I think what I need to do is change that 0x03f8 to the new relative offset of the relocated pointer table, but since it's calculated by a bit shift, there isn't really any flexibility. Plus, I have no idea how to find where in the disc image that command is stored into memory from.

I'm at a total loss right now. Does anyone have any experience with moving pointer tables? Is this something that can be done on PSX?
ROM wasn't hacked in a day.

Gemini

  • Hero Member
  • *****
  • Posts: 2015
  • 時を越えよう、そして彼女の元に戻ろう
    • View Profile
    • Apple of Eden
Re: PSX - Relocating pointer table
« Reply #1 on: February 27, 2018, 03:16:30 pm »
That looks like a simple int32 pointer table, hence why you get sll v0, t0, 2 @800164c0 to multiply the index by 4 (the size of int32). Alter the pointer at 800bc070 and you're done with relocating the pointer table.
I am the lord, you all know my name, now. I got it all: cash, money, and fame.

theflyingzamboni

  • Jr. Member
  • **
  • Posts: 91
    • View Profile
Re: PSX - Relocating pointer table
« Reply #2 on: February 27, 2018, 04:42:49 pm »
That looks like a simple int32 pointer table, hence why you get sll v0, t0, 2 @800164c0 to multiply the index by 4 (the size of int32). Alter the pointer at 800bc070 and you're done with relocating the pointer table.
Sorry if I'm misunderstanding, but wouldn't that not work? The word stored at 800bc078 is 801a6d3c, which also seems to be used as a base address to calculate the offsets of the text dimensions, which are scattered throughout the text itself. So if I alter that value so that it points to pointer table, won't that mess up all the other operations it's used in? Shouldn't I be altering the value added to the base address, rather than the base address itself?

Also, one of my problems is that I don't know how to find where in the image the word 801a6d3c is loaded into memory from anyway. 3c6d1a (little endian) occurs several times in word-aligned offsets, but never ending with 80, or even 00.
« Last Edit: February 27, 2018, 05:22:35 pm by theflyingzamboni »
ROM wasn't hacked in a day.

Valendian

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
Re: PSX - Relocating pointer table
« Reply #3 on: February 27, 2018, 05:01:45 pm »
Im not the biggest fan of that mnemonic format but what is this doing?
Code: [Select]
800164bc 00621821: ADDU    801a6d3c (v1), 801a6d3c (v1), 000003f8 (v0)
There is no opcode for 32bit indexing. Is there any chance that this is a pseudo opcode? If so the pointer will appear split up like this

Code: [Select]
lui v0, 0x801b
ori v0, 0x6d3c

weissvulf

  • Sr. Member
  • ****
  • Posts: 324
  • Good news! An anomaly solved the enigma.
    • View Profile
Re: PSX - Relocating pointer table
« Reply #4 on: February 27, 2018, 05:23:14 pm »
What you're wanting to do is move the pointer-table further away from the text in order to expand the text. Can you instead move some of the the text further away from the pointer table? Then you would probably just have to edit the individual pointer entries for the moved text. You have the last-op-listed labeled as 'pointer', but it doesn't appear to be an actual memory address. What does the game do with the 0xffffff6f value to get the actual text start address?

Quote
So if I alter that value so that it points to pointer table, won't that mess up all the other operations it's used in? Shouldn't I be altering the value added to the base address, rather than the base address itself?
I think what he was describing is moving the entire text-block (pointers + text). You still have to edit the individual text-pointer entries to move the text further away from the pointer+table, thus making more room.

theflyingzamboni

  • Jr. Member
  • **
  • Posts: 91
    • View Profile
Re: PSX - Relocating pointer table
« Reply #5 on: February 27, 2018, 05:58:05 pm »
What you're wanting to do is move the pointer-table further away from the text in order to expand the text. Can you instead move some of the the text further away from the pointer table? Then you would probably just have to edit the individual pointer entries for the moved text. You have the last-op-listed labeled as 'pointer', but it doesn't appear to be an actual memory address. What does the game do with the 0xffffff6f value to get the actual text start address?
 I think what he was describing is moving the entire text-block (pointers + text). You still have to edit the individual text-pointer entries to move the text further away from the pointer+table, thus making more room.
Wow, thanks! This got me thinking about it in an entirely different way!

To answer your last question first, the game shifts the value (in this case 0xffffff6f) left 2 bits. It then adds this new value to the offset of the start of the pointer table.

Which makes me realize that there's no reason for any of the text to be before the pointer table at all. It's just adding the pointer value, so it shouldn't matter whether the value is positive or negative. I tried adding some new text after the pointer table with a positive pointer value, and it worked fine. Still used the text dimensions from the original first pre-table text entry though.

The issue with those text dimensions though is that they alternate with the text. So it's text block - dimensions - text block - dimensions - etc., with the pointer table at the end. So as soon as I change the length of the text that a particular dimension value is associated with, the code will be pointing to the wrong offset. I'd need to change the offset value being added to the base address, no matter what that base address is.

I think the easiest way around this is to put all of the modified text after the pointer table, and just update the dimension values in the original text block. That gets rid of any need to mess around with opcodes or whatever. I'll just have to do a bit of finagling with my script inserter to handle automating this particular situation.
ROM wasn't hacked in a day.