diff options
Diffstat (limited to 'home')
-rw-r--r-- | home/audio.asm | 598 | ||||
-rw-r--r-- | home/battle.asm | 337 | ||||
-rw-r--r-- | home/init.asm | 2 | ||||
-rw-r--r-- | home/map.asm | 55 |
4 files changed, 965 insertions, 27 deletions
diff --git a/home/audio.asm b/home/audio.asm new file mode 100644 index 000000000..348da52c6 --- /dev/null +++ b/home/audio.asm @@ -0,0 +1,598 @@ +; Audio interfaces. + +SoundRestart:: ; 3b4e + + push hl + push de + push bc + push af + + ld a, [hROMBank] + push af + ld a, BANK(_SoundRestart) + ld [hROMBank], a + ld [MBC3RomBank], a + + call _SoundRestart + + pop af + ld [hROMBank], a + ld [MBC3RomBank], a + + pop af + pop bc + pop de + pop hl + ret +; 3b6a + + +UpdateSound:: ; 3b6a + + push hl + push de + push bc + push af + + ld a, [hROMBank] + push af + ld a, BANK(_UpdateSound) + ld [hROMBank], a + ld [MBC3RomBank], a + + call _UpdateSound + + pop af + ld [hROMBank], a + ld [MBC3RomBank], a + + pop af + pop bc + pop de + pop hl + ret +; 3b86 + + +_LoadMusicByte:: ; 3b86 +; CurMusicByte = [a:de] +GLOBAL LoadMusicByte + + ld [hROMBank], a + ld [MBC3RomBank], a + + ld a, [de] + ld [CurMusicByte], a + ld a, BANK(LoadMusicByte) + + ld [hROMBank], a + ld [MBC3RomBank], a + ret +; 3b97 + + +PlayMusic:: ; 3b97 +; Play music de. + + push hl + push de + push bc + push af + + ld a, [hROMBank] + push af + ld a, BANK(_PlayMusic) ; and BANK(_SoundRestart) + ld [hROMBank], a + ld [MBC3RomBank], a + + ld a, e + and a + jr z, .nomusic + + call _PlayMusic + jr .end + +.nomusic + call _SoundRestart + +.end + pop af + ld [hROMBank], a + ld [MBC3RomBank], a + pop af + pop bc + pop de + pop hl + ret +; 3bbc + + +PlayMusic2:: ; 3bbc +; Stop playing music, then play music de. + + push hl + push de + push bc + push af + + ld a, [hROMBank] + push af + ld a, BANK(_PlayMusic) + ld [hROMBank], a + ld [MBC3RomBank], a + + push de + ld de, MUSIC_NONE + call _PlayMusic + call DelayFrame + pop de + call _PlayMusic + + pop af + ld [hROMBank], a + ld [MBC3RomBank], a + + pop af + pop bc + pop de + pop hl + ret + +; 3be3 + + +PlayCryHeader:: ; 3be3 +; Play a cry given parameters at header de + + push hl + push de + push bc + push af + + ld a, [hROMBank] + push af + + ; Cry headers are stuck in one bank. + ld a, BANK(CryHeaders) + ld [hROMBank], a + ld [MBC3RomBank], a + + ld hl, CryHeaders + add hl, de + add hl, de + add hl, de + add hl, de + add hl, de + add hl, de + + ld e, [hl] + inc hl + ld d, [hl] + inc hl + + ld a, [hli] + ld [CryPitch], a + ld a, [hli] + ld [CryEcho], a + ld a, [hli] + ld [CryLength], a + ld a, [hl] + ld [CryLength + 1], a + + ld a, BANK(PlayCry) + ld [hROMBank], a + ld [MBC3RomBank], a + + call PlayCry + + pop af + ld [hROMBank], a + ld [MBC3RomBank], a + + pop af + pop bc + pop de + pop hl + ret +; 3c23 + + +PlaySFX:: ; 3c23 +; Play sound effect de. +; Sound effects are ordered by priority (lowest to highest) + + push hl + push de + push bc + push af + + ; Is something already playing? + call CheckSFX + jr nc, .play + + ; Does it have priority? + ld a, [CurSFX] + cp e + jr c, .done + +.play + ld a, [hROMBank] + push af + ld a, BANK(_PlaySFX) + ld [hROMBank], a + ld [MBC3RomBank], a + + ld a, e + ld [CurSFX], a + call _PlaySFX + + pop af + ld [hROMBank], a + ld [MBC3RomBank], a + +.done + pop af + pop bc + pop de + pop hl + ret +; 3c4e + + +WaitPlaySFX:: ; 3c4e + call WaitSFX + call PlaySFX + ret +; 3c55 + + +WaitSFX:: ; 3c55 +; infinite loop until sfx is done playing + + push hl + +.wait + ld hl, Channel5Flags + bit 0, [hl] + jr nz, .wait + ld hl, Channel6Flags + bit 0, [hl] + jr nz, .wait + ld hl, Channel7Flags + bit 0, [hl] + jr nz, .wait + ld hl, Channel8Flags + bit 0, [hl] + jr nz, .wait + + pop hl + ret +; 3c74 + +IsSFXPlaying:: ; 3c74 +; Return carry if no sound effect is playing. +; The inverse of CheckSFX. + push hl + + ld hl, Channel5Flags + bit 0, [hl] + jr nz, .playing + ld hl, Channel6Flags + bit 0, [hl] + jr nz, .playing + ld hl, Channel7Flags + bit 0, [hl] + jr nz, .playing + ld hl, Channel8Flags + bit 0, [hl] + jr nz, .playing + + pop hl + scf + ret + +.playing + pop hl + and a + ret +; 3c97 + +MaxVolume:: ; 3c97 + ld a, $77 ; max + ld [Volume], a + ret +; 3c9d + +LowVolume:: ; 3c9d + ld a, $33 ; 40% + ld [Volume], a + ret +; 3ca3 + +VolumeOff:: ; 3ca3 + xor a + ld [Volume], a + ret +; 3ca8 + +Function3ca8:: ; 3ca8 + ld a, 4 + ld [MusicFade], a + ret +; 3cae + +Function3cae:: ; 3cae + ld a, 4 | 1 << 7 + ld [MusicFade], a + ret +; 3cb4 + +SkipMusic:: ; 3cb4 +; Skip a frames of music. + and a + ret z + dec a + call UpdateSound + jr SkipMusic +; 3cbc + +FadeToMapMusic:: ; 3cbc + push hl + push de + push bc + push af + + call GetMapMusic + ld a, [wMapMusic] + cp e + jr z, .done + + ld a, 8 + ld [MusicFade], a + ld a, e + ld [MusicFadeIDLo], a + ld a, d + ld [MusicFadeIDHi], a + ld a, e + ld [wMapMusic], a + +.done + pop af + pop bc + pop de + pop hl + ret +; 3cdf + +PlayMapMusic:: ; 3cdf + push hl + push de + push bc + push af + + call GetMapMusic + ld a, [wMapMusic] + cp e + jr z, .done + + push de + ld de, MUSIC_NONE + call PlayMusic + call DelayFrame + pop de + ld a, e + ld [wMapMusic], a + call PlayMusic + +.done + pop af + pop bc + pop de + pop hl + ret +; 3d03 + +EnterMapMusic:: ; 3d03 + push hl + push de + push bc + push af + + xor a + ld [$c2c1], a + ld de, MUSIC_BICYCLE + ld a, [PlayerState] + cp PLAYER_BIKE + jr z, .play + call GetMapMusic +.play + push de + ld de, MUSIC_NONE + call PlayMusic + call DelayFrame + pop de + + ld a, e + ld [wMapMusic], a + call PlayMusic + + pop af + pop bc + pop de + pop hl + ret +; 3d2f + +Function3d2f:: ; 3d2f + ld a, [$c2c1] + and a + jr z, RestartMapMusic + xor a + ld [wMapMusic], a + ld de, MUSIC_NONE + call PlayMusic + call DelayFrame + xor a + ld [$c2c1], a + ret +; 3d47 + +RestartMapMusic:: ; 3d47 + push hl + push de + push bc + push af + ld de, MUSIC_NONE + call PlayMusic + call DelayFrame + ld a, [wMapMusic] + ld e, a + ld d, 0 + call PlayMusic + pop af + pop bc + pop de + pop hl + ret +; 3d62 + +SpecialMapMusic:: ; 3d62 + ld a, [PlayerState] + cp PLAYER_SURF + jr z, .surf + cp PLAYER_SURF_PIKA + jr z, .surf + + ld a, [StatusFlags2] + bit 2, a + jr nz, .contest + +.no + and a + ret + +.bike + ld de, MUSIC_BICYCLE + scf + ret + +.surf + ld de, MUSIC_SURF + scf + ret + +.contest + ld a, [MapGroup] + cp GROUP_ROUTE_35_NATIONAL_PARK_GATE + jr nz, .no + ld a, [MapNumber] + cp MAP_ROUTE_35_NATIONAL_PARK_GATE + jr z, .ranking + cp MAP_ROUTE_36_NATIONAL_PARK_GATE + jr nz, .no + +.ranking + ld de, MUSIC_BUG_CATCHING_CONTEST_RANKING + scf + ret +; 3d97 + +GetMapMusic:: ; 3d97 + call SpecialMapMusic + ret c + call GetMapHeaderMusic + ret +; 3d9f + +Function3d9f:: ; 3d9f +; Places a BCD number at the +; upper center of the screen. +; Unreferenced. + ld a, $20 + ld [$c498], a + ld [$c49c], a + ld a, $50 + ld [$c499], a + ld a, $58 + ld [$c49d], a + xor a + ld [$c49b], a + ld [$c49f], a + ld a, [$c296] + cp $64 + jr nc, .max + add 1 + daa + ld b, a + swap a + and $f + add "0" + ld [$c49a], a + ld a, b + and $f + add "0" + ld [$c49e], a + ret + +.max + ld a, "9" + ld [$c49a], a + ld [$c49e], a + ret +; 3dde + +CheckSFX:: ; 3dde +; Return carry if any SFX channels are active. + ld a, [Channel5Flags] + bit 0, a + jr nz, .playing + ld a, [Channel6Flags] + bit 0, a + jr nz, .playing + ld a, [Channel7Flags] + bit 0, a + jr nz, .playing + ld a, [Channel8Flags] + bit 0, a + jr nz, .playing + and a + ret +.playing + scf + ret +; 3dfe + +Function3dfe:: ; 3dfe + xor a + ld [$c1cc], a + ld [SoundInput], a + ld [rNR10], a + ld [rNR11], a + ld [rNR12], a + ld [rNR13], a + ld [rNR14], a + ret +; 3e10 + + +ChannelsOff:: ; 3e10 +; Quickly turn off music channels + xor a + ld [Channel1Flags], a + ld [Channel2Flags], a + ld [Channel3Flags], a + ld [Channel4Flags], a + ld [SoundInput], a + ret +; 3e21 + +SFXChannelsOff:: ; 3e21 +; Quickly turn off sound effect channels + xor a + ld [Channel5Flags], a + ld [Channel6Flags], a + ld [Channel7Flags], a + ld [Channel8Flags], a + ld [SoundInput], a + ret +; 3e32 diff --git a/home/battle.asm b/home/battle.asm new file mode 100644 index 000000000..fc670d927 --- /dev/null +++ b/home/battle.asm @@ -0,0 +1,337 @@ +UserPartyAttr:: ; 3945 + push af + ld a, [hBattleTurn] + and a + jr nz, .ot + pop af + jr BattlePartyAttr +.ot + pop af + jr OTPartyAttr +; 3951 + + +OpponentPartyAttr:: ; 3951 + push af + ld a, [hBattleTurn] + and a + jr z, .ot + pop af + jr BattlePartyAttr +.ot + pop af + jr OTPartyAttr +; 395d + + +BattlePartyAttr:: ; 395d +; Get attribute a from the active BattleMon's party struct. + push bc + ld c, a + ld b, 0 + ld hl, PartyMons + add hl, bc + ld a, [CurBattleMon] + call GetPartyLocation + pop bc + ret +; 396d + + +OTPartyAttr:: ; 396d +; Get attribute a from the active EnemyMon's party struct. + push bc + ld c, a + ld b, 0 + ld hl, OTPartyMon1Species + add hl, bc + ld a, [CurOTMon] + call GetPartyLocation + pop bc + ret +; 397d + + +ResetDamage:: ; 397d + xor a + ld [CurDamage], a + ld [CurDamage + 1], a + ret +; 3985 + +SetPlayerTurn:: ; 3985 + xor a + ld [hBattleTurn], a + ret +; 3989 + +SetEnemyTurn:: ; 3989 + ld a, 1 + ld [hBattleTurn], a + ret +; 398e + + +UpdateOpponentInParty:: ; 398e + ld a, [hBattleTurn] + and a + jr z, UpdateEnemyMonInParty + jr UpdateBattleMonInParty +; 3995 + +UpdateUserInParty:: ; 3995 + ld a, [hBattleTurn] + and a + jr z, UpdateBattleMonInParty + jr UpdateEnemyMonInParty +; 399c + +UpdateBattleMonInParty:: ; 399c +; Update level, status, current HP + + ld a, [CurBattleMon] + +Function399f:: ; 399f + ld hl, PartyMon1Level + call GetPartyLocation + + ld d, h + ld e, l + ld hl, BattleMonLevel + ld bc, BattleMonMaxHP - BattleMonLevel + jp CopyBytes +; 39b0 + +UpdateEnemyMonInParty:: ; 39b0 +; Update level, status, current HP + +; No wildmons. + ld a, [IsInBattle] + dec a + ret z + + ld a, [CurOTMon] + ld hl, OTPartyMon1Level + call GetPartyLocation + + ld d, h + ld e, l + ld hl, EnemyMonLevel + ld bc, EnemyMonMaxHP - EnemyMonLevel + jp CopyBytes +; 39c9 + + +RefreshBattleHuds:: ; 39c9 + call UpdateBattleHuds + ld c, 3 + call DelayFrames + jp WaitBGMap +; 39d4 + +UpdateBattleHuds:: ; 39d4 + callba Function3df48 + callba Function3e036 + ret +; 39e1 + + +GetBattleVar:: ; 39e1 +; Preserves hl. + push hl + call _GetBattleVar + pop hl + ret +; 39e7 + +_GetBattleVar:: ; 39e7 +; Get variable from pair a, depending on whose turn it is. +; There are 21 variable pairs. + + push bc + + ld hl, .battlevarpairs + ld c, a + ld b, 0 + add hl, bc + add hl, bc + + ld a, [hli] + ld h, [hl] + ld l, a + +; Enemy turn uses the second byte instead. +; This lets battle variable calls be side-neutral. + ld a, [hBattleTurn] + and a + jr z, .getvar + inc hl + +.getvar +; var id + ld a, [hl] + ld c, a + ld b, 0 + + ld hl, .vars + add hl, bc + add hl, bc + + ld a, [hli] + ld h, [hl] + ld l, a + + ld a, [hl] + + pop bc + ret + +.battlevarpairs + dw .substatus1, .substatus2, .substatus3, .substatus4, .substatus5 + dw .substatus1opp, .substatus2opp, .substatus3opp, .substatus4opp, .substatus5opp + dw .status, .statusopp, .animation, .effect, .power, .type + dw .curmove, .lastcounter, .lastcounteropp, .lastmove, .lastmoveopp + + const_def + const PLAYER_SUBSTATUS_1 + const ENEMY_SUBSTATUS_1 + const PLAYER_SUBSTATUS_2 + const ENEMY_SUBSTATUS_2 + const PLAYER_SUBSTATUS_3 + const ENEMY_SUBSTATUS_3 + const PLAYER_SUBSTATUS_4 + const ENEMY_SUBSTATUS_4 + const PLAYER_SUBSTATUS_5 + const ENEMY_SUBSTATUS_5 + const PLAYER_STATUS + const ENEMY_STATUS + const PLAYER_MOVE_ANIMATION + const ENEMY_MOVE_ANIMATION + const PLAYER_MOVE_EFFECT + const ENEMY_MOVE_EFFECT + const PLAYER_MOVE_POWER + const ENEMY_MOVE_POWER + const PLAYER_MOVE_TYPE + const ENEMY_MOVE_TYPE + const PLAYER_CUR_MOVE + const ENEMY_CUR_MOVE + const PLAYER_COUNTER_MOVE + const ENEMY_COUNTER_MOVE + const PLAYER_LAST_MOVE + const ENEMY_LAST_MOVE + +; player enemy +.substatus1 db PLAYER_SUBSTATUS_1, ENEMY_SUBSTATUS_1 +.substatus1opp db ENEMY_SUBSTATUS_1, PLAYER_SUBSTATUS_1 +.substatus2 db PLAYER_SUBSTATUS_2, ENEMY_SUBSTATUS_2 +.substatus2opp db ENEMY_SUBSTATUS_2, PLAYER_SUBSTATUS_2 +.substatus3 db PLAYER_SUBSTATUS_3, ENEMY_SUBSTATUS_3 +.substatus3opp db ENEMY_SUBSTATUS_3, PLAYER_SUBSTATUS_3 +.substatus4 db PLAYER_SUBSTATUS_4, ENEMY_SUBSTATUS_4 +.substatus4opp db ENEMY_SUBSTATUS_4, PLAYER_SUBSTATUS_4 +.substatus5 db PLAYER_SUBSTATUS_5, ENEMY_SUBSTATUS_5 +.substatus5opp db ENEMY_SUBSTATUS_5, PLAYER_SUBSTATUS_5 +.status db PLAYER_STATUS, ENEMY_STATUS +.statusopp db ENEMY_STATUS, PLAYER_STATUS +.animation db PLAYER_MOVE_ANIMATION, ENEMY_MOVE_ANIMATION +.effect db PLAYER_MOVE_EFFECT, ENEMY_MOVE_EFFECT +.power db PLAYER_MOVE_POWER, ENEMY_MOVE_POWER +.type db PLAYER_MOVE_TYPE, ENEMY_MOVE_TYPE +.curmove db PLAYER_CUR_MOVE, ENEMY_CUR_MOVE +.lastcounter db PLAYER_COUNTER_MOVE, ENEMY_COUNTER_MOVE +.lastcounteropp db ENEMY_COUNTER_MOVE, PLAYER_COUNTER_MOVE +.lastmove db PLAYER_LAST_MOVE, ENEMY_LAST_MOVE +.lastmoveopp db ENEMY_LAST_MOVE, PLAYER_LAST_MOVE + +.vars + dw PlayerSubStatus1, EnemySubStatus1 + dw PlayerSubStatus2, EnemySubStatus2 + dw PlayerSubStatus3, EnemySubStatus3 + dw PlayerSubStatus4, EnemySubStatus4 + dw PlayerSubStatus5, EnemySubStatus5 + dw BattleMonStatus, EnemyMonStatus + dw PlayerMoveAnimation, EnemyMoveAnimation + dw PlayerMoveEffect, EnemyMoveEffect + dw PlayerMovePower, EnemyMovePower + dw PlayerMoveType, EnemyMoveType + dw CurPlayerMove, CurEnemyMove + dw LastEnemyCounterMove, LastPlayerCounterMove + dw LastPlayerMove, LastEnemyMove +; 3a90 + + +Function3a90:: ; 3a90 + inc hl + ld a, [hROMBank] + push af + ld a, [hli] + ld e, a + ld a, [hli] + ld d, a + ld a, [hli] + ld [hROMBank], a + ld [MBC3RomBank], a + ld a, e + ld l, a + ld a, d + ld h, a + ld de, $d00c + ld bc, $0028 + call CopyBytes + pop af + ld [hROMBank], a + ld [MBC3RomBank], a + ret +; 3ab2 + + +MobileTextBorder:: ; 3ab2 + +CELL_PHONE_TOP EQU $5e +CELL_PHONE_BOTTOM EQU $5f + + ; For mobile link battles only. + ld a, [InLinkBattle] + cp 4 + ret c + + ; Draw a cell phone icon at the + ; top right corner of the border. + hlcoord 19, 12 + ld [hl], CELL_PHONE_TOP + hlcoord 19, 13 + ld [hl], CELL_PHONE_BOTTOM + ret +; 3ac3 + + +BattleTextBox:: ; 3ac3 +; Open a textbox and print text at hl. + push hl + call SpeechTextBox + call MobileTextBorder + call Function1ad2 + call Function321c + pop hl + call PrintTextBoxText + ret +; 3ad5 + + +StdBattleTextBox:: ; 3ad5 +; Open a textbox and print battle text at 20:hl. + +GLOBAL BattleText + + ld a, [hROMBank] + push af + + ld a, BANK(BattleText) + rst Bankswitch + + call BattleTextBox + + pop af + rst Bankswitch + ret +; 3ae1 diff --git a/home/init.asm b/home/init.asm index b879b9802..3d83a03cf 100644 --- a/home/init.asm +++ b/home/init.asm @@ -172,7 +172,7 @@ Init:: ; 17d call SoundRestart xor a - ld [CurMusic], a + ld [wMapMusic], a jp GameInit ; 245 diff --git a/home/map.asm b/home/map.asm index d581eb6b4..6c7a79592 100644 --- a/home/map.asm +++ b/home/map.asm @@ -1034,7 +1034,7 @@ Function2653:: ; 2653 ; 2674 Function2674:: ; 2674 - callba Unknown_0x974f3 + callba Function974f3 ld a, [ScriptMode] push af ld hl, ScriptFlags @@ -2021,8 +2021,8 @@ Function2bae:: ; 2bae callba Function8c001 call Function2173 call Function2821 - ld a, $9 - call Function3cb4 + ld a, 9 + call SkipMusic pop af rst Bankswitch @@ -2259,48 +2259,51 @@ GetWorldMapLocation:: ; 0x2caf ret ; 0x2cbd -Function2cbd:: ; 2cbd +GetMapHeaderMusic:: ; 2cbd +RADIO_TOWER_MUSIC EQU 7 + push hl push bc - ld de, $0006 + ld de, 6 ; music call GetMapHeaderMember ld a, c - cp $64 - jr z, .asm_2cee - bit 7, c - jr nz, .asm_2cda + cp MUSIC_MAHOGANY_MART + jr z, .mahoganymart + bit RADIO_TOWER_MUSIC, c + jr nz, .radiotower callba Function8b342 ld e, c - ld d, $0 -.asm_2cd7 + ld d, 0 +.done pop bc pop hl ret -.asm_2cda +.radiotower ld a, [StatusFlags2] bit 0, a - jr z, .asm_2ce6 - ld de, $0056 - jr .asm_2cd7 + jr z, .clearedradiotower + ld de, MUSIC_ROCKET_OVERTURE + jr .done -.asm_2ce6 +.clearedradiotower + ; the rest of the byte ld a, c - and $7f + and 1 << RADIO_TOWER_MUSIC - 1 ld e, a - ld d, $0 - jr .asm_2cd7 + ld d, 0 + jr .done -.asm_2cee +.mahoganymart ld a, [StatusFlags2] bit 7, a - jr z, .asm_2cfa - ld de, $0048 - jr .asm_2cd7 + jr z, .clearedmahogany + ld de, MUSIC_ROCKET_HIDEOUT + jr .done -.asm_2cfa - ld de, $0026 - jr .asm_2cd7 +.clearedmahogany + ld de, MUSIC_CHERRYGROVE_CITY + jr .done ; 2cff Function2cff:: ; 2cff |