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

Author Topic: PSX experts: Any idea why my translation fails to load on hardware?  (Read 3502 times)

Kil

  • Jr. Member
  • **
  • Posts: 12
    • View Profile
Hi I've mostly finished my English translation for Langrisser 4 PSX. People who tried to play it on a PSX/PSP reported that the game would sit at the loading screen at certain points so it's unplayable on real hardware at the moment. I've thought hard about what the problem could be, but the fact that it absolutely doesn't occur during emulation means I can't dig around in pSX debugger to find out what's wrong.

One weird thing about this all is that it works fine when loading the first few scenario scripts. At the end of the scenario 2 battle when it tries to load the epilogue, it fails to load.

Now there's essentially nothing strange about that particular data, yet it always fails to load. All the scripts are inside a 25MB file called SCEN.DAT on the CD. The scripts in SCEN.DAT are accessed by a simple virtual file system in this file. The VFS is just 4 byte little endian pointers to the start of each script's data. The game code reads the pointer of the script it wants and the pointer after it, and using these two values, seems to calculate the size/location of the data it wants and then fetches it from the CD (this part is fuzzy for me because I don't really know about the intricacies of how the PSX CD system works or CDROMs in general.) I took all of this into account when I made my text extraction/insertion tool so it automatically rewrites these pointers based on how big the new text is (The size of the dat file remains the same though - I erased stuff from an unused scenario for space).

Regardless of all that, I think the key to figuring this mystery out is the fact that the entire translation works fine on emulators, and only fails at certain points on real hardware. Whatever the problem is, it must be so miniscule and specialized that emulators aren't accurate enough to freeze over it. I assume some aspects of the PSX CD system have been abstracted in these emulators and just aren't emulated accurately, so there's no way to figure out the problem inside of an emulator debugger.

Some more info:
All of the files on the translated CD are the same size as the original, I've carefully seen to that
Made sure to pad the end of all data in rebuilt files to multiples of 0x800 as they should be
Poured over the output of all my rebuilt files in a hex editor numerous times - the troublesome data looks normal
I use CDMAGE to rebuild the CD/insert translated files
There are ASM hacks in the new executable but they don't seem to be the problem
The SYSTEM.BIN file (has a similar VFS in it) was also translated, but that loads fine

Any ideas?

Gemini

  • Hero Member
  • *****
  • Posts: 2007
  • 時を越えよう、そして彼女の元に戻ろう
    • View Profile
    • Apple of Eden
Re: PSX experts: Any idea why my translation fails to load on hardware?
« Reply #1 on: July 13, 2011, 11:54:23 am »
If it just hangs and kills the console, I say it's a memory alignment issue.
I am the lord, you all know my name, now. I got it all: cash, money, and fame.

Kil

  • Jr. Member
  • **
  • Posts: 12
    • View Profile
Re: PSX experts: Any idea why my translation fails to load on hardware?
« Reply #2 on: July 13, 2011, 01:15:33 pm »
There is some data after the text which is pushed and repointed... the PSX can't load anything with the lw opcode unless it's word aligned right? Yes, some of those are probably misaligned.

God damn it, this had me stumped for over a month.

I'm a bit surprised emulators allow misaligned memory reads, but I guess it is much faster than checking each memory read, and no real games are going to be reading any misaligned memory anyway.
« Last Edit: July 13, 2011, 01:26:04 pm by Kil »

Gemini

  • Hero Member
  • *****
  • Posts: 2007
  • 時を越えよう、そして彼女の元に戻ろう
    • View Profile
    • Apple of Eden
Re: PSX experts: Any idea why my translation fails to load on hardware?
« Reply #3 on: July 13, 2011, 07:14:49 pm »
The PlayStation emulator on the PSP actually crashes whenever a misaligned read/write takes place. It's a very good way to test stuff before even burning yet another CD.
I am the lord, you all know my name, now. I got it all: cash, money, and fame.

Kil

  • Jr. Member
  • **
  • Posts: 12
    • View Profile
Re: PSX experts: Any idea why my translation fails to load on hardware?
« Reply #4 on: July 13, 2011, 09:12:49 pm »
Well you were right apparently as my tester says everything's working now. The data after the text was sometimes being aligned to halfwords so any script had a 50% chance of crashing. Thanks.

weissvulf

  • Sr. Member
  • ****
  • Posts: 324
  • Good news! An anomaly solved the enigma.
    • View Profile
Sorry for resurrecting this post, but I recently had this same problem and found this thread through a search. I wanted to add a little information that might help anyone else having the same problem.

1. Maybe a no brainier, but LH/SH (Load/Store Halfword) commands have to be aligned also, as well as the LW/SW.

2. The PSx v1.13 debugger does seem to check for non-aligned memory read/writes IF there is a conditional break set up. It doesn't crash like a real Playstation would, but a misaligned LW seems to "blank" the register (loads "00000000") that is being loaded into. A misaligned SW is ignored (nothing is written to memory).

3. The PSP has a MIPS processor just like the original PS1 so it likely has a hardware restriction on misaligned Loads or Stores. So like Gemini said, if it causes the PSP emulator to lockup, misalignment is a likely culprit.

4. I haven't used them, but the commands LWL/LWR and SWL/SWR (load/store word left/right) seem to be functionally identical to LW/SW and supposedly allow misaligned reads/writes.  They read/write 4 bytes to the left or right of the given location. It might save some headaches use them instead.

In the game I'm working on, it originally used LH to read a two-byte Japanese letter, then advanced a second register (that stored the memory read locations) by 2: ready to read the next letter. When I gave it a half-width English font, I set it to read 1 byte, advance 1 byte. What I didn't realize was the game later reloaded the letter (using LH) to check for "dots/circles" accent marks. Since I had changed the memory register to advance by 1, the LH for the "dots/circles" was creating an intermittent misaligned read. Anyways, thanks Gemini and Kil for the helpful information  ;)

KC

  • Full Member
  • ***
  • Posts: 209
    • View Profile
4. I haven't used them, but the commands LWL/LWR and SWL/SWR (load/store word left/right) seem to be functionally identical to LW/SW and supposedly allow misaligned reads/writes.  They read/write 4 bytes to the left or right of the given location. It might save some headaches use them instead.
To clarify this, you can load/write unaligned words with LWL/LWR, but they only work in pairs. You have to point LWL to the last byte of the word in memory, and LWR to the first byte - or vice versa on big endian machines.
So when you want to read from 0x123 into r1:

Code: [Select]
lwl r1,0x126(r0)
lwr r1,0x123(r0)

If you use armips, you can use ulw/usw macros for those.