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

Author Topic: Inserting text with Cartographer and Atlas (Wonderswan)  (Read 1342 times)

Iredc

  • Jr. Member
  • **
  • Posts: 24
    • View Profile
Inserting text with Cartographer and Atlas (Wonderswan)
« on: February 06, 2019, 01:49:24 pm »
Hello. I'm currently trying to hack the game "Digimon Tamers-Brave Tamer" for the Wonderswan Color.
So far, I've managed to build a complete table and find out how the pointers work. The pointers are right below the text, and work as follows: If, for example, the starting point of the text has offset 00279E8C, then the pointer is 0C00E839.

That is, the second bit of the pointer is the last bit of the offset (preceded by a zero and followed by two zeroes), the 5th and 6th bits are the 6th and 7th bits of the offset, then comes a 3, and then the 5th bit of the offset. I know, it's messy, but I don't know how to explain it better. I've compared several pointers and all follow the same formula.

This way, I've inserted text successfully in an empty section of the ROM, updating the pointers manually in WindHex. However, I would like to know if I can use tools like Cartographer and Atlas to rewrite the pointers automatically. This is the first time I get past the initial stages of hacking a ROM and I'm a bit lost as to how to use these tools.

For starters, Cartographer is suddenly giving me an error ("Cannot open table file") even though it worked previously fine with said table. But is Cartographer absolutely necessary for the process? Or can I simply use WindHex to dump the text?

Then it comes Atlas. I read the documentation, but the examples given are for NES or GB pointers. I don't know what kind of script I could write for these WSC pointers (or if it's possible at all).

abw

  • Sr. Member
  • ****
  • Posts: 303
    • View Profile
Re: Inserting text with Cartographer and Atlas (Wonderswan)
« Reply #1 on: February 06, 2019, 09:54:26 pm »
Hello. I'm currently trying to hack the game "Digimon Tamers-Brave Tamer" for the Wonderswan Color.
So far, I've managed to build a complete table and find out how the pointers work. The pointers are right below the text, and work as follows: If, for example, the starting point of the text has offset 00279E8C, then the pointer is 0C00E839.

That is, the second bit of the pointer is the last bit of the offset (preceded by a zero and followed by two zeroes), the 5th and 6th bits are the 6th and 7th bits of the offset, then comes a 3, and then the 5th bit of the offset. I know, it's messy, but I don't know how to explain it better. I've compared several pointers and all follow the same formula.
Hopefully somebody with more Wonderswan knowledge will comment on this, but I was under the impression the WSC had a 20-bit address space, which means a pointer value of 0C00E839 is at least 8 bits too big. If the pointers really are that messy, probably you're going to have trouble finding anything that will handle that format already, but I would recommend taking some time to confirm what's going on with those pointers before going too much further. If you know how to use a debugger, try setting a read breakpoint on the pointer address and step through the code to find out what the game does with that value. Or even just experiment with updating the pointer to some string and seeing what changes when the game tries to display that string.

For starters, Cartographer is suddenly giving me an error ("Cannot open table file") even though it worked previously fine with said table. But is Cartographer absolutely necessary for the process? Or can I simply use WindHex to dump the text?
Cartographer isn't absolutely necessary for the process, it just does a lot of the Atlas formatting for you and is a good sanity check to make sure you understand how the game's pointers work; if you can't dump the original text successfully, you're probably going to have a hard time inserting modified text successfully. As for the table file problem, it sounds like Cartographer can't find it any more; did you maybe move the table file or change where you're calling Cartographer from? Cartographer assumes relative paths inside its command file are relative to your current directory.

KingMike

  • Forum Moderator
  • Hero Member
  • *****
  • Posts: 6927
  • *sigh* A changed avatar. Big deal.
    • View Profile
Re: Inserting text with Cartographer and Atlas (Wonderswan)
« Reply #2 on: February 06, 2019, 10:00:43 pm »
WonderSwan uses an X86-type CPU.

As I understand (from what little I've read about X86 ASM), X86 uses segment:offset notation which will always seem to be 32-bits, but if it is only physically capable of 20 bits (I'm guessing on like 386 or something it was effectively 20 bits but later CPUs had actual effective 32 bit addressing?),
then the total address is (segment*0x10)+offset, which does indeed give a 20-bit range but means there are 4096 different ways to address the same byte (since that means 0000:0020 = 0001:0010 = 0002:0000 and so on...)
"My watch says 30 chickens" Google, 2018

