øAslickproductions.org/forum/index.php?PHPSESSID=5f0fck550j2m4m2fpbtkj2vkm1&topic=993.msg10724e:/My Web Sites/Slick Productions - FFIV Message Board/slickproductions.org/forum/indexe06f-2.htmlslickproductions.org/forum/index.php?PHPSESSID=5f0fck550j2m4m2fpbtkj2vkm1&topic=993.0e:/My Web Sites/Slick Productions - FFIV Message Board/slickproductions.org/forum/indexe06f-2.html.zxu~g^ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÈ0P.oúOKtext/htmlISO-8859-1gzip@øÕoúÿÿÿÿÿÿÿÿTue, 10 Mar 2020 12:04:28 GMT0ó°° ®0®P®€§²ð®t~g^ÿÿÿÿÿÿÿÿ4"oú Moving the location of Dialogue Bank 1

Author Topic: Moving the location of Dialogue Bank 1  (Read 2978 times)

Phoenix

  • FF4 Hacker
  • *
  • Posts: 456
    • View Profile
    • Phoenix Hacks
Moving the location of Dialogue Bank 1
« on: March 28, 2009, 06:59:07 AM »
I haven't even searched or tried yet, but does anyone know off-hand how to move the location of dialogue bank 1? I'm about 10% done with coding my events, dialogue, NPCs, etc. and I've used almost 50% of the dialogue space.
:nuts:
I thought it might save me some time in finding and decoding the ASM routine if I asked here first. Any takers?

Phoenix

  • FF4 Hacker
  • *
  • Posts: 456
    • View Profile
    • Phoenix Hacks
