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

Author Topic: Learning Cartographer+Atlas: Base Pointer & GameBoy  (Read 7398 times)

TheFireRed

  • Restricted Access
  • Jr. Member
  • *
  • Posts: 43
  • Fall of Fall
    • View Profile
Learning Cartographer+Atlas: Base Pointer & GameBoy
« on: May 12, 2014, 12:20:28 pm »
Hi guys! I've been recently interested in doing my own translations with Atlas. Just the other day I managed to write a fully working script for Zelda (NES). It was such a huge achievement for me,  :) so now I've decided to take it to the next level and try something harder – which is Link's Awakening DX (GBC). The dialogue script begins at 51931 and these are my Cartographer commands:
Code: [Select]
#GAME NAME:        Zelda DX (GBC)

#BLOCK NAME:        Dialogos
#TYPE:            NORMAL
#METHOD:        POINTER_RELATIVE
#POINTER ENDIAN:    LITTLE
#POINTER TABLE START:    $70000
#POINTER TABLE STOP:    $7055F
#POINTER SIZE:        $02
#POINTER SPACE:        $00
#ATLAS PTRS:        Yes
#BASE POINTER:        $
#TABLE:            zelda.tbl
#COMMENTS:        Yes
#END BLOCK
I tried several addresses in BASE POINTER but none of them seem to work. Sometimes a readable line lurks but obviously that won't help me at all. Anyone willing to guide me so I can realise what am I doing wrong? Thank you!  :beer:
« Last Edit: May 12, 2014, 02:38:59 pm by TheFireRed »

BlackDog61

  • Hero Member
  • *****
  • Posts: 784
    • View Profile
    • Super Robot Wars A Portable translation thread
Re: Learning Cartographer+Atlas: Base Pointer & GameBoy
« Reply #1 on: May 12, 2014, 02:59:13 pm »
Hi there!

I looked at: http://www.romhacking.net/documents/413/
which explains a bit about pointers on the GB. I am going to assume that they are similar on the GBC. ;)
From wwhat they say, absolute pointers are expected to span over 3 bytes.
From the commands you quoted, it seems that text starts before the pointers.
Text spans from 51931 to ???
Pointers span from 70000 to 7055F. (Since you said they are over 2 bytes, this means there are a total of 688 pointers.)

Is this correct? Is this really what you wanted?

Because, the way I look at it, if text is before the pointers, then you indeed need to have a "base pointer" that makes things go back to the ROM where text is.
You should work the math out for 2 pointers to be sure.
Ex:
- first word goes from 51931 to 5194B. first pointer value is 000A. => this would mean that the base pointer should be 51931-000A = 51927.
- second word goes from 5194C to 51983. second pointer value is 0025. => This confirms we calculated the offset ok (5194C-0025 = 51927)

Can you give us the values for your ROM?

(Also, the output from cartographer would be useful.)
« Last Edit: May 12, 2014, 03:05:55 pm by BlackDog61 »

Pennywise

  • Hero Member
  • *****
  • Posts: 2257
  • I'm curious
    • View Profile
    • Yojimbo's Translations
Re: Learning Cartographer+Atlas: Base Pointer & GameBoy
« Reply #2 on: May 12, 2014, 03:30:00 pm »
Well, pointers refer to the CPU address space reserved for the program ROM. With GB/C, the pointers are always going to be reverse order and in the 0000-7fff range. Since the first 4000 bytes of the ROM are always fixed to the beginning of the address space, your text pointers usually are in the 4000-7fff range.

What the base pointer does is sort of the pad the offset in the ROM until it's the same as the offset that points to the address space.

Situations when the base pointer will be 0.

Let's say you have text in the second ROM bank (4000-7fff) and the pointer is 8060 or $6080. Well, this is the only situation where the ROM offsets and address offsets match up. So the base pointer is 0.

Situations in which you need a base pointer of more than 0.

Let's say you have text in the ROM bank of 14000-17fff and your pointer is 8060 or $6080. If you have a base pointer of 0, cartographer is going to pull the text from 6080 in the ROM, but you need it to pull the text from 16080 in the ROM. So how much do you need to add to the offset to equal that? The answer is your base pointer.

