As Terra and Celes gain levels or have their levels averaged, they will automatically fill their spell lists with up to sixteen spells specified by their learning tables. There are two routines that handle this process: one at C2/61FC which addresses when the character gains a level and another at C0/A17F when the character has their level averaged (so if you intend to change who learns magic on level up, you will need to address said change in both routines). Spell learning is achieved by setting the corresponding Spell RAM byte for the character to $80 ($1A6E-$1AA3 for Terra, $1BB2-$1BE7 for Celes).