shithub: pokecrystal

Download patch

ref: 87b733994bdcb85e544f99899e50193c407909c6
parent: a5f5418faeb2ded9ddd898851ea0716e2d6ecf09
author: pikalaxalt <[email protected]>
date: Sun May 15 17:50:31 EDT 2016

SPRITE_ANIM_FRAME_IDX constants

--- a/battle/effect_commands.asm
+++ b/battle/effect_commands.asm
@@ -2832,11 +2832,11 @@
 	call GetDamageStatsCritical
 	jr c, .thickclub
 
-	ld hl, EnemyStats + 2
+	ld hl, EnemyDefense
 	ld a, [hli]
 	ld b, a
 	ld c, [hl]
-	ld hl, PlayerStats
+	ld hl, PlayerAttack
 	jr .thickclub
 
 .special
@@ -2856,11 +2856,11 @@
 	call GetDamageStatsCritical
 	jr c, .lightball
 
-	ld hl, EnemyStats + SP_DEFENSE * 2
+	ld hl, EnemySpDef
 	ld a, [hli]
 	ld b, a
 	ld c, [hl]
-	ld hl, PlayerStats + SP_ATTACK * 2
+	ld hl, PlayerSpAtk
 
 .lightball
 ; Note: Returns player special attack at hl in hl.
@@ -3098,11 +3098,11 @@
 	call GetDamageStatsCritical
 	jr c, .thickclub
 
-	ld hl, PlayerStats + 2
+	ld hl, PlayerDefense
 	ld a, [hli]
 	ld b, a
 	ld c, [hl]
-	ld hl, EnemyStats
+	ld hl, EnemyAttack
 	jr .thickclub
 
 .Special:
@@ -3121,11 +3121,11 @@
 	ld hl, EnemyMonSpclAtk
 	call GetDamageStatsCritical
 	jr c, .lightball
-	ld hl, PlayerStats + 8
+	ld hl, PlayerSpDef
 	ld a, [hli]
 	ld b, a
 	ld c, [hl]
-	ld hl, EnemyStats + 6
+	ld hl, EnemySpAtk
 
 .lightball
 	call LightBallBoost
--- a/constants/sprite_constants.asm
+++ b/constants/sprite_constants.asm
@@ -517,3 +517,146 @@
 	const SPRITE_ANIM_INDEX_2A
 	const SPRITE_ANIM_INDEX_2B
 	const SPRITE_ANIM_INDEX_2C
