pokered/home.asm

1809 lines
36 KiB
NASM
Raw Normal View History

INCLUDE "constants.asm"
2020-07-03 17:03:21 +00:00
SECTION "NULL", ROM0
NULL::
2014-05-25 17:26:42 +00:00
2020-07-03 17:03:21 +00:00
INCLUDE "home/header.asm"
2014-05-25 17:26:42 +00:00
2020-07-03 17:03:21 +00:00
SECTION "High Home", ROM0
2014-05-25 17:26:42 +00:00
2020-07-03 17:03:21 +00:00
INCLUDE "home/lcd.asm"
INCLUDE "home/clear_sprites.asm"
INCLUDE "home/copy.asm"
2014-05-25 17:26:42 +00:00
2020-07-03 17:03:21 +00:00
SECTION "Home", ROM0
2014-05-25 17:26:42 +00:00
2020-07-03 17:03:21 +00:00
INCLUDE "home/start.asm"
INCLUDE "home/joypad.asm"
INCLUDE "data/maps/map_header_pointers.asm"
INCLUDE "home/overworld.asm"
2014-05-25 17:26:42 +00:00
2016-06-12 00:24:04 +00:00
CheckForUserInterruption::
; Return carry if Up+Select+B, Start or A are pressed in c frames.
; Used only in the intro and title screen.
2014-05-25 17:26:42 +00:00
call DelayFrame
2014-05-25 17:26:42 +00:00
push bc
2014-05-25 18:21:48 +00:00
call JoypadLowSensitivity
2014-05-25 17:26:42 +00:00
pop bc
ld a, [hJoyHeld]
cp D_UP + SELECT + B_BUTTON
jr z, .input
ld a, [hJoy5]
and START | A_BUTTON
jr nz, .input
2014-05-25 17:26:42 +00:00
dec c
jr nz, CheckForUserInterruption
2014-05-25 17:26:42 +00:00
and a
ret
.input
2014-05-25 17:26:42 +00:00
scf
ret
; function to load position data for destination warp when switching maps
; INPUT:
; a = ID of destination warp within destination map
2016-06-12 00:24:04 +00:00
LoadDestinationWarpPosition::
ld b, a
2020-07-03 23:59:41 +00:00
ld a, [hLoadedROMBank]
2014-05-25 17:26:42 +00:00
push af
ld a, [wPredefParentBank]
2020-07-03 23:59:41 +00:00
ld [hLoadedROMBank], a
ld [MBC1RomBank], a
ld a, b
2014-05-25 17:26:42 +00:00
add a
add a
ld c, a
ld b, 0
add hl, bc
ld bc, 4
ld de, wCurrentTileBlockMapViewPointer
2014-05-25 17:26:42 +00:00
call CopyData
pop af
2020-07-03 23:59:41 +00:00
ld [hLoadedROMBank], a
ld [MBC1RomBank], a
2014-05-25 17:26:42 +00:00
ret
2020-07-04 02:57:43 +00:00
INCLUDE "home/pokemon.asm"
INCLUDE "home/print_bcd.asm"
INCLUDE "home/pics.asm"
2020-07-04 02:57:43 +00:00
INCLUDE "data/tilesets/collision_tile_ids.asm"
INCLUDE "home/copy2.asm"
INCLUDE "home/text.asm"
INCLUDE "home/vcopy.asm"
INCLUDE "home/init.asm"
INCLUDE "home/vblank.asm"
INCLUDE "home/fade.asm"
INCLUDE "home/serial.asm"
INCLUDE "home/timer.asm"
INCLUDE "home/audio.asm"
2014-09-18 04:02:59 +00:00
2020-07-04 02:57:43 +00:00
UpdateSprites::
ld a, [wUpdateSpritesEnabled]
2014-09-18 04:02:59 +00:00
dec a
2020-07-04 02:57:43 +00:00
ret nz
2020-07-03 23:59:41 +00:00
ld a, [hLoadedROMBank]
2014-05-25 17:26:42 +00:00
push af
2020-07-04 02:57:43 +00:00
ld a, BANK(_UpdateSprites)
2020-07-03 23:59:41 +00:00
ld [hLoadedROMBank], a
ld [MBC1RomBank], a
2020-07-04 02:57:43 +00:00
call _UpdateSprites
2014-05-25 17:26:42 +00:00
pop af
2020-07-03 23:59:41 +00:00
ld [hLoadedROMBank], a
ld [MBC1RomBank], a
2014-05-25 17:26:42 +00:00
ret
2020-07-04 02:57:43 +00:00
INCLUDE "data/items/marts.asm"
INCLUDE "home/overworld_text.asm"
INCLUDE "home/uncompress.asm"
2014-09-18 04:02:59 +00:00
2020-07-04 02:57:43 +00:00
ResetPlayerSpriteData::
ld hl, wSpriteStateData1
call ResetPlayerSpriteData_ClearSpriteData
ld hl, wSpriteStateData2
call ResetPlayerSpriteData_ClearSpriteData
ld a, $1
ld [wSpriteStateData1], a
ld [wSpriteStateData2 + $0e], a
ld hl, wSpriteStateData1 + 4
ld [hl], $3c ; set Y screen pos
inc hl
inc hl
ld [hl], $40 ; set X screen pos
2014-05-25 17:26:42 +00:00
ret
2020-07-04 02:57:43 +00:00
; overwrites sprite data with zeroes
ResetPlayerSpriteData_ClearSpriteData::
ld bc, $10
2014-05-25 17:26:42 +00:00
xor a
2020-07-04 02:57:43 +00:00
jp FillMemory
2014-05-25 17:26:42 +00:00
2020-07-04 02:57:43 +00:00
FadeOutAudio::
ld a, [wAudioFadeOutControl]
and a ; currently fading out audio?
jr nz, .fadingOut
ld a, [wd72c]
bit 1, a
ret nz
ld a, $77
ld [rNR50], a
ret
.fadingOut
ld a, [wAudioFadeOutCounter]
2014-05-25 17:26:42 +00:00
and a
2020-07-04 02:57:43 +00:00
jr z, .counterReachedZero
dec a
ld [wAudioFadeOutCounter], a
2014-05-25 17:26:42 +00:00
ret
2020-07-04 02:57:43 +00:00
.counterReachedZero
ld a, [wAudioFadeOutCounterReloadValue]
ld [wAudioFadeOutCounter], a
ld a, [rNR50]
and a ; has the volume reached 0?
jr z, .fadeOutComplete
ld b, a
2020-07-04 02:57:43 +00:00
and $f
dec a
ld c, a
2020-07-04 02:57:43 +00:00
ld a, b
and $f0
swap a
dec a
swap a
or c
ld [rNR50], a
2014-05-25 17:26:42 +00:00
ret
2020-07-04 02:57:43 +00:00
.fadeOutComplete
ld a, [wAudioFadeOutControl]
ld b, a
2020-07-04 02:57:43 +00:00
xor a
ld [wAudioFadeOutControl], a
ld a, SFX_STOP_ALL_MUSIC
ld [wNewSoundID], a
call PlaySound
ld a, [wAudioSavedROMBank]
ld [wAudioROMBank], a
ld a, b
2020-07-04 02:57:43 +00:00
ld [wNewSoundID], a
jp PlaySound
2014-05-25 17:26:42 +00:00
2020-07-04 02:57:43 +00:00
INCLUDE "home/predef_text.asm"
INCLUDE "home/start_menu.asm"
2014-05-25 17:26:42 +00:00
2020-07-04 02:57:43 +00:00
; function to count how many bits are set in a string of bytes
2014-05-25 17:26:42 +00:00
; INPUT:
; hl = address of string of bytes
; b = length of string of bytes
; OUTPUT:
2015-08-07 11:24:06 +00:00
; [wNumSetBits] = number of set bits
2016-06-12 00:24:04 +00:00
CountSetBits::
ld c, 0
2014-05-25 17:26:42 +00:00
.loop
ld a, [hli]
ld e, a
ld d, 8
2014-05-25 17:26:42 +00:00
.innerLoop ; count how many bits are set in the current byte
srl e
ld a, 0
2014-05-25 17:26:42 +00:00
adc c
2020-07-04 02:57:43 +00:00
ld c, a
dec d
jr nz, .innerLoop
2014-05-25 17:26:42 +00:00
dec b
2020-07-04 02:57:43 +00:00
jr nz, .loop
ld a, c
ld [wNumSetBits], a
2014-05-25 17:26:42 +00:00
ret
2020-07-04 02:57:43 +00:00
; subtracts the amount the player paid from their money
; OUTPUT: carry = 0(success) or 1(fail because there is not enough money)
SubtractAmountPaidFromMoney::
jpba SubtractAmountPaidFromMoney_
2014-05-25 17:26:42 +00:00
2020-07-04 02:57:43 +00:00
; adds the amount the player sold to their money
AddAmountSoldToMoney::
ld de, wPlayerMoney + 2
ld hl, hMoney + 2 ; total price of items
ld c, 3 ; length of money in bytes
predef AddBCDPredef ; add total price to money
ld a, MONEY_BOX
ld [wTextBoxID], a
call DisplayTextBoxID ; redraw money text box
ld a, SFX_PURCHASE
call PlaySoundWaitForCurrent
jp WaitForSoundToFinish
; function to remove an item (in varying quantities) from the player's bag or PC box
; INPUT:
; HL = address of inventory (either wNumBagItems or wNumBoxItems)
; [wWhichPokemon] = index (within the inventory) of the item to remove
; [wItemQuantity] = quantity to remove
RemoveItemFromInventory::
2020-07-03 23:59:41 +00:00
ld a, [hLoadedROMBank]
2014-05-25 17:26:42 +00:00
push af
2020-07-04 02:57:43 +00:00
ld a, BANK(RemoveItemFromInventory_)
2020-07-03 23:59:41 +00:00
ld [hLoadedROMBank], a
ld [MBC1RomBank], a
2020-07-04 02:57:43 +00:00
call RemoveItemFromInventory_
2014-05-25 17:26:42 +00:00
pop af
2020-07-03 23:59:41 +00:00
ld [hLoadedROMBank], a
ld [MBC1RomBank], a
2014-05-25 17:26:42 +00:00
ret
2020-07-04 02:57:43 +00:00
; function to add an item (in varying quantities) to the player's bag or PC box
; INPUT:
; HL = address of inventory (either wNumBagItems or wNumBoxItems)
; [wcf91] = item ID
; [wItemQuantity] = item quantity
; sets carry flag if successful, unsets carry flag if unsuccessful
AddItemToInventory::
2014-05-25 17:26:42 +00:00
push bc
2020-07-04 02:57:43 +00:00
ld a, [hLoadedROMBank]
2014-05-25 17:26:42 +00:00
push af
2020-07-04 02:57:43 +00:00
ld a, BANK(AddItemToInventory_)
ld [hLoadedROMBank], a
ld [MBC1RomBank], a
call AddItemToInventory_
pop bc
ld a, b
2020-07-04 02:57:43 +00:00
ld [hLoadedROMBank], a
ld [MBC1RomBank], a
2014-05-25 17:26:42 +00:00
pop bc
ret
2020-07-04 02:57:43 +00:00
INCLUDE "home/list_menu.asm"
INCLUDE "home/names.asm"
2014-05-25 17:26:42 +00:00
; reloads text box tile patterns, current map view, and tileset tile patterns
2016-06-12 00:24:04 +00:00
ReloadMapData::
2020-07-03 23:59:41 +00:00
ld a, [hLoadedROMBank]
2014-05-25 17:26:42 +00:00
push af
ld a, [wCurMap]
2014-05-25 17:26:42 +00:00
call SwitchToMapRomBank
call DisableLCD
call LoadTextBoxTilePatterns
call LoadCurrentMapView
call LoadTilesetTilePatternData
call EnableLCD
pop af
2020-07-03 23:59:41 +00:00
ld [hLoadedROMBank], a
ld [MBC1RomBank], a
2014-05-25 17:26:42 +00:00
ret
; reloads tileset tile patterns
2016-06-12 00:24:04 +00:00
ReloadTilesetTilePatterns::
2020-07-03 23:59:41 +00:00
ld a, [hLoadedROMBank]
2014-05-25 17:26:42 +00:00
push af
ld a, [wCurMap]
2014-05-25 17:26:42 +00:00
call SwitchToMapRomBank
call DisableLCD
call LoadTilesetTilePatternData
call EnableLCD
pop af
2020-07-03 23:59:41 +00:00
ld [hLoadedROMBank], a
ld [MBC1RomBank], a
2014-05-25 17:26:42 +00:00
ret
; shows the town map and lets the player choose a destination to fly to
2016-06-12 00:24:04 +00:00
ChooseFlyDestination::
ld hl, wd72e
res 4, [hl]
2015-07-19 18:56:13 +00:00
jpba LoadTownMap_Fly
2014-05-25 17:26:42 +00:00
2014-08-09 05:39:13 +00:00
; causes the text box to close without waiting for a button press after displaying text
2016-06-12 00:24:04 +00:00
DisableWaitingAfterTextDisplay::
ld a, $01
ld [wDoNotWaitForButtonPressAfterDisplayingText], a
2014-05-25 17:26:42 +00:00
ret
; uses an item
; UseItem is used with dummy items to perform certain other functions as well
; INPUT:
; [wcf91] = item ID
2014-05-25 17:26:42 +00:00
; OUTPUT:
2015-07-15 06:16:06 +00:00
; [wActionResultOrTookBattleTurn] = success
2017-06-24 20:01:43 +00:00
; 00: unsuccessful
2014-05-25 17:26:42 +00:00
; 01: successful
; 02: not able to be used right now, no extra menu displayed (only certain items use this)
2016-06-12 00:24:04 +00:00
UseItem::
2015-07-19 18:56:13 +00:00
jpba UseItem_
2014-05-25 17:26:42 +00:00
; confirms the item toss and then tosses the item
; INPUT:
; hl = address of inventory (either wNumBagItems or wNumBoxItems)
; [wcf91] = item ID
; [wWhichPokemon] = index of item within inventory
2015-07-13 06:00:48 +00:00
; [wItemQuantity] = quantity to toss
2014-05-25 17:26:42 +00:00
; OUTPUT:
; clears carry flag if the item is tossed, sets carry flag if not
2016-06-12 00:24:04 +00:00
TossItem::
2020-07-03 23:59:41 +00:00
ld a, [hLoadedROMBank]
2014-05-25 17:26:42 +00:00
push af
ld a, BANK(TossItem_)
2020-07-03 23:59:41 +00:00
ld [hLoadedROMBank], a
ld [MBC1RomBank], a
2014-05-25 17:26:42 +00:00
call TossItem_
pop de
ld a, d
2020-07-03 23:59:41 +00:00
ld [hLoadedROMBank], a
ld [MBC1RomBank], a
2014-05-25 17:26:42 +00:00
ret
; checks if an item is a key item
; INPUT:
; [wcf91] = item ID
2014-05-25 17:26:42 +00:00
; OUTPUT:
2015-07-13 06:00:48 +00:00
; [wIsKeyItem] = result
2014-05-25 17:26:42 +00:00
; 00: item is not key item
; 01: item is key item
2016-06-12 00:24:04 +00:00
IsKeyItem::
2014-05-25 17:26:42 +00:00
push hl
push de
push bc
callba IsKeyItem_
pop bc
pop de
pop hl
ret
; function to draw various text boxes
; INPUT:
2015-02-07 10:43:08 +00:00
; [wTextBoxID] = text box ID
2015-08-05 21:20:29 +00:00
; b, c = y, x cursor position (TWO_OPTION_MENU only)
2016-06-12 00:24:04 +00:00
DisplayTextBoxID::
2020-07-03 23:59:41 +00:00
ld a, [hLoadedROMBank]
2014-05-25 17:26:42 +00:00
push af
ld a, BANK(DisplayTextBoxID_)
2020-07-03 23:59:41 +00:00
ld [hLoadedROMBank], a
ld [MBC1RomBank], a
2014-05-25 17:26:42 +00:00
call DisplayTextBoxID_
pop bc
ld a, b
2020-07-03 23:59:41 +00:00
ld [hLoadedROMBank], a
ld [MBC1RomBank], a
2014-05-25 17:26:42 +00:00
ret
2014-09-14 18:29:18 +00:00
; not zero if an NPC movement script is running, the player character is
; automatically stepping down from a door, or joypad states are being simulated
2016-06-12 00:24:04 +00:00
IsPlayerCharacterBeingControlledByGame::
ld a, [wNPCMovementScriptPointerTableNum]
2014-05-25 17:26:42 +00:00
and a
ret nz
ld a, [wd736]
2014-09-14 18:29:18 +00:00
bit 1, a ; currently stepping down from door bit
2014-05-25 17:26:42 +00:00
ret nz
ld a, [wd730]
2014-05-25 17:26:42 +00:00
and $80
ret
2016-06-12 00:24:04 +00:00
RunNPCMovementScript::
ld hl, wd736
2014-05-25 17:26:42 +00:00
bit 0, [hl]
res 0, [hl]
jr nz, .playerStepOutFromDoor
ld a, [wNPCMovementScriptPointerTableNum]
2014-05-25 17:26:42 +00:00
and a
ret z
dec a
add a
ld d, 0
2014-05-25 17:26:42 +00:00
ld e, a
ld hl, .NPCMovementScriptPointerTables
2014-05-25 17:26:42 +00:00
add hl, de
ld a, [hli]
ld h, [hl]
ld l, a
2020-07-03 23:59:41 +00:00
ld a, [hLoadedROMBank]
2014-05-25 17:26:42 +00:00
push af
ld a, [wNPCMovementScriptBank]
2020-07-03 23:59:41 +00:00
ld [hLoadedROMBank], a
ld [MBC1RomBank], a
ld a, [wNPCMovementScriptFunctionNum]
2014-05-25 17:26:42 +00:00
call CallFunctionInTable
pop af
2020-07-03 23:59:41 +00:00
ld [hLoadedROMBank], a
ld [MBC1RomBank], a
2014-05-25 17:26:42 +00:00
ret
2016-06-12 18:35:21 +00:00
.NPCMovementScriptPointerTables
2015-07-15 20:58:21 +00:00
dw PalletMovementScriptPointerTable
dw PewterMuseumGuyMovementScriptPointerTable
dw PewterGymGuyMovementScriptPointerTable
.playerStepOutFromDoor
2015-07-19 18:56:13 +00:00
jpba PlayerStepOutFromDoor
2014-05-25 17:26:42 +00:00
2016-06-12 00:24:04 +00:00
EndNPCMovementScript::
2015-07-19 18:56:13 +00:00
jpba _EndNPCMovementScript
2014-05-25 17:26:42 +00:00
2016-06-12 00:24:04 +00:00
EmptyFunc2::
2014-05-25 17:26:42 +00:00
ret
2020-07-04 02:57:43 +00:00
INCLUDE "home/trainers.asm"
2014-05-25 17:26:42 +00:00
2014-09-14 18:29:18 +00:00
; checks if the player's coordinates match an arrow movement tile's coordinates
; and if so, decodes the RLE movement data
; b = player Y
; c = player X
2016-06-12 00:24:04 +00:00
DecodeArrowMovementRLE::
2014-05-25 17:26:42 +00:00
ld a, [hli]
cp $ff
2014-09-14 18:29:18 +00:00
ret z ; no match in the list
2014-05-25 17:26:42 +00:00
cp b
2014-09-14 18:29:18 +00:00
jr nz, .nextArrowMovementTileEntry1
2014-05-25 17:26:42 +00:00
ld a, [hli]
cp c
2014-09-14 18:29:18 +00:00
jr nz, .nextArrowMovementTileEntry2
2014-05-25 17:26:42 +00:00
ld a, [hli]
ld d, [hl]
ld e, a
ld hl, wSimulatedJoypadStatesEnd
2014-05-25 17:26:42 +00:00
call DecodeRLEList
dec a
ld [wSimulatedJoypadStatesIndex], a
2014-05-25 17:26:42 +00:00
ret
2014-09-14 18:29:18 +00:00
.nextArrowMovementTileEntry1
2014-05-25 17:26:42 +00:00
inc hl
2014-09-14 18:29:18 +00:00
.nextArrowMovementTileEntry2
2014-05-25 17:26:42 +00:00
inc hl
inc hl
2014-09-14 18:29:18 +00:00
jr DecodeArrowMovementRLE
2014-05-25 17:26:42 +00:00
2016-06-12 00:24:04 +00:00
FuncTX_ItemStoragePC::
2014-05-25 17:26:42 +00:00
call SaveScreenTilesToBuffer2
ld b, BANK(PlayerPC)
ld hl, PlayerPC
jr bankswitchAndContinue
2016-06-12 00:24:04 +00:00
FuncTX_BillsPC::
2014-05-25 17:26:42 +00:00
call SaveScreenTilesToBuffer2
2014-09-18 04:02:59 +00:00
ld b, BANK(BillsPC_)
ld hl, BillsPC_
2014-05-25 17:26:42 +00:00
jr bankswitchAndContinue
2016-06-12 18:35:21 +00:00
FuncTX_GameCornerPrizeMenu::
2014-05-25 17:26:42 +00:00
; XXX find a better name for this function
; special_F7
ld b, BANK(CeladonPrizeMenu)
ld hl, CeladonPrizeMenu
2016-06-12 00:24:04 +00:00
bankswitchAndContinue::
2014-05-25 17:26:42 +00:00
call Bankswitch
jp HoldTextDisplayOpen ; continue to main text-engine function
2016-06-12 00:24:04 +00:00
FuncTX_PokemonCenterPC::
2014-05-25 17:26:42 +00:00
ld b, BANK(ActivatePC)
ld hl, ActivatePC
jr bankswitchAndContinue
2016-06-12 00:24:04 +00:00
StartSimulatingJoypadStates::
2014-05-25 17:26:42 +00:00
xor a
ld [wOverrideSimulatedJoypadStatesMask], a
ld [wSpriteStateData2 + $06], a ; player's sprite movement byte 1
ld hl, wd730
2014-05-25 17:26:42 +00:00
set 7, [hl]
ret
2016-06-12 00:24:04 +00:00
IsItemInBag::
2014-05-25 17:26:42 +00:00
; given an item_id in b
; set zero flag if item isn't in player's bag
; else reset zero flag
; related to Pokémon Tower and ghosts
2015-08-13 05:14:31 +00:00
predef GetQuantityOfItemInBag
ld a, b
2014-05-25 17:26:42 +00:00
and a
ret
2016-06-12 00:24:04 +00:00
DisplayPokedex::
ld [wd11e], a
2015-07-19 18:56:13 +00:00
jpba _DisplayPokedex
2014-05-25 17:26:42 +00:00
2016-06-12 00:24:04 +00:00
SetSpriteFacingDirectionAndDelay::
call SetSpriteFacingDirection
ld c, 6
2014-05-25 17:26:42 +00:00
jp DelayFrames
2016-06-12 00:24:04 +00:00
SetSpriteFacingDirection::
2014-05-25 17:26:42 +00:00
ld a, $9
2020-07-03 23:59:41 +00:00
ld [hSpriteDataOffset], a
call GetPointerWithinSpriteStateData1
2015-07-18 15:17:29 +00:00
ld a, [hSpriteFacingDirection]
2014-05-25 17:26:42 +00:00
ld [hl], a
ret
2016-06-12 00:24:04 +00:00
SetSpriteImageIndexAfterSettingFacingDirection::
ld de, -7
2014-05-25 17:26:42 +00:00
add hl, de
ld [hl], a
ret
; tests if the player's coordinates are in a specified array
; INPUT:
; hl = address of array
; OUTPUT:
2015-07-16 03:04:58 +00:00
; [wCoordIndex] = if there is match, the matching array index
2014-05-25 17:26:42 +00:00
; sets carry if the coordinates are in the array, clears carry if not
2016-06-12 00:24:04 +00:00
ArePlayerCoordsInArray::
ld a, [wYCoord]
ld b, a
ld a, [wXCoord]
ld c, a
2014-05-25 17:26:42 +00:00
; fallthrough
2016-06-12 00:24:04 +00:00
CheckCoords::
2014-05-25 17:26:42 +00:00
xor a
ld [wCoordIndex], a
2014-05-25 17:26:42 +00:00
.loop
ld a, [hli]
2016-06-12 18:35:21 +00:00
cp $ff ; reached terminator?
jr z, .notInArray
2014-05-25 17:26:42 +00:00
push hl
ld hl, wCoordIndex
2014-05-25 17:26:42 +00:00
inc [hl]
pop hl
.compareYCoord
cp b
jr z, .compareXCoord
2014-05-25 17:26:42 +00:00
inc hl
jr .loop
.compareXCoord
ld a, [hli]
2014-05-25 17:26:42 +00:00
cp c
jr nz, .loop
2014-05-25 17:26:42 +00:00
.inArray
scf
ret
.notInArray
and a
ret
; tests if a boulder's coordinates are in a specified array
; INPUT:
; hl = address of array
2020-07-03 23:59:41 +00:00
; [hSpriteIndex] = index of boulder sprite
2014-05-25 17:26:42 +00:00
; OUTPUT:
2015-07-16 03:04:58 +00:00
; [wCoordIndex] = if there is match, the matching array index
2014-05-25 17:26:42 +00:00
; sets carry if the coordinates are in the array, clears carry if not
2016-06-12 00:24:04 +00:00
CheckBoulderCoords::
2014-05-25 17:26:42 +00:00
push hl
ld hl, wSpriteStateData2 + $04
2020-07-03 23:59:41 +00:00
ld a, [hSpriteIndex]
2014-05-25 17:26:42 +00:00
swap a
ld d, $0
ld e, a
add hl, de
ld a, [hli]
sub $4 ; because sprite coordinates are offset by 4
ld b, a
ld a, [hl]
sub $4 ; because sprite coordinates are offset by 4
ld c, a
pop hl
jp CheckCoords
2016-06-12 00:24:04 +00:00
GetPointerWithinSpriteStateData1::
2014-05-25 17:26:42 +00:00
ld h, $c1
jr _GetPointerWithinSpriteStateData
2014-05-25 17:26:42 +00:00
2016-06-12 00:24:04 +00:00
GetPointerWithinSpriteStateData2::
2014-05-25 17:26:42 +00:00
ld h, $c2
_GetPointerWithinSpriteStateData:
2020-07-03 23:59:41 +00:00
ld a, [hSpriteDataOffset]
2014-05-25 17:26:42 +00:00
ld b, a
2020-07-03 23:59:41 +00:00
ld a, [hSpriteIndex]
2014-05-25 17:26:42 +00:00
swap a
add b
ld l, a
ret
; decodes a $ff-terminated RLEncoded list
; each entry is a pair of bytes <byte value> <repetitions>
; the final $ff will be replicated in the output list and a contains the number of bytes written
; de: input list
; hl: output list
2016-06-12 00:24:04 +00:00
DecodeRLEList::
2014-05-25 17:26:42 +00:00
xor a
ld [wRLEByteCount], a ; count written bytes here
.listLoop
ld a, [de]
cp $ff
jr z, .endOfList
2015-07-24 03:48:35 +00:00
ld [hRLEByteValue], a ; store byte value to be written
2014-05-25 17:26:42 +00:00
inc de
ld a, [de]
ld b, $0
ld c, a ; number of bytes to be written
ld a, [wRLEByteCount]
add c
ld [wRLEByteCount], a ; update total number of written bytes
2015-07-24 03:48:35 +00:00
ld a, [hRLEByteValue]
2014-05-25 17:26:42 +00:00
call FillMemory ; write a c-times to output
inc de
jr .listLoop
.endOfList
ld a, $ff
ld [hl], a ; write final $ff
ld a, [wRLEByteCount]
inc a ; include sentinel in counting
ret
2020-07-03 23:59:41 +00:00
; sets movement byte 1 for sprite [hSpriteIndex] to $FE and byte 2 to [hSpriteMovementByte2]
2016-06-12 00:24:04 +00:00
SetSpriteMovementBytesToFE::
2014-05-25 17:26:42 +00:00
push hl
call GetSpriteMovementByte1Pointer
ld [hl], $fe
call GetSpriteMovementByte2Pointer
2015-07-18 15:17:29 +00:00
ld a, [hSpriteMovementByte2]
2014-05-25 17:26:42 +00:00
ld [hl], a
pop hl
ret
2020-07-03 23:59:41 +00:00
; sets both movement bytes for sprite [hSpriteIndex] to $FF
2016-06-12 00:24:04 +00:00
SetSpriteMovementBytesToFF::
2014-05-25 17:26:42 +00:00
push hl
call GetSpriteMovementByte1Pointer
ld [hl], $FF
2014-05-25 17:26:42 +00:00
call GetSpriteMovementByte2Pointer
ld [hl], $FF ; prevent person from walking?
2014-05-25 17:26:42 +00:00
pop hl
ret
2020-07-03 23:59:41 +00:00
; returns the sprite movement byte 1 pointer for sprite [hSpriteIndex] in hl
2016-06-12 00:24:04 +00:00
GetSpriteMovementByte1Pointer::
ld h, $C2
2020-07-03 23:59:41 +00:00
ld a, [hSpriteIndex]
2014-05-25 17:26:42 +00:00
swap a
2016-06-12 18:35:21 +00:00
add 6
ld l, a
2014-05-25 17:26:42 +00:00
ret
2020-07-03 23:59:41 +00:00
; returns the sprite movement byte 2 pointer for sprite [hSpriteIndex] in hl
2016-06-12 00:24:04 +00:00
GetSpriteMovementByte2Pointer::
2014-05-25 17:26:42 +00:00
push de
ld hl, wMapSpriteData
2020-07-03 23:59:41 +00:00
ld a, [hSpriteIndex]
2014-05-25 17:26:42 +00:00
dec a
add a
ld d, 0
ld e, a
add hl, de
2014-05-25 17:26:42 +00:00
pop de
ret
2016-06-12 00:24:04 +00:00
GetTrainerInformation::
2014-05-25 17:26:42 +00:00
call GetTrainerName
2015-02-07 10:43:08 +00:00
ld a, [wLinkState]
2014-05-25 17:26:42 +00:00
and a
jr nz, .linkBattle
ld a, BANK(TrainerPicAndMoneyPointers)
2014-05-25 17:26:42 +00:00
call BankswitchHome
2015-08-31 02:38:41 +00:00
ld a, [wTrainerClass]
2014-05-25 17:26:42 +00:00
dec a
ld hl, TrainerPicAndMoneyPointers
ld bc, $5
call AddNTimes
2015-04-09 11:05:57 +00:00
ld de, wTrainerPicPointer
2014-05-25 17:26:42 +00:00
ld a, [hli]
ld [de], a
inc de
ld a, [hli]
ld [de], a
2015-07-25 03:27:59 +00:00
ld de, wTrainerBaseMoney
2014-05-25 17:26:42 +00:00
ld a, [hli]
ld [de], a
inc de
ld a, [hli]
ld [de], a
jp BankswitchBack
.linkBattle
2015-04-09 11:05:57 +00:00
ld hl, wTrainerPicPointer
2014-05-25 17:26:42 +00:00
ld de, RedPicFront
ld [hl], e
inc hl
ld [hl], d
ret
2016-06-12 00:24:04 +00:00
GetTrainerName::
2015-07-19 18:56:13 +00:00
jpba GetTrainerName_
2014-05-25 17:26:42 +00:00
2014-05-26 00:27:02 +00:00
HasEnoughMoney::
; Check if the player has at least as much
2015-07-17 08:21:40 +00:00
; money as the 3-byte BCD value at hMoney.
2014-05-26 00:27:02 +00:00
ld de, wPlayerMoney
2015-07-17 08:21:40 +00:00
ld hl, hMoney
2014-05-26 00:27:02 +00:00
ld c, 3
2014-05-25 17:26:42 +00:00
jp StringCmp
2014-05-26 00:27:02 +00:00
HasEnoughCoins::
; Check if the player has at least as many
2015-07-17 08:21:40 +00:00
; coins as the 2-byte BCD value at hCoins.
2014-05-25 17:26:42 +00:00
ld de, wPlayerCoins
2015-07-17 08:21:40 +00:00
ld hl, hCoins
2014-05-26 00:27:02 +00:00
ld c, 2
2014-05-25 17:26:42 +00:00
jp StringCmp
2020-07-04 02:57:43 +00:00
INCLUDE "home/bankswitch.asm"
INCLUDE "home/yes_no.asm"
2014-05-25 17:26:42 +00:00
; calculates the difference |a-b|, setting carry flag if a<b
2016-06-12 00:24:04 +00:00
CalcDifference::
2014-05-25 17:26:42 +00:00
sub b
ret nc
cpl
add $1
scf
ret
2016-06-12 00:24:04 +00:00
MoveSprite::
2020-07-03 23:59:41 +00:00
; move the sprite [hSpriteIndex] with the movement pointed to by de
2015-07-15 11:27:59 +00:00
; actually only copies the movement data to wNPCMovementDirections for later
2014-05-25 17:26:42 +00:00
call SetSpriteMovementBytesToFF
2016-06-12 00:24:04 +00:00
MoveSprite_::
2014-05-25 17:26:42 +00:00
push hl
push bc
call GetSpriteMovementByte1Pointer
xor a
ld [hl], a
ld hl, wNPCMovementDirections
ld c, 0
2014-05-25 17:26:42 +00:00
.loop
ld a, [de]
ld [hli], a
2014-05-25 17:26:42 +00:00
inc de
inc c
2016-06-12 18:35:21 +00:00
cp $FF ; have we reached the end of the movement data?
jr nz, .loop
2014-05-25 17:26:42 +00:00
ld a, c
ld [wNPCNumScriptedSteps], a ; number of steps taken
2014-05-25 17:26:42 +00:00
pop bc
ld hl, wd730
set 0, [hl]
2014-05-25 17:26:42 +00:00
pop hl
xor a
ld [wOverrideSimulatedJoypadStatesMask], a
ld [wSimulatedJoypadStatesEnd], a
2014-05-25 17:26:42 +00:00
dec a
ld [wJoyIgnore], a
ld [wWastedByteCD3A], a
2014-05-25 17:26:42 +00:00
ret
2015-07-15 20:58:21 +00:00
; divides [hDividend2] by [hDivisor2] and stores the quotient in [hQuotient2]
2016-06-12 00:24:04 +00:00
DivideBytes::
2014-05-25 17:26:42 +00:00
push hl
2016-06-12 18:35:21 +00:00
ld hl, hQuotient2
2014-05-25 17:26:42 +00:00
xor a
ld [hld], a
ld a, [hld]
and a
jr z, .done
2014-05-25 17:26:42 +00:00
ld a, [hli]
.loop
2014-05-25 17:26:42 +00:00
sub [hl]
jr c, .done
2014-05-25 17:26:42 +00:00
inc hl
inc [hl]
dec hl
jr .loop
.done
2014-05-25 17:26:42 +00:00
pop hl
ret
2014-09-18 04:02:59 +00:00
LoadFontTilePatterns::
ld a, [rLCDC]
bit 7, a ; is the LCD enabled?
jr nz, .on
.off
ld hl, FontGraphics
ld de, vFont
2015-08-10 04:56:20 +00:00
ld bc, FontGraphicsEnd - FontGraphics
2014-09-18 04:02:59 +00:00
ld a, BANK(FontGraphics)
2014-05-25 17:26:42 +00:00
jp FarCopyDataDouble ; if LCD is off, transfer all at once
2014-09-18 04:02:59 +00:00
.on
ld de, FontGraphics
ld hl, vFont
2015-08-10 04:56:20 +00:00
lb bc, BANK(FontGraphics), (FontGraphicsEnd - FontGraphics) / $8
2014-05-25 17:26:42 +00:00
jp CopyVideoDataDouble ; if LCD is on, transfer during V-blank
2014-09-18 04:02:59 +00:00
LoadTextBoxTilePatterns::
ld a, [rLCDC]
bit 7, a ; is the LCD enabled?
jr nz, .on
.off
ld hl, TextBoxGraphics
ld de, vChars2 + $600
2015-08-10 04:56:20 +00:00
ld bc, TextBoxGraphicsEnd - TextBoxGraphics
2014-09-18 04:02:59 +00:00
ld a, BANK(TextBoxGraphics)
2014-05-25 17:26:42 +00:00
jp FarCopyData2 ; if LCD is off, transfer all at once
2014-09-18 04:02:59 +00:00
.on
ld de, TextBoxGraphics
ld hl, vChars2 + $600
2015-08-10 04:56:20 +00:00
lb bc, BANK(TextBoxGraphics), (TextBoxGraphicsEnd - TextBoxGraphics) / $10
2014-05-25 17:26:42 +00:00
jp CopyVideoData ; if LCD is on, transfer during V-blank
2014-09-18 04:02:59 +00:00
LoadHpBarAndStatusTilePatterns::
ld a, [rLCDC]
bit 7, a ; is the LCD enabled?
jr nz, .on
.off
ld hl, HpBarAndStatusGraphics
ld de, vChars2 + $620
2015-08-10 04:56:20 +00:00
ld bc, HpBarAndStatusGraphicsEnd - HpBarAndStatusGraphics
2014-09-18 04:02:59 +00:00
ld a, BANK(HpBarAndStatusGraphics)
2014-05-25 17:26:42 +00:00
jp FarCopyData2 ; if LCD is off, transfer all at once
2014-09-18 04:02:59 +00:00
.on
ld de, HpBarAndStatusGraphics
ld hl, vChars2 + $620
2015-08-10 04:56:20 +00:00
lb bc, BANK(HpBarAndStatusGraphics), (HpBarAndStatusGraphicsEnd - HpBarAndStatusGraphics) / $10
2014-05-25 17:26:42 +00:00
jp CopyVideoData ; if LCD is on, transfer during V-blank
2014-09-18 04:02:59 +00:00
FillMemory::
; Fill bc bytes at hl with a.
2014-05-25 17:26:42 +00:00
push de
ld d, a
.loop
ld a, d
2014-09-18 04:02:59 +00:00
ld [hli], a
2014-05-25 17:26:42 +00:00
dec bc
ld a, b
or c
jr nz, .loop
pop de
ret
2016-06-12 00:24:04 +00:00
UncompressSpriteFromDE::
2014-09-18 04:02:59 +00:00
; Decompress pic at a:de.
2015-08-31 02:38:41 +00:00
ld hl, wSpriteInputPtr
2014-05-25 17:26:42 +00:00
ld [hl], e
inc hl
ld [hl], d
jp UncompressSpriteData
2016-06-12 00:24:04 +00:00
SaveScreenTilesToBuffer2::
2015-07-18 20:52:03 +00:00
coord hl, 0, 0
2014-05-25 17:26:42 +00:00
ld de, wTileMapBackup2
2015-07-14 07:16:19 +00:00
ld bc, SCREEN_WIDTH * SCREEN_HEIGHT
2014-05-25 17:26:42 +00:00
call CopyData
ret
2016-06-12 00:24:04 +00:00
LoadScreenTilesFromBuffer2::
2014-05-25 17:26:42 +00:00
call LoadScreenTilesFromBuffer2DisableBGTransfer
2015-08-30 06:21:54 +00:00
ld a, 1
2020-07-03 23:59:41 +00:00
ld [hAutoBGTransferEnabled], a
2014-05-25 17:26:42 +00:00
ret
2020-07-03 23:59:41 +00:00
; loads screen tiles stored in wTileMapBackup2 but leaves hAutoBGTransferEnabled disabled
2016-06-12 00:24:04 +00:00
LoadScreenTilesFromBuffer2DisableBGTransfer::
2014-05-25 17:26:42 +00:00
xor a
2020-07-03 23:59:41 +00:00
ld [hAutoBGTransferEnabled], a
2014-05-25 17:26:42 +00:00
ld hl, wTileMapBackup2
2015-07-18 20:52:03 +00:00
coord de, 0, 0
2015-08-30 06:21:54 +00:00
ld bc, SCREEN_WIDTH * SCREEN_HEIGHT
2014-05-25 17:26:42 +00:00
call CopyData
ret
2016-06-12 00:24:04 +00:00
SaveScreenTilesToBuffer1::
2015-07-18 20:52:03 +00:00
coord hl, 0, 0
2014-05-25 17:26:42 +00:00
ld de, wTileMapBackup
2015-07-14 07:16:19 +00:00
ld bc, SCREEN_WIDTH * SCREEN_HEIGHT
2014-05-25 17:26:42 +00:00
jp CopyData
2016-06-12 00:24:04 +00:00
LoadScreenTilesFromBuffer1::
2014-05-25 17:26:42 +00:00
xor a
2020-07-03 23:59:41 +00:00
ld [hAutoBGTransferEnabled], a
2014-05-25 17:26:42 +00:00
ld hl, wTileMapBackup
2015-07-18 20:52:03 +00:00
coord de, 0, 0
2015-07-14 07:16:19 +00:00
ld bc, SCREEN_WIDTH * SCREEN_HEIGHT
2014-05-25 17:26:42 +00:00
call CopyData
2015-08-30 06:21:54 +00:00
ld a, 1
2020-07-03 23:59:41 +00:00
ld [hAutoBGTransferEnabled], a
2014-05-25 17:26:42 +00:00
ret
2016-06-12 00:24:04 +00:00
DelayFrames::
2016-06-12 18:35:21 +00:00
; wait c frames
2014-05-25 17:26:42 +00:00
call DelayFrame
dec c
jr nz, DelayFrames
2014-05-25 17:26:42 +00:00
ret
2016-06-12 00:24:04 +00:00
PlaySoundWaitForCurrent::
2014-05-25 17:26:42 +00:00
push af
call WaitForSoundToFinish
pop af
jp PlaySound
; Wait for sound to finish playing
2016-06-12 00:24:04 +00:00
WaitForSoundToFinish::
ld a, [wLowHealthAlarm]
2014-05-25 17:26:42 +00:00
and $80
ret nz
push hl
2015-08-09 05:32:44 +00:00
.waitLoop
ld hl, wChannelSoundIDs + Ch5
2014-05-25 17:26:42 +00:00
xor a
or [hl]
inc hl
or [hl]
inc hl
inc hl
or [hl]
2015-08-09 05:32:44 +00:00
jr nz, .waitLoop
2014-05-25 17:26:42 +00:00
pop hl
ret
2020-07-04 02:57:43 +00:00
INCLUDE "home/names2.asm"
2014-05-25 17:26:42 +00:00
2016-06-12 00:24:04 +00:00
GetItemPrice::
2015-02-08 02:37:40 +00:00
; Stores item's price as BCD at hItemPrice (3 bytes)
; Input: [wcf91] = item id
2020-07-03 23:59:41 +00:00
ld a, [hLoadedROMBank]
2014-05-25 17:26:42 +00:00
push af
2015-02-08 02:37:40 +00:00
ld a, [wListMenuID]
cp MOVESLISTMENU
ld a, BANK(ItemPrices)
2016-06-12 18:35:21 +00:00
jr nz, .ok
2014-05-25 17:26:42 +00:00
ld a, $f ; hardcoded Bank
2016-06-12 18:35:21 +00:00
.ok
2020-07-03 23:59:41 +00:00
ld [hLoadedROMBank], a
ld [MBC1RomBank], a
2015-02-08 02:37:40 +00:00
ld hl, wItemPrices
2014-05-25 17:26:42 +00:00
ld a, [hli]
ld h, [hl]
ld l, a
ld a, [wcf91] ; a contains item id
2014-05-25 17:26:42 +00:00
cp HM_01
jr nc, .getTMPrice
2014-05-25 17:26:42 +00:00
ld bc, $3
2016-06-12 18:35:21 +00:00
.loop
2014-05-25 17:26:42 +00:00
add hl, bc
dec a
2016-06-12 18:35:21 +00:00
jr nz, .loop
2014-05-25 17:26:42 +00:00
dec hl
ld a, [hld]
2015-02-08 02:37:40 +00:00
ld [hItemPrice + 2], a
2014-05-25 17:26:42 +00:00
ld a, [hld]
2015-02-08 02:37:40 +00:00
ld [hItemPrice + 1], a
2014-05-25 17:26:42 +00:00
ld a, [hl]
2015-02-08 02:37:40 +00:00
ld [hItemPrice], a
2016-06-12 18:35:21 +00:00
jr .done
.getTMPrice
ld a, BANK(GetMachinePrice)
2020-07-03 23:59:41 +00:00
ld [hLoadedROMBank], a
ld [MBC1RomBank], a
2014-05-25 17:26:42 +00:00
call GetMachinePrice
2016-06-12 18:35:21 +00:00
.done
2015-02-08 02:37:40 +00:00
ld de, hItemPrice
2014-05-25 17:26:42 +00:00
pop af
2020-07-03 23:59:41 +00:00
ld [hLoadedROMBank], a
ld [MBC1RomBank], a
2014-05-25 17:26:42 +00:00
ret
; copies a string from [de] to [wcf4b]
2016-06-12 00:24:04 +00:00
CopyStringToCF4B::
ld hl, wcf4b
2014-05-25 17:26:42 +00:00
; fall through
; copies a string from [de] to [hl]
2016-06-12 00:24:04 +00:00
CopyString::
2014-05-25 17:26:42 +00:00
ld a, [de]
inc de
ld [hli], a
cp "@"
jr nz, CopyString
ret
; this function is used when lower button sensitivity is wanted (e.g. menus)
; OUTPUT: [hJoy5] = pressed buttons in usual format
; there are two flags that control its functionality, [hJoy6] and [hJoy7]
2017-06-24 20:01:43 +00:00
; there are essentially three modes of operation
2014-05-25 17:26:42 +00:00
; 1. Get newly pressed buttons only
; ([hJoy7] == 0, [hJoy6] == any)
; Just copies [hJoyPressed] to [hJoy5].
2014-05-25 17:26:42 +00:00
; 2. Get currently pressed buttons at low sample rate with delay
; ([hJoy7] == 1, [hJoy6] != 0)
2014-05-25 17:26:42 +00:00
; If the user holds down buttons for more than half a second,
; report buttons as being pressed up to 12 times per second thereafter.
; If the user holds down buttons for less than half a second,
; report only one button press.
; 3. Same as 2, but report no buttons as pressed if A or B is held down.
; ([hJoy7] == 1, [hJoy6] == 0)
2016-06-12 00:24:04 +00:00
JoypadLowSensitivity::
2014-05-25 18:21:48 +00:00
call Joypad
ld a, [hJoy7] ; flag
2014-05-25 17:26:42 +00:00
and a ; get all currently pressed buttons or only newly pressed buttons?
ld a, [hJoyPressed] ; newly pressed buttons
jr z, .storeButtonState
ld a, [hJoyHeld] ; all currently pressed buttons
2014-05-25 17:26:42 +00:00
.storeButtonState
ld [hJoy5], a
ld a, [hJoyPressed] ; newly pressed buttons
2014-05-25 17:26:42 +00:00
and a ; have any buttons been newly pressed since last check?
jr z, .noNewlyPressedButtons
2014-05-25 17:26:42 +00:00
.newlyPressedButtons
ld a, 30 ; half a second delay
2020-07-03 23:59:41 +00:00
ld [hFrameCounter], a
2014-05-25 17:26:42 +00:00
ret
.noNewlyPressedButtons
2020-07-03 23:59:41 +00:00
ld a, [hFrameCounter]
2014-05-25 17:26:42 +00:00
and a ; is the delay over?
jr z, .delayOver
2014-05-25 17:26:42 +00:00
.delayNotOver
xor a
ld [hJoy5], a ; report no buttons as pressed
2014-05-25 17:26:42 +00:00
ret
.delayOver
; if [hJoy6] = 0 and A or B is pressed, report no buttons as pressed
ld a, [hJoyHeld]
2014-09-18 04:02:59 +00:00
and A_BUTTON | B_BUTTON
jr z, .setShortDelay
ld a, [hJoy6] ; flag
2014-05-25 17:26:42 +00:00
and a
jr nz, .setShortDelay
2014-05-25 17:26:42 +00:00
xor a
ld [hJoy5], a
2014-05-25 17:26:42 +00:00
.setShortDelay
ld a, 5 ; 1/12 of a second delay
2020-07-03 23:59:41 +00:00
ld [hFrameCounter], a
2014-05-25 17:26:42 +00:00
ret
2016-06-12 00:24:04 +00:00
WaitForTextScrollButtonPress::
2020-07-03 23:59:41 +00:00
ld a, [hDownArrowBlinkCount1]
2014-05-25 17:26:42 +00:00
push af
2020-07-03 23:59:41 +00:00
ld a, [hDownArrowBlinkCount2]
2014-05-25 17:26:42 +00:00
push af
xor a
2020-07-03 23:59:41 +00:00
ld [hDownArrowBlinkCount1], a
2014-05-25 17:26:42 +00:00
ld a, $6
2020-07-03 23:59:41 +00:00
ld [hDownArrowBlinkCount2], a
2014-09-14 18:29:18 +00:00
.loop
2014-05-25 17:26:42 +00:00
push hl
2014-09-14 18:29:18 +00:00
ld a, [wTownMapSpriteBlinkingEnabled]
2014-05-25 17:26:42 +00:00
and a
2014-09-14 18:29:18 +00:00
jr z, .skipAnimation
call TownMapSpriteBlinkingAnimation
.skipAnimation
2015-07-18 20:52:03 +00:00
coord hl, 18, 16
2014-05-25 17:26:42 +00:00
call HandleDownArrowBlinkTiming
pop hl
2014-05-25 18:21:48 +00:00
call JoypadLowSensitivity
2015-02-07 10:43:08 +00:00
predef CableClub_Run
ld a, [hJoy5]
2014-05-25 17:26:42 +00:00
and A_BUTTON | B_BUTTON
2014-09-14 18:29:18 +00:00
jr z, .loop
2014-05-25 17:26:42 +00:00
pop af
2020-07-03 23:59:41 +00:00
ld [hDownArrowBlinkCount2], a
2014-05-25 17:26:42 +00:00
pop af
2020-07-03 23:59:41 +00:00
ld [hDownArrowBlinkCount1], a
2014-05-25 17:26:42 +00:00
ret
2014-09-14 18:29:18 +00:00
; (unless in link battle) waits for A or B being pressed and outputs the scrolling sound effect
2016-06-12 00:24:04 +00:00
ManualTextScroll::
2015-02-07 10:43:08 +00:00
ld a, [wLinkState]
cp LINK_STATE_BATTLING
2014-05-25 17:26:42 +00:00
jr z, .inLinkBattle
call WaitForTextScrollButtonPress
2015-07-19 08:46:12 +00:00
ld a, SFX_PRESS_AB
2014-05-25 17:26:42 +00:00
jp PlaySound
.inLinkBattle
ld c, 65
2014-05-25 17:26:42 +00:00
jp DelayFrames
; function to do multiplication
; all values are big endian
; INPUT
; FF96-FF98 = multiplicand
; FF99 = multiplier
; OUTPUT
; FF95-FF98 = product
2016-06-12 00:24:04 +00:00
Multiply::
2014-05-25 17:26:42 +00:00
push hl
push bc
callab _Multiply
pop bc
pop hl
ret
; function to do division
; all values are big endian
; INPUT
; FF95-FF98 = dividend
; FF99 = divisor
; b = number of bytes in the dividend (starting from FF95)
; OUTPUT
; FF95-FF98 = quotient
; FF99 = remainder
2016-06-12 00:24:04 +00:00
Divide::
2014-05-25 17:26:42 +00:00
push hl
push de
push bc
2020-07-03 23:59:41 +00:00
ld a, [hLoadedROMBank]
2014-05-25 17:26:42 +00:00
push af
ld a, BANK(_Divide)
2020-07-03 23:59:41 +00:00
ld [hLoadedROMBank], a
ld [MBC1RomBank], a
2014-05-25 17:26:42 +00:00
call _Divide
pop af
2020-07-03 23:59:41 +00:00
ld [hLoadedROMBank], a
ld [MBC1RomBank], a
2014-05-25 17:26:42 +00:00
pop bc
pop de
pop hl
ret
; This function is used to wait a short period after printing a letter to the
; screen unless the player presses the A/B button or the delay is turned off
2015-07-15 02:46:52 +00:00
; through the [wd730] or [wLetterPrintingDelayFlags] flags.
2016-06-12 00:24:04 +00:00
PrintLetterDelay::
ld a, [wd730]
bit 6, a
2014-05-25 17:26:42 +00:00
ret nz
ld a, [wLetterPrintingDelayFlags]
bit 1, a
2014-05-25 17:26:42 +00:00
ret z
push hl
push de
push bc
ld a, [wLetterPrintingDelayFlags]
bit 0, a
jr z, .waitOneFrame
ld a, [wOptions]
2014-09-18 04:02:59 +00:00
and $f
2020-07-03 23:59:41 +00:00
ld [hFrameCounter], a
2014-05-25 17:26:42 +00:00
jr .checkButtons
.waitOneFrame
ld a, 1
2020-07-03 23:59:41 +00:00
ld [hFrameCounter], a
2014-05-25 17:26:42 +00:00
.checkButtons
2014-05-25 18:21:48 +00:00
call Joypad
ld a, [hJoyHeld]
2014-05-25 17:26:42 +00:00
.checkAButton
bit 0, a ; is the A button pressed?
jr z, .checkBButton
2014-05-25 17:26:42 +00:00
jr .endWait
.checkBButton
bit 1, a ; is the B button pressed?
jr z, .buttonsNotPressed
2014-05-25 17:26:42 +00:00
.endWait
call DelayFrame
jr .done
.buttonsNotPressed ; if neither A nor B is pressed
2020-07-03 23:59:41 +00:00
ld a, [hFrameCounter]
2014-05-25 17:26:42 +00:00
and a
jr nz, .checkButtons
2014-05-25 17:26:42 +00:00
.done
pop bc
pop de
pop hl
ret
2020-05-27 19:15:53 +00:00
; Copies [hl, bc) to [de, de + bc - hl).
2014-05-25 17:26:42 +00:00
; In other words, the source data is from hl up to but not including bc,
; and the destination is de.
2016-06-12 00:24:04 +00:00
CopyDataUntil::
ld a, [hli]
ld [de], a
2014-05-25 17:26:42 +00:00
inc de
ld a, h
2014-05-25 17:26:42 +00:00
cp b
jr nz, CopyDataUntil
ld a, l
2014-05-25 17:26:42 +00:00
cp c
jr nz, CopyDataUntil
2014-05-25 17:26:42 +00:00
ret
2020-07-04 02:57:43 +00:00
INCLUDE "home/move_mon.asm"
2014-05-25 17:26:42 +00:00
; skips a text entries, each of size NAME_LENGTH (like trainer name, OT name, rival name, ...)
; hl: base pointer, will be incremented by NAME_LENGTH * a
2016-06-12 00:24:04 +00:00
SkipFixedLengthTextEntries::
2014-05-25 17:26:42 +00:00
and a
ret z
ld bc, NAME_LENGTH
2014-05-25 17:26:42 +00:00
.skipLoop
add hl, bc
dec a
jr nz, .skipLoop
ret
2016-06-12 00:24:04 +00:00
AddNTimes::
2014-05-25 17:26:42 +00:00
; add bc to hl a times
and a
ret z
.loop
add hl, bc
2014-05-25 17:26:42 +00:00
dec a
jr nz, .loop
2014-05-25 17:26:42 +00:00
ret
; Compare strings, c bytes in length, at de and hl.
; Often used to compare big endian numbers in battle calculations.
2016-06-12 00:24:04 +00:00
StringCmp::
ld a, [de]
2014-05-25 17:26:42 +00:00
cp [hl]
ret nz
inc de
inc hl
dec c
jr nz, StringCmp
2014-05-25 17:26:42 +00:00
ret
; INPUT:
; a = oam block index (each block is 4 oam entries)
; b = Y coordinate of upper left corner of sprite
; c = X coordinate of upper left corner of sprite
; de = base address of 4 tile number and attribute pairs
2016-06-12 00:24:04 +00:00
WriteOAMBlock::
ld h, wOAMBuffer / $100
2014-05-25 17:26:42 +00:00
swap a ; multiply by 16
ld l, a
2014-05-25 17:26:42 +00:00
call .writeOneEntry ; upper left
push bc
ld a, 8
2014-05-25 17:26:42 +00:00
add c
ld c, a
2014-05-25 17:26:42 +00:00
call .writeOneEntry ; upper right
pop bc
ld a, 8
2014-05-25 17:26:42 +00:00
add b
ld b, a
2014-05-25 17:26:42 +00:00
call .writeOneEntry ; lower left
ld a, 8
2014-05-25 17:26:42 +00:00
add c
ld c, a
2014-05-25 17:26:42 +00:00
; lower right
.writeOneEntry
ld [hl], b ; Y coordinate
2014-05-25 17:26:42 +00:00
inc hl
ld [hl], c ; X coordinate
2014-05-25 17:26:42 +00:00
inc hl
ld a, [de] ; tile number
2014-05-25 17:26:42 +00:00
inc de
ld [hli], a
ld a, [de] ; attribute
2014-05-25 17:26:42 +00:00
inc de
ld [hli], a
2014-05-25 17:26:42 +00:00
ret
2016-06-12 00:24:04 +00:00
HandleMenuInput::
2014-05-25 17:26:42 +00:00
xor a
ld [wPartyMenuAnimMonEnabled], a
2014-05-25 17:26:42 +00:00
2016-06-12 00:24:04 +00:00
HandleMenuInput_::
2020-07-03 23:59:41 +00:00
ld a, [hDownArrowBlinkCount1]
2014-05-25 17:26:42 +00:00
push af
2020-07-03 23:59:41 +00:00
ld a, [hDownArrowBlinkCount2]
2014-05-25 17:26:42 +00:00
push af ; save existing values on stack
xor a
2020-07-03 23:59:41 +00:00
ld [hDownArrowBlinkCount1], a ; blinking down arrow timing value 1
ld a, 6
2020-07-03 23:59:41 +00:00
ld [hDownArrowBlinkCount2], a ; blinking down arrow timing value 2
2014-05-25 17:26:42 +00:00
.loop1
xor a
ld [wAnimCounter], a ; counter for pokemon shaking animation
2014-05-25 17:26:42 +00:00
call PlaceMenuCursor
call Delay3
.loop2
push hl
ld a, [wPartyMenuAnimMonEnabled]
2014-05-25 17:26:42 +00:00
and a ; is it a pokemon selection menu?
jr z, .getJoypadState
2014-05-25 17:26:42 +00:00
callba AnimatePartyMon ; shake mini sprite of selected pokemon
.getJoypadState
pop hl
2014-05-25 18:21:48 +00:00
call JoypadLowSensitivity
ld a, [hJoy5]
2014-05-25 17:26:42 +00:00
and a ; was a key pressed?
jr nz, .keyPressed
2014-05-25 17:26:42 +00:00
push hl
2015-07-18 20:52:03 +00:00
coord hl, 18, 11 ; coordinates of blinking down arrow in some menus
2014-05-25 17:26:42 +00:00
call HandleDownArrowBlinkTiming ; blink down arrow (if any)
pop hl
ld a, [wMenuJoypadPollCount]
2014-05-25 17:26:42 +00:00
dec a
jr z, .giveUpWaiting
2014-05-25 17:26:42 +00:00
jr .loop2
.giveUpWaiting
; if a key wasn't pressed within the specified number of checks
pop af
2020-07-03 23:59:41 +00:00
ld [hDownArrowBlinkCount2], a
2014-05-25 17:26:42 +00:00
pop af
2020-07-03 23:59:41 +00:00
ld [hDownArrowBlinkCount1], a ; restore previous values
2014-05-25 17:26:42 +00:00
xor a
ld [wMenuWrappingEnabled], a ; disable menu wrapping
2014-05-25 17:26:42 +00:00
ret
.keyPressed
xor a
ld [wCheckFor180DegreeTurn], a
ld a, [hJoy5]
ld b, a
bit 6, a ; pressed Up key?
jr z, .checkIfDownPressed
2014-05-25 17:26:42 +00:00
.upPressed
ld a, [wCurrentMenuItem] ; selected menu item
2014-05-25 17:26:42 +00:00
and a ; already at the top of the menu?
jr z, .alreadyAtTop
2014-05-25 17:26:42 +00:00
.notAtTop
dec a
ld [wCurrentMenuItem], a ; move selected menu item up one space
2014-05-25 17:26:42 +00:00
jr .checkOtherKeys
.alreadyAtTop
ld a, [wMenuWrappingEnabled]
2014-05-25 17:26:42 +00:00
and a ; is wrapping around enabled?
jr z, .noWrappingAround
ld a, [wMaxMenuItem]
ld [wCurrentMenuItem], a ; wrap to the bottom of the menu
2014-05-25 17:26:42 +00:00
jr .checkOtherKeys
.checkIfDownPressed
bit 7, a
jr z, .checkOtherKeys
2014-05-25 17:26:42 +00:00
.downPressed
ld a, [wCurrentMenuItem]
2014-05-25 17:26:42 +00:00
inc a
ld c, a
ld a, [wMaxMenuItem]
2014-05-25 17:26:42 +00:00
cp c
jr nc, .notAtBottom
2014-05-25 17:26:42 +00:00
.alreadyAtBottom
ld a, [wMenuWrappingEnabled]
2014-05-25 17:26:42 +00:00
and a ; is wrapping around enabled?
jr z, .noWrappingAround
ld c, $00 ; wrap from bottom to top
2014-05-25 17:26:42 +00:00
.notAtBottom
ld a, c
ld [wCurrentMenuItem], a
2014-05-25 17:26:42 +00:00
.checkOtherKeys
ld a, [wMenuWatchedKeys]
2014-05-25 17:26:42 +00:00
and b ; does the menu care about any of the pressed keys?
jp z, .loop1
2014-05-25 17:26:42 +00:00
.checkIfAButtonOrBButtonPressed
ld a, [hJoy5]
2014-09-18 04:02:59 +00:00
and A_BUTTON | B_BUTTON
jr z, .skipPlayingSound
2014-05-25 17:26:42 +00:00
.AButtonOrBButtonPressed
push hl
ld hl, wFlags_0xcd60
bit 5, [hl]
2014-05-25 17:26:42 +00:00
pop hl
jr nz, .skipPlayingSound
ld a, SFX_PRESS_AB
call PlaySound
2014-05-25 17:26:42 +00:00
.skipPlayingSound
pop af
2020-07-03 23:59:41 +00:00
ld [hDownArrowBlinkCount2], a
2014-05-25 17:26:42 +00:00
pop af
2020-07-03 23:59:41 +00:00
ld [hDownArrowBlinkCount1], a ; restore previous values
2014-05-25 17:26:42 +00:00
xor a
ld [wMenuWrappingEnabled], a ; disable menu wrapping
ld a, [hJoy5]
2014-05-25 17:26:42 +00:00
ret
.noWrappingAround
ld a, [wMenuWatchMovingOutOfBounds]
2014-05-25 17:26:42 +00:00
and a ; should we return if the user tried to go past the top or bottom?
jr z, .checkOtherKeys
2014-05-25 17:26:42 +00:00
jr .checkIfAButtonOrBButtonPressed
2016-06-12 00:24:04 +00:00
PlaceMenuCursor::
ld a, [wTopMenuItemY]
2014-05-25 17:26:42 +00:00
and a ; is the y coordinate 0?
jr z, .adjustForXCoord
2015-07-18 20:52:03 +00:00
coord hl, 0, 0
ld bc, SCREEN_WIDTH
2014-05-25 17:26:42 +00:00
.topMenuItemLoop
add hl, bc
2014-05-25 17:26:42 +00:00
dec a
jr nz, .topMenuItemLoop
2014-05-25 17:26:42 +00:00
.adjustForXCoord
ld a, [wTopMenuItemX]
ld b, 0
ld c, a
add hl, bc
2014-05-25 17:26:42 +00:00
push hl
ld a, [wLastMenuItem]
2014-05-25 17:26:42 +00:00
and a ; was the previous menu id 0?
jr z, .checkForArrow1
2014-05-25 17:26:42 +00:00
push af
2020-07-03 23:59:41 +00:00
ld a, [hFlagsFFF6]
bit 1, a ; is the menu double spaced?
jr z, .doubleSpaced1
ld bc, 20
2014-05-25 17:26:42 +00:00
jr .getOldMenuItemScreenPosition
.doubleSpaced1
ld bc, 40
2014-05-25 17:26:42 +00:00
.getOldMenuItemScreenPosition
pop af
.oldMenuItemLoop
add hl, bc
2014-05-25 17:26:42 +00:00
dec a
jr nz, .oldMenuItemLoop
2014-05-25 17:26:42 +00:00
.checkForArrow1
ld a, [hl]
cp "▶" ; was an arrow next to the previously selected menu item?
jr nz, .skipClearingArrow
2014-05-25 17:26:42 +00:00
.clearArrow
ld a, [wTileBehindCursor]
ld [hl], a
2014-05-25 17:26:42 +00:00
.skipClearingArrow
pop hl
ld a, [wCurrentMenuItem]
2014-05-25 17:26:42 +00:00
and a
jr z, .checkForArrow2
2014-05-25 17:26:42 +00:00
push af
2020-07-03 23:59:41 +00:00
ld a, [hFlagsFFF6]
bit 1, a ; is the menu double spaced?
jr z, .doubleSpaced2
ld bc, 20
2014-05-25 17:26:42 +00:00
jr .getCurrentMenuItemScreenPosition
.doubleSpaced2
ld bc, 40
2014-05-25 17:26:42 +00:00
.getCurrentMenuItemScreenPosition
pop af
.currentMenuItemLoop
add hl, bc
2014-05-25 17:26:42 +00:00
dec a
jr nz, .currentMenuItemLoop
2014-05-25 17:26:42 +00:00
.checkForArrow2
ld a, [hl]
2016-06-12 18:35:21 +00:00
cp "▶" ; has the right arrow already been placed?
jr z, .skipSavingTile ; if so, don't lose the saved tile
ld [wTileBehindCursor], a ; save tile before overwriting with right arrow
2014-05-25 17:26:42 +00:00
.skipSavingTile
ld a, "▶" ; place right arrow
ld [hl], a
ld a, l
ld [wMenuCursorLocation], a
ld a, h
ld [wMenuCursorLocation + 1], a
ld a, [wCurrentMenuItem]
ld [wLastMenuItem], a
2014-05-25 17:26:42 +00:00
ret
; This is used to mark a menu cursor other than the one currently being
; manipulated. In the case of submenus, this is used to show the location of
; the menu cursor in the parent menu. In the case of swapping items in list,
; this is used to mark the item that was first chosen to be swapped.
2016-06-12 00:24:04 +00:00
PlaceUnfilledArrowMenuCursor::
ld b, a
ld a, [wMenuCursorLocation]
ld l, a
ld a, [wMenuCursorLocation + 1]
ld h, a
ld [hl], $ec ; outline of right arrow
ld a, b
2014-05-25 17:26:42 +00:00
ret
; Replaces the menu cursor with a blank space.
2016-06-12 00:24:04 +00:00
EraseMenuCursor::
ld a, [wMenuCursorLocation]
ld l, a
ld a, [wMenuCursorLocation + 1]
ld h, a
ld [hl], " "
2014-05-25 17:26:42 +00:00
ret
; This toggles a blinking down arrow at hl on and off after a delay has passed.
; This is often called even when no blinking is occurring.
2020-07-03 23:59:41 +00:00
; The reason is that most functions that call this initialize hDownArrowBlinkCount1 to 0.
2014-05-25 17:26:42 +00:00
; The effect is that if the tile at hl is initialized with a down arrow,
; this function will toggle that down arrow on and off, but if the tile isn't
2017-01-20 23:32:43 +00:00
; initialized with a down arrow, this function does nothing.
2014-05-25 17:26:42 +00:00
; That allows this to be called without worrying about if a down arrow should
; be blinking.
2016-06-12 00:24:04 +00:00
HandleDownArrowBlinkTiming::
ld a, [hl]
ld b, a
ld a, "▼"
2014-05-25 17:26:42 +00:00
cp b
jr nz, .downArrowOff
2014-05-25 17:26:42 +00:00
.downArrowOn
2020-07-03 23:59:41 +00:00
ld a, [hDownArrowBlinkCount1]
2014-05-25 17:26:42 +00:00
dec a
2020-07-03 23:59:41 +00:00
ld [hDownArrowBlinkCount1], a
2014-05-25 17:26:42 +00:00
ret nz
2020-07-03 23:59:41 +00:00
ld a, [hDownArrowBlinkCount2]
2014-05-25 17:26:42 +00:00
dec a
2020-07-03 23:59:41 +00:00
ld [hDownArrowBlinkCount2], a
2014-05-25 17:26:42 +00:00
ret nz
ld a, " "
ld [hl], a
ld a, $ff
2020-07-03 23:59:41 +00:00
ld [hDownArrowBlinkCount1], a
ld a, $06
2020-07-03 23:59:41 +00:00
ld [hDownArrowBlinkCount2], a
2014-05-25 17:26:42 +00:00
ret
.downArrowOff
2020-07-03 23:59:41 +00:00
ld a, [hDownArrowBlinkCount1]
2014-05-25 17:26:42 +00:00
and a
ret z
dec a
2020-07-03 23:59:41 +00:00
ld [hDownArrowBlinkCount1], a
2014-05-25 17:26:42 +00:00
ret nz
dec a
2020-07-03 23:59:41 +00:00
ld [hDownArrowBlinkCount1], a
ld a, [hDownArrowBlinkCount2]
2014-05-25 17:26:42 +00:00
dec a
2020-07-03 23:59:41 +00:00
ld [hDownArrowBlinkCount2], a
2014-05-25 17:26:42 +00:00
ret nz
ld a, $06
2020-07-03 23:59:41 +00:00
ld [hDownArrowBlinkCount2], a
ld a, "▼"
ld [hl], a
2014-05-25 17:26:42 +00:00
ret
; The following code either enables or disables the automatic drawing of
; text boxes by DisplayTextID. Both functions cause DisplayTextID to wait
2015-07-26 02:26:54 +00:00
; for a button press after displaying text (unless [wEnteringCableClub] is set).
2014-05-25 17:26:42 +00:00
2016-06-12 00:24:04 +00:00
EnableAutoTextBoxDrawing::
2014-05-25 17:26:42 +00:00
xor a
jr AutoTextBoxDrawingCommon
2016-06-12 00:24:04 +00:00
DisableAutoTextBoxDrawing::
ld a, $01
2014-05-25 17:26:42 +00:00
2016-06-12 00:24:04 +00:00
AutoTextBoxDrawingCommon::
ld [wAutoTextBoxDrawingControl], a
2014-05-25 17:26:42 +00:00
xor a
ld [wDoNotWaitForButtonPressAfterDisplayingText], a ; make DisplayTextID wait for button press
2014-05-25 17:26:42 +00:00
ret
2016-06-12 00:24:04 +00:00
PrintText::
2014-09-18 04:02:59 +00:00
; Print text hl at (1, 14).
2014-05-25 17:26:42 +00:00
push hl
ld a, MESSAGE_BOX
ld [wTextBoxID], a
2014-05-25 17:26:42 +00:00
call DisplayTextBoxID
call UpdateSprites
call Delay3
pop hl
2016-06-12 00:24:04 +00:00
PrintText_NoCreatingTextBox::
2015-07-18 20:52:03 +00:00
coord bc, 1, 14
2014-05-25 17:26:42 +00:00
jp TextCommandProcessor
2020-07-04 02:57:43 +00:00
INCLUDE "home/print_num.asm"
2014-09-18 04:02:59 +00:00
CallFunctionInTable::
; Call function a in jumptable hl.
; de is not preserved.
2014-05-25 17:26:42 +00:00
push hl
push de
push bc
add a
2014-09-18 04:02:59 +00:00
ld d, 0
ld e, a
add hl, de
ld a, [hli]
ld h, [hl]
ld l, a
ld de, .returnAddress
2014-05-25 17:26:42 +00:00
push de
jp hl
2014-05-25 17:26:42 +00:00
.returnAddress
pop bc
pop de
pop hl
ret
IsInArray::
; Search an array at hl for the value in a.
; Entry size is de bytes.
; Return count b and carry if found.
ld b, 0
IsInRestOfArray::
ld c, a
.loop
ld a, [hl]
cp -1
jr z, .notfound
cp c
jr z, .found
inc b
add hl, de
jr .loop
.notfound
and a
ret
.found
scf
ret
2016-06-12 00:24:04 +00:00
RestoreScreenTilesAndReloadTilePatterns::
2014-05-25 17:26:42 +00:00
call ClearSprites
ld a, $1
2014-09-13 07:50:56 +00:00
ld [wUpdateSpritesEnabled], a
call ReloadMapSpriteTilePatterns
2014-05-25 17:26:42 +00:00
call LoadScreenTilesFromBuffer2
call LoadTextBoxTilePatterns
2015-08-12 09:16:56 +00:00
call RunDefaultPaletteCommand
2014-05-25 17:26:42 +00:00
jr Delay3
GBPalWhiteOutWithDelay3::
call GBPalWhiteOut
Delay3::
; The bg map is updated each frame in thirds.
; Wait three frames to let the bg map fully update.
ld c, 3
jp DelayFrames
GBPalNormal::
; Reset BGP and OBP0.
ld a, %11100100 ; 3210
ld [rBGP], a
ld a, %11010000 ; 3100
ld [rOBP0], a
ret
GBPalWhiteOut::
; White out all palettes.
xor a
ld [rBGP], a
ld [rOBP0], a
ld [rOBP1], a
2014-05-25 17:26:42 +00:00
ret
2016-06-12 00:24:04 +00:00
RunDefaultPaletteCommand::
ld b, SET_PAL_DEFAULT
2016-06-12 00:24:04 +00:00
RunPaletteCommand::
ld a, [wOnSGB]
2014-05-25 17:26:42 +00:00
and a
ret z
2015-08-12 09:16:56 +00:00
predef_jump _RunPaletteCommand
2014-05-25 17:26:42 +00:00
GetHealthBarColor::
; Return at hl the palette of
; an HP bar e pixels long.
ld a, e
cp 27
ld d, 0 ; green
jr nc, .gotColor
cp 10
inc d ; yellow
jr nc, .gotColor
inc d ; red
.gotColor
ld [hl], d
ret
; Copy the current map's sprites' tile patterns to VRAM again after they have
; been overwritten by other tile patterns.
2016-06-12 00:24:04 +00:00
ReloadMapSpriteTilePatterns::
2015-02-09 02:40:08 +00:00
ld hl, wFontLoaded
2014-05-25 17:26:42 +00:00
ld a, [hl]
push af
res 0, [hl]
push hl
xor a
2015-08-31 02:38:41 +00:00
ld [wSpriteSetID], a
2014-05-25 17:26:42 +00:00
call DisableLCD
callba InitMapSprites
call EnableLCD
pop hl
pop af
ld [hl], a
call LoadPlayerSpriteGraphics
call LoadFontTilePatterns
jp UpdateSprites
GiveItem::
; Give player quantity c of item b,
; and copy the item's name to wcf4b.
2014-05-25 17:26:42 +00:00
; Return carry on success.
ld a, b
ld [wd11e], a
ld [wcf91], a
2014-05-25 17:26:42 +00:00
ld a, c
2015-07-13 06:00:48 +00:00
ld [wItemQuantity], a
ld hl, wNumBagItems
2014-05-25 17:26:42 +00:00
call AddItemToInventory
ret nc
call GetItemName
call CopyStringToCF4B
scf
ret
GivePokemon::
; Give the player monster b at level c.
ld a, b
ld [wcf91], a
2014-05-25 17:26:42 +00:00
ld a, c
2015-08-31 02:38:41 +00:00
ld [wCurEnemyLVL], a
2015-07-16 03:04:58 +00:00
xor a ; PLAYER_PARTY_DATA
ld [wMonDataLocation], a
2015-07-19 18:56:13 +00:00
jpba _GivePokemon
2014-05-25 17:26:42 +00:00
Random::
; Return a random number in a.
; For battles, use BattleRandom.
push hl
push de
push bc
callba Random_
2014-09-18 04:02:59 +00:00
ld a, [hRandomAdd]
2014-05-25 17:26:42 +00:00
pop bc
pop de
pop hl
ret
2014-05-31 08:22:15 +00:00
INCLUDE "home/predef.asm"
2014-05-25 17:26:42 +00:00
2016-06-12 00:24:04 +00:00
UpdateCinnabarGymGateTileBlocks::
2015-07-21 21:21:14 +00:00
jpba UpdateCinnabarGymGateTileBlocks_
2014-05-25 17:26:42 +00:00
2016-06-12 00:24:04 +00:00
CheckForHiddenObjectOrBookshelfOrCardKeyDoor::
2020-07-03 23:59:41 +00:00
ld a, [hLoadedROMBank]
2014-05-25 17:26:42 +00:00
push af
2014-05-25 17:51:53 +00:00
ld a, [hJoyHeld]
2014-09-14 18:29:18 +00:00
bit 0, a ; A button
jr z, .nothingFound
; A button is pressed
ld a, BANK(CheckForHiddenObject)
2014-09-14 18:29:18 +00:00
ld [MBC1RomBank], a
2020-07-03 23:59:41 +00:00
ld [hLoadedROMBank], a
2014-09-14 18:29:18 +00:00
call CheckForHiddenObject
ld a, [hFoundHiddenObject]
2014-05-25 17:26:42 +00:00
and a
2014-09-14 18:29:18 +00:00
jr nz, .hiddenObjectNotFound
ld a, [wHiddenObjectFunctionRomBank]
ld [MBC1RomBank], a
2020-07-03 23:59:41 +00:00
ld [hLoadedROMBank], a
2014-09-14 18:29:18 +00:00
ld de, .returnAddress
2014-05-25 17:26:42 +00:00
push de
jp hl
2014-09-14 18:29:18 +00:00
.returnAddress
2014-05-25 17:26:42 +00:00
xor a
2014-09-14 18:29:18 +00:00
jr .done
.hiddenObjectNotFound
2014-05-25 17:26:42 +00:00
callba PrintBookshelfText
ld a, [hFFDB]
2014-05-25 17:26:42 +00:00
and a
2014-09-14 18:29:18 +00:00
jr z, .done
.nothingFound
2014-05-25 17:26:42 +00:00
ld a, $ff
2014-09-14 18:29:18 +00:00
.done
ld [hFoundHiddenObjectOrBookshelf], a
2014-05-25 17:26:42 +00:00
pop af
2014-09-14 18:29:18 +00:00
ld [MBC1RomBank], a
2020-07-03 23:59:41 +00:00
ld [hLoadedROMBank], a
2014-05-25 17:26:42 +00:00
ret
2016-06-12 00:24:04 +00:00
PrintPredefTextID::
2015-07-24 03:48:35 +00:00
ld [hSpriteIndexOrTextID], a
2014-09-18 04:02:59 +00:00
ld hl, TextPredefs
2014-09-14 18:29:18 +00:00
call SetMapTextPointer
2015-07-15 06:16:06 +00:00
ld hl, wTextPredefFlag
2014-05-25 17:26:42 +00:00
set 0, [hl]
call DisplayTextID
2016-06-12 00:24:04 +00:00
RestoreMapTextPointer::
2015-08-31 02:38:41 +00:00
ld hl, wMapTextPtr
ld a, [hSavedMapTextPtr]
2014-05-25 17:26:42 +00:00
ld [hli], a
ld a, [hSavedMapTextPtr + 1]
2014-05-25 17:26:42 +00:00
ld [hl], a
ret
2016-06-12 00:24:04 +00:00
SetMapTextPointer::
2015-08-31 02:38:41 +00:00
ld a, [wMapTextPtr]
ld [hSavedMapTextPtr], a
2015-08-31 02:38:41 +00:00
ld a, [wMapTextPtr + 1]
ld [hSavedMapTextPtr + 1], a
2014-05-25 17:26:42 +00:00
ld a, l
2015-08-31 02:38:41 +00:00
ld [wMapTextPtr], a
2014-05-25 17:26:42 +00:00
ld a, h
2015-08-31 02:38:41 +00:00
ld [wMapTextPtr + 1], a
2014-05-25 17:26:42 +00:00
ret
2020-07-04 02:57:43 +00:00
INCLUDE "data/text_predef_pointers.asm"