This page is a mirror of Tepples' nesdev forum mirror (URL TBD).
Last updated on Oct-18-2019 Download

Change the text appearance direction to Right-to-Left?

Change the text appearance direction to Right-to-Left?
by on (#127915)
Hi
I want to translate "Captain Tsubasa Vol. II - Super Striker (J) [!].nes" from Japanese to Persian
But there is a problem
Japanese is written from Left-to-Right but Persian is written from Right-to-Left
So for the fist step I have to change the text direction which appears from Left-to-Right to Right-to-Left
I made some progress already :

I go to a page that the text appears gradually from Left-to-Right.
Then I hit the Pause button and then Debug --> Name Table Viewer
By pointing the first character of the sentence I found some nice info : Tile ID : #$4B / PPU address : $2269
Debug --> Debugger --> add --> address : 2269 / Write / PPU Mem --> OK

Then I restart the game and Debug --> Trace Logger --> Start Logging

Then I found this :
LDA $05EB,X @ $05EC A:00 X:01 Y:01
STA $2007 A:4B X:01 Y:01

So 4B (hex value of the character) is coming from $05EC
I set a write break point for $05EC and I found this :
LDA ($4D),Y @ $A2AD A:A2 X:05 Y:00
.
PHA A:4B X:22 Y:49
.
PLA A:82 X:03 Y:49 S:4D
.
STA $05E9,X @ $05EC A:4B X:03 Y:49

So 4B is coming from $A2AD
Debug --> Hex Editor --> File --> Go Address --> A2AD --> Right Click --> Go Here In Rom File --> $62BD

I change the 4B to 4C to see if the first character changes, and yes that's it!

************************************

Then I set a Read break point for $A2AD, well nothing new I found this already :
LDA ($4D),Y @ $A2AD

Then a write break point for $2006 :

LDA $05EA,X @ $05EA A:02 X:00 Y:02
STA $2006 A:22 X:00 Y:02
LDA $05E9,X @ $05E9 A:22 X:00 Y:02
STA $2006 A:49 X:00 Y:02

$2249 is the PPU address and goes high on showing up every character, so I have to trace $05E9 and #$49
I set a write break point for $05E9 and I found this :
LDY $0053 A:4C X:22 Y:00
.
TYA A:22 X:00 Y:49
STA $05E9,X @ $05E9 A:49 X:00 Y:49

This shows that #$49 is coming from $0053
So I set a write break point for $0053 :
LDA $0051 A:22 X:03 Y:00
STA $0053 A:49 X:03 Y:00

Another write break point for $0051 :
LDA $004F A:22 X:03 Y:00
STA $0051 A:49 X:03 Y:00

Another write break point for $004F :
$84CF:A9 49 LDA #$49 A:08 X:03 Y:00
$84D1:85 4F STA $004F = #$49 A:49 X:03 Y:00

Debug --> Hex Editor --> File --> Go Address --> 84CF --> Right Click --> Go Here In Rom File --> $04E0

I change #$49 to #$5C and I expect the sentence appears from somewhere near to the right edge of the screen, Yes that's it!

************************************

As I found before the PPU address goes high on showing up every character so I have to change something to make it go down
I look at ram address while the text appears and I found that $0053 goes high as the text appears so I set a write break point for $0053 :
$84F6:E6 53 INC $0053 A:82 X:05 Y:59

Debug --> Hex Editor --> File --> Go Address --> 84F6 --> Right Click --> Go Here In Rom File --> $0506
So I have to change E6 (INC) to C6 (DEC)
YES it worked! The text appears from Right-to-Left!

************************************

OK it is good so far!
But what is the problem now?
When the page changes the old text won't disappear!
But the new text appears just fine while overwriting the old text!
I seems after the first page, the game tries to clears the original place of the text on the left alignment of the screen.
Should I check for $2007 / $2006 / $2249 (Original PPU address of the) for anything like 00 or FF on them?
Any help would be appreciated.
Re: Change the text appearance direction to Right-to-Left?
by on (#127975)
I would load up a previous version of the ROM before you reversed the direction, and check out any writes to $2006 just before a text-clear to see where it is trying to write the tiles that "erase" the text (the tile ID might not necessarily be #$00 or #$FF, you'll have to figure that out on your own. Check the name table viewer to be sure.) Compare that to the same point in your altered ROM and see if any of the changes you had made affected the text-clear routine. It could have to do with your switch from INC to DEC. I don't have the ROM in front of me, so I'm just guessing, but that's where I would start looking.
Re: Change the text appearance direction to Right-to-Left?
by on (#128002)
Thanks for the answer.
I found out something :
It seems the text clear routine is bind to the PPU address of the first character
I followed the text clear routine and I reach to $04E0

I guess this is how the clear text routine works (X means clear) :
Left Alignment (Normal) :
| ABC.................. |
| XXX.................. |

Right Alignment (Hack) :
| ...............ABC... |
| ...............XXX... |

Inversion (Hack) :
| ..........CBA....... |
| ..............XXX... |

After inverting the text direction the clear routine starts from A and tries to clear forward which is already blank!
The clear routine writes 00 to 2007 in a loop, it uses the fact that PPU address goes high automatically

Any idea how to fix it?
Re: Change the text appearance direction to Right-to-Left?
by on (#128009)
Finally I had to cheat : :mrgreen:
There is an Arabic translation of this game and it has the Text Direction hack so I compared it with the Original one :

From Original (Captain Tsubasa Vol. II - Super Striker (J) [!].nes)

Code:
$88B1:A5 54     LDA $0054 = #$09           A:80 X:F8 Y:22 S:4E P:NvUbdizc
$88B3:49 FF     EOR #$FF                   A:09 X:F8 Y:22 S:4E P:nvUbdizc
$88B5:18        CLC                        A:F6 X:F8 Y:22 S:4E P:NvUbdizc
$88B6:69 1F     ADC #$1F                   A:F6 X:F8 Y:22 S:4E P:NvUbdizc
$88B8:AA        TAX                        A:15 X:F8 Y:22 S:4E P:nvUbdizC
$88B9:A0 08     LDY #$08                   A:15 X:15 Y:22 S:4E P:nvUbdizC
$88BB:A5 4F     LDA $004F = #$49           A:15 X:15 Y:08 S:4E P:nvUbdizC
$88BD:29 E0     AND #$E0                   A:49 X:15 Y:08 S:4E P:nvUbdizC
$88BF:05 54     ORA $0054 = #$09           A:40 X:15 Y:08 S:4E P:nvUbdizC
$88C1:85 E6     STA $00E6 = #$10           A:49 X:15 Y:08 S:4E P:nvUbdizC


From Arabic Translation (Captain Tsubasa Vol. II - Super Striker (Ar) [Extraordinary].nes)

Code:
$88B1:A5 54     LDA $0054 = #$1B           A:80 X:F8 Y:09 S:4E P:NvUbdizc
$88B3:38        SEC                        A:1B X:F8 Y:09 S:4E P:nvUbdizc
$88B4:E9 05     SBC #$05                   A:1B X:F8 Y:09 S:4E P:nvUbdizC
$88B6:AA        TAX                        A:16 X:F8 Y:09 S:4E P:nvUbdizC
$88B7:A0 08     LDY #$08                   A:16 X:16 Y:09 S:4E P:nvUbdizC
$88B9:A5 4F     LDA $004F = #$5B           A:16 X:16 Y:08 S:4E P:nvUbdizC
$88BB:38        SEC                        A:5B X:16 Y:08 S:4E P:nvUbdizC
$88BC:E5 54     SBC $0054 = #$1B           A:5B X:16 Y:08 S:4E P:nvUbdizC
$88BE:18        CLC                        A:40 X:16 Y:08 S:4E P:nvUbdizC
$88BF:69 06     ADC #$06                   A:40 X:16 Y:08 S:4E P:nvUbdizc
$88C1:85 E6     STA $00E6 = #$10           A:46 X:16 Y:08 S:4E P:nvUbdizc


It works fine for me, but I can't understand how it really works, so can anyone explain it for me?
Re: Change the text appearance direction to Right-to-Left?
by on (#128024)
Does this pseudocode help?

Code:
 
; first version:

foo = $54  ( holds 9)
bar = $4F  ( holds $49)
baz = $E6  ( holds $10, after this holds $49)

x := 30 - foo
y := 8
baz := bar & %11100000 | foo

; second version:

foo = $54  ( holds $1B)
bar = $4F  ( holds $5B)
baz = $E6  ( holds $10, after this holds $46)


x := foo - 5
y := 8
baz := bar - foo + 6