summaryrefslogtreecommitdiff
path: root/Hard-coded-logic.md
diff options
context:
space:
mode:
Diffstat (limited to 'Hard-coded-logic.md')
-rw-r--r--Hard-coded-logic.md114
1 files changed, 114 insertions, 0 deletions
diff --git a/Hard-coded-logic.md b/Hard-coded-logic.md
index 9806570..22e3f4c 100644
--- a/Hard-coded-logic.md
+++ b/Hard-coded-logic.md
@@ -7,6 +7,7 @@ Much of the game logic can be changed via the files in [data/](../blob/master/da
- [Maps that don't display a location sign](#maps-that-dont-display-a-location-sign)
- [Outdoor maps within indoor maps don't confuse Dig or Escape Rope](#outdoor-maps-within-indoor-maps-dont-confuse-dig-or-escape-rope)
- [Landmark limits when scrolling in the Town Map](#landmark-limits-when-scrolling-in-the-town-map)
+- [Some high values for maps' music IDs play incorrectly](#some-high-values-for-maps-music-ids-play-incorrectly)
- [Trainer classes with different battle music](#trainer-classes-with-different-battle-music)
- [`RIVAL1`'s first Pokémon has no held item](#rival1s-first-pokémon-has-no-held-item)
- [`RIVAL1` and `RIVAL2` don't print their trainer class in battle](#rival1-and-rival2-dont-print-their-trainer-class-in-battle)
@@ -130,6 +131,119 @@ This is caused by `InitEnemyTrainer` in [engine/battle/core.asm](../blob/master/
```
+## Some high values for maps' music IDs play incorrectly
+
+If a map's music ID is $64 (the value of `MUSIC_MAHOGANY_MART` or `MUSIC_SUICUNE_BATTLE`) in [data/maps/maps.asm](../blob/master/data/maps/maps.asm) it will play either `MUSIC_ROCKET_HIDEOUT` or `MUSIC_CHERRYGROVE_CITY`. Moreover, if a map's music ID is $80 or above (the value of `RADIO_TOWER_MUSIC`) it might play `MUSIC_ROCKET_OVERTURE` or something else.
+
+This is caused by `GetMapMusic` in [home/map.asm](../blob/master/home/map.asm):
+
+```asm
+GetMapMusic:: ; 2cbd
+ push hl
+ push bc
+ ld de, MAP_MUSIC
+ call GetMapField
+ ld a, c
+ cp MUSIC_MAHOGANY_MART
+ jr z, .mahoganymart
+ bit RADIO_TOWER_MUSIC_F, c
+ jr nz, .radiotower
+ farcall Function8b342
+ ld e, c
+ ld d, 0
+.done
+ pop bc
+ pop hl
+ ret
+
+.radiotower
+ ld a, [wStatusFlags2]
+ bit STATUSFLAGS2_ROCKETS_IN_RADIO_TOWER_F, a
+ jr z, .clearedradiotower
+ ld de, MUSIC_ROCKET_OVERTURE
+ jr .done
+
+.clearedradiotower
+ ; the rest of the byte
+ ld a, c
+ and RADIO_TOWER_MUSIC - 1
+ ld e, a
+ ld d, 0
+ jr .done
+
+.mahoganymart
+ ld a, [wStatusFlags2]
+ bit STATUSFLAGS2_ROCKETS_IN_MAHOGANY_F, a
+ jr z, .clearedmahogany
+ ld de, MUSIC_ROCKET_HIDEOUT
+ jr .done
+
+.clearedmahogany
+ ld de, MUSIC_CHERRYGROVE_CITY
+ jr .done
+; 2cff
+```
+
+This can cause problems if you add too many new music songs, or rearrange the existing ones. A solution would be to redefine the special music constants in [constants/music_constants.asm](../blob/master/constants/music_constants.asm):
+
+```asm
+; GetMapMusic picks music for these values (see home/map.asm)
+MUSIC_MAHOGANY_MART EQU $fc
+MUSIC_RADIO_TOWER EQU $fd
+
+; ExitPokegearRadio_HandleMusic uses these values
+RESTART_MAP_MUSIC EQU $fe
+ENTER_MAP_MUSIC EQU $ff
+```
+
+And then edit `GetMapMusic`:
+
+```asm
+GetMapMusic:: ; 2cbd
+ push hl
+ push bc
+ ld de, MAP_MUSIC
+ call GetMapField
+ ld a, c
+ cp MUSIC_MAHOGANY_MART
+ jr z, .mahoganymart
+ cp MUSIC_RADIO_TOWER
+ jr z, .radiotower
+ farcall Function8b342
+ ld e, c
+ ld d, 0
+.done
+ pop bc
+ pop hl
+ ret
+
+.radiotower
+ ld a, [wStatusFlags2]
+ bit STATUSFLAGS2_ROCKETS_IN_RADIO_TOWER_F, a
+ jr z, .clearedradiotower
+ ld de, MUSIC_ROCKET_OVERTURE
+ jr .done
+
+.clearedradiotower
+ ld de, MUSIC_GOLDENROD_CITY
+ jr .done
+
+.mahoganymart
+ ld a, [wStatusFlags2]
+ bit STATUSFLAGS2_ROCKETS_IN_MAHOGANY_F, a
+ jr z, .clearedmahogany
+ ld de, MUSIC_ROCKET_HIDEOUT
+ jr .done
+
+.clearedmahogany
+ ld de, MUSIC_CHERRYGROVE_CITY
+ jr .done
+; 2cff
+```
+
+You'll also need to edit [data/maps/maps.asm](../blob/master/data/maps/maps.asm) so the Radio Tower maps use `MUSIC_RADIO_TOWER` instead of `RADIO_TOWER_MUSIC | MUSIC_GOLDENROD_CITY`.
+
+
## Trainer classes with different battle music
This is caused by `PlayBattleMusic` in [engine/battle/start_battle.asm](../blob/master/engine/battle/start_battle.asm). The routine's logic is: