Cite as
pret/pokecrystal
Original
https://github.com/pret/pokecrystal
Pinned
pret/pokecrystal @ 97187cd21b15e9a266a786318c851848f2fac24b
Accessed
2026-10-20
Licence
none stated (no LICENSE file; GitHub reports no license)
Credit
The pret community, about 92 GitHub contributors (2026-10-20), led in commit count by yenatch, Rangi42, kanzure, roukaour and PikalaxALT. See https://github.com/pret/pokecrystal/graphs/contributors. Its docs/bugs_and_glitches.md catalogues known bugs with fixes.
Notes
Builds the English (UE) Crystal ROMs v1.0 and v1.1 and the Australian release (README, roms.sha1), not Gold/Silver (pret/pokegold is a separate project, not read here).

Cited on

Claims (53)

The game sets the STAT interrupt to fire at every horizontal blank, and the handler copies the byte for the current line from a 144-entry table into whichever video register a pointer in high RAM names; while that pointer is 0 the handler does nothing. The handler runs in the horizontal blank after line LY, so entry n takes effect from line n + 1, and line 0 shows the register's value from before the frame (the Magnet Train writes its top band's scroll to hSCX for that line).home/init.asm L111–112home/header.asm L46–47home/lcd.asm L12–31ram/wram.asm L3628constants/hardware.inc L997Code
On the Magnet Train ride the scenery in the screen's top and bottom bands scrolls 4 pixels a frame, while the middle band, the train's, scrolls 1 pixel a frame to a hold point, pauses, then 2 a frame to its stop. Each frame the ride sets a horizontal scroll value for every screen line, in three bands of 47, 48, and 49 lines; the top and bottom bands take twice an offset that moves 2 a frame, and the middle band takes the train's position.engine/events/magnet_train.asm L86–114engine/events/magnet_train.asm L229–240engine/events/magnet_train.asm L1–23engine/events/magnet_train.asm L274–289engine/events/magnet_train.asm L317–346engine/events/magnet_train.asm L352–365engine/events/magnet_train.asm L42–53constants/hardware.inc L1008Code
A wild Pokémon's catch rate is its species' catch-rate byte, copied into the wild Pokémon's battle data when the battle loads it (45 for Bulbasaur).engine/battle/core.asm L6383–6385data/pokemon/base_stats/bulbasaur.asm L7Code
The Poké Ball item routine catches outright with a Master Ball or in the catching tutorial. Otherwise a ball's routine changes the catch rate: the Ultra Ball doubles it, and the Great, Safari, and Park Balls add half of it, each capped at 255. The Poké Ball has no routine and leaves it as it is.engine/items/item_effects.asm L242–270engine/items/item_effects.asm L722–754Code
For a Pokémon with max HP over 341 the catch formula breaks: when 3M is 256 or more, for max HP M and current HP H, the ball routine first divides both 3M and 2H by 4 (a quartered 2H of 0 becomes 1) and keeps only each low byte. Except with a Level Ball, it scales the ball-modified rate C′ by HP: X=max⁡(⌊C′(3M−2H)/3M⌋,1).engine/items/item_effects.asm L272–338Code
The Level Ball doubles the catch rate when the player's Pokémon is higher in level than the wild one, quadruples it when half the player's level is still higher, and multiplies it by 8 when a quarter is, capped at 255. It then skips the HP and status steps: its final rate is that multiplied catch rate alone.engine/items/item_effects.asm L1036–1057engine/items/item_effects.asm L272–276Code
Crystal adds 10 to X for a sleeping or frozen Pokémon, capped at 255, and nothing for burn, poison, or paralysis: the test meant to add 5 for them reads a value the sleep-and-freeze mask has already cleared. Gold and Silver have the same code, and their disassembly notes that those three statuses were meant to rank between sleep and none.engine/items/item_effects.asm L339–355Code
The final rate is stored, and one random byte at most that rate catches, so the chance is (X+1)/256 and a final rate of 255 always catches. This one roll decides the throw; the wobbles come after.engine/items/item_effects.asm L372–386Code
Computed, counting every value of the roll as equally likely: a Bulbasaur (catch rate 45) with max HP 100 and no status in a Poké Ball has a final rate of 15 at full HP, so 16 in 256 (6.25%), and 44 at 1 HP, so 45 in 256 (17.6%).engine/items/item_effects.asm L278–338engine/items/item_effects.asm L372–380data/pokemon/base_stats/bulbasaur.asm L7Code
The ball's wobbles are drawn after the throw is decided. A caught Pokémon always gets three. On a failed throw, each of up to three wobbles happens with chance p/256, where p is read from the first row of the wobble table whose catch rate is at least the final rate (63 for a rate of 1, up to 255 for 255). The table's comment gives the left column over 255 as the right column over 255 to the fourth power, so each p is a fourth root, p/255=(𝑟𝑎𝑡𝑒/255)1/4.engine/battle_anims/pokeball_wobble.asm L1–44data/battle/wobble_probabilities.asm L1–27Code
Gold and Silver run the same capture code as Crystal: from the catch-rate load to the final roll, the ball routine differs only in comments, and the wobble table is identical.engine/items/item_effects.asm L242–382data/battle/wobble_probabilities.asm L1–27Code
Crystal's type chart has 108 non-neutral rows over 17 types, then a -2 marker, Normal→Ghost and Fighting→Ghost ×0, and a -1 end.data/types/type_matchups.asm L1–118constants/type_constants.asm L7–37Code
Multipliers are unchanged from Red/Blue: scaled by 10, with 20 for “super effective”, 05 for “not very effective”, 00 for no effect, and 10 for effective.constants/battle_constants.asm L20–25Code
Crystal's type constants add Steel (physical), Dark (special), and an unused curse type named “???”; the Bird type remains, still with no rows.constants/type_constants.asm L9–37data/types/names.asm L37Code
The STAB battle command applies weather and badge type boosts, then STAB (damage+⌊damage/2⌋ if either attacker type matches), then the type chart.engine/battle/effect_commands.asm L1251–1288Code
A comment in pokecrystal's STAB battle command expands STAB as “Same Type Attack Bonus”.engine/battle/effect_commands.asm L1214–1215Code
Struggle returns from the STAB battle command at once, so it skips weather, badge boosts, STAB, and the type chart.engine/battle/effect_commands.asm L1216–1219Code
Each type chart row matching the move's type and either defender type computes damage×value; a nonzero product becomes ⌊product/10⌋, raised to 1 if that truncates to 0, and a zero product stays 0.engine/battle/effect_commands.asm L1291–1379ram/hram.asm L66–82Code
In Crystal, a ×0 type chart row makes the move miss as soon as it matches, where Red and Blue mark a miss only when the damage reaches 0.engine/battle/effect_commands.asm L1329–1336constants/battle_constants.asm L25Code
A ×¼ hit no longer truncates to a miss: 2 damage through two ½ rows gives ⌊2 × 5 / 10⌋ = 1, then ⌊1 × 5 / 10⌋ = 0, raised to 1.engine/battle/effect_commands.asm L1361–1373constants/battle_constants.asm L24Code
Against a target hit by Foresight, the type chart is read only up to an end marker placed before the Normal-against-Ghost and Fighting-against-Ghost immunities, so those two rows are skipped.engine/battle/effect_commands.asm L1302–1310data/types/type_matchups.asm L112–118engine/battle/move_effects/foresight.asm L1–14Code
After the loop, the type matchup check's combined value (m=⌊m×row/10⌋ from 10) replaces the effectiveness byte, so the text reflects every row: ×4 is 40, ×¼ is 2, and ½ with 2× is 10.engine/battle/effect_commands.asm L1388–1396engine/battle/effect_commands.asm L1405–1471engine/battle/effect_commands.asm L2324–2333engine/battle/effect_commands.asm L2197–2202Code
An Ice move against a Water/Flying Pokémon prints no effectiveness message in Crystal: the message reads a combined value that starts at 10 and is multiplied by each matching row's value and divided by 10, here 10 → 5 → 10.data/types/type_matchups.asm L35–39constants/battle_constants.asm L21–24engine/battle/effect_commands.asm L1416–1464engine/battle/effect_commands.asm L1388–1395engine/battle/effect_commands.asm L2324–2328Code
As in Red and Blue, row order matters: an Ice move against a Water/Flying Pokémon takes 3 damage to ⌊3 × 5 / 10⌋ = 1 at the ½ row, then to ⌊1 × 20 / 10⌋ = 2 at the 2× row, not 3.data/types/type_matchups.asm L35–39constants/battle_constants.asm L21–24Code
Crystal's type chart makes Ghost-type moves super effective on Psychic types.data/types/type_matchups.asm L94Code
Crystal's table adds Steel and Dark and changes four Red/Blue matchups: Poison→Bug ×2 → ×1, Bug→Poison ×2 → ×½, Ghost→Psychic ×0 → ×2, and Ice→Fire ×1 → ×½.data/types/type_matchups.asm L1–118constants/battle_constants.asm L21–25Code
Type still picks the stats: Steel is physical (numbered below the first special type); Dark is special, using Special Attack against Special Defense.engine/battle/effect_commands.asm L2543–2545constants/type_constants.asm L9–35Code
A plain damaging move takes these steps in order: the critical-hit roll; loading the attacking and defending stats; the base damage formula, then held-item type boosts and the critical ×2; then weather, badge type boosts, the same-type ×1.5, and the type chart rows; then the random factor; and last the accuracy check.data/moves/effects.asm L5–14data/battle/effect_command_pointers.asm L12–16engine/battle/effect_commands.asm L1201–1205engine/battle/effect_commands.asm L2525–2533engine/battle/effect_commands.asm L2943–3023engine/battle/effect_commands.asm L3108–3116engine/battle/effect_commands.asm L1251–1296engine/battle/misc.asm L147–181engine/battle/effect_commands.asm L1496–1497engine/battle/effect_commands.asm L1546Code
As in Red and Blue, damage is multiplied by a random byte from 217 to 255 and divided by 255, and 0 or 1 damage is left untouched.engine/battle/effect_commands.asm L1503–1536macros/data.asm L23Code
The critical-hit battle command sums a critical level, +1 for Focus Energy, +2 for a high-critical move, and +1 for a Scope Lens, then rolls against 17, 32, 64, 85, or 128 in 256 for levels 0 to 4; Chansey with a Lucky Punch and Farfetch'd with a Stick get level 2 and skip the other bonuses.engine/battle/effect_commands.asm L1120–1207data/battle/critical_hit_chances.asm L1–8data/moves/critical_hit_moves.asm L1–9macros/data.asm L25–26Code
A critical hit doubles the damage after held-item boosts and before the cap at 997 and the final +2. Unless the attacker's attacking-stat stage is higher than the defender's defending-stat stage, it also uses both Pokémon's stats without stages, which drops Reflect and Light Screen; pret's comment asks for the defender's stage to be higher, but the code takes this path at equal stages too.engine/battle/effect_commands.asm L2983–3028engine/battle/effect_commands.asm L3087–3098engine/battle/effect_commands.asm L3108–3120engine/battle/effect_commands.asm L2660–2701engine/battle/effect_commands.asm L2548–2592engine/battle/effect_commands.asm L2797–2835engine/battle/core.asm L6688–6694Code
The hit-check battle command scales the accuracy byte by the accuracy and evasion stages, subtracts 20 if the target holds a BrightPowder, and then hits on a random byte below it; an accuracy of 255 always hits.engine/battle/effect_commands.asm L1584–1608data/battle/accuracy_multipliers.asm L1–17data/items/attributes.asm L15–16Code
The battle command that ends a multi-hit loop gives 2–5 hits with Red and Blue's odds and Triple Kick 1–3 hits, 1/3 each, and jumps back to the critical-hit command, so every hit rolls its own critical and damage; the hit check sits before the loop and runs once.engine/battle/effect_commands.asm L5203–5284engine/battle/effect_commands.asm L5320–5328data/moves/effects.asm L842–851Code
Crystal's random-number routine is Red and Blue's generator, adding the divider register (with carry) to one byte and subtracting it (with borrow) from a second, but it returns the second where Red and Blue's returns the first; pret's comment says the divider counts at 16,384 Hz.home/random.asm L1–29Code
On each step, the wild encounter check starts a battle when a random byte is below the map's rate for the time of day (morning, day, or night) or its water rate; the Pokémon March or Ruins of Alph radio doubles the rate, and the Pokémon Lullaby or a Cleanse Tag in the party halves it.engine/overworld/wildmons.asm L195–250data/wild/johto_grass.asm L1237–1238Code
A second random number from 1 to 100 picks one of a grass area's 7 slots, at 30, 30, 20, 10, 5, 4, and 1 percent, or one of 3 water slots at 60, 30, and 10 percent.data/wild/probabilities.asm L6–21engine/overworld/wildmons.asm L274–278Code
In an ordinary wild battle Crystal keeps Red and Blue's escape formula. With P the player's Pokémon's Speed and E the foe's, P≥E escapes; otherwise the player escapes when a random byte is at most ⌊32P/(⌊E/4⌋mod256)⌋ plus 30 for each earlier attempt, or at once when the divisor ⌊E/4⌋mod256 is 0 or the sum passes 255. A held Smoke Ball always escapes, and the foe's Mean Look or a trapping move holding the player prevents it.engine/battle/core.asm L3680–3710engine/battle/core.asm L3714–3728data/items/attributes.asm L221–222engine/battle/core.asm L3730–3791engine/battle/core.asm L5310–5312home/compare.asm L1–7data/moves/moves.asm L228data/moves/effects.asm L1452–1456engine/battle/effect_commands.asm L6285–6300data/moves/moves.asm L51engine/battle/effect_commands.asm L5612–5638Code
Crystal ranks moves by priority: 3 for Protect, Detect, and Endure, 2 for Quick Attack, Mach Punch, and ExtremeSpeed, 1 for most moves, and 0 for Roar, Whirlwind, Counter, Mirror Coat, and Vital Throw; at equal priority a held Quick Claw goes first on a random byte below 60, then higher Speed, then a coin flip.engine/battle/core.asm L477–555engine/battle/core.asm L829–854data/moves/effects_priorities.asm L1–8data/items/attributes.asm L155–156macros/data.asm L23constants/battle_constants.asm L17–18data/moves/moves.asm L14–267Code
Crystal's Rain Dance, Sunny Day, and weather tables match Gold's: Rain Dance and Sunny Day set rain or sun for 5 turns, and in rain a Water move does ×1.5 and a Fire move ×½, in sun the reverse.engine/battle/move_effects/rain_dance.asm L1–5engine/battle/move_effects/sunny_day.asm L1–5data/battle/weather_modifiers.asm L1–5constants/battle_constants.asm L22–24engine/battle/misc.asm L52–120Code
Computed, for a Bulbasaur (catch rate 45) with max HP 100 and no status in a Poké Ball: at full HP it is caught about 6.0% of the time in Red and Blue, 6.25% in Crystal, and 6.25% in Emerald; at 1 HP, 18.0%, 17.6%, and 19.8%. Here the three formulas land close together, though they roll twice in Red and Blue, once in Crystal, and up to four times in Emerald.engine/items/item_effects.asm L289–338engine/items/item_effects.asm L372–380data/pokemon/base_stats/bulbasaur.asm L7Code
Computed by comparing the two tables row by row: Emerald's type table holds the same 110 rows as Crystal's, in the same order, so no type is new and no matchup changed.data/types/type_matchups.asm L1–118Code
Gold and Silver already use the staged critical hit that Crystal keeps line for line: Focus Energy (+1), a high-critical move (+2), and a Scope Lens (+1) add to a critical level, which reads 17, 32, 64, 85, or 128 in 256 from a table. Chansey holding a Lucky Punch and Farfetch'd holding a Stick get level 2 at once and skip the other bonuses.engine/battle/effect_commands.asm L1120–1213Code
Gold and Silver's hit-check command, which Crystal keeps unchanged, subtracts a target's BrightPowder value (20) from the stage-scaled accuracy byte, lets a byte of 255 always hit, and otherwise hits on a random byte below it.engine/battle/effect_commands.asm L1546–1850Code
Gold and Silver's type chart already has the 17 types (computed from the type constants), Steel and Dark included, and Ghost's ×2 on Psychic (a factor of 20 over 10), so these date from Gold and Silver; Crystal's chart has these rows too.data/types/type_matchups.asm L1–118Code
Gold and Silver's same-type bonus command, which Crystal keeps unchanged, applies the weather and badge type boosts and then STAB, damage+⌊damage/2⌋, before the type rows.engine/battle/effect_commands.asm L1214–1397Code
Gold and Silver's damage-variation command leaves 0 or 1 damage alone and otherwise multiplies by a random byte, rotated, redrawn until it is at least 217 (85 percent + 1), and divides by 255 (100 percent); Crystal keeps the command unchanged. Their damage-calculation command differs from Crystal's only in comments and one doubling written sla a where Crystal has add a.engine/battle/effect_commands.asm L3113–3115engine/battle/effect_commands.asm L1496–1545Code
Gold and Silver's loop-end command, which Crystal keeps apart from a comment, loops back to the critical command for every hit of a 2–5-hit move, so each hit rolls its own critical and damage.engine/battle/effect_commands.asm L5203–5335Code
On each step, Gold and Silver's wild-encounter check reads the map's encounter rate for the current time of day (morning, day, or night), or its water rate, doubles it for the Pokémon March or Ruins of Alph radio, halves it for the Pokémon Lullaby or a Cleanse Tag, and starts a battle when a random byte is below it; Crystal keeps this unchanged.engine/overworld/wildmons.asm L176–251Code
The time of day picks which of a grass area's three sets of 7 slots is used; a roll from 1 to 100 then picks a slot at 30, 30, 20, 10, 5, 4, and 1 percent, or one of 3 water slots at 60, 30, and 10 percent. Crystal's routine and table are the same.data/wild/probabilities.asm L6–21engine/overworld/wildmons.asm L252–348Code
Gold and Silver's escape formula is Red and Blue's, ⌊32P/(⌊E/4⌋mod256)⌋ plus 30 for each earlier attempt against a random byte, with a held Smoke Ball that always escapes; Crystal adds two battle types, Celebi's and Suicune's, that block escape.engine/battle/core.asm L3689–3694Code
In HeartGold and SoulSilver the Apricorn balls change the catch rate itself and leave the multiplier at 10, after which the rate is capped at 255 (a negative one becomes 1) and goes through the usual HP and status steps: the Fast Ball ×4 when the wild species' base Speed is 100 or more, the Level Ball ×2 when the attacking battler's level is above the wild Pokémon's, ×4 when half its level (rounded down) is above it, and ×8 when a quarter of its level (rounded down) is, the Lure Ball ×3 when fishing, the Love Ball ×8 for the same species of the opposite gender, and the Moon Ball ×4 for the 14 species of the Nidoran, Clefairy, Jigglypuff, and Skitty families listed in an assembly data table. Crystal's Level Ball skips the HP and status steps, and its disassembly's comments mark the Moon Ball as never boosting, the Love Ball as boosting the same gender, and the Fast Ball as boosting only three species.engine/items/item_effects.asm L272–276engine/items/item_effects.asm L917–925engine/items/item_effects.asm L977–982engine/items/item_effects.asm L1001–1008Code
In HeartGold and SoulSilver a Heavy Ball takes 20 off the catch rate of every Pokémon under 204.8 kg (a result below 0 becomes 1), because its last branch tests the catch rate against 1024 instead of the weight; a comment in the decompilation calls this a mistake. The catch rate there is the species' base catch rate, a byte, so at most 255. The ball adds 40 to the catch rate at 409.6 kg or more, 30 at 307.2 kg, and 20 at 204.8 kg, reading weight in tenths of a kilogram from the Pokédex data. Crystal subtracts 20 only below 102.4 kg and adds nothing from there to 204.8 kg.engine/items/item_effects.asm L779–784engine/items/item_effects.asm L843–870Code
Ruby and Sapphire's type chart holds the same 110 rows as Emerald's and Crystal's, in the same order, with literal 0xFE and 0xFF bytes where Emerald names them as constants.data/types/type_matchups.asm L1–118Code