Difference between revisions of "Assembly FAQ"

From Final Fantasy Hacktics Wiki
Jump to navigation Jump to search
(Created page with "Brief overview! - Assembly refers to the code on the game disc; it's the language the game runs in. more specifically, it runs on MIPS r300. when using psxfin, use the r3000...")
 
m
Line 1: Line 1:
 
Brief overview!
 
Brief overview!
  - Assembly refers to the code on the game disc; it's the language the game runs in. more specifically, it runs on MIPS r300. when using psxfin, use the r3000 debugger.
+
  - Assembly refers to the code on the game disc; it's the language the game runs in. More specifically, it runs on MIPS r300. When using psxfin, use the r3000 debugger.
  - The game disc also contains tabular data interwoven with the code, and individual files for things like images and sound. these are not all in RAM at once, and cannot be accessed at a whim.
+
  - The game disc also contains tabular data interwoven with the code, and individual files for things like images and sound. These are not all in RAM at once, and cannot be accessed at a whim.
  
  [[https://ffhacktics.com/wiki/FFTPatcher_Suite| FFTPatcher Suit]]
+
  [[https://ffhacktics.com/wiki/FFTPatcher_Suite| FFTPatcher Suite]]
 
  [[https://ffhacktics.com/smf/index.php?topic=12508.msg228258| How to use the patching tools]] Please see these pages to learn about the tools we use for patching!
 
  [[https://ffhacktics.com/smf/index.php?topic=12508.msg228258| How to use the patching tools]] Please see these pages to learn about the tools we use for patching!
  
'''Q. Some data points/routines in the wiki contradict each other; how can a routine/data point be 2 different things at the same time?'''
+
__TOC__
 +
 
 +
==Q. Some data points/routines in the wiki contradict each other; how can a routine/data point be 2 different things at the same time?==
 +
 
  A. they're not! the files in FFT are very large and not all of them can actually be open at the same time! for example, BATTLE.BIN and WORLD.BIN are ''mutually exclusive'' and are never opened at the same time. a short rundown:
 
  A. they're not! the files in FFT are very large and not all of them can actually be open at the same time! for example, BATTLE.BIN and WORLD.BIN are ''mutually exclusive'' and are never opened at the same time. a short rundown:
* SCUS_942.21  -> '''always open.''' This is the executable of the game itself.
+
* WORLD.BIN    -> '''Opened when not in battle.''' This handles everything from shops/towns to saving to the formation screen.
+
* SCUS_942.21  -> '''always open.''' This is the executable of the game itself.
* WLDCORE.BIN  -> '''Opened at the same time as WORLD.BIN.''' It mostly contains sprite and portrait data, though does handle some things on its own.
+
* WORLD.BIN    -> '''Opened when not in battle.''' This handles everything from shops/towns to saving to the formation screen.
* BATTLE.BIN  -> '''Opened during any combat OR during events.''' This is where all of ability formula processing takes place, as well as handles things like the map and playing events.
+
* WLDCORE.BIN  -> '''Opened at the same time as WORLD.BIN.''' It mostly contains sprite and portrait data, though does handle some things on its own.
* OPEN.BIN    -> '''Opened at startup.''' This shows the movie at the beginning of the game, and also handles starting a new game. It may be open in place of WLDCORE for this.
+
* BATTLE.BIN  -> '''Opened during any combat OR during events.''' This is where all of ability formula processing takes place, as well as handles things like the map and playing events.
* ATTACK.OUT  -> '''Opened during the deployment screen.''' it exclusively handles deployment and displaying graphics for deployment.
+
* OPEN.BIN    -> '''Opened at startup.''' This shows the movie at the beginning of the game, and also handles starting a new game. It may be open in place of WLDCORE for this.
* REQUIRE.OUT  -> '''Opened when ending battle.''' this handles the formation screen if dismissing units to make room for others, and which units leave due to low brave/faith, among other things.
+
* ATTACK.OUT  -> '''Opened during the deployment screen.''' it exclusively handles deployment and displaying graphics for deployment.
* OPTION.OUT  -> '''Opened when changing options during battle.''' this mimics the WORLD routines that allow changing the game options.
+
* REQUIRE.OUT  -> '''Opened when ending battle.''' this handles the formation screen if dismissing units to make room for others, and which units leave due to low brave/faith, among other things.
* ETC.OUT      -> handles showing other battle/event graphics such as chapter title cards and game over.
+
* OPTION.OUT  -> '''Opened when changing options during battle.''' this mimics the WORLD routines that allow changing the game options.
* EQUIP.OUT    -> '''Opened when using re-equip.''' this mimics the WORLD routines that allow equipment changing.
+
* ETC.OUT      -> handles showing other battle/event graphics such as chapter title cards and game over.
* CARD.OUT    -> '''Opened when saving between events.''' this mimics the WORLD routines that allow saving to the memory card.
+
* EQUIP.OUT    -> '''Opened when using re-equip.''' this mimics the WORLD routines that allow equipment changing.
* BUNIT.OUT    -> '''Opened when viewing the unit list during battle.''' it mimics the WORLD routines for the formation screen, though the units present are snapshotted from their poses in combat.
+
* CARD.OUT    -> '''Opened when saving between events.''' this mimics the WORLD routines that allow saving to the memory card.
* JOBSTTS.OUT  -> '''Opened when viewing unit jobs & abilities during battle.''' it mimics the WORLD routines that display the scrollable jobs/abilities menus.
+
* BUNIT.OUT    -> '''Opened when viewing the unit list during battle.''' it mimics the WORLD routines for the formation screen, though the units present are snapshotted from their poses in combat.
  all other files tend to be opened on demand (such as effect files, extra combat graphics, etc.).  
+
* JOBSTTS.OUT  -> '''Opened when viewing unit jobs & abilities during battle.''' it mimics the WORLD routines that display the scrollable jobs/abilities menus.
 +
   
 +
All other files tend to be opened on demand (such as effect files, extra combat graphics, etc.).  
 
  Any file that is not open cannot have its routines called or its data read/written to, so be careful.
 
  Any file that is not open cannot have its routines called or its data read/written to, so be careful.
----
+
==Q. How can I access these files if they aren't open? can I open them?==
'''Q. How can I access these files if they aren't open? can I open them?'''
+
 
  A. no, you probably can't. there's a lot of communication back and forth that goes into opening a file, which relies on precisely timing connecting to hardware IO ports and making sure the disc is spinning and that it's spinning to the correct hour, minute, and second of the cd, having another hardware function read the disc into ram, and all this requires a million checks and balances and making sure the cpu is still reading game code in the background...
 
  A. no, you probably can't. there's a lot of communication back and forth that goes into opening a file, which relies on precisely timing connecting to hardware IO ports and making sure the disc is spinning and that it's spinning to the correct hour, minute, and second of the cd, having another hardware function read the disc into ram, and all this requires a million checks and balances and making sure the cpu is still reading game code in the background...
 
  so, no. not yet.  
 
  so, no. not yet.  
 
  rely on files that are already open.
 
  rely on files that are already open.
----
+
==Q. Some routines start and end making changes and then undoing them with r29 and r31. What's up with that?==
'''Q. Some routines start and end making changes and then undoing them with r29 and r31. What's up with that?'''
+
 
  A. That's the stack. Which does need more explanation:
 
  A. That's the stack. Which does need more explanation:
  "r29" or "sp" depending on the assembly is the "stack pointer". It contains the current address of the stack currently being utilised.
+
   
  The "stack" is a nebulously large amount of space used to store temporary information. it is handled from the bottom up.
+
* "r29" or "sp" depending on the assembly is the "stack pointer". It contains the current address of the stack currently being utilized.
  "r31" or "ra" is especially prevelent since any "jal" will ''overwrite'' r31. so it needs to be preserved ''in'' the stack, and grabbed later to use jr r31.
+
  * The "stack" is a nebulously large amount of space used to store temporary information. it is handled from the bottom up.
  Failure to preserve r31 will cause your routine to return into itself and freeze your game.
+
  * "r31" or "ra" is especially prevalent since any "jal" will ''overwrite'' r31. so it needs to be preserved ''in'' the stack, and grabbed later to use jr r31.
  When you subtract from the stack pointer, you are in essense creating temporary storage space. When you add it again, you are deleting said storage space.
+
  * Failure to preserve r31 will cause your routine to return into itself and freeze your game.
  The stack pointer always needs to be preserved going in and out of a routine.
+
  * When you subtract from the stack pointer, you are in essence creating temporary storage space. When you add it again, you are deleting said storage space.
  Other registers that need to be preserved with the same method as r31 are r16, r17, r18, r19, r20, r21, r22, r23, r26, r27, r28, and r30.
+
  * The stack pointer always needs to be preserved going in and out of a routine.
  r24 and r25 are exempt from this, for some reason.
+
  * Other registers that need to be preserved with the same method as r31 are r16, r17, r18, r19, r20, r21, r22, r23, r26, r27, r28, and r30.
  Because of how these registers are treated, you as the compiler ''need to assume'' that any ''other'' register '''will contain garbage data after any routine call.'''
+
  * r24 and r25 are exempt from this, for some reason.
  Without manually checking it yourself there is no guarrantee a register will hold its information between calls.
+
  * Because of how these registers are treated, you as the compiler ''need to assume'' that any ''other'' register '''will contain garbage data after any routine call.'''
----
+
  * Without manually checking it yourself there is no guarantee a register will hold its information between calls.
  
 
More questions to come soon. answers? perhaps.
 
More questions to come soon. answers? perhaps.

Revision as of 04:59, 23 September 2024

Brief overview!

- Assembly refers to the code on the game disc; it's the language the game runs in. More specifically, it runs on MIPS r300. When using psxfin, use the r3000 debugger.
- The game disc also contains tabular data interwoven with the code, and individual files for things like images and sound. These are not all in RAM at once, and cannot be accessed at a whim.
[FFTPatcher Suite]
[How to use the patching tools] Please see these pages to learn about the tools we use for patching!

Q. Some data points/routines in the wiki contradict each other; how can a routine/data point be 2 different things at the same time?

A. they're not! the files in FFT are very large and not all of them can actually be open at the same time! for example, BATTLE.BIN and WORLD.BIN are mutually exclusive and are never opened at the same time. a short rundown:

* SCUS_942.21  -> always open. This is the executable of the game itself.
* WORLD.BIN    -> Opened when not in battle. This handles everything from shops/towns to saving to the formation screen.
* WLDCORE.BIN  -> Opened at the same time as WORLD.BIN. It mostly contains sprite and portrait data, though does handle some things on its own.
* BATTLE.BIN   -> Opened during any combat OR during events. This is where all of ability formula processing takes place, as well as handles things like the map and playing events.
* OPEN.BIN     -> Opened at startup. This shows the movie at the beginning of the game, and also handles starting a new game. It may be open in place of WLDCORE for this.
* ATTACK.OUT   -> Opened during the deployment screen. it exclusively handles deployment and displaying graphics for deployment.
* REQUIRE.OUT  -> Opened when ending battle. this handles the formation screen if dismissing units to make room for others, and which units leave due to low brave/faith, among other things.
* OPTION.OUT   -> Opened when changing options during battle. this mimics the WORLD routines that allow changing the game options.
* ETC.OUT      -> handles showing other battle/event graphics such as chapter title cards and game over.
* EQUIP.OUT    -> Opened when using re-equip. this mimics the WORLD routines that allow equipment changing.
* CARD.OUT     -> Opened when saving between events. this mimics the WORLD routines that allow saving to the memory card.
* BUNIT.OUT    -> Opened when viewing the unit list during battle. it mimics the WORLD routines for the formation screen, though the units present are snapshotted from their poses in combat.
* JOBSTTS.OUT  -> Opened when viewing unit jobs & abilities during battle. it mimics the WORLD routines that display the scrollable jobs/abilities menus.

All other files tend to be opened on demand (such as effect files, extra combat graphics, etc.). 
Any file that is not open cannot have its routines called or its data read/written to, so be careful.

Q. How can I access these files if they aren't open? can I open them?

A. no, you probably can't. there's a lot of communication back and forth that goes into opening a file, which relies on precisely timing connecting to hardware IO ports and making sure the disc is spinning and that it's spinning to the correct hour, minute, and second of the cd, having another hardware function read the disc into ram, and all this requires a million checks and balances and making sure the cpu is still reading game code in the background...
so, no. not yet. 
rely on files that are already open.

Q. Some routines start and end making changes and then undoing them with r29 and r31. What's up with that?

A. That's the stack. Which does need more explanation:

* "r29" or "sp" depending on the assembly is the "stack pointer". It contains the current address of the stack currently being utilized.
* The "stack" is a nebulously large amount of space used to store temporary information. it is handled from the bottom up.
* "r31" or "ra" is especially prevalent since any "jal" will overwrite r31. so it needs to be preserved in the stack, and grabbed later to use jr r31.
* Failure to preserve r31 will cause your routine to return into itself and freeze your game.
* When you subtract from the stack pointer, you are in essence creating temporary storage space. When you add it again, you are deleting said storage space.
* The stack pointer always needs to be preserved going in and out of a routine.
* Other registers that need to be preserved with the same method as r31 are r16, r17, r18, r19, r20, r21, r22, r23, r26, r27, r28, and r30.
* r24 and r25 are exempt from this, for some reason.
* Because of how these registers are treated, you as the compiler need to assume that any other register will contain garbage data after any routine call.
* Without manually checking it yourself there is no guarantee a register will hold its information between calls.

More questions to come soon. answers? perhaps.