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

Poll

Restored: ROM space allowing, should attacks be tallied for each weapon type used in combat? (support multiple weapon EXP for weapon swapping)

No. Restored already has passive growth, only end-of-combat weapon should receive bonus.
Yes. All weapons used in combat should receive this bonus credit.

Author Topic: Final Fantasy II Restored  (Read 145794 times)

redmagejoe

  • Sr. Member
  • ****
  • Posts: 302
    • View Profile
Final Fantasy II Restored
« on: December 10, 2019, 03:09:14 am »
Current Version (Playtesters Wanted!)
Bug Fixes Only WIP
Bug Fixes Only WIP + No Growth Barrier
Restored WIP
List of Bug Fixes (WIP)


Bug Fix To-Do List
  • WIP Parts of Palamecia Castle 7F do not block teleport spells. The offending Map ID is $71.
  • WIP The Mysidia Cave B4 (B3 if you consider first floor 1F) treasure room uses an incorrect battle background. The offending Map ID is $29 and uses the default (forest) battle background.
  • WIP Warping out of Mysidian Tower results in the player being drawn back in by the tower beam animation. Either exit coordinates need to be adjusted, or the entire animation sequence/script removed for all entrances after the first time.
  • Fine-tune Ultima? Without a PSP Final Fantasy disASM or at least analysis, there's no way of knowing the exact formula.
  • The Paloom-Poft 32 gil boat ride is nonconditional, not relocating or updating based on the player's location when paying for the trip. Boat NPCs should instead offer trips to the town opposite their respective location and relocate the boat outside of the town in which you're paying for the trip.
  • Healing items in combat are bound to casting on self, rather than allowing a target to be chosen. This renders Phoenix Down, Gold Needle, and Maiden's Kiss useless in combat. Consider implementing new routine for targetting with these items.
  • In the dialogue immediately before and after fighting the boss monster when retaking Fynn castle, there's a graphics glitch after closing the dialogue boxes that causes Hilda and Gordon to appear on the thrones for a few frames.
  • Killing a large monster (e.g. a Fire Gigas) while Leon is dead results in Leon's feet being temporarily cut off.
  • You are able to continue interacting with NPCs that have been removed until you exit the conversation. These NPCs never have any interactions AT ALL (meaningful or otherwise) after the point at which you're "expected" to close the UI. Can a window close be forced after the last dialog in these instances?
  • Remakes suggest that dual-wielding is supposed to actually increase your number of hits, or at the very least, run a second damage calculation. More testing is needed on this and how feasible it would be to put in the patch.
  • When flashing the background during spell casting, there's a 10x3 rectangle at the bottom-left of the screen and a line between the battle area and the info area that do not flash; either the entire screen background should flash or the entire info area background should not flash.
  • The floor parts of the table, stool, counter, and barrel graphics only match up well with one of the floor patterns they appear on (table matches Bofsk Sewers, others match towns) and look out of place on other floor patterns.
  • The BGM pauses for a frame when closing the row menu.
  • Attempting to send your first non-KO/Stone character to the back row when all other non-KO/Stone characters are in the back row should play the error SFX.
  • Sprite tiles covered or uncovered by an opening or closing window should disappear or appear on the same frame as the changed background tiles rather than the entire sprite disappearing when the window starts opening or the entire sprite appearing after the window finishes closing.
  • Sprites have a 3px vertical offset from their background tile, resulting in the tops of sprites located 1 tile below the bottom of a window overlapping with the window.

