Focus Energy glitch: Difference between revisions
Jump to navigation
Jump to search
Content added Content deleted
m (→Ambiguity: Fixed spelling.) |
m (→Analysis: Use <syntaxhighlight> tags for assembly code.) |
||
Line 8: | Line 8: | ||
The relevant block of code for Focus Energy's effect is this<ref>[https://github.com/pret/pokered/blob/bb76c06120bcd1fc0f86bd3cc96cbbde93c0c80c/engine/battle/core.asm#L4610-L4619 The same block of code in the pokered disassembly]</ref>, beginning at offset 3E055 in Pokémon Red and Blue (view 0F:6055 in a debugger). Thanks Wack0 for walking through this. |
The relevant block of code for Focus Energy's effect is this<ref>[https://github.com/pret/pokered/blob/bb76c06120bcd1fc0f86bd3cc96cbbde93c0c80c/engine/battle/core.asm#L4610-L4619 The same block of code in the pokered disassembly]</ref>, beginning at offset 3E055 in Pokémon Red and Blue (view 0F:6055 in a debugger). Thanks Wack0 for walking through this. |
||
<syntaxhighlight lang="asm"> |
|||
bit 2, a ; test for focus energy |
|||
jr nz, .focusEnergyUsed |
|||
sla b ; b=b*2 |
|||
jr nc, .noFocusEnergyUsed ; if b was below 128, skip... |
|||
ld b, $ff ; a cap at 255/256 |
|||
jr .noFocusEnergyUsed |
|||
.focusEnergyUsed |
|||
srl b ; whoops! b=b/2, and if you look, the jump to here is before the b=b*2, so b is effectively 1/4 of what it should be |
|||
.noFocusEnergyUsed ; no cap at 255/256 for focus energy. I wonder if, if done properly, this would have caused bugs related to integer wraparound... |
|||
; ... (check for high critical hit move here) |
|||
</syntaxhighlight> |
|||
The relative jump to '.focusEnergyUsed' that happens when Focus Energy is used makes the game skip a 'sla b' (double b), and then a 'srl b' (half b) at '.focusEnergyUsed' halves the value in register 'b'. |
The relative jump to '.focusEnergyUsed' that happens when Focus Energy is used makes the game skip a 'sla b' (double b), and then a 'srl b' (half b) at '.focusEnergyUsed' halves the value in register 'b'. |