shithub: pokecrystal

Download patch

ref: 2d0ed1159e187d7dcdefd982fc6babea9f303f1e
parent: 8c3905c4cdb4f24810473da51d52cc3e16062173
author: Remy Oukaour <remy.oukaour@gmail.com>
date: Mon Jan 1 08:43:02 EST 2018

Use constants for rBGPI+rOBPI auto-increment
Fix some documentation

--- a/constants/hardware_constants.asm
+++ b/constants/hardware_constants.asm
@@ -145,8 +145,10 @@
 rHDMA5      EQU $ff55 ; CGB Mode Only - New DMA Length/Mode/Start
 rRP         EQU $ff56 ; CGB Mode Only - Infrared Communications Port
 rBGPI       EQU $ff68 ; CGB Mode Only - Background Palette Index
+rBGPI_AUTO_INCREMENT EQU 7 ; increment rBGPI after write to rBGPD
 rBGPD       EQU $ff69 ; CGB Mode Only - Background Palette Data
 rOBPI       EQU $ff6a ; CGB Mode Only - Sprite Palette Index
+rOBPI_AUTO_INCREMENT EQU 7 ; increment rOBPI after write to rOBPD
 rOBPD       EQU $ff6b ; CGB Mode Only - Sprite Palette Data
 rUNKNOWN1   EQU $ff6c ; (FEh) Bit 0 (Read/Write) - CGB Mode Only
 rSVBK       EQU $ff70 ; CGB Mode Only - WRAM Bank
--- a/constants/map_constants.asm
+++ b/constants/map_constants.asm
@@ -21,7 +21,7 @@
 ; `mapgroup` indexes are for the sub-tables of MapGroupPointers (see maps/map_headers.asm)
 	const_def
 
-	newgroup                                                    ;  1
+	newgroup                                                     ;  1
 
 	mapgroup OLIVINE_POKECENTER_1F,                        4,  5 ;  1
 	mapgroup OLIVINE_GYM,                                  8,  5 ;  2
@@ -38,7 +38,7 @@
 	mapgroup ROUTE_39,                                    18, 10 ; 13
 	mapgroup OLIVINE_CITY,                                18, 20 ; 14
 
-	newgroup                                                    ;  2
+	newgroup                                                     ;  2
 
 	mapgroup MAHOGANY_RED_GYARADOS_SPEECH_HOUSE,           4,  4 ;  1
 	mapgroup MAHOGANY_GYM,                                 9,  5 ;  2
@@ -48,7 +48,7 @@
 	mapgroup ROUTE_44,                                     9, 30 ;  6
 	mapgroup MAHOGANY_TOWN,                                9, 10 ;  7
 
-	newgroup                                                    ;  3
+	newgroup                                                     ;  3
 
 	mapgroup SPROUT_TOWER_1F,                              8, 10 ;  1
 	mapgroup SPROUT_TOWER_2F,                              8, 10 ;  2
@@ -142,7 +142,7 @@
 	mapgroup SAFARI_ZONE_BETA,                            18, 10 ; 90
 	mapgroup VICTORY_ROAD,                                36, 10 ; 91
 
-	newgroup                                                    ;  4
+	newgroup                                                     ;  4
 
 	mapgroup ECRUTEAK_HOUSE,                               9, 10 ;  1
 	mapgroup WISE_TRIOS_ROOM,                              4,  4 ;  2
@@ -154,7 +154,7 @@
 	mapgroup ECRUTEAK_ITEMFINDER_HOUSE,                    4,  4 ;  8
 	mapgroup ECRUTEAK_CITY,                               18, 20 ;  9
 
-	newgroup                                                    ;  5
+	newgroup                                                     ;  5
 
 	mapgroup BLACKTHORN_GYM_1F,                            9,  5 ;  1
 	mapgroup BLACKTHORN_GYM_2F,                            9,  5 ;  2
@@ -167,7 +167,7 @@
 	mapgroup ROUTE_46,                                    18, 10 ;  9
 	mapgroup BLACKTHORN_CITY,                             18, 20 ; 10
 
-	newgroup                                                    ;  6
+	newgroup                                                     ;  6
 
 	mapgroup CINNABAR_POKECENTER_1F,                       4,  5 ;  1
 	mapgroup CINNABAR_POKECENTER_2F_BETA,                  4,  8 ;  2
