øAslickproductions.org/forum/index.php?PHPSESSID=5f0fck550j2m4m2fpbtkj2vkm1&topic=1933.0e:/My Web Sites/Slick Productions - FFIV Message Board/slickproductions.org/forum/index63eb.htmlslickproductions.org/forum/index.php?PHPSESSID=5f0fck550j2m4m2fpbtkj2vkm1&board=17.60e:/My Web Sites/Slick Productions - FFIV Message Board/slickproductions.org/forum/index63eb.html.zxˆ9h^ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÈ °VÌ OKtext/htmlISO-8859-1gzip8:ÖÌ ÿÿÿÿÿÿÿÿWed, 11 Mar 2020 01:22:41 GMT0ó°° ®0®P®€§²ð®ˆ9h^ÿÿÿÿÿÿÿÿ¿+Ì  Text display subroutines

Author Topic: Text display subroutines  (Read 5446 times)

noisecross

  • FF5 Hacker
  • *
  • Posts: 146
    • View Profile
Text display subroutines
« on: April 16, 2014, 06:17:12 AM »
Hello everybody,

First of all let me introduce myself. I am noisecross and currently I am trying to hack another translation of the SNES FFV to my mother tongue (Spanish).
I have been looking for some information about the memory map of the game, the disassembles, etc... but I can see the less documented part of the game is just the code related with texts displaying.

So, I am here to ask for some information just about that. My goal is not using the RPGe translation project as a template because their patch increases the size of the ROM and I am trying to keep the original 16Mbits size.

Currently I have detected the position of every text table on the ROM, the tables with fixed register sizes (i.e. the items) and the tables with offsets and variable register sizes (i.e. the item descriptions). Probably relocating the text tables I can manage to keep the original ROM size taking into account that the 1bpp graphic table used to store the Japanese kanjis is not going to be used on a western translation.

If you are interested, I will share every interesting info I found on my researches.

LightPhoenix

  • FF5 Hacker
  • *
  • Posts: 130
    • View Profile
Re: Text display subroutines
« Reply #1 on: April 19, 2014, 05:58:28 PM »
Hola!

Most of the information about the text locations can be found in the guides on the front page here, but there are a few minor stragglers here and there that aren't documented as far as I know (for example, some of the text stuff).  Also, a lot of the menu system is not very well documented here, but I've done a bunch of research on it and would be happy to answer any questions.  Feel free to share anything you've found out!

noisecross

  • FF5 Hacker
  • *
  • Posts: 146
    • View Profile
Re: Text display subroutines
« Reply #2 on: May 08, 2014, 05:40:05 AM »
Hi again,

Thank you LightPhoenix.

I have done a (briefly commented) disassembly of the bank C1 to start working on the reverse engineering and the comprehension of the code. I think I have disassembled it correctly in, at least, a 95%.

Please feel free to download it at https://drive.google.com/file/d/0B_2QTJAEY6l-ZDY5bEh0WHhoLVk. If anyone is interested, you can always upload it to the slickproductions docs page and highlight me any error you found on the file.

a lot of the menu system is not very well documented here, but I've done a bunch of research on it and would be happy to answer any questions.

Do you have that research documented? It should be nice to see how the menu works as I am going to have problems to fit the western words inside the little menu windows. Just if you can give me a list with the addresses of the main drawing routines of the menu , it would be a great help. Thanks a lot!

LightPhoenix

  • FF5 Hacker
  • *
  • Posts: 130
    • View Profile
Re: Text display subroutines
« Reply #3 on: May 11, 2014, 04:18:16 PM »
So, my work on it is a bit all over and I haven't looked at it in a while (been taking a break from FF5).  I make no claim that any of this is exactly right.

I've attached a few text files that document what I have, it should be enough for you to start figuring out anything else.

C1 is probably not the place you need to look; it mostly handles sprite animation.  That's not to say it's not involved, but most of what I've seen is in C2,

The core of the out-of-combat menu layout is found at C2/A075, with the actual data (12 words; 24 bytes) starting at C0/F601.  The actual text drawing and menu control is the 11th word, and is itself a link to a table.  The layout is a two byte header for the table size, and then a list of eight byte entries.  For example, the Item menu looks like this:

Code: [Select]
Item Menu Controls - C3/A73C
============================
(Data Length)
18 01

(Use/Sort/Rare)
     IT IP CX CY U  D  L  R
----------------------------
(00) 0F 01 40 10 00 00 00 02
(01) 0F 02 58 10 01 01 00 02
(02) 0F 03 70 10 02 02 00 03
(03) 0F 04 A8 10 03 03 02 03

