Romhacking.net

Romhacking => Help Wanted Ads => Topic started by: gukid/ioev on January 11, 2022, 11:46:01 am

Title: [Technical] [PSX] Breath of Fire IV Controller Layout Text
Post by: gukid/ioev on January 11, 2022, 11:46:01 am
I'm working on a hack that reverts the controller layouts in Breath of Fire 4 to their (way more sensible) Japanese counterpart.  So far I have the layouts working, and they can be selected from the settings menu.  I also have updated all of the icons in the text to be correct (as far as I can tell.)

I've been having a really hard time figuring out where the data is that determines the layouts that are displayed on the controller settings screen, and also the text labels for the player name input screen (though I haven't looked into this part much yet.)

I know where these strings are stored, and changing the indexes or strings themselves changes what is displayed on screen, but there are 2 dynamic fields that swap one button functions on layouts 3/4 that are on different buttons from the Japanese version, and this part can't be corrected by changing the text or indexes.

I'm also pretty sure one of the strings won't fit correctly (Talk/Confirm needs to be on the right) and I'm assuming I'll have to tweak the spacing a little bit, or put "Confirm" on a new line if that's possible.

I'm familiar with the .EMI file format, and have have read through https://www.romhacking.net/hacks/6413/ (bof4 text documentation by navarchos) but it seems this screen must be stored in a slightly different way.

Any help would be greatly appreciated!  Also I can go into further details about what I have figured out if that would be helpful.
Title: Re: [Technical] [PSX] Breath of Fire IV Controller Layout Text
Post by: navarchos on January 12, 2022, 09:17:42 am
Looks like you'd want to change a pointer table in GAME.EMI. Here's what I got from tracing assembly:


801b2808 94440000: lhu    $a0(80116cf8), 0x0000(v0)([801b52f8] = 80bf)
...
8014c0e0 3084ffff: andi   $a0(000080bf), 0xffff
8014c0e4 00042342: srl    $a0(000080bf), 0x0d
8014c0e8 14800003: bne    $a0(00000004), $r0(00000000), 0x8014c0f8
8014c0ec 00051040: sll    $v0(801b52f8), $a1(000000bf), 0x01
8014c0f8 24020002: move   $v0(0000017e), 0x0002
8014c0fc 14820008: bne    $a0(00000004), $v0(00000002), 0x8014c120
8014c100 24020004: move   $v0(00000002), 0x0004
8014c120 14820008: bne    $a0(00000004), $v0(00000004), 0x8014c144
8014c124 2482ffff: addiu  $v0(00000004), $a0(00000004), 0xffff
8014c128 3c02801e: lui    $v0(00000003), 0x801e
8014c12c 3442b000: ori    $v0(801e0000), 0xb000
8014c130 00051840: sll    $v1(00000002), $a1(000000bf), 0x01
8014c134 00621821: addu   $v1(0000017e), $v0(801eb000)
8014c138 94630000: lhu    $v1(801eb17e), 0x0000(v1)([801eb17e] = 109c)

I'm looking at the string "action"
First, it loads 0x80bf from the memory (which in turn, is from GAME.EMI), then it extracts only the lower bytes (0xbf), multiplies that by two and adds it to a base address for a pointer table.
0xbf indicates that the 0xbf-th (or 191st) pointer is to be read, and the 191st pointer does point to "action"

The address to this pointer is 0x000202f8 in GAME.EMI, hope that helps
Title: Re: [Technical] [PSX] Breath of Fire IV Controller Layout Text
Post by: gukid/ioev on January 12, 2022, 10:29:31 am
Thank you!  I'm sure this is it.

The controller layout data is actually at the end of this block, and I while I noticed that the character Strings are contained here, I didn't notice that that there was also a whole bunch of other strings that were mostly control codes.  It won't be as easy as just swapping in the Japanese file data but I think it'll be pretty straightforward once I map out the string table.

Update:

The table ends up looking like:
Code: [Select]
C880      Camera
BD80   Change Rank
BE80 /Cancel
C780 Subscrn
BF80 Action
C080 Talk/Confirm
C980 Dash
C180 START button      Pause
C280 SELECT button     Help

BD80   Change Rank
C880      Camera
BE80 /Cancel
C780 Subscrn
BF80 Action
C080 Talk/Confirm
C980 Dash
C180 START button      Pause
C280 SELECT button     Help

