In other news, I got the "9 small" nametable positions worked out, but they seem to be getting cut off by the menu drawing that happens later. I'll have to look into that =x
I fixed that! And I think updated the github thing too! With the fix! This is exciting. Edit: I spent too long explaining boxes before posting, oops...
I'm gonna try to explain the boxes now. I might not make it.
So at the start of a normal battle, it draws the player name box: Bank C, FinishBattlePrepAndFadeIn
When it gets to BattleLogicLoop, it draws the enemy name box, then the command box on top of it.
It uses UndrawNBattleBlocks_L (Where N is the number in A, so it always LDA #'s first) to remove a box.
SOMETIMES it uses a variable called btl_combatboxcount_alt and sometimes it uses btl_combatboxcount to know how many boxes are currently drawn, so it can use that number in A while undrawing them. I think these variables are only actually used for mid-battle stuff: Attacker, attack name, defender, damage, etc. Menu boxes the player is in control of don't use them and just undraw the boxes as needed.
As for how each box is made... after the game chooses what kind of box to draw, those different routines load up a table of 5 bytes: look for lut_BattleCommandBoxInfo to see them all. DrawBattleBoxAndText has the explanation for how the bytes are used. Basically just width, height, X and Y coordinates to start from, and the first byte is 0 if its a box and 1 if its text--in which case instead of width and height, its the pointer to the text string?
Sometimes there's some... fiddly stuff, I guess, where it takes all the text data and puts it in RAM at $0340. (First it clears it though: ClearUnformattedCombatBoxBuffer) The best example is the magic menu. You can see the unformatted strings there: The L, the #, the $FF for space, the $0E for item name control code, then the spell's item ID, and so on. The game puts it there (well I chose the location so I can see all the drawing stuff in the same space instead of all over $6000 somewhere) so it can read what it needs to draw while switching banks to get the item names and stuff.
And THEN a single text string is formatted to RAM: I've moved this to $0320. When you open the magic menu, and the game's still running, this will display the last line of the box, the level 4 or 8 spells.
So it will read the unformatted part, format it, then draw it inside the box. This seems quicker than the usual way it draws text in menus, which is to keep bank-swapping back and forth as it formats and draws every single tile in turn?
Then, uhmm... I guess before it draws all that to the screen, it first copies it to $0400. If you put the RAM viewer to have 32 bytes a line, you can actually see the screen if you have the right table file loaded!
There's also ClearBattleMessageBuffer, which basically clears the "screen" in RAM, before doing any of the actual formatting and copying of tiles.
BattleDrawMessageBuffer draws the RAM screen to the PPU... It draws 1 row a frame from the top to the bottom.
And where it gets complicated is BattleDrawMessageBuffer_Reverse, which draws 2 rows a frame, from the bottom to the top.
Then UndrawBattleBlock does a bunch of stuff to clear the screen in RAM, re-draw it without the last box, and then it uses the Reverse version to re-draw it to the PPU so it looks like the boxes are folding upwards as they vanish one by one.
So every new box drawn or erased, it goes through the whole process of figuring out how many boxes, what's in them, copying the source pointers to RAM, formatting them line by line, copying that line to another part of RAM, and then finally drawing the whole message half of the screen.
I'm still not entirely certain.
Update: Fixed the magic in menus bug, updated the box drawing logic for menus. So now:
Draws the player box first, then it will draw the roster box, and waits for any input (any button I think) before drawing the command box.
If surprised: Draws the player box, does the turn, then draws the roster box and does the wait for input before drawing the command box.
The input wait thing only happens at the start of battle, not between turns!
Magic menu undraws the command box, no more seeing flickers of anything between boxes being drawn.
Player HP should be updated after every entity's turn properly.
If you figure out sequence of menu logic that undraws something that shouldn't be undrawn (player box vanishing, command box not showing up when it should be) please try to remember exactly what you did!
I am INTENSELY frustrated about the header bytes with these boxes. A byte of 1 means that the Y position is 1 down from where I want it to be, somehow. You just can't put text on the top border of these boxes! And I can't figure out where its doing this...