@@ -178,7 +178,7 @@
 	mapgroup ROUTE_21,                                    18, 10 ;  7
 	mapgroup CINNABAR_ISLAND,                              9, 10 ;  8
 
-	newgroup                                                    ;  7
+	newgroup                                                     ;  7
 
 	mapgroup CERULEAN_GYM_BADGE_SPEECH_HOUSE,              4,  4 ;  1
 	mapgroup CERULEAN_POLICE_STATION,                      4,  4 ;  2
@@ -198,7 +198,7 @@
 	mapgroup ROUTE_25,                                     9, 30 ; 16
 	mapgroup CERULEAN_CITY,                               18, 20 ; 17
 
-	newgroup                                                    ;  8
+	newgroup                                                     ;  8
 
 	mapgroup AZALEA_POKECENTER_1F,                         4,  5 ;  1
 	mapgroup CHARCOAL_KILN,                                4,  4 ;  2
@@ -208,7 +208,7 @@
 	mapgroup ROUTE_33,                                     9, 10 ;  6
 	mapgroup AZALEA_TOWN,                                  9, 20 ;  7
 
-	newgroup                                                    ;  9
+	newgroup                                                     ;  9
 
 	mapgroup LAKE_OF_RAGE_HIDDEN_POWER_HOUSE,              4,  4 ;  1
 	mapgroup LAKE_OF_RAGE_MAGIKARP_HOUSE,                  4,  4 ;  2
@@ -217,7 +217,7 @@
 	mapgroup ROUTE_43,                                    27, 10 ;  5
 	mapgroup LAKE_OF_RAGE,                                18, 20 ;  6
 
-	newgroup                                                    ; 10
+	newgroup                                                     ; 10
 
 	mapgroup ROUTE_32,                                    45, 10 ;  1
 	mapgroup ROUTE_35,                                    18, 10 ;  2
@@ -237,7 +237,7 @@
 	mapgroup ROUTE_36_RUINS_OF_ALPH_GATE,                  4,  5 ; 16
 	mapgroup ROUTE_36_NATIONAL_PARK_GATE,                  4,  5 ; 17
 
-	newgroup                                                    ; 11
+	newgroup                                                     ; 11
 
 	mapgroup ROUTE_34,                                    27, 10 ;  1
 	mapgroup GOLDENROD_CITY,                              18, 20 ;  2
@@ -264,7 +264,7 @@
 	mapgroup ROUTE_34_ILEX_FOREST_GATE,                    4,  5 ; 23
 	mapgroup DAY_CARE,                                     4,  5 ; 24
 
-	newgroup                                                    ; 12
+	newgroup                                                     ; 12
 
 	mapgroup ROUTE_6,                                      9, 10 ;  1
 	mapgroup ROUTE_11,                                     9, 20 ;  2
@@ -280,7 +280,7 @@
 	mapgroup ROUTE_6_SAFFRON_GATE,                         4,  5 ; 12
 	mapgroup ROUTE_6_UNDERGROUND_PATH_ENTRANCE,            4,  4 ; 13
 
-	newgroup                                                    ; 13
+	newgroup                                                     ; 13
 
 	mapgroup ROUTE_1,                                     18, 10 ;  1
 	mapgroup PALLET_TOWN,                                  9, 10 ;  2
@@ -289,7 +289,7 @@
 	mapgroup BLUES_HOUSE,                                  4,  4 ;  5
 	mapgroup OAKS_LAB,                                     6,  5 ;  6
 
-	newgroup                                                    ; 14
+	newgroup                                                     ; 14
 
 	mapgroup ROUTE_3,                                      9, 30 ;  1
 	mapgroup PEWTER_CITY,                                 18, 20 ;  2
@@ -300,7 +300,7 @@
 	mapgroup PEWTER_POKECENTER_2F_BETA,                    4,  8 ;  7
 	mapgroup PEWTER_SNOOZE_SPEECH_HOUSE,                   4,  4 ;  8
 
-	newgroup                                                    ; 15
+	newgroup                                                     ; 15
 
 	mapgroup OLIVINE_PORT,                                18, 10 ;  1
 	mapgroup VERMILION_PORT,                              18, 10 ;  2