(Item List)
     IT IP CX CY U  D  L  R
----------------------------
(04) 10 01 08 4E 1A 06 20 05
(05) 10 02 78 4E 1A 07 04 06
(06) 10 03 08 5A 04 08 05 07
(07) 10 04 78 5A 05 09 06 08
(08) 10 05 08 66 06 0A 07 09
(09) 10 06 78 66 07 0B 08 0A
(0A) 10 07 08 72 08 0C 09 0B
(0B) 10 08 78 72 09 0D 0A 0C
(0C) 10 09 08 7E 0A 0E 0B 0D
(0D) 10 0A 78 7E 0B 0F 0C 0E
(0E) 10 0B 08 8A 0C 10 0D 0F
(0F) 10 0C 78 8A 0D 11 0E 10
(10) 10 0D 08 96 0E 12 0F 11
(11) 10 0E 78 96 0F 13 10 12
(12) 10 0F 08 A2 10 14 11 13
(13) 10 10 78 A2 11 15 12 14
(14) 10 11 08 AE 12 16 13 15
(15) 10 12 78 AE 13 17 14 16
(16) 10 13 08 BA 14 18 15 17
(17) 10 14 78 BA 15 19 16 18
(18) 10 15 08 C6 16 1B 17 19
(19) 10 16 78 C6 17 1B 18 21

(Scroll Up/Down)
(1A) 86 02 00 00 00 00 00 00
(1B) 86 01 00 00 00 00 00 00

(Submenu - Player Select)
(1C) 1E 01 08 60 1F 1D 1C 1C
(1D) 1E 02 08 80 1C 1E 1D 1D
(1E) 1E 03 08 A0 1D 1F 1E 1E
(1F) 1E 04 08 C0 1E 1C 1F 1F

(Scroll Right/Left)
(20) 86 04 00 00 00 00 00 00
(21) 86 03 00 00 00 00 00 00

(Weapon Equip Info)
(22) 24 01 00 00 22 22 22 22

The first entry is an index that is used to determine function.  For example, index #10 handles item menu entries.  However, the actual jumping is not so simple.

The code starts at roughly C2/A47C.  It looks at whether the instruction has changed or not and whether you're scrolling or not.  For non-scrolling instructions, the flow is basically 1) check of the instruction type changed; 2a) if it didn't, run the no-change code; 2b) if it did, run the previous instruction's exit code; 3b) check if the new instruction has special enter code; 4b) if it did, run the enter code; 4c) if it didn't, run the no-change code.  Phew.

So for #10, C2/AC01 is the code for if you've just started selecting an item (ie, pressed A on Use) whereas C2/AC1E is the code if you moving to another item (ie scrolling through the list).  There's no exit code for #10, it just peaces out.

These functions control pretty much all of the non-combat menu drawing.  For example, the location to draw text to is located at C0/ED8F and read at C2/C7DF.  However, various layout stuff is handled  by other data in the original 12-word table.
« Last Edit: December 08, 2014, 04:48:55 AM by Jorgur »

noisecross

  • FF5 Hacker
  • *
  • Posts: 146
    • View Profile
Re: Text display subroutines
« Reply #4 on: May 27, 2014, 10:14:27 AM »
Wow! Thanks a lot. I find it really useful : )

I have been taking a look on the main speech read functions (bank C0) to understand how the speech is stored and read in both Japanese and RPGe versions. Anybody interested, can found a draft written (in crap English) about that on https://docs.google.com/file/d/0B_2QTJAEY6l-ZUp4TmpqQzNEZnc/edit

The VWF has been troubling me for a while but I think I have understood how it works and can write some ASM to implement it.

By the way LightPhoenix, in another post you are talking about finding a way to free RAM in order to store some data you need for a hack. I am trying to avoid the usage of a memory buffer in my research (the $1C00), so maybe you could use that space.

noisecross

  • FF5 Hacker
  • *
  • Posts: 146
    • View Profile
Re: Text display subroutines
« Reply #5 on: June 07, 2014, 04:17:59 PM »
I was able to write some ASM to add a VWF to my hack, but after doing some experiments I think there is no way to store all the speech in just one bank.

The uncompressed text have a size of about 0x22000 bytes.
Using the 70 slots dictionary the game have (choosing the better words to fill the dictionary), the size goes to 0x1C000 bytes.
Appliying Huffman compression, the size is about 0x12300 bytes plus a Huffman tree of 0x600 bytes.

I don't really know how to compress further that point so looks like I am going to be forced to extend the size of the rom to store all the text I want to display.

Jorgur

  • Moderator
  • *
  • Posts: 437
  • Gender: Male
    • View Profile