TheFireRed

  • Restricted Access
  • Jr. Member
  • *
  • Posts: 43
  • Fall of Fall
    • View Profile
Re: Learning Cartographer+Atlas: Base Pointer & GameBoy
« Reply #3 on: May 12, 2014, 04:33:25 pm »
Hi there!

I looked at: http://www.romhacking.net/documents/413/
which explains a bit about pointers on the GB. I am going to assume that they are similar on the GBC. ;)
From wwhat they say, absolute pointers are expected to span over 3 bytes.
From the commands you quoted, it seems that text starts before the pointers.
I only read about GB pointers at DataCrystal and it was quite lacking in information. This document seems way better! I'll take a look at it, thank you!

Text spans from 51931 to ???
Pointers span from 70000 to 7055F. (Since you said they are over 2 bytes, this means there are a total of 688 pointers.)

Is this correct? Is this really what you wanted?
Yes, it's correct. There are precisely 2AF pointers (counting line 0) = 688 p.
But! By using LALE I have just discovered that all dialogues are scattered throughout the ROM. For instance, p. 107 points to 5BF8B (You've got the Thunder Drum!) whereas p. 108 points to 70B2A (Hi! It's me, the photographer! You seem curious about Grandpa Ulrira). There's plenty of free space and unused French and German dialogues (meaning a multi3 release was planned at a point?).

For starters, now I know that texts start at 2668E, although it's pointer number 24E. THAT CHANGES EVERYTHING! I'm going to make some changes to the Cartographer commands.

Can you give us the values for your ROM?

