Glitch City Laboratories Archives

Glitch City Laboratories closed on 1 September 2020 (announcement). This is an archived copy of a thread from Glitch City Laboratories Forums.

You can join Glitch City Research Institute to ask questions or discuss current developments.

You may also download the archive of this forum in .tar.gz, .sql.gz, or .sqlite.gz formats.

Generation I Glitch Discussion

Need Explanations - Page 1

Need Explanations

Posted by: Foundno.
Date: 2015-04-02 19:21:50
You guys have helped me before, and I trust you will help me again.

I have two questions for you glitch masters to ponder:

1. Why does the Mew/Ditto glitch work? Whenever I ask this, people say "Flying away from the trainer makes the game think you're in a battle when you're not." Thanks, Captain Obvious! Why does making the game think you're in a trainer battle when you're not spawn a Pokemon? Does it change the address at D186? And why does the Special stat determine the Index Number? Why not the Defense stat? And why does the Attack stat change the Level? It just doesn't make sense.

2. What happens when you go out of bounds in English Yellow (my personal fave)? The screen turns blue with patches of green, and the menu can be partially seen in the top right corner. The top half of the menu is written in Ash and Pikachu sprites (I'm presuming the sprites and the text are related somehow, as in many glitches you or an NPC turns into letters), and the bottom half is in Japanese? Huh?

Torchickens or TheZZAZZGlitch (the best glitchers on GCL), could you give me an answer to this?

Even if you are not one of the two mentioned above, could you answer my question? I'm interested.

Re: Need Explanations

Posted by: Háčky
Date: 2015-04-02 21:47:27
1. Why does the Mew/Ditto glitch work? Whenever I ask this, people say "Flying away from the trainer makes the game think you're in a battle when you're not." Thanks, Captain Obvious! Why does making the game think you're in a trainer battle when you're not spawn a Pokemon? Does it change the address at D186? And why does the Special stat determine the Index Number? Why not the Defense stat? And why does the Attack stat change the Level? It just doesn't make sense.

When a Trainer spots you, the game loads the Trainer class into $CD2D and team number into $CD2E, and sets a map script that will have the Trainer give his/her dialogue and start the battle. When you leave the map, the current script for that map is saved, and will be run again when you re-enter that map.

In battle, $CD0FCD1F are used to store the stats and stat modifiers of your active Pokémon, and $CD23CD33 are used for the enemy Pokémon. This data consists of the Pokémons level and unmodified stats (HP, Attack, Defense, Speed, Special), followed by the modifier stages for Attack, Defense, Speed, Special, Accuracy, and Evasion. Thus, $CD2D is the lower byte (big-endian) of the enemys Special stat, and $CD2E is its Attack modifier. When you return to the map where you began the glitch, the map script will read these values and start a battle against whatever Pokémon or Trainer they indicate.

Re: Need Explanations

Posted by: Torchickens
Date: 2015-04-03 07:27:21
Thanks for your great explanation Háčky!

Do you know why the "!" part of Trainer-Fly disables the start menu and partially disables A and B and why these buttons aren't disabled with a death warp? I guess how it works may be so you can't press start after "!" appears, but in a death warp, after the "!" appears and the game is in the process of warping you via black out, you can use Start and A/B properly again.

I would like to add the fact that the map scripts are stored from D5F1+ onward. They are actually accessible with PC item underflow so you can create a "Trainer-Fly" with no Trainers.

A value of 01 for one of these scripts for certain maps with Trainers means that the previous text box is loaded based on the text ID in CF13 (often 00 start menu), which can be a completely different text box due the same text ID corresponding to another text box in another map. e.g. Lavender's text box 07 "We heal your Pokémon - Pokémon Center" and 07 on Route 8, a Lass battle "We must look silly standing here like this!"

If the text ID corresponds to an NPC that triggers a battle, then CD2D gets overwritten again with the intended (Trainer) battle. This occurs if you return to Viridian Forest/Route 6 immediately after the death warp, but if you have already beaten them their defeated text will appear and you will get the Special stat encounter.



2. What happens when you go out of bounds in English Yellow (my personal fave)? The screen turns blue with patches of green, and the menu can be partially seen in the top right corner. The top half of the menu is written in Ash and Pikachu sprites (I'm presuming the sprites and the text are related somehow, as in many glitches you or an NPC turns into letters), and the bottom half is in Japanese? Huh?


I think this is considered as a connection to map FF; a map that doesn't exist in itself and is written for loading the last map for a warp in an indoor map.  I do not know what goes on, but at some point usually a rst 38 is loaded (ROM:0000 did this), which points to 0038, which also contains a rst 38 (it points to itself). Going backwards from DFFB, the memory starts to get overwritten with 0039 infinitely until a freeze. You may see a black screen if an unknown opcode is run.

When I set a breakpoint to rst 38, I noticed that in blue, part of the previous location I was at (Lavender Town) was loaded and if I advanced the CPU with F9, the game would continue to load the map.

[img]http://i2.minus.com/iFPDtm97Ra8z4.png[/img]

On further analysis, it is not the map but the screen data updated by opening the start menu that is loaded.
When I set a breakpoint to the memory, sometimes the game went to a place in the memory (8000-EFFF) with a rst 38, sometimes it didn't.

The start menu with sprites as text is hidden in the VRAM after you close it.

Re: Need Explanations

Posted by: Stackout
Date: 2015-04-03 11:10:46
Somewhat offtopic, but regarding $0038 containing "rst 38".. I'm going to make a guess that when debugging, hardware breakpoints were set on $0038 so someone could use the stack to locate why a freeze happened.

Re: Need Explanations

Posted by: Háčky
Date: 2015-04-03 13:20:28
Do you know why the "!" part of Trainer-Fly disables the start menu and partially disables A and B and why these buttons aren't disabled with a death warp? I guess how it works may be so you can't press start after "!" appears, but in a death warp, after the "!" appears and the game is in the process of warping you via black out, you can use Start and A/B properly again.


Bit 0 of $CD60 is set when the Trainer spots you, and disables the Start menu and so on. Its cleared when you win a Trainer battle, when you black out (either in- or out-of-battle), or when you save and reset.

Bit 0 of $D730 is set when an NPC starts walking, and is cleared when theyre done walking. When a Trainer spots you, the battle wont start until this is cleared, though you can still battle Trainers by talking to them (once you can talk to them, by clearing $CD60). This is why its necessary to fight another Trainer who can walk up to you, or to challenge the Elite Four, which clears this flag when Prof. Oak is done walking in the ending cutscene.

Actually, it seems theres a way to make this glitch work without fighting a Trainer at all: after using the PC to save the game and reset (as in the Elite Four method, clearing $CD60), fly to Pewter City and ask the guy next to the Poké Mart to escort you to the museum. That walking NPC will clear $D730 when hes done, allowing the battle to start when you return to the map with the long-range Trainer.

Re: Need Explanations

Posted by: Torchickens
Date: 2015-04-03 14:18:02
Interesting, thanks a lot for your explanation.

Curiously, when bit 0 of CD60 is set although you can't open the start menu manually it can open up by itself (by returning to a route when bit 0 of D730 is clear) and once it is open you can close it with start or B. So the start button is not completely unfunctionable. Once the battle ends, CD60 is reset.

Re: Need Explanations

Posted by: Torchickens
Date: 2019-12-24 05:15:55

Do you know why the "!" part of Trainer-Fly disables the start menu and partially disables A and B and why these buttons aren't disabled with a death warp? I guess how it works may be so you can't press start after "!" appears, but in a death warp, after the "!" appears and the game is in the process of warping you via black out, you can use Start and A/B properly again.


Bit 0 of $CD60 is set when the Trainer spots you, and disables the Start menu and so on. Its cleared when you win a Trainer battle, when you black out (either in- or out-of-battle), or when you save and reset.

Bit 0 of $D730 is set when an NPC starts walking, and is cleared when theyre done walking. When a Trainer spots you, the battle wont start until this is cleared, though you can still battle Trainers by talking to them (once you can talk to them, by clearing $CD60). This is why its necessary to fight another Trainer who can walk up to you, or to challenge the Elite Four, which clears this flag when Prof. Oak is done walking in the ending cutscene.

Actually, it seems theres a way to make this glitch work without fighting a Trainer at all: after using the PC to save the game and reset (as in the Elite Four method, clearing $CD60), fly to Pewter City and ask the guy next to the Poké Mart to escort you to the museum. That walking NPC will clear $D730 when hes done, allowing the battle to start when you return to the map with the long-range Trainer.


Questions:

1. While experimenting, doing Brock Through Walls for me, changing south connection ($D37C) to 0x76, and Oak finishing walking results in a freeze (like white screen/$rst 38 and not just lock up). Anyone have any idea why? Or is it just Red is stepping into map 0xFF? - Resolved? : Changing D392 instead let me avoid the freeze so it probably was stepping out of bounds.

2. Why is it if you continue to hold B with Brock Through Walls active, you can use Surf and proceed to Surf through walls until you let go?