+
+	const_def
+
+	const SPRITE_ANIM_FRAME_IDX_00
+    const SPRITE_ANIM_FRAME_IDX_01
+    const SPRITE_ANIM_FRAME_IDX_02
+    const SPRITE_ANIM_FRAME_IDX_03
+    const SPRITE_ANIM_FRAME_IDX_04
+    const SPRITE_ANIM_FRAME_IDX_05
+    const SPRITE_ANIM_FRAME_IDX_06
+    const SPRITE_ANIM_FRAME_IDX_07
+    const SPRITE_ANIM_FRAME_IDX_08
+    const SPRITE_ANIM_FRAME_IDX_09
+    const SPRITE_ANIM_FRAME_IDX_0A
+    const SPRITE_ANIM_FRAME_IDX_0B
+    const SPRITE_ANIM_FRAME_IDX_0C
+    const SPRITE_ANIM_FRAME_IDX_0D
+    const SPRITE_ANIM_FRAME_IDX_0E
+    const SPRITE_ANIM_FRAME_IDX_0F
+    const SPRITE_ANIM_FRAME_IDX_10
+    const SPRITE_ANIM_FRAME_IDX_11
+    const SPRITE_ANIM_FRAME_IDX_12
+    const SPRITE_ANIM_FRAME_IDX_13
+    const SPRITE_ANIM_FRAME_IDX_14
+    const SPRITE_ANIM_FRAME_IDX_15
+    const SPRITE_ANIM_FRAME_IDX_16
+    const SPRITE_ANIM_FRAME_IDX_17
+    const SPRITE_ANIM_FRAME_IDX_18
+    const SPRITE_ANIM_FRAME_IDX_19
+    const SPRITE_ANIM_FRAME_IDX_1A
+    const SPRITE_ANIM_FRAME_IDX_1B
+    const SPRITE_ANIM_FRAME_IDX_1C
+    const SPRITE_ANIM_FRAME_IDX_1D
+    const SPRITE_ANIM_FRAME_IDX_1E
+    const SPRITE_ANIM_FRAME_IDX_1F
+    const SPRITE_ANIM_FRAME_IDX_20
+    const SPRITE_ANIM_FRAME_IDX_21
+    const SPRITE_ANIM_FRAME_IDX_22
+    const SPRITE_ANIM_FRAME_IDX_23
+    const SPRITE_ANIM_FRAME_IDX_24
+    const SPRITE_ANIM_FRAME_IDX_25
+    const SPRITE_ANIM_FRAME_IDX_26
+    const SPRITE_ANIM_FRAME_IDX_27
+    const SPRITE_ANIM_FRAME_IDX_28
+    const SPRITE_ANIM_FRAME_IDX_29
+    const SPRITE_ANIM_FRAME_IDX_2A
+    const SPRITE_ANIM_FRAME_IDX_2B
+    const SPRITE_ANIM_FRAME_IDX_2C
+    const SPRITE_ANIM_FRAME_IDX_2D
+    const SPRITE_ANIM_FRAME_IDX_2E
+    const SPRITE_ANIM_FRAME_IDX_2F
+    const SPRITE_ANIM_FRAME_IDX_30
+    const SPRITE_ANIM_FRAME_IDX_31
+    const SPRITE_ANIM_FRAME_IDX_32
+    const SPRITE_ANIM_FRAME_IDX_33
+    const SPRITE_ANIM_FRAME_IDX_34
+    const SPRITE_ANIM_FRAME_IDX_35
+    const SPRITE_ANIM_FRAME_IDX_36
+    const SPRITE_ANIM_FRAME_IDX_37
+    const SPRITE_ANIM_FRAME_IDX_38
+    const SPRITE_ANIM_FRAME_IDX_39
+    const SPRITE_ANIM_FRAME_IDX_3A
+    const SPRITE_ANIM_FRAME_IDX_3B
+    const SPRITE_ANIM_FRAME_IDX_3C
+    const SPRITE_ANIM_FRAME_IDX_3D
+    const SPRITE_ANIM_FRAME_IDX_3E
+    const SPRITE_ANIM_FRAME_IDX_3F
+    const SPRITE_ANIM_FRAME_IDX_40
+    const SPRITE_ANIM_FRAME_IDX_41
+    const SPRITE_ANIM_FRAME_IDX_42
+    const SPRITE_ANIM_FRAME_IDX_43
+    const SPRITE_ANIM_FRAME_IDX_44
+    const SPRITE_ANIM_FRAME_IDX_45
+    const SPRITE_ANIM_FRAME_IDX_46
+    const SPRITE_ANIM_FRAME_IDX_47
+    const SPRITE_ANIM_FRAME_IDX_48
+    const SPRITE_ANIM_FRAME_IDX_49
+    const SPRITE_ANIM_FRAME_IDX_4A
+    const SPRITE_ANIM_FRAME_IDX_4B
+    const SPRITE_ANIM_FRAME_IDX_4C
+    const SPRITE_ANIM_FRAME_IDX_4D
+    const SPRITE_ANIM_FRAME_IDX_4E
+    const SPRITE_ANIM_FRAME_IDX_4F
+    const SPRITE_ANIM_FRAME_IDX_50
+    const SPRITE_ANIM_FRAME_IDX_51
+    const SPRITE_ANIM_FRAME_IDX_52
+    const SPRITE_ANIM_FRAME_IDX_53
+    const SPRITE_ANIM_FRAME_IDX_54
+    const SPRITE_ANIM_FRAME_IDX_55
+    const SPRITE_ANIM_FRAME_IDX_56
+    const SPRITE_ANIM_FRAME_IDX_57
+    const SPRITE_ANIM_FRAME_IDX_58
+    const SPRITE_ANIM_FRAME_IDX_59
+    const SPRITE_ANIM_FRAME_IDX_5A
+    const SPRITE_ANIM_FRAME_IDX_5B
+    const SPRITE_ANIM_FRAME_IDX_5C
+    const SPRITE_ANIM_FRAME_IDX_5D
+    const SPRITE_ANIM_FRAME_IDX_5E
+    const SPRITE_ANIM_FRAME_IDX_5F
+    const SPRITE_ANIM_FRAME_IDX_60
+    const SPRITE_ANIM_FRAME_IDX_61
+    const SPRITE_ANIM_FRAME_IDX_62
+    const SPRITE_ANIM_FRAME_IDX_63
+    const SPRITE_ANIM_FRAME_IDX_64
+    const SPRITE_ANIM_FRAME_IDX_65
+    const SPRITE_ANIM_FRAME_IDX_66
+    const SPRITE_ANIM_FRAME_IDX_67
+    const SPRITE_ANIM_FRAME_IDX_68
+    const SPRITE_ANIM_FRAME_IDX_69
+    const SPRITE_ANIM_FRAME_IDX_6A
+    const SPRITE_ANIM_FRAME_IDX_6B
+    const SPRITE_ANIM_FRAME_IDX_6C
+    const SPRITE_ANIM_FRAME_IDX_6D
+    const SPRITE_ANIM_FRAME_IDX_6E
+    const SPRITE_ANIM_FRAME_IDX_6F
+    const SPRITE_ANIM_FRAME_IDX_70
+    const SPRITE_ANIM_FRAME_IDX_71
+    const SPRITE_ANIM_FRAME_IDX_72
+    const SPRITE_ANIM_FRAME_IDX_73
+    const SPRITE_ANIM_FRAME_IDX_74
+    const SPRITE_ANIM_FRAME_IDX_75
+    const SPRITE_ANIM_FRAME_IDX_76
+    const SPRITE_ANIM_FRAME_IDX_77
+    const SPRITE_ANIM_FRAME_IDX_78
+    const SPRITE_ANIM_FRAME_IDX_79
+    const SPRITE_ANIM_FRAME_IDX_7A
+    const SPRITE_ANIM_FRAME_IDX_7B
+    const SPRITE_ANIM_FRAME_IDX_7C
+    const SPRITE_ANIM_FRAME_IDX_7D
+    const SPRITE_ANIM_FRAME_IDX_7E
+    const SPRITE_ANIM_FRAME_IDX_7F
+    const SPRITE_ANIM_FRAME_IDX_80
+    const SPRITE_ANIM_FRAME_IDX_81
+    const SPRITE_ANIM_FRAME_IDX_82
+    const SPRITE_ANIM_FRAME_IDX_83
+    const SPRITE_ANIM_FRAME_IDX_84
+    const SPRITE_ANIM_FRAME_IDX_85
+    const SPRITE_ANIM_FRAME_IDX_86
+    const SPRITE_ANIM_FRAME_IDX_87
+    const SPRITE_ANIM_FRAME_IDX_88
+    const SPRITE_ANIM_FRAME_IDX_89
+    const SPRITE_ANIM_FRAME_IDX_8A
+    const SPRITE_ANIM_FRAME_IDX_8B
--- a/data/sprite_engine.asm
+++ b/data/sprite_engine.asm
@@ -68,205 +68,223 @@
 ; 8d76a
 ; OAM idx (see SpriteAnimOAMData), flip flags/duration
 .Frameset_00:
-	db $00, $20
+	db SPRITE_ANIM_FRAME_IDX_00, $20
 	db -1
 
 .Frameset_01:
-	db $00, $08
-	db $01, $08
+	db SPRITE_ANIM_FRAME_IDX_00, $08
+	db SPRITE_ANIM_FRAME_IDX_01, $08
 	db -2
 
 .Frameset_02:
-	db $3d, $08
-	db $3e, $08
+	db SPRITE_ANIM_FRAME_IDX_3D, $08
+	db SPRITE_ANIM_FRAME_IDX_3E, $08
 	db -2
 
 .Frameset_03:
-	db $3f, $08
-	db $40, $08
+	db SPRITE_ANIM_FRAME_IDX_3F, $08
+	db SPRITE_ANIM_FRAME_IDX_40, $08
 	db -2
 
 .Frameset_04:
-	db $00, $04
-	db $01, $04
+	db SPRITE_ANIM_FRAME_IDX_00, $04
+	db SPRITE_ANIM_FRAME_IDX_01, $04
 	db -2
 
 .Frameset_05:
-	db $3d, $04
-	db $3e, $04
+	db SPRITE_ANIM_FRAME_IDX_3D, $04
+	db SPRITE_ANIM_FRAME_IDX_3E, $04
 	db -2
 
 .Frameset_06:
-	db $3f, $04
-	db $40, $04
+	db SPRITE_ANIM_FRAME_IDX_3F, $04
+	db SPRITE_ANIM_FRAME_IDX_40, $04
 	db -2
 
 .Frameset_11:
-	db $00, $08
-	db $01, $08
-	db $00, $08
-	db $01, $48
+	db SPRITE_ANIM_FRAME_IDX_00, $08
+	db SPRITE_ANIM_FRAME_IDX_01, $08
+	db SPRITE_ANIM_FRAME_IDX_00, $08
+	db SPRITE_ANIM_FRAME_IDX_01, $48
 	db -2
 
 .Frameset_2d:
-	db $63, $08
-	db $64, $08
-	db $63, $08
-	db $64, $48
+	db SPRITE_ANIM_FRAME_IDX_63, $08
+	db SPRITE_ANIM_FRAME_IDX_64, $08
+	db SPRITE_ANIM_FRAME_IDX_63, $08
+	db SPRITE_ANIM_FRAME_IDX_64, $48
 	db -2
 
 .Frameset_2e:
