Can someone help me make sense of these old ASM notes regarding Font Spacing?

Started by Choppasmith, May 15, 2017, 12:08:07 AM

Previous topic - Next topic


Hi there! So I'm working on giving MoxHyPa's translation of Itadaki Street Special on PS2 a much needed facelift. I'm nearly finished, doing graphics now, and should have a patch up by the end of the month.

I've been using some old project notes and translations by DQ Translations released by them in and old forum thread here. I originally used their graphic templates to add English graphics for ISS Portable.

Anyhoo, they had some notes regarding font spacing and seemed to have it figured out. There's a bit of text I've compiled into a pastebin here:

They also had a couple screenshots

I know begging is frowned upon, but I was kinda hoping someone could look at this and tell me how I could utilize it (like if it's a simple matter of editing some values in a Hex Editor) since having more room for names and such would be a GODSEND.

There's also some stuff about Pointers but I think it's because they made a custom inserting program. If not, hey cool, I'll still release my patch as is. Still very playable and MUCH better than the old one.


I can help you a little bit.

FPR = Floating Point Register
20 = 14
That's because
20 really DOES equal 0x14

Raymond Hettinger of Python likes to say he's a young man in hex because he's 0x3? years old.

I don't know how to read the instruction: (don't know what sd means and don't know what var_170($sp) means
seg000:001EC89C   sd $v0, 0x170+var_170($sp)

I'm not great at reading assembly. Maybe it is adjusting the size on each pass based on the current character. That's what it looks like.


I am not that good at assembly but here is a try.
From what I see , the notes contains parts of setting up printing parameters for different parts of the game and then calling up the main printing function.  I have made a C version of just one of those example, they all seem to be almost the same, just that they set different value and then jump to what appears to be the main printing function. Note, I can be completely wrong here!

a0, a1, a2,a3 , tX registers are used for arguments.
sd instruction stores a doubleword at the speciffied address.Not sure what it is doing there, perhaps storing value to the stack, or to an array/structure.
seg000:001EC898   li $v0, 0x14                                v0 = 0x14 text size
seg000:001EC89C   sd $v0, 0x170+var_170($sp)                  0x170+var170(sp)  = v0 = 0x14
seg000:001EC8A0   daddu $a0, $s1, $0                          a0 =  s1;
seg000:001EC8A4   sd $v0, 0x170+var_168($sp)                  0x170+var_168($sp) = v0;
seg000:001EC8A8   daddu $a1, $s0, $0                          a1= s0
seg000:001EC8AC   li $a2, 0x41                                a2 = 0x41
seg000:001EC8B0   li $a3, 0xFFFFFFFF                          a3= 0xFFFFFFFF
seg000:001EC8B4   sd $v1, 0x170+var_160($sp)                  0x170+var_160($sp) = v1
seg000:001EC8B8   li $t0, 0x26                                t0 = 0x26
seg000:001EC8BC   li $t1, 0x16A                               t1 = 0x16A
seg000:001EC8C0   li $t2, 0x200                               t2 = 0x200
seg000:001EC8C4   jal sub_1E6410                             
seg000:001EC8C8   li $t3, 0x1C0                               t3 = 0x1c0

//         a0 , a1 , a2 , a3 ,      t0 ,       t1 ,         t2     t3;
int size , a0 , a1 , a2 , a3 , StartPoint ,StartPoint2 , char_nr , t3;
long unk1;   // 0x170+var170(sp)
long unk2    // 0x170+var_160($sp)
long unk3    //0x170+var_160($sp)

size = 0x14;
unknown1 = size;    // = 0x14
a0 = s1;  //No idea what s1 contains.
unk2 = s0;

unk2 =  size     // = 0x14
a1 = s0;
a2 = 0x41;
a3 = 0xFFFFFFFF;
unk3 = v1;
StartPoint = 0x26;
StartPoint2 = 0x16A
char_nr = 0x200
t3 = 0x1c0

// Sub_1E6410(a0, a1, a2 , a3 , t0, t1 , t2 , t3);

//  Sub_1E6410(a0, a1, a2 , a3 , StartPoint , StartPoint2 , char_nr , t3);

Sub_1E6410(s1, s0, 0x41 , 0xFFFFFFFF , 0x26  , 0x16A , 0x200 , 0x1C0);

The question is: what do you want to do?
If you want to do something simple, like changing the number of max characters before newline you can easily do that with changing the value of the $t2 register. Takes like 2 seconds in PS2Dis.
I am not sure what the StartingPoint, and StartingPoint2 are how are they used.


Thanks for the info guys!  :)