Restored Improvements
  • IMPLEMENTED Running works 100% of the time during first round of surprise attacks.
  • IMPLEMENTED B Button Dash patch. (courtesy of SpiderDave made for ChaosRush translation)
  • IMPLEMENTED The 4 Mysidian Tower Orbs are buffed to give all 4 characters their stat boosts.
  • IMPLEMENTED Passive skill growth for weapons and spells, adding 1 "use" of each weapon and spell per battle to take advantage of the battle rank bonus.
  • IMPLEMENTED Iron Giant is now an inescapable encounter. Iron Giant can still run from your party if your HP is too high in the original version.
  • IMPLEMENTED Preemptive Strike notification previously appeared after the first round of player command selection. The notification now appears at the beginning of battle.
  • IMPLEMENTED Holy Lance casts Holy 16 rather than Holy 8 for a more meaningful effect by the end of the game, when you obtain it.
  • IMPLEMENTED Dead characters have their row preserved after battle, rather than automatically being assigned to the back row.
  • IMPLEMENTED Certain key items take up valuable inventory slots long after they are relevant to the game or story, when they should be consumed within the context of the story. There is no way to dispose of them. Certain key items are now deleted once their relevance has expired. Goddess's Bell once it is used to open Kashuan Keep. Pass after you use it to gain access to the landed Dreadnought. The Egil's Torch after acquiring Sunfire. Sunfire after being thrown into the Dreadnought. White Mask after it is placed upon the Goddess Statue. Black Mask after it is placed upon the Doppelganger. Pendant after it is used to summon the Wyvern. Crystal Rod after first time entering Mysidian Tower. 8 of 32 inventory slots are thus freed up.
  • Change post-liberation BGM of Castle Fynn to Rebel Army Theme?
  • Change battle windows to Final Fantasy blue?
  • Only display key items in the NPC Item UI.
  • Update battle messages, adding failure or # of success messages for buffs and such spells.
  • Add level up messages for Evasion/Magic Resist.
  • Re-order level up messages to match the order of stats as displayed in the status menu. (HP, MP, Strength, Agility, Stamina, Intellect, Spirit, M.Power)
  • Consider tallying attack counter and converting to weapon experience the moment weapons are switched in combat, to more accurately increase weapon experience. See if a JSR can be fit in before the actual change to weapon type changes. This would be an improvement on the remakes, even.
  • Add a row indicator on the main menu screen.
  • Update the status (/equip, but more work) menu screen to display magic penalty, armour resistances, attack elements/families, and weapon special effect.
  • Use different battle messages for Flee failure when the battle can't be escaped vs. when the character failed their success roll.
  • Display a message for inescapable battles at the beginning of combat.
  • Display spell animations for all targets simultaneously.
  • Consider demakes of BGMs used in remakes?
  • New title screen using the series standard font/style, used in all current entries and added to Final Fantasy Restored. Seeking interested NES artists who can make use of compression techniques similar to those incorporated by koitsu here. More specific details as presented in koitsu's email to me can be provided on request.

Resources
Game Systems Breakdown with Bugs Mentioned
Game Systems Discussion @ GameFAQs
abw's Drive (disassemblies included)
FF2 CDL
Updated SRAM Map
Map ID Table

Spell IDs
Code: [Select]
C0 Fire        CA Confuse     D4 Cure        DE Mini
C1 Thunder     CB Blind       D5 Life        DF Silence
C2 Blizzard    CC Curse       D6 Basuna      E0 Sap
C3 Scourge     CD Toad        D7 Esuna       E1 Fog
C4 Drain       CE Break       D8 Barrier     E2 Slow
C5 Osmose      CF Death       D9 Blink       E3 Swap
C6 Flare       D0 Warp        DA Protect     E4 Fear
C7 Sleep       D1 Berserk     DB Shell       E5 Holy
C8 Stun        D2 Haste       DC Wall        E6 Teleport
C9 Stop        D3 Aura        DD Dispel      E7 Ultima

Contributors
Red Mage Joe - Minor Coding, Project Organizing, Playtesting, Scutwork
abw - Primary Coding, Disassembly, Playtesting, and countless other contributions without which this project wouldn't be possible
Jiggers - SRAM Mapping, Map Data Decoding/Tools, other contributions
Leviathan Mist - Playtesting, Restored Ideas
Special Thanks to Cyneprepou4uk, Disch, Chaos Rush, Demiforce, for their contributions to this project, both directly and indirectly.
« Last Edit: September 06, 2020, 01:44:53 pm by redmagejoe »

Cyneprepou4uk

  • Hero Member
  • *****
  • Posts: 576
  • I am the baldest romhacker
    • View Profile
Re: Final Fantasy II Disassembly?
« Reply #1 on: December 10, 2019, 04:18:01 am »
Kids these days, can't do anything without a disassembly.
iromhacker.ru - NES ROM hacking tutorials for beginners. Please use Google Translate browser extension

Lenophis

  • Discord Staff
  • Hero Member
  • *****
  • Posts: 971
  • The return of the sombrero!
    • View Profile
    • Slick Productions
Re: Final Fantasy II Disassembly?
« Reply #2 on: December 10, 2019, 08:57:46 am »
A complete disassembly was not made. I should know. I do have some hacking bytes, but it's not complete, or anything like you're looking for. The only code I've tangled with is what made the DTE Fixer Upper patch. I haven't really hacked FF2 in a while.


https://ff6randomizer.codeplex.com/ - Randomize your FF6 experience!

redmagejoe

  • Sr. Member
  • ****
  • Posts: 302
    • View Profile
Re: Final Fantasy II Restored
« Reply #3 on: December 12, 2019, 01:13:02 pm »
Kids these days, can't do anything without a disassembly.