@@ -315,7 +315,7 @@
 	mapgroup MOUNT_MOON_GIFT_SHOP,                         4,  4 ; 11
 	mapgroup TIN_TOWER_ROOF,                               9, 10 ; 12
 
-	newgroup                                                    ; 16
+	newgroup                                                     ; 16
 
 	mapgroup ROUTE_23,                                     9, 10 ;  1
 	mapgroup INDIGO_PLATEAU_POKECENTER_1F,                 7,  9 ;  2
@@ -326,7 +326,7 @@
 	mapgroup LANCES_ROOM,                                 12,  5 ;  7
 	mapgroup HALL_OF_FAME,                                 7,  5 ;  8
 
-	newgroup                                                    ; 17
+	newgroup                                                     ; 17
 
 	mapgroup ROUTE_13,                                     9, 30 ;  1
 	mapgroup ROUTE_14,                                    18, 10 ;  2
@@ -342,7 +342,7 @@
 	mapgroup SAFARI_ZONE_WARDENS_HOME,                     4,  5 ; 12
 	mapgroup ROUTE_15_FUCHSIA_GATE,                        4,  5 ; 13
 
-	newgroup                                                    ; 18
+	newgroup                                                     ; 18
 
 	mapgroup ROUTE_8,                                      9, 20 ;  1
 	mapgroup ROUTE_12,                                    27, 10 ;  2
@@ -359,7 +359,7 @@
 	mapgroup ROUTE_8_SAFFRON_GATE,                         4,  5 ; 13
 	mapgroup ROUTE_12_SUPER_ROD_HOUSE,                     4,  4 ; 14
 
-	newgroup                                                    ; 19
+	newgroup                                                     ; 19
 
 	mapgroup ROUTE_28,                                     9, 20 ;  1
 	mapgroup SILVER_CAVE_OUTSIDE,                         18, 20 ;  2
@@ -366,7 +366,7 @@
 	mapgroup SILVER_CAVE_POKECENTER_1F,                    4,  5 ;  3
 	mapgroup ROUTE_28_FAMOUS_SPEECH_HOUSE,                 4,  4 ;  4
 
-	newgroup                                                    ; 20
+	newgroup                                                     ; 20
 
 	mapgroup POKECENTER_2F,                                4,  8 ;  1
 	mapgroup TRADE_CENTER,                                 4,  5 ;  2
@@ -375,7 +375,7 @@
 	mapgroup MOBILE_TRADE_ROOM_MOBILE,                     4,  5 ;  5
 	mapgroup MOBILE_BATTLE_ROOM,                           4,  5 ;  6
 
-	newgroup                                                    ; 21
+	newgroup                                                     ; 21
 
 	mapgroup ROUTE_7,                                      9, 10 ;  1
 	mapgroup ROUTE_16,                                     9, 10 ;  2
@@ -404,7 +404,7 @@
 	mapgroup ROUTE_7_SAFFRON_GATE,                         4,  5 ; 25
 	mapgroup ROUTE_17_18_GATE,                             4,  5 ; 26
 
-	newgroup                                                    ; 22
+	newgroup                                                     ; 22
 
 	mapgroup ROUTE_40,                                    18, 10 ;  1
 	mapgroup ROUTE_41,                                    27, 25 ;  2
@@ -423,7 +423,7 @@
 	mapgroup ROUTE_40_BATTLE_TOWER_GATE,                   4,  5 ; 15
 	mapgroup BATTLE_TOWER_OUTSIDE,                        14, 10 ; 16
 
-	newgroup                                                    ; 23
+	newgroup                                                     ; 23
 
 	mapgroup ROUTE_2,                                     27, 10 ;  1
 	mapgroup ROUTE_22,                                     9, 20 ;  2
@@ -439,7 +439,7 @@
 	mapgroup ROUTE_2_GATE,                                 4,  5 ; 12
 	mapgroup VICTORY_ROAD_GATE,                            9, 10 ; 13
 
-	newgroup                                                    ; 24
+	newgroup                                                     ; 24
 
 	mapgroup ROUTE_26,                                    54, 10 ;  1
 	mapgroup ROUTE_27,                                     9, 40 ;  2