(Also, the output from cartographer would be useful.)
Apart from the dialogue start address (now 2668E) and the table pointer, what else do you need?  :-[

For now here's a sample of the output using 48F31 as base pointer. https://www.dropbox.com/s/9y9podk1wdqfx62/zelda_script_000.txt

I calculated that number like this:

Code: [Select]
Second pointer (at 70002): 59 8A

8A 59

Dialogue: 05 19 8A

8A59 - 5198A = 48F31

That's definitely the second dialogue, but still the rest of the output is messed up. If it helps, here's a screenshot of the hex editor at the pointer table.


PS: It looks like my brain just switched on. I think the pointer table is located at 70001 and not 70000. We'll see if I can manage.  ;D




BINGO!!!!!!!!!!!

Spoiler:
Code: [Select]
//GAME NAME:        Zelda DX (GBC)

//BLOCK #000 NAME:        Dialogos

//POINTER #0 @ $70001 - STRING #0 @ $51931

#W16($70001)
//Whoa, boy! Whereya off to in    such a hurry?   Set a spell, I  got somethin' tatell ya![END]


//POINTER #1 @ $70003 - STRING #1 @ $5198A

#W16($70003)
//What a relief! Ithought you'd   never wake up!  You were tossingand turning...  What?  Zelda?   No, my name's   Marin!  You muststill be feelinga little woozy. You are on      Koholint Island![END]


//POINTER #2 @ $70005 - STRING #2 @ $51A4B

#W16($70005)
//Follow the lane south to reach  the beach where I found you.    Since you washedashore, lots of nasty monsters  have been in thearea, so be     careful, okay?[END]


//POINTER #3 @ $70007 - STRING #3 @ $51AEA

#W16($70007)
//Hi!  Tarin went to the forest tolook for toad-  stools, but I'd rather sing.    Listen to this, it's called the 'Ballad of the  Wind Fish.'[END]


//POINTER #4 @ $70009 - STRING #4 @ $51B76

#W16($70009)
//Hey!  That's a  nice Ocarina youhave there! Willyou accompany   me as I sing?[END]


//POINTER #5 @ $7000B - STRING #5 @ $51BC4

#W16($7000B)
//I just love to  sing-- what can I say?  What do you like to do, [NAME]?[END]


//POINTER #6 @ $7000D - STRING #6 @ $51C0B

#W16($7000D)
//[NAME], Tarin's  taking a nap at home.  I don't  know how he can sleep on such a nice day!  It   makes me want tosing a song...  Yes, the song is'Ballad of the  Wind Fish!'[END]


//POINTER #7 @ $7000F - STRING #7 @ $51CB7

#W16($7000F)
//Eh? It's locked!You can open thedoor with the   Nightmare Key.[END]


//POINTER #8 @ $70011 - STRING #8 @ $51CF6

#W16($70011)
//You got a Piece of Power!  You  can feel the    energy flowing  through you![END]


//POINTER #9 @ $70013 - STRING #9 @ $51D43

#W16($70013)
//Ahhh... It has  the Sleepy Toad-stool, it does! We'll mix it up something in a  jiffy, we will![END]


//POINTER #10 @ $70015 - STRING #10 @ $51DA3

#W16($70015)
//The last thing Ikin remember wasbitin' into a   big juicy toad- stool... Then, Ihad the darndestdream... I was araccoon!  Yeah, sounds strange, but it sure was fun![END]


//POINTER #11 @ $70017 - STRING #11 @ $51E48

#W16($70017)
//I'm all tucker'dout...  I think I better set a  spell before I  head home...[END]


//POINTER #12 @ $70019 - STRING #12 @ $51E95

#W16($70019)
//Double double,  toil and troublea toadstool mix makes powder fortricks![END]


//POINTER #13 @ $7001B - STRING #13 @ $51EDD

#W16($7001B)
//As a raccoon, mynose is verrry  sensitive, ta   stuff like dust and powder...[END]


//POINTER #14 @ $7001D - STRING #14 @ $51F2B

#W16($7001D)
//It's the toad-  stool you pickedin the woods.   What is it for? You hold it overyour head and a mellow aroma    wafts into your nostrils.[END]


//POINTER #15 @ $7001F - STRING #15 @ $51FB5

#W16($7001F)
//You pick the    toadstool... As you hold it overyour head, a    mellow aroma    flows into your nostrils.[END][/spoiler]
Full file: https://www.dropbox.com/s/265g7d9tx1rye8e/zelda_script2_000.txt but some dialogues seem to be missing

Looks like I can't use the same base pointer since the dialogues are scattered, am I right?



How do I make Atlas render and recognise special characters from my text file? (you know the drill, ¡¿ áéí ñ and such)
« Last Edit: May 13, 2014, 02:14:29 pm by TheFireRed »

BlackDog61

  • Hero Member
  • *****
  • Posts: 784
    • View Profile
    • Super Robot Wars A Portable translation thread
Re: Learning Cartographer+Atlas: Base Pointer & GameBoy
« Reply #4 on: May 13, 2014, 03:03:10 pm »
Good work!
Atlas will recognize characters based on what you feed it with, through the table file. I don't know the codes in your case, but these special characters are probably just missing in the table?
However, the game will be limited to whatever it has in its font. Have you located the font's graphics, to give you an idea of what it supports? (You can always try a lot of hex values and see what the game displays... That is kind of the "slow but exhaustive" way.)
If the font does not have everything you need, then either you can swap out unused characters for useful ones (editing the font's graphic, and then your table) or you get into more complex topics. (It would mean that you need to understand the way that the ASM routine to render the text works, in the part where it fetches characters from the font graphics, to see if you could just extend that. Or extend to another place if there is no room just after the font...)

As for scattered text, the only thing I am used to is seeing various text areas (such as one per chapter, one for items, one for characters, etc) with each having an associated pointer table "somewhat nearby". I don't know if it the case here? In general, you need to find the pointer tables that help cover for all of the text that you see. Which means the rabbit hole goes just a bit further than you might have expected. ;)

TheFireRed

  • Restricted Access
  • Jr. Member
  • *
  • Posts: 43
  • Fall of Fall
    • View Profile
Re: Learning Cartographer+Atlas: Base Pointer & GameBoy
« Reply #5 on: May 13, 2014, 03:25:37 pm »

The font has already been edited and those characters have been included to the table.

EDIT: Turns out I forgot a character out of the way while editing the table and that's why Atlas threw me errors. Whoopsie.  :-X I suppose I should calculate new pointer bases for those chunks of dialogue scattered. In this case it seems the very same pointer table points to different parts of the ROM so the base pointer is inconsistent. I'll keep on going through the rabbit hole. :3


EDIT2: Okay! This is my shiny new Cartographer commands file!

Code: [Select]
#GAME NAME:        Zelda DX (GBC)

#BLOCK NAME:        Text1 001-164
#TYPE:            NORMAL
#METHOD:        POINTER_RELATIVE
#POINTER ENDIAN:    LITTLE
#POINTER TABLE START:    $70001
#POINTER TABLE STOP:    $70148
#POINTER SIZE:        $02
#POINTER SPACE:        $00
#ATLAS PTRS:        Yes
#BASE POINTER:        $4C000
#TABLE:            tbl.tbl
#COMMENTS:        Yes
#END BLOCK

#BLOCK NAME:        Text2 165-265
#TYPE:            NORMAL
#METHOD:        POINTER_RELATIVE
#POINTER ENDIAN:    LITTLE
#POINTER TABLE START:    $70149
#POINTER TABLE STOP:    $70210
#POINTER SIZE:        $02
#POINTER SPACE:        $00
#ATLAS PTRS:        Yes
#BASE POINTER:        $54000
#TABLE:            tbl.tbl
#COMMENTS:        Yes
#END BLOCK

#BLOCK NAME:        Text3 266-402
#TYPE:            NORMAL
#METHOD:        POINTER_RELATIVE
#POINTER ENDIAN:    LITTLE
#POINTER TABLE START:    $70211
#POINTER TABLE STOP:    $70320
#POINTER SIZE:        $02
#POINTER SPACE:        $00
#ATLAS PTRS:        Yes
#BASE POINTER:        $6C000
#TABLE:            tbl.tbl
#COMMENTS:        Yes
#END BLOCK

#BLOCK NAME:        Text4 403-593
#TYPE:            NORMAL
#METHOD:        POINTER_RELATIVE
#POINTER ENDIAN:    LITTLE
#POINTER TABLE START:    $70321
#POINTER TABLE STOP:    $7049C
#POINTER SIZE:        $02
#POINTER SPACE:        $00
#ATLAS PTRS:        Yes
#BASE POINTER:        $70000
#TABLE:            tbl.tbl
#COMMENTS:        Yes
#END BLOCK

#BLOCK NAME:        Text5 594-668
#TYPE:            NORMAL
#METHOD:        POINTER_RELATIVE
#POINTER ENDIAN:    LITTLE
#POINTER TABLE START:    $7049D
#POINTER TABLE STOP:    $70560
#POINTER SIZE:        $02
#POINTER SPACE:        $00
#ATLAS PTRS:        Yes
#BASE POINTER:        $20000
#TABLE:            tbl.tbl
#COMMENTS:        Yes
#END BLOCK

Now all text dialogues are correctly dumped into files! The table pointer seems to be split into several chunks and each one points to different parts of the ROM. What's more, various base pointers are needed throughout the pointer table. Do you have any hints in how to implement this into an Atlas file? Right now I've got this for my testing file:

Code: [Select]
#VAR(Table, TABLE)
#ADDTBL("tbl.tbl", Table)
#ACTIVETBL(Table)
#VAR(PTR, CUSTOMPOINTER)
#CREATEPTR(PTR, "LINEAR", $4C000, 16)
#VAR(PTRTBL, POINTERTABLE)
#PTRTBL(PTRTBL, $70001, 2, PTR)

#HDR($50)
#JMP($51931)
« Last Edit: May 14, 2014, 06:19:03 am by TheFireRed »

TheFireRed

  • Restricted Access
  • Jr. Member
  • *
  • Posts: 43
  • Fall of Fall
    • View Profile
Re: Learning Cartographer+Atlas: Base Pointer & GameBoy
« Reply #6 on: May 21, 2014, 03:35:54 pm »
Here's a question: can I use multiple endtags for the autowrite? I've got some strings ending with /FE=<CHOICE>, which are obviously different from the usual /FF=<END>.

This is my Atlas commands file:

Code: [Select]
#VAR(Table, TABLE)
#ADDTBL("tbl.tbl", Table)
#ACTIVETBL(Table)

#VAR(PTR, CUSTOMPOINTER)
#CREATEPTR(PTR, "LINEAR", $4C000, 16)

#VAR(PTR0, POINTERTABLE)
#PTRTBL(PTR0, $70001, 2, PTR)

#HDR($50)
#JMP($51931, $53FFF)

#AUTOWRITE(PTR0, "<END>")
#AUTOWRITE(PTR0, "<CHOICE>")

//#W16($70001)
//Whoa, boy! Whereya off to in    such a hurry?   Set a spell, I  got somethin' tatell ya!<END>
//POINTER #1 @ $70003 - STRING #1 @ $5198A
¡Pero chaval!   
¿Ande vas con   
tanta prisa?   
¡Ven aquí, hijo,
que tengo algo 
que decirte!<END>

and so on

//#W16($70061)
//  Deluxe Shovel    200 Rupees!  Seems expensive!    Buy  No Way!<CHOICE>
//POINTER #49 @ $70063 - STRING #49 @ $52969
Pala lujosa por
200 rupias. ¡Es
un poco cara!   
¿Comprar?       
    Sí   ¡No!<CHOICE>


Since #AUTOWRITE(PTR0, "<END>", "<CHOICE>") won't work, I assumed adding two #AUTOWRITE commands would do the trick. I tried this and it seems it's working fine, so am I correct?

Pennywise

  • Hero Member
  • *****
  • Posts: 2257
  • I'm curious
    • View Profile
    • Yojimbo's Translations
Re: Learning Cartographer+Atlas: Base Pointer & GameBoy
« Reply #7 on: May 21, 2014, 09:15:04 pm »
Just out of curiosity, but why do you have #HDR($50)?

#HDR is used for ROMs that have external headers tacked onto the beginning of the ROM a la the NES. The GB doesn't have that and #HDR is unnecessary.

TheFireRed

  • Restricted Access
  • Jr. Member
  • *
  • Posts: 43
  • Fall of Fall
    • View Profile
Re: Learning Cartographer+Atlas: Base Pointer & GameBoy
« Reply #8 on: May 22, 2014, 12:34:58 pm »
I actually used one of your files as a template and I assumed that I needed to write a HDR command too. But now that you're telling me it totally makes sense. Line erased. Thanks!  :beer:

BlackDog61

  • Hero Member
  • *****
  • Posts: 784
    • View Profile
    • Super Robot Wars A Portable translation thread
Re: Learning Cartographer+Atlas: Base Pointer & GameBoy
« Reply #9 on: May 22, 2014, 02:55:04 pm »

Now all text dialogues are correctly dumped into files! The table pointer seems to be split into several chunks and each one points to different parts of the ROM. What's more, various base pointers are needed throughout the pointer table. Do you have any hints in how to implement this into an Atlas file? Right now I've got this for my testing file:

What is the logic of the change in base pointer in the table? Ex:
- Is there a set of 30 consecutive pointers pointing at a part of the ROM, then 30 other pointers pointing somewhere else, and then another continuous set, etc? => This could be solved by having several "block" sections in the Cartographer file.
- Do even consecutivev pointers point to different sections, but every 4 pointers is coherent in pointed area? (like pointers 1, 5, 9 point to one area of the ROM, and 2,6,10 to another)? In that case you can set different block sections and tell Cartographer that the pointers in the table are separated by bytes it should not interpret (i.e. 3 pointers), and set up 4 such blocks in your file.
- or is there something different?

It would be surprising to me if there was not some kind of logic.

Note: I have never used "autowrite", so I cannto help here. But if it works both for dumping and inserting, then it just has to be right. :)

TheFireRed

  • Restricted Access
  • Jr. Member
  • *
  • Posts: 43
  • Fall of Fall
    • View Profile
Re: Learning Cartographer+Atlas: Base Pointer & GameBoy
« Reply #10 on: May 22, 2014, 03:51:57 pm »
I may not have explained it appropriately. Yes, as you first mentioned, in the table pointer there are a number of consecutive pointers pointing to a whole chunk of text, but then the pointers change directions to another continuous set. This occurs four times, making a total of 5 text blocks.

The first pointers ($70001-$70148) point to the second text block in the ROM (2668E-27FFF, base pointer $4C000), etc. When I was testing the script dumps I noticed that the dialogues ended abruptly, so I came to the conclusion that I needed to recalculate the addresses in new text blocks for Cartographer. I completed it by trial and error, basically. Interestingly enough the last pointers point to the first text block in the ROM.

It will definitely sound silly to you (and I know that I'm just reinventing the wheel), but I find this astonishing.  :happy: Not only that, but also how these two little powerful tools are able to work across completely different games.

BlackDog61

  • Hero Member
  • *****
  • Posts: 784
    • View Profile
    • Super Robot Wars A Portable translation thread
Re: Learning Cartographer+Atlas: Base Pointer & GameBoy
« Reply #11 on: May 22, 2014, 04:15:13 pm »
It is astonishing to me too (the base pointer changing).
As for Cartographer + Atlas, I would rather say they are pleasantly useful.
I just wish someone would help me with my other post about them. ;)

Have we ansered all of your questions?
With 5 blocks having each a different base offset, you should be all set, should you not?
Are you planning to post your files in the Documents section of this site?  8)

