summaryrefslogtreecommitdiff
path: root/engine/tilesets
diff options
context:
space:
mode:
authormid-kid <esteve.varela@gmail.com>2018-03-25 16:18:33 +0200
committermid-kid <esteve.varela@gmail.com>2018-03-25 16:18:33 +0200
commit0d9241889fc8a2f047b9fd6db25e55de1e721877 (patch)
tree4ae588ae9d97639b456e6d2ba64a94676ddcf703 /engine/tilesets
parent60e21a86638cad5fd25133cda1c545461304d902 (diff)
Organize the engine/ directory, take 3
Renamed `title` to `movies`. Moved some functions from `engine/routines/` to their fitting directories, and cleaned up the base `engine/` directory. Moved `engine/pokemon/tmhm.asm` back to `engine/items/`. Made a new subdirectory: * engine/tilesets: Contains all map-related graphics routines.
Diffstat (limited to 'engine/tilesets')
-rw-r--r--engine/tilesets/map_palettes.asm86
-rw-r--r--engine/tilesets/mapgroup_roofs.asm20
-rw-r--r--engine/tilesets/tileset_anims.asm1060
-rw-r--r--engine/tilesets/tileset_palettes.asm151
-rw-r--r--engine/tilesets/timeofdaypals.asm415
5 files changed, 1732 insertions, 0 deletions
diff --git a/engine/tilesets/map_palettes.asm b/engine/tilesets/map_palettes.asm
new file mode 100644
index 000000000..a9d2b382f
--- /dev/null
+++ b/engine/tilesets/map_palettes.asm
@@ -0,0 +1,86 @@
+SwapTextboxPalettes:: ; 4c000
+ hlcoord 0, 0
+ decoord 0, 0, wAttrMap
+ ld b, SCREEN_HEIGHT
+.loop
+ push bc
+ ld c, SCREEN_WIDTH
+.innerloop
+ ld a, [hl]
+ push hl
+ srl a
+ jr c, .UpperNybble
+ ld hl, wTilesetPalettes
+ add [hl]
+ ld l, a
+ ld a, [wTilesetPalettes + 1]
+ adc 0
+ ld h, a
+ ld a, [hl]
+ and $f
+ jr .next
+
+.UpperNybble:
+ ld hl, wTilesetPalettes
+ add [hl]
+ ld l, a
+ ld a, [wTilesetPalettes + 1]
+ adc 0
+ ld h, a
+ ld a, [hl]
+ swap a
+ and $f
+
+.next
+ pop hl
+ ld [de], a
+ res 7, [hl]
+ inc hl
+ inc de
+ dec c
+ jr nz, .innerloop
+ pop bc
+ dec b
+ jr nz, .loop
+ ret
+
+ScrollBGMapPalettes:: ; 4c03f
+ ld hl, wBGMapBuffer
+ ld de, wBGMapPalBuffer
+.loop
+ ld a, [hl]
+ push hl
+ srl a
+ jr c, .UpperNybble
+
+; .LowerNybble
+ ld hl, wTilesetPalettes
+ add [hl]
+ ld l, a
+ ld a, [wTilesetPalettes + 1]
+ adc 0
+ ld h, a
+ ld a, [hl]
+ and $f
+ jr .next
+
+.UpperNybble:
+ ld hl, wTilesetPalettes
+ add [hl]
+ ld l, a
+ ld a, [wTilesetPalettes + 1]
+ adc 0
+ ld h, a
+ ld a, [hl]
+ swap a
+ and $f
+
+.next
+ pop hl
+ ld [de], a
+ res 7, [hl]
+ inc hl
+ inc de
+ dec c
+ jr nz, .loop
+ ret
diff --git a/engine/tilesets/mapgroup_roofs.asm b/engine/tilesets/mapgroup_roofs.asm
new file mode 100644
index 000000000..58e5e7cfe
--- /dev/null
+++ b/engine/tilesets/mapgroup_roofs.asm
@@ -0,0 +1,20 @@
+LoadMapGroupRoof:: ; 1c000
+ ld a, [wMapGroup]
+ ld e, a
+ ld d, 0
+ ld hl, MapGroupRoofs
+ add hl, de
+ ld a, [hl]
+ cp -1
+ ret z
+ ld hl, Roofs
+ ld bc, 9 tiles
+ call AddNTimes
+ ld de, vTiles2 tile $0a
+ ld bc, 9 tiles
+ call CopyBytes
+ ret
+; 1c021
+
+
+INCLUDE "data/maps/roofs.asm"
diff --git a/engine/tilesets/tileset_anims.asm b/engine/tilesets/tileset_anims.asm
new file mode 100644
index 000000000..bf0037e65
--- /dev/null
+++ b/engine/tilesets/tileset_anims.asm
@@ -0,0 +1,1060 @@
+_AnimateTileset:: ; fc000
+; Iterate over a given pointer array of
+; animation functions (one per frame).
+
+; Typically in wra1, vra0
+
+ ld a, [wTilesetAnim]
+ ld e, a
+ ld a, [wTilesetAnim + 1]
+ ld d, a
+
+ ld a, [hTileAnimFrame]
+ ld l, a
+ inc a
+ ld [hTileAnimFrame], a
+
+ ld h, 0
+ add hl, hl
+ add hl, hl
+ add hl, de
+
+; 2-byte parameter
+; All functions take input de.
+ ld e, [hl]
+ inc hl
+ ld d, [hl]
+ inc hl
+
+; Function address
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+
+ jp hl
+; fc01b
+
+Tileset0Anim: ; 0xfc01b
+TilesetJohtoModernAnim: ; 0xfc01b
+TilesetKantoAnim: ; 0xfc01b
+ dw vTiles2 tile $14, AnimateWaterTile
+ dw NULL, WaitTileAnimation
+ dw NULL, WaitTileAnimation
+ dw NULL, WaitTileAnimation
+ dw NULL, TileAnimationPalette
+ dw NULL, WaitTileAnimation
+ dw NULL, AnimateFlowerTile
+ dw NULL, WaitTileAnimation
+ dw NULL, WaitTileAnimation
+ dw NULL, StandingTileFrame8
+ dw NULL, DoneTileAnimation
+; 0xfc047
+
+TilesetParkAnim: ; 0xfc047
+ dw vTiles2 tile $14, AnimateWaterTile
+ dw NULL, WaitTileAnimation
+ dw vTiles2 tile $5f, AnimateFountain
+ dw NULL, WaitTileAnimation
+ dw NULL, TileAnimationPalette
+ dw NULL, WaitTileAnimation
+ dw NULL, AnimateFlowerTile
+ dw NULL, WaitTileAnimation
+ dw NULL, WaitTileAnimation
+ dw NULL, StandingTileFrame8
+ dw NULL, DoneTileAnimation
+; 0xfc073
+
+TilesetForestAnim: ; 0xfc073
+ dw NULL, ForestTreeLeftAnimation
+ dw NULL, ForestTreeRightAnimation
+ dw NULL, WaitTileAnimation
+ dw NULL, WaitTileAnimation
+ dw NULL, WaitTileAnimation
+ dw NULL, ForestTreeLeftAnimation2
+ dw NULL, ForestTreeRightAnimation2
+ dw NULL, AnimateFlowerTile
+ dw vTiles2 tile $14, AnimateWaterTile
+ dw NULL, TileAnimationPalette
+ dw NULL, StandingTileFrame8
+ dw NULL, DoneTileAnimation
+; 0xfc0a3
+
+TilesetJohtoAnim: ; 0xfc0a3
+ dw vTiles2 tile $14, AnimateWaterTile
+ dw NULL, WaitTileAnimation
+ dw NULL, WaitTileAnimation
+ dw NULL, TileAnimationPalette
+ dw NULL, WaitTileAnimation
+ dw NULL, AnimateFlowerTile
+ dw WhirlpoolFrames1, AnimateWhirlpoolTile
+ dw WhirlpoolFrames2, AnimateWhirlpoolTile
+ dw WhirlpoolFrames3, AnimateWhirlpoolTile
+ dw WhirlpoolFrames4, AnimateWhirlpoolTile
+ dw NULL, WaitTileAnimation
+ dw NULL, StandingTileFrame8
+ dw NULL, DoneTileAnimation
+; 0xfc0d7
+
+UnusedTilesetAnim_fc0d7: ; 0xfc0d7
+ dw vTiles2 tile $03, WriteTileToBuffer
+ dw wTileAnimBuffer, ScrollTileRightLeft
+ dw vTiles2 tile $03, WriteTileFromBuffer
+ dw NULL, WaitTileAnimation
+ dw NULL, WaitTileAnimation
+ dw NULL, WaitTileAnimation
+ dw NULL, AnimateFlowerTile
+ dw NULL, WaitTileAnimation
+ dw NULL, WaitTileAnimation
+ dw NULL, WaitTileAnimation
+ dw NULL, DoneTileAnimation
+; 0xfc103
+
+UnusedTilesetAnim_fc103: ; 0xfc103
+ dw vTiles2 tile $14, WriteTileToBuffer
+ dw wTileAnimBuffer, ScrollTileRightLeft
+ dw vTiles2 tile $14, WriteTileFromBuffer
+ dw NULL, WaitTileAnimation
+ dw NULL, WaitTileAnimation
+ dw NULL, WaitTileAnimation
+ dw NULL, WaitTileAnimation
+ dw NULL, WaitTileAnimation
+ dw NULL, WaitTileAnimation
+ dw NULL, WaitTileAnimation
+ dw NULL, DoneTileAnimation
+; 0xfc12f
+
+TilesetPortAnim: ; 0xfc12f
+ dw vTiles2 tile $14, AnimateWaterTile
+ dw NULL, WaitTileAnimation
+ dw NULL, WaitTileAnimation
+ dw NULL, WaitTileAnimation
+ dw NULL, WaitTileAnimation
+ dw NULL, TileAnimationPalette
+ dw NULL, WaitTileAnimation
+ dw NULL, WaitTileAnimation
+ dw NULL, WaitTileAnimation
+ dw NULL, WaitTileAnimation
+ dw NULL, StandingTileFrame8
+ dw NULL, DoneTileAnimation
+; 0xfc15f
+
+TilesetEliteFourRoomAnim: ; 0xfc15f
+ dw NULL, LavaBubbleAnim2
+ dw NULL, WaitTileAnimation
+ dw NULL, WaitTileAnimation
+ dw NULL, WaitTileAnimation
+ dw NULL, LavaBubbleAnim1
+ dw NULL, WaitTileAnimation
+ dw NULL, StandingTileFrame8
+ dw NULL, DoneTileAnimation
+; 0xfc17f
+
+UnusedTilesetAnim_fc17f: ; 0xfc17f
+ dw vTiles2 tile $53, WriteTileToBuffer
+ dw wTileAnimBuffer, ScrollTileDown
+ dw wTileAnimBuffer, ScrollTileDown
+ dw vTiles2 tile $53, WriteTileFromBuffer
+ dw vTiles2 tile $03, WriteTileToBuffer
+ dw wTileAnimBuffer, ScrollTileRightLeft
+ dw vTiles2 tile $03, WriteTileFromBuffer
+ dw vTiles2 tile $53, WriteTileToBuffer
+ dw wTileAnimBuffer, ScrollTileDown
+ dw wTileAnimBuffer, ScrollTileDown
+ dw vTiles2 tile $53, WriteTileFromBuffer
+ dw NULL, DoneTileAnimation
+; 0xfc1af
+
+UnusedTilesetAnim_fc1af: ; 0xfc1af
+ dw vTiles2 tile $54, WriteTileToBuffer
+ dw wTileAnimBuffer, ScrollTileDown
+ dw wTileAnimBuffer, ScrollTileDown
+ dw vTiles2 tile $54, WriteTileFromBuffer
+ dw NULL, WaitTileAnimation
+ dw vTiles2 tile $03, WriteTileToBuffer
+ dw wTileAnimBuffer, ScrollTileRightLeft
+ dw vTiles2 tile $03, WriteTileFromBuffer
+ dw NULL, WaitTileAnimation
+ dw vTiles2 tile $54, WriteTileToBuffer
+ dw wTileAnimBuffer, ScrollTileDown
+ dw wTileAnimBuffer, ScrollTileDown
+ dw vTiles2 tile $54, WriteTileFromBuffer
+ dw NULL, DoneTileAnimation
+; 0xfc1e7
+
+TilesetCaveAnim: ; 0xfc1e7
+TilesetDarkCaveAnim: ; 0xfc1e7
+ dw vTiles2 tile $14, WriteTileToBuffer
+ dw NULL, FlickeringCaveEntrancePalette
+ dw wTileAnimBuffer, ScrollTileRightLeft
+ dw NULL, FlickeringCaveEntrancePalette
+ dw vTiles2 tile $14, WriteTileFromBuffer
+ dw NULL, FlickeringCaveEntrancePalette
+ dw NULL, TileAnimationPalette
+ dw NULL, FlickeringCaveEntrancePalette
+ dw vTiles2 tile $40, WriteTileToBuffer
+ dw NULL, FlickeringCaveEntrancePalette
+ dw wTileAnimBuffer, ScrollTileDown
+ dw NULL, FlickeringCaveEntrancePalette
+ dw wTileAnimBuffer, ScrollTileDown
+ dw NULL, FlickeringCaveEntrancePalette
+ dw wTileAnimBuffer, ScrollTileDown
+ dw NULL, FlickeringCaveEntrancePalette
+ dw vTiles2 tile $40, WriteTileFromBuffer
+ dw NULL, FlickeringCaveEntrancePalette
+ dw NULL, DoneTileAnimation
+; 0xfc233
+
+TilesetIcePathAnim: ; 0xfc233
+ dw vTiles2 tile $35, WriteTileToBuffer
+ dw NULL, FlickeringCaveEntrancePalette
+ dw wTileAnimBuffer, ScrollTileRightLeft
+ dw NULL, FlickeringCaveEntrancePalette
+ dw vTiles2 tile $35, WriteTileFromBuffer
+ dw NULL, FlickeringCaveEntrancePalette
+ dw NULL, TileAnimationPalette
+ dw NULL, FlickeringCaveEntrancePalette
+ dw vTiles2 tile $31, WriteTileToBuffer
+ dw NULL, FlickeringCaveEntrancePalette
+ dw wTileAnimBuffer, ScrollTileDown
+ dw NULL, FlickeringCaveEntrancePalette
+ dw wTileAnimBuffer, ScrollTileDown
+ dw NULL, FlickeringCaveEntrancePalette
+ dw wTileAnimBuffer, ScrollTileDown
+ dw NULL, FlickeringCaveEntrancePalette
+ dw vTiles2 tile $31, WriteTileFromBuffer
+ dw NULL, FlickeringCaveEntrancePalette
+ dw NULL, DoneTileAnimation
+; 0xfc27f
+
+TilesetTowerAnim: ; 0xfc27f
+ dw TowerPillarTilePointer9, AnimateTowerPillarTile
+ dw TowerPillarTilePointer10, AnimateTowerPillarTile
+ dw TowerPillarTilePointer7, AnimateTowerPillarTile
+ dw TowerPillarTilePointer8, AnimateTowerPillarTile
+ dw TowerPillarTilePointer5, AnimateTowerPillarTile
+ dw TowerPillarTilePointer6, AnimateTowerPillarTile
+ dw TowerPillarTilePointer3, AnimateTowerPillarTile
+ dw TowerPillarTilePointer4, AnimateTowerPillarTile
+ dw TowerPillarTilePointer1, AnimateTowerPillarTile
+ dw TowerPillarTilePointer2, AnimateTowerPillarTile
+ dw NULL, StandingTileFrame
+ dw NULL, WaitTileAnimation
+ dw NULL, WaitTileAnimation
+ dw NULL, WaitTileAnimation
+ dw NULL, WaitTileAnimation
+ dw NULL, DoneTileAnimation
+; 0xfc2bf
+
+UnusedTilesetAnim_fc2bf: ; 0xfc2bf
+ dw vTiles2 tile $4f, WriteTileToBuffer
+ dw wTileAnimBuffer, ScrollTileRightLeft
+ dw vTiles2 tile $4f, WriteTileFromBuffer
+ dw NULL, WaitTileAnimation
+ dw NULL, WaitTileAnimation
+ dw NULL, WaitTileAnimation
+ dw NULL, WaitTileAnimation
+ dw NULL, WaitTileAnimation
+ dw NULL, WaitTileAnimation
+ dw NULL, DoneTileAnimation
+; 0xfc2e7
+
+TilesetBattleTowerOutsideAnim: ; 0xfc2e7
+TilesetHouseAnim: ; 0xfc2e7
+TilesetPlayersHouseAnim: ; 0xfc2e7
+TilesetPokecenterAnim: ; 0xfc2e7
+TilesetGateAnim: ; 0xfc2e7
+TilesetLabAnim: ; 0xfc2e7
+TilesetFacilityAnim: ; 0xfc2e7
+TilesetMartAnim: ; 0xfc2e7
+TilesetMansionAnim: ; 0xfc2e7
+TilesetGameCornerAnim: ; 0xfc2e7
+TilesetTraditionalHouseAnim: ; 0xfc2e7
+TilesetTrainStationAnim: ; 0xfc2e7
+TilesetChampionsRoomAnim: ; 0xfc2e7
+TilesetLighthouseAnim: ; 0xfc2e7
+TilesetPlayersRoomAnim: ; 0xfc2e7
+TilesetPokeComCenterAnim: ; 0xfc2e7
+TilesetBattleTowerAnim: ; 0xfc2e7
+TilesetRuinsOfAlphAnim: ; 0xfc2e7
+TilesetRadioTowerAnim: ; 0xfc2e7
+TilesetUndergroundAnim: ; 0xfc2e7
+TilesetBetaWordRoomAnim: ; 0xfc2e7
+TilesetHoOhWordRoomAnim: ; 0xfc2e7
+TilesetKabutoWordRoomAnim: ; 0xfc2e7
+TilesetOmanyteWordRoomAnim: ; 0xfc2e7
+TilesetAerodactylWordRoomAnim: ; 0xfc2e7
+ dw NULL, WaitTileAnimation
+ dw NULL, WaitTileAnimation
+ dw NULL, WaitTileAnimation
+ dw NULL, WaitTileAnimation
+ dw NULL, DoneTileAnimation
+; 0xfc2fb
+
+DoneTileAnimation: ; fc2fb
+; Reset the animation command loop.
+ xor a
+ ld [hTileAnimFrame], a
+
+WaitTileAnimation: ; fc2fe
+; Do nothing this frame.
+ ret
+; fc2ff
+
+StandingTileFrame8: ; fc2ff
+ ld a, [wTileAnimationTimer]
+ inc a
+ and %111
+ ld [wTileAnimationTimer], a
+ ret
+; fc309
+
+
+ScrollTileRightLeft: ; fc309
+; Scroll right for 4 ticks, then left for 4 ticks.
+ ld a, [wTileAnimationTimer]
+ inc a
+ and %111
+ ld [wTileAnimationTimer], a
+ and %100
+ jr nz, ScrollTileLeft
+ jr ScrollTileRight
+; fc318
+
+ScrollTileUpDown: ; fc318
+; Scroll up for 4 ticks, then down for 4 ticks.
+ ld a, [wTileAnimationTimer]
+ inc a
+ and %111
+ ld [wTileAnimationTimer], a
+ and %100
+ jr nz, ScrollTileDown
+ jr ScrollTileUp
+; fc327
+
+ScrollTileLeft: ; fc327
+ ld h, d
+ ld l, e
+ ld c, 4
+.loop
+rept 4
+ ld a, [hl]
+ rlca
+ ld [hli], a
+endr
+ dec c
+ jr nz, .loop
+ ret
+; fc33b
+
+ScrollTileRight: ; fc33b
+ ld h, d
+ ld l, e
+ ld c, 4
+.loop
+rept 4
+ ld a, [hl]
+ rrca
+ ld [hli], a
+endr
+ dec c
+ jr nz, .loop
+ ret
+; fc34f
+
+ScrollTileUp: ; fc34f
+ ld h, d
+ ld l, e
+ ld d, [hl]
+ inc hl
+ ld e, [hl]
+ ld bc, TILE_WIDTH * 2 - 2
+ add hl, bc
+ ld a, TILE_WIDTH / 2
+.loop
+ ld c, [hl]
+ ld [hl], e
+ dec hl
+ ld b, [hl]
+ ld [hl], d
+ dec hl
+ ld e, [hl]
+ ld [hl], c
+ dec hl
+ ld d, [hl]
+ ld [hl], b
+ dec hl
+ dec a
+ jr nz, .loop
+ ret
+; fc36a
+
+ScrollTileDown: ; fc36a
+ ld h, d
+ ld l, e
+ ld de, TILE_WIDTH * 2 - 2
+ push hl
+ add hl, de
+ ld d, [hl]
+ inc hl
+ ld e, [hl]
+ pop hl
+ ld a, TILE_WIDTH / 2
+.loop
+ ld b, [hl]
+ ld [hl], d
+ inc hl
+ ld c, [hl]
+ ld [hl], e
+ inc hl
+ ld d, [hl]
+ ld [hl], b
+ inc hl
+ ld e, [hl]
+ ld [hl], c
+ inc hl
+ dec a
+ jr nz, .loop
+ ret
+; fc387
+
+
+AnimateFountain: ; fc387
+ ld hl, sp+0
+ ld b, h
+ ld c, l
+ ld hl, .frames
+ ld a, [wTileAnimationTimer]
+ and %111
+ add a
+ add l
+ ld l, a
+ jr nc, .okay
+ inc h
+.okay
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ ld sp, hl
+ ld l, e
+ ld h, d
+ jp WriteTile
+
+.frames
+ dw .frame1
+ dw .frame2
+ dw .frame3
+ dw .frame4
+ dw .frame3
+ dw .frame4
+ dw .frame5
+ dw .frame1
+
+.frame1 INCBIN "gfx/tilesets/fountain/1.2bpp"
+.frame2 INCBIN "gfx/tilesets/fountain/2.2bpp"
+.frame3 INCBIN "gfx/tilesets/fountain/3.2bpp"
+.frame4 INCBIN "gfx/tilesets/fountain/4.2bpp"
+.frame5 INCBIN "gfx/tilesets/fountain/5.2bpp"
+; fc402
+
+
+AnimateWaterTile: ; fc402
+; Draw a water tile for the current frame in VRAM tile at de.
+
+; Save sp in bc (see WriteTile).
+ ld hl, sp+0
+ ld b, h
+ ld c, l
+
+ ld a, [wTileAnimationTimer]
+
+; 4 tile graphics, updated every other frame.
+ and %110
+
+; 2 x 8 = 16 bytes per tile
+ add a
+ add a
+ add a
+
+ add LOW(WaterTileFrames)
+ ld l, a
+ ld a, 0
+ adc HIGH(WaterTileFrames)
+ ld h, a
+
+; The stack now points to the start of the tile for this frame.
+ ld sp, hl
+
+ ld l, e
+ ld h, d
+
+ jp WriteTile
+; fc41c
+
+WaterTileFrames: ; fc41c
+ INCBIN "gfx/tilesets/water/water.2bpp"
+; fc45c
+
+
+ForestTreeLeftAnimation: ; fc45c
+ ld hl, sp+0
+ ld b, h
+ ld c, l
+
+; Only during the Celebi event.
+ ld a, [wCelebiEvent]
+ bit CELEBIEVENT_FOREST_IS_RESTLESS_F, a
+ jr nz, .asm_fc46c
+ ld hl, ForestTreeLeftFrames
+ jr .asm_fc47d
+
+.asm_fc46c
+ ld a, [wTileAnimationTimer]
+ call GetForestTreeFrame
+ add a
+ add a
+ add a
+ add LOW(ForestTreeLeftFrames)
+ ld l, a
+ ld a, 0
+ adc HIGH(ForestTreeLeftFrames)
+ ld h, a
+
+.asm_fc47d
+ ld sp, hl
+ ld hl, vTiles2 tile $0c
+ jp WriteTile
+; fc484
+
+
+ForestTreeLeftFrames: ; fc484
+ INCBIN "gfx/tilesets/forest-tree/1.2bpp"
+ INCBIN "gfx/tilesets/forest-tree/2.2bpp"
+; fc4a4
+
+ForestTreeRightFrames: ; fc4a4
+ INCBIN "gfx/tilesets/forest-tree/3.2bpp"
+ INCBIN "gfx/tilesets/forest-tree/4.2bpp"
+; fc4c4
+
+
+ForestTreeRightAnimation: ; fc4c4
+ ld hl, sp+0
+ ld b, h
+ ld c, l
+
+; Only during the Celebi event.
+ ld a, [wCelebiEvent]
+ bit CELEBIEVENT_FOREST_IS_RESTLESS_F, a
+ jr nz, .asm_fc4d4
+ ld hl, ForestTreeRightFrames
+ jr .asm_fc4eb
+
+.asm_fc4d4
+ ld a, [wTileAnimationTimer]
+ call GetForestTreeFrame
+ add a
+ add a
+ add a
+ add LOW(ForestTreeLeftFrames)
+ ld l, a
+ ld a, 0
+ adc HIGH(ForestTreeLeftFrames)
+ ld h, a
+ push bc
+ ld bc, ForestTreeRightFrames - ForestTreeLeftFrames
+ add hl, bc
+ pop bc
+
+.asm_fc4eb
+ ld sp, hl
+ ld hl, vTiles2 tile $0f
+ jp WriteTile
+; fc4f2
+
+
+ForestTreeLeftAnimation2: ; fc4f2
+ ld hl, sp+0
+ ld b, h
+ ld c, l
+
+; Only during the Celebi event.
+ ld a, [wCelebiEvent]
+ bit CELEBIEVENT_FOREST_IS_RESTLESS_F, a
+ jr nz, .asm_fc502
+ ld hl, ForestTreeLeftFrames
+ jr .asm_fc515
+
+.asm_fc502
+ ld a, [wTileAnimationTimer]
+ call GetForestTreeFrame
+ xor 2
+ add a
+ add a
+ add a
+ add LOW(ForestTreeLeftFrames)
+ ld l, a
+ ld a, 0
+ adc HIGH(ForestTreeLeftFrames)
+ ld h, a
+
+.asm_fc515
+ ld sp, hl
+ ld hl, vTiles2 tile $0c
+ jp WriteTile
+; fc51c
+
+
+ForestTreeRightAnimation2: ; fc51c
+ ld hl, sp+0
+ ld b, h
+ ld c, l
+
+; Only during the Celebi event.
+ ld a, [wCelebiEvent]
+ bit CELEBIEVENT_FOREST_IS_RESTLESS_F, a
+ jr nz, .asm_fc52c
+ ld hl, ForestTreeRightFrames
+ jr .asm_fc545
+
+.asm_fc52c
+ ld a, [wTileAnimationTimer]
+ call GetForestTreeFrame
+ xor 2
+ add a
+ add a
+ add a
+ add LOW(ForestTreeLeftFrames)
+ ld l, a
+ ld a, 0
+ adc HIGH(ForestTreeLeftFrames)
+ ld h, a
+ push bc
+ ld bc, ForestTreeRightFrames - ForestTreeLeftFrames
+ add hl, bc
+ pop bc
+
+.asm_fc545
+ ld sp, hl
+ ld hl, vTiles2 tile $0f
+ jp WriteTile
+; fc54c
+
+
+GetForestTreeFrame: ; fc54c
+; Return 0 if a is even, or 2 if odd.
+ and a
+ jr z, .even
+ cp 1
+ jr z, .odd
+ cp 2
+ jr z, .even
+ cp 3
+ jr z, .odd
+ cp 4
+ jr z, .even
+ cp 5
+ jr z, .odd
+ cp 6
+ jr z, .even
+.odd
+ ld a, 2
+ scf
+ ret
+.even
+ xor a
+ ret
+; fc56d
+
+
+AnimateFlowerTile: ; fc56d
+; No parameters.
+
+; Save sp in bc (see WriteTile).
+ ld hl, sp+0
+ ld b, h
+ ld c, l
+
+; Alternate tile graphic every other frame
+ ld a, [wTileAnimationTimer]
+ and %10
+ ld e, a
+
+; CGB has different color mappings for flowers.
+ ld a, [hCGB]
+ and 1
+
+ add e
+ swap a
+ ld e, a
+ ld d, 0
+ ld hl, FlowerTileFrames
+ add hl, de
+ ld sp, hl
+
+ ld hl, vTiles2 tile $03
+
+ jp WriteTile
+; fc58c
+
+FlowerTileFrames: ; fc58c
+ INCBIN "gfx/tilesets/flower/dmg_1.2bpp"
+ INCBIN "gfx/tilesets/flower/cgb_1.2bpp"
+ INCBIN "gfx/tilesets/flower/dmg_2.2bpp"
+ INCBIN "gfx/tilesets/flower/cgb_2.2bpp"
+; fc5cc
+
+
+LavaBubbleAnim1: ; fc5cc
+; Splash in the bottom-right corner of the fountain.
+ ld hl, sp+0
+ ld b, h
+ ld c, l
+ ld a, [wTileAnimationTimer]
+ and %110
+ srl a
+ inc a
+ inc a
+ and %011
+ swap a
+ ld e, a
+ ld d, 0
+ ld hl, LavaBubbleFrames
+ add hl, de
+ ld sp, hl
+ ld hl, vTiles2 tile $5b
+ jp WriteTile
+; fc5eb
+
+
+LavaBubbleAnim2: ; fc5eb
+; Splash in the top-left corner of the fountain.
+ ld hl, sp+0
+ ld b, h
+ ld c, l
+ ld a, [wTileAnimationTimer]
+ and %110
+ add a
+ add a
+ add a
+ ld e, a
+ ld d, 0
+ ld hl, LavaBubbleFrames
+ add hl, de
+ ld sp, hl
+ ld hl, vTiles2 tile $38
+ jp WriteTile
+; fc605
+
+
+LavaBubbleFrames: ; fc605
+ INCBIN "gfx/tilesets/lava/1.2bpp"
+ INCBIN "gfx/tilesets/lava/2.2bpp"
+ INCBIN "gfx/tilesets/lava/3.2bpp"
+ INCBIN "gfx/tilesets/lava/4.2bpp"
+; fc645
+
+
+AnimateTowerPillarTile: ; fc645
+; Read from struct at de:
+; Destination (VRAM)
+; Address of the first tile in the frame array
+
+ ld hl, sp+0
+ ld b, h
+ ld c, l
+
+ ld a, [wTileAnimationTimer]
+ and %111
+
+; Get frame index a
+ ld hl, .frames
+ add l
+ ld l, a
+ ld a, 0
+ adc h
+ ld h, a
+ ld a, [hl]
+
+; Destination
+ ld l, e
+ ld h, d
+ ld e, [hl]
+ inc hl
+ ld d, [hl]
+ inc hl
+
+; Add the frame index to the starting address
+ add [hl]
+ inc hl
+ ld h, [hl]
+ ld l, a
+ ld a, 0
+ adc h
+ ld h, a
+
+ ld sp, hl
+ ld l, e
+ ld h, d
+ jr WriteTile
+
+.frames
+ db $00, $10, $20, $30, $40, $30, $20, $10
+; fc673
+
+
+StandingTileFrame: ; fc673
+ ld hl, wTileAnimationTimer
+ inc [hl]
+ ret
+; fc678
+
+
+AnimateWhirlpoolTile: ; fc678
+; Update whirlpool tile using struct at de.
+
+; Struct:
+; VRAM address
+; Address of the first tile
+
+; Only does one of 4 tiles at a time.
+
+; Save sp in bc (see WriteTile).
+ ld hl, sp+0
+ ld b, h
+ ld c, l
+
+; de = VRAM address
+ ld l, e
+ ld h, d
+ ld e, [hl]
+ inc hl
+ ld d, [hl]
+ inc hl
+; Tile address is now at hl.
+
+; Get the tile for this frame.
+ ld a, [wTileAnimationTimer]
+ and %11 ; 4 frames x2
+ swap a ; * 16 bytes per tile
+
+ add [hl]
+ inc hl
+ ld h, [hl]
+ ld l, a
+ ld a, 0
+ adc h
+ ld h, a
+
+; The stack now points to the desired frame.
+ ld sp, hl
+
+ ld l, e
+ ld h, d
+
+ jr WriteTile
+; fc696
+
+
+WriteTileFromBuffer: ; fc696
+; Write tiledata at wTileAnimBuffer to de.
+; wTileAnimBuffer is loaded to sp for WriteTile.
+
+ ld hl, sp+0
+ ld b, h
+ ld c, l
+
+ ld hl, wTileAnimBuffer
+ ld sp, hl
+
+ ld h, d
+ ld l, e
+ jr WriteTile
+; fc6a2
+
+
+WriteTileToBuffer: ; fc6a2
+; Write tiledata de to wTileAnimBuffer.
+; de is loaded to sp for WriteTile.
+
+ ld hl, sp+0
+ ld b, h
+ ld c, l
+
+ ld h, d
+ ld l, e
+ ld sp, hl
+
+ ld hl, wTileAnimBuffer
+
+ ; fallthrough
+
+WriteTile: ; fc6ac
+; Write one 8x8 tile ($10 bytes) from sp to hl.
+
+; Warning: sp is saved in bc so we can abuse pop.
+; sp is restored to address bc. Save sp in bc before calling.
+
+ pop de
+ ld [hl], e
+ inc hl
+ ld [hl], d
+
+rept 7
+ pop de
+ inc hl
+ ld [hl], e
+ inc hl
+ ld [hl], d
+endr
+
+; restore sp
+ ld h, b
+ ld l, c
+ ld sp, hl
+ ret
+; fc6d7
+
+
+TileAnimationPalette: ; fc6d7
+; Transition between color values 0-2 for color 0 in palette 3.
+
+; No palette changes on DMG.
+ ld a, [hCGB]
+ and a
+ ret z
+
+; We don't want to mess with non-standard palettes.
+ ld a, [rBGP] ; BGP
+ cp %11100100
+ ret nz
+
+; Only update on even frames.
+ ld a, [wTileAnimationTimer]
+ ld l, a
+ and 1 ; odd
+ ret nz
+
+; Ready for BGPD input...
+
+ ld a, (1 << rBGPI_AUTO_INCREMENT) palette PAL_BG_WATER
+ ld [rBGPI], a
+
+ ld a, [rSVBK]
+ push af
+ ld a, BANK(wBGPals1)
+ ld [rSVBK], a
+
+; Update color 0 in order 0 1 2 1
+ ld a, l
+ and %110 ; frames 0 2 4 6
+ jr z, .color0
+ cp %100 ; frame 4
+ jr z, .color2
+
+.color1
+ ld hl, wBGPals1 palette PAL_BG_WATER color 1
+ ld a, [hli]
+ ld [rBGPD], a
+ ld a, [hli]
+ ld [rBGPD], a
+ jr .end
+
+.color0
+ ld hl, wBGPals1 palette PAL_BG_WATER color 0
+ ld a, [hli]
+ ld [rBGPD], a
+ ld a, [hli]
+ ld [rBGPD], a
+ jr .end
+
+.color2
+ ld hl, wBGPals1 palette PAL_BG_WATER color 2
+ ld a, [hli]
+ ld [rBGPD], a
+ ld a, [hli]
+ ld [rBGPD], a
+
+.end
+ pop af
+ ld [rSVBK], a
+ ret
+; fc71e
+
+
+FlickeringCaveEntrancePalette: ; fc71e
+; No palette changes on DMG.
+ ld a, [hCGB]
+ and a
+ ret z
+; We don't want to mess with non-standard palettes.
+ ld a, [rBGP]
+ cp %11100100
+ ret nz
+; We only want to be here if we're in a dark cave.
+ ld a, [wTimeOfDayPalset]
+ cp %11111111 ; 3,3,3,3
+ ret nz
+
+ ld a, [rSVBK]
+ push af
+ ld a, BANK(wBGPals1)
+ ld [rSVBK], a
+; Ready for BGPD input...
+ ld a, (1 << rBGPI_AUTO_INCREMENT) palette PAL_BG_YELLOW
+ ld [rBGPI], a
+ ld a, [hVBlankCounter]
+ and %10
+ jr nz, .bit1set
+ ld hl, wBGPals1 palette PAL_BG_YELLOW
+ jr .okay
+
+.bit1set
+ ld hl, wBGPals1 palette PAL_BG_YELLOW color 1
+
+.okay
+ ld a, [hli]
+ ld [rBGPD], a
+ ld a, [hli]
+ ld [rBGPD], a
+
+ pop af
+ ld [rSVBK], a
+ ret
+; fc750
+
+
+TowerPillarTilePointer1: dw vTiles2 tile $2d, TowerPillarTile1
+TowerPillarTilePointer2: dw vTiles2 tile $2f, TowerPillarTile2
+TowerPillarTilePointer3: dw vTiles2 tile $3d, TowerPillarTile3
+TowerPillarTilePointer4: dw vTiles2 tile $3f, TowerPillarTile4
+TowerPillarTilePointer5: dw vTiles2 tile $3c, TowerPillarTile5
+TowerPillarTilePointer6: dw vTiles2 tile $2c, TowerPillarTile6
+TowerPillarTilePointer7: dw vTiles2 tile $4d, TowerPillarTile7
+TowerPillarTilePointer8: dw vTiles2 tile $4f, TowerPillarTile8
+TowerPillarTilePointer9: dw vTiles2 tile $5d, TowerPillarTile9
+TowerPillarTilePointer10: dw vTiles2 tile $5f, TowerPillarTile10
+
+TowerPillarTile1: INCBIN "gfx/tilesets/tower-pillar/1.2bpp"
+TowerPillarTile2: INCBIN "gfx/tilesets/tower-pillar/2.2bpp"
+TowerPillarTile3: INCBIN "gfx/tilesets/tower-pillar/3.2bpp"
+TowerPillarTile4: INCBIN "gfx/tilesets/tower-pillar/4.2bpp"
+TowerPillarTile5: INCBIN "gfx/tilesets/tower-pillar/5.2bpp"
+TowerPillarTile6: INCBIN "gfx/tilesets/tower-pillar/6.2bpp"
+TowerPillarTile7: INCBIN "gfx/tilesets/tower-pillar/7.2bpp"
+TowerPillarTile8: INCBIN "gfx/tilesets/tower-pillar/8.2bpp"
+TowerPillarTile9: INCBIN "gfx/tilesets/tower-pillar/9.2bpp"
+TowerPillarTile10: INCBIN "gfx/tilesets/tower-pillar/10.2bpp"
+; fca98
+
+
+WhirlpoolFrames1: dw vTiles2 tile $32, WhirlpoolTiles1
+WhirlpoolFrames2: dw vTiles2 tile $33, WhirlpoolTiles2
+WhirlpoolFrames3: dw vTiles2 tile $42, WhirlpoolTiles3
+WhirlpoolFrames4: dw vTiles2 tile $43, WhirlpoolTiles4
+; fcaa8
+
+WhirlpoolTiles1: INCBIN "gfx/tilesets/whirlpool/1.2bpp"
+WhirlpoolTiles2: INCBIN "gfx/tilesets/whirlpool/2.2bpp"
+WhirlpoolTiles3: INCBIN "gfx/tilesets/whirlpool/3.2bpp"
+WhirlpoolTiles4: INCBIN "gfx/tilesets/whirlpool/4.2bpp"
+; fcba8
diff --git a/engine/tilesets/tileset_palettes.asm b/engine/tilesets/tileset_palettes.asm
new file mode 100644
index 000000000..e2c39c0ab
--- /dev/null
+++ b/engine/tilesets/tileset_palettes.asm
@@ -0,0 +1,151 @@
+LoadSpecialMapPalette: ; 494ac
+ ld a, [wMapTileset]
+ cp TILESET_POKECOM_CENTER
+ jr z, .pokecom_2f
+ cp TILESET_BATTLE_TOWER
+ jr z, .battle_tower
+ cp TILESET_ICE_PATH
+ jr z, .ice_path
+ cp TILESET_HOUSE
+ jr z, .house
+ cp TILESET_RADIO_TOWER
+ jr z, .radio_tower
+ cp TILESET_MANSION
+ jr z, .mansion_mobile
+ jr .do_nothing
+
+.pokecom_2f
+ call LoadPokeComPalette
+ scf
+ ret
+
+.battle_tower
+ call LoadBattleTowerPalette
+ scf
+ ret
+
+.ice_path
+ ld a, [wEnvironment]
+ and $7
+ cp INDOOR ; Hall of Fame
+ jr z, .do_nothing
+ call LoadIcePathPalette
+ scf
+ ret
+
+.house
+ call LoadHousePalette
+ scf
+ ret
+
+.radio_tower
+ call LoadRadioTowerPalette
+ scf
+ ret
+
+.mansion_mobile
+ call LoadMansionPalette
+ scf
+ ret
+
+.do_nothing
+ and a
+ ret
+; 494f2
+
+LoadPokeComPalette: ; 494f2
+ ld a, BANK(wBGPals1)
+ ld de, wBGPals1
+ ld hl, PokeComPalette
+ ld bc, 8 palettes
+ call FarCopyWRAM
+ ret
+; 49501
+
+PokeComPalette: ; 49501
+INCLUDE "gfx/tilesets/pokecom_center.pal"
+; 49541
+
+LoadBattleTowerPalette: ; 49541
+ ld a, BANK(wBGPals1)
+ ld de, wBGPals1
+ ld hl, BattleTowerPalette
+ ld bc, 8 palettes
+ call FarCopyWRAM
+ ret
+; 49550
+
+BattleTowerPalette: ; 49550
+INCLUDE "gfx/tilesets/battle_tower.pal"
+; 49590
+
+LoadIcePathPalette: ; 49590
+ ld a, BANK(wBGPals1)
+ ld de, wBGPals1
+ ld hl, IcePathPalette
+ ld bc, 8 palettes
+ call FarCopyWRAM
+ ret
+; 4959f
+
+IcePathPalette: ; 4959f
+INCLUDE "gfx/tilesets/ice_path.pal"
+; 495df
+
+LoadHousePalette: ; 495df
+ ld a, BANK(wBGPals1)
+ ld de, wBGPals1
+ ld hl, HousePalette
+ ld bc, 8 palettes
+ call FarCopyWRAM
+ ret
+; 495ee
+
+HousePalette: ; 495ee
+INCLUDE "gfx/tilesets/house.pal"
+; 4962e
+
+LoadRadioTowerPalette: ; 4962e
+ ld a, BANK(wBGPals1)
+ ld de, wBGPals1
+ ld hl, RadioTowerPalette
+ ld bc, 8 palettes
+ call FarCopyWRAM
+ ret
+; 4963d
+
+RadioTowerPalette: ; 4963d
+INCLUDE "gfx/tilesets/radio_tower.pal"
+; 4967d
+
+MansionPalette1: ; 4967d
+INCLUDE "gfx/tilesets/mansion_1.pal"
+; 496c5
+
+LoadMansionPalette: ; 496c5
+ ld a, BANK(wBGPals1)
+ ld de, wBGPals1
+ ld hl, MansionPalette1
+ ld bc, 8 palettes
+ call FarCopyWRAM
+ ld a, BANK(wBGPals1)
+ ld de, wBGPals1 palette PAL_BG_YELLOW
+ ld hl, MansionPalette2
+ ld bc, 1 palettes
+ call FarCopyWRAM
+ ld a, BANK(wBGPals1)
+ ld de, wBGPals1 palette PAL_BG_WATER
+ ld hl, MansionPalette1 + 6 palettes
+ ld bc, 1 palettes
+ call FarCopyWRAM
+ ld a, BANK(wBGPals1)
+ ld de, wBGPals1 palette PAL_BG_ROOF
+ ld hl, MansionPalette1 + 8 palettes
+ ld bc, 1 palettes
+ call FarCopyWRAM
+ ret
+; 496fe
+
+MansionPalette2: ; 496fe
+INCLUDE "gfx/tilesets/mansion_2.pal"
+; 49706
diff --git a/engine/tilesets/timeofdaypals.asm b/engine/tilesets/timeofdaypals.asm
new file mode 100644
index 000000000..b8d43d252
--- /dev/null
+++ b/engine/tilesets/timeofdaypals.asm
@@ -0,0 +1,415 @@
+DummyPredef35: ; 8c000
+DummyPredef36:
+ ret
+
+UpdateTimeOfDayPal:: ; 8c001
+ call UpdateTime
+ ld a, [wTimeOfDay]
+ ld [wCurTimeOfDay], a
+ call GetTimePalette
+ ld [wTimeOfDayPal], a
+ ret
+; 8c011
+
+
+_TimeOfDayPals:: ; 8c011
+; return carry if pals are changed
+
+; forced pals?
+ ld hl, wTimeOfDayPalFlags
+ bit 7, [hl]
+ jr nz, .dontchange
+
+; do we need to bother updating?
+ ld a, [wTimeOfDay]
+ ld hl, wCurTimeOfDay
+ cp [hl]
+ jr z, .dontchange
+
+; if so, the time of day has changed
+ ld a, [wTimeOfDay]
+ ld [wCurTimeOfDay], a
+
+; get palette id
+ call GetTimePalette
+
+; same palette as before?
+ ld hl, wTimeOfDayPal
+ cp [hl]
+ jr z, .dontchange
+
+; update palette id
+ ld [wTimeOfDayPal], a
+
+; save bg palette 7
+ ld hl, wBGPals1 palette PAL_BG_TEXT
+
+; save wram bank
+ ld a, [rSVBK]
+ ld b, a
+
+ ld a, BANK(wBGPals1)
+ ld [rSVBK], a
+
+; push palette
+ ld c, NUM_PAL_COLORS
+.push
+ ld d, [hl]
+ inc hl
+ ld e, [hl]
+ inc hl
+ push de
+ dec c
+ jr nz, .push
+
+; restore wram bank
+ ld a, b
+ ld [rSVBK], a
+
+
+; update sgb pals
+ ld b, SCGB_MAPPALS
+ call GetSGBLayout
+
+
+; restore bg palette 7
+ ld hl, wOBPals1 - 1 ; last byte in wBGPals1
+
+; save wram bank
+ ld a, [rSVBK]
+ ld d, a
+
+ ld a, BANK(wOBPals1)
+ ld [rSVBK], a
+
+; pop palette
+ ld e, NUM_PAL_COLORS
+.pop
+ pop bc
+ ld [hl], c
+ dec hl
+ ld [hl], b
+ dec hl
+ dec e
+ jr nz, .pop
+
+; restore wram bank
+ ld a, d
+ ld [rSVBK], a
+
+; update palettes
+ call _UpdateTimePals
+ call DelayFrame
+
+; successful change
+ scf
+ ret
+
+.dontchange
+; no change occurred
+ and a
+ ret
+; 8c070
+
+
+_UpdateTimePals:: ; 8c070
+ ld c, $9 ; normal
+ call GetTimePalFade
+ call DmgToCgbTimePals
+ ret
+; 8c079
+
+FadeInPalettes:: ; 8c079
+ ld c, $12
+ call GetTimePalFade
+ ld b, $4
+ call ConvertTimePalsDecHL
+ ret
+; 8c084
+
+FadeOutPalettes:: ; 8c084
+ call FillWhiteBGColor
+ ld c, $9
+ call GetTimePalFade
+ ld b, $4
+ call ConvertTimePalsIncHL
+ ret
+; 8c092
+
+BattleTowerFade: ; 8c092
+ call FillWhiteBGColor
+ ld c, $9
+ call GetTimePalFade
+ ld b, $4
+.asm_8c09c
+ call DmgToCgbTimePals
+ inc hl
+ inc hl
+ inc hl
+ ld c, $7
+ call DelayFrames
+ dec b
+ jr nz, .asm_8c09c
+ ret
+; 8c0ab
+
+FadeInQuickly: ; 8c0ab
+ ld c, $0
+ call GetTimePalFade
+ ld b, $4
+ call ConvertTimePalsIncHL
+ ret
+; 8c0b6
+
+FadeBlackQuickly: ; 8c0b6
+ ld c, $9
+ call GetTimePalFade
+ ld b, $4
+ call ConvertTimePalsDecHL
+ ret
+; 8c0c1
+
+
+FillWhiteBGColor: ; 8c0c1
+ ld a, [rSVBK]
+ push af
+ ld a, BANK(wBGPals1)
+ ld [rSVBK], a
+
+ ld hl, wBGPals1
+ ld a, [hli]
+ ld e, a
+ ld a, [hli]
+ ld d, a
+ ld hl, wBGPals1 + 1 palettes
+ ld c, 6
+.loop
+ ld a, e
+ ld [hli], a
+ ld a, d
+ ld [hli], a
+rept 6
+ inc hl
+endr
+ dec c
+ jr nz, .loop
+
+ pop af
+ ld [rSVBK], a
+ ret
+; 8c0e5
+
+ReplaceTimeOfDayPals: ; 8c0e5
+ ld hl, .BrightnessLevels
+ ld a, [wMapTimeOfDay]
+ cp $4 ; Dark cave, needs Flash
+ jr z, .DarkCave
+ and $7
+ add l
+ ld l, a
+ ld a, $0
+ adc h
+ ld h, a
+ ld a, [hl]
+ ld [wTimeOfDayPalset], a
+ ret
+
+.DarkCave:
+ ld a, [wStatusFlags]
+ bit STATUSFLAGS_FLASH_F, a
+ jr nz, .UsedFlash
+ ld a, %11111111 ; 3, 3, 3, 3
+ ld [wTimeOfDayPalset], a
+ ret
+
+.UsedFlash:
+ ld a, %10101010 ; 2, 2, 2, 2
+ ld [wTimeOfDayPalset], a
+ ret
+; 8c10f (23:410f)
+
+.BrightnessLevels: ; 8c10f
+ dc 3, 2, 1, 0
+ dc 1, 1, 1, 1
+ dc 2, 2, 2, 2
+ dc 0, 0, 0, 0
+ dc 3, 3, 3, 3
+ dc 3, 2, 1, 0
+ dc 3, 2, 1, 0
+ dc 3, 2, 1, 0
+; 8c117
+
+GetTimePalette: ; 8c117
+ ld a, [wTimeOfDay]
+ ld e, a
+ ld d, 0
+ ld hl, .TimePalettes
+ add hl, de
+ add hl, de
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ jp hl
+; 8c126
+
+.TimePalettes:
+ dw .MorningPalette
+ dw .DayPalette
+ dw .NitePalette
+ dw .DarknessPalette
+
+.MorningPalette:
+ ld a, [wTimeOfDayPalset]
+ and %00000011 ; 0
+ ret
+
+.DayPalette:
+ ld a, [wTimeOfDayPalset]
+ and %00001100 ; 1
+ srl a
+ srl a
+ ret
+
+.NitePalette:
+ ld a, [wTimeOfDayPalset]
+ and %00110000 ; 2
+ swap a
+ ret
+
+.DarknessPalette:
+ ld a, [wTimeOfDayPalset]
+ and %11000000 ; 3
+ rlca
+ rlca
+ ret
+; 8c14e
+
+
+DmgToCgbTimePals: ; 8c14e
+ push hl
+ push de
+ ld a, [hli]
+ call DmgToCgbBGPals
+ ld a, [hli]
+ ld e, a
+ ld a, [hli]
+ ld d, a
+ call DmgToCgbObjPals
+ pop de
+ pop hl
+ ret
+; 8c15e
+
+ConvertTimePalsIncHL: ; 8c15e
+.loop
+ call DmgToCgbTimePals
+ inc hl
+ inc hl
+ inc hl
+ ld c, 2
+ call DelayFrames
+ dec b
+ jr nz, .loop
+ ret
+; 8c16d
+
+ConvertTimePalsDecHL: ; 8c16d
+.loop
+ call DmgToCgbTimePals
+ dec hl
+ dec hl
+ dec hl
+ ld c, 2
+ call DelayFrames
+ dec b
+ jr nz, .loop
+ ret
+; 8c17c
+
+
+GetTimePalFade: ; 8c17c
+; check cgb
+ ld a, [hCGB]
+ and a
+ jr nz, .cgb
+
+; else: dmg
+
+; index
+ ld a, [wTimeOfDayPal]
+ and %11
+
+; get fade table
+ push bc
+ ld c, a
+ ld b, $0
+ ld hl, .dmgfades
+ add hl, bc
+ add hl, bc
+ ld a, [hli]
+ ld h, [hl]
+ ld l, a
+ pop bc
+
+; get place in fade table
+ ld b, $0
+ add hl, bc
+ ret
+
+.cgb
+ ld hl, .cgbfade
+ ld b, $0
+ add hl, bc
+ ret
+
+.dmgfades
+ dw .morn
+ dw .day
+ dw .nite
+ dw .darkness
+
+.morn
+ db %11111111, %11111111, %11111111
+ db %11111110, %11111110, %11111110
+ db %11111001, %11100100, %11100100
+ db %11100100, %11010000, %11010000
+ db %10010000, %10000000, %10000000
+ db %01000000, %01000000, %01000000
+ db %00000000, %00000000, %00000000
+
+.day
+ db %11111111, %11111111, %11111111
+ db %11111110, %11111110, %11111110
+ db %11111001, %11100100, %11100100
+ db %11100100, %11010000, %11010000
+ db %10010000, %10000000, %10000000
+ db %01000000, %01000000, %01000000
+ db %00000000, %00000000, %00000000
+
+.nite
+ db %11111111, %11111111, %11111111
+ db %11111110, %11111110, %11111110
+ db %11111001, %11100100, %11100100
+ db %11101001, %11010000, %11010000
+ db %10010000, %10000000, %10000000
+ db %01000000, %01000000, %01000000
+ db %00000000, %00000000, %00000000
+
+.darkness
+ db %11111111, %11111111, %11111111
+ db %11111110, %11111110, %11111111
+ db %11111110, %11100100, %11111111
+ db %11111101, %11010000, %11111111
+ db %11111101, %10000000, %11111111
+ db %00000000, %01000000, %00000000
+ db %00000000, %00000000, %00000000
+
+.cgbfade
+ db %11111111, %11111111, %11111111
+ db %11111110, %11111110, %11111110
+ db %11111001, %11111001, %11111001
+ db %11100100, %11100100, %11100100
+ db %10010000, %10010000, %10010000
+ db %01000000, %01000000, %01000000
+ db %00000000, %00000000, %00000000
+; 8c20f