’Cause all games were better on the GBC

You are not logged in.

#1 2013-02-03 19:21:28

From: Somewhere in Johto
Registered: 2011-08-10
Post 263/410

Adding Completely New Tile Animations to Gold

Basically, I found this other GBC game that want to copy the animated tiles from over to Gold.  I have already extracted the tiles from the other game, but what I would like to know is where to insert them in Gold (like what bank), and how I would make a new animation instruction for displaying those tiles (if possible)? Or would I have to replace existing animation instructions?

I'm pretty sure my question is pretty hard to understand, but I'm wasn't exactly sure how to word it.

Last edited by Munchulax (2013-02-03 19:22:56)

“To live is the rarest thing in the world. Most people exist, that is all.” ― Oscar Wilde


#2 2013-02-03 21:15:16

Registered: 2012-04-09
Post 118/672

Re: Adding Completely New Tile Animations to Gold

The animations for tileset 0 are a good example, at $fc01e (2f:401e).

;      param, function
    dw $9140, AnimateWaterTile
    dw $0000, WaitTileAnimation
    dw $0000, WaitTileAnimation
    dw $0000, WaitTileAnimation
    dw $0000, TileAnimationPalette
    dw $0000, WaitTileAnimation
    dw $0000, AnimateFlowerTile
    dw $0000, WaitTileAnimation
    dw $0000, WaitTileAnimation
    dw $0000, NextTileFrame8
    dw $0000, DoneTileAnimation

You can see that this loop animates water, flowers and changes a pallete (in this case, it's water's).

One function = one frame. DoneTileAnimation resets the loop. NextTileFrame8 means that the animation's counter loops from 0-7 (8 frames total).

The parameter is typically a VRAM address for the tile(s) that you're writing to. The current tileset starts from $9000, and each tile is $10 bytes. A quick way to figure out which tile you're on is to take the middle 2 digits. For $9140, the middle digits are $14, so we're on the 20th tile.

AnimateFlowerTile assumes that the flower is always at the same tile, so it doesn't take any parameters.

A standard function works by checking $cf42 (TileAnimationTimer) and getting the right tile based on which part of the animation we're on. The actual change is made by jumping to WriteAnimationTile ($fc4c7). There are a couple requirements for using this function.

Let's look at the water animation:

AnimateWaterTile: ; fc406
; draw a tile for a given frame into vram
; hl: vram tile address (dest)
; save sp in bc
    ld hl, sp+$0
    ld b, h
    ld c, l

WriteAnimationTile ends by replacing the stack pointer (sp) with bc. Putting the stack pointer in bc in the first place needs to happen or everything will break.

; get frame
    ld a, [TileAnimationTimer]
; 4 possible values -> 4 tiles
    and %110 ; 0, 2, 4, 6
; # bytes from starting location
; 2 x 8 = 16 bytes per tile
    add a ;
    add a ; x8
    add a ;

The water tile changes once every 20 frames. From before, the TileAnimationTimer for tileset 0 loops over 8 animation counts (10 frames each). Since the rate is halved, the number of bytes per tile is implicitly doubled, so we only need to multiply the current frame by 8 to get the current tile.

; add to start address
    add WaterTileFrames & $ff
    ld l, a
    ld a, $0
    adc WaterTileFrames / $100
    ld h, a
; sp is now sitting at the start of the tile for this frame
    ld sp, hl
    ld l, e
    ld h, d
    jp WriteAnimationTile
; fc420

The reason we had to save sp in bc is that WriteAnimationTile uses the stack to update the tile as quickly as possible, since writing to VRAM is time-sensitive.

The tile graphics for water animations are right after:

WaterTileFrames: ; fc420
; frame 0-3
INCBIN "gfx/tilesets/water.2bpp"
; fc460

And that's pretty much all there is to tile animations. I haven't looked for the pointer table yet but it should be in the same bank.

Last edited by comet (2013-02-03 21:20:10)


#3 2013-02-05 23:50:20

From: Somewhere in Johto
Registered: 2011-08-10
Post 267/410

Re: Adding Completely New Tile Animations to Gold

Okay, I think I get tile animations a lot better now.  If I have any other questions, I'll be sure to ask.  Thanks for your help.

(If you're wondering why it took me so long to reply, it's because I was studying ASM so that I could understand the post :P)

Last edited by Munchulax (2013-02-05 23:50:45)

“To live is the rarest thing in the world. Most people exist, that is all.” ― Oscar Wilde


Board footer

Powered by FluxBB