-	db $65, $08
-	db $66, $08
-	db $65, $08
-	db $66, $48
+	db SPRITE_ANIM_FRAME_IDX_65, $08
+	db SPRITE_ANIM_FRAME_IDX_66, $08
+	db SPRITE_ANIM_FRAME_IDX_65, $08
+	db SPRITE_ANIM_FRAME_IDX_66, $48
 	db -2
 
 .Frameset_07:
-	db $1e, $01
-	db $1f, $01
+	db SPRITE_ANIM_FRAME_IDX_1E, $01
+	db SPRITE_ANIM_FRAME_IDX_1F, $01
 	db -2
 
 .Frameset_08:
-	db $20, $01
+	db SPRITE_ANIM_FRAME_IDX_20, $01
 	db -3, $01
 	db -2
 
 .Frameset_09:
-	db $21, $01
+	db SPRITE_ANIM_FRAME_IDX_21, $01
 	db -3, $01
 	db -2
 
 .Frameset_0a:
-	db $81, $0c
-	db $82, $01
-	db $83, $01
-	db $82, $04
-	db $81, $0c
-	db $82, $0c
-	db $83, $04
-	db $84, $20
-	db $85, $03
-	db $86, $03
-	db $87, $04
-	db $88, $04
-	db $89, $04
-	db $8a, $0a
-	db $8b, $07
+	db SPRITE_ANIM_FRAME_IDX_81, $0c
+	db SPRITE_ANIM_FRAME_IDX_82, $01
+	db SPRITE_ANIM_FRAME_IDX_83, $01
+	db SPRITE_ANIM_FRAME_IDX_82, $04
+	db SPRITE_ANIM_FRAME_IDX_81, $0c
+	db SPRITE_ANIM_FRAME_IDX_82, $0c
+	db SPRITE_ANIM_FRAME_IDX_83, $04
+	db SPRITE_ANIM_FRAME_IDX_84, $20
+	db SPRITE_ANIM_FRAME_IDX_85, $03
+	db SPRITE_ANIM_FRAME_IDX_86, $03
+	db SPRITE_ANIM_FRAME_IDX_87, $04
+	db SPRITE_ANIM_FRAME_IDX_88, $04
+	db SPRITE_ANIM_FRAME_IDX_89, $04
+	db SPRITE_ANIM_FRAME_IDX_8A, $0a
+	db SPRITE_ANIM_FRAME_IDX_8B, $07
 	db -1
 
 .Frameset_0b:
-	db $23, $03
-	db $23, $83
+	db SPRITE_ANIM_FRAME_IDX_23, $03
+	db SPRITE_ANIM_FRAME_IDX_23, $83
 	db -2
 
 .Frameset_0c:
-	db $24, $02
-	db $25, $02
-	db $26, $02
-	db $25, $02
+	db SPRITE_ANIM_FRAME_IDX_24, $02
+	db SPRITE_ANIM_FRAME_IDX_25, $02
+	db SPRITE_ANIM_FRAME_IDX_26, $02
+	db SPRITE_ANIM_FRAME_IDX_25, $02
 	db -2
 
 .Frameset_0d:
-	db $27, $07
-	db $28, $07
-	db $27, $87
-	db $28, $47
+	db SPRITE_ANIM_FRAME_IDX_27, $07
+	db SPRITE_ANIM_FRAME_IDX_28, $07
+	db SPRITE_ANIM_FRAME_IDX_27, $87
+	db SPRITE_ANIM_FRAME_IDX_28, $47
 	db -2
 
 .Frameset_0e:
-	db $29, $07
-	db $2a, $07
-	db $29, $07
-	db $2b, $07
+	db SPRITE_ANIM_FRAME_IDX_29, $07
+	db SPRITE_ANIM_FRAME_IDX_2A, $07
+	db SPRITE_ANIM_FRAME_IDX_29, $07
+	db SPRITE_ANIM_FRAME_IDX_2B, $07
 	db -2
 
 .Frameset_0f:
-	db $29, $07
-	db $2c, $07
-	db $2d, $07
-	db $2c, $07
-	db $29, $07
+	db SPRITE_ANIM_FRAME_IDX_29, $07
+	db SPRITE_ANIM_FRAME_IDX_2C, $07
+	db SPRITE_ANIM_FRAME_IDX_2D, $07
+	db SPRITE_ANIM_FRAME_IDX_2C, $07
+	db SPRITE_ANIM_FRAME_IDX_29, $07
 	db -1
 
 .Frameset_10:
-	db $2e, $14
+	db SPRITE_ANIM_FRAME_IDX_2E, $14
 	db -1
 
 .Frameset_12:
-	db $2f, $20
+	db SPRITE_ANIM_FRAME_IDX_2F, $20
 	db -1
 
 .Frameset_13:
-	db $30, $20
+	db SPRITE_ANIM_FRAME_IDX_30, $20
 	db -1
 
 .Frameset_14:
-	db $30, $03
-	db $31, $03
-	db $30, $03
-	db $31, $43
+	db SPRITE_ANIM_FRAME_IDX_30, $03
+	db SPRITE_ANIM_FRAME_IDX_31, $03
+	db SPRITE_ANIM_FRAME_IDX_30, $03
+	db SPRITE_ANIM_FRAME_IDX_31, $43
 	db -2
 
 .Frameset_15:
-	db $32, $04
-	db $33, $04
-	db $34, $04
+	db SPRITE_ANIM_FRAME_IDX_32, $04
+	db SPRITE_ANIM_FRAME_IDX_33, $04
+	db SPRITE_ANIM_FRAME_IDX_34, $04
 	db -4
 
 .Frameset_16:
-	db $35, $03
-	db $36, $03
+	db SPRITE_ANIM_FRAME_IDX_35, $03
+	db SPRITE_ANIM_FRAME_IDX_36, $03
 	db -2
 
 .Frameset_17:
-	db $37, $07
-	db $38, $07
+	db SPRITE_ANIM_FRAME_IDX_37, $07
+	db SPRITE_ANIM_FRAME_IDX_38, $07
 	db -2
 
 .Frameset_18:
-	db $39, $20
+	db SPRITE_ANIM_FRAME_IDX_39, $20
 	db -1
 
 .Frameset_19:
-	db $3b, $02
-	db $3a, $02
-	db $3b, $02
+	db SPRITE_ANIM_FRAME_IDX_3B, $02
+	db SPRITE_ANIM_FRAME_IDX_3A, $02
+	db SPRITE_ANIM_FRAME_IDX_3B, $02
 	db -1
 
 .Frameset_1a:
-	db $3c, $20
+	db SPRITE_ANIM_FRAME_IDX_3C, $20
 	db -1
 
 .Frameset_1b:
-	db $41, $08
-	db $42, $08
-	db $41, $08
-	db $42, $48
+	db SPRITE_ANIM_FRAME_IDX_41, $08
+	db SPRITE_ANIM_FRAME_IDX_42, $08
+	db SPRITE_ANIM_FRAME_IDX_41, $08
+	db SPRITE_ANIM_FRAME_IDX_42, $48
 	db -2