C880      Camera
BD80   Change Rank
BE80 /Cancel
C780 Subscrn
C980 Dash
C080 Talk/Confirm
BF80 Action
C180 START button      Pause
C280 SELECT button     Help

BD80   Change Rank
C880      Camera
BE80 /Cancel
C780 Subscrn
C980 Dash
C080 Talk/Confirm
BF80 Action
C180 START button      Pause
C280 SELECT button     Help

Which is definitely the button layouts, although it doesn't handle where the strings are positioned.  So while I can achieve most of what I want to do here, I'll need to go up one additional "layer" per-se, and find the data that references these layouts so I can reposition the text.

Update:

Since I'm new I often forget what tools I have available to figure this stuff out.  Modifying values in memory directly after this table alters the position of the strings.  Getting close!
Title: Re: [Technical] [PSX] Breath of Fire IV Controller Layout Text
Post by: navarchos on January 12, 2022, 09:25:52 pm
More tracing, this time with the help of NO$PSX's extremely useful VRAM and GPU debugger:

Once again, I'm looking at the string "Action"
The GPU command used to render the first character gives a hint as to how the entire string is positioned:

Code: [Select]
64808080 # variable size textured rectangle
006C0070 # upper left edge of the rectangle (yyyyxxxx)
3C004C08 # clut + uv coordinates
000C0008 # size of rectangle

The second line is the one we're looking for.

X coordinate:
Code: [Select]
80140f98 8fb50034: LW      00000000 (s5), 0034 (801ff670 (sp)) [801ff6a4]
...
801b281c 92040000: LBU     00000004 (a0), 0000 (801b5318 (s0)) [801b5318]
...
801b282c 02a42021: ADDU    00000030 (a0), 00000040 (s5), 00000030 (a0) # final x coordinate = 0x40 + 0x30 = 0x70
...
80140b04 acc40008: SW      006c0070 (a0), 0008 (8002f078 (a2)) [8002f080] # push coordinates
The value at 0x801ff6a4 can't be changed, and is likely the offset of the current character being rendered by the GPU, as such, it's probably not the offset we're looking for. However we can change the value at 0x801b5318, which is the x-axis offset. Just like the pointer-to-pointer, this is found in the GAME.EMI file, at 0x20318.

