Using a pointer recalculator to insert text blocks easily.
Written by Prez@lfx.org.

Last updated: August 23rd, 2000.


Introduction:
  The goal of this document is to explain in simple terms how to use
  a utility to recalculate the pointers for a large block of text. Why?
  Mainly because I see a lot of people spending hours doing it by hand,
  or because the utilities out there that I've seen lack the documentation
  needed to get a large audience of users to concider using them.


Requirements:
  You will need a few things before being able to dig into this document:

  Included:
  - the Final Fantasy 1 table file (ff1.tbl)
  - the example script file (freedom.txt)
      This script file has a list of freedom related quotes that are
      formatted and ready to be inserted into the FF1.NES rom. I've also
      added our "Default Line" as well, for all the original entries that
      aren't accounted for in the new script.

  Not included:
  - "A Simple Pointer Table Recalculator"
      This is a simple pointer table recalculator (hehe) that I wrote, and
      you can get it at http://prez.lfx.org/dist/recalc/recalc10.zip .
  - a copy of Necrosaro's Thingy
      I know a few of you might be scared of it, as a lot of newer hackers
      are, but this is one of the ultimate hacking tools out there. Don't
      worry, you only have to hit a few buttons, and you might even find
      that you like it.
  - a Final Fantasy 1 (english) rom
  - a brief understanding of pointers:
      Not taught here, I remember a
      good document was 'MadHackers guide to pointers', or something
      like that. Try picking that document up, and reading it first)
  - a general romhacking know-how:
      This document requires that you a "assumed" level of knowledge
      about romhacking. If you don't, you might run into terms or ideas
      that you don't understand. If this is the case, learn about them,
      then return to this tutorial.


