The frame added for Everstone is probably another >>63 calc to decide what parent passes everstone nature if both of them hold it. Since we only have one holding it, it doesn't change anything and is just a dummy frame.
For the Ditto dummy frame it probably says "hey I have to decide which is which" and consumes a frame to think about it. But it always ends up making the Ditto male. Same for the species dummy calc (it has to go find what offspring).

The moment you press OK and the screen fades out completely,
the 0x04000104 timer value gets set as the new seed.
The game then takes that seed and considers it the initial,
and that initial seed is your TID.

​

Code:

The SID is set later in the process, but is still related to the seed.
It is taken from the frame you are on when you end the miniaturization,
taking the seed on that frame (and using the upper16).

The first time, the trainer is just the event value determined by the formula. Each time after, it checks the current value against the previous value. If the current RNG proc is greater than the last one, 1 is added to the event result. So, if RNG proc 1 gave you 0x10 and RNG proc 2 is 0x11, 1 is added to the current proc, so trainer 2 would be # 0x12.

Also, the "skipped" frames aren't actually skipped, per se. The Emerald RNG, like the R/S RNG, runs right before the IRQ handler. The IRQ handler runs 60x/sec, so the RNG runs 60x/sec+ a few when it cycles multiple times on a (vblank, not RNG)frame(I think, pretty sure).

I see this question come up more often that I would expect. Here's why no one should do it:

To start, let's take Pokemon Crystal as an example:

In page0 of the RAM(shown as HRAM in most emulators), there are 4 values we want to pay attention to:

FF04, a division register- not sure what it's dividing, though. No one else is either, from what I've read.
FF9B, a counter, [FF9B]++ each frame it seems
FFE1, the first 8-bit "RNG"
FFE2, the second 8-bit "RNG"

Now, the relevant Z80 assembly I pulled out today:

Hide(Move your mouse to the hide area to reveal the content)Show HideHide Hide

What we're seeing here is the way the RNG advances in gen 1 and 2, though this particular example is for gen 2. Each time the counter(FF9B) increments, RNG byte1 is incremented by the value at FF04 and RNG byte2 is decremented by the value at FF04. Also, the 2 bytes are at times combined and used as a 16-bit values. All the cases where they're used separately and together would need to be documented.

