OK, let me try to explain everything I've done so far...
So, the place in RAM where the digits are stored immediately before they're loaded for visual processing is 00:0340. As previously mentioned, it's four bytes per digit: x,y,(digit+70),(vhoopppc).
It should be noted that the game does, by default, assign five digits per target, even though five digits are normally never used.
Now, byte 2 of those entries (the digit) is loaded into the table at 0340 from a table at 7E:DBE6. This table also assigns five digits per target, but the uppermost digit is never loaded into 340. Instead, the game loads 1000s, 100s, 10s, 1s and the 10000s of the next entry (which is always FF, or blank) into the entry for each target.
So, the first fix was to change
$02/E5AA BD E6 DB LDA $DBE6,x[$7E:DC19]which is the opcode responsible for loading each displayed digit, so that it reads
$02/E5AA BD E5 DB LDA $DBE5,x[$7E:DC18]
So now the game is accounting for the correct five digits for each target. As a result, the damage digits display one sprite to the right from where they normally would, but I personally find that completely inoffensive. It can probably be shifted, but I say why bother? It looks fine.
So now we're at the point where the problem at hand is the fact that nothing is being loaded into the 10000s place digit. You can cheat the damage up to 16383, but only "6383" will show up. This has to do with the decimal conversion process, and more specifically what the game is doing (or not doing) with the last remainder.
The conversion routine loads the digits into 180C-180F, and they are loaded from there into the table at DBE6. As far as I can see, the 10000s place digit is never loaded into 180B.
So I spent a while watching a live disassembly of the conversion routine. I still don't get what is happening or how it happens. My understanding of the ROL opcode is that it essentially works like ASL, except that it can be performed on two bytes at once... and sometimes if you ROL 00 00, you get 01 00, and I have no idea where that bit comes from.
anyway... from what I can see, the storing of digits into 180C-180F is pretty hardcoded. the game doesn't do a STA $180C,x op that is performed four times as X increases. it's STA $180C, STA $180D, STA $180E and STA $180F. What I did notice was, right before the jump into this subroutine, the game does this:
$02/86C1 A2 10 27 LDX #$2710
Well, 0x270F is equal to 9999, so it occurred to me that this op might be setting the upper limit of what numbers are considered in the decimal conversion process.
So since we want the game to accept damage as high as 0x3FFF, I changed this op to:
$02/86C1 A2 00 40 LDX #$4000
I then cheated 0x3000 damage into A4 and watched what happened...
0x3000 is equal to 12288.
The output I got on screen was "[random incorrect sprite]288"
So I looked at what was in the table at DBE6...
Bear in mind that the format for digits is (actual digit + 70), so correct would be 71 72 72 78 78
What I had was FF 7C 72 78 78
Well, A + 2 = C, which means what the game was doing was now accounting for the value over 9999, but instead of separating that 7C into two usable digits, it was just going with it.
So I found the op that stores 7C into DBE7:
$02/CA35 99 E7 DB STA $DBE7,y[$7E:DBED]
$02/CA38 C8 INY ;(I needed this one-byte op to, because I was writing a JSL)
And I changed it to:
$02/CA35 22 E0 EF 12 JSL $12EFE0[$12:EFE0]
Then wrote the subroutine:
$12/EFE0 C9 7A CMP #$7A ;compare the digit about to be stored into the table with 7A
$12/EFE2 90 0A BCC $0A [$EFEE] ;if it is lower than 7A, skip to the end of this routine (and proceed as normal)
$12/EFE4 48 PHA ;if it is 7A or higher (which will only happen with the digit in the 1000s place, then stack it
$12/EFE5 A9 71 LDA #$71
$12/EFE7 99 E6 DB STA $DBE6,y[$7E:DBED];load 71 into the 10000s place
$12/EFEA 68 PLA ;pull the digit back off the stack
$12/EFEB 38 SEC
$12/EFEC E9 0A SBC #$0A ;subtract 0A
$12/EFEE 99 E7 DB STA $DBE7,y[$7E:DBEE];then proceed as normal
$12/EFF1 C8 INY ;(this is a replacement of that INY we cannibalized at 02/CA38
$12/EFF2 6B RTL
And there you have it!
Five digits now display properly... as long as you cheat in damage over 9999. I still haven't gotten to the point of turning off those limits. For the most part, this will just be a matter of finding them (there are several, different ones for damage routines of different commands) and changing them from 270F to 3FFF.
The Multi-Target damage routines may require a little figuring out, because I think the game does something weird where if the total calculated damage is over 9999, the first target gets 9999 and the rest of the damage is distributed among the remaining targets... or something like that.
Oh well, we'll see.
I'm off work today, but I have some chores to do, so I'm not positive I'll be able to get a lot of work in on this.
Here's hoping.