Author Topic: Chrono Trigger - The Fifth Element  (Read 3380 times)

PowerPanda

  • Guru of Time
  • Earthbound (+15)
  • *
  • Posts: 43
    • View Profile
Chrono Trigger - The Fifth Element
« on: August 18, 2023, 10:14:40 pm »
So, for a long time, I've wanted to make a CT hack that separates Frog and Marle into different elements, Water and Ice. I've hoped that if I ignored this idea long enough, it would go away, but it didn't. So tonight I started digging.

My original thought was to have Ice replace the Shadow element, and turn all Shadow attacks into non-elemental damage. That would mess with the few enemies that absorb shadow though, not to mention messing with counterattacks and Dual Techs.

However, in looking at some of the data tables, it looks like there MIGHT be room to add up to 4 more elements. I want to get some of these ideas down so you can all tell me what's wrong with my logic.
------
TECH DATA (https://www.chronocompendium.com/Term/Tech_Data_Notes.html)

Byte 4 controls whether it's a physical/magic attack in its lower nibble, and which element it is in its upper nibble. Byte 5 is unused though. So if physical/magic were moved to Byte 5, then that would free up 4 bits in Byte 4 for new elements.

BATTLE DATA (https://www.chronocompendium.com/Term/Battle_Data_Format.html)

Byte 1 shares this same property, and its upper nibble even lines up with Tech Data Byte 4 (80 is Lightning, 40 is Shadow, 20 is Water, and 10 is Fire). The lower nibbles appear to be all unused. I don't know what Byte 1 does, but there is room for adidng more here.

That leaves finding unused bytes for the actual element defense. It looks like bytes 1C, 1F,  24, and 4F are all unused. Could those be used for defense against new elements?

MENU ELEMENT GRAPHICS (https://www.chronocompendium.com/Term/Attack_Types.html)

If the DS graphics were used, which are half the size, there would be leftover tiles for more elements.
------

I'm thinking the additional elements would be:
5 - Ice, for Marle
6 - Wind, an element not specifically for 1 character, used for things like Slash, Blade Toss, Falcon Strike, and Tail Spin.
7 - Hot, one of 2 "secret" elements used for color-coded enemies and counter-attacks. This responds to Fire, Lightning, and Wind, so that a Red enemy can be hit with any element.
8 - Cold, the other "secret" element, which responds to Ice, Water, and Shadow. Blue enemies can be hit with either.

So color me surprised, but this actually seems... doable? Please tell me why I'm wrong so I can get this out of my head permanently.

Mauron

  • Guru of Reason Emeritus
  • Errare Explorer (+1500)
  • *
  • Posts: 1765
  • Nu-chan
    • View Profile
    • Maurtopia
Re: Chrono Trigger - The Fifth Element
« Reply #1 on: August 20, 2023, 03:24:02 pm »
I wrote most of those notes, so I can answer your questions.

Tech data: This part should be good. You should be able to treat Bytes 4 and 5 as a long bitfield.

Menu element graphics: It would be just as easy to add new graphics in the same style as the SNES version and just block off the necessary space through Temporal Flux.

Battle Data: This is the hard part. Not impossible, but you also have to consider the player and enemy data equivalents. I'll address each piece separately.

Byte 1 comes from player data. Each characters gets a bonus to elemental defense based on this value. The labeled unused values are set in character data, but not checked. I gave them labels for my best guess depending on who they were set on. They could easily be repurposed.

Elemental defense: For coding purposes, it would be best keep these together. The unknowns at the end are likely unused, but this was harder to confirm than 4F because of the nature of character data.

Enemy data: This is the biggest hurdle - there's only one unused byte, 05, and elemental defense needs a full byte to be set.

Battle data was designed to be 0x80 bytes long for ease of coding purposes. Character data was designed to be shorter, only 0x50 bytes long. Because 0x4F gets preserved, it's easier to see that end game saves have this unchanged, while anything after that only exists for a single battle. Those large unknown groups are likely unused as well.

For AI purposes, you can have more reaction flags than you have actual elements. The attack flags on byte 4 are ANDed with the reaction flags in AI, and a non-zero result is a hit.

Normally, this means the AI checks one flag against one or two incoming ones, but this could be reversed as checking three elements (Ice, water, shadow) against an incoming attack (magical ice).

AI notes (https://www.chronocompendium.com/Term/Enemy_AI.html)

Basically, it depends on how big a project you want.

PowerPanda

  • Guru of Time
  • Earthbound (+15)
  • *
  • Posts: 43
    • View Profile
Re: Chrono Trigger - The Fifth Element
« Reply #2 on: August 20, 2023, 10:08:28 pm »
Thanks for the reply. If I'm understanding it correctly, adding 1 element would be a lot more doable than adding 4. So if I were to just add "Ice", then it could use byte 4F, and I wouldn't have to shuffle as much around.

That would be doable. I looked through enemies last night, and realized I didn't have to have a "hot" and "cold" hidden element. That was overcomplicating things. Wind would be nice to have, but it doesn't add nearly as much as making Frog and Marle have separate elements.

Is there a battle code disassembly available anywhere? I want to check to see if the element bytes are direct-referenced or indexed. Sorry, I'm pretty new to Chrono Trigger, aside from the music engine. Most of my work on the Chrono Trigger Soundtrack Expansion was using the exact same tools as I used for my work on Final Fantasy VI, and just shifting data references. I have done several hacks that use the same approach as this before though; just for different purposes.

inuksuk

  • Earthbound (+15)
  • *
  • Posts: 41
    • View Profile
Re: Chrono Trigger - The Fifth Element
« Reply #3 on: August 22, 2023, 07:04:27 pm »
The routine starting at $C1EF39 reads elemental defenses. The first section tests the element bitflags and chooses an index to read the corresponding elemental defense.

Code: [Select]
     Weapon Effect 0A: TDC                                  ;C1EF39|7B      |      ; Magic Attack
                       LDA.W $B190                          ;C1EF3A|AD90B1  |00B190; Load element/AI byte
                       STA.B $2C                            ;C1EF3D|852C    |00002C; 
                                                            ;      |        |      ; 
       Test Lightning: BIT.B #$80                           ;C1EF3F|8980    |      ; 
                       BEQ Test Shadow                      ;C1EF41|F003    |C1EF46; 
                       TDC                                  ;C1EF43|7B      |      ; Load zero
                       BRA Element was detected             ;C1EF44|8016    |C1EF5C; 
                                                            ;      |        |      ; 
                                                            ;      |        |      ; 
          Test Shadow: BIT.B #$40                           ;C1EF46|8940    |      ; 
                       BEQ Test Water                       ;C1EF48|F004    |C1EF4E; 
                       LDA.B #$01                           ;C1EF4A|A901    |      ; Load one
                       BRA Element was detected             ;C1EF4C|800E    |C1EF5C; 
                                                            ;      |        |      ; 
                                                            ;      |        |      ; 
           Test Water: BIT.B #$20                           ;C1EF4E|8920    |      ; 
                       BEQ Test Fire                        ;C1EF50|F004    |C1EF56; 
                       LDA.B #$02                           ;C1EF52|A902    |      ; Load two
                       BRA Element was detected             ;C1EF54|8006    |C1EF5C; 
                                                            ;      |        |      ; 
                                                            ;      |        |      ; 
            Test Fire: BIT.B #$10                           ;C1EF56|8910    |      ; 
                       BEQ Return                           ;C1EF58|F061    |C1EFBB; 
                       LDA.B #$03                           ;C1EF5A|A903    |      ; Load three
                                                            ;      |        |      ; 
 Element was detected: STA.W $B2CD                          ;C1EF5C|8DCDB2  |00B2CD; Store elemental defense index

The next section of the routine reads the elemental defense from the defender's stat block.

Code: [Select]
Element was detected:  STA.W $B2CD                          ;C1EF5C|8DCDB2  |00B2CD; Store elemental defense index
                       LDA.B #$04                           ;C1EF5F|A904    |      ; 
                       STA.W $B2CF                          ;C1EF61|8DCFB2  |00B2CF; Store damage multiplier numerator
                       LDA.W $B2CD                          ;C1EF64|ADCDB2  |00B2CD; Load index
                       REP #$20                             ;C1EF67|C220    |      ; 
                       CLC                                  ;C1EF69|18      |      ; 
                       ADC.W $B1F6                          ;C1EF6A|6DF6B1  |00B1F6; Add index to defender stat block offset
                       TAX                                  ;C1EF6D|AA      |      ; 
                       TDC                                  ;C1EF6E|7B      |      ; 
                       SEP #$20                             ;C1EF6F|E220    |      ; 
                       LDA.W $5E6C,X                        ;C1EF71|BD6C5E  |005E6C; Load elemental defense

There's a bit more processing and then the damage adjustment that follows. So, the elemental defenses are referenced by index as you can see. I don't think there's a battle code disassembly, though I did go through a bunch of it early this year.

Mauron

  • Guru of Reason Emeritus
  • Errare Explorer (+1500)
  • *
  • Posts: 1765
  • Nu-chan
    • View Profile
    • Maurtopia
Re: Chrono Trigger - The Fifth Element
« Reply #4 on: August 22, 2023, 10:01:21 pm »
My notes are fairly disorganized, but I can contribute some.

This checks magic and elemental defense in battle. $7E:B190 has the incoming attack's element flags.

Code: [Select]
Disassembly: Check Magic defense
$C1/EF39 7B TDC
$C1/EF3A AD 90 B1 LDA $B190  [$7E:B190]
$C1/EF3D 85 2C STA $2C    [$00:002C]
$C1/EF3F 89 80 BIT #$80
$C1/EF41 F0 03 BEQ $03    [$EF46]
$C1/EF43 7B TDC
$C1/EF44 80 16 BRA $16    [$EF5C]
$C1/EF46 89 40 BIT #$40
$C1/EF48 F0 04 BEQ $04    [$EF4E]
$C1/EF4A A9 01 LDA #$01
$C1/EF4C 80 0E BRA $0E    [$EF5C]
$C1/EF4E 89 20 BIT #$20
$C1/EF50 F0 04 BEQ $04    [$EF56]
$C1/EF52 A9 02 LDA #$02
$C1/EF54 80 06 BRA $06    [$EF5C]
$C1/EF56 89 10 BIT #$10
$C1/EF58 F0 61 BEQ $61    [$EFBB]
$C1/EF5A A9 03 LDA #$03
$C1/EF5C 8D CD B2 STA $B2CD  [$7E:B2CD]
$C1/EF5F A9 04 LDA #$04
$C1/EF61 8D CF B2 STA $B2CF  [$7E:B2CF]
$C1/EF64 AD CD B2 LDA $B2CD  [$7E:B2CD]
$C1/EF67 C2 20 REP #$20
$C1/EF69 18 CLC
$C1/EF6A 6D F6 B1 ADC $B1F6  [$7E:B1F6] // Battle stats offset of first target
$C1/EF6D AA TAX
$C1/EF6E 7B TDC
$C1/EF6F E2 20 SEP #$20
$C1/EF71 BD 6C 5E LDA $5E6C,x[$7E:5E80]
$C1/EF74 8D CE B2 STA $B2CE  [$7E:B2CE]
$C1/EF77 89 80 BIT #$80
$C1/EF79 F0 08 BEQ $08    [$EF83]
$C1/EF7B AD FC B1 LDA $B1FC  [$7E:B1FC]
$C1/EF7E 09 40 ORA #$40
$C1/EF80 8D FC B1 STA $B1FC  [$7E:B1FC]
$C1/EF83 AD CE B2 LDA $B2CE  [$7E:B2CE]
$C1/EF86 29 3F AND #$3F
$C1/EF88 8D CE B2 STA $B2CE  [$7E:B2CE]
$C1/EF8B BD 6C 5E LDA $5E6C,x[$7E:5E80]
$C1/EF8E 89 40 BIT #$40
$C1/EF90 F0 09 BEQ $09    [$EF9B]
$C1/EF92 AD CE B2 LDA $B2CE  [$7E:B2CE]
$C1/EF95 38 SEC
$C1/EF96 E9 02 SBC #$02
$C1/EF98 8D CE B2 STA $B2CE  [$7E:B2CE]
$C1/EF9B AE 89 AD LDX $AD89  [$7E:AD89] // Current damage
$C1/EF9E 86 28 STX $28    [$00:0028]
$C1/EFA0 AD CF B2 LDA $B2CF  [$7E:B2CF] // always 4
$C1/EFA3 AA TAX
$C1/EFA4 85 2A STA $2A    [$00:002A]
$C1/EFA6 20 0B C9 JSR $C90B  [$C1:C90B] // Damage * 4
$C1/EFA9 A6 2C LDX $2C    [$00:002C]
$C1/EFAB 86 28 STX $28    [$00:0028]
$C1/EFAD AD CE B2 LDA $B2CE  [$7E:B2CE] // Elemental Defense
$C1/EFB0 AA TAX
$C1/EFB1 86 2A STX $2A    [$00:002A]
$C1/EFB3 20 2A C9 JSR $C92A  [$C1:C92A] // Current Damage * 4 / (Elemental Defense)
$C1/EFB6 A6 2C LDX $2C    [$00:002C]
$C1/EFB8 8E 89 AD STX $AD89  [$7E:AD89]
$C1/EFBB 60 RTS

I'm not sure why they bothered storing 4 to $7E:B2CF ahead of time.

This is enemy creation at the start of battle.

Code: [Select]
Disassembly: Create enemy routine
$FD/B438 7B TDC
$FD/B439 A8 TAY
$FD/B43A 84 04 STY $04    [$00:0004]
$FD/B43C BD 0D AF LDA $AF0D,x[$7E:AF0E]
$FD/B43F 85 04 STA $04    [$00:0004]
$FD/B441 C2 20 REP #$20
$FD/B443 0A ASL A
$FD/B444 0A ASL A
$FD/B445 0A ASL A
$FD/B446 85 00 STA $00    [$00:0000]
$FD/B448 0A ASL A
$FD/B449 18 CLC
$FD/B44A 65 00 ADC $00    [$00:0000]
$FD/B44C 38 SEC
$FD/B44D E5 04 SBC $04    [$00:0004]
$FD/B44F AA TAX
$FD/B450 A5 02 LDA $02    [$00:0002]
$FD/B452 EB XBA
$FD/B453 4A LSR A
$FD/B454 A8 TAY
$FD/B455 7B TDC
$FD/B456 E2 20 SEP #$20
$FD/B458 20 D6 B4 JSR $B4D6  [$FD:B4D6]
$FD/B45B A5 04 LDA $04    [$00:0004]
$FD/B45D 99 AD 5F STA $5FAD,y[$7E:5FAD]
$FD/B460 BF 00 47 CC LDA $CC4700,x[$CC:4701]
$FD/B464 99 B0 5F STA $5FB0,y[$7E:5FB0]
$FD/B467 99 B2 5F STA $5FB2,y[$7E:5FB2]
$FD/B46A E8 INX
$FD/B46B BF 00 47 CC LDA $CC4700,x[$CC:4701]
$FD/B46F 99 B1 5F STA $5FB1,y[$7E:5FB1]
$FD/B472 99 B3 5F STA $5FB3,y[$7E:5FB3]
$FD/B475 E8 INX
$FD/B476 BF 00 47 CC LDA $CC4700,x[$CC:4701]
$FD/B47A 99 BF 5F STA $5FBF,y[$7E:5FBF]
$FD/B47D 99 BF 5F STA $5FBF,y[$7E:5FBF]
$FD/B480 5A PHY
$FD/B481 7B TDC
$FD/B482 85 00 STA $00    [$00:0000]
$FD/B484 99 CA 5F STA $5FCA,y[$7E:5FCA]
$FD/B487 99 CB 5F STA $5FCB,y[$7E:5FCB]
$FD/B48A 99 CC 5F STA $5FCC,y[$7E:5FCC]
$FD/B48D E8 INX
$FD/B48E BF 00 47 CC LDA $CC4700,x[$CC:4701]
$FD/B492 99 CF 5F STA $5FCF,y[$7E:5FCF]
$FD/B495 C8 INY
$FD/B496 E6 00 INC $00    [$00:0000]
$FD/B498 A5 00 LDA $00    [$00:0000]
$FD/B49A C9 05 CMP #$05
$FD/B49C 90 EF BCC $EF    [$B48D]
$FD/B49E 7A PLY
$FD/B49F B9 D2 5F LDA $5FD2,y[$7E:5FD2]
$FD/B4A2 99 CD 5F STA $5FCD,y[$7E:5FCD]
$FD/B4A5 B9 D3 5F LDA $5FD3,y[$7E:5FD3]
$FD/B4A8 99 CE 5F STA $5FCE,y[$7E:5FCE]
$FD/B4AB 5A PHY
$FD/B4AC 7B TDC
$FD/B4AD 85 00 STA $00    [$00:0000]
$FD/B4AF E8 INX
$FD/B4B0 BF 00 47 CC LDA $CC4700,x[$CC:4701]
$FD/B4B4 99 E4 5F STA $5FE4,y[$7E:5FE4]
$FD/B4B7 C8 INY
$FD/B4B8 E6 00 INC $00    [$00:0000]
$FD/B4BA A5 00 LDA $00    [$00:0000]
$FD/B4BC C9 0C CMP #$0C
$FD/B4BE 90 EF BCC $EF    [$B4AF]
$FD/B4C0 7A PLY
$FD/B4C1 7B TDC
$FD/B4C2 85 00 STA $00    [$00:0000]
$FD/B4C4 E8 INX
$FD/B4C5 BF 00 47 CC LDA $CC4700,x[$CC:4701]
$FD/B4C9 99 C6 5F STA $5FC6,y[$7E:5FC6]
$FD/B4CC C8 INY
$FD/B4CD E6 00 INC $00    [$00:0000]
$FD/B4CF A5 00 LDA $00    [$00:0000]
$FD/B4D1 C9 03 CMP #$03
$FD/B4D3 90 EF BCC $EF    [$B4C4]
$FD/B4D5 6B RTL

Starting at $7E:5E2D, are battle states for all potential participants - 3 PCs and 8 enemies.

I don't have the code where PCs are granted their personal elemental bonus handy.

inuksuk

  • Earthbound (+15)
  • *
  • Posts: 41
    • View Profile
Re: Chrono Trigger - The Fifth Element
« Reply #5 on: August 23, 2023, 05:51:15 pm »
Here's the routine that detects the personal element defense bonus. It's called three times at the start of battle. Elemental defenses are all set to four, then the PC's bonus defense element gets set to five.

Code: [Select]
Load elemental resistance: LDA.W $AEFF,X                    ;FDB3FE|BDFFAE  |00AEFF; X holds battle ID
                       CMP.B #$FF                           ;FDB401|C9FF    |      ; 
                       BEQ Return                           ;FDB403|F032    |FDB437; 
                       LDA.B #$04                           ;FDB405|A904    |      ; Load four
                       STA.W $5E6C,Y                        ;FDB407|996C5E  |005E6C; Store Lightning defense
                       STA.W $5E6D,Y                        ;FDB40A|996D5E  |005E6D; Store Shadow defense
                       STA.W $5E6E,Y                        ;FDB40D|996E5E  |005E6E; Store Water defense
                       STA.W $5E6F,Y                        ;FDB410|996F5E  |005E6F; Store Fire defense
                       LDA.W $5E2E,Y                        ;FDB413|B92E5E  |005E2E; Load personal element defense bonus
                                                            ;      |        |      ; 
       Test Lightning: BIT.B #$80                           ;FDB416|8980    |      ; 
                       BEQ Test Shadow                      ;FDB418|F002    |FDB41C; 
                       BRA Store resistance                 ;FDB41A|8016    |FDB432; 
                                                            ;      |        |      ; 
                                                            ;      |        |      ; 
          Test Shadow: BIT.B #$40                           ;FDB41C|8940    |      ; 
                       BEQ Test Water                       ;FDB41E|F003    |FDB423; 
                       INY                                  ;FDB420|C8      |      ; 
                       BRA Store resistance                 ;FDB421|800F    |FDB432; 
                                                            ;      |        |      ; 
                                                            ;      |        |      ; 
           Test Water: BIT.B #$20                           ;FDB423|8920    |      ; 
                       BEQ Test Fire                        ;FDB425|F004    |FDB42B; 
                       INY                                  ;FDB427|C8      |      ; 
                       INY                                  ;FDB428|C8      |      ; 
                       BRA Store resistance                 ;FDB429|8007    |FDB432; 
                                                            ;      |        |      ; 
                                                            ;      |        |      ; 
            Test Fire: BIT.B #$10                           ;FDB42B|8910    |      ; 
                       BEQ Return                           ;FDB42D|F008    |FDB437; 
                       INY                                  ;FDB42F|C8      |      ; 
                       INY                                  ;FDB430|C8      |      ; 
                       INY                                  ;FDB431|C8      |      ; 
                                                            ;      |        |      ; 
     Store resistance: LDA.B #$05                           ;FDB432|A905    |      ; 
                       STA.W $5E6C,Y                        ;FDB434|996C5E  |005E6C; Store personal element resistance
                                                            ;      |        |      ; 
               Return: RTL                                  ;FDB437|6B      |      ;
« Last Edit: August 23, 2023, 05:53:15 pm by inuksuk »

PowerPanda

  • Guru of Time
  • Earthbound (+15)
  • *
  • Posts: 43
    • View Profile
Re: Chrono Trigger - The Fifth Element
« Reply #6 on: August 25, 2023, 10:57:26 pm »
Thank you, inuksuk and Mauron. I need to get some good solid time in a debugger, which might not happen for a couple of weeks, but based on your notes, I have high hopes that this is doable.

I'm playing through Chrono Trigger with my kids right now, because they had never seen the game before, and I just got to the first Spekkio battle. He casts Lightning, Fire, Water, and Ice, and that has steeled my resolve to make this work.