Iredc

  • Jr. Member
  • **
  • Posts: 24
    • View Profile
Re: Inserting text with Cartographer and Atlas (Wonderswan)
« Reply #3 on: February 07, 2019, 02:05:39 pm »
Thank you for your answers.
I didn't move Cartographer around, nor any of the files inside the folder. It could load the table before, but now it stopped working. I also checked that no hex code was assigned to several characters in the table (i.e. 65=A, 65=B). I guess something broke in my computer? Or maybe the table became corrupted or something, though WindHex loads it without problem. :huh:

As for the debugger, is it something like Cheat Engine reading addresses while emulating the game? I could try it, though I'm not sure I'll be able to interpret the results. I've seen other posts about Wonderswan pointers, and it seems they're pretty difficult: https://www.romhacking.net/forum/index.php?topic=17949.0
I was lucky this game in particular has the pointers right below the text, so they were intuitive to find out. So far, the formula works. Changing the pointer 0D00013A to 0B00013A, for example, effectively shows in screen the last two characters from the previous line.

Here are some pictures of the progress so far (the introduction):
https://pasteboard.co/I05XpN1.jpg
https://pasteboard.co/I05XNfg.jpg

As you can see, the major problem now is that the font is too big. So even if I have a lot of empty space in the ROM, I still can't write much (not that the original Japanese lines were much longer, anyway). I'd need to resize the font, if that's possible.

Quote
then the total address is (segment*0x10)+offset, which does indeed give a 20-bit range but means there are 4096 different ways to address the same byte

Do you mean that the same pointer could eventually point to several lines at once? That could be very problematic. :-\

KingMike

  • Forum Moderator
  • Hero Member
  • *****
  • Posts: 6927
  • *sigh* A changed avatar. Big deal.
    • View Profile
Re: Inserting text with Cartographer and Atlas (Wonderswan)
« Reply #4 on: February 07, 2019, 06:52:39 pm »
No, one pointer will always point to the same effective address.
It is in theory possible for one pointer value to be created many different ways.

As to Debugger, that means an emulator designed with built-in debugging functions (that is, functions designed to help with finding code or data).
Unfortunately the only one I know of for Wonderswan is one of the many emulator mods that Guest created for various consoles many years ago. While it was great he wanted to help more obscure consoles get debug tools, his debug mods are rather cumbersome to use. (as I recall they all needed to be configured before running the emulator by editing one of the text files, and then still pushing keys while the emulator is running. I used the Genesis one for fan-translating Nadia and I still don't know how I managed to do it. :P )
"My watch says 30 chickens" Google, 2018

Iredc

  • Jr. Member
  • **
  • Posts: 24
    • View Profile
Re: Inserting text with Cartographer and Atlas (Wonderswan)
« Reply #5 on: February 08, 2019, 10:39:26 am »
Quote
Unfortunately the only one I know of for Wonderswan is one of the many emulator mods that Guest created for various consoles many years ago. While it was great he wanted to help more obscure consoles get debug tools, his debug mods are rather cumbersome to use.

That wouldn't be the Mednafen emulator, would it? I couldn't start it because of some .txt configuration missing.
This is what I get in Cheat Engine when searching for the word "However" (hex:BBDCE4D2E3D2DF, pointer:0A00EB39)

Is this the kind of code I should be looking for?

By the way, there was a bit more about the pointers than I previously thought. The 7th bit of the pointer is only a "3" for offsets in the 0027XXXX range. For offsets in 0037XXXX range, it's a "7".
I don't think I can do anything with Atlas this way. But I suppose I can keep inserting the pointers manually. Since there's no math involved, it's not much trouble to write them.

For the moment, I'm more concerned about the font size in screen. So far, I've been unsuccesful trying to locate a font width table or anything like that.

KingMike

  • Forum Moderator
  • Hero Member
  • *****
  • Posts: 6927
  • *sigh* A changed avatar. Big deal.
    • View Profile
Re: Inserting text with Cartographer and Atlas (Wonderswan)
« Reply #6 on: February 09, 2019, 01:32:54 pm »
Guest modified many standalone open-source emulators. I can't remember which one he found for WS/WSC. I just remember all the ones out at the time had some kind of omission. (one was missing sound, the other was missing the Y keys. Like... I know making an emulator is very tough but how do you emulate a console without having all the buttons mapped? :P )
"My watch says 30 chickens" Google, 2018