summaryrefslogtreecommitdiff
path: root/yellow/main.asm
diff options
context:
space:
mode:
authorluckytyphlosion <alan.rj.huang@gmail.com>2016-03-17 17:37:20 -0400
committerluckytyphlosion <alan.rj.huang@gmail.com>2016-03-17 18:00:54 -0400
commitbd5a5f70d44a0fef041027be12d439588f863507 (patch)
tree2d0394e028908d087dc2aef3bd4202f55a486e64 /yellow/main.asm
parent16e361c05aa533801a1b5856ec884ffd34f35730 (diff)
Split bank1 up.
Diffstat (limited to 'yellow/main.asm')
-rwxr-xr-xyellow/main.asm1173
1 files changed, 15 insertions, 1158 deletions
diff --git a/yellow/main.asm b/yellow/main.asm
index b528f3bb..2a3f743e 100755
--- a/yellow/main.asm
+++ b/yellow/main.asm
@@ -19,1196 +19,53 @@ INCLUDE "home.asm"
SECTION "bank01",ROMX,BANK[$01]
INCLUDE "data/facing.asm"
-INCLUDE "engine/battle/safari_zone.asm"
-INCLUDE "engine/titlescreen.asm"
-
-LoadMonData_: ; 442b (1:442b)
-; Load monster [wWhichPokemon] from list [wMonDataLocation]:
-; 0: partymon
-; 1: enemymon
-; 2: boxmon
-; 3: daycaremon
-; Return monster id at wcf91 and its data at wLoadedMon.
-; Also load base stats at wMonHeader for convenience.
-
- ld a, [wDayCareMonSpecies]
- ld [wcf91], a
- ld a, [wMonDataLocation]
- cp DAYCARE_DATA
- jr z, .GetMonHeader
-
- ld a, [wWhichPokemon]
- ld e, a
- call GetMonSpecies
-
-.GetMonHeader
- ld a, [wcf91]
- ld [wd0b5], a ; input for GetMonHeader
- call GetMonHeader
-
- ld hl, wPartyMons
- ld bc, wPartyMon2 - wPartyMon1
- ld a, [wMonDataLocation]
- cp ENEMY_PARTY_DATA
- jr c, .getMonEntry
-
- ld hl, wEnemyMons
- jr z, .getMonEntry
-
- cp 2
- ld hl, wBoxMons
- ld bc, wBoxMon2 - wBoxMon1
- jr z, .getMonEntry
- ld hl, wDayCareMon
- jr .copyMonData
+INCLUDE "engine/battle/safari_zone.asm"
-.getMonEntry
- ld a, [wWhichPokemon]
- call AddNTimes
+INCLUDE "engine/titlescreen.asm"
+INCLUDE "engine/load_mon_data.asm"
-.copyMonData
- ld de, wLoadedMon
- ld bc, wPartyMon2 - wPartyMon1
- jp CopyData
-
-; get species of mon e in list [wMonDataLocation] for LoadMonData
-GetMonSpecies: ; 4478 (1:4478)
- ld hl, wPartySpecies
- ld a, [wMonDataLocation]
- and a
- jr z, .getSpecies
- dec a
- jr z, .enemyParty
- ld hl, wBoxSpecies
- jr .getSpecies
-.enemyParty
- ld hl, wEnemyPartyMons
-.getSpecies
- ld d, 0
- add hl, de
- ld a, [hl]
- ld [wcf91], a
- ret
-
INCLUDE "data/item_prices.asm"
INCLUDE "text/item_names.asm"
-
-UnusedNames: ; 491e (1:491e)
- db "かみなりバッヂ@"
- db "かいがらバッヂ@"
- db "おじぞうバッヂ@"
- db "はやぶさバッヂ@"
- db "ひんやりバッヂ@"
- db "なかよしバッヂ@"
- db "バラバッヂ@"
- db "ひのたまバッヂ@"
- db "ゴールドバッヂ@"
- db "たまご@"
- db "ひよこ@"
- db "ブロンズ@"
- db "シルバー@"
- db "ゴールド@"
- db "プチキャプテン@"
- db "キャプテン@"
- db "プチマスター@"
- db "マスター@"
- db "エクセレント"
+INCLUDE "text/unused_names.asm"
INCLUDE "engine/overworld/oam.asm"
-PrintWaitingText: ; 4b89 (1:4b89)
- coord hl, 3, 10
- lb bc, 1, 11
- ld a, [wIsInBattle]
- and a
- jr z, .asm_4b9a
- call TextBoxBorder
- jr .asm_4b9d
-.asm_4b9a
- call CableClub_TextBoxBorder
-.asm_4b9d
- coord hl, 4, 11
- ld de, WaitingText
- call PlaceString
- ld c, 50
- jp DelayFrames
-
-WaitingText: ; 4bab (1:4bab)
- db "Waiting...!@"
-
-_UpdateSprites: ; 4bb7 (1:4bb7)
- ld h, wSpriteStateData1 / $100
- inc h
- ld a, $e ; (wSpriteStateData2 + $0e) & $ff
-.spriteLoop
- ld l, a
- sub $e
- ld c, a
- ld [H_CURRENTSPRITEOFFSET], a
- ld a, [hl]
- and a
- jr z, .skipSprite ; tests $c2Xe
- push hl
- push de
- push bc
- call .updateCurrentSprite
- pop bc
- pop de
- pop hl
-.skipSprite
- ld a, l
- add $10 ; move to next sprite
- cp $e ; test for overflow (back at $0e)
- jr nz, .spriteLoop
- ret
-.updateCurrentSprite ; 4bd7 (1:4bd7)
- ld a, [H_CURRENTSPRITEOFFSET]
- and a
- jp z, UpdatePlayerSprite
- cp $f0 ; pikachu
- jp z, Func_1552
- ld a, [hl]
-
-UpdateNonPlayerSprite: ; 4be3 (1:4be3)
- dec a
- swap a
- ld [$ff93], a ; $10 * sprite#
- ld a, [wNPCMovementScriptSpriteOffset] ; some sprite offset?
- ld b, a
- ld a, [H_CURRENTSPRITEOFFSET]
- cp b
- jr nz, .unequal
- jp DoScriptedNPCMovement
-.unequal
- jp UpdateNPCSprite
-
-; This detects if the current sprite (whose offset is at H_CURRENTSPRITEOFFSET)
-; is going to collide with another sprite by looping over the other sprites.
-; The current sprite's offset will be labelled with i (e.g. $c1i0).
-; The loop sprite's offset will labelled with j (e.g. $c1j0).
-;
-; Note that the Y coordinate of the sprite (in [$c1k4]) is one of the following
-; 9 values when the sprite is aligned with the grid: $fc, $0c, $1c, $2c, ..., $7c.
-; The reason that 4 is added below to the coordinate is to make it align with a
-; multiple of $10 to make comparisons easier.
-DetectCollisionBetweenSprites: ; 4bf7 (1:4bf7)
- ; nop
-
- ld h, wSpriteStateData1 / $100
- ld a, [H_CURRENTSPRITEOFFSET]
- ld l, a
-
- ld a, [hl] ; a = [$c1i0] (picture) (0 if slot is unused)
- and a ; is this sprite slot slot used?
- ret z ; return if not used
-
- ld a, l
- add 3
- ld l, a
-
- ld a, [hli] ; a = [$c1i3] (delta Y) (-1, 0, or 1)
- call SetSpriteCollisionValues
-
- ld a, [hli] ; a = [$C1i4] (Y screen coordinate)
- add 4 ; align with multiple of $10
-
-; The effect of the following 3 lines is to
-; add 7 to a if moving south or
-; subtract 7 from a if moving north.
- add b
- and $f0
- or c
-
- ld [$ff90], a ; store Y coordinate adjusted for direction of movement
-
- ld a, [hli] ; a = [$c1i5] (delta X) (-1, 0, or 1)
- call SetSpriteCollisionValues
- ld a, [hl] ; a = [$C1i6] (X screen coordinate)
-
-; The effect of the following 3 lines is to
-; add 7 to a if moving east or
-; subtract 7 from a if moving west.
- add b
- and $f0
- or c
-
- ld [$ff91], a ; store X coordinate adjusted for direction of movement
-
- ld a, l
- add 7
- ld l, a
-
- xor a
- ld [hld], a ; zero [$c1id] XXX what's [$c1id] for?
- ld [hld], a ; zero [$c1ic] (directions in which collisions occurred)
-
- ld a, [$ff91]
- ld [hld], a ; [$c1ib] = adjusted X coordinate
- ld a, [$ff90]
- ld [hl], a ; [$c1ia] = adjusted Y coordinate
-
- xor a ; zero the loop counter
-
-.loop
- ld [$ff8f], a ; store loop counter
- swap a
- ld e, a
- ld a, [H_CURRENTSPRITEOFFSET]
- cp e ; does the loop sprite match the current sprite?
- jp z, .next ; go to the next sprite if they match
-
- ld d, h
- ld a, [de] ; a = [$c1j0] (picture) (0 if slot is unused)
- and a ; is this sprite slot slot used?
- jp z, .next ; go the next sprite if not used
-
- inc e
- inc e
- ld a, [de] ; a = [$c1j2] ($ff means the sprite is offscreen)
- inc a
- jp z, .next ; go the next sprite if offscreen
-
- ld a, [H_CURRENTSPRITEOFFSET]
- add 10
- ld l, a
-
- inc e
- ld a, [de] ; a = [$c1j3] (delta Y)
- call SetSpriteCollisionValues
-
- inc e
- ld a, [de] ; a = [$C1j4] (Y screen coordinate)
- add 4 ; align with multiple of $10
-
-; The effect of the following 3 lines is to
-; add 7 to a if moving south or
-; subtract 7 from a if moving north.
- add b
- and $f0
- or c
-
- sub [hl] ; subtract the adjusted Y coordinate of sprite i ([$c1ia]) from that of sprite j
-
-; calculate the absolute value of the difference to get the distance
- jr nc, .noCarry1
- cpl
- inc a
-.noCarry1
- ld [$ff90], a ; store the distance between the two sprites' adjusted Y values
-
-; Use the carry flag set by the above subtraction to determine which sprite's
-; Y coordinate is larger. This information is used later to set [$c1ic],
-; which stores which direction the collision occurred in.
-; The following 5 lines set the lowest 2 bits of c, which are later shifted left by 2.
-; If sprite i's Y is larger, set lowest 2 bits of c to 10.
-; If sprite j's Y is larger or both are equal, set lowest 2 bits of c to 01.
- push af
- rl c
- pop af
- ccf
- rl c
-
-; If sprite i's delta Y is 0, then b = 7, else b = 9.
- ld b, 7
- ld a, [hl] ; a = [$c1ia] (adjusted Y coordinate)
- and $f
- jr z, .next1
- ld b, 9
-
-.next1
- ld a, [$ff90] ; a = distance between adjusted Y coordinates
- sub b
- ld [$ff92], a ; store distance adjusted using sprite i's direction
- ld a, b
- ld [$ff90], a ; store 7 or 9 depending on sprite i's delta Y
- jr c, .checkXDistance
-
-; If sprite j's delta Y is 0, then b = 7, else b = 9.
- ld b, 7
- dec e
- ld a, [de] ; a = [$c1j3] (delta Y)
- inc e
- and a
- jr z, .next2
- ld b, 9
-
-.next2
- ld a, [$ff92] ; a = distance adjusted using sprite i's direction
- sub b ; adjust distance using sprite j's direction
- jr z, .checkXDistance
- jr nc, .next ; go to next sprite if distance is still positive after both adjustments
-
-.checkXDistance
- inc e
- inc l
- ld a, [de] ; a = [$c1j5] (delta X)
-
- push bc
-
- call SetSpriteCollisionValues
- inc e
- ld a, [de] ; a = [$c1j6] (X screen coordinate)
-
-; The effect of the following 3 lines is to
-; add 7 to a if moving east or
-; subtract 7 from a if moving west.
- add b
- and $f0
- or c
-
- pop bc
-
- sub [hl] ; subtract the adjusted X coordinate of sprite i ([$c1ib]) from that of sprite j
-
-; calculate the absolute value of the difference to get the distance
- jr nc, .noCarry2
- cpl
- inc a
-.noCarry2
- ld [$ff91], a ; store the distance between the two sprites' adjusted X values
-
-; Use the carry flag set by the above subtraction to determine which sprite's
-; X coordinate is larger. This information is used later to set [$c1ic],
-; which stores which direction the collision occurred in.
-; The following 5 lines set the lowest 2 bits of c.
-; If sprite i's X is larger, set lowest 2 bits of c to 10.
-; If sprite j's X is larger or both are equal, set lowest 2 bits of c to 01.
- push af
- rl c
- pop af
- ccf
- rl c
-
-; If sprite i's delta X is 0, then b = 7, else b = 9.
- ld b, 7
- ld a, [hl] ; a = [$c1ib] (adjusted X coordinate)
- and $f
- jr z, .next3
- ld b, 9
-
-.next3
- ld a, [$ff91] ; a = distance between adjusted X coordinates
- sub b
- ld [$ff92], a ; store distance adjusted using sprite i's direction
- ld a, b
- ld [$ff91], a ; store 7 or 9 depending on sprite i's delta X
- jr c, .collision
-
-; If sprite j's delta X is 0, then b = 7, else b = 9.
- ld b, 7
- dec e
- ld a, [de] ; a = [$c1j5] (delta X)
- inc e
- and a
- jr z, .next4
- ld b, 9
-
-.next4
- ld a, [$ff92] ; a = distance adjusted using sprite i's direction
- sub b ; adjust distance using sprite j's direction
- jr z, .collision
- jr nc, .next ; go to next sprite if distance is still positive after both adjustments
-
-.collision
- ld a, l
- and $f0 ; collision with pikachu?
- jr nz, .asm_4cd9
- xor a
- ld [wd434], a
- ld a, [$ff8f]
- cp $f
- jr nz, .asm_4cd9
- call Func_4d0a
- jr .asm_4cef
-.asm_4cd9
- ld a, [$ff91] ; a = 7 or 9 depending on sprite i's delta X
- ld b, a
- ld a, [$ff90] ; a = 7 or 9 depending on sprite i's delta Y
- inc l
-
-; If delta X isn't 0 and delta Y is 0, then b = %0011, else b = %1100.
-; (note that normally if delta X isn't 0, then delta Y must be 0 and vice versa)
- cp b
- jr c, .next5
- ld b, %1100
- jr .next6
-.next5
- ld b, %0011
-
-.next6
- ld a, c ; c has 2 bits set (one of bits 0-1 is set for the X axis and one of bits 2-3 for the Y axis)
- and b ; we select either the bit in bits 0-1 or bits 2-3 based on the calculation immediately above
- or [hl] ; or with existing collision direction bits in [$c1ic]
- ld [hl], a ; store new value
- ld a, c ; useless code because a is overwritten before being used again
-
-; set bit in [$c1ie] or [$c1if] to indicate which sprite the collision occurred with
- inc l
- inc l
-.asm_4cef
- ld a, [$ff8f] ; a = loop counter
- ld de, SpriteCollisionBitTable
- add a
- add e
- ld e, a
- jr nc, .noCarry3
- inc d
-.noCarry3
- ld a, [de]
- or [hl]
- ld [hli], a
- inc de
- ld a, [de]
- or [hl]
- ld [hl], a
-
-.next
- ld a, [$ff8f] ; a = loop counter
- inc a
- cp $10
- jp nz, .loop
- ret
+INCLUDE "engine/print_waiting_text.asm"
-; takes delta X or delta Y in a
-; b = delta X/Y
-; c = 0 if delta X/Y is 0
-; c = 7 if delta X/Y is 1
-; c = 9 if delta X/Y is -1
-Func_4d0a: ; 4d0a (1:4d0a)
- ld a, [$ff91]
- ld b, a
- ld a, [$ff90]
- inc l
- cp b
- jr c, .asm_4d17
- ld b, %1100
- jr .asm_4d19
-.asm_4d17
- ld b, %11
-.asm_4d19
- ld a, c
- and b
- ld [wd434], a
- ld a, c
- inc l
- inc l
- ret
-
-SetSpriteCollisionValues: ; 4d22 (1:4d22)
- and a
- ld b, 0
- ld c, 0
- jr z, .done
- ld c, 9
- cp -1
- jr z, .ok
- ld c, 7
- ld a, 0
-.ok
- ld b, a
-.done
- ret
-
-SpriteCollisionBitTable: ; 4d35 (1:4d35)
- db %00000000,%00000001
- db %00000000,%00000010
- db %00000000,%00000100
- db %00000000,%00001000
- db %00000000,%00010000
- db %00000000,%00100000
- db %00000000,%01000000
- db %00000000,%10000000
- db %00000001,%00000000
- db %00000010,%00000000
- db %00000100,%00000000
- db %00001000,%00000000
- db %00010000,%00000000
- db %00100000,%00000000
- db %01000000,%00000000
- db %10000000,%00000000
-
+INCLUDE "engine/overworld/map_sprite_functions1.asm"
INCLUDE "engine/overworld/item.asm"
INCLUDE "engine/overworld/movement.asm"
-
INCLUDE "engine/cable_club.asm"
-
-LoadTrainerInfoTextBoxTiles: ; 5b9a (1:5b9a)
- ld de, TrainerInfoTextBoxTileGraphics
- ld hl, vChars2 + $760
- lb bc, BANK(TrainerInfoTextBoxTileGraphics), (TrainerInfoTextBoxTileGraphicsEnd - TrainerInfoTextBoxTileGraphics) / $10
- jp CopyVideoData
-
INCLUDE "engine/menu/main_menu.asm"
-
INCLUDE "engine/oak_speech.asm"
-
-SpecialWarpIn: ; 6042 (1:6042)
- call LoadSpecialWarpData
- predef LoadTilesetHeader
- ld hl,wd732
- bit 2,[hl] ; dungeon warp or fly warp?
- res 2,[hl]
- jr z,.next
-; if dungeon warp or fly warp
- ld a,[wDestinationMap]
- jr .next2
-.next
- bit 1,[hl]
- jr z,.next3
- call EmptyFunc
-.next3
- ld a,0
-.next2
- ld b,a
- ld a,[wd72d]
- and a
- jr nz,.next4
- ld a,b
-.next4
- ld hl,wd732
- bit 4,[hl] ; dungeon warp?
- ret nz
-; if not dungeon warp
- ld [wLastMap],a
- ret
-
-; gets the map ID, tile block map view pointer, tileset, and coordinates
-LoadSpecialWarpData: ; 6073 (1:6073)
- ld a, [wd72d]
- cp TRADE_CENTER
- jr nz, .notTradeCenter
- ld hl, TradeCenterSpec1
- ld a, [hSerialConnectionStatus]
- cp USING_INTERNAL_CLOCK ; which gameboy is clocking determines who is on the left and who is on the right
- jr z, .copyWarpData
- ld hl, TradeCenterSpec2
- jr .copyWarpData
-.notTradeCenter
- cp COLOSSEUM
- jr nz, .notColosseum
- ld hl, ColosseumSpec1
- ld a, [hSerialConnectionStatus]
- cp USING_INTERNAL_CLOCK
- jr z, .copyWarpData
- ld hl, ColosseumSpec2
- jr .copyWarpData
-.notColosseum
- ld a, [wd732]
- bit 1, a
- jr nz, .notFirstMap
- bit 2, a
- jr nz, .notFirstMap
- ld hl, FirstMapSpec
-.copyWarpData
- ld de, wCurMap
- ld c, $7
-.copyWarpDataLoop
- ld a, [hli]
- ld [de], a
- inc de
- dec c
- jr nz, .copyWarpDataLoop
- ld a, [hli]
- ld [wCurMapTileset], a
- xor a
- jr .done
-.notFirstMap
- ld a, [wLastMap]
- ld hl, wd732
- bit 4, [hl] ; used dungeon warp (jumped down hole/waterfall)?
- jr nz, .usedDunegonWarp
- bit 6, [hl] ; return to last pokemon center (or player's house)?
- res 6, [hl]
- jr z, .otherDestination
-; return to last pokemon center or player's house
- ld a, [wLastBlackoutMap]
- jr .usedFlyWarp
-.usedDunegonWarp
- ld hl, wd72d
- res 4, [hl]
- ld a, [wDungeonWarpDestinationMap]
- ld b, a
- ld [wCurMap], a
- ld a, [wWhichDungeonWarp]
- ld c, a
- ld hl, DungeonWarpList
- ld de, 0
- ld a, 6
- ld [wDungeonWarpDataEntrySize], a
-.dungeonWarpListLoop
- ld a, [hli]
- cp b
- jr z, .matchedDungeonWarpDestinationMap
- inc hl
- jr .nextDungeonWarp
-.matchedDungeonWarpDestinationMap
- ld a, [hli]
- cp c
- jr z, .matchedDungeonWarpID
-.nextDungeonWarp
- ld a, [wDungeonWarpDataEntrySize]
- add e
- ld e, a
- jr .dungeonWarpListLoop
-.matchedDungeonWarpID
- ld hl, DungeonWarpData
- add hl, de
- jr .copyWarpData2
-.otherDestination
- ld a, [wDestinationMap]
-.usedFlyWarp
- ld b, a
- ld [wCurMap], a
- ld hl, FlyWarpDataPtr
-.flyWarpDataPtrLoop
- ld a, [hli]
- inc hl
- cp b
- jr z, .foundFlyWarpMatch
- inc hl
- inc hl
- jr .flyWarpDataPtrLoop
-.foundFlyWarpMatch
- ld a, [hli]
- ld h, [hl]
- ld l, a
-.copyWarpData2
- ld de, wCurrentTileBlockMapViewPointer
- ld c, $6
-.copyWarpDataLoop2
- ld a, [hli]
- ld [de], a
- inc de
- dec c
- jr nz, .copyWarpDataLoop2
- xor a ; OVERWORLD
- ld [wCurMapTileset], a
-.done
- ld [wYOffsetSinceLastSpecialWarp], a
- ld [wXOffsetSinceLastSpecialWarp], a
- ld a, $ff ; the player's coordinates have already been updated using a special warp, so don't use any of the normal warps
- ld [wDestinationWarpID], a
- ret
+INCLUDE "engine/overworld/special_warps.asm"
INCLUDE "data/special_warps.asm"
-; not IshiharaTeam
-SetDebugTeam: ; 623e (1:623e)
- ld de, DebugTeam
-.loop
- ld a, [de]
- cp $ff
- ret z
- ld [wcf91], a
- inc de
- ld a, [de]
- ld [wCurEnemyLVL], a
- inc de
- call AddPartyMon
- jr .loop
-
-DebugTeam: ; 6253 (1:6253)
- db SNORLAX,80
- db PERSIAN,80
- db JIGGLYPUFF,15
- db PIKACHU,5
- db $FF
-EmptyFunc: ; 64ea (1:64ea)
- ret
+INCLUDE "engine/debug1.asm"
INCLUDE "engine/menu/naming_screen.asm"
INCLUDE "engine/oak_speech2.asm"
-; subtracts the amount the player paid from their money
-; sets carry flag if there is enough money and unsets carry flag if not
-SubtractAmountPaidFromMoney_: ; 68a6 (1:68a6)
- ld de, wPlayerMoney
- ld hl, hMoney ; total price of items
- ld c, 3 ; length of money in bytes
- call StringCmp
- ret c
- ld de, wPlayerMoney + 2
- ld hl, hMoney + 2 ; total price of items
- ld c, 3 ; length of money in bytes
- predef SubBCDPredef ; subtract total price from money
- ld a, MONEY_BOX
- ld [wTextBoxID], a
- call DisplayTextBoxID ; redraw money text box
- and a
- ret
+INCLUDE "engine/subtract_paid_money.asm"
-HandleItemListSwapping: ; 68c9 (1:68c9)
- ld a,[wListMenuID]
- cp a,ITEMLISTMENU
- jp nz,DisplayListMenuIDLoop ; only rearrange item list menus
- push hl
- ld hl,wListPointer
- ld a,[hli]
- ld h,[hl]
- ld l,a
- inc hl ; hl = beginning of list entries
- ld a,[wCurrentMenuItem]
- ld b,a
- ld a,[wListScrollOffset]
- add b
- add a
- ld c,a
- ld b,0
- add hl,bc ; hl = address of currently selected item entry
- ld a,[hl]
- pop hl
- inc a
- jp z,DisplayListMenuIDLoop ; ignore attempts to swap the Cancel menu item
- ld a,[wMenuItemToSwap] ; ID of item chosen for swapping (counts from 1)
- and a ; has the first item to swap already been chosen?
- jr nz,.swapItems
-; if not, set the currently selected item as the first item
- ld a,[wCurrentMenuItem]
- inc a
- ld b,a
- ld a,[wListScrollOffset] ; index of top (visible) menu item within the list
- add b
- ld [wMenuItemToSwap],a ; ID of item chosen for swapping (counts from 1)
- ld c,20
- call DelayFrames
- jp DisplayListMenuIDLoop
-.swapItems
- ld a,[wCurrentMenuItem]
- inc a
- ld b,a
- ld a,[wListScrollOffset]
- add b
- ld b,a
- ld a,[wMenuItemToSwap] ; ID of item chosen for swapping (counts from 1)
- cp b ; is the currently selected item the same as the first item to swap?
- jp z,DisplayListMenuIDLoop ; ignore attempts to swap an item with itself
- dec a
- ld [wMenuItemToSwap],a ; ID of item chosen for swapping (counts from 1)
- ld c,20
- call DelayFrames
- push hl
- push de
- ld hl,wListPointer
- ld a,[hli]
- ld h,[hl]
- ld l,a
- inc hl ; hl = beginning of list entries
- ld d,h
- ld e,l ; de = beginning of list entries
- ld a,[wCurrentMenuItem]
- ld b,a
- ld a,[wListScrollOffset]
- add b
- add a
- ld c,a
- ld b,0
- add hl,bc ; hl = address of currently selected item entry
- ld a,[wMenuItemToSwap] ; ID of item chosen for swapping (counts from 1)
- add a
- add e
- ld e,a
- jr nc,.noCarry
- inc d
-.noCarry ; de = address of first item to swap
- ld a,[de]
- ld b,a
- ld a,[hli]
- cp b
- jr z,.swapSameItemType
-.swapDifferentItems
- ld [$ff95],a ; [$ff95] = second item ID
- ld a,[hld]
- ld [$ff96],a ; [$ff96] = second item quantity
- ld a,[de]
- ld [hli],a ; put first item ID in second item slot
- inc de
- ld a,[de]
- ld [hl],a ; put first item quantity in second item slot
- ld a,[$ff96]
- ld [de],a ; put second item quantity in first item slot
- dec de
- ld a,[$ff95]
- ld [de],a ; put second item ID in first item slot
- xor a
- ld [wMenuItemToSwap],a ; 0 means no item is currently being swapped
- pop de
- pop hl
- jp DisplayListMenuIDLoop
-.swapSameItemType
- inc de
- ld a,[hl]
- ld b,a
- ld a,[de]
- add b ; a = sum of both item quantities
- cp a,100 ; is the sum too big for one item slot?
- jr c,.combineItemSlots
-; swap enough items from the first slot to max out the second slot if they can't be combined
- sub a,99
- ld [de],a
- ld a,99
- ld [hl],a
- jr .done
-.combineItemSlots
- ld [hl],a ; put the sum in the second item slot
- ld hl,wListPointer
- ld a,[hli]
- ld h,[hl]
- ld l,a
- dec [hl] ; decrease the number of items
- ld a,[hl]
- ld [wListCount],a ; update number of items variable
- cp a,1
- jr nz,.skipSettingMaxMenuItemID
- ld [wMaxMenuItem],a ; if the number of items is only one now, update the max menu item ID
-.skipSettingMaxMenuItemID
- dec de
- ld h,d
- ld l,e
- inc hl
- inc hl ; hl = address of item after first item to swap
-.moveItemsUpLoop ; erase the first item slot and move up all the following item slots to fill the gap
- ld a,[hli]
- ld [de],a
- inc de
- inc a ; reached the $ff terminator?
- jr z,.afterMovingItemsUp
- ld a,[hli]
- ld [de],a
- inc de
- jr .moveItemsUpLoop
-.afterMovingItemsUp
- xor a
- ld [wListScrollOffset],a
- ld [wCurrentMenuItem],a
-.done
- xor a
- ld [wMenuItemToSwap],a ; 0 means no item is currently being swapped
- pop de
- pop hl
- jp DisplayListMenuIDLoop
+INCLUDE "engine/menu/swap_items.asm"
INCLUDE "engine/overworld/pokemart.asm"
INCLUDE "engine/learn_move.asm"
INCLUDE "engine/overworld/pokecenter.asm"
+INCLUDE "engine/overworld/set_blackout_map.asm"
-SetLastBlackoutMap: ; 6ef0 (1:6ef0)
-; Set the map to return to when
-; blacking out or using Teleport or Dig.
-; Safari rest houses don't count.
-
- push hl
- ld hl, SafariZoneRestHouses
- ld a, [wCurMap]
- ld b, a
-.loop
- ld a, [hli]
- cp -1
- jr z, .notresthouse
- cp b
- jr nz, .loop
- jr .done
-
-.notresthouse
- ld a, [wLastMap]
- ld [wLastBlackoutMap], a
-.done
- pop hl
- ret
-
-SafariZoneRestHouses: ; 6f0a (1:6f0a)
- db SAFARI_ZONE_REST_HOUSE_2
- db SAFARI_ZONE_REST_HOUSE_3
- db SAFARI_ZONE_REST_HOUSE_4
- db -1
-
-; function that performs initialization for DisplayTextID
-DisplayTextIDInit: ; 6f0e (1:6f0e)
- xor a
- ld [wListMenuID],a
- ld a,[wAutoTextBoxDrawingControl]
- bit 0,a
- jr nz,.skipDrawingTextBoxBorder
- ld a,[hSpriteIndexOrTextID] ; text ID (or sprite ID)
- and a
- jr nz,.notStartMenu
-; if text ID is 0 (i.e. the start menu)
-; Note that the start menu text border is also drawn in the function directly
-; below this, so this seems unnecessary.
- CheckEvent EVENT_GOT_POKEDEX
-; start menu with pokedex
- coord hl, 10, 0
- lb bc, 14, 8
- jr nz,.drawTextBoxBorder
-; start menu without pokedex
- coord hl, 10, 0
- lb bc, 12, 8
- jr .drawTextBoxBorder
-; if text ID is not 0 (i.e. not the start menu) then do a standard dialogue text box
-.notStartMenu
- coord hl, 0, 12
- lb bc, 4, 18
-.drawTextBoxBorder
- call TextBoxBorder
-.skipDrawingTextBoxBorder
- ld hl,wFontLoaded
- set 0,[hl]
- ld hl,wFlags_0xcd60
- bit 4,[hl]
- res 4,[hl]
- jr nz,.skipMovingSprites
- call UpdateSprites
-.skipMovingSprites
-; loop to copy C1X9 (direction the sprite is facing) to C2X9 for each sprite
-; this is done because when you talk to an NPC, they turn to look your way
-; the original direction they were facing must be restored after the dialogue is over
- ld hl,wSpriteStateData1 + $19
- ld c,$0f
- ld de,$0010
-.spriteFacingDirectionCopyLoop
- ld a,[hl]
- inc h
- ld [hl],a
- dec h
- add hl,de
- dec c
- jr nz,.spriteFacingDirectionCopyLoop
-; loop to force all the sprites in the middle of animation to stand still
-; (so that they don't like they're frozen mid-step during the dialogue)
- ld hl,wSpriteStateData1 + 2
- ld de,$0010
- ld c,e
-.spriteStandStillLoop
- ld a,[hl]
- cp a,$ff ; is the sprite visible?
- jr z,.nextSprite
-; if it is visible
- and a,$fc
- ld [hl],a
-.nextSprite
- add hl,de
- dec c
- jr nz,.spriteStandStillLoop
- ld b,vBGMap1 / $100 ; window background address
- call CopyScreenTileBufferToVRAM ; transfer background in WRAM to VRAM
- xor a
- ld [hWY],a ; put the window on the screen
- call LoadFontTilePatterns
- ld a,$01
- ld [H_AUTOBGTRANSFERENABLED],a ; enable continuous WRAM to VRAM transfer each V-blank
- ret
-
-; function that displays the start menu
-DrawStartMenu: ; 6f80 (1:6f80)
- CheckEvent EVENT_GOT_POKEDEX
-; menu with pokedex
- coord hl, 10, 0
- lb bc, 14, 8
- jr nz,.drawTextBoxBorder
-; shorter menu if the player doesn't have the pokedex
- coord hl, 10, 0
- lb bc, 12, 8
-.drawTextBoxBorder
- call TextBoxBorder
- ld a,D_DOWN | D_UP | START | B_BUTTON | A_BUTTON
- ld [wMenuWatchedKeys],a
- ld a,$02
- ld [wTopMenuItemY],a ; Y position of first menu choice
- ld a,$0b
- ld [wTopMenuItemX],a ; X position of first menu choice
- ld a,[wBattleAndStartSavedMenuItem] ; remembered menu selection from last time
- ld [wCurrentMenuItem],a
- ld [wLastMenuItem],a
- xor a
- ld [wMenuWatchMovingOutOfBounds],a
- ld hl,wd730
- set 6,[hl] ; no pauses between printing each letter
- coord hl, 12, 2
- CheckEvent EVENT_GOT_POKEDEX
-; case for not having pokdex
- ld a,$06
- jr z,.storeMenuItemCount
-; case for having pokedex
- ld de,StartMenuPokedexText
- call PrintStartMenuItem
- ld a,$07
-.storeMenuItemCount
- ld [wMaxMenuItem],a ; number of menu items
- ld de,StartMenuPokemonText
- call PrintStartMenuItem
- ld de,StartMenuItemText
- call PrintStartMenuItem
- ld de,wPlayerName ; player's name
- call PrintStartMenuItem
- ld a,[wd72e]
- bit 6,a ; is the player using the link feature?
-; case for not using link feature
- ld de,StartMenuSaveText
- jr z,.printSaveOrResetText
-; case for using link feature
- ld de,StartMenuResetText
-.printSaveOrResetText
- call PrintStartMenuItem
- ld de,StartMenuOptionText
- call PrintStartMenuItem
- ld de,StartMenuExitText
- call PlaceString
- ld hl,wd730
- res 6,[hl] ; turn pauses between printing letters back on
- ret
-
-StartMenuPokedexText: ; 7002 (1:7002)
- db "POKéDEX@"
-
-StartMenuPokemonText: ; 700a (1:700a)
- db "#MON@"
-
-StartMenuItemText: ; 700f (1:700f)
- db "ITEM@"
-
-StartMenuSaveText: ; 7014 (1:7014)
- db "SAVE@"
-
-StartMenuResetText: ; 7019 (1:7019)
- db "RESET@"
-
-StartMenuExitText: ; 701f (1:701f)
- db "EXIT@"
-
-StartMenuOptionText: ; 7024 (1:7024)
- db "OPTION@"
-
-PrintStartMenuItem: ; 702b (1:702b)
- push hl
- call PlaceString
- pop hl
- ld de,SCREEN_WIDTH * 2
- add hl,de
- ret
-
+INCLUDE "engine/menu/text_ids1.asm"
INCLUDE "engine/overworld/cable_club_npc.asm"
+INCLUDE "engine/menu/text_ids2.asm"
-INCLUDE "engine/text_boxes.asm"
INCLUDE "engine/battle/moveEffects/drain_hp_effect.asm"
-
INCLUDE "engine/menu/players_pc.asm"
-
-_RemovePokemon: ; 7a0f (1:7a0f)
- ld hl, wPartyCount
- ld a, [wRemoveMonFromBox]
- and a
- jr z, .usePartyCount
- ld hl, wNumInBox
-.usePartyCount
- ld a, [hl]
- dec a
- ld [hli], a
- ld a, [wWhichPokemon]
- ld c, a
- ld b, $0
- add hl, bc
- ld e, l
- ld d, h
- inc de
-.shiftMonSpeciesLoop
- ld a, [de]
- inc de
- ld [hli], a
- inc a ; reached terminator?
- jr nz, .shiftMonSpeciesLoop ; if not, continue shifting species
- ld hl, wPartyMonOT
- ld d, PARTY_LENGTH - 1 ; max number of pokemon to shift
- ld a, [wRemoveMonFromBox]
- and a
- jr z, .usePartyMonOTs
- ld hl, wBoxMonOT
- ld d, MONS_PER_BOX - 1
-.usePartyMonOTs
- ld a, [wWhichPokemon]
- call SkipFixedLengthTextEntries
- ld a, [wWhichPokemon]
- cp d ; are we removing the last pokemon?
- jr nz, .notRemovingLastMon ; if not, shift the pokemon below
- ld [hl], $ff ; else, write the terminator and return
- ret
-.notRemovingLastMon
- ld d, h
- ld e, l
- ld bc, NAME_LENGTH
- add hl, bc
- ld bc, wPartyMonNicks
- ld a, [wRemoveMonFromBox]
- and a
- jr z, .usePartyMonNicks
- ld bc, wBoxMonNicks
-.usePartyMonNicks
- call CopyDataUntil
- ld hl, wPartyMons
- ld bc, wPartyMon2 - wPartyMon1
- ld a, [wRemoveMonFromBox]
- and a
- jr z, .usePartyMonStructs
- ld hl, wBoxMons
- ld bc, wBoxMon2 - wBoxMon1
-.usePartyMonStructs
- ld a, [wWhichPokemon]
- call AddNTimes ; get address of the pokemon removed
- ld d, h ; store in de for CopyDataUntil
- ld e, l
- ld a, [wRemoveMonFromBox]
- and a
- jr z, .copyUntilPartyMonOTs
- ld bc, wBoxMon2 - wBoxMon1
- add hl, bc ; get address of pokemon after the pokemon removed
- ld bc, wBoxMonOT ; address of when to stop copying
- jr .continue
-.copyUntilPartyMonOTs
- ld bc, wPartyMon2 - wPartyMon1
- add hl, bc ; get address of pokemon after the pokemon removed
- ld bc, wPartyMonOT ; address of when to stop copying
-.continue
- call CopyDataUntil ; shift all pokemon data after the removed mon to the removed mon's location
- ld hl, wPartyMonNicks
- ld a, [wRemoveMonFromBox]
- and a
- jr z, .usePartyMonNicks2
- ld hl, wBoxMonNicks
-.usePartyMonNicks2
- ld bc, NAME_LENGTH
- ld a, [wWhichPokemon]
- call AddNTimes
- ld d, h
- ld e, l
- ld bc, NAME_LENGTH
- add hl, bc
- ld bc, wPartyMonNicksEnd
- ld a, [wRemoveMonFromBox]
- and a
- jr z, .copyUntilPartyMonNicksEnd
- ld bc, wBoxMonNicksEnd
-.copyUntilPartyMonNicksEnd
- jp CopyDataUntil
-
-_DisplayPokedex: ; 7abf (1:7abf)
- ld hl, wd730
- set 6, [hl]
- predef ShowPokedexData
- ld hl, wd730
- res 6, [hl]
- call ReloadMapData
- ld c, 10
- call DelayFrames
- predef IndexToPokedex
- ld a, [wd11e]
- dec a
- ld c, a
- ld b, FLAG_SET
- ld hl, wPokedexSeen
- predef FlagActionPredef
- ld a, $1
- ld [wDoNotWaitForButtonPressAfterDisplayingText], a
- ret
+INCLUDE "engine/remove_pokemon.asm"
+INCLUDE "engine/display_pokedex.asm"
SECTION "bank03",ROMX,BANK[$03]