News: 11 March 2016 - Forum Rules
Current Moderators - DarkSol, KingMike, MathOnNapkins, Azkadellia, Danke

Author Topic: Understanding NES text routines  (Read 4528 times)

Pennywise

  • Hero Member
  • *****
  • Posts: 2250
  • I'm curious
    • View Profile
    • Yojimbo's Translations
Re: Understanding NES text routines
« Reply #20 on: February 22, 2019, 04:21:02 pm »
Who can say at this point. Best of luck to you.

AFAIK, there is no tutorial on how to use cartographer, Atlas etc. You can either learn how to use them or learn a high level language and code your own utilities to handle everything. If you're gonna be doing NES hacking, the former option will suffice as 95% of the games will work with those tools. They're designed to be generic and flexible and all you have to do is make a batch file to execute them.

For cartographer, just use the example included in the archive to rip the script for practice. Then adapt the command file to the game you're working on.

Gyroballer

  • Jr. Member
  • **
  • Posts: 26
    • View Profile
Re: Understanding NES text routines
« Reply #21 on: February 22, 2019, 04:47:33 pm »
Who can say at this point. Best of luck to you.

AFAIK, there is no tutorial on how to use cartographer, Atlas etc. You can either learn how to use them or learn a high level language and code your own utilities to handle everything. If you're gonna be doing NES hacking, the former option will suffice as 95% of the games will work with those tools. They're designed to be generic and flexible and all you have to do is make a batch file to execute them.

For cartographer, just use the example included in the archive to rip the script for practice. Then adapt the command file to the game you're working on.

I was able to dump scripts with Cartographer, but was a bit confused with the pointer part and a bit scared to ruin things, but I think I'll just have to give it the college try. I'd probably rather use their tools than try to make something in C# for an individual game.

I definitely appreciate all the advice.

KingMike

  • Forum Moderator
  • Hero Member
  • *****
  • Posts: 6906
  • *sigh* A changed avatar. Big deal.
    • View Profile
Re: Understanding NES text routines
« Reply #22 on: February 22, 2019, 08:21:44 pm »
Okay, I was using the game from that tutorial because it wasn't clear that you had moved on to DB3 - the two games aren't going to do things exactly the same.
I only noticed from the file name at the bottom of the screenshots. :)
"My watch says 30 chickens" Google, 2018

Psyklax

  • Hero Member
  • *****
  • Posts: 1056
    • View Profile
    • Psyklax Translations
Re: Understanding NES text routines
« Reply #23 on: February 23, 2019, 03:31:48 am »
Now, I wouldn't necessarily recommend the way I do script dumping/insertion - it works for me, but I know it's a bit convoluted. I'll briefly explain what I do.

I use a program simply called Pointer Tables:
http://www.romhacking.net/utilities/502/

What I like about it is that it's very simple to use and completely adaptable to any system. You input where the pointer table in the ROM is, where the text is, and use a suitably formatted table file (Japanese must be in UTF8), and it does a simple dump, which you can then edit and insert. With a bit of fiddling, it can work with anything.

I use TextPad for all my text editing needs, but the one thing PT doesn't do is change the pointers in the ROM after inserting text, so you have to do that manually. You could write down the address of every string manually, but that takes time, so I use a simple Python script that my Dad wrote for me which gives the location of every particular byte (such as FF to signify the end of a string, for example). I can then take that list of addresses, use OpenOffice Calc to add 1 to each of them, and put the result back in the ROM. As I said, not everyone is going to be able to use my method, but for me, it works. :)

One bit of advice, especially when using Pointer Tables: make backups! I use Dropbox for my hacking folder, and make a new file every time I do something significant like inserting text with PT. Of course, I'm not stupid enough to share files directly from my Dropbox account with everyone - gotta keep that stuff private. ;) But given that hacking 8- and 16-bit games means tiny filesizes, there's no good reason not to use Dropbox.

Well, I hope this gives you a little inspiration, for what it's worth. Just remember: if you want to be good at hacking, you have to enjoy the process, not just the result. :D

Pennywise

  • Hero Member
  • *****
  • Posts: 2250
  • I'm curious
    • View Profile
    • Yojimbo's Translations
Re: Understanding NES text routines
« Reply #24 on: February 23, 2019, 06:41:35 pm »
Well, if you're concerned about the pointer part. All you're really doing is specifying the pointer table start/end locations and updating the ROM offset to match CPU offsets.