Okay ramblers, let's get rambling:

  (pre). Open ff1.nes in Thingy.
       Put your ff1.nes, ff1.tbl, and freedom.txt all in the same directory,
       then run "C:\THINGY\>thingy ff1.nes ff1.tbl". I've already setup the
       table file to have all the bookmarks you'll need, so the Thingy
       portion of this document should be rather simple.

  1. Find the location at which the dialog block starts.
       (Don't do this for this demonstration, since I've done it for you)

       Chances are that if you have been able to dump the script (properly),
       that you know where this address is. An easy way to find this is to
       goto a string in that dialog block, then start scrolling upwards.
       After scrolling up a bit, you will run into a place where it stops
       displaying text, and more so just gibberish. In the Final Fantasy
       rom, it looks a little like this:

         t m mm7mqm#m#mhenton
         aln9nQnln.n#n#n#n
         #o woSo#olip#phiqyoq
         Nothing here./LIGHT W
         ARRIORS.. Just as*i
         n Lukahn's prophecy
         .*Garland has kidnap

       As you can see, "Nothing here." is the first string in this dialog
       block. Since the string "Nothing here." starts at 28210h in the rom,
       this will be our "Dialog Block Start" address. Make note of this.

         Dialogue start: 28210


  2. Insert the new script.

       Now, this is where the thingy goodness comes in. In the table file
       I've already added location and inserting bookmarks that look
       like this:

         (28210h)Dialogue Block
         {28210h-freedom.txt}Freedom

       The first one is a location bookmark, and the second one is a
       script file inserting bookmark. Don't think about it too much, but
       this is something you'll use a lot if you start using thingy. I find
       them very helpful, since I don't have to keep retyping addresses.

       So, now that you've opened FF1.NES in Thingy, hit "J" (Jump), and
       select the bookmark named "Dialogue Block". You will now be at the
       "Nothing here." line.

       Now, to insert the freedom.txt into the game, hit "I" and then select
       the bookmark called "freedom". Wasn't that easy? But you're not done
       with Thingy yet.

       There are still a few addresses/values we need to get our hands on,
       so let's do that.

         Dialogue start:          28210
         Dialogue end:            ?
         Pointer table start:     ?
         Break value:             ?
         Default pointer address: ? 


  3. Find the Dialogue block ending address, and default pointer address.

       First, the Dialogue end address will be the last character before the
       message break in the last line in the new script, excluding the
       "Default message". This might sound hard, but it's really simple:

       Since the default message was included in our script file, (if you
       didn't look at the script, the default line is:

         I have no political
         insight.<END>

       ) the last message is going to be the message directly before this:

         One man with courage is
         a majority.
             --Thomas Jefferson<END>

       The Dialogue end address is the location at which the 'n' in Mr.
       Jefferson's last name is stored. If you goto the location in rom, you
       will see that it is stored at 2844E.

       Also, while we're here, we can grab the address of the Default
       message, which is 28450. (The starting of the "I have no po..." line.)

         Dialogue start:          28210
         Dialogue end:            2844E
         Pointer table start:     ?
         Break value:             ?
         Default pointer address: 28450 

  4. Find the Pointer Table Starting address

       Now comes the tricky part, finding where the pointer table starts.
       If you know a simple way to calculate the pointers for the game you
       are working with, you can easily calculate the pointer for the first
       message. If I haven't already mentioned, the pointer table should be
       directly above the dialogue block, so this makes it somewhat easier
       to find the starting of the pointer table.

       Since a lot of the games I've worked with don't have a simple way of
       calculating the pointer (because they have some odd offset value),
       I'll try and explain a good way of spotting the beginning of a table
       file. This method may not work for you, but it has worked for me many
       times.

       Basically, scroll upwards from the start of the dialogue block
       in your hexeditor (Thingy:) and watch the second byte of each
       line (on the hexidecimal side of the screen). You should notice
       that the number you are looking at gets progressively smaller.
       It will probably look something like this:

           ,--.
         A3|A2|E9 A2 03 A3 5C A3 78 A3 8A A3 95 A3 BB A3
         E5|A3|35 A4 65 A4 94 A4 DA A4 F8 A4 16 A5 5C A5
         7D|A5|CA A5 0F A6 30 A6 4F A6 89 A6 A1 A6 CB A6
         DF|A6|23 A7 3D A7 63 A7 94 A7 F1 A7 1E A8 4E A8
         6E|A8|7C A8 CF A8 12 A9 36 A9 6F A9 9D A9 C1 A9
           `--'                                   

       After a bit, the numbers you are looking at will drop unreasonably:

         01 01 01 01 05 05 05 05 05 05 05 03 05 05 05 03
         01[01]01 01 01 01 01 01 01 02 00 03 03 03 03 03
         00[82]09 82 5C 82 BD 82 D9 82 30 83 53 83 D1 83
         FF 83 5E 84 78 84 94 84 CF 84 08 85 27 85 80 85

       It is a worthy guess that 00 82 is the first, pointer.

        [00]82 09 82 5C 82 BD 82 D9 82 30 83 53 83 D1 83
         
       The location of the "00" byte will be the Pointer table start
       location. In the FF1.NES rom, this is at 28010.

         Dialogue start:          28210
         Dialogue end:            2844E
         Pointer table start:     28010
         Break value:             ?
         Default pointer address: 28450 

  5. Find the Dialogue Break Value.

       ..last but not least, the Break Value. This will be the value that
       tells the game to stop. This is the \XX value in your FF1.TBL table
       file. This is so simple to find that I won't explain it :) The value
       is 00.

         Dialogue start:          28210
         Dialogue end:            2844E
         Pointer table start:     28010
         Break value:             00
         Default pointer address: 28450 



  6. Run the program..

       C:\THINGY>RECALC.EXE FF1.NES 28210 2844E 28010 00 28450

       Recalculating: Dialog Block (28210-2844E)
                      Pointer Block (28010)
                      1st pointer: 8200
                      Break value: 00

     ..and then go play the game, I've included a few snapshots of what this
     particular tutorial's output is, so hopefully the same method worked for
     you.


Thanks goes out to:
  
  Of course, no romhacking document is complete without a little hello to
  all those people who have helped you along the way.

  MadHacker
    You wrote the first pointer document I ever read, and I still refer new
    hackers to it.
    
  Aziwoqpd
    This poor guy had to put up with all my silly programming questions when
    I first started programming. I appricate it very much. He has also been
    more than kind to host my website, and has done me a done of favors.

  Haws
    Another programming buddy of mine. Thanks again for the "UNIX Network
    Programming" book, and all the help you've offered by explaining.

  DesertAngel
    Thanks for nothing, fool.. You wouldn't even offer a word of advice when
    I had that overflow bug ;) all you could say was "Uhh.. I'm having sex
    right now", well thanks :) because after a short debugging session, I
    fixed it myself :) Thanks for this "tough love" support/lazyness.

  The CTC
    Thank you for the service that you provide to romhackers. It is most
    appricated by everyone.


Contact:

  Did you like this tutorial? Did you hate it? Do you hate me?
  You have no idea how much I want to know :) So bring it on..

  E-mail: prez@lfx.org
  ICQ:    1035105
  IRC:    prez_ on EFnet (#romhacking)
