diff options
-rw-r--r-- | constants/wram_constants.asm | 30 | ||||
-rwxr-xr-x | engine/main_menu.asm | 6 | ||||
-rwxr-xr-x | engine/overworld/map_objects.asm | 2 | ||||
-rw-r--r-- | home.asm | 4 | ||||
-rw-r--r-- | home/audio.asm | 292 | ||||
-rw-r--r-- | home/map.asm | 4 | ||||
-rwxr-xr-x | macros/wram.asm | 13 | ||||
-rw-r--r-- | main.asm | 2 | ||||
-rw-r--r-- | pokegold.link | 2 | ||||
-rw-r--r-- | pokesilver.link | 2 | ||||
-rw-r--r-- | wram.asm | 50 |
11 files changed, 273 insertions, 134 deletions
diff --git a/constants/wram_constants.asm b/constants/wram_constants.asm index c8eca267..4c3917c8 100644 --- a/constants/wram_constants.asm +++ b/constants/wram_constants.asm @@ -1,3 +1,5 @@ +; InputType: ; c2c7 +AUTO_INPUT EQU $ff ; MonType: ; cf5f PARTYMON EQU 0 @@ -72,11 +74,29 @@ SATURDAY EQU 6 ; MapObjects: ; d71e PLAYER_OBJECT EQU 0 - -NUM_OBJECTS EQU $10 - -; InputType: ; c2c7 -AUTO_INPUT EQU $ff +NUM_OBJECTS EQU 16 + +; wStatusFlags:: + const_def + const STATUSFLAGS_POKEDEX_F ; 0 + const STATUSFLAGS_UNOWN_DEX_F ; 1 + const STATUSFLAGS_FLASH_F ; 2 + const STATUSFLAGS_CAUGHT_POKERUS_F ; 3 + const STATUSFLAGS_ROCKET_SIGNAL_F ; 4 + const STATUSFLAGS_NO_WILD_ENCOUNTERS_F ; 5 + const STATUSFLAGS_HALL_OF_FAME_F ; 6 + const STATUSFLAGS_MAIN_MENU_MOBILE_CHOICES_F ; 7 + +; wStatusFlags2:: + const_def + const STATUSFLAGS2_ROCKETS_IN_RADIO_TOWER_F ; 0 + const STATUSFLAGS2_SAFARI_GAME_F ; 1 + const STATUSFLAGS2_BUG_CONTEST_TIMER_F ; 2 + const STATUSFLAGS2_UNUSED_3_F ; 3 + const STATUSFLAGS2_BIKE_SHOP_CALL_F ; 4 + const STATUSFLAGS2_UNUSED_5_F ; 5 + const STATUSFLAGS2_REACHED_GOLDENROD_F ; 6 + const STATUSFLAGS2_ROCKETS_IN_MAHOGANY_F ; 7 ; wJohtoBadges: ; d57c const_def diff --git a/engine/main_menu.asm b/engine/main_menu.asm index ff480e37..73debf65 100755 --- a/engine/main_menu.asm +++ b/engine/main_menu.asm @@ -266,8 +266,8 @@ Function5c3a: ; 5c3a (1:5c3a) ret Function5c41: ; 5c41 (1:5c41) - ld hl, wOAMBuffer - ld bc, wOptions - wOAMBuffer + ld hl, wVirtualOAM + ld bc, wOptions - wVirtualOAM xor a call ByteFill @@ -1064,7 +1064,7 @@ Intro_PlacePlayerSprite: ; 6210 (1:6210) lb bc, BANK(PlayerSpriteGFX), 12 ld hl, $8000 call Request2bpp - ld hl, wOAMBuffer + ld hl, wVirtualOAM ld de, .OAMData ld a, [de] inc de diff --git a/engine/overworld/map_objects.asm b/engine/overworld/map_objects.asm index 1c118ed6..2bf5fda2 100755 --- a/engine/overworld/map_objects.asm +++ b/engine/overworld/map_objects.asm @@ -1176,7 +1176,7 @@ Function58b0: ; 58b0 (1:58b0) cp b ret nc ld l, a - ld h, wOAMBuffer / $100 + ld h, wVirtualOAM / $100 ld de, $4 ld a, b ld c, $a0 @@ -192,7 +192,7 @@ jp_de:: ret ClearSprites:: ; 30ff (0:30ff) - ld hl, wOAMBuffer + ld hl, wVirtualOAM ld b, $a0 xor a .asm_3105 @@ -202,7 +202,7 @@ ClearSprites:: ; 30ff (0:30ff) ret HideSprites:: - ld hl, wOAMBuffer + ld hl, wVirtualOAM ld de, $4 ld b, $28 ld a, $a0 diff --git a/home/audio.asm b/home/audio.asm index 8f3ec91c..d57a126b 100644 --- a/home/audio.asm +++ b/home/audio.asm @@ -1,37 +1,47 @@ -MapSetup_Sound_Off:: ; 3d4f (0:3d4f) +; Audio interfaces. + +MapSetup_Sound_Off:: push hl push de push bc push af - ld a, [hROMBank] + + ldh a, [hROMBank] push af ld a, BANK(_MapSetup_Sound_Off) - ld [hROMBank], a + ldh [hROMBank], a ld [MBC3RomBank], a + call _MapSetup_Sound_Off + pop af - ld [hROMBank], a + ldh [hROMBank], a ld [MBC3RomBank], a + pop af pop bc pop de pop hl ret -UpdateSound:: ; 3d6b (0:3d6b) +UpdateSound:: push hl push de push bc push af - ld a, [hROMBank] + + ldh a, [hROMBank] push af ld a, BANK(_UpdateSound) - ld [hROMBank], a + ldh [hROMBank], a ld [MBC3RomBank], a + call _UpdateSound + pop af - ld [hROMBank], a + ldh [hROMBank], a ld [MBC3RomBank], a + pop af pop bc pop de @@ -39,38 +49,45 @@ UpdateSound:: ; 3d6b (0:3d6b) ret _LoadMusicByte:: - ld [hROMBank], a +; wCurMusicByte = [a:de] + ldh [hROMBank], a ld [MBC3RomBank], a ld a, [de] ld [wCurMusicByte], a - ld a, BANK(_UpdateSound) + ld a, BANK(LoadMusicByte) - ld [hROMBank], a + ldh [hROMBank], a ld [MBC3RomBank], a ret -PlayMusic:: ; 3d98 (0:3d98) +PlayMusic:: +; Play music de. + push hl push de push bc push af - ld a, [hROMBank] + + ldh a, [hROMBank] push af - ld a, BANK(_PlayMusic) - ld [hROMBank], a + ld a, BANK(_PlayMusic) ; aka BANK(_MapSetup_Sound_Off) + ldh [hROMBank], a ld [MBC3RomBank], a + ld a, e and a - jr z, .asm_3daf - call _PlayMusic ; $4b30 - jr .asm_3db2 + jr z, .nomusic + + call _PlayMusic + jr .end -.asm_3daf +.nomusic call _MapSetup_Sound_Off -.asm_3db2 + +.end pop af - ld [hROMBank], a + ldh [hROMBank], a ld [MBC3RomBank], a pop af pop bc @@ -79,51 +96,62 @@ PlayMusic:: ; 3d98 (0:3d98) ret PlayMusic2:: +; Stop playing music, then play music de. + push hl push de push bc push af - ld a, [hROMBank] + + ldh a, [hROMBank] push af ld a, BANK(_PlayMusic) - ld [hROMBank], a + ldh [hROMBank], a ld [MBC3RomBank], a + push de ld de, MUSIC_NONE call _PlayMusic call DelayFrame pop de call _PlayMusic + pop af - ld [hROMBank], a + ldh [hROMBank], a ld [MBC3RomBank], a + pop af pop bc pop de pop hl ret -PlayCry:: ; 3de4 (0:3de4) +PlayCry:: +; Play cry de. + push hl push de push bc push af - ld a, [hROMBank] + + ldh a, [hROMBank] push af + + ; Cries are stuck in one bank. ld a, BANK(PokemonCries) - ld [hROMBank], a + ldh [hROMBank], a ld [MBC3RomBank], a + ld hl, PokemonCries +rept 6 ; sizeof(mon_cry) add hl, de - add hl, de - add hl, de - add hl, de - add hl, de - add hl, de +endr + ld e, [hl] inc hl ld d, [hl] inc hl + ld a, [hli] ld [wCryPitch], a ld a, [hli] @@ -132,42 +160,57 @@ PlayCry:: ; 3de4 (0:3de4) ld [wCryLength], a ld a, [hl] ld [wCryLength + 1], a + ld a, BANK(_PlayCry) - ld [hROMBank], a + ldh [hROMBank], a ld [MBC3RomBank], a + call _PlayCry + pop af - ld [hROMBank], a + ldh [hROMBank], a ld [MBC3RomBank], a + pop af pop bc pop de pop hl ret -PlaySFX:: ; 3e24 (0:3e24) +PlaySFX:: +; Play sound effect de. +; Sound effects are ordered by priority (highest to lowest) + push hl push de push bc push af + + ; Is something already playing? call CheckSFX - jr nc, .asm_3e33 + jr nc, .play + + ; Does it have priority? ld a, [wCurSFX] cp e - jr c, .asm_3e4a -.asm_3e33 - ld a, [hROMBank] + jr c, .done + +.play + ldh a, [hROMBank] push af - ld a, BANK(_PlaySFX) ; $3a - ld [hROMBank], a + ld a, BANK(_PlaySFX) + ldh [hROMBank], a ld [MBC3RomBank], a + ld a, e ld [wCurSFX], a - call _PlaySFX ; $4c04 + call _PlaySFX + pop af - ld [hROMBank], a + ldh [hROMBank], a ld [MBC3RomBank], a -.asm_3e4a + +.done pop af pop bc pop de @@ -179,31 +222,35 @@ WaitPlaySFX:: call PlaySFX ret -WaitSFX:: ; 3e56 (0:3e56) +WaitSFX:: +; infinite loop until sfx is done playing + push hl -.asm_3e57 + +.wait ld hl, wChannel5Flags1 bit 0, [hl] - jr nz, .asm_3e57 + jr nz, .wait ld hl, wChannel6Flags1 bit 0, [hl] - jr nz, .asm_3e57 + jr nz, .wait ld hl, wChannel7Flags1 bit 0, [hl] - jr nz, .asm_3e57 + jr nz, .wait ld hl, wChannel8Flags1 bit 0, [hl] - jr nz, .asm_3e57 + jr nz, .wait + pop hl ret MaxVolume:: - ld a, $77 + ld a, MAX_VOLUME ld [wVolume], a ret LowVolume:: - ld a, $33 + ld a, $33 ; 40% ld [wVolume], a ret @@ -212,41 +259,46 @@ VolumeOff:: ld [wVolume], a ret -FadeOutMusic:: - ld a, $4 +Unused_FadeOutMusic:: + ld a, 4 ld [wMusicFade], a ret FadeInMusic:: - ld a, 4 | 1 << 7 + ld a, 4 | (1 << MUSIC_FADE_IN_F) ld [wMusicFade], a ret -Function3e92:: ; 3e92 (0:3e92) +SkipMusic:: +; Skip a frames of music. +.loop and a ret z dec a call UpdateSound - jr Function3e92 + jr .loop FadeToMapMusic:: push hl push de push bc push af - call GetMapMusic + + call GetMapMusic_MaybeSpecial ld a, [wMapMusic] cp e - jr z, .asm_3eb8 - ld a, $8 + jr z, .done + + ld a, 8 ld [wMusicFade], a ld a, e ld [wMusicFadeID], a ld a, d ld [wMusicFadeID + 1], a ld a, e - ld [wChannelsEnd], a -.asm_3eb8 + ld [wMapMusic], a + +.done pop af pop bc pop de @@ -258,10 +310,12 @@ PlayMapMusic:: push de push bc push af - call GetMapMusic + + call GetMapMusic_MaybeSpecial ld a, [wMapMusic] cp e - jr z, .asm_3edc + jr z, .done + push de ld de, MUSIC_NONE call PlayMusic @@ -270,7 +324,8 @@ PlayMapMusic:: ld a, e ld [wMapMusic], a call PlayMusic -.asm_3edc + +.done pop af pop bc pop de @@ -282,22 +337,25 @@ EnterMapMusic:: push de push bc push af + xor a ld [wDontPlayMapMusicOnReload], a ld de, MUSIC_BICYCLE ld a, [wPlayerState] - cp $1 - jr z, .asm_3ef6 - call GetMapMusic -.asm_3ef6 + cp PLAYER_BIKE + jr z, .play + call GetMapMusic_MaybeSpecial +.play push de ld de, MUSIC_NONE call PlayMusic call DelayFrame pop de + ld a, e - ld [wChannelsEnd], a + ld [wMapMusic], a call PlayMusic + pop af pop bc pop de @@ -309,7 +367,7 @@ TryRestartMapMusic:: and a jr z, RestartMapMusic xor a - ld [wChannelsEnd], a + ld [wMapMusic], a ld de, MUSIC_NONE call PlayMusic call DelayFrame @@ -325,9 +383,9 @@ RestartMapMusic:: ld de, MUSIC_NONE call PlayMusic call DelayFrame - ld a, [wChannelsEnd] + ld a, [wMapMusic] ld e, a - ld d, $0 + ld d, 0 call PlayMusic pop af pop bc @@ -335,15 +393,18 @@ RestartMapMusic:: pop hl ret -SpecialMapMusic:: ; 3f40 (0:3f40) +SpecialMapMusic:: ld a, [wPlayerState] cp PLAYER_SURF jr z, .surf cp PLAYER_SURF_PIKA jr z, .surf - CheckFlag ENGINE_BUG_CONTEST_TIMER + + ld a, [wStatusFlags2] + bit STATUSFLAGS2_BUG_CONTEST_TIMER_F, a jr nz, .contest -.normal + +.no and a ret @@ -360,73 +421,76 @@ SpecialMapMusic:: ; 3f40 (0:3f40) .contest ld a, [wMapGroup] cp GROUP_ROUTE_35_NATIONAL_PARK_GATE - jr nz, .normal + jr nz, .no ld a, [wMapNumber] cp MAP_ROUTE_35_NATIONAL_PARK_GATE jr z, .ranking cp MAP_ROUTE_36_NATIONAL_PARK_GATE - jr nz, .normal + jr nz, .no + .ranking ld de, MUSIC_BUG_CATCHING_CONTEST_RANKING scf ret -GetMapMusic:: ; 3f75 (0:3f75) +GetMapMusic_MaybeSpecial:: call SpecialMapMusic ret c - call GetMapHeaderMusic + call GetMapMusic ret -Function3f7d:: - ld a, $20 - ld [$c398], a - ld [$c39c], a - ld a, $50 - ld [$c399], a - ld a, $58 - ld [$c39d], a +Unreferenced_Function3d9f:: +; Places a BCD number at the +; upper center of the screen. + ld a, 4 * TILE_WIDTH + ld [wVirtualOAMSprite38YCoord], a + ld [wVirtualOAMSprite39YCoord], a + ld a, 10 * TILE_WIDTH + ld [wVirtualOAMSprite38XCoord], a + ld a, 11 * TILE_WIDTH + ld [wVirtualOAMSprite39XCoord], a xor a - ld [$c39b], a - ld [$c39f], a - ld a, [wc196] - cp $64 - jr nc, .asm_3fb3 - add $1 + ld [wVirtualOAMSprite38Attributes], a + ld [wVirtualOAMSprite39Attributes], a + ld a, [wUnusedBCDNumber] + cp 100 + jr nc, .max + add 1 daa ld b, a swap a and $f - add $f6 - ld [$c39a], a + add "0" + ld [wVirtualOAMSprite38TileID], a ld a, b and $f - add $f6 - ld [$c39e], a + add "0" + ld [wVirtualOAMSprite39TileID], a ret -.asm_3fb3 - ld a, $ff - ld [$c39a], a - ld [$c39e], a +.max + ld a, "9" + ld [wVirtualOAMSprite38TileID], a + ld [wVirtualOAMSprite39TileID], a ret -CheckSFX:: ; 3fbc (0:3fbc) +CheckSFX:: +; Return carry if any SFX channels are active. ld a, [wChannel5Flags1] bit 0, a - jr nz, .asm_3fda + jr nz, .playing ld a, [wChannel6Flags1] bit 0, a - jr nz, .asm_3fda + jr nz, .playing ld a, [wChannel7Flags1] bit 0, a - jr nz, .asm_3fda + jr nz, .playing ld a, [wChannel8Flags1] bit 0, a - jr nz, .asm_3fda + jr nz, .playing and a ret - -.asm_3fda +.playing scf ret @@ -434,9 +498,9 @@ TerminateExpBarSound:: xor a ld [wChannel5Flags1], a ld [wSoundInput], a - ld [rNR10], a - ld [rNR11], a - ld [rNR12], a - ld [rNR13], a - ld [rNR14], a + ldh [rNR10], a + ldh [rNR11], a + ldh [rNR12], a + ldh [rNR13], a + ldh [rNR14], a ret diff --git a/home/map.asm b/home/map.asm index 473280ba..ea4b5a26 100644 --- a/home/map.asm +++ b/home/map.asm @@ -2165,7 +2165,7 @@ ReloadTilesetAndPalettes:: ; 2c87 (0:2c87) call OverworldTextModeSwitch call LoadTileset ld a, $8 - call Function3e92 + call SkipMusic pop af rst Bankswitch call EnableLCD @@ -2340,7 +2340,7 @@ GetWorldMapLocation:: pop hl ret -GetMapHeaderMusic:: +GetMapMusic:: push hl push bc ld de, $6 diff --git a/macros/wram.asm b/macros/wram.asm index 1df2ee28..6c55c468 100755 --- a/macros/wram.asm +++ b/macros/wram.asm @@ -299,6 +299,19 @@ map_object: MACRO ds 2 ENDM +sprite_oam_struct: MACRO +\1YCoord:: db +\1XCoord:: db +\1TileID:: db +\1Attributes:: db +; bit 7: priority +; bit 6: y flip +; bit 5: x flip +; bit 4: pal # (non-cgb) +; bit 3: vram bank (cgb only) +; bit 2-0: pal # (cgb only) +ENDM + sprite_anim_struct: MACRO \1Index:: ds 1 ; 0 \1FramesetID:: ds 1 ; 1 @@ -39,7 +39,7 @@ LoadPushOAM:: ; 4032 (1:4032) ret PushOAM: - ld a, wOAMBuffer / $100 + ld a, wVirtualOAM / $100 ld [rDMA], a ld a, $28 .asm_4046 diff --git a/pokegold.link b/pokegold.link index 6fc903c1..0ce9ca26 100644 --- a/pokegold.link +++ b/pokegold.link @@ -360,7 +360,7 @@ WRAM0 "Audio RAM" "WRAM" "GBC Palettes" - "OAM Buffer" + "Sprites" "TileMap" "Animated Objects" "Video" diff --git a/pokesilver.link b/pokesilver.link index 6fc903c1..0ce9ca26 100644 --- a/pokesilver.link +++ b/pokesilver.link @@ -360,7 +360,7 @@ WRAM0 "Audio RAM" "WRAM" "GBC Palettes" - "OAM Buffer" + "Sprites" "TileMap" "Animated Objects" "Video" @@ -24,7 +24,7 @@ wChannel8:: channel_struct wChannel8 ; c15f wCurTrackDuty:: ds 1 wCurTrackIntensity:: ds 1 wCurTrackFrequency:: dw -wc196:: ds 1 ; BCD value, dummied out +wUnusedBCDNumber:: db ; BCD value, dummied out wCurNoteDuration:: ds 1 ; used in MusicE0 and LoadNote wCurMusicByte:: ; c198 @@ -202,9 +202,51 @@ wTempOBPals:: palbuffer wTempOB ; c240 wBGPals:: palbuffer wBG ; c280 wOBPals:: palbuffer wOB ; c2c0 -SECTION "OAM Buffer", WRAM0 -wOAMBuffer:: ; c300 - ds 4 * 40 +SECTION "Sprites", WRAM0 + +wVirtualOAM:: ; c300 +wVirtualOAMSprite00:: sprite_oam_struct wVirtualOAMSprite00 +wVirtualOAMSprite01:: sprite_oam_struct wVirtualOAMSprite01 +wVirtualOAMSprite02:: sprite_oam_struct wVirtualOAMSprite02 +wVirtualOAMSprite03:: sprite_oam_struct wVirtualOAMSprite03 +wVirtualOAMSprite04:: sprite_oam_struct wVirtualOAMSprite04 +wVirtualOAMSprite05:: sprite_oam_struct wVirtualOAMSprite05 +wVirtualOAMSprite06:: sprite_oam_struct wVirtualOAMSprite06 +wVirtualOAMSprite07:: sprite_oam_struct wVirtualOAMSprite07 +wVirtualOAMSprite08:: sprite_oam_struct wVirtualOAMSprite08 +wVirtualOAMSprite09:: sprite_oam_struct wVirtualOAMSprite09 +wVirtualOAMSprite10:: sprite_oam_struct wVirtualOAMSprite10 +wVirtualOAMSprite11:: sprite_oam_struct wVirtualOAMSprite11 +wVirtualOAMSprite12:: sprite_oam_struct wVirtualOAMSprite12 +wVirtualOAMSprite13:: sprite_oam_struct wVirtualOAMSprite13 +wVirtualOAMSprite14:: sprite_oam_struct wVirtualOAMSprite14 +wVirtualOAMSprite15:: sprite_oam_struct wVirtualOAMSprite15 +wVirtualOAMSprite16:: sprite_oam_struct wVirtualOAMSprite16 +wVirtualOAMSprite17:: sprite_oam_struct wVirtualOAMSprite17 +wVirtualOAMSprite18:: sprite_oam_struct wVirtualOAMSprite18 +wVirtualOAMSprite19:: sprite_oam_struct wVirtualOAMSprite19 +wVirtualOAMSprite20:: sprite_oam_struct wVirtualOAMSprite20 +wVirtualOAMSprite21:: sprite_oam_struct wVirtualOAMSprite21 +wVirtualOAMSprite22:: sprite_oam_struct wVirtualOAMSprite22 +wVirtualOAMSprite23:: sprite_oam_struct wVirtualOAMSprite23 +wVirtualOAMSprite24:: sprite_oam_struct wVirtualOAMSprite24 +wVirtualOAMSprite25:: sprite_oam_struct wVirtualOAMSprite25 +wVirtualOAMSprite26:: sprite_oam_struct wVirtualOAMSprite26 +wVirtualOAMSprite27:: sprite_oam_struct wVirtualOAMSprite27 +wVirtualOAMSprite28:: sprite_oam_struct wVirtualOAMSprite28 +wVirtualOAMSprite29:: sprite_oam_struct wVirtualOAMSprite29 +wVirtualOAMSprite30:: sprite_oam_struct wVirtualOAMSprite30 +wVirtualOAMSprite31:: sprite_oam_struct wVirtualOAMSprite31 +wVirtualOAMSprite32:: sprite_oam_struct wVirtualOAMSprite32 +wVirtualOAMSprite33:: sprite_oam_struct wVirtualOAMSprite33 +wVirtualOAMSprite34:: sprite_oam_struct wVirtualOAMSprite34 +wVirtualOAMSprite35:: sprite_oam_struct wVirtualOAMSprite35 +wVirtualOAMSprite36:: sprite_oam_struct wVirtualOAMSprite36 +wVirtualOAMSprite37:: sprite_oam_struct wVirtualOAMSprite37 +wVirtualOAMSprite38:: sprite_oam_struct wVirtualOAMSprite38 +wVirtualOAMSprite39:: sprite_oam_struct wVirtualOAMSprite39 +wVirtualOAMEnd:: + SECTION "TileMap", WRAM0 wTileMap:: ; c3a0 |