Quote from: krat0s on May 17, 2017, 12:52:26 PM

The question is: what do you want to do?
If you want to do something simple, like changing the number of max characters before newline you can easily do that with changing the value of the $t2 register. Takes like 2 seconds in PS2Dis.
I am not sure what the StartingPoint, and StartingPoint2 are how are they used.

Well I figure if I can make the game look like those test screenshots and fix the spacing between letters, then I could edit in a new, more condensed font to fix the overlap with bigger letters then I would be golden. That should easily give me room for things like character and Sphere names (currently limited to 5 and 8 letters respectively, FYI, Spheres are essentially powerups that are named after various DQ and FF Abilities and Items so the more visual space I could get the better). Are you saying editing the characters per line value affects the spacing or do you think that's a different value? Even better if I can find this subroutine that's used for Shop and Area names and use it for other strings like Character names and Spheres

At the time I thought I was clever and seeing that all the Shop and Area names had the value of 80 at the end, but then I realized I think all I did was type "half" of a Japanese letter which is enough for the routine to kick in (I've been using the 1 byte letters easily picked up in a hex editor, but I think a lot of this stuff relies on 2 bytes per letter)


So I totally had that eureka moment and finally figured it out. Well somewhat anyway, I got ps2dis and was able to plug in some of DQT's code, but wherever I tried to plug in any of the lines that have +var_160 or whatever, ps2dis doesn't seem to recognize it. I noticed the way the code is entered in the notes are slightly different then how it's actually entered in PS2dis, so Im sure it's a matter of entering it the right way. Any ideas?


Quote from: Choppasmith on June 05, 2017, 12:39:32 AM
So I totally had that eureka moment and finally figured it out. Well somewhat anyway, I got ps2dis and was able to plug in some of DQT's code, but wherever I tried to plug in any of the lines that have +var_160 or whatever, ps2dis doesn't seem to recognize it. I noticed the way the code is entered in the notes are slightly different then how it's actually entered in PS2dis, so Im sure it's a matter of entering it the right way. Any ideas?
What are you trying to do?
What are you changing in PS2Dis?
Post as many details as possible.


Well I discovered that the "notes" I posted above was DQT's own code for the menu text.

Here's their first set:

seg000:001EC898   li $v0, 0x14
seg000:001EC89C   sd $v0, 0x170+var_170($sp)
seg000:001EC8A0   daddu $a0, $s1, $0
seg000:001EC8A4   sd $v0, 0x170+var_168($sp)
seg000:001EC8A8   daddu $a1, $s0, $0
seg000:001EC8AC   li $a2, 0x41
seg000:001EC8B0   li $a3, 0xFFFFFFFF
seg000:001EC8B4   sd $v1, 0x170+var_160($sp)
seg000:001EC8B8   li $t0, 0x26
seg000:001EC8BC   li $t1, 0x16A
seg000:001EC8C0   li $t2, 0x200
seg000:001EC8C4   jal sub_1E6410
seg000:001EC8C8   li $t3, 0x1C0

And here's the same block of code as it currently is in game (copied from ps2dis, sorry about the formatting)

addiu v0, zero, $0014 # 001ec898:24020012 v0=$00000014
sd v0, $0000(sp) # 001ec89c:ffa20000
daddu a0, s1, zero # 001ec8a0:0220202d
sd v0, $0008(sp) # 001ec8a4:ffa20008
daddu a1, s0, zero # 001ec8a8:0200282d
addiu a2, zero, $0041 # 001ec8ac:24060041 a2=$00000041
addiu a3, zero, $ffff # 001ec8b0:2407ffff a3=$ffffffff
sd v1, $0010(sp) # 001ec8b4:ffa30010
addiu t0, zero, $0026 # 001ec8b8:24080026 t0=$00000026
addiu t1, zero, $016a # 001ec8bc:2409016a t1=$0000016a
addiu t2, zero, $0200 # 001ec8c0:240a0200 t2=$00000200
jal $001e6410 # 001ec8c4:0c079904
addiu t3, zero, $01c0 # 001ec8c8:240b01c0 t3=$000001c0

It's mostly that second line, 1ec89c. If I try to enter the line as written above it doesn't seem to recognize it, it just stays unchanged. As I said above, if I can add that custom routine to all the text windows and maybe find the routine used for Shop and Area names above and apply it to other text strings like Sphere names and Character names. But if I can't do that, I have a backup. Knowing that first line is text size, I figured I could just lower the font size so that the text could better fit into windows, which as you said, is something that only takes 2 seconds. I'm currently using PCSX2dis to try and find ALL the text window routines. If you know any tips that might help my search go faster, I'd appreciate it. This stuff involving breakpoints is a little daunting and confusing.

EDIT: Yeah some pointers on using programs like PCSX2dis would be helpful. I've tried to setup breakpoints to when certain text is displayed, but even when it breaks I can't seem to find anything as to where the text printing routine is.


Going to explain this for you. I will try to make it simple but I don't have PS2Dis opened in front of me.
First open PS2Dis and load the main file which you already have done so. Then you should go in the Analyzer file menu and Invoke Analyzer.
Pressing F will open a tiny textbox when you can input the address in hex and jump right there. Since you posted that assembly here , it means you have figured that out.
PS2Dis does come with a small document explaining some basic operations I think.
To make changes you click on the instruction lines and press enter, edit the lines with the new opcodes then you press simply press enter again. At the moment that edit box has been closed and you see the new edited line in the main window, the change is already made. You can close PSDis and rebuild the iso and test to see if it works. Do you know how to properly deal with PS2 image replacement/generation?

Now, the ASM from that team notes is not an edited version. In fact it's from the game. In case you are wondering how that it is possible, it because the team used IDA Pro to dissamble , and it displays things a bit different. I know for  sure that it is from IDA Pro because of that var_ that you are having problems to update.
In the PS2Dis that you posted, it' almost the same code. Other members can prove it!
I will take only one line:
li $v0, 0x14  #sets the value of the register v0 to 0x14.  V0=0x14

In the PSDis for this line we have:
Addiu $v0 , zero , 0x14  # it mea  that in v0 will be stored the value of the addition of the zero and 0x14. Zero is an register which always holds the value zero. So v0=0+0x14 =0x14

See? It's the same thing for every line despite the fact that it looks different.

If the team notes are correct and the v0 is the text size which is always 0x14 then all you have to do is to go to the address of each
li $v0 , 0x14    of the different section of the notes an you will  of course see:
Addiu $v0 , zero , 0x14

Pres Enter on that line and change the "14". Leave the 0x as it is. This way you are changing the text size (if that is really text size and the previous translation team managed to reverse it successfully.) Obviosly , the value is in hex.
I would recommend setting the value to 0x12 , or 0x13 , values near the original value and see what happens.

June 09, 2017, 03:56:06 PM - (Auto Merged - Double Posts are not allowed before 7 days.)

Hi, I finslly had some free time and been dealing all day with this.
Tried editing in PS2Dis but for some reason it just won't save up the changes.
So.. went straight to IDA Pro, made some changes and boom:
Normal :

Smaller size , 0x10:

Changing colour:

Smaller text with new colour printed at lower than the image box:

So far I have:

//  Sub_1E6410(a0, a1, Flashing_Icon_Value , Colour , StartPointX , StartPointY , EndpointX , EndpointY);

a0 -  seems to be a structure contains the text and some other values. Not important and no need to change.

a1 -  Takes the following values: 0x02 , 0x03, 0x04 , 0x07, 0x08, 0x09, 0x0A, 0xc ,   0x14 ,  0x15  ,  0x16 , 0x17, 0x18   , 0x60 ,  0x61. They seem like control code but we will find out soon.

Flashing_Icon_value  - This is somehow related to that upside done flashing triangle but I don't know excatly how. It is 0x41 and any value bigger than 0x45 causes text corrupted , very strange value. I do not think that you need to deal with this. Leave it as it is. One thing i am sure though, setting it's value to 0 disables the icon and just the text is displayed.

Colour - yes, it's colour , I wonder how I didn't notice it before , all FFs correspond to white and everywhere the text is white. I still have to figure out how we will find correct value to make new colors display properly(the blur color you see in the screeshot above was my second random edot, the first one displayed nothing.)

StartPointX - X position when you want the text to start.
StartPointX - Y position when you want the text to start.

EndPointX - Now this is always 0x200 and that = 512. No need to change this i think. Read below.
EndPointX - Now this always 0x1C0 and that = 448. No need to change this i think. Read below.
Here is the interesting part! Go back to the PCSX2 screenshots and you see the title bar. You will notice 512x448, the resolution!. Now sure what these values do but I don't think there is any need to tamper them.

As for the text size you must change the value in v0.
Since PS2Dis is giving me a headache and getting IDA Pro is too much for you , I will make simple. I will list the hex offsets of the size value for each function so you can edit them.

(The DQT team has 9 section. Through trial and erro I managed to discover that the 9 secton/fragement of code (002EB8B8  -  002EB8E4)  handles the main menu printing.) Other routines do other stuff. It is up to you to check what this routines do and I suggest that you edit the size of one of them at a time, making it smaller or bigger and then keep playing the game. After identifying one section give back its original value and change the size for the other section, you get the point.

I am making an editor for you for today I spent too much time and the byte swap is giving me a headache.

Routine                       ELF hex size address/ try small values(0x10, 0x11 is quite good , even 0x18 is too big)
001EC898  -  001EC8C8      :  0x000EC918
0021F2C8  -  0021F2FC      :  0x0011F348
0022DE48  -  0022DE78      :  0x0012DEC8
0022E180  -  0022E1B0      :  0x0012E200
0023B170  -  0023B1A4      :  0x0013B1F0
0023C000  -  0023C03C      :  //Value is not set directly but loaded from somewhere!
002539F0  -  00253A18      :  0x00153A70
002EB8B8  -  002EB8E4      :  0x001EB938    // Main Menu!!
002F9BA0  -  002F9BCC      :  0x001F9C20

So just use any regular editor and as soon as you land in there you will see 14 and change to something small or bigger.
NOTE: To successfully edit the value you must edit 2 bytes, even the one after it. The 00. The byte after 14 is 00 and together they form:
0x1400  , however the bytes are reversed so we get 0x0014 ! This means that unless setting bigger than 255 values (which in this case you certainly don't , even 0x18 is really big), there is no need to mess with the other byte. Just go ahead edit only the 0x14 byte!

That's for now. Got to go, will try to find more details tomorrow.


Wow! I missed your edit until now, and here I was feeling glum, about to post that I haven't made any headway.

<---n00b mind blown!

I mean, yeah, I figured out that I can look at the address in PS2Dis, subtract FFF80 and change it easily in a hex editor, and with my lack of programming knowledge, this seems right up my alley. I can just make the font slightly smaller so that the text better fits into windows.



I was able to figure out that

2eb8b8 Main menu Profile/Name select text font size
21f2c8 Options Text size
22DE48 Unknown text size
22E180 Unknown text size
23B170 "Change Rules" text size
002539F0 Unknown
02F9BA0 Turn Order text size

Maybe this was a bad assumption on my part but I figured all the text printing routines would be "addiu v0, zero, $0014" with maybe the 14 being different for various sizes. Because I wanted to try and fix stuff like this:

By reducing the font size like I did above.

Searched all throughout the file using PCSX2dis to try and alter the files in real time. Nothing, nadda. Heck even the Main menu items could use a bit of shrinking and I can't find that either.

Are you saying I should just look at anything involving v0 value and not necessarily addiu or anything else? What would be the best way to search? Thanks for all your help. My mind is still blown! Since making this thread I've gone from:

This stuff is WAYY beyond me > I think I get it > I'm getting it > Hey! I'm doing some ASM hacking!