From 435b0cf686e55bbe60acbce1e6154b0c2450bbac Mon Sep 17 00:00:00 2001 From: PikalaxALT Date: Mon, 16 Nov 2015 16:01:45 -0500 Subject: Options menu, some mobile fns --- engine/color.asm | 13 +- engine/flypoints.asm | 916 ---------------------------------------- engine/map_objects.asm | 2 +- engine/options_menu.asm | 565 +++++++++++++++++++++++++ engine/radio2.asm | 260 ++++++++++++ engine/specials.asm | 4 +- engine/town_map.asm | 1068 +++++++++++++++++++++++++++++++++++++++++++++++ engine/wildmons.asm | 1057 ++++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 2960 insertions(+), 925 deletions(-) delete mode 100755 engine/flypoints.asm create mode 100755 engine/options_menu.asm create mode 100755 engine/town_map.asm create mode 100755 engine/wildmons.asm (limited to 'engine') diff --git a/engine/color.asm b/engine/color.asm index d24fdf2df..c44b296d4 100644 --- a/engine/color.asm +++ b/engine/color.asm @@ -1,4 +1,4 @@ - +PALPACKET_LENGTH EQU $10 INCLUDE "predef/sgb.asm" SHINY_ATK_BIT EQU 5 @@ -89,7 +89,7 @@ Function8aa4: ; 8aa4 push bc ld hl, PalPacket_9ce6 ld de, wcda9 - ld bc, PalPacket_9cf6 - PalPacket_9ce6 + ld bc, PALPACKET_LENGTH call CopyBytes pop bc pop de @@ -232,7 +232,7 @@ Function8b81: ; 8b81 push af ld hl, PalPacket_9ce6 ld de, wcda9 - ld bc, $0010 + ld bc, PALPACKET_LENGTH call CopyBytes pop af call Function9775 @@ -437,7 +437,7 @@ endr push hl ld hl, PalPacket_9ce6 ld de, wcda9 - ld bc, $0010 + ld bc, PALPACKET_LENGTH call CopyBytes pop hl rept 2 @@ -792,7 +792,7 @@ Function974b: ; 974b and a jp nz, Function97f9 ld a, [wPlayerSpriteSetupFlags] - bit 2, a + bit 2, a ; transformed to male jr nz, .male ld a, [PlayerGender] and a @@ -1212,7 +1212,7 @@ Function99d8: ; 99d8 ld a, $e4 ld [rBGP], a ld de, VTiles1 - ld bc, $0140 + ld bc, 20 tiles call CopyData ld b, $12 .asm_99ea @@ -1367,6 +1367,7 @@ BlkPacket_9b86: ; 9a86 ; 9b96 ; 9b96 + PalPacket_9b96: db $51, $48, $00, $49, $00, $4a, $00, $4b, $00, $00, $00, $00, $00, $00, $00, $00 PalPacket_9ba6: db $51, $2b, $00, $24, $00, $20, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00 PalPacket_9bb6: db $51, $41, $00, $42, $00, $43, $00, $44, $00, $00, $00, $00, $00, $00, $00, $00 diff --git a/engine/flypoints.asm b/engine/flypoints.asm deleted file mode 100755 index f56facf09..000000000 --- a/engine/flypoints.asm +++ /dev/null @@ -1,916 +0,0 @@ -_FlyMap: ; 91af3 - call ClearBGPalettes - call ClearTileMap - call ClearSprites - ld hl, hInMenu - ld a, [hl] - push af - ld [hl], $1 - xor a - ld [hBGMapMode], a - callba Function8cf53 - call Function91ff2 - ld de, GFX_922e1 - ld hl, VTiles2 tile $30 - lb bc, BANK(GFX_922e1), 6 - call Request1bpp - call FlyMap - call Function91c8f - ld b, $2 - call GetSGBLayout - call SetPalettes -.loop - call JoyTextDelay - ld hl, hJoyPressed - ld a, [hl] - and B_BUTTON - jr nz, .pressedB - ld a, [hl] - and A_BUTTON - jr nz, .pressedA - call FlyMapScroll - call GetMapCursorCoordinates - callba Function8cf69 - call DelayFrame - jr .loop - -.pressedB - ld a, -1 - jr .exit - -.pressedA - ld a, [wd002] - ld l, a - ld h, 0 - add hl, hl - ld de, Flypoints + 1 - add hl, de - ld a, [hl] - -.exit - ld [wd002], a - pop af - ld [hInMenu], a - call ClearBGPalettes - ld a, $90 - ld [hWY], a - xor a - ld [hBGMapAddress], a - ld a, VBGMap0 / $100 - ld [hBGMapAddress + 1], a - ld a, [wd002] - ld e, a - ret -; 91b73 - -FlyMapScroll: ; 91b73 - ld a, [StartFlypoint] - ld e, a - ld a, [EndFlypoint] - ld d, a - ld hl, hJoyLast - ld a, [hl] - and D_UP - jr nz, .ScrollNext - ld a, [hl] - and D_DOWN - jr nz, .ScrollPrev - ret - -.ScrollNext - ld hl, wd002 - ld a, [hl] - cp d - jr nz, .NotAtEndYet - ld a, e - dec a - ld [hl], a - -.NotAtEndYet - inc [hl] - call CheckIfVisitedFlypoint - jr z, .ScrollNext - jr .Finally - -.ScrollPrev - ld hl, wd002 - ld a, [hl] - cp e - jr nz, .NotAtStartYet - ld a, d - inc a - ld [hl], a - -.NotAtStartYet - dec [hl] - call CheckIfVisitedFlypoint - jr z, .ScrollPrev - -.Finally - call TownMapBubble - call WaitBGMap - xor a - ld [hBGMapMode], a - ret -; 91bb5 - -TownMapBubble: ; 91bb5 -; Draw the bubble containing the location text in the town map HUD - -; Top-left corner - hlcoord 1, 0 - ld a, $30 - ld [hli], a - -; Top row - ld bc, 16 - ld a, " " - call ByteFill - -; Top-right corner - ld a, $31 - ld [hl], a - hlcoord 1, 1 - - -; Middle row - ld bc, 18 - ld a, " " - call ByteFill - - -; Bottom-left corner - hlcoord 1, 2 - ld a, $32 - ld [hli], a - -; Bottom row - ld bc, 16 - ld a, " " - call ByteFill - -; Bottom-right corner - ld a, $33 - ld [hl], a - - -; Print "Where?" - hlcoord 2, 0 - ld de, .Where - call PlaceString - -; Print the name of the default flypoint - call .Name - -; Up/down arrows - hlcoord 18, 1 - ld [hl], $34 - ret - -.Where - db "Where?@" - -.Name -; We need the map location of the default flypoint - ld a, [wd002] - ld l, a - ld h, 0 - add hl, hl ; two bytes per flypoint - ld de, Flypoints - add hl, de - ld e, [hl] - - callba GetLandmarkName - - hlcoord 2, 1 - ld de, StringBuffer1 - call PlaceString - ret -; 91c17 - -GetMapCursorCoordinates: ; 91c17 - ld a, [wd002] - ld l, a - ld h, $0 - add hl, hl - ld de, Flypoints - add hl, de - ld e, [hl] - callba GetLandmarkCoords - ld a, [wd003] - ld c, a - ld a, [wd004] - ld b, a - ld hl, $4 - add hl, bc - ld [hl], e - ld hl, $5 - add hl, bc - ld [hl], d - ret -; 91c3c - -CheckIfVisitedFlypoint: ; 91c3c -; Check if the flypoint loaded in [hl] has been visited yet. - push bc - push de - push hl - ld l, [hl] - ld h, 0 - add hl, hl - ld de, Flypoints + 1 - add hl, de - ld c, [hl] - call HasVisitedSpawn - pop hl - pop de - pop bc - and a - ret -; 91c50 - -HasVisitedSpawn: ; 91c50 -; Check if spawn point c has been visited. - ld hl, VisitedSpawns - ld b, CHECK_FLAG - ld d, 0 - predef FlagPredef - ld a, c - ret -; 91c5e - -Flypoints: ; 91c5e -; landmark, spawn point - - const_def - -flypoint: MACRO -; \1\@FLY EQUS "FLY_\1" -; \1\@SPAWN EQUS "SPAWN_\1" - ; const \1\@FLY - ; db \2, \1\@SPAWN - const FLY_\1 - db \2, SPAWN_\1 -ENDM - -; Johto - flypoint NEW_BARK, NEW_BARK_TOWN - flypoint CHERRYGROVE, CHERRYGROVE_CITY - flypoint VIOLET, VIOLET_CITY - flypoint AZALEA, AZALEA_TOWN - flypoint GOLDENROD, GOLDENROD_CITY - flypoint ECRUTEAK, ECRUTEAK_CITY - flypoint OLIVINE, OLIVINE_CITY - flypoint CIANWOOD, CIANWOOD_CITY - flypoint MAHOGANY, MAHOGANY_TOWN - flypoint LAKE, LAKE_OF_RAGE - flypoint BLACKTHORN, BLACKTHORN_CITY - flypoint MT_SILVER, SILVER_CAVE - -; Kanto -KANTO_FLYPOINT EQU const_value - - flypoint PALLET, PALLET_TOWN - flypoint VIRIDIAN, VIRIDIAN_CITY - flypoint PEWTER, PEWTER_CITY - flypoint CERULEAN, CERULEAN_CITY - flypoint VERMILION, VERMILION_CITY - flypoint ROCK_TUNNEL, ROCK_TUNNEL - flypoint LAVENDER, LAVENDER_TOWN - flypoint CELADON, CELADON_CITY - flypoint SAFFRON, SAFFRON_CITY - flypoint FUCHSIA, FUCHSIA_CITY - flypoint CINNABAR, CINNABAR_ISLAND - flypoint INDIGO, INDIGO_PLATEAU - - db -1 -; 91c8f - -Function91c8f: ; 91c8f - ret -; 91c90 - -FlyMap: ; 91c90 - - ld a, [MapGroup] - ld b, a - ld a, [MapNumber] - ld c, a - call GetWorldMapLocation - -; If we're not in a valid location, i.e. Pokecenter floor 2F, -; the backup map information is used - - cp SPECIAL_MAP - jr nz, .CheckRegion - - ld a, [BackupMapGroup] - ld b, a - ld a, [BackupMapNumber] - ld c, a - call GetWorldMapLocation - -.CheckRegion -; The first 46 locations are part of Johto. The rest are in Kanto - cp KANTO_LANDMARK - jr nc, .KantoFlyMap - -.JohtoFlyMap -; Note that .NoKanto should be modified in tandem with this branch - - push af - -; Start from New Bark Town - ld a, FLY_NEW_BARK - ld [wd002], a - -; Flypoints begin at New Bark Town... - ld [StartFlypoint], a -; ..and end at Silver Cave - ld a, FLY_MT_SILVER - ld [EndFlypoint], a - -; Fill out the map - call FillJohtoMap - call .MapHud - pop af - call TownMapPlayerIcon - ret - -.KantoFlyMap - -; The event that there are no flypoints enabled in a map is not -; accounted for. As a result, if you attempt to select a flypoint -; when there are none enabled, the game will crash. Additionally, -; the flypoint selection has a default starting point that -; can be flown to even if none are enabled - -; To prevent both of these things from happening when the player -; enters Kanto, fly access is restricted until Indigo Plateau is -; visited and its flypoint enabled - - push af - ld c, SPAWN_INDIGO - call HasVisitedSpawn - and a - jr z, .NoKanto - -; Kanto's map is only loaded if we've visited Indigo Plateau - -; Flypoints begin at Pallet Town... - ld a, FLY_PALLET - ld [StartFlypoint], a -; ...and end at Indigo Plateau - ld a, FLY_INDIGO - ld [EndFlypoint], a - -; Because Indigo Plateau is the first flypoint the player -; visits, it's made the default flypoint - ld [wd002], a - -; Fill out the map - call FillKantoMap - call .MapHud - pop af - call TownMapPlayerIcon - ret - -.NoKanto -; If Indigo Plateau hasn't been visited, we use Johto's map instead - -; Start from New Bark Town - ld a, FLY_NEW_BARK - ld [wd002], a - -; Flypoints begin at New Bark Town... - ld [StartFlypoint], a -; ..and end at Silver Cave - ld a, FLY_MT_SILVER - ld [EndFlypoint], a - - call FillJohtoMap - - pop af - -.MapHud - call TownMapBubble - call TownMapPals - - ld hl, VBGMap0 ; BG Map 0 - call TownMapBGUpdate - - call TownMapMon - ld a, c - ld [wd003], a - ld a, b - ld [wd004], a - ret -; 91d11 - -Function91d11: ; 91d11 - ld a, [wd002] - push af - ld a, [wd003] - push af - ld a, e - ld [wd002], a - call ClearSprites - xor a - ld [hBGMapMode], a - ld a, $1 - ld [hInMenu], a - ld de, GFX_922d1 - ld hl, VTiles0 tile $7f - lb bc, BANK(GFX_922d1), 1 - call Request2bpp ; actually 1bpp - call Function91ed0 - ld hl, VTiles0 tile $78 - ld c, $4 - call Request2bpp - call Function91ff2 - call FillKantoMap - call Function91de9 - call TownMapPals - ld hl, VBGMap1 - call TownMapBGUpdate - call FillJohtoMap - call Function91de9 - call TownMapPals - ld hl, VBGMap0 - call TownMapBGUpdate - ld b, $2 - call GetSGBLayout - call SetPalettes - xor a - ld [hBGMapMode], a - xor a - call Function91e1e -.asm_91d6e - call JoyTextDelay - ld hl, hJoyPressed - ld a, [hl] - and A_BUTTON | B_BUTTON - jr nz, .asm_91d8f - ld a, [hJoypadDown] - and SELECT - jr nz, .asm_91d87 - call Function91d9b - call Function91dcd - jr .asm_91d8a - -.asm_91d87 - call Function91e5a - -.asm_91d8a - call DelayFrame - jr .asm_91d6e - -.asm_91d8f - call ClearSprites - pop af - ld [wd003], a - pop af - ld [wd002], a - ret -; 91d9b - -Function91d9b: ; 91d9b - ld a, [hl] - and $20 - jr nz, .asm_91da6 - ld a, [hl] - and $10 - jr nz, .asm_91db7 - ret - -.asm_91da6 - ld a, [hWY] - cp $90 - ret z - call ClearSprites - ld a, $90 - ld [hWY], a - xor a - call Function91e1e - ret - -.asm_91db7 - ld a, [StatusFlags] - bit 6, a ; hall of fame - ret z - ld a, [hWY] - and a - ret z - call ClearSprites - xor a - ld [hWY], a - ld a, $1 - call Function91e1e - ret -; 91dcd - -Function91dcd: ; 91dcd - ld a, [hVBlankCounter] - ld e, a - and $f - ret nz - ld a, e - and $10 - jr nz, .asm_91ddc - call ClearSprites - ret - -.asm_91ddc - hlcoord 0, 0 - ld de, Sprites - ld bc, $a0 - call CopyBytes - ret -; 91de9 - -Function91de9: ; 91de9 - hlcoord 0, 0 - ld bc, SCREEN_WIDTH - ld a, $7f - call ByteFill - hlcoord 0, 1 - ld a, $6 - ld [hli], a - ld bc, SCREEN_HEIGHT - ld a, $7 - call ByteFill - ld [hl], $17 - call GetPokemonName - hlcoord 2, 0 - call PlaceString - ld h, b - ld l, c - ld de, String_91e16 - call PlaceString - ret -; 91e16 - -String_91e16: - db "'S NEST@" -; 91e1e - -Function91e1e: ; 91e1e - ld [wd003], a - ld e, a - callba Function2a01f - decoord 0, 0 - ld hl, Sprites -.asm_91e2e - ld a, [de] - and a - jr z, .asm_91e4d - push de - ld e, a - push hl - callba GetLandmarkCoords - pop hl - ld a, d - sub $4 - ld [hli], a - ld a, e - sub $4 - ld [hli], a - ld a, $7f - ld [hli], a - xor a - ld [hli], a - pop de - inc de - jr .asm_91e2e - -.asm_91e4d - ld hl, Sprites - decoord 0, 0 - ld bc, $a0 - call CopyBytes - ret -; 91e5a - -Function91e5a: ; 91e5a - call Function91ea9 - ret c - - ld a, [wd002] - ld e, a - callba GetLandmarkCoords - ld c, e - ld b, d - ld de, Unknown_91e9c - ld hl, Sprites -.asm_91e70 - ld a, [de] - cp $80 - jr z, .asm_91e91 - - add b - ld [hli], a - inc de - - ld a, [de] - add c - ld [hli], a - inc de - - ld a, [de] - add $78 - ld [hli], a - inc de - - push bc - ld c, 0 - ld a, [PlayerGender] - bit 0, a - jr z, .asm_91e8c - inc c -.asm_91e8c - ld a, c - ld [hli], a - pop bc - - jr .asm_91e70 - -.asm_91e91 - ld hl, Sprites + $10 - ld bc, SpritesEnd - (Sprites + $10) - xor a - call ByteFill - ret -; 91e9c - -Unknown_91e9c: ; 91e9c - db -8, -8, 0 - db -8, 0, 1 - db 0, -8, 2 - db 0, 0, 3 - db $80 ; terminator -; 91ea9 - -Function91ea9: ; 91ea9 - ld a, [wd002] - cp FAST_SHIP - jr z, .johto - cp KANTO_LANDMARK - jr c, .johto - -.kanto - ld a, [wd003] - and a - jr z, .clear - jr .ok - -.johto - ld a, [wd003] - and a - jr nz, .clear - -.ok - and a - ret - -.clear - ld hl, Sprites - ld bc, SpritesEnd - Sprites - xor a - call ByteFill - scf - ret -; 91ed0 - -Function91ed0: ; 91ed0 - ld a, [wd002] - cp FAST_SHIP - jr z, .asm_91ede - callba GetPlayerIcon - ret - -.asm_91ede - ld de, FastShipGFX - ld b, BANK(FastShipGFX) - ret -; 91ee4 - -TownMapBGUpdate: ; 91ee4 -; Update BG Map tiles and attributes - -; BG Map address - ld a, l - ld [hBGMapAddress], a - ld a, h - ld [hBGMapAddress + 1], a - -; Only update palettes on CGB - ld a, [hCGB] - and a - jr z, .tiles - -; BG Map mode 2 (palettes) - ld a, 2 - ld [hBGMapMode], a - -; The BG Map is updated in thirds, so we wait -; 3 frames to update the whole screen's palettes. - ld c, 3 - call DelayFrames - -.tiles -; Update BG Map tiles - call WaitBGMap - -; Turn off BG Map update - xor a - ld [hBGMapMode], a - ret -; 91eff - -FillJohtoMap: ; 91eff - ld de, JohtoMap - jr FillTownMap - -FillKantoMap: ; 91f04 - ld de, KantoMap - -FillTownMap: ; 91f07 - hlcoord 0, 0 -.loop - ld a, [de] - cp $ff - ret z - ld a, [de] - ld [hli], a - inc de - jr .loop -; 91f13 - -TownMapPals: ; 91f13 -; Assign palettes based on tile ids - - hlcoord 0, 0 - decoord 0, 0, AttrMap - ld bc, 360 -.loop -; Current tile - ld a, [hli] - push hl - -; HP/borders use palette 0 - cp $60 - jr nc, .pal0 - -; The palette data is condensed to nybbles, -; least-significant first. - ld hl, TownMapPalMap - srl a - jr c, .odd - -; Even-numbered tile ids take the bottom nybble... - add l - ld l, a - ld a, h - adc 0 - ld h, a - ld a, [hl] - and %111 - jr .update - -.odd -; ...and odd ids take the top. - add l - ld l, a - ld a, h - adc 0 - ld h, a - ld a, [hl] - swap a - and %111 - jr .update - -.pal0 - xor a - -.update - pop hl - ld [de], a - inc de - dec bc - ld a, b - or c - jr nz, .loop - ret - -TownMapPalMap: - db $11, $21, $22, $00, $11, $13, $54, $54, $11, $21, $22, $00 - db $11, $10, $01, $00, $11, $21, $22, $00, $00, $00, $00, $00 - db $00, $00, $44, $04, $00, $00, $00, $00, $33, $33, $33, $33 - db $33, $33, $33, $03, $33, $33, $33, $33, $00, $00, $00, $00 -; 91f7b - -TownMapMon: ; 91f7b -; Draw the FlyMon icon at town map location in - -; Get FlyMon species - ld a, [CurPartyMon] - ld hl, PartySpecies - ld e, a - ld d, $0 - add hl, de - ld a, [hl] - ld [wd265], a - -; Get FlyMon icon - ld e, 8 ; starting tile in VRAM - callba GetSpeciesIcon - -; Animation/palette - ld de, 0 - ld a, $0 - call _InitSpriteAnimStruct - - ld hl, 3 - add hl, bc - ld [hl], 8 - ld hl, 2 - add hl, bc - ld [hl], 0 - ret -; 91fa6 - -TownMapPlayerIcon: ; 91fa6 -; Draw the player icon at town map location in a - push af - - callba GetPlayerIcon - -; Standing icon - ld hl, VTiles0 tile $10 - ld c, 4 ; # tiles - call Request2bpp - -; Walking icon - ld hl, $c0 - add hl, de - ld d, h - ld e, l - ld hl, VTiles0 tile $14 - ld c, 4 ; # tiles - ld a, BANK(ChrisSpriteGFX) ; does nothing - call Request2bpp - -; Animation/palette - ld de, 0 - ld b, $0a ; Male - ld a, [PlayerGender] - bit 0, a - jr z, .asm_91fd3 - ld b, $1e ; Female -.asm_91fd3 - ld a, b - call _InitSpriteAnimStruct - - ld hl, $3 - add hl, bc - ld [hl], $10 - - pop af - ld e, a - push bc - callba GetLandmarkCoords - pop bc - - ld hl, 4 - add hl, bc - ld [hl], e - ld hl, 5 - add hl, bc - ld [hl], d - ret -; 0x91ff2 - -Function91ff2: ; 91ff2 - ld hl, TownMapGFX - ld de, VTiles2 - lb bc, BANK(TownMapGFX), $30 - call DecompressRequest2bpp - ret -; 91fff - - -JohtoMap: ; 91fff -INCBIN "gfx/misc/johto.bin" -; 92168 - -KantoMap: ; 92168 -INCBIN "gfx/misc/kanto.bin" -; 922d1 - - -GFX_922d1: ; 922d1 -INCBIN "gfx/unknown/0922d1.2bpp" -GFX_922e1: ; 922e1 -INCBIN "gfx/unknown/0922e1.2bpp" -GFX_92301: ; 92301 -INCBIN "gfx/unknown/092301.2bpp" diff --git a/engine/map_objects.asm b/engine/map_objects.asm index e442b7f77..ef8878565 100644 --- a/engine/map_objects.asm +++ b/engine/map_objects.asm @@ -3053,7 +3053,7 @@ Function57bc: ; 57bc ret .ok - ld a, 0 + ld a, PERSON_ACTION_00 ld [PlayerAction], a ret ; 57ca diff --git a/engine/options_menu.asm b/engine/options_menu.asm new file mode 100755 index 000000000..ed2c21f30 --- /dev/null +++ b/engine/options_menu.asm @@ -0,0 +1,565 @@ +_OptionsMenu: ; e41d0 + ld hl, hInMenu + ld a, [hl] + push af + ld [hl], $1 + call ClearBGPalettes + hlcoord 0, 0 + ld b, $10 + ld c, $12 + call TextBox + hlcoord 2, 2 + ld de, StringOptions + call PlaceString + xor a + ld [wJumptableIndex], a + ld c, $6 ; number of items on the menu minus 1 (for cancel) + +.print_text_loop ; this next will display the settings of each option when the menu is opened + push bc + xor a + ld [hJoyLast], a + call GetOptionPointer + pop bc + ld hl, wJumptableIndex + inc [hl] + dec c + jr nz, .print_text_loop + + call UpdateFrame + xor a + ld [wJumptableIndex], a + inc a + ld [hBGMapMode], a + call WaitBGMap + ld b, SCGB_08 + call GetSGBLayout + call SetPalettes + +.joypad_loop + call JoyTextDelay + ld a, [hJoyPressed] + and START | B_BUTTON + jr nz, .ExitOptions + call OptionsControl + jr c, .dpad + call GetOptionPointer + jr c, .ExitOptions + +.dpad + call Functione455c + ld c, 3 + call DelayFrames + jr .joypad_loop + +.ExitOptions + ld de, SFX_TRANSACTION + call PlaySFX + call WaitSFX + pop af + ld [hInMenu], a + ret +; e4241 + +StringOptions: ; e4241 + db "TEXT SPEED" + db " :" + db "BATTLE SCENE" + db " :" + db "BATTLE STYLE" + db " :" + db "SOUND" + db " :" + db "PRINT" + db " :" + db "MENU ACCOUNT" + db " :" + db "FRAME" + db " :TYPE" + db "CANCEL@" +; e42d6 + + +GetOptionPointer: ; e42d6 + ld a, [wJumptableIndex] ; load the cursor position to a + ld e, a ; copy it to de + ld d, 0 + ld hl, .Pointers +rept 2 + add hl, de +endr + ld a, [hli] + ld h, [hl] + ld l, a + jp [hl] ; jump to the code of the current highlighted item +; e42e5 + +.Pointers + dw Options_TextSpeed + dw Options_BattleScene + dw Options_BattleStyle + dw Options_Sound + dw Options_Print + dw Options_MenuAccount + dw Options_Frame + dw Options_Cancel +; e42f5 + + +Options_TextSpeed: ; e42f5 + call GetTextSpeed + ld a, [hJoyPressed] + bit D_LEFT_F, a + jr nz, .LeftPressed + bit D_RIGHT_F, a + jr z, .NonePressed + ld a, c ; right pressed + cp SLOW_TEXT + jr c, .Increase + ld c, FAST_TEXT +- 1 + +.Increase + inc c + ld a, e + jr .Save + +.LeftPressed + ld a, c + and a + jr nz, .Decrease + ld c, SLOW_TEXT + 1 + +.Decrease + dec c + ld a, d + +.Save + ld b, a + ld a, [Options] + and $f0 + or b + ld [Options], a + +.NonePressed + ld b, 0 + ld hl, .Strings +rept 2 + add hl, bc +endr + ld e, [hl] + inc hl + ld d, [hl] + hlcoord 11, 3 + call PlaceString + and a + ret +; e4331 + +.Strings + dw .Fast + dw .Mid + dw .Slow + +.Fast + db "FAST@" +.Mid + db "MID @" +.Slow + db "SLOW@" +; e4346 + + +GetTextSpeed: ; e4346 + ld a, [Options] ; This converts the number of frames, to 0, 1, 2 representing speed + and 7 + cp 5 ; 5 frames of delay is slow + jr z, .slow + cp 1 ; 1 frame of delay is fast + jr z, .fast + ld c, MED_TEXT ; set it to mid if not one of the above + lb de, 1, 5 + ret + +.slow + ld c, SLOW_TEXT + lb de, 3, 1 + ret + +.fast + ld c, FAST_TEXT + lb de, 5, 3 + ret +; e4365 + + +Options_BattleScene: ; e4365 + ld hl, Options + ld a, [hJoyPressed] + bit D_LEFT_F, a + jr nz, .LeftPressed + bit D_RIGHT_F, a + jr z, .NonePressed + bit BATTLE_SCENE, [hl] + jr nz, .ToggleOn + jr .ToggleOff + +.LeftPressed + bit BATTLE_SCENE, [hl] + jr z, .ToggleOff + jr .ToggleOn + +.NonePressed + bit BATTLE_SCENE, [hl] + jr z, .ToggleOn + jr .ToggleOff + +.ToggleOn + res BATTLE_SCENE, [hl] + ld de, .On + jr .Display + +.ToggleOff + set BATTLE_SCENE, [hl] + ld de, .Off + +.Display + hlcoord 11, 5 + call PlaceString + and a + ret +; e4398 + +.On + db "ON @" +.Off + db "OFF@" +; e43a0 + + +Options_BattleStyle: ; e43a0 + ld hl, Options + ld a, [hJoyPressed] + bit D_LEFT_F, a + jr nz, .LeftPressed + bit D_RIGHT_F, a + jr z, .NonePressed + bit BATTLE_SHIFT, [hl] + jr nz, .ToggleShift + jr .ToggleSet + +.LeftPressed + bit BATTLE_SHIFT, [hl] + jr z, .ToggleSet + jr .ToggleShift + +.NonePressed + bit BATTLE_SHIFT, [hl] + jr nz, .ToggleSet + +.ToggleShift + res BATTLE_SHIFT, [hl] + ld de, .Shift + jr .Display + +.ToggleSet + set BATTLE_SHIFT, [hl] + ld de, .Set + +.Display + hlcoord 11, 7 + call PlaceString + and a + ret +; e43d1 + +.Shift + db "SHIFT@" +.Set + db "SET @" +; e43dd + + +Options_Sound: ; e43dd + ld hl, Options + ld a, [hJoyPressed] + bit D_LEFT_F, a + jr nz, .LeftPressed + bit D_RIGHT_F, a + jr z, .NonePressed + bit STEREO, [hl] + jr nz, .SetMono + jr .SetStereo + +.LeftPressed + bit STEREO, [hl] + jr z, .SetStereo + jr .SetMono + +.NonePressed + bit STEREO, [hl] + jr nz, .ToggleStereo + jr .ToggleMono + +.SetMono + res STEREO, [hl] + call RestartMapMusic + +.ToggleMono + ld de, .Mono + jr .Display + +.SetStereo + set STEREO, [hl] + call RestartMapMusic + +.ToggleStereo + ld de, .Stereo + +.Display + hlcoord 11, 9 + call PlaceString + and a + ret +; e4416 + +.Mono + db "MONO @" +.Stereo + db "STEREO@" +; e4424 + + +Options_Print: ; e4424 + call GetPrinterSetting + ld a, [hJoyPressed] + bit D_LEFT_F, a + jr nz, .LeftPressed + bit D_RIGHT_F, a + jr z, .NonePressed + ld a, c + cp 4 + jr c, .Increase + ld c, -1 + +.Increase + inc c + ld a, e + jr .Save + +.LeftPressed + ld a, c + and a + jr nz, .Decrease + ld c, 5 + +.Decrease + dec c + ld a, d + +.Save + ld b, a + ld [GBPrinter], a + +.NonePressed + ld b, $0 + ld hl, .Strings +rept 2 + add hl, bc +endr + ld e, [hl] + inc hl + ld d, [hl] + hlcoord 11, 11 + call PlaceString + and a + ret +; e445a + +.Strings + dw .Lightest + dw .Lighter + dw .Normal + dw .Darker + dw .Darkest + +.Lightest + db "LIGHTEST@" +.Lighter + db "LIGHTER @" +.Normal + db "NORMAL @" +.Darker + db "DARKER @" +.Darkest + db "DARKEST @" +; e4491 + + +GetPrinterSetting: ; e4491 + ld a, [GBPrinter] ; converts from the stored printer setting to 0,1,2,3,4 + and a + jr z, .IsLightest + cp PRINT_LIGHTER + jr z, .IsLight + cp PRINT_DARKER + jr z, .IsDark + cp PRINT_DARKEST + jr z, .IsDarkest + ld c, 2 ; normal if none of the above + lb de, PRINT_LIGHTER, PRINT_DARKER ; the 2 values next to this setting + ret + +.IsLightest + ld c, 0 + lb de, PRINT_DARKEST, PRINT_LIGHTER ; the 2 values next to this setting + ret + +.IsLight + ld c, 1 + lb de, PRINT_LIGHTEST, PRINT_NORMAL ; the 2 values next to this setting + ret + +.IsDark + ld c, 3 + lb de, PRINT_NORMAL, PRINT_DARKEST ; the 2 values next to this setting + ret + +.IsDarkest + ld c, 4 + lb de, PRINT_DARKER, PRINT_LIGHTEST ; the 2 values next to this setting + ret +; e44c1 + +Options_MenuAccount: ; e44c1 + ld hl, Options2 + ld a, [hJoyPressed] + bit D_LEFT_F, a + jr nz, .LeftPressed + bit D_RIGHT_F, a + jr z, .NonePressed + bit MENU_ACCOUNT, [hl] + jr nz, .ToggleOff + jr .ToggleOn + +.LeftPressed + bit MENU_ACCOUNT, [hl] + jr z, .ToggleOn + jr .ToggleOff + +.NonePressed + bit MENU_ACCOUNT, [hl] + jr nz, .ToggleOn + +.ToggleOff + res MENU_ACCOUNT, [hl] + ld de, .Off + jr .Display + +.ToggleOn + set MENU_ACCOUNT, [hl] + ld de, .On + +.Display + hlcoord 11, 13 + call PlaceString + and a + ret +; e44f2 + +.Off + db "OFF@" +.On + db "ON @" +; e44fa + + +Options_Frame: ; e44fa + ld hl, TextBoxFrame + ld a, [hJoyPressed] + bit D_LEFT_F, a + jr nz, .LeftPressed + bit D_RIGHT_F, a + jr nz, .RightPressed + and a + ret + +.RightPressed + ld a, [hl] + inc a + jr .Save + +.LeftPressed + ld a, [hl] + dec a + +.Save + and $7 + ld [hl], a +UpdateFrame: ; e4512 + ld a, [TextBoxFrame] + hlcoord 16, 15 ; where on the screen the number is drawn + add "1" + ld [hl], a + call LoadFontsExtra + and a + ret +; e4520 + +Options_Cancel: ; e4520 + ld a, [hJoyPressed] + and A_BUTTON + jr nz, .Exit + and a + ret + +.Exit + scf + ret +; e452a + +OptionsControl: ; e452a + ld hl, wJumptableIndex + ld a, [hJoyLast] + cp D_DOWN + jr z, .DownPressed + cp D_UP + jr z, .UpPressed + and a + ret + +.DownPressed + ld a, [hl] ; load the cursor position to a + cp $7 ; maximum number of items in option menu + jr nz, .CheckFive + ld [hl], $0 + scf + ret + +.CheckFive ; I have no idea why this exists... + cp $5 + jr nz, .Increase + ld [hl], $5 + +.Increase + inc [hl] + scf + ret + +.UpPressed + ld a, [hl] + cp $6 + jr nz, .NotSix + ld [hl], $5 ; Another thing where I'm not sure why it exists + scf + ret + +.NotSix + and a + jr nz, .Decrease + ld [hl], $8 ; number of option items +1 + +.Decrease + dec [hl] + scf + ret +; e455c diff --git a/engine/radio2.asm b/engine/radio2.asm index 1d07c904c..e9ffedd7c 100644 --- a/engine/radio2.asm +++ b/engine/radio2.asm @@ -402,3 +402,263 @@ PlacesAndPeopleName: db "Places & People@" LetsAllSingName: db "Let's All Sing!@" PokeFluteStationName: db "# FLUTE@" ; 9191c + + +Function9191c: ; 9191c + ld hl, Options + ld a, [hl] + push af + set 4, [hl] + ld a, [hInMenu] + push af + ld a, $1 + ld [hInMenu], a + ld a, [VramState] + push af + xor a + ld [VramState], a + call ClearBGPalettes + call ClearTileMap + call ClearSprites + call DisableLCD + call Function90c4e + callba Function8cf53 + ld a, 8 + call SkipMusic + ld a, $e3 + ld [rLCDC], a + call Function90d56 + ld [wd002], a + ld [wd003], a + xor a + ld [hBGMapMode], a + call Function91a04 + call Function3200 + ld a, [wd002] + call Function9106a + ld a, [wd003] + call Function91098 + ld a, c + ld [wd004], a + ld a, b + ld [wd005], a + ld b, SCGB_02 + call GetSGBLayout + call SetPalettes + ld a, [hCGB] + and a + jr z, .asm_9198b + ld a, $e4 + call Functioncf8 + call DelayFrame + +.asm_9198b + ld a, [wd002] + cp KANTO_LANDMARK + jr nc, .asm_9199b + ld d, KANTO_LANDMARK - 1 + ld e, 1 + call Function919b0 + jr .asm_919a1 + +.asm_9199b + call Function910e8 + call Function919b0 + +.asm_919a1 + pop af + ld [VramState], a + pop af + ld [hInMenu], a + pop af + ld [Options], a + call ClearBGPalettes + ret +; 919b0 + +Function919b0: ; 919b0 +.asm_919b0 + call JoyTextDelay + ld hl, hJoyPressed + ld a, [hl] + and B_BUTTON + ret nz + ld hl, hJoyLast + ld a, [hl] + and D_UP + jr nz, .asm_919d4 + ld a, [hl] + and D_DOWN + jr nz, .asm_919e1 +.asm_919c7 + push de + callba Function8cf69 + pop de + call DelayFrame + jr .asm_919b0 + +.asm_919d4 + ld hl, wd003 + ld a, [hl] + cp d + jr c, .asm_919de + ld a, e + dec a + ld [hl], a + +.asm_919de + inc [hl] + jr .asm_919ec + +.asm_919e1 + ld hl, wd003 + ld a, [hl] + cp e + jr nz, .asm_919eb + ld a, d + inc a + ld [hl], a + +.asm_919eb + dec [hl] + +.asm_919ec + push de + ld a, [wd003] + call Function910b4 + ld a, [wd004] + ld c, a + ld a, [wd005] + ld b, a + ld a, [wd003] + call Function910d4 + pop de + jr .asm_919c7 +; 91a04 + +Function91a04: ; 91a04 + ld a, [wd002] + cp KANTO_LANDMARK + jr nc, .asm_91a0f + ld e, $0 + jr .asm_91a11 + +.asm_91a0f + ld e, $1 + +.asm_91a11 + callba Function91ae1 + ld a, $7 + ld bc, 6 + hlcoord 1, 0 + call ByteFill + hlcoord 0, 0 + ld [hl], $6 + hlcoord 7, 0 + ld [hl], $17 + hlcoord 7, 1 + ld [hl], $16 + hlcoord 7, 2 + ld [hl], $26 + ld a, $7 + ld bc, NAME_LENGTH + hlcoord 8, 2 + call ByteFill + hlcoord 19, 2 + ld [hl], $17 + ld a, [wd003] + call Function910b4 + callba TownMapPals + ret +; 91a53 + +PlayRadio: ; 91a53 + ld hl, Options + ld a, [hl] + push af + set 4, [hl] + call .PlayStation + ld c, 100 + call DelayFrames +.loop + call JoyTextDelay + ld a, [hJoyPressed] + and A_BUTTON | B_BUTTON + jr nz, .stop + ld a, [wc6da] + ld l, a + ld a, [wc6db] + ld h, a + ld a, [wc6d9] + and a + jr z, .zero + rst FarCall + +.zero + call DelayFrame + jr .loop + +.stop + pop af + ld [Options], a + call Function91492 + ret +; 91a87 + +.PlayStation: ; 91a87 + ld a, -1 + ld [EnemyTurnsTaken], a + ld hl, .StationPointers + ld d, $0 +rept 2 + add hl, de +endr + ld a, [hli] + ld h, [hl] + ld l, a + ld de, .jump_return + push de + jp [hl] + +.jump_return + push de + hlcoord 0, 12 + lb bc, 4, 18 + call TextBox + hlcoord 1, 14 + ld [hl], $72 + pop de + hlcoord 2, 14 + call PlaceString + ld h, b + ld l, c + ld [hl], $73 + call WaitBGMap + ret +; 91ab9 + +.StationPointers: ; 91ab9 + dw .OakOrPnP + dw LoadStation_OaksPokemonTalk + dw LoadStation_PokedexShow + dw LoadStation_PokemonMusic + dw LoadStation_LuckyChannel + dw LoadStation_UnownRadio + dw LoadStation_PlacesAndPeople + dw LoadStation_LetsAllSing + dw LoadStation_RocketRadio +; 91acb + +.OakOrPnP: ; 91acb + call IsInJohto + and a + jr nz, .kanto + call UpdateTime + ld a, [TimeOfDay] + and a + jp z, LoadStation_PokedexShow + jp LoadStation_OaksPokemonTalk + +.kanto + jp LoadStation_PlacesAndPeople +; 91ae1 diff --git a/engine/specials.asm b/engine/specials.asm index 21d391faa..825cf3870 100644 --- a/engine/specials.asm +++ b/engine/specials.asm @@ -160,7 +160,7 @@ SpecialsPointers:: ; c029 add_special Function17d2b6 add_special Function17d2ce add_special Function17f53d - add_special Function103612 + add_special AskMobileOrCable add_special SpecialHoOhChamber add_special Function102142 add_special Special_CelebiShrineEvent @@ -180,7 +180,7 @@ SpecialsPointers:: ; c029 add_special Mobile_HealParty add_special RefreshSprites add_special Function1037c2 - add_special Function10630f + add_special Mobile_DummyReturnFalse add_special Function103780 add_special Function10387b add_special Function4ae12 diff --git a/engine/town_map.asm b/engine/town_map.asm new file mode 100755 index 000000000..bc24af23b --- /dev/null +++ b/engine/town_map.asm @@ -0,0 +1,1068 @@ +Function91ae1: ; 91ae1 + ld a, e + and a + jr nz, .kanto + call Function91ff2 + call FillJohtoMap + ret + +.kanto + call Function91ff2 + call FillKantoMap + ret +; 91af3 + +_FlyMap: ; 91af3 + call ClearBGPalettes + call ClearTileMap + call ClearSprites + ld hl, hInMenu + ld a, [hl] + push af + ld [hl], $1 + xor a + ld [hBGMapMode], a + callba Function8cf53 + call Function91ff2 + ld de, GFX_922e1 + ld hl, VTiles2 tile $30 + lb bc, BANK(GFX_922e1), 6 + call Request1bpp + call FlyMap + call Function91c8f + ld b, $2 + call GetSGBLayout + call SetPalettes +.loop + call JoyTextDelay + ld hl, hJoyPressed + ld a, [hl] + and B_BUTTON + jr nz, .pressedB + ld a, [hl] + and A_BUTTON + jr nz, .pressedA + call FlyMapScroll + call GetMapCursorCoordinates + callba Function8cf69 + call DelayFrame + jr .loop + +.pressedB + ld a, -1 + jr .exit + +.pressedA + ld a, [wd002] + ld l, a + ld h, 0 + add hl, hl + ld de, Flypoints + 1 + add hl, de + ld a, [hl] + +.exit + ld [wd002], a + pop af + ld [hInMenu], a + call ClearBGPalettes + ld a, $90 + ld [hWY], a + xor a + ld [hBGMapAddress], a + ld a, VBGMap0 / $100 + ld [hBGMapAddress + 1], a + ld a, [wd002] + ld e, a + ret +; 91b73 + +FlyMapScroll: ; 91b73 + ld a, [StartFlypoint] + ld e, a + ld a, [EndFlypoint] + ld d, a + ld hl, hJoyLast + ld a, [hl] + and D_UP + jr nz, .ScrollNext + ld a, [hl] + and D_DOWN + jr nz, .ScrollPrev + ret + +.ScrollNext + ld hl, wd002 + ld a, [hl] + cp d + jr nz, .NotAtEndYet + ld a, e + dec a + ld [hl], a + +.NotAtEndYet + inc [hl] + call CheckIfVisitedFlypoint + jr z, .ScrollNext + jr .Finally + +.ScrollPrev + ld hl, wd002 + ld a, [hl] + cp e + jr nz, .NotAtStartYet + ld a, d + inc a + ld [hl], a + +.NotAtStartYet + dec [hl] + call CheckIfVisitedFlypoint + jr z, .ScrollPrev + +.Finally + call TownMapBubble + call WaitBGMap + xor a + ld [hBGMapMode], a + ret +; 91bb5 + +TownMapBubble: ; 91bb5 +; Draw the bubble containing the location text in the town map HUD + +; Top-left corner + hlcoord 1, 0 + ld a, $30 + ld [hli], a + +; Top row + ld bc, 16 + ld a, " " + call ByteFill + +; Top-right corner + ld a, $31 + ld [hl], a + hlcoord 1, 1 + + +; Middle row + ld bc, 18 + ld a, " " + call ByteFill + + +; Bottom-left corner + hlcoord 1, 2 + ld a, $32 + ld [hli], a + +; Bottom row + ld bc, 16 + ld a, " " + call ByteFill + +; Bottom-right corner + ld a, $33 + ld [hl], a + + +; Print "Where?" + hlcoord 2, 0 + ld de, .Where + call PlaceString + +; Print the name of the default flypoint + call .Name + +; Up/down arrows + hlcoord 18, 1 + ld [hl], $34 + ret + +.Where + db "Where?@" + +.Name +; We need the map location of the default flypoint + ld a, [wd002] + ld l, a + ld h, 0 + add hl, hl ; two bytes per flypoint + ld de, Flypoints + add hl, de + ld e, [hl] + + callba GetLandmarkName + + hlcoord 2, 1 + ld de, StringBuffer1 + call PlaceString + ret +; 91c17 + +GetMapCursorCoordinates: ; 91c17 + ld a, [wd002] + ld l, a + ld h, $0 + add hl, hl + ld de, Flypoints + add hl, de + ld e, [hl] + callba GetLandmarkCoords + ld a, [wd003] + ld c, a + ld a, [wd004] + ld b, a + ld hl, $4 + add hl, bc + ld [hl], e + ld hl, $5 + add hl, bc + ld [hl], d + ret +; 91c3c + +CheckIfVisitedFlypoint: ; 91c3c +; Check if the flypoint loaded in [hl] has been visited yet. + push bc + push de + push hl + ld l, [hl] + ld h, 0 + add hl, hl + ld de, Flypoints + 1 + add hl, de + ld c, [hl] + call HasVisitedSpawn + pop hl + pop de + pop bc + and a + ret +; 91c50 + +HasVisitedSpawn: ; 91c50 +; Check if spawn point c has been visited. + ld hl, VisitedSpawns + ld b, CHECK_FLAG + ld d, 0 + predef FlagPredef + ld a, c + ret +; 91c5e + +Flypoints: ; 91c5e +; landmark, spawn point + + const_def + +flypoint: MACRO +; \1\@FLY EQUS "FLY_\1" +; \1\@SPAWN EQUS "SPAWN_\1" + ; const \1\@FLY + ; db \2, \1\@SPAWN + const FLY_\1 + db \2, SPAWN_\1 +ENDM + +; Johto + flypoint NEW_BARK, NEW_BARK_TOWN + flypoint CHERRYGROVE, CHERRYGROVE_CITY + flypoint VIOLET, VIOLET_CITY + flypoint AZALEA, AZALEA_TOWN + flypoint GOLDENROD, GOLDENROD_CITY + flypoint ECRUTEAK, ECRUTEAK_CITY + flypoint OLIVINE, OLIVINE_CITY + flypoint CIANWOOD, CIANWOOD_CITY + flypoint MAHOGANY, MAHOGANY_TOWN + flypoint LAKE, LAKE_OF_RAGE + flypoint BLACKTHORN, BLACKTHORN_CITY + flypoint MT_SILVER, SILVER_CAVE + +; Kanto +KANTO_FLYPOINT EQU const_value + + flypoint PALLET, PALLET_TOWN + flypoint VIRIDIAN, VIRIDIAN_CITY + flypoint PEWTER, PEWTER_CITY + flypoint CERULEAN, CERULEAN_CITY + flypoint VERMILION, VERMILION_CITY + flypoint ROCK_TUNNEL, ROCK_TUNNEL + flypoint LAVENDER, LAVENDER_TOWN + flypoint CELADON, CELADON_CITY + flypoint SAFFRON, SAFFRON_CITY + flypoint FUCHSIA, FUCHSIA_CITY + flypoint CINNABAR, CINNABAR_ISLAND + flypoint INDIGO, INDIGO_PLATEAU + + db -1 +; 91c8f + +Function91c8f: ; 91c8f + ret +; 91c90 + +FlyMap: ; 91c90 + + ld a, [MapGroup] + ld b, a + ld a, [MapNumber] + ld c, a + call GetWorldMapLocation + +; If we're not in a valid location, i.e. Pokecenter floor 2F, +; the backup map information is used + + cp SPECIAL_MAP + jr nz, .CheckRegion + + ld a, [BackupMapGroup] + ld b, a + ld a, [BackupMapNumber] + ld c, a + call GetWorldMapLocation + +.CheckRegion +; The first 46 locations are part of Johto. The rest are in Kanto + cp KANTO_LANDMARK + jr nc, .KantoFlyMap + +.JohtoFlyMap +; Note that .NoKanto should be modified in tandem with this branch + + push af + +; Start from New Bark Town + ld a, FLY_NEW_BARK + ld [wd002], a + +; Flypoints begin at New Bark Town... + ld [StartFlypoint], a +; ..and end at Silver Cave + ld a, FLY_MT_SILVER + ld [EndFlypoint], a + +; Fill out the map + call FillJohtoMap + call .MapHud + pop af + call TownMapPlayerIcon + ret + +.KantoFlyMap + +; The event that there are no flypoints enabled in a map is not +; accounted for. As a result, if you attempt to select a flypoint +; when there are none enabled, the game will crash. Additionally, +; the flypoint selection has a default starting point that +; can be flown to even if none are enabled + +; To prevent both of these things from happening when the player +; enters Kanto, fly access is restricted until Indigo Plateau is +; visited and its flypoint enabled + + push af + ld c, SPAWN_INDIGO + call HasVisitedSpawn + and a + jr z, .NoKanto + +; Kanto's map is only loaded if we've visited Indigo Plateau + +; Flypoints begin at Pallet Town... + ld a, FLY_PALLET + ld [StartFlypoint], a +; ...and end at Indigo Plateau + ld a, FLY_INDIGO + ld [EndFlypoint], a + +; Because Indigo Plateau is the first flypoint the player +; visits, it's made the default flypoint + ld [wd002], a + +; Fill out the map + call FillKantoMap + call .MapHud + pop af + call TownMapPlayerIcon + ret + +.NoKanto +; If Indigo Plateau hasn't been visited, we use Johto's map instead + +; Start from New Bark Town + ld a, FLY_NEW_BARK + ld [wd002], a + +; Flypoints begin at New Bark Town... + ld [StartFlypoint], a +; ..and end at Silver Cave + ld a, FLY_MT_SILVER + ld [EndFlypoint], a + + call FillJohtoMap + + pop af + +.MapHud + call TownMapBubble + call TownMapPals + + ld hl, VBGMap0 ; BG Map 0 + call TownMapBGUpdate + + call TownMapMon + ld a, c + ld [wd003], a + ld a, b + ld [wd004], a + ret +; 91d11 + +Function91d11: ; 91d11 + ld a, [wd002] + push af + ld a, [wd003] + push af + ld a, e + ld [wd002], a + call ClearSprites + xor a + ld [hBGMapMode], a + ld a, $1 + ld [hInMenu], a + + ld de, GFX_922d1 + ld hl, VTiles0 tile $7f + lb bc, BANK(GFX_922d1), 1 + call Request2bpp ; actually 1bpp + + call Function91ed0 + + ld hl, VTiles0 tile $78 + ld c, $4 + call Request2bpp + + call Function91ff2 + call FillKantoMap + call Function91de9 + call TownMapPals + ld hl, VBGMap1 + call TownMapBGUpdate + call FillJohtoMap + call Function91de9 + call TownMapPals + ld hl, VBGMap0 + call TownMapBGUpdate + ld b, $2 + call GetSGBLayout + call SetPalettes + xor a + ld [hBGMapMode], a + xor a + call Function91e1e +.loop + call JoyTextDelay + ld hl, hJoyPressed + ld a, [hl] + and A_BUTTON | B_BUTTON + jr nz, .a_b + ld a, [hJoypadDown] + and SELECT + jr nz, .select + call Function91d9b + call Function91dcd + jr .next + +.select + call Function91e5a + +.next + call DelayFrame + jr .loop + +.a_b + call ClearSprites + pop af + ld [wd003], a + pop af + ld [wd002], a + ret +; 91d9b + +Function91d9b: ; 91d9b + ld a, [hl] + and $20 + jr nz, .asm_91da6 + ld a, [hl] + and $10 + jr nz, .asm_91db7 + ret + +.asm_91da6 + ld a, [hWY] + cp $90 + ret z + call ClearSprites + ld a, $90 + ld [hWY], a + xor a + call Function91e1e + ret + +.asm_91db7 + ld a, [StatusFlags] + bit 6, a ; hall of fame + ret z + ld a, [hWY] + and a + ret z + call ClearSprites + xor a + ld [hWY], a + ld a, $1 + call Function91e1e + ret +; 91dcd + +Function91dcd: ; 91dcd + ld a, [hVBlankCounter] + ld e, a + and $f + ret nz + ld a, e + and $10 + jr nz, .asm_91ddc + call ClearSprites + ret + +.asm_91ddc + hlcoord 0, 0 + ld de, Sprites + ld bc, $a0 + call CopyBytes + ret +; 91de9 + +Function91de9: ; 91de9 + hlcoord 0, 0 + ld bc, SCREEN_WIDTH + ld a, $7f + call ByteFill + hlcoord 0, 1 + ld a, $6 + ld [hli], a + ld bc, SCREEN_HEIGHT + ld a, $7 + call ByteFill + ld [hl], $17 + call GetPokemonName + hlcoord 2, 0 + call PlaceString + ld h, b + ld l, c + ld de, String_91e16 + call PlaceString + ret +; 91e16 + +String_91e16: + db "'S NEST@" +; 91e1e + +Function91e1e: ; 91e1e + ld [wd003], a + ld e, a + callba Function2a01f + decoord 0, 0 + ld hl, Sprites +.asm_91e2e + ld a, [de] + and a + jr z, .asm_91e4d + push de + ld e, a + push hl + callba GetLandmarkCoords + pop hl + ld a, d + sub $4 + ld [hli], a + ld a, e + sub $4 + ld [hli], a + ld a, $7f + ld [hli], a + xor a + ld [hli], a + pop de + inc de + jr .asm_91e2e + +.asm_91e4d + ld hl, Sprites + decoord 0, 0 + ld bc, $a0 + call CopyBytes + ret +; 91e5a + +Function91e5a: ; 91e5a + call Function91ea9 + ret c + + ld a, [wd002] + ld e, a + callba GetLandmarkCoords + ld c, e + ld b, d + ld de, Unknown_91e9c + ld hl, Sprites +.asm_91e70 + ld a, [de] + cp $80 + jr z, .asm_91e91 + + add b + ld [hli], a + inc de + + ld a, [de] + add c + ld [hli], a + inc de + + ld a, [de] + add $78 + ld [hli], a + inc de + + push bc + ld c, 0 + ld a, [PlayerGender] + bit 0, a + jr z, .asm_91e8c + inc c +.asm_91e8c + ld a, c + ld [hli], a + pop bc + + jr .asm_91e70 + +.asm_91e91 + ld hl, Sprites + $10 + ld bc, SpritesEnd - (Sprites + $10) + xor a + call ByteFill + ret +; 91e9c + +Unknown_91e9c: ; 91e9c + db -8, -8, 0 + db -8, 0, 1 + db 0, -8, 2 + db 0, 0, 3 + db $80 ; terminator +; 91ea9 + +Function91ea9: ; 91ea9 + ld a, [wd002] + cp FAST_SHIP + jr z, .johto + cp KANTO_LANDMARK + jr c, .johto + +.kanto + ld a, [wd003] + and a + jr z, .clear + jr .ok + +.johto + ld a, [wd003] + and a + jr nz, .clear + +.ok + and a + ret + +.clear + ld hl, Sprites + ld bc, SpritesEnd - Sprites + xor a + call ByteFill + scf + ret +; 91ed0 + +Function91ed0: ; 91ed0 + ld a, [wd002] + cp FAST_SHIP + jr z, .asm_91ede + callba GetPlayerIcon + ret + +.asm_91ede + ld de, FastShipGFX + ld b, BANK(FastShipGFX) + ret +; 91ee4 + +TownMapBGUpdate: ; 91ee4 +; Update BG Map tiles and attributes + +; BG Map address + ld a, l + ld [hBGMapAddress], a + ld a, h + ld [hBGMapAddress + 1], a + +; Only update palettes on CGB + ld a, [hCGB] + and a + jr z, .tiles + +; BG Map mode 2 (palettes) + ld a, 2 + ld [hBGMapMode], a + +; The BG Map is updated in thirds, so we wait +; 3 frames to update the whole screen's palettes. + ld c, 3 + call DelayFrames + +.tiles +; Update BG Map tiles + call WaitBGMap + +; Turn off BG Map update + xor a + ld [hBGMapMode], a + ret +; 91eff + +FillJohtoMap: ; 91eff + ld de, JohtoMap + jr FillTownMap + +FillKantoMap: ; 91f04 + ld de, KantoMap + +FillTownMap: ; 91f07 + hlcoord 0, 0 +.loop + ld a, [de] + cp $ff + ret z + ld a, [de] + ld [hli], a + inc de + jr .loop +; 91f13 + +TownMapPals: ; 91f13 +; Assign palettes based on tile ids + + hlcoord 0, 0 + decoord 0, 0, AttrMap + ld bc, 360 +.loop +; Current tile + ld a, [hli] + push hl + +; HP/borders use palette 0 + cp $60 + jr nc, .pal0 + +; The palette data is condensed to nybbles, +; least-significant first. + ld hl, TownMapPalMap + srl a + jr c, .odd + +; Even-numbered tile ids take the bottom nybble... + add l + ld l, a + ld a, h + adc 0 + ld h, a + ld a, [hl] + and %111 + jr .update + +.odd +; ...and odd ids take the top. + add l + ld l, a + ld a, h + adc 0 + ld h, a + ld a, [hl] + swap a + and %111 + jr .update + +.pal0 + xor a + +.update + pop hl + ld [de], a + inc de + dec bc + ld a, b + or c + jr nz, .loop + ret + +TownMapPalMap: + db $11, $21, $22, $00, $11, $13, $54, $54, $11, $21, $22, $00 + db $11, $10, $01, $00, $11, $21, $22, $00, $00, $00, $00, $00 + db $00, $00, $44, $04, $00, $00, $00, $00, $33, $33, $33, $33 + db $33, $33, $33, $03, $33, $33, $33, $33, $00, $00, $00, $00 +; 91f7b + +TownMapMon: ; 91f7b +; Draw the FlyMon icon at town map location in + +; Get FlyMon species + ld a, [CurPartyMon] + ld hl, PartySpecies + ld e, a + ld d, $0 + add hl, de + ld a, [hl] + ld [wd265], a + +; Get FlyMon icon + ld e, 8 ; starting tile in VRAM + callba GetSpeciesIcon + +; Animation/palette + ld de, 0 + ld a, $0 + call _InitSpriteAnimStruct + + ld hl, 3 + add hl, bc + ld [hl], 8 + ld hl, 2 + add hl, bc + ld [hl], 0 + ret +; 91fa6 + +TownMapPlayerIcon: ; 91fa6 +; Draw the player icon at town map location in a + push af + + callba GetPlayerIcon + +; Standing icon + ld hl, VTiles0 tile $10 + ld c, 4 ; # tiles + call Request2bpp + +; Walking icon + ld hl, $c0 + add hl, de + ld d, h + ld e, l + ld hl, VTiles0 tile $14 + ld c, 4 ; # tiles + ld a, BANK(ChrisSpriteGFX) ; does nothing + call Request2bpp + +; Animation/palette + ld de, 0 + ld b, $0a ; Male + ld a, [PlayerGender] + bit 0, a + jr z, .asm_91fd3 + ld b, $1e ; Female +.asm_91fd3 + ld a, b + call _InitSpriteAnimStruct + + ld hl, $3 + add hl, bc + ld [hl], $10 + + pop af + ld e, a + push bc + callba GetLandmarkCoords + pop bc + + ld hl, 4 + add hl, bc + ld [hl], e + ld hl, 5 + add hl, bc + ld [hl], d + ret +; 0x91ff2 + +Function91ff2: ; 91ff2 + ld hl, TownMapGFX + ld de, VTiles2 + lb bc, BANK(TownMapGFX), $30 + call DecompressRequest2bpp + ret +; 91fff + + +JohtoMap: ; 91fff +INCBIN "gfx/misc/johto.bin" +; 92168 + +KantoMap: ; 92168 +INCBIN "gfx/misc/kanto.bin" +; 922d1 + + +GFX_922d1: ; 922d1 +INCBIN "gfx/unknown/0922d1.2bpp" +GFX_922e1: ; 922e1 +INCBIN "gfx/unknown/0922e1.2bpp" +GFX_92301: ; 92301 +INCBIN "gfx/unknown/092301.2bpp" +Function92311: ; unreferenced + xor a + ld [wd002], a + call ClearBGPalettes + call ClearTileMap + call ClearSprites + ld hl, hInMenu + ld a, [hl] + push af + ld [hl], $1 + xor a + ld [hBGMapMode], a + callba Function8cf53 + call Function91ff2 + ld de, GFX_922e1 + ld hl, VTiles2 tile $30 + lb bc, BANK(GFX_922e1), 6 + call Request1bpp + call FillKantoMap + call TownMapBubble + call TownMapPals + ld hl, VBGMap1 + call TownMapBGUpdate + call FillJohtoMap + call TownMapBubble + call TownMapPals + ld hl, VBGMap0 + call TownMapBGUpdate + call TownMapMon + ld a, c + ld [wd003], a + ld a, b + ld [wd004], a + ld b, SCGB_02 + call GetSGBLayout + call SetPalettes +.loop + call JoyTextDelay + ld hl, hJoyPressed + ld a, [hl] + and B_BUTTON + jr nz, .pressedB + ld a, [hl] + and A_BUTTON + jr nz, .pressedA + call Function923b8 + call GetMapCursorCoordinates + callba Function8cf69 + call DelayFrame + jr .loop + +.pressedB + ld a, -1 + jr .asm_9239f + +.pressedA + ld a, [wd002] + ld l, a + ld h, 0 + add hl, hl + ld de, Flypoints + 1 + add hl, de + ld a, [hl] + +.asm_9239f + ld [wd002], a + pop af + ld [hInMenu], a + call ClearBGPalettes + ld a, $90 + ld [hWY], a + xor a + ld [hBGMapAddress], a + ld a, VBGMap0 / $100 + ld [hBGMapAddress + 1], a + ld a, [wd002] + ld e, a + ret +; 923b8 + +Function923b8: ; 923b8 + ld hl, hJoyLast + ld a, [hl] + and D_DOWN | D_RIGHT + jr nz, .asm_923c6 + ld a, [hl] + and D_UP | D_LEFT + jr nz, .asm_923d3 + ret + +.asm_923c6 + ld hl, wd002 + ld a, [hl] + cp FLY_INDIGO + jr c, .asm_923d0 + ld [hl], -1 +.asm_923d0 + inc [hl] + jr .asm_923dd + +.asm_923d3 + ld hl, wd002 + ld a, [hl] + and a + jr nz, .asm_923dc + ld [hl], FLY_INDIGO + 1 +.asm_923dc + dec [hl] + +.asm_923dd + ld a, [wd002] + cp KANTO_FLYPOINT + jr c, .johto + + call FillKantoMap + xor a + ld b, $9c + jr .asm_923f3 + +.johto + call FillJohtoMap + ld a, $90 + ld b, $98 + +.asm_923f3 + ld [hWY], a + ld a, b + ld [hBGMapAddress + 1], a + call TownMapBubble + call WaitBGMap + xor a + ld [hBGMapMode], a + ret +; 92402 diff --git a/engine/wildmons.asm b/engine/wildmons.asm new file mode 100755 index 000000000..6f39e19dc --- /dev/null +++ b/engine/wildmons.asm @@ -0,0 +1,1057 @@ +LoadWildMonData: ; 29ff8 + call _GrassWildmonLookup + jr c, .copy + ld hl, wd25a + xor a + ld [hli], a + ld [hli], a + ld [hl], a + jr .done_copy +.copy + inc hl + inc hl + ld de, wd25a + ld bc, $3 + call CopyBytes +.done_copy + call _WaterWildmonLookup + ld a, $0 + jr nc, .no_copy + inc hl + inc hl + ld a, [hl] +.no_copy + ld [wd25d], a + ret + +Function2a01f: ; 2a01f + hlcoord 0, 0 + ld bc, SCREEN_WIDTH * SCREEN_HEIGHT + xor a + call ByteFill + ld a, e + and a + jr nz, .kanto + decoord 0, 0 + ld hl, JohtoGrassWildMons + call Function2a052 + ld hl, JohtoWaterWildMons + call Function2a06e + call Function2a0b7 + call Function2a0cf + ret + +.kanto + decoord 0, 0 + ld hl, KantoGrassWildMons + call Function2a052 + ld hl, KantoWaterWildMons + jp Function2a06e +; 2a052 + +Function2a052: ; 2a052 +.loop + ld a, [hl] + cp $ff + ret z + push hl + ld a, [hli] + ld b, a + ld a, [hli] + ld c, a +rept 3 + inc hl +endr + ld a, $15 + call Function2a088 + jr nc, .next + ld [de], a + inc de + +.next + pop hl + ld bc, $2f + add hl, bc + jr .loop +; 2a06e + +Function2a06e: ; 2a06e +.loop + ld a, [hl] + cp $ff + ret z + push hl + ld a, [hli] + ld b, a + ld a, [hli] + ld c, a + inc hl + ld a, $3 + call Function2a088 + jr nc, .next + ld [de], a + inc de + +.next + pop hl + ld bc, 9 + add hl, bc + jr .loop +; 2a088 + +Function2a088: ; 2a088 + inc hl +.loop + push af + ld a, [wd265] + cp [hl] + jr z, .found +rept 2 + inc hl +endr + pop af + dec a + jr nz, .loop + and a + ret + +.found + pop af + jp Function2a09c +; 2a09c + +Function2a09c: ; 2a09c + push de + call GetWorldMapLocation + ld c, a + hlcoord 0, 0 + ld de, SCREEN_WIDTH * SCREEN_HEIGHT +.loop + ld a, [hli] + cp c + jr z, .found + dec de + ld a, e + or d + jr nz, .loop + ld a, c + pop de + scf + ret + +.found + pop de + and a + ret +; 2a0b7 + +Function2a0b7: ; 2a0b7 + ld a, [wRoamMon1Species] + ld b, a + ld a, [wd265] + cp b + ret nz + ld a, [wRoamMon1MapGroup] + ld b, a + ld a, [wRoamMon1MapNumber] + ld c, a + call Function2a09c + ret nc + ld [de], a + inc de + ret +; 2a0cf + +Function2a0cf: ; 2a0cf + ld a, [wRoamMon2Species] + ld b, a + ld a, [wd265] + cp b + ret nz + ld a, [wRoamMon2MapGroup] + ld b, a + ld a, [wRoamMon2MapNumber] + ld c, a + call Function2a09c + ret nc + ld [de], a + inc de + ret +; 2a0e7 + +TryWildEncounter:: ; 2a0e7 +; Try to trigger a wild encounter. + call .EncounterRate + jr nc, .no_battle + call ChooseWildEncounter + jr nz, .no_battle + call CheckRepelEffect + jr nc, .no_battle + xor a + ret + +.no_battle + xor a ; BATTLETYPE_NORMAL + ld [TempWildMonSpecies], a + ld [BattleType], a + ld a, 1 + and a + ret +; 2a103 + +.EncounterRate: ; 2a103 + call GetMapEncounterRate + call ApplyMusicEffectOnEncounterRate + call ApplyCleanseTagEffectOnEncounterRate + call Random + cp b + ret +; 2a111 + +GetMapEncounterRate: ; 2a111 + ld hl, wd25a + call CheckOnWater + ld a, 3 + jr z, .ok + ld a, [TimeOfDay] +.ok + ld c, a + ld b, 0 + add hl, bc + ld b, [hl] + ret +; 2a124 + +ApplyMusicEffectOnEncounterRate:: ; 2a124 +; Pokemon March and Ruins of Alph signal double encounter rate. +; Pokemon Lullaby halves encounter rate. + ld a, [wMapMusic] + cp MUSIC_POKEMON_MARCH + jr z, .double + cp MUSIC_RUINS_OF_ALPH_RADIO + jr z, .double + cp MUSIC_POKEMON_LULLABY + ret nz + srl b + ret + +.double + sla b + ret +; 2a138 + +ApplyCleanseTagEffectOnEncounterRate:: ; 2a138 +; Cleanse Tag halves encounter rate. + ld hl, PartyMon1Item + ld de, PARTYMON_STRUCT_LENGTH + ld a, [PartyCount] + ld c, a +.loop + ld a, [hl] + cp CLEANSE_TAG + jr z, .cleansetag + add hl, de + dec c + jr nz, .loop + ret + +.cleansetag + srl b + ret +; 2a14f + +ChooseWildEncounter: ; 2a14f + call LoadWildMonDataPointer + jp nc, .nowildbattle + call CheckEncounterRoamMon + jp c, .startwildbattle + +rept 3 + inc hl +endr + call CheckOnWater + ld de, .WaterMonTable + jr z, .watermon +rept 2 + inc hl +endr + ld a, [TimeOfDay] + ld bc, $e + call AddNTimes + ld de, .GrassMonTable + +.watermon +; hl contains the pointer to the wild mon data, let's save that to the stack + push hl +.randomloop + call Random + cp 100 + jr nc, .randomloop + inc a ; 1 <= a <= 100 + ld b, a + ld h, d + ld l, e +; This next loop chooses which mon to load up. +.prob_bracket_loop + ld a, [hli] + cp b + jr nc, .got_it + inc hl + jr .prob_bracket_loop + +.got_it + ld c, [hl] + ld b, 0 + pop hl + add hl, bc ; this selects our mon + ld a, [hli] + ld b, a +; If the Pokemon is encountered by surfing, we need to give the levels some variety. + call CheckOnWater + jr nz, .ok +; Check if we buff the wild mon, and by how much. + call Random + cp 35 percent + jr c, .ok + inc b + cp 65 percent + jr c, .ok + inc b + cp 85 percent + jr c, .ok + inc b + cp 95 percent + jr c, .ok + inc b +; Store the level +.ok + ld a, b + ld [CurPartyLevel], a + ld b, [hl] + ; ld a, b + call ValidateTempWildMonSpecies + jr c, .nowildbattle + + ld a, b ; This is in the wrong place. + cp UNOWN + jr nz, .done + + ld a, [UnlockedUnowns] + and a + jr z, .nowildbattle + +.done + jr .loadwildmon + +.nowildbattle + ld a, 1 + and a + ret + +.loadwildmon + ld a, b + ld [TempWildMonSpecies], a + +.startwildbattle + xor a + ret +; 2a1cb + +.GrassMonTable: ; 2a1cb + db 30, $0 ; 30% chance + db 60, $2 ; 30% chance + db 80, $4 ; 20% chance + db 90, $6 ; 10% chance + db 95, $8 ; 5% chance + db 99, $a ; 4% chance + db 100, $c ; 1% chance +; 2a1d9 + +.WaterMonTable: ; 2a1d9 + db 60, $0 ; 60% chance + db 90, $2 ; 30% chance + db 100, $4 ; 10% chance +; 2a1df + +CheckRepelEffect:: ; 2a1df +; If there is no active Repel, there's no need to be here. + ld a, [wRepelEffect] + and a + jr z, .encounter +; Get the first Pokemon in your party that isn't fainted. + ld hl, PartyMon1HP + ld bc, PARTYMON_STRUCT_LENGTH - 1 +.loop + ld a, [hli] + or [hl] + jr nz, .ok + add hl, bc + jr .loop + +.ok +; to PartyMonLevel +rept 4 + dec hl +endr + + ld a, [CurPartyLevel] + cp [hl] + jr nc, .encounter + and a + ret + +.encounter + scf + ret +; 2a200 + +LoadWildMonDataPointer: ; 2a200 + call CheckOnWater + jr z, _WaterWildmonLookup + +_GrassWildmonLookup: ; 2a205 + ld hl, SwarmGrassWildMons + ld bc, GRASS_WILDDATA_LENGTH + call _SwarmWildmonCheck + ret c + ld hl, JohtoGrassWildMons + ld de, KantoGrassWildMons + call _JohtoWildmonCheck + ld bc, GRASS_WILDDATA_LENGTH + jr _NormalWildmonOK + +_WaterWildmonLookup: ; 2a21d + ld hl, SwarmWaterWildMons + ld bc, WATER_WILDDATA_LENGTH + call _SwarmWildmonCheck + ret c + ld hl, JohtoWaterWildMons + ld de, KantoWaterWildMons + call _JohtoWildmonCheck + ld bc, WATER_WILDDATA_LENGTH + jr _NormalWildmonOK + +_JohtoWildmonCheck + call IsInJohto + and a + ret z + ld h, d + ld l, e + ret + +_SwarmWildmonCheck + call CopyCurrMapDE + push hl + ld hl, SwarmFlags + bit 2, [hl] + pop hl + jr z, .CheckYanma + ld a, [wdfcc] + cp d + jr nz, .CheckYanma + ld a, [wdfcd] + cp e + jr nz, .CheckYanma + call LookUpWildmonsForMapDE + jr nc, _NoSwarmWildmon + scf + ret + +.CheckYanma + push hl + ld hl, SwarmFlags + bit 3, [hl] + pop hl + jr z, _NoSwarmWildmon + ld a, [wdc5a] + cp d + jr nz, _NoSwarmWildmon + ld a, [wdc5b] + cp e + jr nz, _NoSwarmWildmon + call LookUpWildmonsForMapDE + jr nc, _NoSwarmWildmon + scf + ret + +_NoSwarmWildmon + and a + ret + +_NormalWildmonOK + call CopyCurrMapDE + jr LookUpWildmonsForMapDE +; 2a27f + +CopyCurrMapDE: ; 2a27f + ld a, [MapGroup] + ld d, a + ld a, [MapNumber] + ld e, a + ret +; 2a288 + +LookUpWildmonsForMapDE: ; 2a288 + push hl + ld a, [hl] + inc a + jr z, .nope + ld a, d + cp [hl] + jr nz, .next + inc hl + ld a, e + cp [hl] + jr z, .yup + +.next + pop hl + add hl, bc + jr LookUpWildmonsForMapDE + +.nope + pop hl + and a + ret + +.yup + pop hl + scf + ret +; 2a2a0 + + +InitRoamMons: ; 2a2a0 +; initialize wRoamMon structs + +; species + ld a, RAIKOU + ld [wRoamMon1Species], a + ld a, ENTEI + ld [wRoamMon2Species], a +; ld a, SUICUNE +; ld [wRoamMon3Species], a + +; level + ld a, 40 + ld [wRoamMon1Level], a + ld [wRoamMon2Level], a +; ld [wRoamMon3Level], a + +; raikou starting map + ld a, GROUP_ROUTE_42 + ld [wRoamMon1MapGroup], a + ld a, MAP_ROUTE_42 + ld [wRoamMon1MapNumber], a + +; entei starting map + ld a, GROUP_ROUTE_37 + ld [wRoamMon2MapGroup], a + ld a, MAP_ROUTE_37 + ld [wRoamMon2MapNumber], a + +; suicune starting map +; ld a, GROUP_ROUTE_38 +; ld [wRoamMon3MapGroup], a +; ld a, MAP_ROUTE_38 +; ld [wRoamMon3MapNumber], a + +; hp + xor a ; generate new stats + ld [wRoamMon1HP], a + ld [wRoamMon2HP], a +; ld [wRoamMon3HP], a + + ret +; 2a2ce + + +CheckEncounterRoamMon: ; 2a2ce + push hl +; Don't trigger an encounter if we're on water. + call CheckOnWater + jr z, .DontEncounterRoamMon +; Load the current map group and number to de + call CopyCurrMapDE +; Randomly select a beast. + call Random + cp 100 ; 25/64 chance + jr nc, .DontEncounterRoamMon + and %00000011 ; Of that, a 3/4 chance. Running total: 75/256, or around 29.3%. + jr z, .DontEncounterRoamMon + dec a ; 1/3 chance that it's Entei, 1/3 chance that it's Raikou +; Compare its current location with yours + ld hl, wRoamMon1MapGroup + ld c, a + ld b, 0 + ld a, 7 ; length of the RoamMon struct + call AddNTimes + ld a, d + cp [hl] + jr nz, .DontEncounterRoamMon + inc hl + ld a, e + cp [hl] + jr nz, .DontEncounterRoamMon +; We've decided to take on a beast, so stage its information for battle. +rept 3 + dec hl +endr + ld a, [hli] + ld [TempWildMonSpecies], a + ld a, [hl] + ld [CurPartyLevel], a + ld a, BATTLETYPE_ROAMING + ld [BattleType], a + + pop hl + scf + ret + +.DontEncounterRoamMon + pop hl + and a + ret +; 2a30d + + +UpdateRoamMons: ; 2a30d + ld a, [wRoamMon1MapGroup] + cp GROUP_N_A + jr z, .SkipRaikou + ld b, a + ld a, [wRoamMon1MapNumber] + ld c, a + call .Update + ld a, b + ld [wRoamMon1MapGroup], a + ld a, c + ld [wRoamMon1MapNumber], a + +.SkipRaikou + ld a, [wRoamMon2MapGroup] + cp GROUP_N_A + jr z, .SkipEntei + ld b, a + ld a, [wRoamMon2MapNumber] + ld c, a + call .Update + ld a, b + ld [wRoamMon2MapGroup], a + ld a, c + ld [wRoamMon2MapNumber], a + +.SkipEntei + ld a, [wRoamMon3MapGroup] + cp GROUP_N_A + jr z, .SkipSuicune + ld b, a + ld a, [wRoamMon3MapNumber] + ld c, a + call .Update + ld a, b + ld [wRoamMon3MapGroup], a + ld a, c + ld [wRoamMon3MapNumber], a + +.SkipSuicune + jp _BackUpMapIndices +; 2a355 + + +.Update: ; 2a355 + ld hl, RoamMaps +.loop +; Are we at the end of the table? + ld a, [hl] + cp -1 + ret z +; Is this the correct entry? + ld a, b + cp [hl] + jr nz, .next + inc hl + ld a, c + cp [hl] + jr z, .yes +; We don't have the correct entry yet, so let's continue. A 0 terminates each entry. +.next + ld a, [hli] + and a + jr nz, .next + jr .loop + +; We have the correct entry now, so let's choose a random map from it. +.yes + inc hl + ld d, h + ld e, l +.update_loop + ld h, d + ld l, e +; Choose which map to warp to. + call Random + and $1f ; 1/8n chance it moves to a completely random map, where n is the number of roaming connections from the current map. + jr z, JumpRoamMon + and 3 + cp [hl] + jr nc, .update_loop ; invalid index, try again + inc hl + ld c, a + ld b, $0 +rept 2 + add hl, bc +endr + ld a, [wdfe7] + cp [hl] + jr nz, .done + inc hl + ld a, [wdfe6] + cp [hl] + jr z, .update_loop + dec hl + +.done + ld a, [hli] + ld b, a + ld c, [hl] + ret + +JumpRoamMons: ; 2a394 + ld a, [wRoamMon1MapGroup] + cp GROUP_N_A + jr z, .SkipRaikou + call JumpRoamMon + ld a, b + ld [wRoamMon1MapGroup], a + ld a, c + ld [wRoamMon1MapNumber], a +.SkipRaikou + + ld a, [wRoamMon2MapGroup] + cp GROUP_N_A + jr z, .SkipEntei + call JumpRoamMon + ld a, b + ld [wRoamMon2MapGroup], a + ld a, c + ld [wRoamMon2MapNumber], a +.SkipEntei + + ld a, [wRoamMon3MapGroup] + cp GROUP_N_A + jr z, .SkipSuicune + call JumpRoamMon + ld a, b + ld [wRoamMon3MapGroup], a + ld a, c + ld [wRoamMon3MapNumber], a +.SkipSuicune + + jp _BackUpMapIndices + +JumpRoamMon: ; 2a3cd +.loop + ld hl, RoamMaps +.innerloop1 ; This loop is completely unnecessary. + call Random ; Choose a random number + and $f ; Take the lower nybble only. This gives a number between 0 and 15. + cp $10 ; If the number is greater than or equal to 16, loop back and try again. + jr nc, .innerloop1 ; I'm sure you can guess why this check is bogus. + inc a + ld b, a +.innerloop2 ; Loop to get hl to the address of the chosen roam map. + dec b + jr z, .ok +.innerloop3 ; Loop to skip the current roam map, which is terminated by a 0. + ld a, [hli] + and a + jr nz, .innerloop3 + jr .innerloop2 +; Check to see if the selected map is the one the player is currently in. If so, try again. +.ok + ld a, [MapGroup] + cp [hl] + jr nz, .done + inc hl + ld a, [MapNumber] + cp [hl] + jr z, .loop + dec hl +; Return the map group and number in bc. +.done + ld a, [hli] + ld b, a + ld c, [hl] + ret +; 2a3f6 + +_BackUpMapIndices: ; 2a3f6 + ld a, [wdfe4] + ld [wdfe6], a + ld a, [wdfe5] + ld [wdfe7], a + ld a, [MapNumber] + ld [wdfe4], a + ld a, [MapGroup] + ld [wdfe5], a + ret +; 2a40f + +RoamMaps: ; 2a40f +; Maps that roaming monsters can be on, +; and possible maps they can jump to. +; Notably missing are Route 40 and +; Route 41, which are water routes. + roam_map ROUTE_29, 2, ROUTE_30, ROUTE_46 + roam_map ROUTE_30, 2, ROUTE_29, ROUTE_31 + roam_map ROUTE_31, 3, ROUTE_30, ROUTE_32, ROUTE_36 + roam_map ROUTE_32, 3, ROUTE_36, ROUTE_31, ROUTE_33 + roam_map ROUTE_33, 2, ROUTE_32, ROUTE_34 + roam_map ROUTE_34, 2, ROUTE_33, ROUTE_35 + roam_map ROUTE_35, 2, ROUTE_34, ROUTE_36 + roam_map ROUTE_36, 4, ROUTE_35, ROUTE_31, ROUTE_32, ROUTE_37 + roam_map ROUTE_37, 3, ROUTE_36, ROUTE_38, ROUTE_42 + roam_map ROUTE_38, 3, ROUTE_37, ROUTE_39, ROUTE_42 + roam_map ROUTE_39, 1, ROUTE_38 + roam_map ROUTE_42, 4, ROUTE_43, ROUTE_44, ROUTE_37, ROUTE_38 + roam_map ROUTE_43, 2, ROUTE_42, ROUTE_44 + roam_map ROUTE_44, 3, ROUTE_42, ROUTE_43, ROUTE_45 + roam_map ROUTE_45, 2, ROUTE_44, ROUTE_46 + roam_map ROUTE_46, 2, ROUTE_45, ROUTE_29 + db -1 +; 2a4a0 + +ValidateTempWildMonSpecies: ; 2a4a0 +; Due to a development oversight, this function is called with the wild Pokemon's level, not its species, in a. + and a + jr z, .nowildmon ; = 0 + cp NUM_POKEMON + 1 ; 252 + jr nc, .nowildmon ; >= 252 + and a ; 1 <= Species <= 251 + ret + +.nowildmon + scf + ret +; 2a4ab + +RandomPhoneRareWildMon: ; 2a4ab +; Related to the phone? + callba GetCallerLocation + ld d, b + ld e, c + ld hl, JohtoGrassWildMons + ld bc, GRASS_WILDDATA_LENGTH + call LookUpWildmonsForMapDE + jr c, .GetGrassmon + ld hl, KantoGrassWildMons + call LookUpWildmonsForMapDE + jr nc, .done + +.GetGrassmon + push hl + ld bc, 5 + 4 * 2 ; Location of the level of the 5th wild Pokemon in that map + add hl, bc + ld a, [TimeOfDay] + ld bc, 7 * 2 + call AddNTimes +.randloop1 + call Random + and $3 + jr z, .randloop1 + dec a + ld c, a + ld b, $0 +rept 2 + add hl, bc +endr +; We now have the pointer to one of the last (rarest) three wild Pokemon found in that area. + inc hl + ld c, [hl] ; Contains the species index of this rare Pokemon + pop hl + ld de, 5 + 0 * 2 + add hl, de + inc hl ; Species index of the most common Pokemon on that route + ld b, 4 +.loop2 + ld a, [hli] + cp c ; Compare this most common Pokemon with the rare one stored in c. + jr z, .done + inc hl + dec b + jr nz, .loop2 +; This Pokemon truly is rare. + push bc + dec c + ld a, c + call CheckSeenMon + pop bc + jr nz, .done +; Since we haven't seen it, have the caller tell us about it. + ld de, StringBuffer1 + call CopyName1 + ld a, c + ld [wd265], a + call GetPokemonName + ld hl, UnknownText_0x2a51a + call PrintText + xor a + ld [ScriptVar], a + ret + +.done + ld a, $1 + ld [ScriptVar], a + ret +; 2a51a + +UnknownText_0x2a51a: ; 0x2a51a + ; I just saw some rare @ in @ . I'll call you if I see another rare #MON, OK? + text_jump UnknownText_0x1bd34b + db "@" +; 0x2a51f + +RandomPhoneWildMon: ; 2a51f + callba GetCallerLocation + ld d, b + ld e, c + ld hl, JohtoGrassWildMons + ld bc, GRASS_WILDDATA_LENGTH + call LookUpWildmonsForMapDE + jr c, .ok + ld hl, KantoGrassWildMons + call LookUpWildmonsForMapDE + +.ok + ld bc, 5 + 0 * 2 + add hl, bc + ld a, [TimeOfDay] + inc a + ld bc, 7 * 2 +.loop + dec a + jr z, .done + add hl, bc + jr .loop + +.done + call Random + and $3 + ld c, a + ld b, $0 +rept 2 + add hl, bc +endr + inc hl + ld a, [hl] + ld [wd265], a + call GetPokemonName + ld hl, StringBuffer1 + ld de, StringBuffer4 + ld bc, PKMN_NAME_LENGTH + jp CopyBytes +; 2a567 + +RandomPhoneMon: ; 2a567 +; Get a random monster owned by the trainer who's calling. + callba GetCallerLocation + ld hl, TrainerGroups + ld a, d + dec a + ld c, a + ld b, 0 +rept 2 + add hl, bc +endr + ld a, BANK(TrainerGroups) + call GetFarHalfword + +.skip_trainer + dec e + jr z, .skipped +.skip + ld a, BANK(Trainers) + call GetFarByte + inc hl + cp -1 + jr nz, .skip + jr .skip_trainer +.skipped + +.skip_name + ld a, BANK(Trainers) + call GetFarByte + inc hl + cp "@" + jr nz, .skip_name + + ld a, BANK(Trainers) + call GetFarByte + inc hl + ld bc, 2 + cp 0 + jr z, .got_mon_length + ld bc, 2 + NUM_MOVES + cp 1 + jr z, .got_mon_length + ld bc, 2 + 1 + cp 2 + jr z, .got_mon_length + ld bc, 2 + 1 + NUM_MOVES +.got_mon_length + + ld e, 0 + push hl +.count_mon + inc e + add hl, bc + ld a, BANK(Trainers) + call GetFarByte + cp -1 + jr nz, .count_mon + pop hl + +.rand + call Random + and 7 + cp e + jr nc, .rand + + inc a +.get_mon + dec a + jr z, .got_mon + add hl, bc + jr .get_mon +.got_mon + + inc hl ; species + ld a, BANK(Trainers) + call GetFarByte + ld [wd265], a + call GetPokemonName + ld hl, StringBuffer1 + ld de, StringBuffer4 + ld bc, PKMN_NAME_LENGTH + jp CopyBytes +; 2a5e9 + + +JohtoGrassWildMons: ; 0x2a5e9 +INCLUDE "data/wild/johto_grass.asm" + +JohtoWaterWildMons: ; 0x2b11d +INCLUDE "data/wild/johto_water.asm" + +KantoGrassWildMons: ; 0x2b274 +INCLUDE "data/wild/kanto_grass.asm" + +KantoWaterWildMons: ; 0x2b7f7 +INCLUDE "data/wild/kanto_water.asm" + +SwarmGrassWildMons: ; 0x2b8d0 +INCLUDE "data/wild/swarm_grass.asm" + +SwarmWaterWildMons: ; 0x2b92f +INCLUDE "data/wild/swarm_water.asm" -- cgit v1.2.3