-	db $43, $08
-	db $44, $08
+
+; XXX
+	db SPRITE_ANIM_FRAME_IDX_43, $08
+	db SPRITE_ANIM_FRAME_IDX_44, $08
 	db -2
-	db $45, $08
-	db $46, $08
+
+; XXX
+	db SPRITE_ANIM_FRAME_IDX_45, $08
+	db SPRITE_ANIM_FRAME_IDX_46, $08
 	db -2
-	db $47, $08
-	db $48, $08
+
+; XXX
+	db SPRITE_ANIM_FRAME_IDX_47, $08
+	db SPRITE_ANIM_FRAME_IDX_48, $08
 	db -2
-	db $49, $01
-	db $49, $41
-	db $49, $c1
-	db $49, $81
+
+; XXX
+	db SPRITE_ANIM_FRAME_IDX_49, $01
+	db SPRITE_ANIM_FRAME_IDX_49, $41
+	db SPRITE_ANIM_FRAME_IDX_49, $c1
+	db SPRITE_ANIM_FRAME_IDX_49, $81
 	db -2
-	db $4a, $20
+
+; XXX
+	db SPRITE_ANIM_FRAME_IDX_4A, $20
 	db -1
-	db $4b, $20
+
+; XXX
+	db SPRITE_ANIM_FRAME_IDX_4B, $20
 	db -1
-	db $4c, $20
+
+; XXX
+	db SPRITE_ANIM_FRAME_IDX_4C, $20
 	db -1
-	db $4d, $20
+
+; XXX
+	db SPRITE_ANIM_FRAME_IDX_4D, $20
 	db -1
-	db $4e, $03
+
+; XXX
+	db SPRITE_ANIM_FRAME_IDX_4E, $03
 	db -3, $03
 	db -2
 
@@ -275,193 +293,193 @@
 	db -1
 
 .Frameset_1d:
-	db $4f, $20
+	db SPRITE_ANIM_FRAME_IDX_4F, $20
 	db -1
 
 .Frameset_1e:
-	db $50, $02
-	db $51, $10
+	db SPRITE_ANIM_FRAME_IDX_50, $02
+	db SPRITE_ANIM_FRAME_IDX_51, $10
 	db -3, $01
-	db $52, $01
+	db SPRITE_ANIM_FRAME_IDX_52, $01
 	db -3, $01
-	db $53, $01
+	db SPRITE_ANIM_FRAME_IDX_53, $01
 	db -4
 
 .Frameset_1f:
-	db $54, $20
+	db SPRITE_ANIM_FRAME_IDX_54, $20
 	db -1
 
 .Frameset_20:
-	db $55, $20
+	db SPRITE_ANIM_FRAME_IDX_55, $20
 	db -1
 
 .Frameset_21:
-	db $55, $60
+	db SPRITE_ANIM_FRAME_IDX_55, $60
 	db -1
 
 .Frameset_22:
-	db $55, $a0
+	db SPRITE_ANIM_FRAME_IDX_55, $a0
 	db -1
 
 .Frameset_23:
-	db $55, $e0
+	db SPRITE_ANIM_FRAME_IDX_55, $e0
 	db -1
 
 .Frameset_24:
-	db $56, $0a
-	db $57, $09
-	db $58, $0a
-	db $59, $0a
-	db $58, $09
-	db $5a, $0a
+	db SPRITE_ANIM_FRAME_IDX_56, $0a
+	db SPRITE_ANIM_FRAME_IDX_57, $09
+	db SPRITE_ANIM_FRAME_IDX_58, $0a
+	db SPRITE_ANIM_FRAME_IDX_59, $0a
+	db SPRITE_ANIM_FRAME_IDX_58, $09
+	db SPRITE_ANIM_FRAME_IDX_5A, $0a
 	db -2
 
 .Frameset_25:
-	db $50, $02
-	db $5b, $02
-	db $50, $02
-	db $5b, $42
+	db SPRITE_ANIM_FRAME_IDX_50, $02
+	db SPRITE_ANIM_FRAME_IDX_5B, $02
+	db SPRITE_ANIM_FRAME_IDX_50, $02
+	db SPRITE_ANIM_FRAME_IDX_5B, $42
 	db -2
 
 .Frameset_26:
-	db $5c, $02
+	db SPRITE_ANIM_FRAME_IDX_5C, $02
 	db -1
 
 .Frameset_27:
-	db $5d, $02
+	db SPRITE_ANIM_FRAME_IDX_5D, $02
 	db -1
 
 .Frameset_28:
-	db $5e, $02
+	db SPRITE_ANIM_FRAME_IDX_5E, $02
 	db -1
 
 .Frameset_29:
-	db $5f, $02
+	db SPRITE_ANIM_FRAME_IDX_5F, $02
 	db -1
 
 .Frameset_2a:
-	db $60, $02
+	db SPRITE_ANIM_FRAME_IDX_60, $02
 	db -1
 
 .Frameset_2b:
-	db $61, $02
+	db SPRITE_ANIM_FRAME_IDX_61, $02
 	db -1
 
 .Frameset_2c:
-	db $62, $02
+	db SPRITE_ANIM_FRAME_IDX_62, $02
 	db -1
 
 .Frameset_2f:
-	db $32, $03
-	db $33, $03
-	db $34, $03
-	db $30, $03
-	db $31, $03
-	db $30, $03
-	db $31, $43
-	db $30, $03
-	db $31, $03
-	db $30, $03
-	db $31, $43
-	db $30, $03
-	db $31, $03
-	db $30, $03
-	db $31, $43
+	db SPRITE_ANIM_FRAME_IDX_32, $03
+	db SPRITE_ANIM_FRAME_IDX_33, $03
+	db SPRITE_ANIM_FRAME_IDX_34, $03
+	db SPRITE_ANIM_FRAME_IDX_30, $03
+	db SPRITE_ANIM_FRAME_IDX_31, $03
+	db SPRITE_ANIM_FRAME_IDX_30, $03
+	db SPRITE_ANIM_FRAME_IDX_31, $43
+	db SPRITE_ANIM_FRAME_IDX_30, $03
+	db SPRITE_ANIM_FRAME_IDX_31, $03
+	db SPRITE_ANIM_FRAME_IDX_30, $03
+	db SPRITE_ANIM_FRAME_IDX_31, $43
+	db SPRITE_ANIM_FRAME_IDX_30, $03
+	db SPRITE_ANIM_FRAME_IDX_31, $03
+	db SPRITE_ANIM_FRAME_IDX_30, $03
+	db SPRITE_ANIM_FRAME_IDX_31, $43
 	db -1
 
 .Frameset_30:
