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

Cause of inverted sprites - Page 1

Cause of inverted sprites

Posted by: Nerator
Date: 2014-05-05 05:23:35
I decided to look at the cause of inverted (flipped) sprite phenomenon, which takes place after viewing front sprite of some glitch pokemon. I didn't see this documented or looked at anywhere, so if i missed it and it was, i apologize.

Actually, it's not so complicated, as thought it will be. There is an adress in RAM which tells the game if sprite should be flipped or not - 0xd0aa (0xd0a9 in Yellow). If it's 0x00, game displays not flipped sprites like in battle. If it's anything but 0x00, game displays flipped sprites like in Pokedex.

So what exactly causes this address to become not 0x00? Viewing pokedex entry of some glitch pokemon. To be exact, entries with wrong Pokedex number (00 or >151). The answer lies in this piece of code taken from iimarckus' disasm with my comments and key parts in bold.

LoadFlippedFrontSpriteByMonIndex: ; 1384 (0:1384)
ld a, $1
ld [W_SPRITEFLIPPED], a ; ld (d0aa, 1) or set flipped sprite

LoadFrontSpriteByMonIndex: ; 1389 (0:1389)
push hl
ld a, [$d11e]
push af
ld a, [$cf91]
ld [$d11e], a
ld a, $3a
call Predef ; indirect jump to IndexToPokedex (41010 (10:5010))
ld hl, $d11e
ld a, [hl]
pop bc
ld [hl], b
and a ; set zero flag, if a=0
pop hl
jr z, .invalidDexNumber  ; dex #0 invalid
cp $98 ; set carry flag, if a<152
jr c, .validDexNumber
  ; dex >#151 invalid
ld a, RHYDON ; $1
ld [$cf91], a
push hl
ld de, $9000
call LoadMonFrontSprite
pop hl
push af
ld a, $f
ld [$2000], a
xor a
ld [$FF00+$e1], a
call asm_3f0d0
xor a ; same as ld a, 0
ld [W_SPRITEFLIPPED], a ; ld (d0aa), 0 or set sprite unflipped

pop af
ld [$2000], a

So, what can we see here? The game loads LoadFlippedFrontSpriteByMonIndex subroutine, when displayng front sprite in Pokedex, in stats screen or when new pokemon is captured. If Pokedex entry of pokemon is valid (1-151), then game sets 0xd0aa, loads sprite and then resets it to 0. All good. This is the cause of sprites returning back to normal after viewing Pokedex entry or stats of non-glitch pokemon.

But what happens, if Pokedex entry is not valid? Basically, game does not reset 0xd0aa, it only loads 0x1 to 0xcf91 (i think this address stores pokemon or item IDs for some subroutines) and returns back.

I think that's all what i have to say about it. If you think i missed something, feel free to comment, i'll try to look at it asap.

Re: Cause of inverted sprites

Posted by: Torchickens
Date: 2014-05-05 08:58:28
Nice work, thanks.  :)