The CPU memory map for the NES reserves $8000-FFFF for loading/storing ROM banks from the PRG-ROM. Games will switch ROM banks in/out as needed. If you have text that's at $15000 in the ROM and the pointer is $9000, it's not pointing to a ROM offset per se, it's pointing to an offset in the CPU memory map. You need to add x bytes so that the offsets match up.

Gyroballer

  • Jr. Member
  • **
  • Posts: 26
    • View Profile
Re: Understanding NES text routines
« Reply #25 on: February 26, 2019, 05:58:16 pm »


I can not for the life of me locate the items in this game. I've seen some stuff in RAM that may indicate addresses for them, but then I go there and only see the "helper cards" nearby with names that I've translated so far. Which kinda makes sense since the items and help cards are really similar. But the hex values or the text-equivalents only seem to be found in the dialogue (like finding ドラゴンレーダー being said by Goku or Bulma for instance).
 
The closest I've gotten is some sort of list that seemed like the items, but I think it might be referenced when you get the items, which would explain why DragonRadar isn't present and why none of them seem translated after changing the values.

However, I feel like it's weird that I can't find even 1 value even though I've successfully located helper cards.



I've tried tracing the text and didn't understand what was going on or where it may have been referencing.

---
EDIT: I checked the ROM, RAM, and PPU. Maybe because things are stored in CHR, it seems like the RAM and PPU's roles are reversed from what I'm used to. I see 4 copies of the latest text written in the RAM. But even with that, it's like the item text never seems to be written and I can't find where it's coming from.
I also tried variations on the hex searches (like using +-80 or +-40, so for 39, the ー ㏌ レーダー, I checked f9, 79, and b9 as well, looking for like B9 ?? B9 or like 39 ?? 39 -- ダ is CF, and I tried variations mixing CF, as well, and assuming the one without handakuten, タ at 4F but 39 CF 39 showed nothing after I translated all the dialogue references of the radar).

I've also tried blindly looking for sandwiched values (not necessarily just with x9) in locations in RAM close to where text is written and in the ROM and PPU and have had little luck. Looking up pairs of characters like レー and ダー also seemed fruitless.

EDIT2: Similar screens to these, like the stats page, etc. are just completely written like a whole screen in the ROM, interestingly:


Assuming that maybe it was around the "Items" part, I tried editing things there and only crashed the game, so I was likely editing code or important pointers.
I also tried looking for sections like (B7 01 01 01 B7) because if it's written directly to the ROM like the stat page, then it also writes dakuten/handakuten characters (B8/B7), so I could use my alternate table for those sections and seek out spaced handakuten marks like my cavespeak dragon radar, but I had zero luck.

EDIT3: I should note that the Name Table can't understand tiles being written there. It just shows "03", which is the background color, or nothing written there, basically.

Code data logger from the moment I press the Item menu to the moment the item list pops up (instantly, not 1 letter at a time like the item descriptions), it's like 3-4 frames. There's a lot of stuff from CHR ROM displayed that doesn't resemble the text. It's really confusing.
---

Side note: I know I'm gonna need DTE (probably for like "Go", "nin", "ro", etc.) since most of the enemy names took like 4 characters in Japanese but are represented with double that amount in English. Only really something like Murasaki was able to be shortened (since his game name is hilariously ムラサキそうちょうじょうにん, which seems to mean something like Master Sergeant Jounin [like master ninja from Naruto] Murasaki -- 14 characters fitting means I should be able to name them whatever if it'll fit).
« Last Edit: February 26, 2019, 09:16:11 pm by Gyroballer »

Pennywise

  • Hero Member
  • *****
  • Posts: 2250
  • I'm curious
    • View Profile
    • Yojimbo's Translations
Re: Understanding NES text routines
« Reply #26 on: February 26, 2019, 10:49:49 pm »
Probably sprites.

Gyroballer

  • Jr. Member
  • **
  • Posts: 26
    • View Profile
Re: Understanding NES text routines
« Reply #27 on: February 27, 2019, 03:19:06 am »
It may very well be sprites, but I couldn't find them using YY-CHR, TLP, TM, etc. or with using YY-CHR's 8x16 mode or switching around where each letter landed.

It definitely loads all of the items at once, but for instance it knows what order it will be in since normally the DR is the first thing you get, but it's 4th on my list, below food, etc. even though it'd be first when you first load the game and don't have food.

Here's three frames in order:







So on the first frame that the screen can possibly be displayed, before any text is written describing the first item, all the items are shown.



EDIT:
Example of 80 tbl that shows where similar windows are:



Example of typical 00 tbl that shows some names of helper cards and some techniques (both selected from windows like the items):
« Last Edit: February 27, 2019, 03:26:05 am by Gyroballer »

Psyklax

  • Hero Member
  • *****
  • Posts: 1056
    • View Profile
    • Psyklax Translations
Re: Understanding NES text routines
« Reply #28 on: February 27, 2019, 08:45:50 am »
I'd try to look at it myself, but I've no idea how to see these items in the game, since I've no idea how the game works. Could you give either a simple explanation of how to see that list in your screenshot, or provide a save state? Then I'll get to work. 8)

Gyroballer

  • Jr. Member
  • **
  • Posts: 26
    • View Profile
Re: Understanding NES text routines
« Reply #29 on: February 27, 2019, 12:37:09 pm »
I'd try to look at it myself, but I've no idea how to see these items in the game, since I've no idea how the game works. Could you give either a simple explanation of how to see that list in your screenshot, or provide a save state? Then I'll get to work. 8)

Closest thing to simplest explanation is "Game Start", press Select for menu, choose Card/s -> Item Cards, and the item list pops up instantly, whereas textual descriptions of the items up top are written character by character, looking from strings in the CHR.

Zip called psyklax022719.zip and contains savestate near end-game with some items, and also contains very early translation ips with savestate that corresponds to the Japanese one:

https://mega.nz/#!hclCRAKa!0Zz-aGz-G9e9CwZUBpzjL_eInn5E2aICIhrUvZs1_7s

Thanks so much for looking into this. I really have tried to bang my head for the better part of a week on just this part. There are other annoying things that I'll need to figure out, like learning to use DTE for the first time and learning where the particles during battle come from (like Goku "の" critical hit or Enemy "は" took ## damage), but seeing abbreviations or errant characters isn't as bad as lack of item translations at the current state.

Of course, I'll need to figure out the pointers or whatever they're doing to display numbers on the screen, too, because I have to work around the numbers and leave blank spaces in my strings at present.

Edit/Sidenote: I found out that the item names I was translating are at least used when you can choose items in between Tenkaichi Budoukai matches during events, but possibly also when you earn the items.
« Last Edit: February 27, 2019, 01:24:41 pm by Gyroballer »

Psyklax

  • Hero Member
  • *****
  • Posts: 1056
    • View Profile
    • Psyklax Translations
Re: Understanding NES text routines
« Reply #30 on: February 27, 2019, 04:42:49 pm »
Well, thanks for the info on how to see the items. I've found them - but their location is pretty weird. :D

It didn't take long at all, actually. I knew they weren't sprites because FCEUX showed them in the name table. I knew the one item at the start (Dragon Raider?) would have its first letter appear at $218C on PPU RAM, and I knew it would be $D3 because that's a katakana 'to'. Breakpoint, run, see it comes from $218 in RAM, set breakpoint to $218, run again... well I'll be damned.

At $9EDF in RAM ($1EEF in ROM) is an instruction to load the accumulator with $D3 and store it to $218. Then another for the next letter. Then another... so basically the list of items is HARD CODED. Lord only knows why they did this, there's really no logical reason. They could've saved time and space by doing a load relative and incrementing the address, but whatever, at least they're obvious (sort of).

So, how does it work? It's simple when you can read assembly. The ROM includes a routine which inserts the item name into temporary RAM, then puts it from that RAM into the PPU RAM.

Code: [Select]
00:9ED4:A9 B7     LDA #$B7
 00:9ED6:8D 04 02  STA $0204 = #$01
 00:9ED9:8D 06 02  STA $0206 = #$01
 00:9EDC:8D 0A 02  STA $020A = #$01
 00:9EDF:A9 D3     LDA #$D3
 00:9EE1:8D 18 02  STA $0218 = #$01
 00:9EE4:A9 E6     LDA #$E6
 00:9EE6:8D 19 02  STA $0219 = #$01
 00:9EE9:A9 C9     LDA #$C9
 00:9EEB:8D 1A 02  STA $021A = #$01
 00:9EEE:A9 ED     LDA #$ED
 00:9EF0:8D 1B 02  STA $021B = #$01
 00:9EF3:A9 E9     LDA #$E9
 00:9EF5:8D 1C 02  STA $021C = #$01
 00:9EF8:A9 B9     LDA #$B9
 00:9EFA:8D 1D 02  STA $021D = #$01
 00:9EFD:A9 CF     LDA #$CF
 00:9EFF:8D 1E 02  STA $021E = #$01
 00:9F02:A9 B9     LDA #$B9
 00:9F04:8D 1F 02  STA $021F = #$01
 00:9F07:60        RTS -----------------------------------------