TheFireRed

  • Restricted Access
  • Jr. Member
  • *
  • Posts: 43
  • Fall of Fall
    • View Profile
Re: Learning Cartographer+Atlas: Base Pointer & GameBoy
« Reply #12 on: May 22, 2014, 04:50:19 pm »
Yeah, I think so. Unless something else appears, I'm good to go for now. I'll use this thread for future reference as a rookie romhacker.  :P

And yes, I'll definitely share these documents for everyone else. It'll surely help other people to translate the game in a matter of days. :)

CUE

  • Jr. Member
  • **
  • Posts: 86
    • View Profile
    • Nasío pa'jakear
Re: Learning Cartographer+Atlas: Base Pointer & GameBoy
« Reply #13 on: May 26, 2014, 03:26:49 am »
Cartographer is not the best tool to reinsert the Zelda DX script.

Some info:
Code: [Select]
- 070000-070000: no idea
- 070001-070560: 16bits low-endian pointers
- 070561-070580: message stored, 2 lines, VRAM offset, lower bytes
- 070581-0705A0: message stored, 2 lines, VRAM offset, upper bytes
- 0705A1-0705C0: message stored, 2 lines, tile numbers
- 0705C1-070600: window message, 2 lines, VRAM offset (upper bytes), upper window
                 window message, 2 lines, VRAM offset (upper bytes), lower window
