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

Author Topic: gameboy text routine  (Read 5161 times)

gorgyrip

  • Jr. Member
  • **
  • Posts: 45
    • View Profile
gameboy text routine
« on: July 14, 2015, 03:32:49 am »
Hi,
The game in question is: Crayon Shin-chan - Ora to Shiro wa Otomodachi dayo.
Here's how the text box looks like:


I need to remove those empty lines so I can fit more text.
That text box is the first one in the game and the text starts at 117c5 in rom. So the pointer is c557, bank 04.
I know I should use BGB, but how? At what address i should set a breakpoint?

FAST6191

  • Hero Member
  • *****
  • Posts: 3052
    • View Profile
Re: gameboy text routine
« Reply #1 on: July 14, 2015, 04:16:57 am »
It is exceedingly unlikely that arrangement is "line [enter] [enter] line", the pixel height alone would make me doubt that, beyond it seldom ever happening in games. If you find the text in question and it is than then it is easy enough to change once you know how it starts a new line. I could not find some gameplay footage that included it (though I did not try very hard) so I can not say much more at this point.

What is more likely is that is just a gap put in there at the graphics level. http://problemkaputt.de/pandocs.htm#videodisplay will be my reference for graphics terms here (some people use some slightly different ones but I am going with them).
Text, especially on the GB/GBC, should be in the BG system but I have seen it in the OAM as well. Assuming it is BG (in this case probably the window aspect) then http://problemkaputt.de/pandocs.htm#vramtiledata is what you would want to be looking at.

As for BGB. If you were looking at a disassembly then by all means consider the pointers as they would appear to the console, and should also work within an emulator. However one of the nice things about using emulators is they are not bound to the original hardware setup and you can set breakpoints for reads within the ROM using the ROM address.

dACE

  • Sr. Member
  • ****
  • Posts: 353
    • View Profile
Re: gameboy text routine
« Reply #2 on: July 14, 2015, 08:01:15 am »
I ran the game mentioned in BGB and there is space enough for 6 rows of characters:

Below are an image over the dialog as appears in the memory:



And here is a image over the dialog when I edit the memory manually:



So you should probably add a break-point, for when the value 10 is written into ram-address 9943.

That is at least a starting point - good luck!

/dACE
« Last Edit: July 14, 2015, 08:30:22 am by dACE »

KingMike

  • Forum Moderator
  • Hero Member
  • *****
  • Posts: 7067
  • *sigh* A changed avatar. Big deal.
    • View Profile
Re: gameboy text routine
« Reply #3 on: July 14, 2015, 12:06:15 pm »
How a print routine usually works is that it adds $40 (the size of 2 tilemap rows on the GB) to the tile address after each line.
You could single-space it by changing to $20.

You'd have to disassemble the print routine.
If you can understand ASM, it's probably simple. If you don't, it's a lot of work.
Start be using breakpoints to set a read breakpoint on $57C5 (your text address after being converted to a CPU address)
It probably does some cp instructions to check if the value is a newline character.
(like if a newline was FE, the following instructions "cp a,FE jr z,xxxx" would mean the linebreak routine was at xxxx)

On the Game Boy, RAM $8000-9FFF is VRAM. You usually want to avoid directly messing with that, and only do stuff with the CPU RAM ($C000-DFFF)
"My watch says 30 chickens" Google, 2018

dACE

  • Sr. Member
  • ****
  • Posts: 353
    • View Profile
Re: gameboy text routine
« Reply #4 on: July 14, 2015, 02:43:43 pm »
Look at offset: 1 17D3 in the rom (which I hope to god you have aquired legally) you se the value FE.
That is apparently the carriage return. If you replace it with FF - it will only print the first line.

Then there is offset: B4DD that contains the value 40. Change this to 20 - then the carriage return will only skip a 'single' row.

But now you'll face another problem: each character is always printed two-tiles high, so you will effectively overprint the row above.

/dACE

gorgyrip

  • Jr. Member
  • **
  • Posts: 45
    • View Profile
Re: gameboy text routine
« Reply #5 on: July 14, 2015, 04:14:45 pm »
Guys, thank you all!
Like, dACE said i replaced 40 with 20 at offset B4DD. How did you find that offset?
But that didn't completely solved the problem.
Next I set a breakpoint for 9943. The debugger snaped at 03b2. At 03b8 it was: add hl, bc. hex value 09 replaced it with 00. I hope that's ok.
Now everything looks great.

Can you guys please help me move the pointer table for the text to another bank? The pointer to the pointer table is at offset: 11610

KingMike

  • Forum Moderator
  • Hero Member
  • *****
  • Posts: 7067
  • *sigh* A changed avatar. Big deal.
    • View Profile
Re: gameboy text routine
« Reply #6 on: July 15, 2015, 08:39:45 am »
As I had said, $9943 is VRAM. I'd beware of messing with routines that handle that, as they tend to get reused for many things.
What was the "other problem"?
"My watch says 30 chickens" Google, 2018