So it first loads B7 and stores it in three places: this is the dakuten mark for 'do' 'go' and 'da'. It starts at $204 in RAM, as you can see. Then it loads each letter and puts it in each position in RAM: D3, E6, C9 and so on. If you want, I can do the whole list since a) it won't be very long, and b) I'll make sure that I don't mess anything up with the assembly.

EDIT: I just want to nitpick about your use of the term DTE. Technically, what you're doing isn't dual tile encoding, it's drawing two letters on spare tiles. It's a lot simpler than actual DTE, which is when you modify the game code so that those spare tile addresses refer to two letters instead of one. What you've done does save screen real estate - I did it myself in my first translation for certain combinations - but it's not the most elegant solution. But hey, Nintendo was happy for Pokémon to do that stupid 'PkMn' thing on the Game Boy, so what do I know. :D
« Last Edit: February 27, 2019, 04:54:45 pm by Psyklax »

Gyroballer

  • Jr. Member
  • **
  • Posts: 26
    • View Profile
Re: Understanding NES text routines
« Reply #31 on: February 27, 2019, 07:03:14 pm »
Thank you for the help with this, so much!

Oh right, I'm using ligatures, but I'm gonna have to do real DTE and put in stuff like "Go" or "nin" so I can fit all these long Japanese names into the CHR space I have. I used them a lot in DBZ II since screen space was an issue, but it's more rom space in this one. Also connecting 'i' or 't' to other common pairings just looks better with this and most fonts, especially il, li, and ll. But I also think stuff like ki, hi, it, etc. look good. Some of mine are definitely just there to save space temporarily.

Edit: I ended up being able to translate temporarily as DrgnRadr and will hopefully get DTE working at some point to do something flashier. Got rid of the B7 handakuten marks, as well.

Thanks again, for real. I can probably do the rest of the list, but I appreciate the offer and have already past the point of crediting you (and Pennywise) on this, so I'll make sure that people know I didn't figure this out on my own.

I'll probably post again in the Personal Projects section if I need help after this.
« Last Edit: February 27, 2019, 07:59:06 pm by Gyroballer »

Psyklax

  • Hero Member
  • *****
  • Posts: 1056
    • View Profile
    • Psyklax Translations
Re: Understanding NES text routines
« Reply #32 on: February 28, 2019, 02:48:55 am »
Well, the reason I asked if you wanted my help is because, after a few minutes writing my own assembly routine to replace the existing code, I did this:



Are you sure you don't want me to do the whole list? :)

Gyroballer

  • Jr. Member
  • **
  • Posts: 26
    • View Profile
Re: Understanding NES text routines
« Reply #33 on: February 28, 2019, 03:21:10 am »
That's awesome, sure!

I wish I could do that. I need to figure out how to do ASM so I can improve my hacks.

Psyklax

  • Hero Member
  • *****
  • Posts: 1056
    • View Profile
    • Psyklax Translations
Re: Understanding NES text routines
« Reply #34 on: February 28, 2019, 04:11:52 am »
Well, I've just been through the section of code that deals with the items, and assuming there's no other items elsewhere (if there are, I might need a save state to check them out), this is the whole list. While I could try to translate them myself, I'd rather limit my involvement here to technical help rather than translation, so that either you or whoever is translating can take sole credit.

So, therefore, here's the list:

ねずみ
カメのこうら…きている / おもいごうぎ…きている / カメのこうら…ぬいでいる / おもいごうぎ…ぬいでいる
たべもの
ごちそう
ごくいしょ
ひこうき
キントウン
こガメラ

Regarding the second in the list, there are four different possibilities depending on game conditions, though since I don't know the game, I don't know the context.

Given the wasteful way the items are done in the original game, I will have tons of space to fit them all in, so just let me know how you'd rather translate everything and I'll do what I can.

Gyroballer

  • Jr. Member
  • **
  • Posts: 26
    • View Profile
