’Cause all games were better on the GBC

You are not logged in.

#1 2010-11-20 22:07:47

Registered: 2010-10-16
Post 54/366

R/B Text-Script Structure


Here are some things I found about scripts and events in Red/Blue.
Mainly I can confirm what once MeanMrMustard said about scripts in RBGY:

MeanMrMustard wrote:

There is scripting in R/B. It's all ASM commands though
Like Pre-Made ones .. one for text, one for movements, battles etc..

There isn't a scripting engine (like the one in GSC), although isn't too much different; in fact you have a routine for loading text, one for applying movement, one for playing music, one for giving item, and so on (so for example if you want to display a text you just have to tell the text_ID and then call "text_routine").

Another important thing is about Map header: what in "RBGY Map doc" is called "pointer to text pointer" is "pointer to a table of pointers related to that map's text". In this table, pointers point to a text-script; text-commands are documented below.

Text Pointer
(2 Bytes)
It points to a list of 2-Bytes pointers.
So we have: "Text Pointer" -> List of Pointers -> text-commands.


--MAIN commands--
Thanks to Tauwasser for documenting GSC commands which are somehow similar (not identical, though; there are some differences).

00 = write text. [00][text] (see also 00_sub_commands)
01 = text from RAM. [01][2-byte pointer]
02 = BCD number. [02][2-byte pointer][byte 765bbbbb]
  bbbbb = how many bytes is the number long
   |0 0 0| [0 = zero]
   |0 0 1| [0 = zero][£]
   |0 1 0| [0 = zero]
   |0 1 1| [0 = zero][£]
   |1 0 0| [0 = space]
   |1 0 1| [0 = space][£]
   |1 1 0| [0 = nothing]
   |1 1 1| [0 = nothing][£]

03 = set new address in RAM for text. [03][2-byte RAM address]
04 = draw box. [04][2-Byte pointer][height Y][width X]
05 = write text starting at 2nd line of text-box. [05][text][ending command]
06 = wait for keypress A or B (put blinking arrow in textbox). [06]
07 = shift texts 1 row above (2nd line becomes 1st line); address for next text = 2nd line. [07]
08 = ASM routine follows [08][ASM code...]
09 = write hex-to-dec number from RAM to textbox [09][2-byte RAM address][byte bbbbcccc]
  bbbb = how many bytes to read (read number is big-endian)
  cccc = how many digits display (decimal)
(note: max of decimal digits is 7,i.e. max number correctly displayable is 9999999)
0A = if pressed A or B then wait 30 VBlanks, else do nothing. [0A]
0B = play sound_86. [0B]
0C = Writes groups of 3 dots. [0C][byte: number of groups]
0D = wait for keypress A or B (no blinking arrow?)
17 = 3-Bytes Pointer follows [17][2-byte pointer][bank]
50 = end of command/text-script

--SOUND commands--

0B = sound_86 (Hiro obtains ITEM)[same as 0F]
0E = sound_91 (learnt something)
0F = sound_86 (given rare candy)[same as 0B]
10 = sound_89 (PKMN successfully caught)
11 = sound_94 (Hiro gives OAK the PARCEL)
12 = sound_9A (successfully caught)
13 = sound_98 (sond heard when "new data will be added for..")
14 = MonCry (Nidorina)
15 = MonCry (Pidgeot)
16 = MonCry (Dewgong)

The following aren't  commands programmed in the game, they just happen to perform certain sounds by pure chance (and I don't guarantee anything about them). I'm leaving them here just for your curiosity.

1B = "follow me" music [same as 35]
1E = SS.Anne music
27 = music stops
2F = music stops
35 = "follow me" music [same as 1B]
40 = viridian music
46 = music stops
4D = SS.Anne music
4E = SS.Anne music

--OTHER commands--
Some sub-commands and info about behaviours inside certain main commands:

00 = simple text
4E = new line
51 = new page
55 = scroll page
50 = end single command
50 50 = end completely
57 = end completely
58 = end completely (waits for key-press [button A or B])

08 = ASM routine
; How to correctly terminate a command_08 script:
    db $08
    ld hl,Pointer_to_3B_P    ;(actually points to the byte [0x17] that comes before the 3B_P)
    call $3c49
    jp $24d7            ; it basically ends the text-script with [0x50]

Let's see a simple text-script.

 Address $1D227:

17 A0 4E 25                     = text-script continues at [pointer][bank], then return here
11                              = play sound
50                              = end

; Address $94EA0 (=25:4EA0):