Y coordinate:
Code: [Select]
80140f9c 8fb40030: LW      00000088 (s4), 0030 (801ff670 (sp)) [801ff6a0]
...
801b2820 92050001: LBU     000000bf (a1), 0001 (801b5318 (s0)) [801b5319]
...
801b2838 02852821: ADDU    00000030 (a1), 0000003c (s4), 00000030 (a1) # final y coordinate = 0x3c + 0x30 = 0x6c
...
80140b04 acc40008: SW      006c0070 (a0), 0008 (8002f078 (a2)) [8002f080] # push coordinates
Again, the value at 0x801ff6a0 cannot be changed, but we can change the y-axis offset at 0x801b5319. This is right next to the x-axis in GAME.EMI, at 0x20319.
These offsets are not signed integers, but setting both of them to 0 places the string on the uppermost left corner of the window, so there shouldn't be any problems with the positioning.
(https://cdn.discordapp.com/attachments/712288823614111784/931010817187512340/unknown.png)
Hope that helps.

January 13, 2022, 12:50:11 am - (Auto Merged - Double Posts are not allowed before 7 days.)
If you'd like to change the underlines:

They come as triplets of bytes in GAME.EMI. The first byte of the triplet denotes the x-axis offset of the line, the second is the y-axis offset of the line (which is the same for both start and end points), and the last byte denotes the length of the line.
The location of the y-axis offset of the right underline (which is the one you'll be changing, I assume) is 0x20336 in GAME.EMI.

The line is very faint (especially the right one) but that should help with making sure the text doesn't collide with the line.
Title: Re: [Technical] [PSX] Breath of Fire IV Controller Layout Text
Post by: gukid/ioev on January 13, 2022, 11:01:06 am
Thank you for all of your help!  I had actually figured out the structure of the positioning of the text and bars, but seeing your comments on the ASM is really helpful as I've been having trouble understanding what most of it was doing.

The current state of things is:
(https://media.discordapp.net/attachments/215603125241774080/930932261753356388/unknown.png?width=740&height=582)

I figured it was easier to just shift everything over to the left, than mess with trying to pull apart the "Talk/Action" string and figure out a way to put an additional string on the screen or manage a return code.  I had also considered just removing the text for Action and Cancel and let it be implied, but I think this works well enough.

I've also figured out the characters on the name entry screen, it's a single image with some offsets to which character to display.

I think the only things remaining is one bug that showed up when I changed the controller button mappings back to the japanese data, is on the name entry screen the "Next" function no longer works.  Not a huge deal, but still kind of strange.

Also on the Japanese settings screen it does a neat thing where it moves the text over a bit, and resizes the grey line underneath.  So in the image I posted, Dash would be up against cancel "Dash/Cancel" and if Dash were in the Action position, it would be up against the square button and the line would be shorter.  No idea how it does this though, but I suspect there's some kind of character code for it, so I'll probably end up digging into the Japanese text to see.
Title: Re: [Technical] [PSX] Breath of Fire IV Controller Layout Text
Post by: MD_Prometh on January 13, 2022, 04:26:18 pm
This looks like a cool hack. Always neat to see BOF IV get some love
Title: Re: [Technical] [PSX] Breath of Fire IV Controller Layout Text
Post by: navarchos on January 13, 2022, 05:12:12 pm
Thank you for all of your help!  I had actually figured out the structure of the positioning of the text and bars, but seeing your comments on the ASM is really helpful as I've been having trouble understanding what most of it was doing.

The current state of things is:
(https://media.discordapp.net/attachments/215603125241774080/930932261753356388/unknown.png?width=740&height=582)

I figured it was easier to just shift everything over to the left, than mess with trying to pull apart the "Talk/Action" string and figure out a way to put an additional string on the screen or manage a return code.  I had also considered just removing the text for Action and Cancel and let it be implied, but I think this works well enough.

I've also figured out the characters on the name entry screen, it's a single image with some offsets to which character to display.

I think the only things remaining is one bug that showed up when I changed the controller button mappings back to the japanese data, is on the name entry screen the "Next" function no longer works.  Not a huge deal, but still kind of strange.

Also on the Japanese settings screen it does a neat thing where it moves the text over a bit, and resizes the grey line underneath.  So in the image I posted, Dash would be up against cancel "Dash/Cancel" and if Dash were in the Action position, it would be up against the square button and the line would be shorter.  No idea how it does this though, but I suspect there's some kind of character code for it, so I'll probably end up digging into the Japanese text to see.

That looks great! If I may ask, where are the controller layout data located in GAME.EMI?
Title: Re: [Technical] [PSX] Breath of Fire IV Controller Layout Text
Post by: gukid/ioev on January 13, 2022, 05:39:06 pm
Actually, I was mistaken, it's not in GAME.EMI, it's in:

EDIT: Nevermind, it IS in GAME.EMI, apparently my assumption of the data was off a bit, rather than starting with 00, it ends with 00.  I've updated the locations below.

Code: [Select]
BIN/SYSTEM/CAMP.EMI: 00037464
BIN/SYSTEM/COMMU01.EMI: 00021c64
BIN/SYSTEM/COMMU02.EMI: 00018c64
BIN/SYSTEM/COMMU03.EMI: 00033464
BIN/SYSTEM/COMMU04.EMI: 00019464
BIN/SYSTEM/COMMU05.EMI: 00019464
BIN/SYSTEM/COMMU06.EMI: 00039c64
BIN/SYSTEM/COMMU07.EMI: 00035464
BIN/SYSTEM/COMMU08.EMI: 0002a464
BIN/SYSTEM/COMMU09A.EMI: 00039464
BIN/SYSTEM/COMMU09B.EMI: 00037464
BIN/SYSTEM/COMMU09C.EMI: 0003d464
BIN/SYSTEM/GAME.EMI: 00022498
BIN/SYSTEM/LOT_SHOP.EMI: 0001d464
BIN/SYSTEM/MASTER.EMI: 00035464
BIN/SYSTEM/MSHOP.EMI: 00031464
BIN/SYSTEM/SAVE.EMI: 00033c64
BIN/SYSTEM/SGAMEN.EMI: 00041464
BIN/SYSTEM/SHOP.EMI: 00034c64
BIN/WORLD/AREAD075.EMI: 000fc464
BIN/WORLD/AREAE000.EMI: 000f9464
BIN/WORLD/AREAE003.EMI: 000f9464
BIN/WORLD/AREAE004.EMI: 000f9464
BIN/WORLD/AREAE006.EMI: 000fa464
BIN/WORLD/AREAE013.EMI: 000fa464
BIN/WORLD/AREAE014.EMI: 000fa464
BIN/WORLD/AREAE019.EMI: 000fec64
BIN/WORLD/AREAE021.EMI: 000fec64
BIN/WORLD/AREAE022.EMI: 00100464
BIN/WORLD/AREAE041.EMI: 000fbc64
BIN/WORLD/AREAE049.EMI: 000f9c64

Which brings me to hopefully my last question (before I start testing), what's a good way to get these changes back into the ISO?  I've written a small program to apply all the changes across all the files that contain this (and other) data, but other than inserting them one by one using cdmage, is there some other option?  I was thinking of rebuilding the iso, but I'd like to make as few changes to the original file as possible, to hopefully optimize the patch size.
Title: Re: [Technical] [PSX] Breath of Fire IV Controller Layout Text
Post by: navarchos on January 13, 2022, 06:42:06 pm
If you want to automate using a command-line based tool, you can try PSX-Mode2 (https://www.romhacking.net/utilities/848/). It doesn't change file size when reinserting files with no size changes.
Title: Re: [Technical] [PSX] Breath of Fire IV Controller Layout Text
Post by: gukid/ioev on January 13, 2022, 11:02:45 pm
This worked beautifully, thank you again!

Edit: I also figured out the bug on the name entry screen where the "forward" functionality didn't work after remapping the controls.  Turns out it's hardcoded in an instruction: 0x0020 in us, 0x0010 in jp.  Changing this one byte fixed it.  Time to test!

Edit: Of course I run into trouble right away!  The map has a small menu on it that seems to use some hardcoded inputs just like the name input screen.  Also uses images for the text labels which is making it hard to find the data for the button labels.

I'm curious about this VRAM debugger in no$psx, but when I run Bof4 it plays the audio of the intro movie without video, none of the buttons respond and the it never loads beyond the end of the video.  I'm assuming it works fine for you?
Title: Re: [Technical] [PSX] Breath of Fire IV Controller Layout Text
Post by: navarchos on January 15, 2022, 05:50:04 am
Getting BoFIV to work on NO$PSX is finicky. You can use an earlier version (IIRC from my tests, anything below v1.8 works), or make a savestate from an earlier version, and load it in the most recent version.

I found the labels on the map inside AREAE005.EMI.
Title: Re: [Technical] [PSX] Breath of Fire IV Controller Layout Text
Post by: gukid/ioev on January 15, 2022, 12:37:54 pm
I knew I wasn't crazy thinking that this worked at one point!  I must have started on an older version and upgraded at some point.

I found the graphics for the map menu in the vram debugger, and it looks like it's image based.  I'm not at all familiar with extracting/replacing images so this will be a bit of a challenge.
Title: Re: [Technical] [PSX] Breath of Fire IV Controller Layout Text
Post by: navarchos on January 15, 2022, 05:30:53 pm
Using CrystalTile2 (https://www.romhacking.net/utilities/818/), you can edit the graphics using an external tool, and then reinsert it.


If you double click a tile, it enters CrystalTile's own tile editor. To return to the tile viewer, just press F5 again.
Title: Re: [Technical] [PSX] Breath of Fire IV Controller Layout Text
Post by: gukid/ioev on January 15, 2022, 08:10:06 pm
This is super useful, thank you!  I had checked out CrystalTile2, but didn't realize the tile editor was under a different menu... hah...

I ended up doing this work using an application called TileShop.  The workflow had a few more steps, but it very nicely let me set up the us file on one side and the japanese on the other, and I could just drag and drop the icons from one side to the other.

So the display is correct, but now I need to fix the constants in the code again, which shouldn't be too difficult.  I'm also guessing these graphics will be found in some other files so I'll need to find and replace those as well.

Making steady progress!
Title: Re: [Technical] [PSX] Breath of Fire IV Controller Layout Text
Post by: navarchos on January 16, 2022, 01:25:55 am
There seems to be a piece of dialogue that uses a placeholder code for the action button. Specifically, it's the help dialogue that shows up when you do the jar-clearing minigame in wharf. So far I haven't found another dialogue which uses this placeholder. I think this might be handled automatically by the game, so there's no need to change that.
Title: Re: [Technical] [PSX] Breath of Fire IV Controller Layout Text
Post by: gukid/ioev on January 16, 2022, 11:17:16 am
Yeah, I figure I'm going to be finding little bits of hard coded button assignments all throughout the game.  Thankfully I'm getting a little better at finding where they are.

January 19, 2022, 10:54:47 pm - (Auto Merged - Double Posts are not allowed before 7 days.)
I must have jinxed myself, as I'm having a really hard time finding the fishing menu graphics.  How were you able to figure out that the map menu graphics were in AREAE005.EMI?  I've done some digging (fishing?) in the ram during the fishing scenes, and it seems only AREAE003.EMI and the main executable are loaded, but I don't see the graphics I need in either of those files.  I've also tried to brute force loading many files, but it's quite exhausting having to set the bit depth and size every time.
Title: Re: [Technical] [PSX] Breath of Fire IV Controller Layout Text
Post by: navarchos on January 20, 2022, 05:10:10 pm
I found the graphics in AREA003.EMI and AREAD075.EMI:
(https://media.discordapp.net/attachments/712288823614111784/933844544905154580/unknown.png)
I used 128x32 tiles, 4bpp.
The offsets are, 0xa8800 in AREAD075, and, 0xa6000 in AREAE005. I didn't find any other redundant copies.
I assume you were looking for fishing-related texts in the AREA files? That should work, since graphics and texts in the same area are stored together, sometimes redundantly (such as in this case).

I text dumped the entire contents of the /WORLD folder a while ago. As it is right now, it's not yet organized, and I need to tag the redundant files as well. I could send you a copy of the dump if you want.
Title: Re: [Technical] [PSX] Breath of Fire IV Controller Layout Text
Post by: gukid/ioev on January 20, 2022, 05:30:05 pm
Thank you again!  At first I was looking for fishing related strings, but they seemed to be in quite a few of the files, and I wasn't able to find graphics in them.  It never occurred to me to try different bit depths and sizes!

I was also a little worried about duplicate graphic assets across EMI files.  I guess as long as I can determine the starting offset, I should be able to figure out which "piece" of the emi the graphic makes up, and then can search for that binary string in other files.  I'm probably going to use the same approach for patching multiple files at the same time.  I was actually trying to determine a way of searching for the X button binary graphic somehow, but I don't think that's really possible.

If you'd like to share your text dump with me I'd be glad to accept it.  I'll take any help I can get :)

Edit: Made the changes as before, but it seems it's using a different palette as well, so the buttons show up as the wrong colors.  Will poke around and see if I can find the format of the palette in this file as well.

Edit2: Found a few changed bytes at the top of this section in the file, changed them back to the JP version and we're in business!

The changed palette was a bit of a mixed blessing, searching for what should be all the instances of the fishing graphics I need to modify:

Code: [Select]
BIN/WORLD/AREAD075.EMI: 000a1146
BIN/WORLD/AREAE000.EMI: 0009e946
BIN/WORLD/AREAE003.EMI: 0009e946
BIN/WORLD/AREAE004.EMI: 0009e946
BIN/WORLD/AREAE006.EMI: 0009f146
BIN/WORLD/AREAE013.EMI: 0009f146
BIN/WORLD/AREAE014.EMI: 0009f146
BIN/WORLD/AREAE019.EMI: 000a3146
BIN/WORLD/AREAE021.EMI: 000a3146
BIN/WORLD/AREAE022.EMI: 000a4946
BIN/WORLD/AREAE041.EMI: 000a1146
BIN/WORLD/AREAE049.EMI: 0009f146
Title: Re: [Technical] [PSX] Breath of Fire IV Controller Layout Text
Post by: navarchos on January 20, 2022, 06:35:33 pm
Here (https://www.dropbox.com/s/5uwb11lr5f70txr/scriptdump.zip?dl=1) is the dump.

I was also confused initially since the map menus use 8bpp, while the fishing menu uses 4bpp. As far as I know, the game only uses 8bpp and 4bpp for textures.
Title: Re: [Technical] [PSX] Breath of Fire IV Controller Layout Text
Post by: gukid/ioev on January 24, 2022, 05:51:52 pm
(Edit: turns out what I thought was a missing feature is there, it's just not documented in the help text.)

Finding some strings referring to copying skills into "skill scrolls".  I haven't played the game in a while, but I don't remember anything like this?  It would have used the square button somewhere in camp menu.
Title: Re: [Technical] [PSX] Breath of Fire IV Controller Layout Text
Post by: navarchos on January 24, 2022, 06:29:10 pm
The toggle to change HP&AP/Stats is mapped to the circle button in the subscreen (layout 1)
Skill copying is a part of the game's skill mechanic. You can learn skills from enemies by guarding when that enemy uses the skill, or from masters. Learned skills are displayed on the skill list
Title: Re: [Technical] [PSX] Breath of Fire IV Controller Layout Text
Post by: gukid/ioev on January 24, 2022, 09:47:32 pm
I remember that part, I just don't remember this thing about skill scrolls.  Guess I'll probably get to it while I'm testing.

Also finding references to some mini-game where you have to push "Iggy" off a mast, that I don't remember at all :)
Title: Re: [Technical] [PSX] Breath of Fire IV Controller Layout Text
Post by: navarchos on January 24, 2022, 10:33:15 pm
Ah, what I meant to say was that skill scroll = skill list in the camp. If you no longer want to use a skill, that skill is "returned" to the skill list
Title: Re: [Technical] [PSX] Breath of Fire IV Controller Layout Text
Post by: gukid/ioev on January 25, 2022, 01:46:35 pm
Then this must all be some unused feature?  The text is in CAMP.EMI (there's some other control codes in there):

[Triangle button] Copy skill to Skill Scroll Copy to Skill Scroll? Not enough space. Return skill to Skill Scroll and take ? Return skill to Skill Scroll and take?
Title: Re: [Technical] [PSX] Breath of Fire IV Controller Layout Text
Post by: navarchos on January 25, 2022, 05:16:18 pm
"Copy skill to skill scroll" is used when a master teaches you a skill
"Not enough space. Return skill to Skill Scroll and take ? Return skill to Skill Scroll and take?" is used when a character has too many skills and wants to take that skill from the master
(https://media.discordapp.net/attachments/712288823614111784/935658935476695081/unknown.png)
(https://media.discordapp.net/attachments/712288823614111784/935658858020491334/unknown.png)

These two string are also present in MASTER.EMI, which I think is what the game actually uses when displaying these texts.
Title: Re: [Technical] [PSX] Breath of Fire IV Controller Layout Text
Post by: gukid/ioev on January 28, 2022, 10:32:10 am
Oh perfect, thanks for digging this up!  I guess I would have eventually found it in my testing (Haven't had much time to play yet.)  I'm guessing this one should just stay at Square, but I'll dig around in the Japanese text tonight and see what it was mapped to in that version.
Title: Re: [Technical] [PSX] Breath of Fire IV Controller Layout Text
Post by: gukid/ioev on April 03, 2022, 11:00:30 pm
So I've run into another wall that I can't quite figure out, which is the X button prompt to skip a summon/spell, O in the Japanese version.  I've already changed the button constant, so pressing O now skips, but I can't for the life of me figure out how it's drawing the X button.  As far as I can tell, it's using a regular textbox (I've found the "Pass" text and the X button in vram) but it doesn't seem to be using the same codes as other textboxes.  When I had made changes to the button layout on the settings screen, there is a string being referenced that is only the X button string code (050a150106) which is then positioned on the screen, and I've located this string in memory at the time the Pass prompt is being displayed, but it's not being read.

I've mapped out lots of the memory around the battle system, as to how the windows and prompts are positioned, but it seems the Pass prompt is no where near this stuff by the time it displays on screen.

This is the location of all of the X button constants that I've already changed (1st is address, 2nd is value of the result).  I'm guessing the code for displaying the prompt could be around the same place?  Since the prompt only shows up on the 2+ time you use the spell/summon, I figured they would share some logic around when to enable reading the button press, and displaying the box, but I haven't had much luck finding the button icon mapping with this either.

Code: [Select]
./extracted/BIN/BATTLE/BTLMOVE.EMI: 0000B174: 4000423008004010
./extracted/BIN/BATTLE/BTLMOVE.EMI: 0000B1F4: 4000423008004010
./extracted/BIN/BMAGIC/MAGIC060.EMI: 00015A5C: 4000423008004010
./extracted/BIN/BMAGIC/MAGIC061.EMI: 0001423C: 4000423008004010
./extracted/BIN/BMAGIC/MAGIC062.EMI: 000151E8: 4000423008004010
./extracted/BIN/BMAGIC/MAGIC063.EMI: 00000A80: 4000423008004010
./extracted/BIN/BMAGIC/MAGIC064.EMI: 000009F0: 4000423008004010
./extracted/BIN/BMAGIC/MAGIC065.EMI: 00014188: 4000423008004010
./extracted/BIN/BMAGIC/MAGIC066.EMI: 000149D4: 4000423008004010
./extracted/BIN/BMAGIC/MAGIC067.EMI: 000159F0: 4000423008004010
./extracted/BIN/BMAGIC/MAGIC068.EMI: 000149C8: 4000423008004010
./extracted/BIN/BMAGIC/MAGIC069.EMI: 000151C0: 4000423008004010
./extracted/BIN/BMAGIC/MAGIC070.EMI: 00011A80: 4000423008004010
./extracted/BIN/BMAGIC/MAGIC071.EMI: 0001521C: 4000423008004010
./extracted/BIN/BMAGIC/MAGIC072.EMI: 0000B260: 4000423008004010
./extracted/BIN/BMAGIC/MAGIC073.EMI: 00013998: 4000423008004010
./extracted/BIN/BMAGIC/MAGIC074.EMI: 0001598C: 4000423008004010
./extracted/BIN/BMAGIC/MAGIC075.EMI: 00010230: 4000423008004010
Title: Re: [Technical] [PSX] Breath of Fire IV Controller Layout Text
Post by: navarchos on April 04, 2022, 12:55:48 am
GPU instructions which draw the (X) button:
Code: [Select]
64808080   Color+Command     (CcBbGgRrh)
00CC011A   Vertex            (YyyyXxxxh)
3C0AB8B4   Texcoord+Palette  (ClutYyXxh)
000C000C   Width+Height      (YsizXsizh)
From CPU trace we get:
Code: [Select]
801ec010 acc30004: sw     $v1(64808080), 0x0004(a2)([80024150] = 2c808080) # Color+Command     (CcBbGgRrh)
801ec020 acc8000c: sw     $t0(3c0ab8b4), 0x000c(a2)([80024158] = 7d40a0c0) # Texcoord+Palette  (ClutYyXxh)
801ec040 acc20008: sw     $v0(00cc011a), 0x0008(a2)([80024154] = 00000100) # Vertex            (YyyyXxxxh)
801ec024 acc70010: sw     $a3(000c000c), 0x0010(a2)([8002415c] = 00000120) # Width+Height      (YsizXsizh)
Since we're dealing the texture let's check the texcoord

Code: [Select]
801ebff0 3c083c0a: lui    $t0(80110000), 0x3c0a
801ebff4 3508b8b4: ori    $t0(3c0a0000), 0xb8b4
...
801ec020 acc8000c: sw     $t0(3c0ab8b4), 0x000c(a2)([80024158] = 7d40a0c0) # Texcoord+Palette  (ClutYyXxh)
Searching for the first two instructions in the game files yields:
Code: [Select]
BIN/BMAGIC/MAGIC060.EMI: 00019ba0
BIN/BMAGIC/MAGIC061.EMI: 00019a70
BIN/BMAGIC/MAGIC062.EMI: 0001a63c
BIN/BMAGIC/MAGIC063.EMI: 00006d74
BIN/BMAGIC/MAGIC064.EMI: 000034bc
BIN/BMAGIC/MAGIC065.EMI: 00018228
BIN/BMAGIC/MAGIC066.EMI: 00019ff0
BIN/BMAGIC/MAGIC067.EMI: 0001b5c4
BIN/BMAGIC/MAGIC068.EMI: 00019724
BIN/BMAGIC/MAGIC069.EMI: 00019a54
BIN/BMAGIC/MAGIC070.EMI: 0001834c
BIN/BMAGIC/MAGIC071.EMI: 0001c860
BIN/BMAGIC/MAGIC072.EMI: 0000fd24
BIN/BMAGIC/MAGIC073.EMI: 00017610
BIN/BMAGIC/MAGIC074.EMI: 000197a4
BIN/BMAGIC/MAGIC075.EMI: 00016da0
To change this to another button, you'll need to change the x value, which is assigned by this instruction
Code: [Select]
801ebff4 3508b8b4: ori    $t0(3c0a0000), 0xb8b4
Change this to 3508b8a8 (or a8b80835 in little-endian) if you want a circle to appear

It doesn't appear to be text at all. Hope that helps
Title: Re: [Technical] [PSX] Breath of Fire IV Controller Layout Text
Post by: gukid/ioev on April 04, 2022, 10:20:23 am
Thank you again!  I just checked out the operands for those instructions in the Japanese files, and it is in fact A8 for O, B4 for X.

Actually, one of many the things I was thinking of trying (basically brute force) was to figure out the difference between the X coords of the X/O buttons (12) and then run a diff on one of these files looking for changes of that amount.   I didn't end up doing this though because there were more changes than I expected, but I guess if I had kept with it I may have gotten lucky?

And thank you for your detailed notes!  I know very little about the Playstation hardware and instruction set so this will be really useful in trying to find other cases like this one.  Can I ask how you went about doing the CPU trace?  Normally I just poke around in the assembly while the game is running, but it sounds like running a dump might be a better way of looking at the data.

Also, in your trace, I can se it's saving these GPU instructions to 80024150-8002415c, are these memory addresses mapped to the gpu?  I tried putting a write breakpoint on 80024158, but it only seems to trigger at one point where it appears to be initializing the instruction to 3c01b8b4.

Edit: Also also just made all the changes and things are working perfectly!
Title: Re: [Technical] [PSX] Breath of Fire IV Controller Layout Text
Post by: navarchos on April 04, 2022, 06:33:42 pm
In PCSX-Redux, you can turn on the CPU tracer by going to Debug > Show Assembly, and checking the "CPU Trace" option, which will start tracing the CPU until you stop the game, or the emulator crashes. You'll need to set a breakpoint or else the emulator will continue tracing until it's out of memory. If you're not sure what breakpoint to use, you can just use Debug > Breakpoint on Vsync.

you probably want to make sure this option is off when you open the emulator next time. a mistake I learned the hard way too many times

80024xxx - ??? is a memory region related to the GPU. Putting a write breakpoint there is almost useless, because the data there changes too frequently.
Title: Re: [Technical] [PSX] Breath of Fire IV Controller Layout Text
Post by: gukid/ioev on April 04, 2022, 09:26:59 pm
80024xxx - ??? is a memory region related to the GPU. Putting a write breakpoint there is almost useless, because the data there changes too frequently.

That makes sense. It's probably writing there on every quad/triangle in the scene so would hit it possibly hundreds (thousands?) of times per frame, so finding the one time that it was writing the data I want would take forever.  In my mind I thought maybe I could watch it draw each piece and try to record the data of right before it draws parts of the Pass prompt.

Thanks again for your help!
Title: Re: [Technical] [PSX] Breath of Fire IV Controller Layout Text
Post by: navarchos on April 04, 2022, 10:22:00 pm
Yeah, it's much more difficult to pinpoint how a moving object is being drawn. As for the (X) button, it doesn't move at all, so the instructions that correspond to it in the memory don't change (until it goes away), and it's fairly easy to locate it.
First, I used NO$PSX's GPU debugger to get the GPU instructions which draw the button. Then, I made a savestate in PCSX-Redux when the button appears. Using a hex editor, I searched for the GPU instructions in the savestate. Once I found it, I calculated the corresponding location in the emulator's RAM. I turned on CPU trace and Breakpoint on Vsync. I advanced frame by frame, while the CPU trace captures the CPU instructions. I remove the trace log if the screen doesn't display the button, and I stop when the button appears. I copy the CPU trace to a text editor and then I searched for instructions that modify the RAM address. Someday I'll explain my full workflow in a document.


Oh, and I forgot to mention that the CPU traces appear in the log window.