Re: Understanding NES text routines
« Reply #35 on: February 28, 2019, 11:39:01 am »
I think it's an exhaustive list of the items, but there are "help cards" which act like items and some of those share names with enemies/NPCs, etc., which is frustrating since names seem to repeat a lot in this game.
(Like Krillin is a helper card, but also talks a lot and is also an enemy and a playable character temporarily and he's listed by full name each time)

First item is Dragon Radar

Mouse
Turtle Shell...put on
/Weighted Gi...put on
/Turtle Shell...removed
/Weighted Gi...removed
Food
Meal
Gokuisho (I'll need to find this item, but without seeing the picture, I think it's a scroll)
Airplane
Flying Nimbus (or just Nimbus)
Baby Gamera

I've been doing everything that I haven't asked for help on. Graphics, translation, and basic hacking.

I know that the ones besides ごくいしょ are good, but I'm seriously confused by that one. I don't think it'd be "goddess", but then I'm not sure what it'd be without seeing the item picture.
There's a line in the game with that word after he beats an enemy that contextually I took to assume he was either reading a scroll, praying, or localized/contextualized to meditating.
He uses it to restore ki/energy, and I'm thinking it probably is a scroll, without seeing the picture, so it's got like secret/mystic teachings in it or something.

Thanks again, Psyklax.
« Last Edit: February 28, 2019, 03:42:45 pm by Gyroballer »

Psyklax

  • Hero Member
  • *****
  • Posts: 1056
    • View Profile
    • Psyklax Translations
Re: Understanding NES text routines
« Reply #36 on: February 28, 2019, 04:57:22 pm »
Okay, I'm getting to work now, I think I'll change the system completely by having one simple routine and a list of items. That way it's easy to change if need be.

Also, I somehow missed one item, my mistake. Here it is:

せんず

I think it's cause it's next to Dragon Radar in the list, so I missed it (and yeah, Radar makes sense :D ).

I'll do what I can, so just let me know your translation of that one word. Only problem I have at the moment is the Turtle Shell since I have a screen limit of 16 characters, and they exceed it when saying if they're on or off... actually, if I just use capital letters instead of brackets or whatever, I think I can JUST fit it.

Gyroballer

  • Jr. Member
  • **
  • Posts: 26
    • View Profile
Re: Understanding NES text routines
« Reply #37 on: February 28, 2019, 05:06:57 pm »
Okay, I'm getting to work now, I think I'll change the system completely by having one simple routine and a list of items. That way it's easy to change if need be.

Also, I somehow missed one item, my mistake. Here it is:

せんず

I think it's cause it's next to Dragon Radar in the list, so I missed it (and yeah, Radar makes sense :D ).

I'll do what I can, so just let me know your translation of that one word. Only problem I have at the moment is the Turtle Shell since I have a screen limit of 16 characters, and they exceed it when saying if they're on or off... actually, if I just use capital letters instead of brackets or whatever, I think I can JUST fit it.

Senzu can stay as "Senzu" or be "Senzu Bean" if it'll fit.
Even if I go the DTE route, I'd still be using the double-character tiles of at least li, ll, and il so if the 'll' will help Shell fit, then that would work. It's currently tile 42, although if that table for the items is 80-based, I guess that'd be C2.

KingMike

  • Forum Moderator
  • Hero Member
  • *****
  • Posts: 6906
  • *sigh* A changed avatar. Big deal.
    • View Profile
Re: Understanding NES text routines
« Reply #38 on: February 28, 2019, 10:16:10 pm »
I personally don't like ligatures (I think that's what "squishy tiles" are officially called) due to inconsistent spacing between the same letters but I can understand they may be unavoidable.
(the official "PKMN" thing mentioned before... yeah, they probably wouldn't have fit a few menus without it, and I guess they decided being consistent with its usage was better than not)
"My watch says 30 chickens" Google, 2018

Gyroballer

  • Jr. Member
  • **
  • Posts: 26
    • View Profile
Re: Understanding NES text routines
« Reply #39 on: February 28, 2019, 11:01:46 pm »
I personally don't like ligatures (I think that's what "squishy tiles" are officially called) due to inconsistent spacing between the same letters but I can understand they may be unavoidable.
(the official "PKMN" thing mentioned before... yeah, they probably wouldn't have fit a few menus without it, and I guess they decided being consistent with its usage was better than not)

I would love to do VWF, but I realize it's impractical/nigh impossible on NES, according to what I've heard.
But at least il, li, and ll tend to look better, regardless of their space saving capacity since taking up 1-2 pixels out of 8, compared to a typical 6 or so out of 8 looks pretty goofy:




So when I have enough screen space and rom space, I'll still use those 3 ligatures, likely.

But I'd love to do DTE or something to save rom space and stop using the other ligatures.
« Last Edit: February 28, 2019, 11:38:19 pm by Gyroballer »