- 070601-070640: window message, 2 lines, VRAM offset (lower bytes), upper window
                 window message, 2 lines, VRAM offset (lower bytes), lower window
- 070641-070740: table, tile number for each char code
- 070741-0709F0: page number for each message (only the 6 lower bits) <--- 14, 16, 1C, 1D, 09
- 0709F1-070B29: code

Free space used:
- page 14: rom addr 051931-053FFF
- page 16: rom addr 059701-05BFFF
- page 1C: rom addr 070B2A-073FFF
- page 1D: rom addr 074000-077FFF
- page 09: rom addr 02668E-027FFF
« Last Edit: May 26, 2014, 08:16:23 am by CUE »

RedComet

  • Hero Member
  • *****
  • Posts: 3166
    • View Profile
    • Twilight Translations
Re: Learning Cartographer+Atlas: Base Pointer & GameBoy
« Reply #14 on: May 26, 2014, 09:05:39 am »
Cartographer is not the best tool to reinsert the Zelda DX script.

To be fair, Cartographer is for extraction not insertion. ;)
Twilight Translations - More than just Dragonball Z. :P

CUE

  • Jr. Member
  • **
  • Posts: 86
    • View Profile
    • Nasío pa'jakear
Re: Learning Cartographer+Atlas: Base Pointer & GameBoy
« Reply #15 on: May 26, 2014, 09:10:05 am »
Opsss, I mean Atlas :)

TheFireRed

  • Restricted Access
  • Jr. Member
  • *
  • Posts: 43
  • Fall of Fall
    • View Profile
Re: Learning Cartographer+Atlas: Base Pointer & GameBoy
« Reply #16 on: May 26, 2014, 06:16:11 pm »
Works okay for me I guess, plus it's incredibly fast. Sure, I have to be very careful with spaces and correct formatting, but there are some nice debug features in the game so testing texts won't be very difficult.