@@ -455,7 +455,7 @@
 	mapgroup ROUTE_27_SANDSTORM_HOUSE,                     4,  4 ; 12
 	mapgroup ROUTE_29_46_GATE,                             4,  5 ; 13
 
-	newgroup                                                    ; 25
+	newgroup                                                     ; 25
 
 	mapgroup ROUTE_5,                                      9, 10 ;  1
 	mapgroup SAFFRON_CITY,                                18, 20 ;  2
@@ -473,7 +473,7 @@
 	mapgroup ROUTE_5_SAFFRON_CITY_GATE,                    4,  5 ; 14
 	mapgroup ROUTE_5_CLEANSE_TAG_SPEECH_HOUSE,             4,  4 ; 15
 
-	newgroup                                                    ; 26
+	newgroup                                                     ; 26
 
 	mapgroup ROUTE_30,                                    27, 10 ;  1
 	mapgroup ROUTE_31,                                     9, 20 ;  2
--- a/docs/map_scripts.md
+++ b/docs/map_scripts.md
@@ -65,7 +65,7 @@
 
 ## `.CoordEvents: db` *N*
 
-- **`coord_event` *x*, *y*, *scene id*, *script***
+- **`coord_event` *x*, *y*, *scene_id*, *script***
 
 
 ## `.BGEvents: db` *N*
@@ -90,7 +90,7 @@
 
 ## `.ObjectEvents: db` *N*
 
-- **`object_event` *x*, *y*, *sprite*, *movement*, *ry*, *rx*, *h1*, *h2*, *palette*, *type*, *range*, *script*, *event_flag***
+- **`object_event` *x*, *y*, *sprite*, *movement*, *rx*, *ry*, *h1*, *h2*, *palette*, *type*, *range*, *script*, *event_flag***
 
 Movement types:
 
--- a/engine/battle/anim_hp_bar.asm
+++ b/engine/battle/anim_hp_bar.asm
@@ -45,7 +45,7 @@
 	and a
 	jr nz, .player
 	ld a, [wCurHPAnimMaxHP]
-	cp 6 * 8
+	cp HP_BAR_LENGTH_PX
 	jr nc, .player
 	and a
 	ret
@@ -203,7 +203,7 @@
 
 ShortHPBarAnim_UpdateTiles: ; d730
 	call HPBarAnim_UpdateHPRemaining
-	ld d, $6
+	ld d, HP_BAR_LENGTH
 	ld a, [wWhichHPBar]
 	and $1
 	ld b, a
@@ -229,7 +229,7 @@
 	ld d, a
 	call ComputeHPBarPixels
 	ld c, e
-	ld d, $6
+	ld d, HP_BAR_LENGTH
 	ld a, [wWhichHPBar]
 	and $1
 	ld b, a
@@ -377,7 +377,7 @@
 	ld b, 0
 	ld hl, 0
 	ld a, [wCurHPBarPixels]
-	cp 6 * 8
+	cp HP_BAR_LENGTH_PX
 	jr nc, .return_max
 	and a
 	jr z, .return_zero
@@ -388,7 +388,7 @@
 ; by 48, the loop runs one extra time. To fix, uncomment the line below.
 .loop
 	ld a, l
-	sub 6 * 8
+	sub HP_BAR_LENGTH_PX
 	ld l, a
 	ld a, h
 	sbc $0
@@ -404,7 +404,7 @@
 	add hl, bc
 	pop bc
 	ld a, l
-	sub 6 * 8
+	sub HP_BAR_LENGTH_PX
 	ld l, a
 	ld a, h
 	sbc $0
--- a/engine/color.asm
+++ b/engine/color.asm
@@ -908,7 +908,7 @@
 	call ByteFill
 	ld a, $0
 	ld [rVBK], a
-	ld a, $80
+	ld a, 1 << rBGPI_AUTO_INCREMENT
 	ld [rBGPI], a
 	ld c, 4 * 8
 .bgpals_loop
@@ -918,7 +918,7 @@
 	ld [rBGPD], a
 	dec c
 	jr nz, .bgpals_loop