Sorry :(

I would like to figure out how people who make the disassemblies in the first place do this stuff, how they tear down these binaries built on esoteric, low-level language. The concept just fascinates me, it does, but I just don't have the time anymore (and probably the patience even if I did) to dedicate to the projects. It saddens me, because I always used to think this sort of thing is what I'd be doing as my primary activity. Alas, at best I can scrounge up enough free time to make tweaks and very minor hacks. Things that I feel I have the experience, or at least the aptitude to figure out and dedicate my resources to rather than taking time away from these profound romhacks some of the members of this community are giving their 100% on. I always feel guilty then when I hit a roadblock like this, but it's such a shame when I think that, from a programming standpoint, it MUST be an easy fix, if only I had the means to analyze it.

tl;dr I'm too inexperienced and lacking in time to try to dissect the binary, and I realize at best what I do is tweaks but I'd really like to try and fix some things in that list.

A complete disassembly was not made. I should know. I do have some hacking bytes, but it's not complete, or anything like you're looking for. The only code I've tangled with is what made the DTE Fixer Upper patch. I haven't really hacked FF2 in a while.

That's a bummer. If I were to try and figure out where to begin finding the addresses I'm looking for then... I guess I would have to set a breakpoint and analyze the RAM addresses being read/written to?
« Last Edit: January 19, 2020, 04:44:05 pm by redmagejoe »

Bregalad

  • Hero Member
  • *****
  • Posts: 2753
    • View Profile
Re: Final Fantasy II Disassembly?
« Reply #4 on: December 13, 2019, 02:24:41 am »
There's a disassembly of Final Fantasy around. A lot of code in Final Fantasy 2 and 3 is reused code from Final Fantasy. So although this is not a full solution, it will give you a nice idea how many thing works in the game. Even the RAM map is similar.

Jiggers

  • Sr. Member
  • ****
  • Posts: 422
    • View Profile
    • My Ko-Fi Page
Re: Final Fantasy II Disassembly?
« Reply #5 on: December 13, 2019, 04:24:04 pm »
I might not mind helping out once there's a disassembly. I looked into how to make one and... couldn't really figure it out either. I got the assembly code out in a big list, but it also tried to turn data into code, and I couldn't tell where one bank ended and the next began...

I need a break from my own things, so I might take a look at FF2 and map out some RAM, that'll help someone get started maybe?

One thing you'll want to do is make sure that a disassembly can be re-assembled after edits. I've been absolutely spoiled by FF1's, but its SO much easier to work with than trying to make changes where you can't just shift the whole game by 2 bytes and change every single pointer and jump address in the process.
I know exactly what I'm doing. I just don't know what effect it's going to have.

I wrote some NES music! Its a legal ROM file. - I got a Ko-Fi page too.

redmagejoe

  • Sr. Member
  • ****
  • Posts: 302
    • View Profile
Re: Final Fantasy II Restored
« Reply #6 on: December 13, 2019, 04:28:00 pm »
Any help at all in any form would be appreciated. It would be a great boon not just to fixes I'd like to try to make to the game, but for future hacking of the game.
« Last Edit: January 19, 2020, 04:44:13 pm by redmagejoe »

abw

  • Hero Member
  • *****
  • Posts: 556
    • View Profile
Re: Final Fantasy II Disassembly?
« Reply #7 on: December 13, 2019, 06:24:13 pm »
One thing you'll want to do is make sure that a disassembly can be re-assembled after edits. I've been absolutely spoiled by FF1's, but its SO much easier to work with than trying to make changes where you can't just shift the whole game by 2 bytes and change every single pointer and jump address in the process.
Yeah, but try asking Disch how much time it took to create that disassembly :(.

NES ROMs are tricky things to disassemble. Mostly that's due to mappers, but there are other reasons too.

Assuming you've played the game through in FCEUX at some point, did you happen to have FCEUX's Code/Data Logger running (preferably on the unaltered Japanese ROM, preferably without making any changes via the debugger/hex editor/etc.)?

The reason I ask is that one of my various WIP pet projects is a NES disassembler that uses FCEUX's CDL file to automatically distinguish between code and data (and stuff that is both code and data) and the ROM's iNES header to do some primitive mapper-based things like dividing the ROM into banks based on the mapper's (smallest) bank size and working out the RAM addresses for each of those banks (or at least trying to). With manual work, you can also incorporate comments and labels into the generated disassembly and tell it about things like pointers/pointer tables and what bytes that the CDL didn't log are for. You can see an example from Dragon Warrior II on the wiki.

Actually, a quick search of the internet turned up https://taotao54321.github.io/appsouko/work/CDL/pub/, which appears to have a mostly complete CDL file of "FF2", which I'm hoping means "Final Fantasy II". I plugged it in and played the game for a couple of minutes and FCEUX didn't change anything, so maybe it's legit? How does this look?

redmagejoe

  • Sr. Member
  • ****
  • Posts: 302
    • View Profile
Re: Final Fantasy II Restored
« Reply #8 on: December 13, 2019, 06:28:38 pm »
Actually, a quick search of the internet turned up https://taotao54321.github.io/appsouko/work/CDL/pub/, which appears to have a mostly complete CDL file of "FF2", which I'm hoping means "Final Fantasy II". I plugged it in and played the game for a couple of minutes and FCEUX didn't change anything, so maybe it's legit? How does this look?

https://taotao54321.github.io/appsouko/work/CDL/pub/FF2.txt
@rom_md5 374ed97be8bfd628f6b359a720549ecd

Went to my ROM repo and found the Final Fantasy II (J) [!] and ran it through RHDN's online Hasher-js.
ROM MD5   374ED97BE8BFD628F6B359A720549ECD

We have a match! Good find, abw! :)
« Last Edit: January 19, 2020, 04:44:22 pm by redmagejoe »

Jiggers

  • Sr. Member
  • ****
  • Posts: 422
    • View Profile
    • My Ko-Fi Page
Re: Final Fantasy II Disassembly?
« Reply #9 on: December 13, 2019, 08:35:44 pm »
Here's my SRAM testing so far:

Code: [Select]
6000
00 - $01 = Pirate Ship Visible, triggers animation/fight scene? $02 = in control of pirate ship
01 - Pirate Ship X position
02 - Pirate Ship Y position
03 - $C0 when riding ship in animation, $10 when in control of pirate ship?
04 - $01 - Airship Visible. $02 = trigger animation? $04 = in control of airship
05 - Airship X position
06 - Airship Y position
07 - Airship Flyover Animation Counter?
08 - $02 = On chocobo! $80 = Chocobo Animation?
09 - Chocobo X position (for animation?)
0A - Chocobo Y position (for animation?)
0B -
0C - Ship Usable
0D - Ship X position
0E - Ship Y position
0F -
10 - Player Overworld Position X (for saving)
11 - Player Overworld Position Y (for saving)
12 - Constantly read when moving in town ($36)
13 -
14 - Giant Airship Visible
15 - Giant Airship X position
16 - Giant Airship Y position
17 -
18 -
19 -
1A - Key Item inventory? $02 when given Scott's Ring
1B -
1C - Gold low byte
1D - Gold middle byte
1E - Gold high byte
1F - Battle Text Speed (-1 from option chosen on game start)
20-3F - Seems to be treasure chest contents. Everything starts full, at $FF. Opening the chest south of the room you start in decrements 6022 to $FE. #256 chests total in the game?

40-5F - Game event flags
6042 - Starts $8B, turns to $8A when given Scott's Ring
6046 - Starts $7F, turns to $7E when using Wild Rose on bartender in third town. Then to $7C when given Scott's Ring. Flags character sprites vanishing?

60-7F - Items
80-8F - Passwords - Password IDs starts at $F1 and ends at $FF

6100 - Character stats, $40 per character
00 - Character ID - portrait, sprite
00: Firion
01: Maria
02: Guy
03: Minwu
04: Josef
05: Gordon
06: Leila
07: Ricard
08: Leon
01 - Ailment
01: Blind
02:
04: Venom
08: Cursed
10: Amnesia
20: Toad
40: Stone
80: Dead
02 - Name Letter 1
03 - Name Letter 2
04 - Name Letter 3
05 - Name Letter 4
06 - Name Letter 5
07 - Name Letter 6
08 - Current HP low byte
09 - Current HP high byte
0A - Max HP low byte
0B - Max HP high byte
0C - Current MP low byte
0D - Current MP high byte
0E - Max MP low byte
0F - Max MP high byte
10 - Strength - not shown in menu
11 - Agility - not shown in menu
12 - Stamina - not shown in menu
13 - Intellect - not shown in menu
14 - Spirit - not shown in menu
15 - M. Power - not shown in menu
16 - Min Accuracy %
17 - Max Accuracy %
18 - Attack
19 - Head (Item ID)
1A - Body (Item ID)
1B - Hands (Item ID)
1C - Right Hand (Item ID)
1D - Left Hand (Item ID)
1E - Item 1 (Item ID)
1F - Item 2 (Item ID)
20 - Strength
21 - Agility
22 - Stamina
23 - Intellect
24 - Spirit
25 - M. Power
26 - Defense
27 -
28 -
29 -
2A - Min Evasion %
2B - Max Evasion %
2C - Min M. Resist %
2D - Max M. Resist %
2E -
2F -
30-3F - Known spell slots (Usable spell IDs start at $C0, end at $E7?)

Weapon skills:
$10 per character, in $40 byte intervals
Levels are -1, where 00 = level 1
Both should cap at $63

6200 - Firion's weapon Skills
6240 - Maria's weapon skills
6280 - Guy's weapon skills
62C0 - Character 4's weapon skills?
00 - Unarmed level
01 - Unarmed experience
02 - Shield level
03 - Shield experience
04 - Dagger level
05 - Dagger experience
06 - Staff level
07 - Staff experience
08 - Spear level
09 - Spear experience
0A - Sword level
0B - Sword experience
0C - Axe level
0D - Axe experience
0E - Bow level
0F - Bow experience

6235
6275
62B5
62F5 - Row ; 0 = back row, 01 = front row, 80 = no character portrait visible in menus
« Last Edit: December 14, 2019, 07:01:30 pm by Jiggers »
I know exactly what I'm doing. I just don't know what effect it's going to have.

I wrote some NES music! Its a legal ROM file. - I got a Ko-Fi page too.

redmagejoe

  • Sr. Member
  • ****
  • Posts: 302
    • View Profile
Re: Final Fantasy II Restored
« Reply #10 on: December 13, 2019, 08:39:29 pm »
Quote
Weapon skills:
$10 per character, in $40 byte intervals
Levels are -1, where 00 = level 1
Both should cap at $63
Shouldn't the levels cap at 0F, for 15? Max spell and weapon levels are 16.

On that note, having tampered with SRAM myself a bit to "fix" overmaxed HP, I thought it might be helpful to outline what hex values are needed as "caps" that the game doesn't already impose. While the game DOES prevent stats like Strength, Agility, Stamina, Spirit, Intellect, and presumably M.Power from going above 99, it still does level-up checks on them.

Spirit, Strength, and Intellect, at least, need to have their checks for leveling up skipped when they are at $63 (99), since there's no reason for them to be continuing to try to level up, and it results in you often losing Strength, Intellect, and Stamina accordingly. This can be applied to M.Power, Stamina and Agility as well, but they don't have any unwanted side effects of continuing to "level up" other than it being inconsistent were the other 3 stats fixed.

Weapon Skills aren't problematic either, other than the end-of-battle spam. Since they are using -1 value and starting at $00, $0F should translate to 16, at which point the check for weapon levels should not happen anymore, but they still do. There's also some sort of underflow bug based on battle rank with the weapon levels specifically at $0D and $0E, resulting in a single attack on a Rank 1 battle immediately leveling up the weapon skill.

Spell levels do appear to cap properly, as the experience counter will still go up to 98 or 99, but will never go up beyond that. Scratch that, spells will also "level up" even at 16 if used enough times in battle, though it will simply reset the experience counter back to 00 in the magic window. This game just simply does not have hard caps for most things, with only a few mechanics in place to ensure that weapon and spell levels don't increment above 16 and stats don't increment above 99, while the math is still being calculated and messages displayed as if there were no caps.

Evasion and Magic Defense should cap at 16 (whether that's $0F or $10 I don't know), and I haven't tested if they can still go up. There'd be no easy way to test that, as there's no message stating they go up and you'd only be able to tell from looking at your stat windows 2 battles later.

For HP and MP, having already modified my SRAM to fix overmax, I can say that HP should cap at $0F27 (low byte then high byte) for 9999, and MP should cap at $E703 for 999. Currently it seems likely that these values would continue to level up to $FFFF and would no doubt overflow.
« Last Edit: January 19, 2020, 04:45:00 pm by redmagejoe »

Jiggers

  • Sr. Member
  • ****
  • Posts: 422
    • View Profile
    • My Ko-Fi Page
Re: Final Fantasy II Disassembly?
« Reply #11 on: December 13, 2019, 09:40:17 pm »
Shouldn't the levels cap at 0F, for 15? Max spell and weapon levels are 16.

Oh, yeah, probably! Last time I played FF2 was I think the Wanderswan version over 10 years ago, so I'm not as familiar with its systems. I guessed 99 was the level cap since that's the highest number there's room to print on the status screen.

Quote
Evasion and Magic Defense should cap at 16 (whether that's $0F or $10 I don't know), and I haven't tested if they can still go up. There'd be no easy way to test that, as there's no message stating they go up and you'd only be able to tell from looking at your stat windows 2 battles later.

For all this stuff, what I'd do to find where the routines are change them, is: Starting on the overworld, find one character's evasion stat in Mesen's memory viewer, right click and set a breakpoint on read, then get into a battle. There's probably a bit of code that copies over stats to temporary battle stats. So then you step through it until you see the evasion stat written to somewhere else in memory shortly after that? If it doesn't break there, even better: just set a "write" breakpoint on the same evasion stat, and when it goes up in or after battle, that's the thing that does it! And if its temporary battle stats, set the "write" breakpoint on the new location.

Right now I can't even figure out how to get Chaos Rush's translation patched in without graphical errors...
I know exactly what I'm doing. I just don't know what effect it's going to have.

I wrote some NES music! Its a legal ROM file. - I got a Ko-Fi page too.

redmagejoe

  • Sr. Member
  • ****
  • Posts: 302
    • View Profile
Re: Final Fantasy II Restored
« Reply #12 on: December 13, 2019, 09:58:57 pm »
Here's an IPS you can just slap on the (J) [!] ROM. It's a patch I just pulled using Lunar. Everything works and is retranslated, though it doesn't have the (sometimes buggy) NeoDemiforce title screen.

https://drive.google.com/open?id=1jB61-EFQaoZkxCZnxld4vp0gV9SH8in_
« Last Edit: January 19, 2020, 04:46:39 pm by redmagejoe »

abw

  • Hero Member
  • *****
  • Posts: 556
    • View Profile
Re: Final Fantasy II Disassembly?
« Reply #13 on: December 13, 2019, 11:17:37 pm »
It looks like there are a couple of things already documented on the wiki.

A quick search in my generated disassembly for $6100 turns up (among lots of other things) what looks like code for initializing party stats ($00:$8F80 - $00:$8FBF does appear to contain character #1's initial stats) and other stuff:
Code: [Select]
0x001C7F|$00:$9C6F:A2 3F    LDX #$3F   
; control flow target (from $9CA2)
0x001C81|$00:$9C71:BD 80 8F LDA $8F80,X
0x001C84|$00:$9C74:9D 00 61 STA $6100,X
0x001C87|$00:$9C77:BD 00 90 LDA $9000,X
0x001C8A|$00:$9C7A:9D 40 61 STA $6140,X
0x001C8D|$00:$9C7D:BD 80 90 LDA $9080,X
0x001C90|$00:$9C80:9D 80 61 STA $6180,X
0x001C93|$00:$9C83:BD 80 8F LDA $8F80,X
0x001C96|$00:$9C86:9D C0 61 STA $61C0,X
0x001C99|$00:$9C89:BD C0 8F LDA $8FC0,X
0x001C9C|$00:$9C8C:9D 00 62 STA $6200,X
0x001C9F|$00:$9C8F:BD 40 90 LDA $9040,X
0x001CA2|$00:$9C92:9D 40 62 STA $6240,X
0x001CA5|$00:$9C95:BD C0 90 LDA $90C0,X
0x001CA8|$00:$9C98:9D 80 62 STA $6280,X
0x001CAB|$00:$9C9B:BD C0 8F LDA $8FC0,X
0x001CAE|$00:$9C9E:9D C0 62 STA $62C0,X
0x001CB1|$00:$9CA1:CA      DEX       
0x001CB2|$00:$9CA2:10 CD    BPL $9C71 
0x001CB4|$00:$9CA4:60      RTS       

Later on, there's what looks like possibly some code for capping stats at 99 (#$63), which the CDL didn't log, so I guess our awesome taotao friend didn't manage/bother to max those stats:
Code: [Select]
; indirect control flow target
0x03A1BF|$0E:$A1AF:A9 10    LDA #$10   
0x03A1C1|$0E:$A1B1:D0 0A    BNE $A1BD 
; indirect control flow target
0x03A1C3|$0E:$A1B3:A9 11    LDA #$11   
0x03A1C5|$0E:$A1B5:D0 06    BNE $A1BD 
; indirect control flow target
0x03A1C7|$0E:$A1B7:A9 14    LDA #$14   
0x03A1C9|$0E:$A1B9:D0 02    BNE $A1BD 
; indirect control flow target
0x03A1CB|$0E:$A1BB:A9 13    LDA #$13   
; control flow target (from $A1B1, $A1B5, $A1B9)
0x03A1CD|$0E:$A1BD:85 80    STA $80   
0x03A1CF|$0E:$A1BF:A5 F0    LDA $F0   
0x03A1D1|$0E:$A1C1:29 C0    AND #$C0   
0x03A1D3|$0E:$A1C3:05 80    ORA $80   
0x03A1D5|$0E:$A1C5:AA      TAX       
0x03A1D6|$0E:$A1C6:BD 00 61 LDA $6100,X
0x03A1D9|$0E:$A1C9:18      CLC       
0x03A1DA|$0E:$A1CA:69 0A    ADC #$0A   
0x03A1DC|$0E:$A1CC:C9 64    CMP #$64   
0x03A1DE|$0E:$A1CE:90 02    BCC $A1D2 

; code -> unknown
0x03A1E0|$0E:$A1D0:A9 63    ; LDA #$63   
0x03A1E1|$0E:$A1D1:63      ; INVALID OPCODE

; unknown -> code
; control flow target (from $A1CE)
0x03A1E2|$0E:$A1D2:9D 00 61 STA $6100,X
0x03A1E5|$0E:$A1D5:BD 10 61 LDA $6110,X
0x03A1E8|$0E:$A1D8:18      CLC       
0x03A1E9|$0E:$A1D9:69 0A    ADC #$0A   
0x03A1EB|$0E:$A1DB:C9 64    CMP #$64   
0x03A1ED|$0E:$A1DD:90 02    BCC $A1E1 

; code -> unknown
0x03A1EF|$0E:$A1DF:A9 63    ; LDA #$63   
0x03A1F0|$0E:$A1E0:63      ; INVALID OPCODE

; unknown -> code
; control flow target (from $A1DD)
0x03A1F1|$0E:$A1E1:9D 10 61 STA $6110,X

redmagejoe

  • Sr. Member
  • ****
  • Posts: 302
    • View Profile
Re: Final Fantasy II Restored
« Reply #14 on: December 13, 2019, 11:24:17 pm »
I can also provide my .sav if anyone would like more tangible resources to play with. I currently have everyone at 99 Strength, Agility, Stamina, and Spirit, with Intellect being between 1 and 3 due to the aforementioned gripe about maxed stats leveling up and decreasing other stats. Firion has 9999 HP (was 10030 until I "fixed" it in SRAM) and 999 MP ("fixed"), while the other two characters have ~7400 and 247, and ~6400 and 999 ("fixed"). This was achieved through some extremely obsessive and tedious leveling for the purposes of testing the limits of the game systems. I imagine this might be helpful rather than having to artificially manipulate those stats, though I suppose that isn't in and of itself a difficult task.



Here's the .sav. Characters have above-listed stats, and most of the spells in the game. Cure is at 16 on Firion and Guy, in case that is of benefit to testing spell leveling or experience.

https://drive.google.com/open?id=10j57hRiNoy-tCxq3YoyTwaP5CCJZC8Zs
« Last Edit: January 19, 2020, 04:46:26 pm by redmagejoe »

Jiggers

  • Sr. Member
  • ****
  • Posts: 422
    • View Profile
    • My Ko-Fi Page
Re: Final Fantasy II Disassembly?
« Reply #15 on: December 14, 2019, 06:59:35 pm »
Thanks for the patch! Is it a bug that the flowing text (Programmed by Nasir and so on) has like a whole line of each letter across the screen as it draws in?

Another possible bug is that after being given Scott's ring, and asking "Wild Rose" a second time, will loop all his previous dialogue again, including the ring giving message? Perhaps a forced exit from dialogue when sprites vanish, after pressing any button... unless that would break something else.

I found a few more SRAM bytes, and the $20 bytes that I thought might be game event flags certainly must be. Instead of using up $100 bytes and only using 2 bits or so per byte like FF1, they just crammed it all in there, which I guess is how they made room for 4 save slots, with each save being $300 bytes. I'll update my other post with the things I find as I slog through the game's beginning...
« Last Edit: December 14, 2019, 08:18:05 pm by Jiggers »
I know exactly what I'm doing. I just don't know what effect it's going to have.

I wrote some NES music! Its a legal ROM file. - I got a Ko-Fi page too.

redmagejoe

  • Sr. Member
  • ****
  • Posts: 302
    • View Profile
Re: Final Fantasy II Restored
« Reply #16 on: December 14, 2019, 07:02:02 pm »
That weird drawing effect is, I think, the intended behavior of the title screen. It's just not a very "pretty" title screen, which is why a new one was made for the Neodemiforce patch. Would be nice to get that as a standalone patch someday. Also I provided my .sav if you get to a point where you want to see how it's handling stat behaviors past the beginning game slog.
« Last Edit: January 19, 2020, 04:46:16 pm by redmagejoe »

abw

  • Hero Member
  • *****
  • Posts: 556
    • View Profile
Re: Final Fantasy II Disassembly?
« Reply #17 on: December 15, 2019, 04:35:56 pm »
I put a few hours into creating an updated version of my disassembly, marking in some CHR, the main dialogue, unused code paths, a bunch of pointer tables, probably most of the inter-bank references, formatting some of the larger data blocks, a teeny-tiny bit of documentation on a couple of routines (mostly the ones involving bank swaps), stuff like that. It's still pretty rough, but should make any code changes that you want easier to make.

redmagejoe

  • Sr. Member
  • ****
  • Posts: 302
    • View Profile
Re: Final Fantasy II Restored
« Reply #18 on: December 15, 2019, 05:15:26 pm »
I put a few hours into creating an updated version of my disassembly, marking in some CHR, the main dialogue, unused code paths, a bunch of pointer tables, probably most of the inter-bank references, formatting some of the larger data blocks, a teeny-tiny bit of documentation on a couple of routines (mostly the ones involving bank swaps), stuff like that. It's still pretty rough, but should make any code changes that you want easier to make.

This is great, abw. I'm going to start looking through this and see if I can work with what's provided while I've got some downtime between work projects. The main issue is knowing where to even begin looking to make changes, I'll admit. Once I have an idea of where the relevant routines are for handling stat level up checks at the end of battle, I'll have a much better idea how to move forward.



Found an issue with the ChaosRush translation that can very easily be fixed, but... I noticed that using DTE, he made some spell names use 5 spaces instead of 4, and as a result, in battle any spells above level 9 will be pushed out of the box that displays during the cast. So Scourge 16 becomes [Scrge 1]. This is an easy enough fix, where the space after a spell name is removed so that in the case of 5-character spells it would be [Scrge1 ] or [Scrge16], and for other spells that already only use 4 spaces, it would be [Cure1  ] to [Cure16 ]. Doesn't look too troublesome, but I'd need to find where the combat display boxes handle spell names and levels to adjust that. Removing the space would be easier than trying to check the spell level and formatting based upon that. It wouldn't look too inconsistent with NES era formatting I don't think.



I discovered potentially another bug. When one's Agility and thus Evasion are high enough, and Shield skill is high/maxed, it appears that one of two things are happening. Either Evasion % is rolling over, or it is somehow going above 99% and is only displaying the two least significant digits in the stat window; this seems less likely given the other bugs in this game involving lack of caps.

To elaborate, with Level 16 Shields, 99 Agility, and Dragon Shield equipped on, say, Guy, who has Level 8 Evasion, he goes from 8-99% without the shield equipped to 8-05% with the shield equipped.



D'oh, and apparently I missed the extremely small window to access Paul's Secret Stash. I guess you have to talk to him right after the Cyclone appears and say Cyclone to open it up, but I'm not sure how it's managed. Does it become an object you can permanently interact with? Does it become an open door you can walk through? Does it allow you to interact with it until the access window closes? I'm curious now where the flag is for this value, as I'd like to see if it's possible to manipulate that, or the one involving talking to Paul about the Cyclone all the way up to the end of the game. Another consideration for a patch.
« Last Edit: January 19, 2020, 04:46:08 pm by redmagejoe »

abw

  • Hero Member
  • *****
  • Posts: 556
    • View Profile
Re: Final Fantasy II Disassembly?
« Reply #19 on: December 23, 2019, 02:32:07 pm »
This is great, abw. I'm going to start looking through this and see if I can work with what's provided while I've got some downtime between work projects. The main issue is knowing where to even begin looking to make changes, I'll admit. Once I have an idea of where the relevant routines are for handling stat level up checks at the end of battle, I'll have a much better idea how to move forward.
Like Jiggers said, if you already know a RAM address (e.g. character stats start at $6100) related to the code you're looking for and you already know approximately when the code you're looking for runs, setting a breakpoint on that address and then playing through the part of the game where the code runs is probably the best way to go. (And if you don't know a RAM address, you can also use a trace logger and PPU breakpoint and backtrack from when something related to the code you're looking for appears on screen.)

For character stats, I did just that, setting a write breakpoint on $6110-$6115 and playing until Firion gained a stat. The breakpoint fired at $05:$A8A0, and poking around that section of the disassembly suggests $05:$A874-$05:$A903 is the code for increasing Spirit/Strength/Intellect at the expense of Strength/Intellect/Stamina (capped at 99 for increases and 1 for decreases). $05:$A7E9-$05:$A841 looks like it handles HP/MP increases (no caps, so probably with enough grinding you could overflow the 16-bit storage and end up with 0 Max HP!), and $05:$A842-$05:$A86C is probably for skill level increases (capped at 15). All those routines get called from code starting around $05:$A5F1 (or possibly earlier, I haven't really looked). I added some more rough notes to my disassembly, so hopefully that will help a bit!