In order to abuse the RNG, one would need to figure out the speed of advancement for the counter(I think this is 60fps, not sure), how the division register(FF04) works and what it starts at(if it's even static), etc. It would be a lot of work on my/our end to figure out and on the RNG-er's end to do just to be unable to trade with anyone.

This isn't an important thing, so I didn't spend a lot of time taking it apart. It isn't worth manipulating, but I think it is worth knowing, if nothing else.

arcee actually brought up a very good point about this the other day. it isn't a hard cmp against 500, it's against another register. it's possible that pokegear calls are grouped into rarity tiers and that value changes based on each tier or something.

Hide(Move your mouse to the hide area to reveal the content)Show HideHide Hide

[18:15] <10Kaphotics> so ya the methods are caused by the IRQ handler chewing up frames as it so desires?
[18:34] <Bond697> not exactly
[18:35] <Bond697> the calls to create the pkm are extra calls from outside the one at the end of the main loop
[18:35] <Bond697> the way it works
[18:36] <Bond697> the game runs through one main set of calls that interpret movement, play a bit of sound, play a bit of graphics, handle controls, check for a battle, check for being in/approaching a tile where a battle can happen, etc
[18:36] <Bond697> at the end of the loop, the vblank runs and clears the screen for the next to bed rawn
[18:36] <Bond697> *to be drawn
[18:37] <Bond697> the frame probably advances right before that
[18:37] <Bond697> (the rng frame) through a rand(); call or something
[18:37] <Bond697> so when it’s creating a poke, those are extra calls
[18:38] <Bond697> the methods could be a result of the main loop running at specific times during encounter creation
[18:38] <Bond697> instead of all the calcs running through one trip through the main loop
[18:39] <Bond697> honestly, it’s probably their own fault
[18:39] <Bond697> everything i’ve ever read about gba programming says not to use division and not to use modulus
[18:40] <Bond697> they have no computational accelerator on the gba and so have to be done through software
[18:41] <Bond697> the fact that most everything is done via modulus might cause weird timing issues that leave the game to catch up
[18:42] <Bond697> fishing, for example needs to have running water drawn, has to do a bunch of modulus calcs, there’s a lot going on
[18:43] <Bond697> so the game probably falls behind, finishes the main loop, and starts over again, leaving a gap in the calcs
[18:44] <Bond697> the methods outside of specific event stuff might only exist due to bad programming
[18:45] <10Kaphotics> well said :D
[18:46] <10Kaphotics> the game still uses mod for the *100 level calc in gen 4/5 tho
[18:46] <10Kaphotics> guess it isn't as bad compared to fucking %100 a 65536
[18:46] <Bond697> well
[18:46] <Bond697> there’s a computational accelerator in the ds
[18:46] <Bond697> for div and mod
[18:46] <10Kaphotics> ah yes
[18:46] <10Kaphotics> and then that too
[18:46] <10Kaphotics> however they did the mod
[18:46] <Bond697> in fact, the div i/o registers always return both
[18:46] <10Kaphotics> revealing the errors in nintendos ways :D
[18:46] <Bond697> the div and the remainder
[18:46] <10Kaphotics> you should post that
[18:47] <10Kaphotics> "the mystery of Method 1/2/3/4
[18:47] <Bond697> maybe
[18:47] <10Kaphotics> and one can definitely argue that no spreads are exclusively one method or another
[18:48] <10Kaphotics> due to that "game runs through the main set of calls", milliseconds of time
[18:48] <Bond697> 60x/sec
[18:48] <10Kaphotics> which explains how I was able to get multiple Methods with different tiles
[18:48] <Bond697> it probably just falls behind
[18:50] <Bond697> i would put money on it not being a coincidence that modulus is hard on the system and that there’s weirdness in the calcs that create the method
[18:56] <Bond697> actually
[18:56] <Bond697> every other frame
[18:56] <Bond697> after the game makes the pid
[18:57] <Bond697> it has to run a modulus of a small number (0x19) against a large number(0-0xFFFFFFFF, usually closer to the high end)
[18:57] <Bond697> well, after it makes the temp pid
[18:57] <Bond697> i’ve run through those so many times, they take an incredibly lrge amount of instructions
[18:57] <Bond697> *large
[18:58] <Bond697> because it avoids division and has to do mod and div out via shifting and adding
[18:59] <Bond697> thats probably it right there
[19:01] <Bond697> err, it does mod 25 every time
[19:01] <Bond697> either way, it’s a lot of reducing

Gen 3 and gen 4 had a single RNG advancement routine each. It did the multiplication/addition and right-shifted 16 and that was it. RNG advancement in gen 5 uses 3 dfferent functions, of which 2 are in use for a given advancement. Here's a sort-of code example:

Hide(Move your mouse to the hide area to reveal the content)Show HideHide Hide

Basically, if the programmer needs an "event value"(what I've been calling those (XX * u32) >> 32 things), he can call rand.event(), give it the value he wants multiplied against, and he gets a number back. If he needs the upper half of the RNG, he can call rand() and get the top half back to do calcs against or to convert to a PID, etc. 5th gen is actually pretty consistent in that way. It either returns the result of the rand/event calc or the upper half of the RNG just like gens 3 and 4.

-Dark pokemon are never requested here. Either Game Freak intentionally left out dark types or whoever wrote the routine/s for the clown simply forgot there were 17 types total. I would guess the latter.

Hide(Move your mouse to the hide area to reveal the content)Show HideHide Hide

Patrat RNG
RNG triggers after she says 'The Patrat that I will have you follow today is..'
(u32 * 0x4) >> 32
(in order of left to right too)
0x0 - Patrat with the brightest smile
0x1 - Patrat with cutest dimples
0x2 - Patrat with the trendiest eyebrows
0x3 - Patrat with biggest belly

Movement
(u32 * 0x3) >> 32
Three pre-set movement patterns!
0x0 - Using first patrat (0x0), results in Patrat on far left
0x1 - Using first patrat (0x0), results in Patrat second to left.
0x2 - Using first patrat (0x0), results in Patrat second to right.

Basically, if you have the super rod, you have a 95% chance of getting a nibble. If you use the good or old rods, you have a 70% and 45% chance, respectively. The cmp changes between 5D, 46, and 2D depending on if you use the super, good, or old rod.

Black and White Fishing

Black and White are extremely similar to HG in this regard. The big difference, though, is that BW use the div part of the divmod and HG uses the mod part. The calc is the same as the ESV calc, but for the frame before:

Hide(Move your mouse to the hide area to reveal the content)Show HideHide Hide

Somewhat borderline on the realm of what we should control, so I'll post pretty vaguely so as to document for future TAS abuse:I do know the seed location, not posting unless we find out it doesn't control link battles (ie anything shady).

Seeded in the transition between challenged animation fade to black --> fade to battle

Most likely seeded via the SHA-1 hash like initial seeds.

Stored at a memory location and called as needed for Battle Calculations (note: not Trainer actions)

[u]Paralysis[/u]
((SEED>>32)*100>>32) = Paralysis Check
If 0-24, Pokemon is Paralyzed for the Turn.
If 25-99, Pokemon can move for the Turn.
[u]Infatuation[/u]
((SEED>>32)*100>>32) = Infatuation Check
If 0-49, Pokemon is Infatuated for the Turn.
If 50-99, Pokemon can move for the Turn.
[u]Confusion[/u]
((SEED>>32)*100>>32) = Confusion Check
If 0-49, Pokemon is Confused for the Turn, and receives recoil.
Inflict recoil damage with the next frame (damage).
If 50-99, Pokemon can move for the Turn.

[u]Catching and Critical Capture[/u]
Depending on how you calculate CC and CV,
you will use different multiplications to the seed.
First it calculates if critical capture, then the shake/capture values.
If result < CV, pass check. Total of 4 for regular catch, 1 for CC.
[U][B]Escape Calculation[/B][/U]
Esc = ((SEED>>32)*0xFF), return 0-254.
If Esc < F, then pass run away.
[img]http://archives.bulbagarden.net/media/upload/0/07/Escape_Formula.png[/img]

This is not what the onsite article says about battle damage chances. Even though it was written for D/P, I find it difficult to believe this aspect of the article to be correct.

Gen 3's Damage Random Value was calculated as follows, which is documented by FractalFusion here.

Code:

In battle: Damage variation
For almost all attacks, the amount of damage that an attack does varies
between about 85% and 100%. The game determines damage variation
three frames after it checks for critical hit.
When the game rolls for damage variation, the game will cycle the
RNG 3 times on that frame.
xxxxxxxx
xxxxxxxx
xxxaxxxx Damage variation, max: a==0 min: a==15
The lower the number, the more damage the attack does.

Seed*#>>32 of Usable Moves ... (0-[#-1])
Researcher can't really handle it well, so in general you'd >>30 for 4 moves,
and >>31 for 2 moves. 3 (and 1) by hand LOL.
0 - Move 1
1 - Move 2
2 - Move 3
3 - Move 4
If the Pokemon has less moves (say 3), the operation is *3.
If a Pokemon is out of PP in a move,
it calculates with the # of usable moves that remain.
I didn't test this scenario much at all,
because it will never happen in TAS/RNG.

This will not apply to smart trainer battles, this has only been tested + confirmed on Wild Pokemon.

If I freeze the table counter to an arbitrary value, the table value AFTER that is used.

just as a note, something weird happens with the roamers in emerald. (maybe r/s too)

the roamers are supposed to be method 1, generated ABCD on release. what can happen is a skipped call without the nature = (rand() % 25) beforehand.(because it's supposed to be method 1) i ended up with method 4(ABCE), but without that nature calc beforehand, so there was no reduction in pids based on a pre-determined nature. sabre is thinking that this is also likely the case for any "static pokes", like voltorb, hypno, etc and i would tend to agree with him.

The game accesses the table for the sprite animations, like when the Pokemon blinks and what not.

Code:

16:38 Kaphotics never before has freezing the MTRNG value delayed the game
16:38 Kaphotics I froze it to always access a table value of
16:39 Kaphotics 00052F40
16:39 Kaphotics which is super fucking low
16:39 Kaphotics and the game is just sitting here
16:39 Kaphotics which makes me think, it hates these low numbers for the MTRNG
16:40 Kaphotics looks like the MTRNG controls the sprite (eyes open)
16:40 Kaphotics a low value makes it's eyes close
16:40 Kaphotics a Pokemon won't "appear" unless its eyes are open
16:40 Kaphotics seriously wtf
16:40 Kaphotics I cant throw out a pokemon with the 0 value
16:41 Kaphotics lol my pokemon is blinking like mad

If a Pokemon's eyes are closing/opening, the game hangs until it's not. If you throw a PokeBall at a Pokemon, it won't go inside if the current MTRNG value is 0. Its white silhouette just dances around. Nor will the PokeBall descend/move if the value is 0.

It will calculate for your Pokemon, then for the enemy. This is the reason why the MTRNG advances in twos during the battle.

Trying to get PKRS out of this, since there's +2+4 advancement after the battle ends.
Having this 6/65536 does not work for triggering PKRS, so I'll look more into it.

====

In recap, even with 0001 as the upper16 of the table value, I still couldn't get PKRS.

The game goes through 1 frame per each sprite on the field, including trainers and thrown Pokeballs (even capturing balls). If something has its eyes closed but it is not asleep, the game will wait until its eyes are open for more than one frame (if it's blinking on every frame the game won't advance).

Move decisions consume 1 frame per enemy Pokemon that needs to do a "random" move. Haven't tested for smart trainers with smart moves.

Once you catch the Pokemon, there's another +1 (end of turn calculate next move? probably not. tested it for PKRS, nope).

There's still the +2+4 at the end on the battle fade out, don't know what it's for, but it does it every time as far as I've seen.

[U][B]MTRNG[/B][/U]
0 Initial
0+n If Everstone passes,
skip until the IRNG value%25 is the Everstone Nature

If I had to guess, it does the same thing for international, but whatever IRNG value it gets has to go through the ARNG advancements for the International PID. That's why Everstone doesn't work for International Breeding.

This also illustrates how the game does not use the MTRNG for calculations, only number grabs. The species determination would be from the LCRNG, if anyone cared.

International Breeding in Gen 4 is 5/8192, not 4/8192. Nobody really took note of the first call as it's shared with the Normal Breeding method (and thus the 4 ARNG is what was thought to be the International PIDs).

-load 20A8A98 into r2
-load 41C64E6D into r0
-load *20A8A98 into r3
-multiply r0 *= r3
-add 0x3039(12345d) to the result(instead of 0x6073)
-store the result back to 20A8A98
-(result >> 16) & 0x7FFF - this is trimming off bit 15, returning a number made up of bits 0-14 in r0-basically, it assures numbers between 0 and 7FFF

so why do i think it's unused?

well,

a. the offset it's using as the global state for the rng is inside the arm9 binary, which makes absolutely no sense at all. the area where the arm9 is stored in ram has the arm9 program written to it then isn't written to again. it's basically read only afterwards.

b. the value there never changes from 1, ever, so far as i can tell. i went ahead and made a sort of breakpoint AR code for that rng and tried anywhere i could think of that wouldn't be viable to go in no$debug.(the gts, other online/networked stuff), and the code never caused a break. i did test it beforehand on something that i know is called and it does work.

c. the other 2 times that 41C64E6D is used are both for encryption, not for creating random numbers.

seeing as though the c in the equation is 0x3039, which is 12345 in decimal, it seems that maybe someone made it as a test rng and didn't remove it? considering where it reads and writes to, i wouldn't think it's used at all. if so, someone at gamefreak is really irresponsible. There's actually code past this point in the binary(which ends at 20AA7E0) and it continues until the end.

if someone does manage to find that it is used, please say so. i'm very curious about this one.