-	db $30, $03
-	db $31, $03
-	db $30, $03
-	db $31, $43
-	db $30, $03
-	db $31, $03
-	db $30, $03
-	db $31, $43
-	db $30, $03
-	db $31, $03
-	db $30, $03
-	db $31, $43
-	db $32, $03
-	db $33, $03
-	db $34, $03
+	db SPRITE_ANIM_FRAME_IDX_30, $03
+	db SPRITE_ANIM_FRAME_IDX_31, $03
+	db SPRITE_ANIM_FRAME_IDX_30, $03
+	db SPRITE_ANIM_FRAME_IDX_31, $43
+	db SPRITE_ANIM_FRAME_IDX_30, $03
+	db SPRITE_ANIM_FRAME_IDX_31, $03
+	db SPRITE_ANIM_FRAME_IDX_30, $03
+	db SPRITE_ANIM_FRAME_IDX_31, $43
+	db SPRITE_ANIM_FRAME_IDX_30, $03
+	db SPRITE_ANIM_FRAME_IDX_31, $03
+	db SPRITE_ANIM_FRAME_IDX_30, $03
+	db SPRITE_ANIM_FRAME_IDX_31, $43
+	db SPRITE_ANIM_FRAME_IDX_32, $03
+	db SPRITE_ANIM_FRAME_IDX_33, $03
+	db SPRITE_ANIM_FRAME_IDX_34, $03
 	db -4
 
 .Frameset_31:
-	db $67, $03
-	db $68, $03
+	db SPRITE_ANIM_FRAME_IDX_67, $03
+	db SPRITE_ANIM_FRAME_IDX_68, $03
 	db -2
 
 .Frameset_32:
-	db $6c, $03
+	db SPRITE_ANIM_FRAME_IDX_6C, $03
 	db -1
 
 .Frameset_33:
-	db $6d, $03
+	db SPRITE_ANIM_FRAME_IDX_6D, $03
 	db -1
 
 .Frameset_34:
-	db $69, $02
-	db $6a, $02
-	db $6b, $02
+	db SPRITE_ANIM_FRAME_IDX_69, $02
+	db SPRITE_ANIM_FRAME_IDX_6A, $02
+	db SPRITE_ANIM_FRAME_IDX_6B, $02
 	db -4
 
 .Frameset_35:
-	db $6e, $03
-	db $6f, $03
-	db $70, $03
-	db $71, $03
+	db SPRITE_ANIM_FRAME_IDX_6E, $03
+	db SPRITE_ANIM_FRAME_IDX_6F, $03
+	db SPRITE_ANIM_FRAME_IDX_70, $03
+	db SPRITE_ANIM_FRAME_IDX_71, $03
 	db -2
 
 .Frameset_36:
-	db $71, $03
-	db $6e, $07
+	db SPRITE_ANIM_FRAME_IDX_71, $03
+	db SPRITE_ANIM_FRAME_IDX_6E, $07
 	db -1
 
 .Frameset_37:
-	db $72, $20
-	db $73, $07
-	db $74, $07
+	db SPRITE_ANIM_FRAME_IDX_72, $20
+	db SPRITE_ANIM_FRAME_IDX_73, $07
+	db SPRITE_ANIM_FRAME_IDX_74, $07
 	db -1
 
 .Frameset_38:
-	db $75, $03
+	db SPRITE_ANIM_FRAME_IDX_75, $03
 	db -1
 
 .Frameset_39:
-	db $76, $03
-	db $77, $03
-	db $78, $07
+	db SPRITE_ANIM_FRAME_IDX_76, $03
+	db SPRITE_ANIM_FRAME_IDX_77, $03
+	db SPRITE_ANIM_FRAME_IDX_78, $07
 	db -4
 
 .Frameset_3a:
-	db $76, $43
-	db $77, $43
-	db $78, $47
+	db SPRITE_ANIM_FRAME_IDX_76, $43
+	db SPRITE_ANIM_FRAME_IDX_77, $43
+	db SPRITE_ANIM_FRAME_IDX_78, $47
 	db -4
 
 .Frameset_3b:
-	db $76, $83
-	db $77, $83
-	db $78, $87
+	db SPRITE_ANIM_FRAME_IDX_76, $83
+	db SPRITE_ANIM_FRAME_IDX_77, $83
+	db SPRITE_ANIM_FRAME_IDX_78, $87
 	db -4
 
 .Frameset_3c:
-	db $76, $c3
-	db $77, $c3
-	db $78, $c7
+	db SPRITE_ANIM_FRAME_IDX_76, $c3
+	db SPRITE_ANIM_FRAME_IDX_77, $c3
+	db SPRITE_ANIM_FRAME_IDX_78, $c7
 	db -4
 
 .Frameset_3d:
-	db $79, $03
-	db $7a, $03
-	db $7b, $03
-	db $7c, $07
-	db $7d, $07
+	db SPRITE_ANIM_FRAME_IDX_79, $03
+	db SPRITE_ANIM_FRAME_IDX_7A, $03
+	db SPRITE_ANIM_FRAME_IDX_7B, $03
+	db SPRITE_ANIM_FRAME_IDX_7C, $07
+	db SPRITE_ANIM_FRAME_IDX_7D, $07
 	db -1
 
 .Frameset_3e:
-	db $7e, $03
+	db SPRITE_ANIM_FRAME_IDX_7E, $03
 	db -1
 
 .Frameset_3f:
@@ -469,13 +487,13 @@
 	db -1
 
 .Frameset_40:
-	db $7f, $08
-	db $80, $08
+	db SPRITE_ANIM_FRAME_IDX_7F, $08
+	db SPRITE_ANIM_FRAME_IDX_80, $08
 	db -1
 
 .Frameset_41:
-	db $7f, $48
-	db $80, $48
+	db SPRITE_ANIM_FRAME_IDX_7F, $48
+	db SPRITE_ANIM_FRAME_IDX_80, $48
 	db -1
 ; 8d94d
 
--- a/engine/link.asm
+++ b/engine/link.asm
@@ -25,7 +25,7 @@
 	hlcoord 4, 10
 	ld de, String_PleaseWait
 	call PlaceString
-	call Function28eff
+	call SetTradeRoomBGPals
 	call WaitBGMap2
 	ld hl, wcf5d
 	xor a
@@ -41,7 +41,7 @@
 	call FixDataForLinkTransfer
 	xor a
 	ld [wPlayerLinkAction], a
-	call Function87d
+	call WaitLinkTransfer
 	ld a, [hLinkPlayerNumber]
 	cp $2
 	jr nz, .player_1
@@ -1936,7 +1936,7 @@
 	callab EvolvePokemon
 	call ClearScreen
 	call LoadTradeScreenBorder
-	call Function28eff
+	call SetTradeRoomBGPals
 	callba Link_WaitBGMap
 	ld b, $1
 	pop af
@@ -2029,8 +2029,8 @@
 	ret
 ; 28eff
 
-Function28eff: ; 28eff
-	callba Function16d6a7 ; just a nested farcall; so wasteful
+SetTradeRoomBGPals: ; 28eff
+	callba LoadTradeRoomBGPals_ ; just a nested farcall; so wasteful
 	call SetPalettes
 	ret
 ; 28f09