Re: Moving the location of Dialogue Bank 1
« Reply #1 on: March 31, 2009, 06:38:19 AM »
Since no one has posted, I assumed that no one knew the answer and did some searching for myself. It turns out that in my piles of ASM documentation I had written down the probable location of the dialogue loader  :lungs:  (don't even remember doing that...) so I started there, and lo and behold it was the right area. The loading for the pointers isn't quite next to the dialogue loading, but it's close enough it wasn't difficult to find. Here's the actual pointers loading data that you would need to change (FF2us 1.0 ROM with header):

Code: [Select]
033A8 BF 00 83 11 Load A with 1 byte at 88500+X ; \
033AC D0 F9 Branch to 033A7 if zero flag is clear ;  |
033AE BF FF 82 11 Load A with 1 byte at 884FF+X ;  | bank 2 pointers
033B2 C9 03 Compare A with #03 ;  |
033B4 F0 F1 Branch to 033A7 if zero flag is set ;  |
033B6 BF FF 82 11 Load A with 1 byte at 884FF+X ; /
033BA C9 04 Compare A with #04
033BC F0 E9 Branch to 033A7 if zero flag is set
033BE 88 Decrement Y
033BF D0 E6 Branch to 033A7 if zero flag is clear
033C1 E8 Increment X
033C2 8E 72 07 Store X to $7E:0772
033C5 64 DD Store 0 to $00:D+$DD
033C7 60 Return from subroutine

033C8 20 13 B2 Jump to subroutine at 03413
033CB BF 00 80 10 Load A with 1 byte at 80200+X ; \
033CF 85 3D Store A to $00:D+$3D ;  bank 1 [000-0FF] pointers
033D1 BF 01 80 10 Load A with 1 byte at 80201+X ; /
033D5 85 3E Store A to $00:D+$3E
033D7 A6 3D Load X with 2 bytes at $00:D+$3D
033D9 8E 72 07 Store X to $7E:0772
033DC A9 01 Load A with #01
033DE 85 DD Store A to $00:D+$DD
033E0 60 Return from subroutine

033E1 20 13 B2 Jump to subroutine at 03413
033E4 BF 00 82 10 Load A with 1 byte at 80400+X ; \
033E8 85 3D Store A to $00:D+$3D ;  bank 1 [100-1FF] pointers
033EA BF 01 82 10 Load A with 1 byte at 80401+X ; /
033EE 85 3E Store A to $00:D+$3E
033F0 A6 3D Load X with 2 bytes at $00:D+$3D
033F2 8E 72 07 Store X to $7E:0772
033F5 A9 01 Load A with #01
033F7 85 DD Store A to $00:D+$DD
033F9 60 Return from subroutine

033FA 20 13 B2 Jump to subroutine at 03413
033FD BF 00 A5 13 Load A with 1 byte at 9A700+X ; \
03401 85 3D Store A to $00:D+$3D ;  bank 3 pointers
03403 BF 01 A5 13 Load A with 1 byte at 9A701+X ; /
03407 85 3E Store A to $00:D+$3E
03409 A6 3D Load X with 2 bytes at $00:D+$3D
0340B 8E 72 07 Store X to $7E:0772
0340E A9 02 Load A with #02
03410 85 DD Store A to $00:D+$DD
03412 60 Return from subroutine

And the dialogue loading data:

Code: [Select]
034B7 AE 72 07 Load X with 2 bytes at $7E:0772
034BA E8 Increment X
034BB 8E 72 07 Store X to $7E:0772
034BE AE 72 07 Load X with 2 bytes at $7E:0772
034C1 A5 DD Load A with 1 byte at $00:D+$DD
034C3 D0 07 Branch to 034CC if zero flag is clear
034C5 BF 00 83 11 Load A with 1 byte at 88500+X ; bank 2 data
034C9 4C DB B2 Jump to location 034DB
034CC C9 01 Compare A with #01
034CE D0 07 Branch to 034D7 if zero flag is clear
034D0 BF 00 84 10 Load A with 1 byte at 80600+X ; bank 1 data
034D4 4C DB B2 Jump to location 034DB
034D7 BF 00 A7 13 Load A with 1 byte at 9A900+X ; bank 3 data
034DB 60 Return from subroutine

So, for example, I moved my bank 1 dialogue to 0x102800 by changing the data at 033CB to [BF 00 A6 20] and [BF 01 A6 20], the data at 033E4 to [BF 00 A8 20] and [BF 01 A8 20], and the data at 034D0 to [BF 00 AA 20]. It's worked correctly in my tests so far. Hopefully this information should be easier to find for the next person now.

 :cycle:

Lenophis

  • Forum Overlord
  • *
  • Posts: 1,688
  • Gender: Male
  • I sad
    • View Profile
    • Slick Productions
Re: Moving the location of Dialogue Bank 1
« Reply #2 on: March 31, 2009, 03:27:48 PM »
Since no one has posted, I assumed that no one knew the answer and did some searching for myself. It turns out that in my piles of ASM documentation I had written down the probable location of the dialogue loader  :lungs:  (don't even remember doing that...)
It never fails, does it? :bah:

It's good that you managed to figure it out though. If this game had some disassembled banks, then you guys wouldn't have to go digging in the same spots all the time for this information. :hmm:

119 bugs fixed and counting.

Phoenix

  • FF4 Hacker
  • *
  • Posts: 456
    • View Profile
    • Phoenix Hacks
Re: Moving the location of Dialogue Bank 1
« Reply #3 on: June 06, 2009, 04:10:59 AM »
So it turns out the loader doesn't load past one bank (i.e. once my pointers point to an area past the end of the bank, the dialogue doesn't display). Does anyone have any ASM trickery that would work around this? It'd be nice if someone had insight that could save me some time trying to rework the dialogue loading system...

Lenophis

  • Forum Overlord
  • *
  • Posts: 1,688
  • Gender: Male
  • I sad
    • View Profile
    • Slick Productions
Re: Moving the location of Dialogue Bank 1
« Reply #4 on: June 06, 2009, 04:35:17 AM »
That's fairly easy. If you hit a pointer that looks beyond a bank, increment the bank pointer (assuming the dialogue is in the next bank).

119 bugs fixed and counting.

Phoenix

  • FF4 Hacker
  • *
  • Posts: 456
    • View Profile
    • Phoenix Hacks
Re: Moving the location of Dialogue Bank 1
« Reply #5 on: June 06, 2009, 07:14:49 PM »
Thanks -- that worked, sort of. Incrementing the bank point works, but the dialogue pointer has to be reset to 0000 to point to the right location (at least in my implementation). Here's what I did, I replaced this:

Code: [Select]
034D0 BF 00 84 10 Load A with 1 byte at 80600+X ; bank 1 data
with this:

Code: [Select]
034D0 4C 00 FE Jump to location 08000 ; jump to new split bank determiner

08000 E0 00 56 Compare X with #5600 ; pointers above 5600 point to next bank
08003 B0 05 Branch to 0800A if carry is set
08005 BF 00 AA 20 Load A with 1 byte at 102C00+X ; bank 1 data, part 1
08009 60 Return from subroutine
0800A C2 20 Clear flags #20
0800C 8A Transfer X to A
0800D E9 00 56 Subtract #5600 from A
08010 AA Transfer A to X
08011 E2 20 Set flags #20
08013 BF 00 80 21 Load A with 1 byte at 108200+X ; bank 1 data, part 2
08017 60 Return from subroutine

It loads dialogue fine for the first 2 or 3 windows, and then the dialogue gets messed up. I figured out that single characters work fine, but DTE characters are not loading properly. (I attached an example that I liked.) I'm sure it's from subtracting from the pointer, but I can't figure out how to do it without that. Does anyone have ideas of how to fix this?

My backup plan is to split dialogue bank 1 (since it has 0x200 pointers) and move half of it to an entirely new bank, but that will take more coding, I think.

:edit:
Fixed. After taking a closer look at my code and what it might be doing, I realized I was using a 16-bit accumulator to subtract #5600, but not restoring what was in the top 8-bits after I did that. Somehow this was causing the DTE table pointer to point to 99A20 instead of 99900. I added a push and pull for A outside the subtraction, and things work smoothly now. Here's the revised code, in case anyone's interested:

Code: [Select]
08000 E0 00 56 Compare X with #5600 ; pointers above 5600 point to next bank
08003 B0 05 Branch to 0800A if carry is set
08005 BF 00 AA 20 Load A with 1 byte at 102C00+X ; bank 1 data, part 1
08009 60 Return from subroutine
0800A C2 20 Clear flags #20
0800C 48 Push A (2 bytes) onto stack
0800D 8A Transfer X to A
0800E E9 00 56 Subtract #5600 from A
08011 AA Transfer A to X
08012 68 Pull 2 bytes from stack and store in A
08013 E2 20 Set flags #20
08015 BF 00 80 21 Load A with 1 byte at 108200+X ; bank 1 data, part 2
08019 60 Return from subroutine

Thanks for the tip, Lenophis.
« Last Edit: June 06, 2009, 07:51:40 PM by Phoenix »