-	ld a, $80
+	ld a, 1 << rOBPI_AUTO_INCREMENT
 	ld [rOBPI], a
 	ld c, 4 * 8
 .obpals_loop
--- a/engine/debug.asm
+++ b/engine/debug.asm
@@ -161,19 +161,19 @@
 	ld de, BGPals
 	ld bc, 16 palettes
 	call CopyBytes
-	ld a, $80
+	ld a, 1 << rBGPI_AUTO_INCREMENT
 	ld [rBGPI], a
 	ld hl, Palette_819f4
-	ld c, $40
+	ld c, 8 palettes
 	xor a
 .asm_819c8
 	ld [rBGPD], a
 	dec c
 	jr nz, .asm_819c8
-	ld a, $80
+	ld a, 1 << rOBPI_AUTO_INCREMENT
 	ld [rOBPI], a
 	ld hl, Palette_81a34
-	ld c, $40
+	ld c, 8 palettes
 .asm_819d6
 	ld a, [hli]
 	ld [rOBPD], a
--- a/home/palettes.asm
+++ b/home/palettes.asm
@@ -30,7 +30,7 @@
 	ld hl, BGPals
 
 ; copy 8 pals to bgpd
-	ld a, %10000000 ; auto increment, index 0
+	ld a, 1 << rBGPI_AUTO_INCREMENT
 	ld [rBGPI], a
 	ld c, LOW(rBGPD)
 	ld b, 8 / 2
@@ -46,7 +46,7 @@
 ; hl is now OBPals
 
 ; copy 8 pals to obpd
-	ld a, %10000000 ; auto increment, index 0
+	ld a, 1 << rOBPI_AUTO_INCREMENT
 	ld [rOBPI], a
 	ld c, LOW(rOBPD)
 	ld b, 8 / 2
--- a/tilesets/animations.asm
+++ b/tilesets/animations.asm
@@ -935,26 +935,24 @@
 	ret nz
 
 ; Ready for BGPD input...
-	ld a, %10011000 ; auto increment, index $18 (pal 3 color 0)
+
+	ld a, (1 << rBGPI_AUTO_INCREMENT) palette PAL_BG_WATER
 	ld [rBGPI], a
 
 	ld a, [rSVBK]
 	push af
-	ld a, 5 ; wra5: gfx
+	ld a, BANK(UnknBGPals)
 	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 4
 	jr z, .color2
 
 .color1
-	ld hl, UnknBGPals + $1a ; pal 3 color 1
+	ld hl, UnknBGPals palette PAL_BG_WATER + 2
 	ld a, [hli]
 	ld [rBGPD], a
 	ld a, [hli]
@@ -962,7 +960,7 @@
 	jr .end
 
 .color0
-	ld hl, UnknBGPals + $18 ; pal 3 color 0
+	ld hl, UnknBGPals palette PAL_BG_WATER
 	ld a, [hli]
 	ld [rBGPD], a
 	ld a, [hli]
@@ -970,7 +968,7 @@
 	jr .end
 
 .color2
-	ld hl, UnknBGPals + $1c ; pal 3 color 2
+	ld hl, UnknBGPals palette PAL_BG_WATER + 4
 	ld a, [hli]
 	ld [rBGPD], a
 	ld a, [hli]
@@ -999,19 +997,19 @@
 
 	ld a, [rSVBK]
 	push af
-	ld a, 5 ; wra5: gfx
+	ld a, BANK(UnknBGPals)
 	ld [rSVBK], a
 ; Ready for BGPD input...
-	ld a, %10100000 ; auto-increment, index $20 (pal 4 color 0)
+	ld a, (1 << rBGPI_AUTO_INCREMENT) palette PAL_BG_YELLOW
 	ld [rBGPI], a
 	ld a, [hVBlankCounter]
-	and %00000010
+	and 1 << 1
 	jr nz, .bit1set
-	ld hl, UnknBGPals + $20 ; pal 4 color 0
+	ld hl, UnknBGPals palette PAL_BG_YELLOW
 	jr .okay
 
 .bit1set
-	ld hl, UnknBGPals + $22 ; pal 4 color 2
+	ld hl, UnknBGPals palette PAL_BG_YELLOW + 2
 
 .okay
 	ld a, [hli]