@@ -2150,7 +2150,7 @@
 	ld c, 10
 	call DelayFrames
 	ld a, $4
-	call Function29f17
+	call Link_EnsureSync
 	ld c, 40
 	call DelayFrames
 	xor a
@@ -2199,7 +2199,7 @@
 	ld [rIE], a
 	pop af
 	ld [rIF], a
-	ld hl, wcf5b
+	ld hl, wLinkTimeoutFrames
 	xor a
 	ld [hli], a
 	ld [hl], a
@@ -2240,7 +2240,7 @@
 Special_WaitForLinkedFriend: ; 29d11
 	ld a, [wPlayerLinkAction]
 	and a
-	jr z, .asm_29d2f
+	jr z, .no_link_action
 	ld a, $2
 	ld [rSB], a
 	xor a
@@ -2253,17 +2253,17 @@
 	call DelayFrame
 	call DelayFrame
 
-.asm_29d2f
+.no_link_action
 	ld a, $2
-	ld [wcf5b + 1], a
+	ld [wLinkTimeoutFrames + 1], a
 	ld a, $ff
-	ld [wcf5b], a
-.asm_29d39
+	ld [wLinkTimeoutFrames], a
+.loop
 	ld a, [hLinkPlayerNumber]
 	cp $2
-	jr z, .asm_29d79
+	jr z, .connected
 	cp $1
-	jr z, .asm_29d79
+	jr z, .connected
 	ld a, -1
 	ld [hLinkPlayerNumber], a
 	ld a, $2
@@ -2274,16 +2274,16 @@
 	ld [rSC], a
 	ld a, $80
 	ld [rSC], a
-	ld a, [wcf5b]
+	ld a, [wLinkTimeoutFrames]
 	dec a
-	ld [wcf5b], a
-	jr nz, .asm_29d68
-	ld a, [wcf5b + 1]
+	ld [wLinkTimeoutFrames], a
+	jr nz, .not_done
+	ld a, [wLinkTimeoutFrames + 1]
 	dec a
-	ld [wcf5b + 1], a
-	jr z, .asm_29d8d
+	ld [wLinkTimeoutFrames + 1], a
+	jr z, .done
 
-.asm_29d68
+.not_done
 	ld a, $1
 	ld [rSB], a
 	ld a, $1
@@ -2291,19 +2291,19 @@
 	ld a, $81
 	ld [rSC], a
 	call DelayFrame
-	jr .asm_29d39
+	jr .loop
 
-.asm_29d79
+.connected
 	call LinkDataReceived
 	call DelayFrame
 	call LinkDataReceived
-	ld c, $32
+	ld c, 50
 	call DelayFrames
 	ld a, $1
 	ld [ScriptVar], a
 	ret
 
-.asm_29d8d
+.done
 	xor a
 	ld [ScriptVar], a
 	ret
@@ -2312,7 +2312,7 @@
 Special_CheckLinkTimeout: ; 29d92
 	ld a, $1
 	ld [wPlayerLinkAction], a
-	ld hl, wcf5b
+	ld hl, wLinkTimeoutFrames
 	ld a, $3
 	ld [hli], a
 	xor a
@@ -2322,19 +2322,19 @@
 	ld [hVBlank], a
 	call DelayFrame
 	call DelayFrame
-	call Function29e0c
+	call Link_CheckCommunicationError
 	xor a
 	ld [hVBlank], a
 	ld a, [ScriptVar]
 	and a
 	ret nz
-	jp Function29f04
+	jp Link_ResetSerialRegistersAfterLinkClosure
 ; 29dba
 
 Function29dba: ; 29dba
 	ld a, $5
 	ld [wPlayerLinkAction], a
-	ld hl, wcf5b
+	ld hl, wLinkTimeoutFrames
 	ld a, $3
 	ld [hli], a
 	xor a
@@ -2344,7 +2344,7 @@
 	ld [hVBlank], a
 	call DelayFrame
 	call DelayFrame
-	call Function29e0c
+	call Link_CheckCommunicationError
 	ld a, [ScriptVar]
 	and a
 	jr z, .vblank
@@ -2359,11 +2359,11 @@
 	jr nz, .script_var
 	ld a, $6
 	ld [wPlayerLinkAction], a
-	ld hl, wcf5b
+	ld hl, wLinkTimeoutFrames
 	ld a, $1
 	ld [hli], a
 	ld [hl], $32
-	call Function29e0c
+	call Link_CheckCommunicationError
 	ld a, [wOtherPlayerLinkMode]
 	cp $6
 	jr z, .vblank
@@ -2379,12 +2379,12 @@
 	ret
 ; 29e0c
 
-Function29e0c: ; 29e0c
+Link_CheckCommunicationError: ; 29e0c
 	xor a
 	ld [hFFCA], a
-	ld a, [wcf5b]
+	ld a, [wLinkTimeoutFrames]
 	ld h, a
-	ld a, [wcf5b + 1]
+	ld a, [wLinkTimeoutFrames + 1]
 	ld l, a
 	push hl
 	call .CheckConnected
@@ -2403,7 +2403,7 @@
 
 .load_scriptvar
 	ld [ScriptVar], a
-	ld hl, wcf5b
+	ld hl, wLinkTimeoutFrames
 	xor a
 	ld [hli], a
 	ld [hl], a
@@ -2411,8 +2411,8 @@
 ; 29e3b
 
 .CheckConnected: ; 29e3b
-	call Function87d
-	ld hl, wcf5b
+	call WaitLinkTransfer
+	ld hl, wLinkTimeoutFrames
 	ld a, [hli]
 	inc a
 	ret nz
@@ -2432,8 +2432,8 @@
 ; 29e53
 
 .ConvertDW: ; 29e53
-	; hl = ((hl - $100) / 4) + $100
-	;    = (hl / 4) + $c0
+	; [wLinkTimeoutFrames] = ((hl - $100) / 4) + $100
+	;         = (hl / 4) + $c0
 	dec h
 	srl h
 	rr l
@@ -2441,9 +2441,9 @@
 	rr l
 	inc h
 	ld a, h
-	ld [wcf5b], a
+	ld [wLinkTimeoutFrames], a
 	ld a, l
-	ld [wcf5b + 1], a
+	ld [wLinkTimeoutFrames + 1], a
 	ret
 ; 29e66
 
@@ -2452,12 +2452,11 @@
 	push af
 	callba Link_SaveGame
 	ld a, $1
-	jr nc, .asm_29e75
+	jr nc, .return_result
 	xor a
-
-.asm_29e75
+.return_result
 	ld [ScriptVar], a
-	ld c, $1e
+	ld c, 30
 	call DelayFrames
 	pop af
 	ld [wd265], a
@@ -2466,7 +2465,7 @@
 
 Special_CheckBothSelectedSameRoom: ; 29e82
 	ld a, [wd265]
-	call Function29f17
+	call Link_EnsureSync
 	push af
 	call LinkDataReceived
 	call DelayFrame