Re: Text display subroutines
« Reply #6 on: June 08, 2014, 04:52:19 AM »
So, you will be using RPGe's translation as a template after all, or...?

noisecross

  • FF5 Hacker
  • *
  • Posts: 146
    • View Profile
Re: Text display subroutines
« Reply #7 on: June 08, 2014, 09:41:12 AM »
Hello Jorgur. Well I don't have decided it yet.

The Japanese rom is very compacted and all the free space which can be used to extend the text tables is the kanji graphics section (10240 bytes)... I can use that space to store part of the speech and the Huffman tree, but then there is not enough space to extend the remaining tables (battle speech, locations, items, etc...)

That means I don't find any way to translate the game without extending the size of the rom. As I don't want to reinvent the wheel I will probably end up using the RPGe translation as a template (if I can contact them and asked for their permission) Anyway I would like to think about it carefully.

Are you interested in me working over the RPGe translation?
« Last Edit: June 09, 2014, 03:04:27 AM by noisecross »

Jorgur

  • Moderator
  • *
  • Posts: 437
  • Gender: Male
    • View Profile
Re: Text display subroutines
« Reply #8 on: June 09, 2014, 03:17:16 AM »
Not particularly, but it would save a lot of time. Also, the translation by RPGe does some nifty things such as allowing for longer item/spell names in battle.

There is a Japanese hack for FF5 called Ancient Cave. It uses some of the same space as RPGe's translation, so when some people decided to translate the hack into English they couldn't use RPGe's translation as a template. This resulted in things like "TempTango" instead of "Tempting Tango" and "ElectroMag" instead of "Electromagnetic Field".

noisecross

  • FF5 Hacker
  • *
  • Posts: 146
    • View Profile
Re: Text display subroutines
« Reply #9 on: June 09, 2014, 05:03:18 AM »
Yes, I know. These are the things I wanted to understand and "replicate" starting from the Japanese version.

But well. I guess I'm not "cheating" by using their job as a template after some months of reverse engineering the ROM. And as you said, it would save a lot of time.

I will develop a couple of tools to extract and to inject the text data, and after I found them operational I will share them here.

noisecross

  • FF5 Hacker
  • *
  • Posts: 146
    • View Profile
Re: Text display subroutines
« Reply #10 on: August 30, 2014, 08:49:35 AM »
As I said, here is a tool developed to edit more or lees every text in the game.
Please, feel free to share and use it.

 :edit: Version v0.9 avaliable at 7th January 2015
« Last Edit: January 07, 2015, 06:50:54 AM by noisecross »

Digitsie

  • Mom Bomb
  • *
  • Posts: 105
    • View Profile
Re: Text display subroutines
« Reply #11 on: January 13, 2015, 08:13:28 PM »
My difficulty is that when I try to run the program it never shows up. I can find it in windows processes,  but it won't give me the interface. I'm looking at the readme file... the only thing I can think of is that I have an SFC file.. does the rom have to be in the same directory with a .smc file?

noisecross

  • FF5 Hacker
  • *
  • Posts: 146
    • View Profile
Re: Text display subroutines
« Reply #12 on: January 14, 2015, 03:21:03 AM »
Nice. I have not experienced that behavior before.

The main window is displayed at the beginning of the run just after reading the TBL. No other files required.

So, after the first time you run the tool, it has been created in the same directory a "default.tlb" file?
I am attaching here a TBL file. Put it in the same directory than the tool because maybe it doesn't have rights to create a new default TBL file. Try to run it again after doing that.

Check also the .NET Framework runtime environment you have installed. This tool requires .NET 4.0 Client Profile.
I am attaching here also a dummy version which requires .NET 3.5 Client Profile.

If you are able to run it, please write me how did you made it.
I can also generate a setup file, but I usually prefer portable tools.

Digitsie

  • Mom Bomb
  • *
  • Posts: 105
    • View Profile
Re: Text display subroutines
« Reply #13 on: January 14, 2015, 07:31:44 AM »
I already had 4.52 .NET installed.

Putting the default table in the same directory as the program worked.

Ok! Good to know.

Now how do I get it to read the .SFC? There's no 'all files' option. I'm using the translated .sfc rom.

noisecross

  • FF5 Hacker
  • *
  • Posts: 146
    • View Profile
Re: Text display subroutines
« Reply #14 on: January 14, 2015, 07:38:02 AM »
Rename the file with extension SMC and it should work. I'll add displaying also SFC files in the next update.

Please, notify me if you find more issues writing files (i.e. after exporting a CSV file or editing the file).