gorgyrip

  • Jr. Member
  • **
  • Posts: 45
    • View Profile
Re: gameboy text routine
« Reply #7 on: July 15, 2015, 03:59:51 pm »
Here's a photo:


1. original
2. modified only the address b4dd.  40 replaced with 20. As you can see there's no more an empty line between the text lines, but the second text line erases the first one.
3. modified only the address 03b8. 09 replaced with 00. Text is one line higher and the dakuten is gone.
5. modified both adsresses b4dd and 03b8. Everything looks good.

Is it possible to move the text to another bank if the pointer to the pointer table doesn't contain the bank number?
« Last Edit: July 16, 2015, 02:33:59 am by gorgyrip »

henke37

  • Hero Member
  • *****
  • Posts: 643
    • View Profile
Re: gameboy text routine
« Reply #8 on: July 16, 2015, 05:40:34 pm »
Most pointers have spare bits in the top of the address that you can steal and use for another purpose, like indicating the bank to use.

gorgyrip

  • Jr. Member
  • **
  • Posts: 45
    • View Profile
Re: gameboy text routine
« Reply #9 on: July 17, 2015, 02:51:46 am »
Most pointers have spare bits in the top of the address that you can steal and use for another purpose, like indicating the bank to use.
Can you please explain?

henke37

  • Hero Member
  • *****
  • Posts: 643
    • View Profile
Re: gameboy text routine
« Reply #10 on: July 17, 2015, 08:33:37 am »
You know how games tend to use numbers stored in a fixed size type? Sometimes the number doesn't even reach half of the maximum value. Especially not for 4 byte numbers. As such, you can steal the high bits, since they are never used normally.

gorgyrip

  • Jr. Member
  • **
  • Posts: 45
    • View Profile
Re: gameboy text routine
« Reply #11 on: July 17, 2015, 12:03:07 pm »
You know how games tend to use numbers stored in a fixed size type? Sometimes the number doesn't even reach half of the maximum value. Especially not for 4 byte numbers. As such, you can steal the high bits, since they are never used normally.

Sorry, you lost me. Can you please give me an example?
At $11610 i have 4b56. That points to the pointer table. How can I edit that so it points for bank 8?

Pennywise

  • Hero Member
  • *****
  • Posts: 2355
  • I'm curious
    • View Profile
    • Yojimbo's Translations
Re: gameboy text routine
« Reply #12 on: July 17, 2015, 12:25:30 pm »
There usually isn't enough space in a $4000 byte bank to contain an entire translated text block, but it's entirely dependent on what you're trying to move. If it's smaller text block that only takes up a fraction of the space, then all you have to do is change the bank number. If not, I use a method of splitting a text block between banks. It's not terribly complex, all it is a check that if X of the pointer index is past a certain number, and if so then swap banks, and if not then stay the course. Basically you need to learn Z80 and read up on some hardware docs to get a better understanding of the GB architecture.

KingMike

  • Forum Moderator
  • Hero Member
  • *****
  • Posts: 7067
  • *sigh* A changed avatar. Big deal.
    • View Profile
Re: gameboy text routine
« Reply #13 on: July 17, 2015, 01:03:20 pm »
You can only edit a pointer to expand to other banks if you write an ASM hack to support it.

It's not extremely difficult but it's certainly not a trivial hack.
I did the hack Pennywise is talking about in one game (since real GB pointers are under $8000, I made a hack so that $8000-BFFF references one expanded bank, and $C000-FFFF is another. But if the game has more than one routine that reads the pointer, then it can get messy which is why it's not a simple hack.)
The other hack I'd write, if 2 extra banks isn't enough, is to use an invalid pointer as a bank+string number flag. That's probably way more space than you'd ever need in a GB game :D
"My watch says 30 chickens" Google, 2018

gorgyrip

  • Jr. Member
  • **
  • Posts: 45
    • View Profile
Re: gameboy text routine
« Reply #14 on: July 17, 2015, 03:04:22 pm »
I understand now, but i't too much for me.
I don't want 2 banks, I want to have all the text in an empty bank.

If it's smaller text block that only takes up a fraction of the space, then all you have to do is change the bank number.
How do I do that?
« Last Edit: July 18, 2015, 03:31:12 am by gorgyrip »

henke37

  • Hero Member
  • *****
  • Posts: 643
    • View Profile
Re: gameboy text routine
« Reply #15 on: July 18, 2015, 07:12:53 am »
You have to edit the game code. There is no other way to change bank but to run code that does it.

gorgyrip

  • Jr. Member
  • **
  • Posts: 45
    • View Profile
Re: gameboy text routine
« Reply #16 on: July 24, 2015, 05:16:43 pm »
Pennywise or KingMike, can you please post your code?