@@ -2527,9 +2526,9 @@
 Special_CloseLink: ; 29eee
 	xor a
 	ld [wLinkMode], a
-	ld c, $3
+	ld c, 3
 	call DelayFrames
-	jp Function29f04
+	jp Link_ResetSerialRegistersAfterLinkClosure
 ; 29efa
 
 Special_FailedLinkToPast: ; 29efa
@@ -2536,10 +2535,10 @@
 	ld c, 40
 	call DelayFrames
 	ld a, $e
-	jp Function29f17
+	jp Link_EnsureSync
 ; 29f04
 
-Function29f04: ; 29f04
+Link_ResetSerialRegistersAfterLinkClosure: ; 29f04
 	ld c, 3
 	call DelayFrames
 	ld a, -1
@@ -2552,7 +2551,7 @@
 	ret
 ; 29f17
 
-Function29f17: ; 29f17
+Link_EnsureSync: ; 29f17
 	add $d0
 	ld [wPlayerLinkAction], a
 	ld [wcf57], a
--- a/engine/link_trade.asm
+++ b/engine/link_trade.asm
@@ -145,8 +145,8 @@
 	ret
 ; 16d6a7
 
-Function16d6a7: ; 16d6a7
-	callba Function49811
+LoadTradeRoomBGPals_: ; 16d6a7
+	callba LoadTradeRoomBGPals
 	ret
 ; 16d6ae
 
@@ -171,7 +171,7 @@
 Function16d6ce: ; 16d6ce
 	call LoadStandardMenuDataHeader
 	call Function16d6e1
-	callba Function87d
+	callba WaitLinkTransfer
 	call Call_ExitMenu
 	call WaitBGMap2
 	ret
--- a/engine/mon_icons.asm
+++ b/engine/mon_icons.asm
@@ -38,11 +38,11 @@
 
 
 .Jumptable: ; 8e854 (23:6854)
-	dw Function8e8d5 ; party menu
-	dw Function8e961 ; naming screen
-	dw Function8e97d ; moves (?)
+	dw PartyMenu_InitAnimatedMonIcon ; party menu
+	dw NamingScreen_InitAnimatedMonIcon ; naming screen
+	dw MoveList_InitAnimatedMonIcon ; moves (?)
 	dw Trade_LoadMonIconGFX ; trade
-	dw Function8e898 ; mobile
+	dw Mobile_InitAnimatedMonIcon ; mobile
 	dw Mobile_InitPartyMenuBGPal71 ; mobile
 	dw .GetPartyMenuMonIcon ; unused
 
@@ -84,8 +84,8 @@
 	ld [hl], a
 	ret
 
-Function8e898: ; 8e898 (23:6898)
-	call Function8e8d5
+Mobile_InitAnimatedMonIcon: ; 8e898 (23:6898)
+	call PartyMenu_InitAnimatedMonIcon
 	ld hl, SPRITEANIMSTRUCT_ANIM_SEQ_ID
 	add hl, bc
 	ld a, SPRITE_ANIM_SEQ_NULL
@@ -121,7 +121,7 @@
 	ld [wc608 + 1], a
 	ret
 
-Function8e8d5: ; 8e8d5 (23:68d5)
+PartyMenu_InitAnimatedMonIcon: ; 8e8d5 (23:68d5)
 	call InitPartyMenuIcon
 	call .SpawnItemIcon
 	call SetPartyMonIconAnimSpeed
@@ -144,11 +144,11 @@
 	pop bc
 	pop hl
 	jr c, .mail
-	ld a, $3
+	ld a, SPRITE_ANIM_FRAMESET_03
 	jr .okay
 
 .mail
-	ld a, $2
+	ld a, SPRITE_ANIM_FRAMESET_02
 .okay
 	ld hl, SPRITEANIMSTRUCT_FRAMESET_ID
 	add hl, bc
@@ -218,7 +218,7 @@
 	db $00, $40, $80
 ; 8e961
 
-Function8e961: ; 8e961 (23:6961)
+NamingScreen_InitAnimatedMonIcon: ; 8e961 (23:6961)
 	ld a, [wd265]
 	call ReadMonMenuIcon
 	ld [CurIcon], a
@@ -232,7 +232,7 @@
 	ld [hl], SPRITE_ANIM_SEQ_NULL
 	ret
 
-Function8e97d: ; 8e97d (23:697d)
+MoveList_InitAnimatedMonIcon: ; 8e97d (23:697d)
 	ld a, [wd265]
 	call ReadMonMenuIcon
 	ld [CurIcon], a
--- a/engine/radio.asm
+++ b/engine/radio.asm
@@ -201,10 +201,11 @@
 
 OaksPkmnTalk4:
 ; Choose a random route, and a random Pokemon from that route.
+.sample
 	call Random
 	and $1f
-	cp $f
-	jr nc, OaksPkmnTalk4
+	cp $f ; so wasteful
+	jr nc, .sample
 	; We now have a number between 0 and 14.
 	ld hl, .routes
 	ld c, a
@@ -1576,7 +1577,8 @@
 ; There are only 11 groups to choose from.
 .greater_than_11
 	call Random
-	and $f
+	maskbits NUM_PASSWORD_CATEGORIES
+	and x
 	cp NUM_PASSWORD_CATEGORIES
 	jr nc, .greater_than_11
 ; Store it in the high nybble of e.
--- a/engine/startmenu.asm
+++ b/engine/startmenu.asm
@@ -1457,7 +1457,7 @@
 	push af
 	set NO_TEXT_SCROLL, [hl]
 	call LoadFontsBattleExtra
-	call .asm_12f73
+	call .ChooseMoveToDelete
 	pop bc
 	ld a, b
 	ld [Options], a
@@ -1467,7 +1467,7 @@
 	ret
 ; 12f73
 
-.asm_12f73
+.ChooseMoveToDelete
 	call SetUpMoveScreenBG
 	ld de, DeleteMoveScreenAttrs
 	call SetMenuAttributes
@@ -1474,29 +1474,29 @@
 	call SetUpMoveList
 	ld hl, w2DMenuFlags1
 	set 6, [hl]
-	jr .asm_12f93
+	jr .enter_loop
 
-.asm_12f86
+.loop
 	call ScrollingMenuJoypad
-	bit 1, a
-	jp nz, .asm_12f9f
-	bit 0, a
-	jp nz, .asm_12f9c
+	bit B_BUTTON_F, a
+	jp nz, .b_button
+	bit A_BUTTON_F, a
+	jp nz, .a_button
 
-.asm_12f93
+.enter_loop
 	call PrepareToPlaceMoveData
 	call PlaceMoveData
-	jp .asm_12f86
+	jp .loop
 ; 12f9c
 
-.asm_12f9c
+.a_button
 	and a
-	jr .asm_12fa0
+	jr .finish
 
-.asm_12f9f
+.b_button
 	scf
 
-.asm_12fa0
+.finish
 	push af
 	xor a
 	ld [wSwitchMon], a