00                              = normal text starts
52                              = player's name
7F B1 A4 A2 A4 A8 B5 A4 A3      = normal text
4F                              = new line
A0 7F                           = normal text
50                              = end of normal text

01                              = load text from RAM
6D CD                           = RAM location

00                              = normal text starts
E7                              = normal text
50                              = end of normal text

50                              = end of text-script

Adding Marts & Pokecenters


Last edited by Sawakita (2011-07-27 20:51:10)


#2 2010-11-21 07:41:40

Registered: 2010-10-16
Post 186/2,348

Re: R/B Text-Script Structure

I don't understand how this works yet (mostly the ASM part) but by looking at it with a hex editor should help a lot (much easier to think that way).


#3 2011-01-01 14:36:55

Registered: 2010-10-16
Post 70/366

Re: R/B Text-Script Structure

Added some commands (check first post). The commands with a question mark inside brackets may be just glitch.


#4 2011-01-01 19:01:47

Registered: 2010-10-16
Post 71/366

Re: R/B Text-Script Structure

I just read, by pure chance, some Tauwasser's findings about text-commands (for Gold). I noticed that [08] had the same function than R/B, so I tried the ones I didn't find yet: Why didn't anyone tell me that most text-commands were compatible between GSC and R/B!?

Tauwasser on acmlm wrote:

02 = Write number from ram. Structure: [02][Ram address (2byte)][Byte]

Number of figures = Byte AND 0x1F *2
No Hex --> Dec Conversion

03 = Define new ram address to write to. Structure: [03][Ram address (2byte)]

04 = Write a box. Structure: [04][Ram address (2byte)][Y][X]

These are the ones, I tested, that correspond. Probably there are more.

Last edited by Sawakita (2011-07-27 20:45:18)


#5 2011-01-01 21:09:44

Registered: 2009-11-25
Post 393/3,665

Re: R/B Text-Script Structure

Nice find mate! Always good to find similarities between generations, makes life easier when one is documented as you found out haha.  This should be realyl handy for people.

On a side note:

Haha, wow, I remember reading that argument so many times. I was friends with HyperHacker (Haven't chatted with him in ages) but to this day I still can't understand how he could be that big-headed and not believe what was right in front of him. Even before I had been active on a forum with Tauwasser, I could tell just by reading it that he was clearly a guy who knows what he's talking about and was trying to help. Some people.

I am not very active on this forum. I only pop in from time to time.


#6 2011-07-02 15:39:20

Registered: 2010-10-16
Post 153/366

Re: R/B Text-Script Structure

- added Mart/Pokecenter scripts;
- re-arranged layout better;
- also corrected some wrong statements.

Check first post.


#7 2011-07-02 18:01:09

From: U.S. of A.
Registered: 2011-01-08
Post 25/43

Re: R/B Text-Script Structure

Trying to repoint to text at $BC010, the pointer to which, I believe, is 10402F. I replaced the beginning of some text, including the 00, with "17 10 40 2F 50," but then when I talk to the dude, the game goes haywire and throws a "1 ERROR" after a few minutes. Am I misreading this tutorial? What I think is probably the case is that I'm just putting the command in the wrong place, but if so, where do I put it?
EDIT: Nvm, realized I needed to point to the 00 and not right where the text/routine starts
EDIT: Hah, awesome tutorial. Made this with it:

Last edited by Sherkel (2011-07-03 02:02:13)

Formerly known as Tombstoner


#8 2011-07-07 15:51:02

Registered: 2010-10-16
Post 460/2,348

Re: R/B Text-Script Structure

Just thought of saying that you've done great job with figuring out structures of RB !


#9 2011-07-09 10:39:37

Registered: 2010-10-16
Post 156/366

Re: R/B Text-Script Structure

thanks for the good feedback, I appreciate it.

Last update I somehow forgot to add some other "fast-text" commands: for example there's a command for the "PA: ding dong!" (or whatever it says when you run out of steps or balls in Safari Zone), and for opening the storage systems (both bill's and player's PC), and more. I can't find the txt file where I wrote them down; when I find it I'll update the thread.


#10 2011-07-27 20:43:52

Registered: 2010-10-16
Post 165/366

Re: R/B Text-Script Structure

Added basically all the "main" commands and fixed minor issues. Also pointed out unnoticed differences between 1st/2nd generation engines. Now the only things that are missing should be command_00's sub-commands.

Last edited by Sawakita (2011-07-27 20:44:25)


Board footer

Powered by FluxBB