The Focus Energy bug in Pokemon Red, Blue and Yellow
The move that is supposed to raise your critical hit chance lowers it instead. Here is the one wrong instruction behind it, and the exact odds for all 151 Pokemon.
The short answer. Focus Energy is bugged in Pokemon Red, Blue and Yellow: instead of raising your critical hit chance, it cuts it to about a quarter. The game's critical hit routine halves a number where it should double it, so after Focus Energy (or a Dire Hit) a Scyther's SLASH lands a critical hit 104 times in 256 instead of 255, and its QUICK ATTACK 13 times in 256 instead of 52. Gold, Silver and Crystal fixed it.
- The chance comes from base Speed only. An ordinary move crits base Speed / 2 times in 256; KARATE CHOP, RAZOR LEAF, CRABHAMMER and SLASH 8 times as often, at most 255 in 256. Level, stat changes and the target never count.
- Focus Energy leaves about a quarter of an ordinary move's chance (never more: the game rounds down twice), and roughly a quarter to a half of a high critical move's.
- Dire Hit is the same bug: the item sets the same flag. It lasts until the Pokemon switches out or Haze clears it.
- Tested in the game's own code in an emulator, in Red and Yellow, with the random byte set on both sides of each threshold. How I checked it.
Your Pokemon's critical hit chance, with and without Focus Energy
Pick a Pokemon and a kind of move. The numbers are worked out the way the game works them out, step by step, and the board shows all 256 values the game's random byte can take: the green ones are critical hits.
The wrong instruction
The routine is CriticalHitTest in the game's battle engine (engine/battle/core.asm in pret's disassembly of Red and Blue). It loads the attacker's base Speed and halves it. Then it checks the Focus Energy flag, GETTING_PUMPED. Without the flag it doubles the number with sla b. With the flag it was supposed to double it again, but it runs srl b, a shift to the right: it halves it.
; CriticalHitTest, pret pokered engine/battle/core.asm ld a, [wMonHBaseSpeed] ld b, a srl b ; base Speed / 2 ... bit GETTING_PUMPED, a jr nz, .focusEnergyUsed sla b ; x 2 (capped at 255) ... .focusEnergyUsed srl b ; / 2: the bug ... srl b ; / 2 again for an ordinary move ... ; or x 2, x 2 for SLASH and the others call BattleRandom rlc a rlc a rlc a ; the random byte, rotated left 3 times cp b ; a critical hit if it is below the threshold
pret's own comment on that line: "bug: using focus energy causes a shift to the right instead of left, resulting in 1/4 the usual crit chance".
So the two paths part by a factor of 4 right there: one doubles, the other halves. For Scyther, whose base Speed is 105:
| Step | Without | With Focus Energy |
|---|---|---|
| base Speed / 2 | 52 | 52 |
| the Focus Energy step | x 2 = 104 | / 2 = 26 |
| QUICK ATTACK (an ordinary move): / 2 | 52 in 256 | 13 in 256 |
| SLASH: x 2, then x 2 (capped at 255) | 255 in 256 | 104 in 256 |
The rotation at the end (rlc a three times) moves the random byte's bits around but keeps every value distinct, so it changes which bytes crit, never how many. That is why the board above has a striped pattern.
Nothing else goes in. The level, the Attack stat, stat stages and the target never touch the chance, and Speed means the species' base Speed, not the Pokemon's Speed stat. A Pokemon that used Transform takes its target's species, so it uses the target's base Speed.
All 151 Pokemon, before and after Focus Energy
Critical hits out of 256. The high critical column only matters for the Pokemon that learn one of the four high critical moves, but the game would treat any of them the same way. The fastest Pokemon lose the most: Electrode goes from 70 to 17.
| Pokemon | Base Speed | Ordinary | with FE | High crit | with FE |
|---|---|---|---|---|---|
| Bulbasaur | 45 | 22 | 5 | 176 | 44 |
| Ivysaur | 60 | 30 | 7 | 240 | 60 |
| Venusaur | 80 | 40 | 10 | 255 | 80 |
| Charmander | 65 | 32 | 8 | 255 | 64 |
| Charmeleon | 80 | 40 | 10 | 255 | 80 |
| Charizard | 100 | 50 | 12 | 255 | 100 |
| Squirtle | 43 | 21 | 5 | 168 | 40 |
| Wartortle | 58 | 29 | 7 | 232 | 56 |
| Blastoise | 78 | 39 | 9 | 255 | 76 |
| Caterpie | 45 | 22 | 5 | 176 | 44 |
| Metapod | 30 | 15 | 3 | 120 | 28 |
| Butterfree | 70 | 35 | 8 | 255 | 68 |
| Weedle | 50 | 25 | 6 | 200 | 48 |
| Kakuna | 35 | 17 | 4 | 136 | 32 |
| Beedrill | 75 | 37 | 9 | 255 | 72 |
| Pidgey | 56 | 28 | 7 | 224 | 56 |
| Pidgeotto | 71 | 35 | 8 | 255 | 68 |
| Pidgeot | 91 | 45 | 11 | 255 | 88 |
| Rattata | 72 | 36 | 9 | 255 | 72 |
| Raticate | 97 | 48 | 12 | 255 | 96 |
| Spearow | 70 | 35 | 8 | 255 | 68 |
| Fearow | 100 | 50 | 12 | 255 | 100 |
| Ekans | 55 | 27 | 6 | 216 | 52 |
| Arbok | 80 | 40 | 10 | 255 | 80 |
| Pikachu | 90 | 45 | 11 | 255 | 88 |
| Raichu | 100 | 50 | 12 | 255 | 100 |
| Sandshrew | 40 | 20 | 5 | 160 | 40 |
| Sandslash | 65 | 32 | 8 | 255 | 64 |
| Nidoran♀ | 41 | 20 | 5 | 160 | 40 |
| Nidorina | 56 | 28 | 7 | 224 | 56 |
| Nidoqueen | 76 | 38 | 9 | 255 | 76 |
| Nidoran♂ | 50 | 25 | 6 | 200 | 48 |
| Nidorino | 65 | 32 | 8 | 255 | 64 |
| Nidoking | 85 | 42 | 10 | 255 | 84 |
| Clefairy | 35 | 17 | 4 | 136 | 32 |
| Clefable | 60 | 30 | 7 | 240 | 60 |
| Vulpix | 65 | 32 | 8 | 255 | 64 |
| Ninetales | 100 | 50 | 12 | 255 | 100 |
| Jigglypuff | 20 | 10 | 2 | 80 | 20 |
| Wigglytuff | 45 | 22 | 5 | 176 | 44 |
| Zubat | 55 | 27 | 6 | 216 | 52 |
| Golbat | 90 | 45 | 11 | 255 | 88 |
| Oddish | 30 | 15 | 3 | 120 | 28 |
| Gloom | 40 | 20 | 5 | 160 | 40 |
| Vileplume | 50 | 25 | 6 | 200 | 48 |
| Paras | 25 | 12 | 3 | 96 | 24 |
| Parasect | 30 | 15 | 3 | 120 | 28 |
| Venonat | 45 | 22 | 5 | 176 | 44 |
| Venomoth | 90 | 45 | 11 | 255 | 88 |
| Diglett | 95 | 47 | 11 | 255 | 92 |
| Dugtrio | 120 | 60 | 15 | 255 | 120 |
| Meowth | 90 | 45 | 11 | 255 | 88 |
| Persian | 115 | 57 | 14 | 255 | 112 |
| Psyduck | 55 | 27 | 6 | 216 | 52 |
| Golduck | 85 | 42 | 10 | 255 | 84 |
| Mankey | 70 | 35 | 8 | 255 | 68 |
| Primeape | 95 | 47 | 11 | 255 | 92 |
| Growlithe | 60 | 30 | 7 | 240 | 60 |
| Arcanine | 95 | 47 | 11 | 255 | 92 |
| Poliwag | 90 | 45 | 11 | 255 | 88 |
| Poliwhirl | 90 | 45 | 11 | 255 | 88 |
| Poliwrath | 70 | 35 | 8 | 255 | 68 |
| Abra | 90 | 45 | 11 | 255 | 88 |
| Kadabra | 105 | 52 | 13 | 255 | 104 |
| Alakazam | 120 | 60 | 15 | 255 | 120 |
| Machop | 35 | 17 | 4 | 136 | 32 |
| Machoke | 45 | 22 | 5 | 176 | 44 |
| Machamp | 55 | 27 | 6 | 216 | 52 |
| Bellsprout | 40 | 20 | 5 | 160 | 40 |
| Weepinbell | 55 | 27 | 6 | 216 | 52 |
| Victreebel | 70 | 35 | 8 | 255 | 68 |
| Tentacool | 70 | 35 | 8 | 255 | 68 |
| Tentacruel | 100 | 50 | 12 | 255 | 100 |
| Geodude | 20 | 10 | 2 | 80 | 20 |
| Graveler | 35 | 17 | 4 | 136 | 32 |
| Golem | 45 | 22 | 5 | 176 | 44 |
| Ponyta | 90 | 45 | 11 | 255 | 88 |
| Rapidash | 105 | 52 | 13 | 255 | 104 |
| Slowpoke | 15 | 7 | 1 | 56 | 12 |
| Slowbro | 30 | 15 | 3 | 120 | 28 |
| Magnemite | 45 | 22 | 5 | 176 | 44 |
| Magneton | 70 | 35 | 8 | 255 | 68 |
| Farfetch'd | 60 | 30 | 7 | 240 | 60 |
| Doduo | 75 | 37 | 9 | 255 | 72 |
| Dodrio | 100 | 50 | 12 | 255 | 100 |
| Seel | 45 | 22 | 5 | 176 | 44 |
| Dewgong | 70 | 35 | 8 | 255 | 68 |
| Grimer | 25 | 12 | 3 | 96 | 24 |
| Muk | 50 | 25 | 6 | 200 | 48 |
| Shellder | 40 | 20 | 5 | 160 | 40 |
| Cloyster | 70 | 35 | 8 | 255 | 68 |
| Gastly | 80 | 40 | 10 | 255 | 80 |
| Haunter | 95 | 47 | 11 | 255 | 92 |
| Gengar | 110 | 55 | 13 | 255 | 108 |
| Onix | 70 | 35 | 8 | 255 | 68 |
| Drowzee | 42 | 21 | 5 | 168 | 40 |
| Hypno | 67 | 33 | 8 | 255 | 64 |
| Krabby | 50 | 25 | 6 | 200 | 48 |
| Kingler | 75 | 37 | 9 | 255 | 72 |
| Voltorb | 100 | 50 | 12 | 255 | 100 |
| Electrode | 140 | 70 | 17 | 255 | 140 |
| Exeggcute | 40 | 20 | 5 | 160 | 40 |
| Exeggutor | 55 | 27 | 6 | 216 | 52 |
| Cubone | 35 | 17 | 4 | 136 | 32 |
| Marowak | 45 | 22 | 5 | 176 | 44 |
| Hitmonlee | 87 | 43 | 10 | 255 | 84 |
| Hitmonchan | 76 | 38 | 9 | 255 | 76 |
| Lickitung | 30 | 15 | 3 | 120 | 28 |
| Koffing | 35 | 17 | 4 | 136 | 32 |
| Weezing | 60 | 30 | 7 | 240 | 60 |
| Rhyhorn | 25 | 12 | 3 | 96 | 24 |
| Rhydon | 40 | 20 | 5 | 160 | 40 |
| Chansey | 50 | 25 | 6 | 200 | 48 |
| Tangela | 60 | 30 | 7 | 240 | 60 |
| Kangaskhan | 90 | 45 | 11 | 255 | 88 |
| Horsea | 60 | 30 | 7 | 240 | 60 |
| Seadra | 85 | 42 | 10 | 255 | 84 |
| Goldeen | 63 | 31 | 7 | 248 | 60 |
| Seaking | 68 | 34 | 8 | 255 | 68 |
| Staryu | 85 | 42 | 10 | 255 | 84 |
| Starmie | 115 | 57 | 14 | 255 | 112 |
| Mr.Mime | 90 | 45 | 11 | 255 | 88 |
| Scyther | 105 | 52 | 13 | 255 | 104 |
| Jynx | 95 | 47 | 11 | 255 | 92 |
| Electabuzz | 105 | 52 | 13 | 255 | 104 |
| Magmar | 93 | 46 | 11 | 255 | 92 |
| Pinsir | 85 | 42 | 10 | 255 | 84 |
| Tauros | 110 | 55 | 13 | 255 | 108 |
| Magikarp | 80 | 40 | 10 | 255 | 80 |
| Gyarados | 81 | 40 | 10 | 255 | 80 |
| Lapras | 60 | 30 | 7 | 240 | 60 |
| Ditto | 48 | 24 | 6 | 192 | 48 |
| Eevee | 55 | 27 | 6 | 216 | 52 |
| Vaporeon | 65 | 32 | 8 | 255 | 64 |
| Jolteon | 130 | 65 | 16 | 255 | 128 |
| Flareon | 65 | 32 | 8 | 255 | 64 |
| Porygon | 40 | 20 | 5 | 160 | 40 |
| Omanyte | 35 | 17 | 4 | 136 | 32 |
| Omastar | 55 | 27 | 6 | 216 | 52 |
| Kabuto | 55 | 27 | 6 | 216 | 52 |
| Kabutops | 80 | 40 | 10 | 255 | 80 |
| Aerodactyl | 130 | 65 | 16 | 255 | 128 |
| Snorlax | 30 | 15 | 3 | 120 | 28 |
| Articuno | 85 | 42 | 10 | 255 | 84 |
| Zapdos | 100 | 50 | 12 | 255 | 100 |
| Moltres | 90 | 45 | 11 | 255 | 88 |
| Dratini | 50 | 25 | 6 | 200 | 48 |
| Dragonair | 70 | 35 | 8 | 255 | 68 |
| Dragonite | 80 | 40 | 10 | 255 | 80 |
| Mewtwo | 130 | 65 | 16 | 255 | 128 |
| Mew | 100 | 50 | 12 | 255 | 100 |
Which games have it
- Red, Blue and Yellow: the same routine, byte for byte (I compared Yellow's
CriticalHitTestwith Red's in pret's disassemblies, and ran both games). - The Japanese Red and Green: the same
srl bis in pret's disassembly of Green. I read it there; I did not run it. - Gold, Silver and Crystal: fixed. Their routine,
BattleCommand_Criticalin pret's Crystal disassembly (engine/battle/effect_commands.asm), adds one to a critical hit stage when the Focus Energy flag is set.
How I checked it
- Read:
CriticalHitTestand its listHighCriticalMovesin pret's pokered and pokeyellow, andItemUseDireHit(engine/items/item_effects.asm), which sets the sameGETTING_PUMPEDflag. - Run in the game: battles in Red and in Yellow under the PyBoy emulator, with the battler's battle oracle choosing the random bytes. Scyther used SLASH and QUICK ATTACK before and after Focus Energy, with the byte set so its rotation was one under each threshold (a critical hit) and exactly at it (none): 254 and 51 before, 103, 104, 12 and 13 after. A slow Slowbro (base Speed 30) did the same with WATER GUN: 15 before, 3 after, and its second Focus Energy failed. The game and the battler's engine agreed on every byte, message and battle state.
- The calculator and the table on this page use the same arithmetic as the battler's engine, and a test compares them for all 151 Pokemon, both kinds of move, with and without Focus Energy.
- Not tested: anything on a real Game Boy, and Dire Hit in a running game (it is read from the code only).
Questions
Does Focus Energy work in Pokemon Red and Blue?
No. In Pokemon Red, Blue and Yellow, Focus Energy lowers your critical hit chance to about a quarter of what it was. The game's CriticalHitTest routine shifts a number right where it should shift it left, so the chance is halved instead of doubled. Scyther's Slash drops from 255 in 256 to 104 in 256, and its Quick Attack from 52 in 256 to 13 in 256.
What does Dire Hit do in Gen 1?
The same as Focus Energy. The Dire Hit item sets the very same flag in battle (ItemUseDireHit sets GETTING_PUMPED), so it lowers your critical hit chance to about a quarter too. It wears off when the Pokemon switches out.
How is the critical hit chance worked out in Gen 1?
Only from the attacker's base Speed and the move. An ordinary move crits when a random byte, rotated left three times, is below half the base Speed, so the chance is base Speed / 2 out of 256. Karate Chop, Razor Leaf, Crabhammer and Slash use 8 times that, capped at 255 out of 256. Level, stat changes and the target do not count.
Was the Focus Energy bug ever fixed?
Yes, in Gold, Silver and Crystal. Their critical hit routine (BattleCommand_Critical in pret's disassembly) adds one to a critical hit stage when Focus Energy is up, so it raises the chance as intended.
Does a second Focus Energy make it worse?
No. The flag can only be set once: a second Focus Energy says But, it failed! and changes nothing. The chance stays at its lowered value until the Pokemon switches out or Haze clears the flag.
Was this tested on a real Game Boy?
No. I read the routine in pret's disassembly of Red, Blue and Yellow, and ran it in the game's own code in the PyBoy emulator: battles where the random byte was set just under and just at each threshold, before and after Focus Energy, in Red and in Yellow. Every one matched the battler's engine.