--- a/home/serial.asm
+++ b/home/serial.asm
@@ -143,12 +143,12 @@
 	jr nz, .reset_ffca
 	ld a, [hLinkPlayerNumber]
 	cp $1
-	jr nz, .not_player_1_or_wcf5b_zero
-	call Checkwcf5bNonzero
-	jr z, .not_player_1_or_wcf5b_zero
+	jr nz, .not_player_1_or_wLinkTimeoutFrames_zero
+	call CheckwLinkTimeoutFramesNonzero
+	jr z, .not_player_1_or_wLinkTimeoutFrames_zero
 	call .delay_15_cycles
 	push hl
-	ld hl, wcf5b + 1
+	ld hl, wLinkTimeoutFrames + 1
 	inc [hl]
 	jr nz, .no_rollover_up
 	dec hl
@@ -156,11 +156,11 @@
 
 .no_rollover_up
 	pop hl
-	call Checkwcf5bNonzero
+	call CheckwLinkTimeoutFramesNonzero
 	jr nz, .loop2
 	jp SerialDisconnected
 
-.not_player_1_or_wcf5b_zero
+.not_player_1_or_wLinkTimeoutFrames_zero
 	ld a, [rIE]
 	and $f
 	cp $8
@@ -176,6 +176,7 @@
 	ld a, [hLinkPlayerNumber]
 	cp $1
 	jr z, .reset_ffca
+
 	ld a, 255
 .delay_255_cycles
 	dec a
@@ -188,6 +189,7 @@
 	and $f
 	sub $8
 	jr nz, .rIE_not_equal_8
+
 	ld [wcf5d], a
 	ld a, $50
 	ld [wcf5d + 1], a
@@ -196,10 +198,10 @@
 	ld a, [hSerialReceive]
 	cp $fe
 	ret nz
-	call Checkwcf5bNonzero
-	jr z, .wcf5b_zero
+	call CheckwLinkTimeoutFramesNonzero
+	jr z, .wLinkTimeoutFrames_zero
 	push hl
-	ld hl, wcf5b + 1
+	ld hl, wLinkTimeoutFrames + 1
 	ld a, [hl]
 	dec a
 	ld [hld], a
@@ -209,10 +211,10 @@
 
 .no_rollover
 	pop hl
-	call Checkwcf5bNonzero
+	call CheckwLinkTimeoutFramesNonzero
 	jr z, SerialDisconnected
 
-.wcf5b_zero
+.wLinkTimeoutFrames_zero
 	ld a, [rIE]
 	and $f
 	cp $8
@@ -231,9 +233,9 @@
 	ret
 ; 82b
 
-Checkwcf5bNonzero:: ; 82b
+CheckwLinkTimeoutFramesNonzero:: ; 82b
 	push hl
-	ld hl, wcf5b
+	ld hl, wLinkTimeoutFrames
 	ld a, [hli]
 	or [hl]
 	pop hl
@@ -242,8 +244,8 @@
 
 SerialDisconnected:: ; 833
 	dec a
-	ld [wcf5b], a
-	ld [wcf5b + 1], a
+	ld [wLinkTimeoutFrames], a
+	ld [wLinkTimeoutFrames + 1], a
 	ret
 ; 83b
 
@@ -276,7 +278,7 @@
 Function862:: ; 862
 	call LoadTileMapToTempTileMap
 	callab PlaceWaitingText
-	call Function87d
+	call WaitLinkTransfer
 	jp Call_LoadTempTileMapToTileMap
 ; 871
 
@@ -284,21 +286,21 @@
 Function871:: ; 871
 	call LoadTileMapToTempTileMap
 	callab PlaceWaitingText
-	jp Function87d
+	jp WaitLinkTransfer
 ; 87d
 
 ; One "giant" leap for machinekind
 
-Function87d:: ; 87d
+WaitLinkTransfer:: ; 87d
 	ld a, $ff
 	ld [wOtherPlayerLinkAction], a
 .loop
 	call LinkTransfer
 	call DelayFrame
-	call Checkwcf5bNonzero
+	call CheckwLinkTimeoutFramesNonzero
 	jr z, .check
 	push hl
-	ld hl, wcf5b + 1
+	ld hl, wLinkTimeoutFrames + 1
 	dec [hl]
 	jr nz, .skip
 	dec hl
--- a/home/time.asm
+++ b/home/time.asm
@@ -48,17 +48,20 @@
 
 	ld [hl], RTC_S
 	ld a, [de]
-	and $3f
+	maskbits 60
+	and x
 	ld [hRTCSeconds], a
 
 	ld [hl], RTC_M
 	ld a, [de]
-	and $3f
+	maskbits 60
+	and x
 	ld [hRTCMinutes], a
 
 	ld [hl], RTC_H
 	ld a, [de]
-	and $1f
+	maskbits 24
+	and x
 	ld [hRTCHours], a
 
 	ld [hl], RTC_DL
--- a/macros.asm
+++ b/macros.asm
@@ -270,3 +270,22 @@
 	ld l, a
 	jp [hl]
 endm
+
+maskbits: macro
+; returns to x
+; usage in rejection sampling
+; .loop
+; 	call Random
+; 	maskbits 30
+; 	and x
+; 	cp 30
+; 	jr nc, .loop
+
+x = 1
+rept 8
+IF \1 > x
+x = (x + 1) * 2 +- 1
+ENDC
+endr
+endm
+
--- a/main.asm
+++ b/main.asm
@@ -2507,7 +2507,7 @@
 	callba LoadTradeScreenBorder
 	callba Link_WaitBGMap
 	callba InitTradeSpeciesList
-	callba Function28eff
+	callba SetTradeRoomBGPals
 	call WaitBGMap2
 	ret
 
--- a/predef/crystal.asm
+++ b/predef/crystal.asm
@@ -566,7 +566,7 @@
 	ret
 ; 49811
 
-Function49811: ; 49811
+LoadTradeRoomBGPals: ; 49811
 	ld hl, Palette_49826
 	ld de, UnknBGPals + $10
 	ld bc, $30
--- a/wram.asm
+++ b/wram.asm
@@ -536,10 +536,18 @@
 	ds 1
 
 PlayerStats:: ; c6b6
-	ds 10
+PlayerAttack:: ds 2
+PlayerDefense:: ds 2
+PlayerSpeed:: ds 2
+PlayerSpAtk:: ds 2
+PlayerSpDef:: ds 2
 	ds 1
 EnemyStats:: ; c6c1
-	ds 10
+EnemyAttack:: ds 2
+EnemyDefense:: ds 2
+EnemySpeed:: ds 2
+EnemySpAtk:: ds 2
+EnemySpDef:: ds 2
 	ds 1
 
 PlayerStatLevels:: ; c6cc
@@ -1270,7 +1278,7 @@
 wOtherPlayerLinkAction:: ds 4
 wPlayerLinkAction:: ds 1
 wcf57:: ds 4
-wcf5b:: dw
+wLinkTimeoutFrames:: dw ; cf5b
 wcf5d:: ds 2
 
 MonType:: ; cf5f