From 44cdca9cdde8d673f2971bd8926b385d41802102 Mon Sep 17 00:00:00 2001 From: Zumi <13794376+ZoomTen@users.noreply.github.com> Date: Sat, 18 Nov 2023 10:40:28 +0700 Subject: [PATCH] (Partially) dump banks $0D and $0F (#99) * Bank $0f dumping (will not build) * Optimize title logo graphic * Make buildable again * Add some more labels to bank $0f * Add bank $0d, non-building * fix erroneous shim * bank $0D dump buildable * Make buildable again --------- Co-authored-by: vulcandth --- data/predef_pointers.inc | 2 +- .../{type_matchups.asm => type_matchups.inc} | 4 - engine/debug/field/vram_viewer.inc | 2 +- engine/dumps/bank03.asm | 9 +- engine/dumps/bank0b.asm | 4 +- engine/dumps/bank0d.asm | 11220 ++++++++++++++++ engine/dumps/bank0f.asm | 6583 +++++++++ engine/menu/start_menu.asm | 6 +- gfx/gfx.mk | 2 + gfx/title/title_logo.png | Bin 618 -> 776 bytes gfx/trainer/oldman_back.png | Bin 0 -> 259 bytes gfx/trainer/protagonist_back.png | Bin 0 -> 458 bytes home/menu.asm | 1 + layout.link | 8 +- ram/hram.asm | 7 +- ram/wram.asm | 271 +- shim.sym | 80 +- 17 files changed, 18126 insertions(+), 73 deletions(-) rename data/types/{type_matchups.asm => type_matchups.inc} (98%) create mode 100644 engine/dumps/bank0d.asm create mode 100644 engine/dumps/bank0f.asm create mode 100644 gfx/trainer/oldman_back.png create mode 100644 gfx/trainer/protagonist_back.png mode change 100755 => 100644 shim.sym diff --git a/data/predef_pointers.inc b/data/predef_pointers.inc index 51d20396..9e184b93 100644 --- a/data/predef_pointers.inc +++ b/data/predef_pointers.inc @@ -46,7 +46,7 @@ GiveItemPredef:: add_predef PlaceGraphic add_predef Function3f068 ; 20 add_predef Function3f04a - add_predef Function3d08c + add_predef AnyPartyAlive add_predef Function3d67c add_predef Function3e1a4 add_predef Function3ef19 diff --git a/data/types/type_matchups.asm b/data/types/type_matchups.inc similarity index 98% rename from data/types/type_matchups.asm rename to data/types/type_matchups.inc index 03b5910c..272981c7 100644 --- a/data/types/type_matchups.asm +++ b/data/types/type_matchups.inc @@ -1,7 +1,3 @@ -INCLUDE "constants.asm" - -SECTION "data/types/type_matchups.asm", ROMX - TypeMatchups: ; attacker, defender, *= db TYPE_NORMAL, TYPE_ROCK, NOT_VERY_EFFECTIVE diff --git a/engine/debug/field/vram_viewer.inc b/engine/debug/field/vram_viewer.inc index 668d1df4..ccf2a49b 100644 --- a/engine/debug/field/vram_viewer.inc +++ b/engine/debug/field/vram_viewer.inc @@ -151,7 +151,7 @@ FieldDebug_DoVRAMViewer: ld bc, $180 tiles call ByteFill call LoadFont - callab Function3e39f + callab Call_LoadBattleGraphics xor a ldh [hMapAnims], a call EnableLCD diff --git a/engine/dumps/bank03.asm b/engine/dumps/bank03.asm index 519d2a19..ac37d4ae 100755 --- a/engine/dumps/bank03.asm +++ b/engine/dumps/bank03.asm @@ -3466,8 +3466,8 @@ Textec69: Functionec7a: call ClearPalettes - ld hl, Function3e39f - ld a, BANK(Function3e39f) + ld hl, Call_LoadBattleGraphics + ld a, BANK(Call_LoadBattleGraphics) call FarCall_hl call GetMemSGBLayout call CloseWindow @@ -4424,8 +4424,9 @@ Functionf318: call WaitBGMap xor a ldh [hBattleTurn], a - ld a, BANK(Function3e5bf) - ld hl, Function3e5bf +; wrong bank + ld a, $f + ld hl, Function365bf call FarCall_hl pop hl pop af diff --git a/engine/dumps/bank0b.asm b/engine/dumps/bank0b.asm index f1b484af..bc25e05f 100644 --- a/engine/dumps/bank0b.asm +++ b/engine/dumps/bank0b.asm @@ -226,10 +226,10 @@ asm_2d4a3: call PlaceString ld a, [wCurSpecies] dec a - ld hl, Data4a8b8 + ld hl, Data418b8 ld bc, $7 call AddNTimes - ld a, BANK(Data4a8b8) + ld a, BANK(Data418b8) call GetFarByte ld hl, $c3a0 cp $2 diff --git a/engine/dumps/bank0d.asm b/engine/dumps/bank0d.asm new file mode 100644 index 00000000..0b732e76 --- /dev/null +++ b/engine/dumps/bank0d.asm @@ -0,0 +1,11220 @@ +INCLUDE "constants.asm" + +SECTION "engine/dumps/bank0d.asm@Function34000", ROMX +Function34000: + xor a + ldh [hBattleTurn], a + ld a, [wFieldMoveSucceeded] + and a + ret nz + xor a + ld [wca7d], a + call sub_34677 + ld a, [wca7d] + and a + ret nz + call Function360b1 + ld a, [wc9f0] + jr Function34046 + +Function3401c: + ld a, 1 + ldh [hBattleTurn], a + ld a, [wLinkMode] + and a + jr z, asm_34030 + ld a, [wOtherPlayerLinkAction] + cp $e + jr z, asm_34030 + cp 4 + ret nc + +asm_34030: + xor a + ld [wca7d], a + call sub_34677 + ld a, [wca7d] + and a + ret nz + ld hl, wcaba + inc [hl] + call Function360b1 + ld a, [wc9e9] + +Function34046: + ld b, 0 + ld c, a + ld hl, Data3409d + add hl, bc + add hl, bc + ld a, [hli] + ld h, [hl] + ld l, a + ld de, wca5d + +asm_34054: + ld a, [hli] + ld [de], a + inc de + cp $ff + jr nz, asm_34054 + ld hl, wca5d + ld a, l + ld [wca7b], a + ld a, h + ld [wca7c], a + +asm_34066: + push bc + ld a, [wca7b] + ld l, a + ld a, [wca7c] + ld h, a + ld a, [hli] + ld c, a + cp $ff + ld a, l + ld [wca7b], a + ld a, h + ld [wca7c], a + jr z, asm_3409b + dec c + ld b, 0 + ld hl, Data34599 + add hl, bc + add hl, bc + ld a, [hli] + ld [wPredefBC + 1], a + ld a, [hl] + ld [wPredefBC], a + pop bc + ld hl, asm_34066 + push hl + ld a, [wPredefBC + 1] + ld l, a + ld a, [wPredefBC] + ld h, a + jp hl + +asm_3409b: + pop bc + ret + +Data3409d: + dw Data341b5 + dw Data341c9 + dw Data341d1 + dw Data341e5 + dw Data341f8 + dw Data3420c + dw Data34220 + dw Data34234 + dw Data34249 + dw Data3425b + dw Data34261 + dw Data34261 + dw Data34261 + dw Data34261 + dw Data34261 + dw Data34261 + dw Data34261 + dw Data341b5 + dw Data34266 + dw Data34266 + dw Data34266 + dw Data34266 + dw Data34266 + dw Data34266 + dw Data34266 + dw Data34299 + dw Data3429e + dw Data342ab + dw Data342c1 + dw Data342c6 + dw Data34294 + dw Data342dc + dw Data34339 + dw Data34348 + dw Data3427f + dw Data34343 + dw Data341b5 + dw Data342dc + dw Data342f0 + dw Data3438e + dw Data343b9 + dw Data343b9 + dw Data343a4 + dw Data3438e + dw Data342c6 + dw Data341b5 + dw Data34314 + dw Data34319 + dw Data342ff + dw Data3431e + dw Data34261 + dw Data34261 + dw Data34261 + dw Data34261 + dw Data34261 + dw Data34261 + dw Data34261 + dw Data3433e + dw Data34266 + dw Data34266 + dw Data34266 + dw Data34266 + dw Data34266 + dw Data34266 + dw Data34266 + dw Data34343 + dw Data34348 + dw Data34350 + dw Data3426b + dw Data3426b + dw Data3426b + dw Data3426b + dw Data3426b + dw Data3426b + dw Data3426b + dw Data341b5 + dw Data34325 + dw Data342c6 + dw Data341b5 + dw Data34358 + dw Data3435d + dw Data341b5 + dw Data34371 + dw Data34377 + dw Data3437d + dw Data34383 + dw Data34388 + dw Data343b9 + dw Data343b9 + dw Data343c7 + dw Data343d4 + dw Data343da + dw Data343e0 + dw Data343f6 + dw Data343fc + dw Data34402 + dw Data34407 + dw Data3440c + dw Data34412 + dw Data343b9 + dw Data34417 + dw Data3441d + dw Data34432 + dw Data341b5 + dw Data34437 + dw Data3444f + dw Data34464 + dw Data34469 + dw Data3446e + dw Data34483 + dw Data341b5 + dw Data34488 + dw Data3448d + dw Data34493 + dw Data34499 + dw Data3449f + dw Data344a5 + dw Data344aa + dw Data344c0 + dw Data344c7 + dw Data344dc + dw Data344e2 + dw Data344f7 + dw Data34509 + dw Data3451e + dw Data34524 + dw Data34539 + dw Data3454e + dw Data34553 + dw Data34554 + dw Data341b5 + dw Data341b5 + dw Data34569 + dw Data3456e + dw Data34573 + dw Data34578 + dw Data3458d + dw Data34593 + dw Data341b5 + dw Data341b5 + +Data341b5: + db $2 + db $3 + db $4 + db $5 + db $6 + db $62 + db $7 + db $8 + db $9 + db $a + db $b + db $c + db $d + db $e + db $f + db $10 + db $11 + db $12 + db $4d + db $ff + +Data341c9: + db $2 + db $3 + db $4 + db $7 + db $9 + db $65 + db $14 + db $ff + +Data341d1: + db $2 + db $3 + db $4 + db $5 + db $6 + db $62 + db $7 + db $8 + db $9 + db $a + db $b + db $c + db $d + db $e + db $f + db $10 + db $11 + db $12 + db $13 + db $ff + +Data341e5: + db $2 + db $3 + db $4 + db $5 + db $6 + db $62 + db $7 + db $8 + db $9 + db $b + db $d + db $e + db $f + db $10 + db $15 + db $11 + db $12 + db $4d + db $ff + +Data341f8: + db $2 + db $3 + db $4 + db $5 + db $6 + db $62 + db $7 + db $8 + db $9 + db $a + db $b + db $c + db $d + db $e + db $f + db $10 + db $11 + db $12 + db $17 + db $ff + +Data3420c: + db $2 + db $3 + db $4 + db $5 + db $6 + db $62 + db $7 + db $8 + db $9 + db $a + db $b + db $c + db $d + db $e + db $f + db $10 + db $11 + db $12 + db $18 + db $ff + +Data34220: + db $2 + db $3 + db $4 + db $5 + db $6 + db $62 + db $7 + db $8 + db $9 + db $a + db $b + db $c + db $d + db $e + db $f + db $10 + db $11 + db $12 + db $19 + db $ff + +Data34234: + db $2 + db $3 + db $4 + db $5 + db $6 + db $62 + db $7 + db $8 + db $9 + db $a + db $1a + db $b + db $c + db $d + db $e + db $f + db $10 + db $11 + db $12 + db $4d + db $ff + +Data34249: + db $2 + db $3 + db $4 + db $5 + db $6 + db $62 + db $7 + db $8 + db $9 + db $b + db $d + db $e + db $f + db $10 + db $16 + db $11 + db $12 + db $ff + +Data3425b: + db $2 + db $3 + db $7 + db $9 + db $1b + db $ff + +Data34261: + db $2 + db $3 + db $4 + db $1c + db $ff + +Data34266: + db $2 + db $3 + db $4 + db $1d + db $ff + +Data3426b: + db $2 + db $3 + db $4 + db $5 + db $6 + db $62 + db $7 + db $8 + db $9 + db $a + db $b + db $c + db $d + db $e + db $f + db $10 + db $11 + db $12 + db $1d + db $ff + +Data3427f: + db $2 + db $3 + db $4 + db $5 + db $6 + db $62 + db $7 + db $8 + db $9 + db $a + db $b + db $c + db $d + db $e + db $f + db $10 + db $1e + db $11 + db $12 + db $4d + db $ff + +Data34294: + db $2 + db $3 + db $4 + db $1f + db $ff + +Data34299: + db $2 + db $3 + db $4 + db $20 + db $ff + +Data3429e: + db $21 + db $2 + db $4 + db $3 + db $22 + db $a + db $b + db $c + db $e + db $11 + db $12 + db $4d + db $ff + +Data342ab: + db $3e + db $2 + db $4 + db $9 + db $3d + db $3 + db $5 + db $6 + db $62 + db $7 + db $8 + db $a + db $b + db $c + db $d + db $e + db $f + db $10 + db $11 + db $12 + db $4d + db $ff + +Data342c1: + db $2 + db $3 + db $4 + db $23 + db $ff + +Data342c6: + db $2 + db $3 + db $4 + db $9 + db $5 + db $6 + db $62 + db $7 + db $8 + db $a + db $b + db $c + db $d + db $e + db $f + db $38 + db $10 + db $11 + db $12 + db $24 + db $4d + db $ff + +Data342dc: + db $2 + db $3 + db $4 + db $5 + db $6 + db $62 + db $7 + db $8 + db $9 + db $a + db $b + db $c + db $d + db $e + db $f + db $10 + db $11 + db $12 + db $25 + db $ff + +Data342f0: + db $2 + db $3 + db $4 + db $7 + db $26 + db $a + db $b + db $c + db $d + db $e + db $f + db $10 + db $11 + db $12 + db $ff + +Data342ff: + db $2 + db $3 + db $4 + db $5 + db $6 + db $62 + db $7 + db $8 + db $9 + db $a + db $b + db $c + db $d + db $e + db $f + db $10 + db $27 + db $11 + db $12 + db $4d + db $ff + +Data34314: + db $2 + db $3 + db $4 + db $28 + db $ff + +Data34319: + db $2 + db $3 + db $4 + db $29 + db $ff + +Data3431e: + db $2 + db $3 + db $4 + db $9 + db $7 + db $2a + db $ff + +Data34325: + db $2 + db $3 + db $4 + db $5 + db $6 + db $62 + db $7 + db $8 + db $9 + db $a + db $b + db $c + db $d + db $e + db $f + db $10 + db $11 + db $12 + db $2b + db $ff + +Data34339: + db $2 + db $3 + db $4 + db $2c + db $ff + +Data3433e: + db $2 + db $3 + db $4 + db $2d + db $ff + +Data34343: + db $2 + db $3 + db $4 + db $2e + db $ff + +Data34348: + db $2 + db $3 + db $4 + db $9 + db $7 + db $65 + db $2f + db $ff + +Data34350: + db $2 + db $3 + db $4 + db $7 + db $9 + db $65 + db $30 + db $ff + +Data34358: + db $2 + db $3 + db $4 + db $31 + db $ff + +Data3435d: + db $2 + db $3 + db $4 + db $5 + db $6 + db $62 + db $7 + db $8 + db $9 + db $a + db $b + db $c + db $d + db $e + db $f + db $10 + db $11 + db $12 + db $32 + db $ff + +Data34371: + db $2 + db $3 + db $4 + db $9 + db $33 + db $ff + +Data34377: + db $2 + db $3 + db $4 + db $9 + db $34 + db $ff + +Data3437d: + db $2 + db $3 + db $4 + db $9 + db $35 + db $ff + +Data34383: + db $2 + db $3 + db $4 + db $36 + db $ff + +Data34388: + db $2 + db $3 + db $4 + db $9 + db $37 + db $ff + +Data3438e: + db $3a + db $2 + db $4 + db $39 + db $3 + db $5 + db $6 + db $62 + db $7 + db $8 + db $9 + db $a + db $b + db $c + db $d + db $e + db $f + db $10 + db $11 + db $12 + db $4d + db $ff + +Data343a4: + db $3c + db $2 + db $4 + db $3 + db $9 + db $3b + db $5 + db $6 + db $62 + db $7 + db $8 + db $a + db $b + db $c + db $d + db $e + db $f + db $10 + db $11 + db $12 + db $ff + +Data343b9: + db $2 + db $3 + db $4 + db $3f + db $9 + db $a + db $b + db $c + db $d + db $e + db $11 + db $12 + db $4d + db $ff + +Data343c7: + db $2 + db $3 + db $4 + db $40 + db $a + db $b + db $c + db $d + db $e + db $11 + db $12 + db $4d + db $ff + +Data343d4: + db $2 + db $3 + db $4 + db $9 + db $41 + db $ff + +Data343da: + db $2 + db $3 + db $4 + db $9 + db $42 + db $ff + +Data343e0: + db $2 + db $3 + db $4 + db $5 + db $6 + db $62 + db $7 + db $8 + db $9 + db $43 + db $a + db $b + db $c + db $d + db $e + db $f + db $10 + db $11 + db $12 + db $2b + db $4d + db $ff + +Data343f6: + db $2 + db $3 + db $4 + db $9 + db $44 + db $ff + +Data343fc: + db $2 + db $3 + db $4 + db $9 + db $45 + db $ff + +Data34402: + db $2 + db $3 + db $4 + db $46 + db $ff + +Data34407: + db $2 + db $3 + db $4 + db $47 + db $ff + +Data3440c: + db $2 + db $3 + db $4 + db $9 + db $48 + db $ff + +Data34412: + db $2 + db $3 + db $4 + db $49 + db $ff + +Data34417: + db $2 + db $3 + db $4 + db $9 + db $4a + db $ff + +Data3441d: + db $2 + db $3 + db $4 + db $5 + db $6 + db $62 + db $7 + db $8 + db $4b + db $9 + db $a + db $b + db $c + db $d + db $e + db $f + db $10 + db $11 + db $12 + db $4d + db $ff + +Data34432: + db $2 + db $3 + db $4 + db $4c + db $ff + +Data34437: + db $2 + db $3 + db $4 + db $9 + db $5 + db $6 + db $62 + db $4e + db $7 + db $8 + db $a + db $b + db $c + db $d + db $e + db $f + db $38 + db $10 + db $11 + db $12 + db $4f + db $24 + db $4d + db $ff + +Data3444f: + db $2 + db $3 + db $4 + db $5 + db $6 + db $62 + db $7 + db $8 + db $9 + db $a + db $b + db $c + db $d + db $e + db $f + db $10 + db $50 + db $11 + db $12 + db $4d + db $ff + +Data34464: + db $2 + db $3 + db $4 + db $51 + db $ff + +Data34469: + db $2 + db $3 + db $4 + db $52 + db $ff + +Data3446e: + db $2 + db $3 + db $4 + db $5 + db $6 + db $62 + db $7 + db $8 + db $9 + db $a + db $b + db $c + db $d + db $e + db $f + db $10 + db $53 + db $11 + db $12 + db $4d + db $ff + +Data34483: + db $2 + db $3 + db $4 + db $54 + db $ff + +Data34488: + db $2 + db $3 + db $4 + db $55 + db $ff + +Data3448d: + db $2 + db $3 + db $4 + db $9 + db $56 + db $ff + +Data34493: + db $2 + db $3 + db $4 + db $9 + db $57 + db $ff + +Data34499: + db $2 + db $3 + db $4 + db $9 + db $58 + db $ff + +Data3449f: + db $2 + db $3 + db $4 + db $9 + db $59 + db $ff + +Data344a5: + db $2 + db $3 + db $4 + db $5a + db $ff + +Data344aa: + db $5b + db $2 + db $4 + db $3 + db $5 + db $6 + db $62 + db $7 + db $9 + db $5c + db $8 + db $a + db $b + db $c + db $d + db $e + db $f + db $10 + db $11 + db $12 + db $4d + db $ff + +Data344c0: + db $2 + db $3 + db $4 + db $9 + db $5d + db $2b + db $ff + +Data344c7: + db $2 + db $4 + db $3 + db $5 + db $6 + db $62 + db $7 + db $9 + db $5e + db $8 + db $a + db $b + db $c + db $d + db $e + db $f + db $10 + db $11 + db $12 + db $4d + db $ff + +Data344dc: + db $2 + db $3 + db $4 + db $9 + db $5f + db $ff + +Data344e2: + db $2 + db $3 + db $4 + db $5 + db $6 + db $60 + db $62 + db $7 + db $8 + db $9 + db $a + db $b + db $c + db $d + db $e + db $f + db $10 + db $11 + db $12 + db $4d + db $ff + +Data344f7: + db $2 + db $3 + db $4 + db $9 + db $5 + db $6 + db $61 + db $62 + db $7 + db $8 + db $d + db $e + db $f + db $10 + db $11 + db $12 + db $4d + db $ff + +Data34509: + db $2 + db $3 + db $4 + db $5 + db $6 + db $63 + db $62 + db $7 + db $8 + db $9 + db $a + db $b + db $c + db $d + db $e + db $f + db $10 + db $11 + db $12 + db $4d + db $ff + +Data3451e: + db $2 + db $3 + db $4 + db $9 + db $64 + db $ff + +Data34524: + db $2 + db $3 + db $4 + db $5 + db $6 + db $62 + db $7 + db $8 + db $9 + db $a + db $b + db $c + db $d + db $e + db $f + db $10 + db $53 + db $11 + db $12 + db $25 + db $ff + +Data34539: + db $2 + db $3 + db $4 + db $5 + db $6 + db $66 + db $62 + db $7 + db $8 + db $9 + db $a + db $b + db $c + db $d + db $e + db $f + db $10 + db $11 + db $12 + db $4d + db $ff + +Data3454e: + db $2 + db $3 + db $4 + db $67 + db $ff + +Data34553: + db $ff + +Data34554: + db $2 + db $3 + db $4 + db $5 + db $6 + db $62 + db $7 + db $8 + db $9 + db $a + db $b + db $c + db $d + db $e + db $f + db $10 + db $69 + db $11 + db $12 + db $4d + db $ff + +Data34569: + db $2 + db $3 + db $4 + db $6a + db $ff + +Data3456e: + db $2 + db $3 + db $4 + db $6b + db $ff + +Data34573: + db $2 + db $3 + db $4 + db $6c + db $ff + +Data34578: + db $2 + db $3 + db $4 + db $5 + db $6 + db $6d + db $62 + db $7 + db $8 + db $9 + db $a + db $b + db $c + db $d + db $e + db $f + db $10 + db $11 + db $12 + db $4d + db $ff + +Data3458d: + db $2 + db $3 + db $4 + db $9 + db $6e + db $ff + +Data34593: + db $2 + db $3 + db $4 + db $9 + db $6f + db $ff + +Data34599: + dw sub_34677 + dw asm_34b2c + dw asm_34c83 + dw asm_34d7f + dw asm_34e03 + dw asm_34e8b + dw asm_34ec9 + dw asm_3519b + dw Function351d0 + dw sub_35375 + dw asm_35393 + dw sub_353ef + dw asm_3540e + dw asm_3543f + dw asm_3565c + dw asm_35698 + dw asm_356c9 + dw asm_3574f + dw asm_3622a + dw asm_36184 + dw asm_36371 + dw asm_3638d + dw asm_36426 + dw asm_364dc + dw asm_36555 + dw asm_3751b + dw asm_37549 + dw Function365bf + dw asm_366e3 + dw asm_3714b + dw asm_37180 + dw asm_371ba + dw asm_36894 + dw asm_36908 + dw asm_36985 + dw asm_36a92 + dw asm_36b55 + dw asm_36ba0 + dw asm_36d9b + dw asm_36d3d + dw asm_36d6d + dw asm_36e2b + dw asm_36e1e + dw asm_3724b + dw asm_37305 + dw asm_37407 + dw asm_36299 + dw asm_36ead + dw asm_36f35 + dw asm_36fef + dw asm_3701b + dw asm_375b8 + dw asm_37069 + dw asm_370c2 + dw asm_370c8 + dw asm_37f64 + dw asm_36c02 + dw asm_36beb + dw asm_36cfe + dw asm_36cd9 + dw asm_36969 + dw asm_3693e + dw asm_35a9c + dw asm_35b84 + dw asm_35bbd + dw asm_35c0b + dw asm_35cc5 + dw asm_35cd9 + dw asm_35d31 + dw asm_35d66 + dw asm_35dae + dw asm_35dd4 + dw asm_35e30 + dw asm_35e5e + dw sub_35ee1 + dw asm_35f13 + dw asm_36b74 + dw asm_34e99 + dw asm_34ec1 + dw asm_375ea + dw asm_37672 + dw asm_376a6 + dw asm_376e6 + dw asm_3772b + dw asm_37780 + dw asm_377ab + dw asm_377e8 + dw asm_37828 + dw asm_37876 + dw asm_378af + dw asm_378da + dw asm_378f7 + dw asm_37936 + dw asm_3796e + dw asm_379a8 + dw asm_37a11 + dw asm_37a3a + dw sub_3599d + dw asm_37a8c + dw asm_37aa6 + dw asm_37af7 + dw asm_37b29 + dw asm_37b72 + dw asm_37c76 + dw asm_37c77 + dw asm_37ca5 + dw asm_37caa + dw asm_37caf + dw asm_37d21 + dw asm_37d83 + dw asm_37dae + +sub_34677: + ldh a, [hBattleTurn] + and a + ld a, [wcac1] + jr z, asm_34682 + ld a, [wcac2] + +asm_34682: + inc a + jp z, asm_34991 + xor a + ld [wca3a], a + ld [wca5c], a + ld [wcad2], a + ld [wcad9], a + ld a, $a + ld [wca38], a + ldh a, [hBattleTurn] + and a + jp nz, asm_34809 + ld hl, wca10 + ld a, [hl] + and 7 + jr z, asm_346e5 + dec a + ld [wca10], a + and 7 + jr z, asm_346ba + xor a + ld [wcccd], a + ld de, $0104 + call sub_35f53 + jr asm_346cd + +asm_346ba: + ld hl, text_349a7 + call PrintText + ld hl, Function3d5ce + call CallFromBank0F + ld hl, wca3b + res 0, [hl] + jr asm_346e5 + +asm_346cd: + ld hl, text_34997 + call PrintText + ld a, [wcac1] + cp $ad + jr z, asm_346e5 + cp $d6 + jr z, asm_346e5 + xor a + ld [wcad6], a + jp asm_34991 + +asm_346e5: + ld hl, wca10 + bit 5, [hl] + jr z, asm_34704 + ld a, [wcac1] + cp $ac + jr z, asm_34704 + cp $dd + jr z, asm_34704 + ld hl, text_349b3 + call PrintText + xor a + ld [wcad6], a + jp asm_34991 + +asm_34704: + ld a, [wEnemySubStatus3] + bit 5, a + jp z, asm_3471d + ld a, [wcac1] + cp $e5 + jp z, asm_3471d + ld hl, text_34a55 + call PrintText + jp asm_34991 + +asm_3471d: + ld hl, wPlayerSubStatus3 + bit 3, [hl] + jp z, asm_34730 + res 3, [hl] + ld hl, text_349dc + call PrintText + jp asm_34991 + +asm_34730: + ld hl, wca3e + bit 5, [hl] + jr z, asm_34742 + res 5, [hl] + ld hl, text_349e6 + call PrintText + jp asm_34991 + +asm_34742: + ld hl, wca48 + ld a, [hl] + and a + jr z, asm_34759 + dec a + ld [hl], a + and $f + jr nz, asm_34759 + ld [hl], a + ld [wcad3], a + ld hl, text_349fd + call PrintText + +asm_34759: + ld a, [wPlayerSubStatus3] + add a + jr nc, asm_34796 + ld hl, wca46 + dec [hl] + jr nz, asm_34772 + ld hl, wPlayerSubStatus3 + res 7, [hl] + ld hl, text_34a32 + call PrintText + jr asm_34796 + +asm_34772: + ld hl, text_34a0d + call PrintText + xor a + ld [wcccd], a + ld de, $0103 + call sub_35f53 + call BattleRandom + cp $80 + jp c, asm_34796 + ld hl, wPlayerSubStatus3 + ld a, [hl] + and $80 + ld [hl], a + call sub_34b03 + jr asm_347e2 + +asm_34796: + ld a, [wca3b] + add a + jr nc, asm_347bc + ld hl, text_34aa8 + call PrintText + xor a + ld [wcccd], a + ld de, $010a + call sub_35f53 + call BattleRandom + cp $80 + jp c, asm_347bc + ld hl, text_34ab6 + call PrintText + jr asm_347e2 + +asm_347bc: + ld a, [wcad3] + and a + jr z, asm_347ce + ld hl, wcac1 + cp [hl] + jr nz, asm_347ce + call sub_34acc + jp asm_34991 + +asm_347ce: + ld hl, wca10 + bit 6, [hl] + jr z, asm_34808 + call BattleRandom + cp $3f + jr nc, asm_34808 + ld hl, text_349c8 + call PrintText + +asm_347e2: + ld hl, wPlayerSubStatus3 + ld a, [hl] + and $cc + ld [hl], a + ld hl, wca3b + res 6, [hl] + ld a, [wc9ef] + cp $13 + jr z, asm_347fb + cp $5b + jr z, asm_347fb + jr asm_34805 + +asm_347fb: + res 6, [hl] + ld a, 2 + ld [wca5c], a + call sub_37f0f + +asm_34805: + jp asm_34991 + +asm_34808: + ret + +asm_34809: + ld hl, wcde7 + ld a, [hl] + and 7 + jr z, asm_3484f + dec a + ld [wcde7], a + and a + jr z, asm_3482a + ld hl, text_34997 + call PrintText + xor a + ld [wcccd], a + ld de, $0104 + call sub_35f53 + jr asm_3483d + +asm_3482a: + ld hl, text_349a7 + call PrintText + ld hl, Function3d67c + call CallFromBank0F + ld hl, wca40 + res 0, [hl] + jr asm_3484f + +asm_3483d: + ld a, [wcac1] + cp $ad + jr z, asm_3484f + cp $d6 + jr z, asm_3484f + xor a + ld [wcad7], a + jp asm_34991 + +asm_3484f: + ld hl, wcde7 + bit 5, [hl] + jr z, asm_3486e + ld a, [wcac2] + cp $ac + jr z, asm_3486e + cp $dd + jr z, asm_3486e + ld hl, text_349b3 + call PrintText + xor a + ld [wcad7], a + jp asm_34991 + +asm_3486e: + ld a, [wPlayerSubStatus3] + bit 5, a + jp z, asm_34887 + ld a, [wcac2] + cp $e5 + jp z, asm_34887 + ld hl, text_34a55 + call PrintText + jp asm_34991 + +asm_34887: + ld hl, wEnemySubStatus3 + bit 3, [hl] + jp z, asm_3489a + res 3, [hl] + ld hl, text_349dc + call PrintText + jp asm_34991 + +asm_3489a: + ld hl, wca43 + bit 5, [hl] + jr z, asm_348ac + res 5, [hl] + ld hl, text_349e6 + call PrintText + jp asm_34991 + +asm_348ac: + ld hl, wca50 + ld a, [hl] + and a + jr z, asm_348c3 + dec a + ld [hl], a + and $f + jr nz, asm_348c3 + ld [hl], a + ld [wcad4], a + ld hl, text_349fd + call PrintText + +asm_348c3: + ld a, [wEnemySubStatus3] + add a + jp nc, asm_3491d + ld hl, wca4e + dec [hl] + jr nz, asm_348de + ld hl, wEnemySubStatus3 + res 7, [hl] + ld hl, text_34a32 + call PrintText + jp asm_3491d + +asm_348de: + ld hl, text_34a0d + call PrintText + xor a + ld [wcccd], a + ld de, $0103 + call sub_35f53 + call BattleRandom + cp $80 + jr c, asm_3491d + ld hl, wEnemySubStatus3 + ld a, [hl] + and $80 + ld [hl], a + ld hl, text_34a1b + call PrintText + call sub_35904 + call sub_3599d + xor a + ld [wcccd], a + ldh [hBattleTurn], a + ld de, 1 + call sub_35f53 + ld a, 1 + ldh [hBattleTurn], a + call sub_35f68 + jr asm_34969 + +asm_3491d: + ld a, [wca40] + add a + jr nc, asm_34943 + ld hl, text_34aa8 + call PrintText + xor a + ld [wcccd], a + ld de, $010a + call sub_35f53 + call BattleRandom + cp $80 + jp c, asm_34943 + ld hl, text_34ab6 + call PrintText + jr asm_34969 + +asm_34943: + ld a, [wcad4] + and a + jr z, asm_34955 + ld hl, wcac2 + cp [hl] + jr nz, asm_34955 + call sub_34acc + jp asm_34991 + +asm_34955: + ld hl, wcde7 + bit 6, [hl] + jr z, asm_3498f + call BattleRandom + cp $3f + jr nc, asm_3498f + ld hl, text_349c8 + call PrintText + +asm_34969: + ld hl, wEnemySubStatus3 + ld a, [hl] + and $cc + ld [hl], a + ld hl, wca40 + res 6, [hl] + ld a, [wc9e8] + cp $13 + jr z, asm_34982 + cp $5b + jr z, asm_34982 + jr asm_3498c + +asm_34982: + res 6, [hl] + ld a, 2 + ld [wca5c], a + call sub_37f0f + +asm_3498c: + jp asm_34991 + +asm_3498f: + ret + ret + +asm_34991: + ld a, 1 + ld [wca7d], a + ret + +text_34997: + text "は" + line "ぐうぐう ねむっている" + prompt + +text_349a7: + text "は めをさました!" + prompt + +text_349b3: + text "は" + line "こおって しまって うごかない!" + prompt + +text_349c8: + db "からだが しびれて うごけない" + +text_349dc: + db "は ひるんだ!" + +text_349e6: + db "こうげきの はんどうでは うごけない!" + +text_349fd: + db "かなしばりが とけた!" + +text_34a0d: + db "こんらんしている!" + +text_34a1b: + db "わけも わからずじぶんを こうげきした!" + +text_34a32: + db "こんらんが とけた!" + +text_34a41: + db "の こうげきはまだ つづいている" + +text_34a55: + db "みうごきが とれない!" + +text_34a65: + db "は がまんしている" + +text_34a71: + db "がまんが とかれた!" + +text_34a80: + db "@" + text_from_ram wStringBuffer1 + db "で もちこたえた!" + +text_34a93: + db "は あいてのこうげきを こらえた!" + +text_34aa8: + db "に メロメロだ!" + +text_34ab6: + db "は メロメロでわざが だせなかった!" + +sub_34acc: + ld hl, wcac1 + ld de, wPlayerSubStatus3 + ldh a, [hBattleTurn] + and a + jr z, asm_34adb + inc hl + ld de, wEnemySubStatus3 + +asm_34adb: + ld a, [de] + res 4, a + ld [de], a + ld a, [hl] + ld [wCountSetBitsResult], a + call Unreferenced_GetMoveName + ld hl, text_34aec + jp PrintText + +text_34aec: + text "は かなしばりで@" + text_from_ram wStringBuffer1 + text "がだせない!" +text_34b02: + prompt + +sub_34b03: + ld hl, text_34a1b + call PrintText + xor a + ld [wca39], a + call sub_35904 + call sub_3599d + xor a + ld [wcccd], a + inc a + ldh [hBattleTurn], a + ld de, 1 + call sub_35f53 + ld hl, Function3d5ce + call CallFromBank0F + xor a + ldh [hBattleTurn], a + jp sub_35fc9 + +asm_34b2c: + ldh a, [hBattleTurn] + and a + ret nz + xor a + ld [wcad2], a + ld a, [wLinkMode] + and a + ret nz + ld hl, wPartyMon1ID + ld bc, $30 + ld a, [wcd41] + call AddNTimes + ld a, [wce73] + cp [hl] + jr nz, asm_34b51 + inc hl + ld a, [wce74] + cp [hl] + ret z + +asm_34b51: + ld hl, wBadges + bit 7, [hl] + ld a, $65 + jr nz, asm_34b6e + bit 5, [hl] + ld a, $46 + jr nz, asm_34b6e + bit 3, [hl] + ld a, $32 + jr nz, asm_34b6e + bit 1, [hl] + ld a, $1e + jr nz, asm_34b6e + ld a, $a + +asm_34b6e: + ld b, a + ld c, a + ld a, [wca0f] + ld d, a + add b + ld b, a + jr nc, asm_34b7a + ld b, $ff + +asm_34b7a: + ld a, c + cp d + ret nc + +asm_34b7d: + call BattleRandom + swap a + cp b + jr nc, asm_34b7d + cp c + ret c + +asm_34b87: + call BattleRandom + cp b + jr nc, asm_34b87 + cp c + jr c, asm_34bdb + ld a, d + sub c + ld b, a + call BattleRandom + swap a + sub b + jr c, asm_34baa + cp b + jr nc, asm_34bbc + ld hl, text_34c54 + call PrintText + call sub_34b03 + jp asm_34c34 + +asm_34baa: + call BattleRandom + add a + swap a + and 7 + jr z, asm_34baa + ld [wca10], a + ld hl, text_34c44 + jr asm_34bd6 + +asm_34bbc: + call BattleRandom + and 3 + ld hl, text_34c37 + and a + jr z, asm_34bd6 + ld hl, text_34c54 + dec a + jr z, asm_34bd6 + ld hl, text_34c65 + dec a + jr z, asm_34bd6 + ld hl, text_34c74 + +asm_34bd6: + call PrintText + jr asm_34c34 + +asm_34bdb: + ld a, [wca05] + and a + jr z, asm_34bbc + ld hl, wca0a + push hl + ld a, [hli] + ld b, [hl] + inc hl + add b + ld b, [hl] + inc hl + add b + ld b, [hl] + add b + pop hl + push af + ld a, [wcd40] + ld c, a + ld b, 0 + add hl, bc + ld b, [hl] + pop af + cp b + jr z, asm_34bbc + ld a, 1 + ld [wcad2], a + ld a, [w2DMenuNumRows] + dec a + ld b, a + ld a, [wcd40] + ld c, a + +asm_34c0a: + call BattleRandom + and 3 + cp b + jr nc, asm_34c0a + cp c + jr z, asm_34c0a + ld [wcd40], a + ld hl, wca0a + ld e, a + ld d, 0 + add hl, de + ld a, [hl] + and a + jr z, asm_34c0a + ld a, [wcd40] + ld c, a + ld b, 0 + ld hl, wca04 + add hl, bc + ld a, [hl] + ld [wcac1], a + call Function360b1 + +asm_34c34: + jp asm_357a9 + +text_34c37: + db $1 + db $fc + db $c9 + db $0 + db $ca + db $7f + db $c5 + db $cf + db $b9 + db $c3 + db $b2 + db $d9 + db $58 + +text_34c44: + db $1 + db $fc + db $c9 + db $0 + db $ca + db $7f + db $cb + db $d9 + db $c8 + db $dd + db $ca + db $2c + db $d2 + db $c0 + db $e7 + db $58 + +text_34c54: + db $1 + db $fc + db $c9 + db $0 + db $ca + db $7f + db $b2 + db $b3 + db $ba + db $c4 + db $dd + db $7f + db $b7 + db $b6 + db $c5 + db $b2 + db $58 + +text_34c65: + db $1 + db $fc + db $c9 + db $0 + db $ca + db $7f + db $bf + db $df + db $48 + db $dd + db $7f + db $d1 + db $b2 + db $c0 + db $58 + +text_34c74: + db $1 + db $fc + db $c9 + db $0 + db $ca + db $7f + db $bc + db $d7 + db $de + db $46 + db $d8 + db $dd + db $bc + db $c0 + db $58 + +asm_34c83: + ld hl, text_34c89 + jp PrintText + +text_34c89: + db $0 + db $5a + db $50 + db $8 + ldh a, [hBattleTurn] + and a + ld a, [wc9ef] + ld hl, $cad6 + jr z, asm_34c9e + ld a, [wc9e8] + ld hl, $cad7 + +asm_34c9e: + ld [hl], a + ld [wCountSetBitsResult], a + call sub_34d22 + ld a, [wcad2] + and a + ld hl, Data34cc1 + ret nz + ld a, [wCountSetBitsResult] + cp 3 + ld hl, Data34cc1 + ret c + ld hl, Data34cba + ret + +Data34cba: + db $0 + db $c9 + db $7f + db $50 + db $8 + jr asm_34cc6 + +Data34cc1: + db $0 + db $ca + db $7f + db $50 + db $8 + +asm_34cc6: + ld a, [wcad2] + and a + jr z, asm_34cdc + ld hl, Data34cd0 + ret + +Data34cd0: + db $0 + db $d2 + db $b2 + db $da + db $b2 + db $dd + db $d1 + db $bc + db $bc + db $c3 + db $50 + db $8 + +asm_34cdc: + ld hl, Data34ce0 + ret + +Data34ce0: + db $0 + db $4f + db $50 + db $1 + dw wcd31 + db $8 + ld hl, Data34cf8 + ld a, [wCountSetBitsResult] + add a + push bc + ld b, 0 + ld c, a + add hl, bc + pop bc + ld a, [hli] + ld h, [hl] + ld l, a + ret + +Data34cf8: + dw Data34d02 + dw Data34d0b + dw Data34d12 + dw Data34d17 + dw Data34d1f + +Data34d02: + db $0 + db $dd + db $7f + db $c2 + db $b6 + db $df + db $c0 + db $e7 + db $57 + +Data34d0b: + db $0 + db $dd + db $7f + db $bc + db $c0 + db $e7 + db $57 + +Data34d12: + db $0 + db $bc + db $c0 + db $e7 + db $57 + +Data34d17: + db $0 + db $7f + db $ba + db $b3 + db $29 + db $b7 + db $e7 + db $57 + +Data34d1f: + db $0 + db $e7 + db $57 + +sub_34d22: + push bc + ld a, [wCountSetBitsResult] + ld c, a + ld b, 0 + ld hl, Data34d40 + +asm_34d2c: + ld a, [hli] + cp $ff + jr z, asm_34d3a + cp c + jr z, asm_34d3a + and a + jr nz, asm_34d2c + inc b + jr asm_34d2c + +asm_34d3a: + ld a, b + ld [wCountSetBitsResult], a + pop bc + ret + +Data34d40: + db $e + db $4a + db $0 + db $69 + db $75 + db $78 + db $85 + db $0 + db $60 + db $61 + db $64 + db $66 + db $68 + db $8c + db $0 + db $1 + db $a + db $b + db $11 + db $13 + db $14 + db $15 + db $1e + db $22 + db $23 + db $25 + db $27 + db $2b + db $2c + db $2d + db $2e + db $2f + db $40 + db $44 + db $46 + db $47 + db $51 + db $59 + db $5a + db $5b + db $5c + db $67 + db $6a + db $6b + db $6e + db $6f + db $76 + db $7a + db $80 + db $84 + db $8b + db $8d + db $91 + db $94 + db $96 + db $97 + db $9a + db $9c + db $9f + db $a3 + db $a4 + db $0 + db $ff + +asm_34d7f: + ldh a, [hBattleTurn] + and a + ld a, [wcac1] + ld hl, wca0a + ld de, wPlayerSubStatus3 + jr z, asm_34d96 + ld a, [wcac2] + ld hl, wcde1 + ld de, wEnemySubStatus3 + +asm_34d96: + cp $a5 + ret z + ld a, [de] + and 7 + ret nz + inc de + ld a, [de] + bit 6, a + ret nz + call sub_34dcb + ld a, b + and a + jp nz, asm_357a9 + inc de + ld a, [de] + bit 3, a + ret nz + ldh a, [hBattleTurn] + and a + ld hl, wPartyMon1PP + ld a, [wcd41] + jr z, asm_34dc5 + ld a, [wBattleMode] + dec a + ret z + ld hl, wd932 + ld a, [wca36] + +asm_34dc5: + ld bc, $30 + call AddNTimes + +sub_34dcb: + ldh a, [hBattleTurn] + and a + ld a, [wcd40] + jr z, asm_34dd6 + ld a, [wcac7] + +asm_34dd6: + ld c, a + ld b, 0 + add hl, bc + ld a, [hl] + and a + jr z, asm_34de2 + dec [hl] + ld b, 0 + ret + +asm_34de2: + call sub_37f5f + ld hl, text_34dee + call PrintText + ld b, 1 + ret + +text_34dee: + db $0 + db $bc + db $b6 + db $bc + db $7f + db $dc + db $2b + db $c9 + db $7f + db $43 + db $81 + db $ab + db $93 + db $26 + db $4f + db $c5 + db $b6 + db $df + db $c0 + db $e7 + db $58 + +asm_34e03: + xor a + ld [wca39], a + ldh a, [hBattleTurn] + and a + ld a, [wcdd9] + jr nz, asm_34e12 + ld a, [wca02] + +asm_34e12: + ld [wCurSpecies], a + call GetMonHeader + ld c, 6 + ld hl, wc9f1 + ld de, wca3e + ldh a, [hBattleTurn] + and a + jr z, asm_34e2b + ld hl, wc9ea + ld de, wca43 + +asm_34e2b: + ld a, [hld] + and a + ret z + ld a, [de] + bit 2, a + jr z, asm_34e36 + dec c + dec c + dec c + +asm_34e36: + dec hl + ld b, [hl] + ld hl, Data34e86 + +asm_34e3b: + ld a, [hli] + cp b + jr z, asm_34e44 + inc a + jr nz, asm_34e3b + jr asm_34e46 + +asm_34e44: + dec c + dec c + +asm_34e46: + ld a, [wMonHBaseSpeed] + ld e, a + ld d, 0 + sla e + rl d + sla e + rl d + +asm_34e54: + dec c + jr z, asm_34e5d + srl d + rr e + jr asm_34e54 + +asm_34e5d: + ld b, e + ld a, d + and a + jr z, asm_34e64 + ld b, $ff + +asm_34e64: + push bc + call Function37e1d + ld a, b + cp $49 + ld a, c + pop bc + jr nz, asm_34e75 + add b + ld b, a + jr nc, asm_34e75 + ld b, $ff + +asm_34e75: + call BattleRandom + rlc a + rlc a + rlc a + cp b + ret nc + ld a, 1 + ld [wca39], a + ret + +Data34e86: + dw text_34b02 + dw $a398 + db $ff + +asm_34e8b: + ldh a, [hBattleTurn] + and a + jr nz, asm_34e95 + call Function357b7 + jr asm_34e98 + +asm_34e95: + call sub_3585d + +asm_34e98: + ret + +asm_34e99: + ld a, [wca5c] + ld b, a + inc b + ld a, [wce2a] + ld e, a + ld a, [wce29] + ld d, a + +asm_34ea6: + dec b + ret z + ld a, [wce2a] + add e + ld [wce2a], a + ld a, [wce29] + adc d + ld [wce29], a + jr nc, asm_34ea6 + ld a, $ff + ld [wce29], a + ld [wce2a], a + ret + +asm_34ec1: + ld a, [wca5c] + inc a + ld [wca5c], a + ret + +asm_34ec9: + ld hl, wca20 + ld a, [hli] + ld b, a + ld c, [hl] + ld hl, wcdf7 + ld a, [hli] + ld d, a + ld e, [hl] + ld a, [wc9f2] + ld [wCountSetBitsResult], a + ldh a, [hBattleTurn] + and a + jr z, asm_34ef2 + ld hl, wcdf7 + ld a, [hli] + ld b, a + ld c, [hl] + ld hl, wca20 + ld a, [hli] + ld d, a + ld e, [hl] + ld a, [wc9eb] + ld [wCountSetBitsResult], a + +asm_34ef2: + call sub_34f97 + ld a, [wCountSetBitsResult] + cp b + jr z, asm_34f00 + cp c + jr z, asm_34f00 + jr asm_34f1a + +asm_34f00: + ld hl, wce2a + ld a, [hld] + ld h, [hl] + ld l, a + ld b, h + ld c, l + srl b + rr c + add hl, bc + ld a, h + ld [wce29], a + ld a, l + ld [wce2a], a + ld hl, wca38 + set 7, [hl] + +asm_34f1a: + ld a, [wCountSetBitsResult] + ld b, a + ld hl, TypeMatchups + +asm_34f21: + ld a, [hli] + cp $ff + jr z, asm_34f86 + cp $fe + jr nz, asm_34f3d + push hl + ld hl, wca40 + ldh a, [hBattleTurn] + and a + jr z, asm_34f36 + ld hl, wca3b + +asm_34f36: + bit 3, [hl] + pop hl + jr nz, asm_34f86 + jr asm_34f21 + +asm_34f3d: + cp b + jr nz, asm_34f81 + ld a, [hl] + cp d + jr z, asm_34f49 + cp e + jr z, asm_34f49 + jr asm_34f81 + +asm_34f49: + push hl + push bc + inc hl + ld a, [wca38] + and $80 + ld b, a + ld a, [hl] + and a + jr nz, asm_34f5b + inc a + ld [wca3a], a + xor a + +asm_34f5b: + ldh [hPrintNumDivisor], a + add b + ld [wca38], a + xor a + ldh [hQuotient], a + ld hl, wce29 + ld a, [hli] + ldh [hQuotient + 1], a + ld a, [hld] + ldh [hQuotient + 2], a + call Multiply + ld a, $a + ldh [hPrintNumDivisor], a + ld b, 4 + call Divide + ldh a, [hQuotient + 1] + ld [hli], a + ldh a, [hQuotient + 2] + ld [hl], a + pop bc + pop hl + +asm_34f81: + inc hl + inc hl + jp asm_34f21 + +asm_34f86: + call Function34fff + ld a, [wCountSetBitsResult] + ld b, a + ld a, [wca38] + and $80 + or b + ld [wca38], a + ret + +sub_34f97: + push hl + push de + push bc + ld hl, Data34ff2 + ld a, [wcae2] + ld b, a + ld a, [wCountSetBitsResult] + ld c, a + +asm_34fa5: + ld a, [hli] + cp $ff + jr z, asm_34fee + cp b + jr nz, asm_34fb1 + ld a, [hl] + cp c + jr z, asm_34fb5 + +asm_34fb1: + inc hl + inc hl + jr asm_34fa5 + +asm_34fb5: + xor a + ldh [hQuotient], a + ld a, [wce29] + ldh [hQuotient + 1], a + ld a, [wce2a] + ldh [hQuotient + 2], a + inc hl + ld a, [hl] + ldh [hPrintNumDivisor], a + call Multiply + ld a, $a + ldh [hPrintNumDivisor], a + ld b, 4 + call Divide + ldh a, [hQuotient] + and a + ld bc, $ffff + jr nz, asm_34fe6 + ldh a, [hQuotient + 1] + ld b, a + ldh a, [hQuotient + 2] + ld c, a + or b + jr nz, asm_34fe6 + ld bc, 1 + +asm_34fe6: + ld a, b + ld [wce29], a + ld a, c + ld [wce2a], a + +asm_34fee: + pop bc + pop de + pop hl + ret + +Data34ff2: + db $1 + db $15 + db $14 + db $1 + db $14 + db $5 + db $2 + db $14 + db $14 + db $2 + db $15 + db $5 + db $ff + +Function34fff: + ldh a, [hBattleTurn] + and a + ld hl, wcdf7 + ld a, [wc9f2] + jr z, asm_35010 + ld hl, wca20 + ld a, [wc9eb] + +asm_35010: + ld d, a + ld b, [hl] + inc hl + ld c, [hl] + ld a, $a + ld [wCountSetBitsResult], a + ld hl, TypeMatchups + +asm_3501c: + ld a, [hli] + cp $ff + jr z, asm_3506c + cp $fe + jr nz, asm_35038 + push hl + ld hl, wca40 + ldh a, [hBattleTurn] + and a + jr z, asm_35031 + ld hl, wca3b + +asm_35031: + bit 3, [hl] + pop hl + jr nz, asm_3506c + jr asm_3501c + +asm_35038: + cp d + jr nz, asm_35044 + ld a, [hli] + cp b + jr z, asm_35048 + cp c + jr z, asm_35048 + jr asm_35045 + +asm_35044: + inc hl + +asm_35045: + inc hl + jr asm_3501c + +asm_35048: + xor a + ldh [hProduct], a + ldh [hQuotient], a + ldh [hQuotient + 1], a + ld a, [hli] + ldh [hQuotient + 2], a + ld a, [wCountSetBitsResult] + ldh [hPrintNumDivisor], a + call Multiply + ld a, $a + ldh [hPrintNumDivisor], a + push bc + ld b, 4 + call Divide + pop bc + ldh a, [hQuotient + 2] + ld [wCountSetBitsResult], a + jr asm_3501c + +asm_3506c: + ret + +INCLUDE "data/types/type_matchups.inc" + +asm_3519b: + ld hl, wce29 + ld a, [hli] + and a + jr nz, asm_351a6 + ld a, [hl] + cp 2 + ret c + +asm_351a6: + xor a + ldh [hQuotient], a + dec hl + ld a, [hli] + ldh [hQuotient + 1], a + ld a, [hl] + ldh [hQuotient + 2], a + +asm_351b0: + call BattleRandom + rrca + cp $d9 + jr c, asm_351b0 + ldh [hPrintNumDivisor], a + call Multiply + ld a, $ff + ldh [hPrintNumDivisor], a + ld b, 4 + call Divide + ldh a, [hQuotient + 1] + ld hl, wce29 + ld [hli], a + ldh a, [hQuotient + 2] + ld [hl], a + ret + +Function351d0: + ld hl, wca40 + ld de, wc9f0 + ld bc, wcde7 + ldh a, [hBattleTurn] + and a + jr z, asm_351e7 + ld hl, wca3b + ld de, wc9e9 + ld bc, wca10 + +asm_351e7: + ld a, [de] + cp 8 + jr nz, asm_351f2 + ld a, [bc] + and 7 + jp z, asm_352c4 + +asm_351f2: + bit 2, [hl] + jp nz, asm_352c4 + ld a, [de] + cp $11 + ret z + inc hl + inc hl + inc hl + inc hl + bit 5, [hl] + res 5, [hl] + ret nz + call sub_3750b + jr z, asm_35213 + cp 3 + jp z, asm_352c4 + cp 8 + jp z, asm_352c4 + +asm_35213: + dec hl + dec hl + bit 6, [hl] + jp z, asm_3524d + ld hl, wcad7 + ld de, wc9ef + ldh a, [hBattleTurn] + and a + jr z, asm_3522b + ld hl, wcad6 + ld de, wc9e8 + +asm_3522b: + ld a, [hl] + cp $13 + jr nz, asm_3523c + ld a, [de] + cp $12 + jr z, asm_3524d + cp $57 + jr z, asm_3524d + jp asm_352c4 + +asm_3523c: + cp $5b + jp nz, asm_352c4 + ld a, [de] + cp $59 + jr z, asm_3524d + cp $5a + jr z, asm_3524d + jp asm_352c4 + +asm_3524d: + ldh a, [hBattleTurn] + and a + jr nz, asm_35277 + ld a, [wc9f0] + cp $12 + jr c, asm_3526f + cp $1a + jr c, asm_35267 + cp $3a + jr c, asm_3526f + cp $42 + jr c, asm_35267 + jr asm_3526f + +asm_35267: + ld a, [wca43] + bit 1, a + jp nz, asm_352c4 + +asm_3526f: + ld a, [wca3e] + bit 0, a + ret nz + jr asm_3529a + +asm_35277: + ld a, [wc9e9] + cp $12 + jr c, asm_35294 + cp $1a + jr c, asm_3528c + cp $3a + jr c, asm_35294 + cp $42 + jr c, asm_3528c + jr asm_35294 + +asm_3528c: + ld a, [wca3e] + bit 1, a + jp nz, asm_352c4 + +asm_35294: + ld a, [wca43] + bit 0, a + ret nz + +asm_3529a: + call sub_352df + ld a, [wc9f3] + ld b, a + ldh a, [hBattleTurn] + and a + jr z, asm_352aa + ld a, [wc9ec] + ld b, a + +asm_352aa: + push bc + call Function37e2d + ld a, b + cp $4d + ld a, c + pop bc + jr nz, asm_352bd + ld c, a + ld a, b + sub c + ld b, a + jr nc, asm_352bd + ld b, 0 + +asm_352bd: + call BattleRandom + cp b + jr nc, asm_352c4 + ret + +asm_352c4: + xor a + ld hl, wce29 + ld [hli], a + ld [hl], a + inc a + ld [wca3a], a + ldh a, [hBattleTurn] + and a + jr z, asm_352d9 + ld hl, wEnemySubStatus3 + res 5, [hl] + ret + +asm_352d9: + ld hl, wPlayerSubStatus3 + res 5, [hl] + ret + +sub_352df: + ldh a, [hBattleTurn] + and a + ld hl, wc9f3 + ld a, [wcaae] + ld b, a + ld a, [wcab7] + ld c, a + jr z, asm_352fa + ld hl, wc9ec + ld a, [wcab6] + ld b, a + ld a, [wcaaf] + ld c, a + +asm_352fa: + ld a, $e + sub c + ld c, a + xor a + ldh [hQuotient], a + ldh [hQuotient + 1], a + ld a, [hl] + ldh [hQuotient + 2], a + push hl + ld d, 2 + +asm_35309: + push bc + ld hl, Data35342 + dec b + sla b + ld c, b + ld b, 0 + add hl, bc + pop bc + ld a, [hli] + ldh [hPrintNumDivisor], a + call Multiply + ld a, [hl] + ldh [hPrintNumDivisor], a + ld b, 4 + call Divide + ldh a, [hQuotient + 2] + ld b, a + ldh a, [hQuotient + 1] + or b + jp nz, asm_35332 + ldh [hQuotient + 1], a + ld a, 1 + ldh [hQuotient + 2], a + +asm_35332: + ld b, c + dec d + jr nz, asm_35309 + ldh a, [hQuotient + 1] + and a + ldh a, [hQuotient + 2] + jr z, asm_3533f + ld a, $ff + +asm_3533f: + pop hl + ld [hl], a + ret + +Data35342: + dw $6419 + dw $641c + dw $6421 + dw $6428 + dw $6432 + dw $6442 + dw $101 + dw $a0f + dw $102 + dw $a19 + dw $103 + dw $a23 + dw $104 + +Function3535c: + call sub_3750b + jr nz, asm_35373 + push hl + ld hl, wc9f5 + ldh a, [hBattleTurn] + and a + jr z, asm_3536d + ld hl, wc9ee + +asm_3536d: + call BattleRandom + cp [hl] + pop hl + ret + +asm_35373: + and a + ret + +sub_35375: + ldh a, [hBattleTurn] + and a + ld a, [wca3e] + jr z, asm_35380 + ld a, [wca43] + +asm_35380: + bit 4, a + ret z + xor a + ld [wcccd], a + ld [wccc1], a + inc a + ld [wca5c], a + ld a, $a4 + jp sub_37f23 + +asm_35393: + ld a, [wca3a] + and a + jp nz, sub_37f5f + inc a + ld [wcccd], a + ldh a, [hBattleTurn] + and a + ld a, [wc9ef] + ld c, a + ld de, wca45 + ld a, [wc9f0] + jr z, asm_353b7 + ld a, [wc9e8] + ld c, a + ld de, wca4d + ld a, [wc9e9] + +asm_353b7: + cp $1d + jr z, asm_353d5 + cp $1e + jr z, asm_353d5 + cp $2c + jr z, asm_353d5 + cp $4d + jr z, asm_353d5 + cp $68 + jr z, asm_353cf + xor a + ld [wca5c], a + +asm_353cf: + ld e, c + ld d, 0 + jp sub_35f53 + +asm_353d5: + ld a, [wca5c] + and 1 + xor 1 + ld [wca5c], a + ld a, [de] + cp 1 + ld e, c + ld d, 0 + jp z, sub_35f53 + xor a + ld [wcccd], a + jp sub_35f53 + +sub_353ef: + ldh a, [hBattleTurn] + and a + ld a, [wca3e] + jr z, asm_353fa + ld a, [wca43] + +asm_353fa: + bit 4, a + ret z + xor a + ld [wcccd], a + ld [wccc1], a + ld a, 2 + ld [wca5c], a + ld a, $a4 + jp sub_37f23 + +asm_3540e: + ld a, [wca3a] + and a + ret z + call sub_355a6 + ldh a, [hBattleTurn] + and a + ld a, [wc9ef] + ld hl, wPlayerSubStatus3 + jr z, asm_35427 + ld a, [wc9e8] + ld hl, wEnemySubStatus3 + +asm_35427: + cp $13 + jr z, asm_35432 + cp $5b + jr z, asm_35432 + jp asm_357a9 + +asm_35432: + res 6, [hl] + ld a, 2 + ld [wca5c], a + call sub_37f0f + jp asm_357a9 + +asm_3543f: + ld hl, wca40 + ldh a, [hBattleTurn] + and a + jr z, asm_3544a + ld hl, wca3b + +asm_3544a: + bit 5, [hl] + jr z, asm_35459 + call sub_35ee1 + ld b, 0 + jr nc, asm_35472 + ld b, 1 + jr asm_35472 + +asm_35459: + call Function37e2d + ld a, b + cp $4f + ld b, 0 + jr nz, asm_35472 + call BattleRandom + cp c + jr nc, asm_35472 + call sub_35ee1 + ld b, 0 + jr nc, asm_35472 + ld b, 2 + +asm_35472: + push bc + call sub_354a0 + ldh a, [hBattleTurn] + and a + jr nz, asm_35480 + call sub_35f68 + jr asm_35483 + +asm_35480: + call sub_35fc9 + +asm_35483: + pop bc + ld a, b + and a + ret z + dec a + jr nz, asm_35490 + ld hl, text_34a93 + jp PrintText + +asm_35490: + call Function37e2d + ld a, [hl] + ld [wCountSetBitsResult], a + call GetItemName + ld hl, text_34a80 + jp PrintText + +sub_354a0: + ld de, wca56 + ldh a, [hBattleTurn] + and a + jr nz, asm_354ab + ld de, wca58 + +asm_354ab: + ld a, [wce2a] + ld b, a + ld a, [de] + add b + ld [de], a + dec de + ld a, [wce29] + ld b, a + ld a, [de] + adc b + ld [de], a + ret nc + ld a, $ff + ld [de], a + inc de + ld [de], a + ret + call Function37e2d + ldh a, [hBattleTurn] + and a + ld de, wca12 + ld hl, wca14 + ld a, [wc9ef] + jr z, asm_354db + ld de, wcde9 + ld hl, wcdeb + ld a, [wc9e8] + +asm_354db: + ld b, a + ld a, [de] + cp [hl] + inc de + inc hl + ld a, [de] + sbc [hl] + jp z, asm_3556a + ld a, b + cp $9c + jr nz, asm_3550d + push hl + push de + push af + call sub_37f5f + ld hl, wca10 + ldh a, [hBattleTurn] + and a + jr z, asm_354fb + ld hl, wcde7 + +asm_354fb: + ld a, [hl] + and a + ld [hl], 2 + ld hl, text_35570 + jr z, asm_35507 + ld hl, text_3557d + +asm_35507: + call PrintText + pop af + pop de + pop hl + +asm_3550d: + ld a, [hld] + ld [wHPBarMaxHP], a + ld c, a + ld a, [hl] + ld [wPlayerEffectivenessVsEnemyMons], a + ld b, a + jr z, asm_3551d + srl b + rr c + +asm_3551d: + ld a, [de] + ld [wHPBarOldHP], a + add c + ld [de], a + ld [wHPBarNewHP], a + dec de + ld a, [de] + ld [wcdc6], a + adc b + ld [de], a + ld [wcdc8], a + inc hl + inc de + ld a, [de] + dec de + sub [hl] + dec hl + ld a, [de] + sbc [hl] + jr c, asm_35545 + ld a, [hli] + ld [de], a + ld [wcdc8], a + inc de + ld a, [hl] + ld [de], a + ld [wHPBarNewHP], a + +asm_35545: + call sub_37f0f + ldh a, [hBattleTurn] + and a + ld hl, wTileMap + 190 + ld a, 1 + jr z, asm_35556 + ld hl, wTileMap + 42 + xor a + +asm_35556: + ld [wHPBarType], a + ld a, $17 + call Predef + ld hl, DrawHUDsAndHPBars + call CallFromBank0F + ld hl, text_35593 + jp PrintText + +asm_3556a: + call sub_37f5f + jp Function37499 + +text_35570: + db $0 + db $5a + db $ca + db $4f + db $c8 + db $d1 + db $d8 + db $ca + db $2c + db $d2 + db $c0 + db $e7 + db $57 + +text_3557d: + db $0 + db $5a + db $ca + db $7f + db $b9 + db $de + db $ba + db $b3 + db $c6 + db $c5 + db $df + db $c3 + db $4f + db $c8 + db $d1 + db $d8 + db $ca + db $2c + db $d2 + db $c0 + db $e7 + db $57 + +text_35593: + db $0 + db $5a + db $ca + db $7f + db $c0 + db $b2 + db $d8 + db $e2 + db $b8 + db $dd + db $4f + db $b6 + db $b2 + db $cc + db $b8 + db $bc + db $c0 + db $e7 + db $58 + +sub_355a6: + ld de, wc9f0 + ldh a, [hBattleTurn] + and a + jr z, asm_355b1 + ld de, wc9e9 + +asm_355b1: + ld hl, text_35649 + ld a, [wca38] + and $7f + jr z, asm_355c8 + ld hl, text_35605 + ld a, [wca39] + cp $ff + jr nz, asm_355c8 + ld hl, text_35633 + +asm_355c8: + push de + call PrintText + xor a + ld [wca39], a + pop de + ld a, [de] + cp $2d + ret nz + ld hl, wce29 + ld a, [hli] + ld b, [hl] + srl a + rr b + srl a + rr b + srl a + rr b + ld [hl], b + dec hl + ld [hli], a + or b + jr nz, asm_355ee + inc a + ld [hl], a + +asm_355ee: + ld hl, text_35619 + call PrintText + ld a, 1 + ld [wca5c], a + call sub_37f0f + ldh a, [hBattleTurn] + and a + jp nz, sub_35f68 + jp sub_35fc9 + +text_35605: + db $0 + db $bc + db $b6 + db $bc + db $7f + db $5a + db $c9 + db $4f + db $ba + db $b3 + db $29 + db $b7 + db $ca + db $7f + db $ca + db $2d + db $da + db $c0 + db $e7 + db $58 + +text_35619: + db $0 + db $b2 + db $b7 + db $b5 + db $b2 + db $7f + db $b1 + db $cf + db $df + db $c3 + db $4f + db $5a + db $ca + db $55 + db $2c + db $d2 + db $de + db $c6 + db $7f + db $3c + db $c2 + db $b6 + db $df + db $c0 + db $e7 + db $58 + +text_35633: + db $0 + db $59 + db $c6 + db $ca + db $4f + db $2e + db $de + db $2e + db $de + db $b7 + db $b2 + db $c3 + db $c5 + db $b2 + db $e7 + db $58 + +asm_35643: + ld hl, text_35649 + jp PrintText + +text_35649: + db $0 + db $59 + db $c6 + db $ca + db $4f + db $ba + db $b3 + db $b6 + db $26 + db $7f + db $c5 + db $b2 + db $7f + db $d0 + db $c0 + db $b2 + db $30 + db $56 + db $58 + +asm_3565c: + ld a, [wca39] + and a + jr z, asm_35675 + dec a + add a + ld hl, Data3567a + ld b, 0 + ld c, a + add hl, bc + ld a, [hli] + ld h, [hl] + ld l, a + call PrintText + xor a + ld [wca39], a + +asm_35675: + ld c, $14 + jp DelayFrames + +Data3567a: + dw text_3567e + dw text_3568c + +text_3567e: + db $0 + db $b7 + db $e1 + db $b3 + db $bc + db $e2 + db $c6 + db $7f + db $b1 + db $c0 + db $df + db $c0 + db $e7 + db $58 + +text_3568c: + db $0 + db $b2 + db $c1 + db $29 + db $b7 + db $7f + db $cb + db $df + db $bb + db $c2 + db $e7 + db $58 + +asm_35698: + ld a, [wca38] + and $7f + cp $a + ret z + ld hl, text_356ab + jr nc, asm_356a8 + ld hl, text_356b8 + +asm_356a8: + jp PrintText + +text_356ab: + db $0 + db $ba + db $b3 + db $b6 + db $ca + db $7f + db $3a + db $c2 + db $28 + db $de + db $30 + db $e7 + db $58 + +text_356b8: + db $0 + db $ba + db $b3 + db $b6 + db $ca + db $7f + db $b2 + db $cf + db $cb + db $c4 + db $c2 + db $c9 + db $7f + db $d6 + db $b3 + db $30 + db $58 + +asm_356c9: + ld hl, wcde9 + ld de, wca44 + ldh a, [hBattleTurn] + and a + jr z, asm_356da + ld hl, wca12 + ld de, wca3f + +asm_356da: + ld a, [hli] + or [hl] + ret nz + ld a, [de] + bit 6, a + jr z, asm_3573b + ld hl, text_3573e + call PrintText + ldh a, [hBattleTurn] + and a + ld hl, wcdec + ld bc, wTileMap + 42 + ld a, 0 + jr nz, asm_356fd + ld hl, wca15 + ld bc, wTileMap + 190 + ld a, 1 + +asm_356fd: + ld [wHPBarType], a + ld a, [hld] + ld [wHPBarMaxHP], a + ld a, [hld] + ld [wPlayerEffectivenessVsEnemyMons], a + ld a, [hl] + ld [wHPBarOldHP], a + xor a + ld [hld], a + ld a, [hl] + ld [wcdc6], a + xor a + ld [hl], a + ld [wHPBarNewHP], a + ld [wcdc8], a + ld h, b + ld l, c + ld a, $17 + call Predef + ldh a, [hBattleTurn] + push af + xor 1 + ldh [hBattleTurn], a + xor a + ld [wcccd], a + ld [wccc1], a + inc a + ld [wca5c], a + ld a, $c2 + call sub_37f23 + pop af + ldh [hBattleTurn], a + +asm_3573b: + jp asm_357a9 + +text_3573e: + db $0 + db $59 + db $ca + db $7f + db $5a + db $dd + db $4f + db $d0 + db $c1 + db $2d + db $da + db $c6 + db $7f + db $bc + db $c0 + db $e7 + db $58 + +asm_3574f: + jp asm_35752 + +asm_35752: + ld hl, wca43 + ld de, wcab1 + ld bc, wc9e8 + ldh a, [hBattleTurn] + and a + jr z, asm_35769 + ld hl, wca3e + ld de, wcaa9 + ld bc, wc9ef + +asm_35769: + bit 6, [hl] + ret z + ld a, [de] + cp $d + ret z + ldh a, [hBattleTurn] + xor 1 + ldh [hBattleTurn], a + ld h, b + ld l, c + ld [hl], 0 + inc hl + ld [hl], $a + push hl + ld hl, text_35791 + call PrintText + pop hl + xor a + ld [hld], a + ld a, $63 + ld [hl], a + ldh a, [hBattleTurn] + xor 1 + ldh [hBattleTurn], a + ret + +text_35791: + db $0 + db $5a + db $c9 + db $7f + db $b2 + db $b6 + db $d8 + db $c9 + db $4f + db $1c + db $a6 + db $92 + db $e3 + db $b + db $26 + db $7f + db $b1 + db $26 + db $df + db $c3 + db $b2 + db $b8 + db $e7 + db $58 + +asm_357a9: + ld a, [wca7b] + ld l, a + ld a, [wca7c] + ld h, a + ld a, $ff + ld [hli], a + ld [hli], a + ld [hl], a + ret + +Function357b7: + xor a + ld hl, wce29 + ld [hli], a + ld [hl], a + ld hl, wc9f1 + ld a, [hli] + and a + ld d, a + ret z + ld a, [hl] + cp $14 + jr nc, asm_357fe + ld hl, wcdef + ld a, [hli] + ld b, a + ld c, [hl] + ld a, [wca44] + bit 2, a + jr z, asm_357da + sla c + rl b + +asm_357da: + ld hl, wca16 + ld a, [wca39] + and a + jr z, asm_35831 + ld c, 3 + call sub_35952 + ldh a, [hQuotient + 1] + ld b, a + ldh a, [hQuotient + 2] + ld c, a + push bc + ld hl, wPartyMon1Stats + ld a, [wcd41] + ld bc, $30 + call AddNTimes + pop bc + jr asm_35831 + +asm_357fe: + ld hl, wcdf5 + ld a, [hli] + ld b, a + ld c, [hl] + ld a, [wca44] + bit 1, a + jr z, asm_3580f + sla c + rl b + +asm_3580f: + ld hl, wca1c + ld a, [wca39] + and a + jr z, asm_35831 + ld c, 6 + call sub_35952 + ldh a, [hQuotient + 1] + ld b, a + ldh a, [hQuotient + 2] + ld c, a + push bc + ld hl, wPartyMon1SpclAtk + ld a, [wcd41] + ld bc, $30 + call AddNTimes + pop bc + +asm_35831: + ld a, [hli] + ld l, [hl] + ld h, a + or b + jr z, asm_3584c + srl b + rr c + srl b + rr c + srl h + rr l + srl h + rr l + ld a, l + or h + jr nz, asm_3584c + inc l + +asm_3584c: + ld b, l + ld a, [wca0f] + ld e, a + ld a, [wca39] + and a + jr z, asm_35859 + sla e + +asm_35859: + ld a, 1 + and a + ret + +sub_3585d: + ld hl, wce29 + xor a + ld [hli], a + ld [hl], a + ld hl, wc9ea + ld a, [hli] + ld d, a + and a + ret z + ld a, [hl] + cp $14 + jr nc, asm_358a4 + ld hl, wca18 + ld a, [hli] + ld b, a + ld c, [hl] + ld a, [wca3f] + bit 2, a + jr z, asm_35880 + sla c + rl b + +asm_35880: + ld hl, wcded + ld a, [wca39] + and a + jr z, asm_358d7 + ld hl, wPartyMon1Defense + ld a, [wcd41] + ld bc, $30 + call AddNTimes + ld a, [hli] + ld b, a + ld c, [hl] + push bc + ld c, 2 + call sub_35952 + ld hl, hQuotient + 1 + pop bc + jr asm_358d7 + +asm_358a4: + ld hl, wca1e + ld a, [hli] + ld b, a + ld c, [hl] + ld a, [wca3f] + bit 1, a + jr z, asm_358b5 + sla c + rl b + +asm_358b5: + ld hl, wcdf3 + ld a, [wca39] + and a + jr z, asm_358d7 + ld hl, wPartyMon1SpclDef + ld a, [wcd41] + ld bc, $30 + call AddNTimes + ld a, [hli] + ld b, a + ld c, [hl] + push bc + ld c, 5 + call sub_35952 + ld hl, hQuotient + 1 + pop bc + +asm_358d7: + ld a, [hli] + ld l, [hl] + ld h, a + or b + jr z, asm_358f2 + srl b + rr c + srl b + rr c + srl h + rr l + srl h + rr l + ld a, l + or h + jr nz, asm_358f2 + inc l + +asm_358f2: + ld b, l + ld a, [wcde6] + ld e, a + ld a, [wca39] + and a + jr z, asm_358ff + sla e + +asm_358ff: + ld a, 1 + and a + and a + ret + +sub_35904: + xor a + ld hl, wce29 + ld [hli], a + ld [hl], a + ldh a, [hBattleTurn] + and a + ld hl, wca18 + ld de, wca3f + ld a, [wca0f] + jr z, asm_35921 + ld hl, wcdef + ld de, wca44 + ld a, [wcde6] + +asm_35921: + push af + ld a, [hli] + ld b, a + ld c, [hl] + ld a, [de] + bit 2, a + jr z, asm_3592e + sla c + rl b + +asm_3592e: + dec hl + dec hl + dec hl + ld a, [hli] + ld l, [hl] + ld h, a + or b + jr z, asm_3594c + srl b + rr c + srl b + rr c + srl h + rr l + srl h + rr l + ld a, l + or h + jr nz, asm_3594c + inc l + +asm_3594c: + ld b, l + ld d, $28 + pop af + ld e, a + ret + +sub_35952: + push de + push bc + ld a, [wLinkMode] + cp 3 + jr nz, asm_35976 + ld hl, wd93f + dec c + sla c + ld b, 0 + add hl, bc + ld a, [wca36] + ld bc, $30 + call AddNTimes + ld a, [hli] + ldh [hQuotient + 1], a + ld a, [hl] + ldh [hQuotient + 2], a + pop bc + pop de + ret + +asm_35976: + ld a, [wcde6] + ld [wCurPartyLevel], a + ld a, [wcdd9] + ld [wCurSpecies], a + call GetMonHeader + ld hl, wcddf + ld de, wcd94 + ld a, [hli] + ld [de], a + inc de + ld a, [hl] + ld [de], a + pop bc + ld b, 0 + ld hl, wcd89 + ld a, $19 + call Predef + pop de + ret + +sub_3599d: + ldh a, [hBattleTurn] + and a + ld a, [wc9f0] + jr z, asm_359a8 + ld a, [wc9e9] + +asm_359a8: + cp 7 + jr nz, asm_359b1 + srl c + jr nz, asm_359b1 + inc c + +asm_359b1: + cp $1d + jr z, asm_359bc + cp $1e + jr z, asm_359bc + ld a, d + and a + ret z + +asm_359bc: + xor a + ld hl, hProduct + ld [hli], a + ld [hli], a + ld [hl], a + ld a, e + add a + jr nc, asm_359cc + push af + ld a, 1 + ld [hl], a + pop af + +asm_359cc: + inc hl + ld [hli], a + ld a, 5 + ld [hld], a + push bc + ld b, 4 + call Divide + pop bc + inc [hl] + inc [hl] + inc hl + ld [hl], d + call Multiply + ld [hl], b + call Multiply + ld [hl], c + ld b, 4 + call Divide + ld [hl], $32 + ld b, 4 + call Divide + call Function37e1d + ld hl, Data35a7d + +asm_359f6: + ld a, [hli] + cp $ff + jr z, asm_35a1f + cp b + ld a, [hli] + jr nz, asm_359f6 + ld b, a + ldh a, [hBattleTurn] + and a + ld a, [wc9f2] + jr z, asm_35a0b + ld a, [wc9eb] + +asm_35a0b: + cp b + jr nz, asm_35a1f + ld a, c + add $64 + ldh [hMultiplier], a + call Multiply + ld a, $64 + ldh [hMultiplier], a + ld b, 4 + call Divide + +asm_35a1f: + ld hl, wce29 + ld b, [hl] + ldh a, [hQuotient + 2] + add b + ldh [hQuotient + 2], a + jr nc, asm_35a32 + ldh a, [hQuotient + 1] + inc a + ldh [hQuotient + 1], a + and a + jr z, asm_35a66 + +asm_35a32: + ldh a, [hProduct] + ld b, a + ldh a, [hQuotient] + or a + jr nz, asm_35a66 + ldh a, [hQuotient + 1] + cp 3 + jr c, asm_35a4a + cp 4 + jr nc, asm_35a66 + ldh a, [hQuotient + 2] + cp $e6 + jr nc, asm_35a66 + +asm_35a4a: + inc hl + ldh a, [hQuotient + 2] + ld b, [hl] + add b + ld [hld], a + ldh a, [hQuotient + 1] + ld b, [hl] + adc b + ld [hl], a + jr c, asm_35a66 + ld a, [hl] + cp 3 + jr c, asm_35a6c + cp 4 + jr nc, asm_35a66 + inc hl + ld a, [hld] + cp $e6 + jr c, asm_35a6c + +asm_35a66: + ld a, 3 + ld [hli], a + ld a, $e5 + ld [hld], a + +asm_35a6c: + inc hl + ld a, [hl] + add 2 + ld [hld], a + jr nc, asm_35a74 + inc [hl] + +asm_35a74: + ld a, 1 + and a + ret + +unknown_35a78: + dw text_34b02 + dw $a398 + db $ff + +Data35a7d: + dw $32 + dw $133 + dw $234 + dw $335 + dw $436 + dw $537 + dw $738 + dw $839 + dw $143a + dw $153b + dw $163c + dw $173d + dw $183e + dw $193f + dw $1a40 + db $ff + +asm_35a9c: + ld hl, wca0f + ld de, wc9f0 + ldh a, [hBattleTurn] + and a + jr z, asm_35aad + ld hl, wcde6 + ld de, wc9e9 + +asm_35aad: + ld a, [de] + cp $57 + ld b, [hl] + ld a, 0 + jr z, asm_35afd + ld a, [de] + cp $58 + jr z, asm_35ac9 + cp $28 + jr z, asm_35adc + cp $63 + jr z, asm_35b03 + inc de + ld a, [de] + ld b, a + ld a, 0 + jr asm_35afd + +asm_35ac9: + ld a, b + srl a + add b + ld b, a + +asm_35ace: + call BattleRandom + and a + jr z, asm_35ace + cp b + jr nc, asm_35ace + ld b, a + ld a, 0 + jr asm_35afd + +asm_35adc: + ld hl, wcde9 + ldh a, [hBattleTurn] + and a + jr z, asm_35ae7 + ld hl, wca12 + +asm_35ae7: + ld a, [hli] + srl a + ld b, a + ld a, [hl] + rr a + push af + ld a, b + pop bc + and a + jr nz, asm_35afd + or b + ld a, 0 + jr nz, asm_35afd + ld b, 1 + jr asm_35afd + +asm_35afd: + ld hl, wce29 + ld [hli], a + ld [hl], b + ret + +asm_35b03: + ld hl, wca12 + ldh a, [hBattleTurn] + and a + jr z, asm_35b0e + ld hl, wcde9 + +asm_35b0e: + xor a + ldh [hProduct], a + ldh [hQuotient], a + ld a, [hli] + ldh [hQuotient + 1], a + ld a, [hli] + ldh [hQuotient + 2], a + ld a, $30 + ldh [hPrintNumDivisor], a + call Multiply + ld a, [hli] + ld b, a + ld a, [hl] + ldh [hPrintNumDivisor], a + ld a, b + and a + jr z, asm_35b47 + ldh a, [hPrintNumDivisor] + srl b + rr a + srl b + rr a + ldh [hPrintNumDivisor], a + ldh a, [hQuotient + 1] + ld b, a + srl b + ldh a, [hQuotient + 2] + rr a + srl b + rr a + ldh [hQuotient + 2], a + ld a, b + ldh [hQuotient + 1], a + +asm_35b47: + ld b, 4 + call Divide + ldh a, [hQuotient + 2] + ld b, a + ld hl, Data35b78 + +asm_35b52: + ld a, [hli] + cp b + jr nc, asm_35b59 + inc hl + jr asm_35b52 + +asm_35b59: + ldh a, [hBattleTurn] + and a + ld a, [hl] + jr nz, asm_35b69 + ld hl, wc9f1 + ld [hl], a + push hl + call Function357b7 + jr asm_35b71 + +asm_35b69: + ld hl, wc9ea + ld [hl], a + push hl + call sub_3585d + +asm_35b71: + call sub_3599d + pop hl + ld [hl], 1 + ret + +Data35b78: + db $1 + db $c8 + db $4 + db $96 + db $9 + db $64 + db $10 + db $50 + db $20 + db $28 + db $30 + db $14 + +asm_35b84: + ldh a, [hBattleTurn] + and a + ld hl, wcac2 + ld de, wc9ea + jr z, asm_35b95 + ld hl, wcac1 + ld de, wc9f1 + +asm_35b95: + ld a, 1 + ld [wca3a], a + ld a, [hl] + cp $44 + ret z + ld a, [de] + and a + ret z + inc de + ld a, [de] + cp $14 + ret nc + ld hl, wce29 + ld a, [hli] + or [hl] + ret z + ld a, [hl] + add a + ld [hld], a + ld a, [hl] + adc a + ld [hl], a + jr nc, asm_35bb8 + ld a, $ff + ld [hli], a + ld [hl], a + +asm_35bb8: + xor a + ld [wca3a], a + ret + +asm_35bbd: + ldh a, [hBattleTurn] + and a + ld hl, wca44 + ld de, wca51 + ld a, [wcad7] + jr z, asm_35bd4 + ld hl, wca3f + ld de, wca49 + ld a, [wcad6] + +asm_35bd4: + and a + jr z, asm_35bf5 + bit 4, [hl] + jr nz, asm_35bf5 + ld a, [wca3a] + and a + jr nz, asm_35bf5 + set 4, [hl] + call BattleRandom + and 3 + inc a + inc a + inc a + ld [de], a + call sub_37f0f + ld hl, text_35bfb + jp PrintText + +asm_35bf5: + call sub_37f5f + jp asm_374b1 + +text_35bfb: + db $0 + db $59 + db $ca + db $4f + db $80 + db $ab + db $89 + db $e3 + db $a6 + db $dd + db $7f + db $b3 + db $b9 + db $c0 + db $e7 + db $58 + +asm_35c0b: + ld a, [wca3a] + and a + jp nz, asm_35ca9 + call sub_3750b + jp nz, asm_35ca9 + call sub_37f0f + ld hl, wca15 + ld de, wcdec + call sub_35c59 + ld a, 1 + ld [wHPBarType], a + ld hl, wTileMap + 190 + ld a, $17 + call Predef + ld hl, wcde9 + ld a, [hli] + ld [wcdc6], a + ld a, [hli] + ld [wHPBarOldHP], a + ld a, [hli] + ld [wPlayerEffectivenessVsEnemyMons], a + ld a, [hl] + ld [wHPBarMaxHP], a + call sub_35c88 + xor a + ld [wHPBarType], a + ld hl, wTileMap + 42 + ld a, $17 + call Predef + ld hl, text_35caf + jp PrintText + +sub_35c59: + ld a, [hld] + ld [wHPBarMaxHP], a + ld a, [hld] + ld [wPlayerEffectivenessVsEnemyMons], a + ld a, [hld] + ld b, a + ld [wHPBarOldHP], a + ld a, [hl] + ld [wcdc6], a + dec de + dec de + ld a, [de] + dec de + add b + ld [wce2a], a + ld b, [hl] + ld a, [de] + adc b + srl a + ld [wce29], a + ld a, [wce2a] + rr a + ld [wce2a], a + inc hl + inc hl + inc hl + inc de + inc de + inc de + +sub_35c88: + ld c, [hl] + dec hl + ld a, [wce2a] + sub c + ld b, [hl] + dec hl + ld a, [wce29] + sbc b + jr nc, asm_35c9e + ld a, [wce29] + ld b, a + ld a, [wce2a] + ld c, a + +asm_35c9e: + ld a, c + ld [hld], a + ld [wHPBarNewHP], a + ld a, b + ld [hli], a + ld [wcdc8], a + ret + +asm_35ca9: + call sub_37f5f + jp asm_374b1 + +text_35caf: + db $0 + db $b5 + db $c0 + db $26 + db $b2 + db $c9 + db $7f + db $c0 + db $b2 + db $d8 + db $e2 + db $b8 + db $dd + db $4f + db $dc + db $b6 + db $c1 + db $b1 + db $df + db $c0 + db $e7 + db $58 + +asm_35cc5: + ld hl, wca10 + ldh a, [hBattleTurn] + and a + jr z, asm_35cd0 + ld hl, wca10 + +asm_35cd0: + ld a, [hl] + and 7 + ret nz + inc a + ld [wca3a], a + ret + +asm_35cd9: + ld hl, wcdf7 + ldh a, [hBattleTurn] + and a + jr z, asm_35ce4 + ld hl, wca20 + +asm_35ce4: + ld a, [wca3a] + and a + jr nz, asm_35d2e + call sub_37f0f + ld a, [hli] + ld b, a + ld c, [hl] + +asm_35cf0: + call BattleRandom + and $1f + cp b + jr z, asm_35cf0 + cp c + jr z, asm_35cf0 + cp 9 + jr c, asm_35d09 + cp $14 + jr c, asm_35cf0 + cp $1b + jr c, asm_35d09 + jr asm_35cf0 + +asm_35d09: + ld [hld], a + ld [hl], a + ld [wCountSetBitsResult], a + ld a, $3e + call Predef + ld hl, text_35d19 + jp PrintText + +text_35d19: + db $0 + db $59 + db $c9 + db $7f + db $8f + db $81 + db $42 + db $dd + db $4f + db $50 + db $1 + dw wStringBuffer1 + db $0 + db $c6 + db $7f + db $b6 + db $b4 + db $c0 + db $e7 + db $58 + +asm_35d2e: + jp asm_374b1 + +asm_35d31: + ld hl, wca44 + ldh a, [hBattleTurn] + and a + jr z, asm_35d3c + ld hl, wca3f + +asm_35d3c: + ld a, [wca3a] + and a + jr nz, asm_35d53 + call sub_3750b + jp nz, asm_35d53 + set 5, [hl] + call sub_37f0f + ld hl, text_35d59 + jp PrintText + +asm_35d53: + call sub_37f5f + jp asm_374b1 + +text_35d59: + db $0 + db $59 + db $dd + db $4f + db $a8 + db $ac + db $87 + db $84 + db $ab + db $bc + db $c0 + db $e7 + db $58 + +asm_35d66: + ld a, [wLinkMode] + cp 3 + jr z, asm_35d95 + call sub_3750b + jp nz, asm_35d95 + ld hl, wca04 + ld a, [wcd40] + ld c, a + ld b, 0 + add hl, bc + ld a, [wcad7] + ld [hl], a + ld hl, wPartyMon1Moves + add hl, bc + ld [hl], a + ld [wCountSetBitsResult], a + call Unreferenced_GetMoveName + call sub_37f0f + ld hl, text_35d9b + jp PrintText + +asm_35d95: + call sub_37f5f + jp asm_374b1 + +text_35d9b: + db $0 + db $5a + db $ca + db $4f + db $50 + db $1 + dw wStringBuffer1 + db $0 + db $dd + db $7f + db $f + db $1a + db $ab + db $7 + db $bc + db $c0 + db $e7 + db $58 + +asm_35dae: + call sub_37f0f + ld hl, wc9f0 + ld de, wcde7 + ldh a, [hBattleTurn] + and a + jr z, asm_35dc2 + ld hl, wc9e9 + ld de, wca10 + +asm_35dc2: + push hl + call sub_364a2 + pop hl + ld a, [hl] + push hl + push af + ld a, $a + ld [hl], a + call Function365bf + pop af + pop hl + ld [hl], a + ret + +asm_35dd4: + ldh a, [hBattleTurn] + and a + ld hl, wca05 + ld de, wcac1 + ld bc, wc9ef + ld a, [wca10] + jr z, asm_35df1 + ld hl, wcddc + ld de, wcac2 + ld bc, wc9e8 + ld a, [wcde7] + +asm_35df1: + and 7 + jr z, asm_35e2a + ld a, [wca3a] + and a + jr nz, asm_35e2a + ld a, [hl] + and a + jr z, asm_35e2a + dec hl + +asm_35e00: + push hl + call BattleRandom + and 3 + push bc + ld c, a + ld b, 0 + add hl, bc + pop bc + ld a, [hl] + pop hl + and a + jr z, asm_35e00 + push de + ld d, a + ld a, [bc] + cp d + ld a, d + pop de + jr z, asm_35e00 + ld [de], a + call sub_37f0f + push bc + call Function360b1 + pop bc + inc bc + ld a, [bc] + call Function34046 + jp asm_357a9 + +asm_35e2a: + call sub_37f5f + jp asm_374b1 + +asm_35e30: + ld hl, wca3f + ldh a, [hBattleTurn] + and a + jr z, asm_35e3b + ld hl, wca44 + +asm_35e3b: + set 6, [hl] + call sub_37f0f + ld hl, Data35e46 + jp PrintText + +Data35e46: + db $0 + db $5a + db $ca + db $7f + db $b1 + db $b2 + db $c3 + db $dd + db $4f + db $d0 + db $c1 + db $2d + db $da + db $c6 + db $7f + db $bc + db $d6 + db $b3 + db $c4 + db $bc + db $c3 + db $b2 + db $d9 + db $58 + +asm_35e5e: + ld a, [wca3a] + and a + jr nz, asm_35ec4 + ldh a, [hBattleTurn] + and a + ld hl, wcddb + ld de, wd932 + ld a, [wcad7] + jr z, asm_35e7b + ld hl, wca04 + ld de, wPartyMon1PP + ld a, [wcad6] + +asm_35e7b: + and a + jr z, asm_35ec4 + cp $a5 + jr z, asm_35ec4 + ld b, a + ld c, $ff + +asm_35e85: + inc c + ld a, [hli] + cp b + jr nz, asm_35e85 + ld [wCountSetBitsResult], a + dec hl + ld b, 0 + push bc + ld c, 6 + add hl, bc + pop bc + ld a, [hl] + and $3f + jr z, asm_35ec4 + push bc + push de + call Unreferenced_GetMoveName + pop de + call BattleRandom + and 3 + inc a + inc a + ld b, a + ld a, [hl] + and $3f + cp b + jr nc, asm_35eaf + ld b, a + +asm_35eaf: + ld a, b + ld [wCountSetBitsResult], a + ld a, [hl] + sub b + ld [hl], a + ld h, d + ld l, e + pop bc + add hl, bc + ld [hl], a + call sub_37f0f + ld hl, text_35eca + jp PrintText + +asm_35ec4: + call sub_37f5f + jp asm_374b1 + +text_35eca: + db $0 + db $59 + db $c9 + db $4f + db $50 + db $1 + dw wStringBuffer1 + db $0 + db $dd + db $7f + db $50 + db $9 + dw wCountSetBitsResult + db $11 + db $0 + db $b9 + db $2d + db $df + db $c0 + db $e7 + db $58 + +sub_35ee1: + ld de, wcdea + ldh a, [hBattleTurn] + and a + jr z, asm_35eec + ld de, wca13 + +asm_35eec: + ld hl, wce2a + ld a, [de] + dec de + sub [hl] + dec hl + ld a, [de] + sbc [hl] + jr z, asm_35efb + jr c, asm_35f03 + jr asm_35f11 + +asm_35efb: + inc hl + inc de + ld a, [de] + cp [hl] + jr nz, asm_35f11 + dec hl + dec de + +asm_35f03: + ld a, [de] + ld [hli], a + inc de + ld a, [de] + ld [hl], a + dec [hl] + ld a, [hl] + inc a + jr nz, asm_35f0f + dec hl + dec [hl] + +asm_35f0f: + scf + ret + +asm_35f11: + and a + ret + +asm_35f13: + ld hl, wca10 + ld de, wca3b + ldh a, [hBattleTurn] + and a + jr z, asm_35f24 + ld hl, wcde7 + ld de, wca40 + +asm_35f24: + ld a, [hli] + or [hl] + jr z, asm_35f38 + xor a + ld [hld], a + ld [hl], a + ld a, [de] + res 0, a + ld [de], a + call sub_37f0f + ld hl, text_35f3e + jp PrintText + +asm_35f38: + call sub_37f5f + jp asm_3746a + +text_35f3e: + db $0 + db $5a + db $c9 + db $4f + db $8c + db $92 + db $e3 + db $8f + db $8c + db $b2 + db $2c + db $e2 + db $b3 + db $26 + db $7f + db $c5 + db $b5 + db $df + db $c0 + db $e7 + db $58 + +sub_35f53: + ld a, e + ld [wccc0], a + ld a, d + ld [wccc1], a + ld c, 3 + call DelayFrames + jpab PlayBattleAnim + +sub_35f68: + ld hl, wce29 + ld a, [hli] + ld b, a + ld a, [hl] + or b + jr z, asm_35fc3 + ld a, [wca43] + bit 4, a + jp nz, asm_3602a + ld a, [hld] + ld b, a + ld a, [wcdea] + ld [wHPBarOldHP], a + sub b + ld [wcdea], a + ld a, [hl] + ld b, a + ld a, [wcde9] + ld [wcdc6], a + sbc b + ld [wcde9], a + jr nc, asm_35fa1 + ld a, [wcdc6] + ld [hli], a + ld a, [wHPBarOldHP] + ld [hl], a + xor a + ld hl, wcde9 + ld [hli], a + ld [hl], a + +asm_35fa1: + ld hl, wcdeb + ld a, [hli] + ld [wPlayerEffectivenessVsEnemyMons], a + ld a, [hl] + ld [wHPBarMaxHP], a + ld hl, wcde9 + ld a, [hli] + ld [wcdc8], a + ld a, [hl] + ld [wHPBarNewHP], a + ld hl, wTileMap + 42 + xor a + ld [wHPBarType], a + ld a, $17 + call Predef + +asm_35fc3: + ld hl, DrawHUDsAndHPBars + jp CallFromBank0F + +sub_35fc9: + ld hl, wce29 + ld a, [hli] + ld b, a + ld a, [hl] + or b + jr z, asm_36024 + ld a, [wca3e] + bit 4, a + jp nz, asm_3602a + ld a, [hld] + ld b, a + ld a, [wca13] + ld [wHPBarOldHP], a + sub b + ld [wca13], a + ld [wHPBarNewHP], a + ld b, [hl] + ld a, [wca12] + ld [wcdc6], a + sbc b + ld [wca12], a + ld [wcdc8], a + jr nc, asm_3600c + ld a, [wcdc6] + ld [hli], a + ld a, [wHPBarOldHP] + ld [hl], a + xor a + ld hl, wca12 + ld [hli], a + ld [hl], a + ld hl, wHPBarNewHP + ld [hli], a + ld [hl], a + +asm_3600c: + ld hl, wca14 + ld a, [hli] + ld [wPlayerEffectivenessVsEnemyMons], a + ld a, [hl] + ld [wHPBarMaxHP], a + ld hl, wTileMap + 190 + ld a, 1 + ld [wHPBarType], a + ld a, $17 + call Predef + +asm_36024: + ld hl, DrawHUDsAndHPBars + jp CallFromBank0F + +asm_3602a: + ld hl, text_36084 + call PrintText + ld de, wcabd + ld bc, wca43 + ldh a, [hBattleTurn] + and a + jr z, asm_36041 + ld de, wcabc + ld bc, wca3e + +asm_36041: + ld hl, wce29 + ld a, [hli] + and a + jr nz, asm_3604c + ld a, [de] + sub [hl] + ld [de], a + ret nc + +asm_3604c: + ld h, b + ld l, c + res 4, [hl] + ld hl, text_3609e + call PrintText + ldh a, [hBattleTurn] + push af + xor 1 + ldh [hBattleTurn], a + xor a + ld [wcccd], a + ld [wccc1], a + ld a, 3 + ld [wca5c], a + ld a, $a4 + call sub_37f23 + pop af + ldh [hBattleTurn], a + ldh a, [hBattleTurn] + ld hl, wc9f0 + and a + jr z, asm_3607c + ld hl, wc9e9 + +asm_3607c: + xor a + ld [hl], a + ld hl, DrawHUDsAndHPBars + jp CallFromBank0F + +text_36084: + db $0 + db $59 + db $c6 + db $7f + db $b6 + db $dc + db $df + db $c3 + db $4f + db $3c + db $de + db $bc + db $de + db $26 + db $7f + db $ba + db $b3 + db $29 + db $b7 + db $dd + db $7f + db $b3 + db $b9 + db $c0 + db $e7 + db $58 + +text_3609e: + db $0 + db $59 + db $c9 + db $7f + db $3c + db $de + db $bc + db $de + db $ca + db $4f + db $b7 + db $b4 + db $c3 + db $bc + db $cf + db $df + db $c0 + db $56 + db $58 + +Function360b1: + ldh a, [hBattleTurn] + and a + jp z, asm_360c7 + ld hl, wca44 + ld de, wc9e8 + ld bc, wcad7 + push bc + ld a, [wcac2] + ld b, a + jr asm_360dc + +asm_360c7: + ld hl, wca3f + ld de, wc9ef + ld bc, wcad6 + push bc + ld a, [wcac1] + ld b, a + ld a, [wcabe] + and a + jr z, asm_360dc + ld b, a + +asm_360dc: + ld a, b + pop bc + and a + bit 4, [hl] + jr nz, asm_360fa + ld [wCurSpecies], a + ld [wCountSetBitsResult], a + dec a + ld hl, Moves + ld bc, 7 + call AddNTimes + ld a, $10 + call FarCopyBytes + jr asm_36101 + +asm_360fa: + ld a, [bc] + ld [wCurSpecies], a + ld [wCountSetBitsResult], a + +asm_36101: + call Unreferenced_GetMoveName + jp CopyStringToStringBuffer2 + + ld de, wcde7 + ld bc, wca43 + ldh a, [hBattleTurn] + and a + jp z, asm_36119 + ld de, wca10 + ld bc, wca3e + +asm_36119: + ld a, [bc] + bit 5, a + res 5, a + ld [bc], a + jr nz, asm_3613b + ld a, [de] + and a + ret nz + ld a, [wca38] + and $7f + cp $a + ret c + call Function37e2d + ld a, b + cp $17 + ret z + call Function3535c + ret nc + call sub_37ae9 + ret nz + +asm_3613b: + call BattleRandom + and 7 + jr z, asm_3613b + ld [de], a + call sub_37eec + push de + ld hl, DrawHUDsAndHPBars + call CallFromBank0F + ld hl, text_36176 + call PrintText + pop de + call Function37e2d + ld a, b + cp $d + jr z, asm_36165 + cp $f + jr z, asm_36165 + cp 2 + jr z, asm_36165 + ret + +asm_36165: + ld a, [de] + and $f8 + ld [de], a + ld a, [hl] + call sub_37ec2 + call Function37e60 + ld hl, DrawHUDsAndHPBars + jp CallFromBank0F + +text_36176: + db $0 + db $59 + db $ca + db $4f + db $c8 + db $d1 + db $df + db $c3 + db $bc + db $cf + db $df + db $c0 + db $e7 + db $58 + +asm_36184: + ld de, wcde7 + ld bc, wca43 + ldh a, [hBattleTurn] + and a + jp z, asm_36196 + ld de, wca10 + ld bc, wca3e + +asm_36196: + ld a, [wca38] + and $7f + cp $a + ld hl, text_35649 + jr c, asm_36215 + push bc + call Function37e2d + ld a, b + pop bc + cp $17 + jr nz, asm_361b8 + ld a, [hl] + ld [wCountSetBitsResult], a + call GetItemName + ld hl, text_374f7 + jr asm_36215 + +asm_361b8: + ld a, [de] + and 7 + ld hl, text_3621b + jr nz, asm_36215 + ld hl, text_374b7 + ld a, [de] + and a + jr nz, asm_36215 + call sub_3750b + jr nz, asm_36215 + ld a, [bc] + bit 5, a + res 5, a + ld [bc], a + jr nz, asm_361da + ld a, [wca3a] + and a + jr nz, asm_36215 + +asm_361da: + call BattleRandom + and 7 + jr z, asm_361da + ld [de], a + call sub_37eec + push de + ld hl, DrawHUDsAndHPBars + call CallFromBank0F + ld hl, text_36176 + call PrintText + pop de + call Function37e2d + ld a, b + cp $d + jr z, asm_36204 + cp $f + jr z, asm_36204 + cp 2 + jr z, asm_36204 + ret + +asm_36204: + ld a, [de] + and $f8 + ld [de], a + ld a, [hl] + call sub_37ec2 + call Function37e60 + ld hl, DrawHUDsAndHPBars + jp CallFromBank0F + +asm_36215: + call sub_37f5f + jp PrintText + +text_3621b: + db $0 + db $59 + db $ca + db $7f + db $bd + db $33 + db $c6 + db $4f + db $c8 + db $d1 + db $df + db $c3 + db $b2 + db $d9 + db $58 + +asm_3622a: + ld de, wcde7 + ldh a, [hBattleTurn] + and a + jr z, asm_36235 + ld de, wca10 + +asm_36235: + call sub_3750b + ret nz + ld a, [de] + and a + ret nz + ld a, [wca38] + and $7f + cp $a + ret c + call Function37e2d + ld a, b + cp $14 + ret z + call Function3535c + ret nc + call sub_37ae9 + ret nz + ld a, [de] + set 3, a + ld [de], a + push de + ld de, $0106 + call sub_37f35 + ld hl, DrawHUDsAndHPBars + call CallFromBank0F + ld hl, text_3628d + call PrintText + pop de + call Function37e2d + ld a, b + cp $a + jr z, asm_3627c + cp $f + jr z, asm_3627c + cp 2 + jr z, asm_3627c + ret + +asm_3627c: + ld a, [de] + res 3, a + ld [de], a + ld a, [hl] + call sub_37ec2 + call Function37e60 + ld hl, DrawHUDsAndHPBars + jp CallFromBank0F + +text_3628d: + db $0 + db $59 + db $ca + db $7f + db $34 + db $b8 + db $dd + db $b1 + db $3b + db $c0 + db $e7 + db $58 + +asm_36299: + ld de, wcde7 + ldh a, [hBattleTurn] + and a + jr z, asm_362a4 + ld de, wca10 + +asm_362a4: + ld hl, text_35649 + ld a, [wca38] + and $7f + cp $a + jp c, asm_3634b + ld hl, text_36351 + ld a, [de] + bit 3, a + jp nz, asm_3634b + call Function37e2d + ld a, b + cp $14 + jr nz, asm_362ce + ld a, [hl] + ld [wCountSetBitsResult], a + call GetItemName + ld hl, text_374f7 + jr asm_3634b + +asm_362ce: + ld hl, text_374b7 + and a + jr nz, asm_3634b + call sub_3750b + jr nz, asm_3634b + ld a, [wca3a] + and a + jr nz, asm_3634b + ld a, [de] + set 3, a + ld [de], a + push de + call sub_36331 + jr z, asm_362f4 + call sub_37eec + ld hl, text_3628d + call PrintText + jr asm_36307 + +asm_362f4: + set 0, [hl] + xor a + ld [de], a + call sub_37eec + ld hl, DrawHUDsAndHPBars + call CallFromBank0F + ld hl, text_36363 + call PrintText + +asm_36307: + pop de + call Function37e2d + ld a, b + cp $a + jr z, asm_36319 + cp $f + jr z, asm_36319 + cp 2 + jr z, asm_36319 + ret + +asm_36319: + ld a, [de] + res 3, a + ld [de], a + ld a, [hl] + call sub_37ec2 + call Function37e60 + ld hl, DrawHUDsAndHPBars + call CallFromBank0F + call sub_36331 + ret nz + res 0, [hl] + ret + +sub_36331: + ldh a, [hBattleTurn] + and a + ld a, [wc9f0] + ld hl, wca44 + ld de, wca4f + jr z, asm_36348 + ld a, [wc9e9] + ld hl, wca3f + ld de, wca47 + +asm_36348: + cp $21 + ret + +asm_3634b: + call sub_37f5f + jp PrintText + +text_36351: + db $0 + db $59 + db $ca + db $7f + db $bd + db $33 + db $c6 + db $4f + db $34 + db $b8 + db $dd + db $7f + db $b1 + db $3b + db $c3 + db $b2 + db $d9 + db $58 + +text_36363: + db $0 + db $59 + db $ca + db $4f + db $d3 + db $b3 + db $34 + db $b8 + db $dd + db $b1 + db $3b + db $c0 + db $e7 + db $58 + +asm_36371: + call sub_363a3 + ld hl, text_3637a + jp PrintText + +text_3637a: + db $0 + db $59 + db $b6 + db $d7 + db $4f + db $c0 + db $b2 + db $d8 + db $e2 + db $b8 + db $dd + db $7f + db $bd + db $b2 + db $c4 + db $df + db $c0 + db $e7 + db $58 + +asm_3638d: + call sub_363a3 + ld hl, text_36396 + jp PrintText + +text_36396: + db $0 + db $59 + db $c9 + db $4f + db $d5 + db $d2 + db $dd + db $7f + db $b8 + db $df + db $c0 + db $e7 + db $58 + +sub_363a3: + ld hl, wce29 + ld a, [hl] + srl a + ld [hli], a + ld a, [hl] + rr a + ld [hld], a + or [hl] + jr nz, asm_363b3 + inc hl + inc [hl] + +asm_363b3: + ld hl, wca12 + ld de, wca14 + ldh a, [hBattleTurn] + and a + jp z, asm_363c5 + ld hl, wcde9 + ld de, wcdeb + +asm_363c5: + ld bc, wcdc6 + ld a, [hli] + ld [bc], a + ld a, [hl] + dec bc + ld [bc], a + ld a, [de] + dec bc + ld [bc], a + inc de + ld a, [de] + dec bc + ld [bc], a + ld a, [wce2a] + ld b, [hl] + add b + ld [hld], a + ld [wHPBarNewHP], a + ld a, [wce29] + ld b, [hl] + adc b + ld [hli], a + ld [wcdc8], a + jr c, asm_363f4 + ld a, [hld] + ld b, a + ld a, [de] + dec de + sub b + ld a, [hli] + ld b, a + ld a, [de] + inc de + sbc b + jr nc, asm_36400 + +asm_363f4: + ld a, [de] + ld [hld], a + ld [wHPBarNewHP], a + dec de + ld a, [de] + ld [hli], a + ld [wcdc8], a + inc de + +asm_36400: + ldh a, [hBattleTurn] + and a + ld hl, wTileMap + 190 + ld a, 1 + jr z, asm_3640e + ld hl, wTileMap + 42 + xor a + +asm_3640e: + ld [wHPBarType], a + ld a, $17 + call Predef + ld a, $1e + call Predef + ld a, $23 + call Predef + ld hl, sub_3d3f4 + jp CallFromBank0F + +asm_36426: + xor a + ld [wcccd], a + call sub_3750b + ret nz + ld de, wcde7 + ldh a, [hBattleTurn] + and a + jr z, asm_36439 + ld de, wca10 + +asm_36439: + ld a, [de] + and a + jp nz, sub_364a2 + ld a, [wca38] + and $7f + cp $a + ret c + call Function37e2d + ld a, b + cp $15 + ret z + call Function3535c + ret nc + call sub_37ae9 + ret nz + ld a, [de] + set 4, a + ld [de], a + push de + ld hl, asm_3e291 + call CallFromBank0F + ld de, $0105 + call sub_37f35 + ld hl, DrawHUDsAndHPBars + call CallFromBank0F + ld hl, text_36495 + call PrintText + call Function37e2d + ld a, b + pop de + cp $b + jr z, asm_36484 + cp $f + jr z, asm_36484 + cp 2 + jr z, asm_36484 + ret + +asm_36484: + ld a, [de] + res 4, a + ld [de], a + ld a, [hl] + call sub_37ec2 + call Function37e60 + ld hl, DrawHUDsAndHPBars + jp CallFromBank0F + +text_36495: + db $0 + db $59 + db $ca + db $4f + db $d4 + db $b9 + db $34 + db $dd + db $b5 + db $df + db $c0 + db $e7 + db $58 + +sub_364a2: + ld a, [de] + and $20 + ret z + xor a + ld [de], a + ldh a, [hBattleTurn] + and a + ld a, [wca36] + ld hl, wd93b + jr z, asm_364b9 + ld hl, wPartyMon1Status + ld a, [wcd41] + +asm_364b9: + ld bc, $30 + call AddNTimes + xor a + ld [hl], a + ld hl, text_364c7 + jp PrintText + +text_364c7: + db $0 + db $ce + db $c9 + db $b5 + db $dd + db $b1 + db $3b + db $c3 + db $59 + db $c9 + db $4f + db $ba + db $b5 + db $d8 + db $26 + db $7f + db $c4 + db $b9 + db $c0 + db $e7 + db $58 + +asm_364dc: + xor a + ld [wcccd], a + call sub_3750b + ret nz + ld de, wcde7 + ldh a, [hBattleTurn] + and a + jr z, asm_364ef + ld de, wca10 + +asm_364ef: + ld a, [de] + and a + ret nz + ld a, [wca38] + and $7f + cp $a + ret c + call Function37e2d + ld a, b + cp $16 + ret z + call Function3535c + ret nc + call sub_37ae9 + ret nz + ld a, [de] + set 5, a + ld [de], a + push de + call sub_36ffd + ld de, $0108 + call sub_37f35 + ld hl, DrawHUDsAndHPBars + call CallFromBank0F + ld hl, text_36546 + call PrintText + call Function37e2d + ld a, b + pop de + cp $c + jr z, asm_36535 + cp $f + jr z, asm_36535 + cp 2 + jr z, asm_36535 + ret + +asm_36535: + ld a, [de] + res 5, a + ld [de], a + ld a, [hl] + call sub_37ec2 + call Function37e60 + ld hl, DrawHUDsAndHPBars + jp CallFromBank0F + +text_36546: + db $0 + db $59 + db $ca + db $4f + db $ba + db $b5 + db $d8 + db $32 + db $b9 + db $c6 + db $c5 + db $df + db $c0 + db $e7 + db $58 + +asm_36555: + xor a + ld [wcccd], a + call sub_3750b + ret nz + ld de, wcde7 + ldh a, [hBattleTurn] + and a + jr z, asm_36568 + ld de, wca10 + +asm_36568: + ld a, [de] + and a + ret nz + ld a, [wca38] + and $7f + cp $a + ret c + call Function37e2d + ld a, b + cp $18 + ret z + call Function3535c + ret nc + call sub_37ae9 + ret nz + ld a, [de] + set 6, a + ld [de], a + push de + ld hl, sub_3e254 + call CallFromBank0F + ld de, $0109 + call sub_37f35 + ld hl, DrawHUDsAndHPBars + call CallFromBank0F + call sub_374db + call Function37e2d + ld a, b + pop de + cp $e + jr z, asm_365ae + cp $f + jr z, asm_365ae + cp 2 + jr z, asm_365ae + ret + +asm_365ae: + ld a, [de] + res 6, a + ld [de], a + ld a, [hl] + call sub_37ec2 + call Function37e60 + ld hl, DrawHUDsAndHPBars + jp CallFromBank0F + +Function365bf: + ld hl, wcaa9 + ld de, wc9f0 + ldh a, [hBattleTurn] + and a + jr z, asm_365d0 + ld hl, wcab1 + ld de, wc9e9 + +asm_365d0: + ld a, [de] + sub $a + cp 8 + jr c, asm_365d9 + sub $28 + +asm_365d9: + ld c, a + ld b, 0 + add hl, bc + ld b, [hl] + inc b + ld a, $d + cp b + jp c, asm_366ac + ld a, [de] + cp $12 + jr c, asm_365f1 + inc b + ld a, $d + cp b + jr nc, asm_365f1 + ld b, a + +asm_365f1: + ld [hl], b + ld a, c + cp 4 + jr nc, asm_36661 + push hl + ld hl, wca17 + ld de, wca93 + ldh a, [hBattleTurn] + and a + jr z, asm_36609 + ld hl, wcdee + ld de, wca9e + +asm_36609: + push bc + sla c + ld b, 0 + add hl, bc + ld a, c + add e + ld e, a + jr nc, asm_36615 + inc d + +asm_36615: + pop bc + ld a, [hld] + sub $e7 + jr nz, asm_36621 + ld a, [hl] + sbc 3 + jp z, asm_366aa + +asm_36621: + push hl + push bc + ld hl, Data3687a + dec b + sla b + ld c, b + ld b, 0 + add hl, bc + pop bc + xor a + ldh [hQuotient], a + ld a, [de] + ldh [hQuotient + 1], a + inc de + ld a, [de] + ldh [hQuotient + 2], a + ld a, [hli] + ldh [hPrintNumDivisor], a + call Multiply + ld a, [hl] + ldh [hPrintNumDivisor], a + ld b, 4 + call Divide + pop hl + ldh a, [hQuotient + 2] + sub $e7 + ldh a, [hQuotient + 1] + sbc 3 + jp c, asm_3665a + ld a, 3 + ldh [hQuotient + 1], a + ld a, $e7 + ldh [hQuotient + 2], a + +asm_3665a: + ldh a, [hQuotient + 1] + ld [hli], a + ldh a, [hQuotient + 2] + ld [hl], a + pop hl + +asm_36661: + ld b, c + inc b + call sub_3682e + +asm_36666: + ld hl, wca3e + ld de, wc9ef + ld bc, wcadc + ldh a, [hBattleTurn] + and a + jr z, asm_3667d + ld hl, wca43 + ld de, wc9e8 + ld bc, wcad8 + +asm_3667d: + call sub_35375 + call sub_37f0f + call sub_353ef + ld a, [de] + cp $6b + jr nz, asm_3668f + pop bc + ld a, 1 + ld [bc], a + +asm_3668f: + ldh a, [hBattleTurn] + and a + ld hl, sub_3e360 + call z, CallFromBank0F + ld hl, text_366b2 + call PrintText + ld hl, sub_3e254 + call CallFromBank0F + ld hl, asm_3e291 + jp CallFromBank0F + +asm_366aa: + pop hl + dec [hl] + +asm_366ac: + call sub_37f5f + jp asm_3746a + +text_366b2: + db $0 + db $5a + db $c9 + db $4f + db $50 + db $1 + dw wcd31 + db $0 + db $26 + db $50 + db $8 + ld hl, text_366d3 + ldh a, [hBattleTurn] + and a + ld a, [wc9f0] + jr z, asm_366cc + ld a, [wc9e9] + +asm_366cc: + cp $12 + ret nc + ld hl, text_366db + ret + +text_366d3: + db $a + db $0 + db $4c + db $28 + db $e3 + db $de + db $c4 + db $50 + +text_366db: + db $0 + db $7f + db $b1 + db $26 + db $df + db $c0 + db $e7 + db $58 + +asm_366e3: + ld hl, wcab1 + ld de, wc9f0 + ldh a, [hBattleTurn] + and a + jr z, asm_36703 + ld hl, wcaa9 + ld de, wc9e9 + ld a, [wLinkMode] + cp 3 + jr z, asm_36703 + call BattleRandom + cp $40 + jp c, asm_367f0 + +asm_36703: + call sub_3750b + jp nz, asm_367f0 + ld a, [de] + cp $44 + jr c, asm_36719 + call Function3535c + jp nc, asm_367e6 + ld a, [de] + sub $44 + jr asm_36736 + +asm_36719: + push hl + push de + call Function351d0 + pop de + pop hl + ld a, [wca3a] + and a + jp nz, asm_367f0 + call sub_37e0d + jp nz, asm_367f0 + ld a, [de] + sub $12 + cp 8 + jr c, asm_36736 + sub $28 + +asm_36736: + ld c, a + ld b, 0 + add hl, bc + ld b, [hl] + dec b + jp z, asm_367e6 + ld a, [de] + cp $24 + jr c, asm_3674c + cp $44 + jr nc, asm_3674c + dec b + jr nz, asm_3674c + inc b + +asm_3674c: + ld [hl], b + ld a, c + cp 4 + jr nc, asm_367b9 + push hl + push de + ld hl, wcdee + ld de, wca9e + ldh a, [hBattleTurn] + and a + jr z, asm_36765 + ld hl, wca17 + ld de, wca93 + +asm_36765: + push bc + sla c + ld b, 0 + add hl, bc + ld a, c + add e + ld e, a + jr nc, asm_36771 + inc d + +asm_36771: + pop bc + ld a, [hld] + sub 1 + jr nz, asm_3677c + ld a, [hl] + and a + jp z, asm_367e3 + +asm_3677c: + push hl + push bc + ld hl, Data3687a + dec b + sla b + ld c, b + ld b, 0 + add hl, bc + pop bc + xor a + ldh [hQuotient], a + ld a, [de] + ldh [hQuotient + 1], a + inc de + ld a, [de] + ldh [hQuotient + 2], a + ld a, [hli] + ldh [hPrintNumDivisor], a + call Multiply + ld a, [hl] + ldh [hPrintNumDivisor], a + ld b, 4 + call Divide + pop hl + ldh a, [hQuotient + 2] + ld b, a + ldh a, [hQuotient + 1] + or b + jp nz, asm_367b1 + ldh [hQuotient + 1], a + ld a, 1 + ldh [hQuotient + 2], a + +asm_367b1: + ldh a, [hQuotient + 1] + ld [hli], a + ldh a, [hQuotient + 2] + ld [hl], a + pop de + pop hl + +asm_367b9: + ld b, c + inc b + push de + call sub_3682e + +asm_367bf: + pop de + ld a, [de] + cp $44 + jr nc, asm_367c8 + call sub_37eec + +asm_367c8: + ldh a, [hBattleTurn] + and a + ld hl, sub_3e360 + call nz, CallFromBank0F + ld hl, text_367fa + call PrintText + ld hl, sub_3e254 + call nz, CallFromBank0F + ld hl, asm_3e291 + jp CallFromBank0F + +asm_367e3: + pop de + pop hl + inc [hl] + +asm_367e6: + ld a, [de] + cp $44 + ret nc + call sub_37f5f + jp asm_3746a + +asm_367f0: + ld a, [de] + cp $44 + ret nc + call sub_37f5f + jp asm_37494 + +text_367fa: + db $0 + db $59 + db $c9 + db $4f + db $50 + db $1 + dw wcd31 + db $0 + db $26 + db $50 + db $8 + ld hl, text_36826 + ldh a, [hBattleTurn] + and a + ld a, [wc9f0] + jr z, asm_36814 + ld a, [wc9e9] + +asm_36814: + cp $1a + ret c + cp $44 + ret nc + ld hl, text_3681e + ret + +text_3681e: + db $a + db $0 + db $4c + db $26 + db $b8 + db $df + db $c4 + db $50 + +text_36826: + db $0 + db $7f + db $bb + db $26 + db $df + db $c0 + db $e7 + db $58 + +sub_3682e: + ld hl, text_36845 + ld c, $50 + +asm_36833: + dec b + jr z, asm_3683c + +asm_36836: + ld a, [hli] + cp c + jr z, asm_36833 + jr asm_36836 + +asm_3683c: + ld de, wcd31 + ld bc, $a + jp CopyBytes + +text_36845: + db $ba + db $b3 + db $29 + db $b7 + db $d8 + db $e2 + db $b8 + db $50 + db $3e + db $b3 + db $27 + db $e2 + db $d8 + db $e2 + db $b8 + db $50 + db $bd + db $3a + db $d4 + db $bb + db $50 + db $c4 + db $b8 + db $bc + db $e1 + db $ba + db $b3 + db $29 + db $b7 + db $50 + db $c4 + db $b8 + db $bc + db $e1 + db $3e + db $b3 + db $27 + db $e2 + db $50 + db $d2 + db $b2 + db $c1 + db $e1 + db $b3 + db $d8 + db $c2 + db $50 + db $b6 + db $b2 + db $cb + db $d8 + db $c2 + db $50 + +Data3687a: + dw $6419 + dw $641c + dw $6421 + dw $6428 + dw $6432 + dw $6442 + dw $101 + dw $a0f + dw $102 + dw $a19 + dw $103 + dw $a23 + dw $104 + +asm_36894: + ld bc, wPlayerSubStatus3 + ld de, wc9ef + ld hl, wca56 + ldh a, [hBattleTurn] + and a + jr z, asm_368ab + ld bc, wEnemySubStatus3 + ld de, wc9e8 + ld hl, wca58 + +asm_368ab: + ld a, [bc] + bit 0, a + ret z + push hl + ld hl, wce29 + ld a, [hli] + ld b, a + ld c, [hl] + pop hl + ld a, [hl] + add c + ld [hld], a + ld a, [hl] + adc b + ld [hl], a + ld hl, wca45 + ldh a, [hBattleTurn] + and a + jr z, asm_368c8 + ld hl, wca4d + +asm_368c8: + dec [hl] + jr nz, asm_368ff + ld hl, wPlayerSubStatus3 + res 0, [hl] + ld hl, text_34a71 + call PrintText + ld a, 1 + ld [wc9f1], a + ld hl, wca56 + ld a, [hld] + add a + ld b, a + ld [wce2a], a + ld a, [hl] + rl a + ld [wce29], a + or b + jr nz, asm_368f2 + ld a, 1 + ld [wca3a], a + +asm_368f2: + xor a + ld [hli], a + ld [hl], a + ld a, $75 + ld [wc9ef], a + ld b, $22 + jp asm_37f6b + +asm_368ff: + ld hl, text_34a65 + call PrintText + jp asm_357a9 + +asm_36908: + ld hl, wPlayerSubStatus3 + ld de, wca55 + ld bc, wca45 + ldh a, [hBattleTurn] + and a + jr z, asm_3691f + ld hl, wEnemySubStatus3 + ld de, wTrainerClass + ld bc, wca4d + +asm_3691f: + set 0, [hl] + xor a + ld [de], a + inc de + ld [de], a + ld [wc9f0], a + ld [wc9e9], a + call BattleRandom + and 1 + inc a + inc a + ld [bc], a + ld a, 1 + ld [wca5c], a + call sub_37eec + jp asm_357a9 + +asm_3693e: + ld hl, wPlayerSubStatus3 + ld de, wca45 + ldh a, [hBattleTurn] + and a + jr z, asm_3694f + ld hl, wEnemySubStatus3 + ld de, wca4d + +asm_3694f: + bit 1, [hl] + ret z + ld a, [de] + dec a + ld [de], a + jr nz, asm_36964 + res 1, [hl] + set 7, [hl] + call BattleRandom + and 1 + inc a + inc a + inc de + ld [de], a + +asm_36964: + ld b, $3d + jp asm_37f6b + +asm_36969: + ld hl, wPlayerSubStatus3 + ld de, wca45 + ldh a, [hBattleTurn] + and a + jr z, asm_3697a + ld hl, wEnemySubStatus3 + ld de, wca4d + +asm_3697a: + set 1, [hl] + call BattleRandom + and 1 + inc a + inc a + ld [de], a + ret + +asm_36985: + ldh a, [hBattleTurn] + and a + jr nz, asm_369e4 + ld a, [wBattleMode] + dec a + jr nz, asm_369cf + ld a, [wCurPartyLevel] + ld b, a + ld a, [wca0f] + cp b + jr nc, asm_369bc + add b + ld c, a + inc c + +asm_3699d: + call BattleRandom + cp c + jr nc, asm_3699d + srl b + srl b + cp b + jr nc, asm_369bc + xor a + ld [wca5c], a + call sub_37f0f + ld a, [wc9ef] + cp $64 + jp nz, asm_374b1 + jp Function37499 + +asm_369bc: + ld hl, sub_3d3f4 + call CallFromBank0F + xor a + ld [wcccd], a + inc a + ld [wce06], a + ld a, [wc9ef] + jr asm_36a3e + +asm_369cf: + xor a + ld [wca5c], a + call sub_37f0f + ld hl, text_374c8 + ld a, [wc9ef] + cp $64 + jp nz, PrintText + jp Function37499 + +asm_369e4: + ld a, [wBattleMode] + dec a + jr nz, asm_36a29 + ld a, [wca0f] + ld b, a + ld a, [wCurPartyLevel] + cp b + jr nc, asm_36a16 + add b + ld c, a + inc c + +asm_369f7: + call BattleRandom + cp c + jr nc, asm_369f7 + srl b + srl b + cp b + jr nc, asm_36a16 + xor a + ld [wca5c], a + call sub_37f0f + ld a, [wc9e8] + cp $64 + jp nz, asm_374b1 + jp Function37499 + +asm_36a16: + ld hl, sub_3d3f4 + call CallFromBank0F + xor a + ld [wcccd], a + inc a + ld [wce06], a + ld a, [wc9e8] + jr asm_36a3e + +asm_36a29: + xor a + ld [wca5c], a + call sub_37f0f + ld hl, text_374c8 + ld a, [wc9e8] + cp $64 + jp nz, PrintText + jp asm_37494 + +asm_36a3e: + push af + ld a, 1 + ld [wca5c], a + call sub_37f0f + ld c, 20 + call DelayFrames + pop af + ld hl, text_36a61 + cp $64 + jr z, text_36a5e + ld hl, text_36a73 + cp $2e + jr z, text_36a5e + ld hl, text_36a85 + +text_36a5e: + jp PrintText + +text_36a61: + db $0 + db $5a + db $ca + db $7f + db $be + db $de + db $c4 + db $b3 + db $b6 + db $d7 + db $4f + db $d8 + db $30 + db $c2 + db $bc + db $c0 + db $e7 + db $58 + +text_36a73: + db $0 + db $59 + db $ca + db $7f + db $b5 + db $2c + db $b9 + db $32 + db $b2 + db $c3 + db $4f + db $c6 + db $29 + db $30 + db $bc + db $c0 + db $e7 + db $58 + +text_36a85: + db $0 + db $59 + db $ca + db $4f + db $cc + db $b7 + db $c4 + db $3a + db $bb + db $da + db $c0 + db $e7 + db $58 + +asm_36a92: + ld hl, wPlayerSubStatus3 + ld de, wca45 + ld bc, wca55 + ldh a, [hBattleTurn] + and a + jr z, asm_36aa9 + ld hl, wEnemySubStatus3 + ld de, wca4d + ld bc, wTrainerClass + +asm_36aa9: + bit 2, [hl] + jp nz, asm_36af2 + set 2, [hl] + ld hl, wc9f0 + ldh a, [hBattleTurn] + and a + jr z, asm_36abb + ld hl, wc9e9 + +asm_36abb: + ld a, [hl] + cp $4d + jr z, asm_36aec + cp $2c + ld a, 1 + jr z, asm_36ae7 + ld a, [hl] + cp $68 + jr nz, asm_36ada + +asm_36acb: + call BattleRandom + and 3 + jr z, asm_36acb + dec a + jr nz, asm_36ae7 + ld a, 1 + ld [bc], a + jr asm_36af7 + +asm_36ada: + call BattleRandom + cp 2 + jr c, asm_36ae6 + call BattleRandom + and 3 + +asm_36ae6: + inc a + +asm_36ae7: + ld [de], a + inc a + ld [bc], a + jr asm_36b14 + +asm_36aec: + ld a, 2 + ld [hl], a + dec a + jr asm_36ae7 + +asm_36af2: + ld a, [de] + dec a + ld [de], a + jr nz, asm_36b14 + +asm_36af7: + ld hl, text_36b2b + ld de, wPlayerSubStatus3 + ldh a, [hBattleTurn] + and a + jr z, asm_36b08 + ld hl, text_36b40 + ld de, wEnemySubStatus3 + +asm_36b08: + ld a, [de] + res 2, a + ld [de], a + push bc + call PrintText + pop bc + xor a + ld [bc], a + ret + +asm_36b14: + ld a, [wca7c] + ld h, a + ld a, [wca7b] + ld l, a + +asm_36b1c: + ld a, [hld] + cp 5 + jr nz, asm_36b1c + inc hl + ld a, h + ld [wca7c], a + ld a, l + ld [wca7b], a + ret + +text_36b2b: + db $0 + db $b1 + db $b2 + db $c3 + db $c6 + db $7f + db $50 + db $9 + dw wca55 + db $11 + db $0 + db $b6 + db $b2 + db $7f + db $b1 + db $c0 + db $df + db $c0 + db $e7 + db $58 + +text_36b40: + db $0 + db $b1 + db $b2 + db $c3 + db $c6 + db $7f + db $50 + db $9 + dw wTrainerClass + db $11 + db $0 + db $b6 + db $b2 + db $7f + db $b1 + db $c0 + db $df + db $c0 + db $e7 + db $58 + +asm_36b55: + call sub_3750b + ret nz + ld hl, wEnemySubStatus3 + ld de, wc9f0 + ldh a, [hBattleTurn] + and a + jr z, asm_36b6a + ld hl, wPlayerSubStatus3 + ld de, wc9e9 + +asm_36b6a: + call sub_36ffd + call Function3535c + ret nc + set 3, [hl] + ret + +asm_36b74: + call Function37e1d + ld a, b + cp $4b + ret nz + call sub_3750b + ret nz + ld hl, wEnemySubStatus3 + ld de, wc9f0 + ldh a, [hBattleTurn] + and a + jr z, asm_36b90 + ld hl, wPlayerSubStatus3 + ld de, wc9e9 + +asm_36b90: + push hl + call sub_36ffd + call Function37e1d + pop hl + call BattleRandom + cp c + ret nc + set 3, [hl] + ret + +asm_36ba0: + ld hl, wce29 + xor a + ld [hli], a + ld [hl], a + ld a, [wca38] + and $7f + cp $a + jr c, asm_36be0 + ld hl, wca1b + ld de, wcdf2 + ldh a, [hBattleTurn] + and a + jr z, asm_36bc0 + ld hl, wcdf2 + ld de, wca1b + +asm_36bc0: + ld a, [de] + dec de + ld b, a + ld a, [hld] + sub b + ld a, [de] + ld b, a + ld a, [hl] + sbc b + jr c, asm_36be0 + call Function351d0 + ld a, [wca3a] + and a + ret nz + ld hl, wce29 + ld a, $ff + ld [hli], a + ld [hl], a + ld a, 2 + ld [wca39], a + ret + +asm_36be0: + ld a, $ff + ld [wca39], a + ld a, 1 + ld [wca3a], a + ret + +asm_36beb: + ld hl, wPlayerSubStatus3 + ldh a, [hBattleTurn] + and a + jr z, asm_36bf6 + ld hl, wEnemySubStatus3 + +asm_36bf6: + bit 4, [hl] + ret z + res 4, [hl] + res 6, [hl] + ld b, $39 + jp asm_37f6b + +asm_36c02: + xor a + ld [wcccd], a + inc a + ld [wca5c], a + call sub_37f0f + ld hl, wPlayerSubStatus3 + ld de, wc9ef + ldh a, [hBattleTurn] + and a + jr z, asm_36c1e + ld hl, wEnemySubStatus3 + ld de, wc9e8 + +asm_36c1e: + set 4, [hl] + ld a, [de] + cp $13 + jr nz, asm_36c27 + set 6, [hl] + +asm_36c27: + ld a, [de] + cp $5b + jr nz, asm_36c2e + set 6, [hl] + +asm_36c2e: + ld a, [de] + ld [wMovementBufferCount], a + ld hl, text_36c3b + call PrintText + jp asm_357a9 + +text_36c3b: + db $0 + db $5a + db $50 + db $8 + ld a, [wMovementBufferCount] + cp $d + ld hl, text_36c6b + jr z, asm_36c6a + cp $4c + ld hl, text_36c80 + jr z, asm_36c6a + cp $82 + ld hl, text_36c92 + jr z, asm_36c6a + cp $8f + ld hl, text_36ca0 + jr z, asm_36c6a + cp $13 + ld hl, text_36cb2 + jr z, asm_36c6a + cp $5b + ld hl, text_36cc3 + +asm_36c6a: + ret + +text_36c6b: + db $0 + db $c9 + db $7f + db $cf + db $dc + db $d8 + db $33 + db $4f + db $b8 + db $b3 + db $b7 + db $26 + db $7f + db $b3 + db $2d + db $dd + db $7f + db $cf + db $b8 + db $e7 + db $58 + +text_36c80: + db $0 + db $ca + db $4f + db $cb + db $b6 + db $d8 + db $dd + db $7f + db $b7 + db $e1 + db $b3 + db $bc + db $e1 + db $b3 + db $bc + db $c0 + db $e7 + db $58 + +text_36c92: + db $0 + db $ca + db $4f + db $b8 + db $3b + db $dd + db $7f + db $cb + db $df + db $ba + db $d2 + db $c0 + db $e7 + db $58 + +text_36ca0: + db $0 + db $dd + db $4f + db $ca + db $29 + db $bc + db $b2 + db $7f + db $cb + db $b6 + db $d8 + db $26 + db $7f + db $c2 + db $c2 + db $d1 + db $e7 + db $58 + +text_36cb2: + db $0 + db $ca + db $4f + db $bf + db $d7 + db $c0 + db $b6 + db $b8 + db $7f + db $c4 + db $3b + db $b1 + db $26 + db $df + db $c0 + db $e7 + db $58 + +text_36cc3: + db $0 + db $ca + db $4f + db $b1 + db $c5 + db $dd + db $ce + db $df + db $c3 + db $7f + db $c1 + db $c1 + db $e1 + db $b3 + db $c6 + db $7f + db $d3 + db $28 + db $df + db $c0 + db $e7 + db $58 + +asm_36cd9: + ld hl, wPlayerSubStatus3 + ldh a, [hBattleTurn] + and a + jr z, asm_36ce4 + ld hl, wEnemySubStatus3 + +asm_36ce4: + bit 5, [hl] + ret z + ld a, [wca7c] + ld h, a + ld a, [wca7b] + ld l, a + +asm_36cef: + ld a, [hli] + cp $3b + jr nz, asm_36cef + dec hl + ld a, h + ld [wca7c], a + ld a, l + ld [wca7b], a + ret + +asm_36cfe: + ld hl, wPlayerSubStatus3 + ld de, wca45 + ldh a, [hBattleTurn] + and a + jr z, asm_36d0f + ld hl, wEnemySubStatus3 + ld de, wca4d + +asm_36d0f: + ld a, [wca3a] + and a + ret nz + bit 5, [hl] + jr nz, asm_36d2e + call sub_36ffd + set 5, [hl] + call BattleRandom + and 3 + cp 2 + jr c, asm_36d2b + call BattleRandom + and 3 + +asm_36d2b: + inc a + ld [de], a + ret + +asm_36d2e: + push hl + push de + ld hl, text_34a41 + call PrintText + pop hl + dec [hl] + pop hl + ret nz + res 5, [hl] + ret + +asm_36d3d: + ld hl, wca3e + ldh a, [hBattleTurn] + and a + jr z, asm_36d48 + ld hl, wca43 + +asm_36d48: + bit 1, [hl] + jr nz, asm_36d57 + set 1, [hl] + call sub_37f0f + ld hl, text_36d5a + jp PrintText + +asm_36d57: + jp Function37499 + +text_36d5a: + db $0 + db $5a + db $ca + db $4f + db $bc + db $db + db $b2 + db $7f + db $b7 + db $d8 + db $c6 + db $7f + db $c2 + db $c2 + db $cf + db $da + db $c0 + db $e7 + db $58 + +asm_36d6d: + ld hl, wca3e + ldh a, [hBattleTurn] + and a + jr z, asm_36d78 + ld hl, wca43 + +asm_36d78: + bit 2, [hl] + jr nz, asm_36d87 + set 2, [hl] + call sub_37f0f + ld hl, text_36d8d + jp PrintText + +asm_36d87: + call sub_37f5f + jp Function37499 + +text_36d8d: + db $a + db $0 + db $5a + db $ca + db $4f + db $ca + db $d8 + db $b7 + db $df + db $c3 + db $b2 + db $d9 + db $e7 + db $58 + +asm_36d9b: + ldh a, [hBattleTurn] + and a + ld a, [wc9ef] + ld hl, wca14 + jr z, asm_36dac + ld a, [wc9e8] + ld hl, wcdeb + +asm_36dac: + ld d, a + ld a, [wce29] + ld b, a + ld a, [wce2a] + ld c, a + srl b + rr c + ld a, d + cp $a5 + jr z, asm_36dc2 + srl b + rr c + +asm_36dc2: + ld a, b + or c + jr nz, asm_36dc7 + inc c + +asm_36dc7: + ld a, [hli] + ld [wPlayerEffectivenessVsEnemyMons], a + ld a, [hl] + ld [wHPBarMaxHP], a + dec hl + dec hl + ld a, [hl] + ld [wHPBarOldHP], a + sub c + ld [hld], a + ld [wHPBarNewHP], a + ld a, [hl] + ld [wcdc6], a + sbc b + ld [hl], a + ld [wcdc8], a + jr nc, asm_36ded + xor a + ld [hli], a + ld [hl], a + ld hl, wHPBarNewHP + ld [hli], a + ld [hl], a + +asm_36ded: + ld hl, wTileMap + 190 + ldh a, [hBattleTurn] + and a + ld a, 1 + jr z, asm_36dfb + ld hl, wTileMap + 42 + xor a + +asm_36dfb: + ld [wHPBarType], a + ld a, $17 + call Predef + ld hl, text_36e09 + jp PrintText + +text_36e09: + db $0 + db $5a + db $ca + db $7f + db $ba + db $b3 + db $29 + db $b7 + db $c9 + db $4f + db $ca + db $de + db $34 + db $b3 + db $dd + db $7f + db $b3 + db $b9 + db $c0 + db $e7 + db $58 + +asm_36e1e: + call Function37e2d + ld a, b + cp $19 + ret z + call Function3535c + ret nc + jr asm_36e4e + +asm_36e2b: + call Function37e2d + ld a, b + cp $19 + jr nz, asm_36e43 + ld a, [hl] + ld [wCountSetBitsResult], a + call GetItemName + call sub_37f5f + ld hl, text_374f7 + jp PrintText + +asm_36e43: + call sub_3750b + jr nz, asm_36e9e + ld a, [wca3a] + and a + jr nz, asm_36e9e + +asm_36e4e: + ldh a, [hBattleTurn] + and a + ld hl, wEnemySubStatus3 + ld bc, wca4e + ld a, [wc9f0] + jr z, asm_36e65 + ld hl, wPlayerSubStatus3 + ld bc, wca46 + ld a, [wc9e9] + +asm_36e65: + bit 7, [hl] + jr nz, asm_36e9e + set 7, [hl] + push af + call BattleRandom + and 3 + inc a + inc a + ld [bc], a + pop af + cp $4c + jr z, asm_36e86 + cp $5c + jr z, asm_36e86 + cp $76 + jr z, asm_36e86 + call sub_37f0f + jr asm_36e8c + +asm_36e86: + ld de, $0103 + call sub_37f35 + +asm_36e8c: + ld hl, Data36e92 + jp PrintText + +Data36e92: + db $0 + db $59 + db $ca + db $4f + db $ba + db $de + db $d7 + db $de + db $bc + db $c0 + db $e7 + db $58 + +asm_36e9e: + cp $4c + ret z + cp $5c + ret z + cp $76 + ret z + call sub_37f5f + jp asm_37494 + +asm_36ead: + ld hl, wcde7 + ld de, wc9f2 + ldh a, [hBattleTurn] + and a + jp z, asm_36ebf + ld hl, wca10 + ld de, wc9eb + +asm_36ebf: + ld a, [wca38] + and $7f + cp $a + jr c, asm_36f2f + ld a, [hl] + and a + jr nz, asm_36f29 + push hl + call Function37e2d + ld a, b + cp $18 + ld a, [hl] + pop hl + jr nz, asm_36ee6 + ld [wCountSetBitsResult], a + call GetItemName + call sub_37f5f + ld hl, text_374f7 + jp PrintText + +asm_36ee6: + ld a, [wca3a] + and a + jr nz, asm_36f29 + set 6, [hl] + push hl + ld hl, sub_3e254 + call CallFromBank0F + ld c, 30 + call DelayFrames + call sub_37f0f + ld hl, DrawHUDsAndHPBars + call CallFromBank0F + call sub_374db + call Function37e2d + ld a, b + pop de + cp $e + jr z, asm_36f18 + cp $f + jr z, asm_36f18 + cp 2 + jr z, asm_36f18 + ret + +asm_36f18: + ld a, [de] + res 6, a + ld [de], a + ld a, [hl] + call sub_37ec2 + call Function37e60 + ld hl, DrawHUDsAndHPBars + jp CallFromBank0F + +asm_36f29: + call sub_37f5f + jp asm_374b1 + +asm_36f2f: + call sub_37f5f + jp asm_35643 + +asm_36f35: + call sub_37f5f + ld hl, wca14 + ld de, wcabc + ld bc, wca3e + ldh a, [hBattleTurn] + and a + jr z, asm_36f4f + ld hl, wcdeb + ld de, wcabd + ld bc, wca43 + +asm_36f4f: + ld a, [bc] + bit 4, a + jr nz, asm_36f9d + push bc + ld a, [hli] + ld b, [hl] + srl a + rr b + srl a + rr b + dec hl + dec hl + ld a, b + ld [de], a + ld a, [hld] + sub b + ld d, a + ld a, [hl] + sbc 0 + pop bc + jr c, asm_36fa2 + ld [hli], a + ld [hl], d + ld h, b + ld l, c + set 4, [hl] + ld a, [wce5f] + add a + jr c, asm_36f89 + xor a + ld [wcccd], a + ld [wccc1], a + ld [wca5c], a + ld a, $a4 + call sub_37f23 + jr asm_36f91 + +asm_36f89: + callab Functioncc000_2 + +asm_36f91: + ld hl, text_36fa8 + call PrintText + ld hl, DrawHUDsAndHPBars + jp CallFromBank0F + +asm_36f9d: + ld hl, text_36fd8 + jr asm_36fa5 + +asm_36fa2: + ld hl, text_36fd0 + +asm_36fa5: + jp PrintText + +text_36fa8: + db $0 + db $5a + db $c9 + db $4f + db $3c + db $de + db $bc + db $de + db $26 + db $7f + db $b1 + db $d7 + db $dc + db $da + db $c0 + db $58 + +text_36fd8: + db $0 + db $bc + db $b6 + db $bc + db $7f + db $5a + db $c9 + db $4f + db $d0 + db $26 + db $dc + db $d8 + db $ca + db $7f + db $bd + db $33 + db $c6 + db $7f + db $33 + db $c3 + db $b2 + db $c0 + db $e7 + db $58 + +text_36fd0: + db $0 + db $bc + db $b6 + db $bc + db $7f + db $3c + db $de + db $bc + db $de + db $dd + db $7f + db $30 + db $bd + db $c6 + db $ca + db $4f + db $c0 + db $b2 + db $d8 + db $e2 + db $b8 + db $26 + db $7f + db $c0 + db $d8 + db $c5 + db $b6 + db $df + db $c0 + db $e7 + db $58 + +asm_36fef: + ld hl, wca3e + ldh a, [hBattleTurn] + and a + jr z, asm_36ffa + ld hl, wca43 + +asm_36ffa: + set 5, [hl] + ret + +sub_36ffd: + push hl + ld hl, wca43 + ldh a, [hBattleTurn] + and a + jr z, asm_37009 + ld hl, wca3e + +asm_37009: + res 5, [hl] + pop hl + ret + ld hl, wca3e + ldh a, [hBattleTurn] + and a + jr z, asm_37018 + ld hl, wca43 + +asm_37018: + set 6, [hl] + ret + +asm_3701b: + call sub_37f5f + ld a, [wca3a] + and a + jr nz, asm_37055 + ld hl, wca04 + ld de, wcad7 + ldh a, [hBattleTurn] + and a + jr z, asm_37035 + ld hl, wcddb + ld de, wcad6 + +asm_37035: + call sub_37e0d + jr nz, asm_37055 + ld a, [de] + and a + jr z, asm_37055 + +asm_3703e: + ld a, [hli] + cp $66 + jr nz, asm_3703e + dec hl + ld a, [de] + ld [hl], a + ld [wCountSetBitsResult], a + call Unreferenced_GetMoveName + call sub_37f0f + ld hl, text_37058 + jp PrintText + +asm_37055: + jp Function37499 + +text_37058: + db $0 + db $5a + db $ca + db $4f + db $50 + db $1 + dw wStringBuffer1 + db $0 + db $dd + db $7f + db $b5 + db $3e + db $b4 + db $c0 + db $e7 + db $58 + +asm_37069: + ld a, [wca3a] + and a + jr nz, asm_3709a + ld hl, wca43 + ld de, wcde9 + ldh a, [hBattleTurn] + and a + jr z, asm_37080 + ld hl, wca3e + ld de, wca12 + +asm_37080: + ld a, [de] + cp $16 + jr z, asm_3709a + inc de + ld a, [de] + cp $16 + jr z, asm_3709a + bit 7, [hl] + jr nz, asm_3709a + set 7, [hl] + call sub_37f0f + ld hl, text_370a3 + jp PrintText + +asm_3709a: + call sub_37f5f + ld hl, text_370b2 + jp PrintText + +text_370a3: + db $0 + db $59 + db $c6 + db $4f + db $c0 + db $c8 + db $dd + db $7f + db $b3 + db $b4 + db $c2 + db $b9 + db $c0 + db $e7 + db $58 + +text_370b2: + db $0 + db $59 + db $ca + db $4f + db $ba + db $b3 + db $29 + db $b7 + db $dd + db $7f + db $b6 + db $dc + db $bc + db $c0 + db $e7 + db $58 + +asm_370c2: + call sub_37f0f + jp asm_37480 + +asm_370c8: + ld a, [wca3a] + and a + jr nz, asm_37132 + ld de, wca50 + ld hl, wcddb + ld bc, wcad7 + ldh a, [hBattleTurn] + and a + jr z, asm_370e5 + ld de, wca48 + ld hl, wca04 + ld bc, wcad6 + +asm_370e5: + ld a, [de] + and a + jr nz, asm_37132 + ld a, [bc] + and a + jr z, asm_37132 + cp $a5 + jr z, asm_37132 + ld [wCountSetBitsResult], a + ld b, a + ld c, $ff + +asm_370f7: + inc c + ld a, [hli] + cp b + jr nz, asm_370f7 + ldh a, [hBattleTurn] + and a + ld hl, wcde1 + jr z, asm_37107 + ld hl, wca0a + +asm_37107: + ld b, 0 + add hl, bc + ld a, [hl] + and a + jr z, asm_37132 + call BattleRandom + and 7 + inc a + inc c + swap c + add c + ld [de], a + call sub_37eec + ld hl, wcad3 + ldh a, [hBattleTurn] + and a + jr nz, asm_37125 + inc hl + +asm_37125: + ld a, [wCountSetBitsResult] + ld [hl], a + call Unreferenced_GetMoveName + ld hl, text_37138 + jp PrintText + +asm_37132: + call sub_37f5f + jp Function37499 + +text_37138: + db $0 + db $59 + db $c9 + db $4f + db $50 + db $1 + dw wStringBuffer1 + db $0 + db $dd + db $7f + db $cc + db $b3 + db $2c + db $ba + db $d2 + db $c0 + db $e7 + db $58 + +asm_3714b: + xor a + ld hl, wStringBuffer1 + ld [hli], a + ldh a, [hBattleTurn] + and a + ld a, [wca0f] + jr z, asm_3715b + ld a, [wcde6] + +asm_3715b: + add a + ld hl, wcacc + add [hl] + ld [hld], a + jr nc, text_3716e + inc [hl] + dec hl + jr nz, text_3716e + inc [hl] + +text_3716e: + ld hl, Data3716e + jp PrintText + +Data3716e: + db $0 + db $ba + db $3a + db $de + db $26 + db $7f + db $b1 + db $c0 + db $d8 + db $c6 + db $7f + db $c1 + db $d7 + db $3a + db $df + db $c0 + db $e7 + db $58 + +asm_37180: + ld hl, wcdf7 + ld de, wca20 + ldh a, [hBattleTurn] + and a + jr z, asm_3718f + push hl + ld h, d + ld l, e + pop de + +asm_3718f: + call sub_37e0d + jr nz, asm_371b7 + ld a, [hli] + ld [de], a + inc de + ld a, [hl] + ld [de], a + call sub_37f0f + ld hl, text_371a2 + jp PrintText + +text_371a2: + db $0 + db $59 + db $c9 + db $7f + db $8f + db $81 + db $42 + db $dd + db $4f + db $2c + db $3c + db $de + db $c6 + db $7f + db $ca + db $d8 + db $c2 + db $b9 + db $c0 + db $e7 + db $58 + +asm_371b7: + jp Function37499 + +asm_371ba: + ld a, 7 + ld hl, wcaa9 + call sub_37224 + ld hl, wcab1 + call sub_37224 + ld hl, wca93 + ld de, wca16 + call sub_3722b + ld hl, wca9e + ld de, wcded + call sub_3722b + ld hl, wcde7 + ld de, wcac2 + ldh a, [hBattleTurn] + and a + jr z, asm_371e9 + ld hl, wca10 + dec de + +asm_371e9: + ld a, [hl] + ld [hl], 0 + and $27 + jr z, asm_371f3 + ld a, $ff + ld [de], a + +asm_371f3: + xor a + ld [wca48], a + ld [wca50], a + ld hl, wcad3 + ld [hli], a + ld [hl], a + ld hl, wPlayerSubStatus3 + res 7, [hl] + inc hl + ld a, [hl] + and $78 + ld [hli], a + ld a, [hl] + and $f8 + ld [hl], a + ld hl, wEnemySubStatus3 + res 7, [hl] + inc hl + ld a, [hl] + and $78 + ld [hli], a + ld a, [hl] + and $f8 + ld [hl], a + call sub_37f0f + ld hl, text_37234 + jp PrintText + +sub_37224: + ld b, 8 + +asm_37226: + ld [hli], a + dec b + jr nz, asm_37226 + ret + +sub_3722b: + ld b, 8 + +asm_3722d: + ld a, [hli] + ld [de], a + inc de + dec b + jr nz, asm_3722d + ret + +text_37234: + db $0 + db $bd + db $3d + db $c3 + db $c9 + db $7f + db $8c + db $92 + db $e3 + db $8f + db $8c + db $26 + db $4f + db $d3 + db $c4 + db $c6 + db $7f + db $d3 + db $34 + db $df + db $c0 + db $e7 + db $58 + +asm_3724b: + ldh a, [hBattleTurn] + and a + ld de, wca12 + ld hl, wca14 + ld a, [wc9ef] + jr z, asm_37262 + ld de, wcde9 + ld hl, wcdeb + ld a, [wc9e8] + +asm_37262: + ld b, a + ld a, [de] + cp [hl] + inc de + inc hl + ld a, [de] + sbc [hl] + jp z, asm_372c9 + ld a, b + cp $9c + jr nz, asm_37294 + push hl + push de + push af + call sub_37f5f + ld hl, wca10 + ldh a, [hBattleTurn] + and a + jr z, asm_37282 + ld hl, wcde7 + +asm_37282: + ld a, [hl] + and a + ld [hl], 2 + ld hl, text_372cf + jr z, asm_3728e + ld hl, text_372dc + +asm_3728e: + call PrintText + pop af + pop de + pop hl + +asm_37294: + jr z, asm_372a0 + callab Function3c7d3 + jr asm_372a8 + +asm_372a0: + callab Function3c7f2 + +asm_372a8: + call sub_37f0f + ldh a, [hBattleTurn] + push af + xor 1 + ldh [hBattleTurn], a + callab sub_3c808 + pop af + ldh [hBattleTurn], a + ld hl, DrawHUDsAndHPBars + call CallFromBank0F + ld hl, text_372f2 + jp PrintText + +asm_372c9: + call sub_37f5f + jp Function37499 + +text_372cf: + db $0 + db $5a + db $ca + db $4f + db $c8 + db $d1 + db $d8 + db $ca + db $2c + db $d2 + db $c0 + db $e7 + db $57 + +text_372dc: + db $0 + db $5a + db $ca + db $7f + db $b9 + db $de + db $ba + db $b3 + db $c6 + db $c5 + db $df + db $c3 + db $4f + db $c8 + db $d1 + db $d8 + db $ca + db $2c + db $d2 + db $c0 + db $e7 + db $57 + +text_372f2: + db $0 + db $5a + db $ca + db $7f + db $c0 + db $b2 + db $d8 + db $e2 + db $b8 + db $dd + db $4f + db $b6 + db $b2 + db $cc + db $b8 + db $bc + db $c0 + db $e7 + db $58 + +asm_37305: + ld hl, wca02 + ld de, wcdd9 + ld bc, wca44 + ldh a, [hBattleTurn] + and a + jr nz, asm_37320 + ld hl, wcdd9 + ld de, wca02 + ld bc, wca3f + xor a + ld [wcd40], a + +asm_37320: + call sub_37e0d + jp nz, asm_373f1 + push hl + push de + push bc + ld hl, $ca3e + ldh a, [hBattleTurn] + and a + jr z, asm_37334 + ld hl, $ca43 + +asm_37334: + xor a + ld [wcccd], a + ld [wccc1], a + ld a, 1 + ld [wca5c], a + bit 4, [hl] + push af + ld a, $a4 + call nz, sub_37f23 + ld a, [wce5f] + add a + jr c, asm_37353 + call sub_37f0f + jr asm_3735b + +asm_37353: + callab Functioncc000_2 + +asm_3735b: + xor a + ld [wcccd], a + ld [wccc1], a + ld a, 2 + ld [wca5c], a + pop af + ld a, $a4 + call nz, sub_37f23 + pop bc + ld a, [bc] + set 3, a + ld [bc], a + pop de + pop hl + push hl + ld a, [hli] + ld [de], a + inc hl + inc de + inc de + ld bc, 4 + call CopyBytes + ldh a, [hBattleTurn] + and a + jr z, asm_3738f + ld a, [de] + ld [wcad0], a + inc de + ld a, [de] + ld [wcad1], a + dec de + +asm_3738f: + ld a, [hli] + ld [de], a + inc de + ld a, [hli] + ld [de], a + inc de + ld bc, $c + add hl, bc + push hl + ld h, d + ld l, e + add hl, bc + ld d, h + ld e, l + pop hl + ld bc, $c + call CopyBytes + ld bc, hFFE2 + add hl, bc + push de + ld d, h + ld e, l + pop hl + ld bc, hMapAnims + add hl, bc + ld b, 4 + +asm_373b4: + ld a, [de] + inc de + and a + jr z, asm_373bf + ld a, 5 + ld [hli], a + dec b + jr nz, asm_373b4 + +asm_373bf: + pop hl + ld a, [hl] + ld [wCountSetBitsResult], a + call GetPokemonName + ld hl, wca9e + ld de, wca93 + ld bc, $a + call sub_373e5 + ld hl, wcab1 + ld de, wcaa9 + ld bc, 8 + call sub_373e5 + ld hl, text_373f4 + jp PrintText + +sub_373e5: + ldh a, [hBattleTurn] + and a + jr z, asm_373ee + push hl + ld h, d + ld l, e + pop de + +asm_373ee: + jp CopyBytes + +asm_373f1: + jp Function37499 + +text_373f4: + db $0 + db $5a + db $ca + db $4f + db $50 + db $1 + dw wStringBuffer1 + db $0 + db $c6 + db $7f + db $cd + db $de + db $bc + db $de + db $bc + db $c0 + db $e7 + db $58 + +asm_37407: + ld hl, wca3f + ld de, wc9f0 + ldh a, [hBattleTurn] + and a + jr z, asm_37418 + ld hl, wca44 + ld de, wc9e9 + +asm_37418: + ld a, [de] + cp $40 + jr nz, asm_37428 + bit 1, [hl] + jr nz, asm_37439 + set 1, [hl] + ld hl, text_3743f + jr asm_37431 + +asm_37428: + bit 2, [hl] + jr nz, asm_37439 + set 2, [hl] + ld hl, text_37455 + +asm_37431: + push hl + call sub_37f0f + pop hl + jp PrintText + +asm_37439: + call sub_37f5f + jp Function37499 + +text_3743f: + db $0 + db $5a + db $ca + db $4f + db $c4 + db $b8 + db $bc + db $e1 + db $ba + db $b3 + db $29 + db $b7 + db $c6 + db $7f + db $c2 + db $d6 + db $b8 + db $c5 + db $df + db $c0 + db $e7 + db $58 + +text_37455: + db $0 + db $5a + db $ca + db $4f + db $30 + db $29 + db $b7 + db $ba + db $b3 + db $29 + db $b7 + db $c6 + db $7f + db $c2 + db $d6 + db $b8 + db $c5 + db $df + db $c0 + db $e7 + db $58 + +asm_3746a: + ld hl, text_37470 + jp PrintText + +text_37470: + db $0 + db $bc + db $b6 + db $bc + db $7f + db $ba + db $b3 + db $b6 + db $26 + db $7f + db $c5 + db $b6 + db $df + db $c0 + db $e7 + db $58 + +asm_37480: + ld hl, text_37486 + jp PrintText + +text_37486: + db $0 + db $bc + db $b6 + db $bc + db $7f + db $c5 + db $c6 + db $d3 + db $b5 + db $ba + db $d7 + db $c5 + db $b2 + db $58 + +asm_37494: + ld a, [wcad9] + and a + ret nz + +Function37499: + ld hl, text_3749f + jp PrintText + +text_3749f: + db $0 + db $bc + db $b6 + db $bc + db $7f + db $b3 + db $cf + db $b8 + db $7f + db $b7 + db $cf + db $d7 + db $c5 + db $b6 + db $df + db $c0 + db $e7 + db $58 + +asm_374b1: + ld hl, text_374b7 + jp PrintText + +text_374b7: + db $0 + db $bc + db $b6 + db $bc + db $7f + db $59 + db $c6 + db $ca + db $4f + db $b7 + db $b6 + db $c5 + db $b6 + db $df + db $c0 + db $e7 + db $58 + +text_374c8: + db $0 + db $59 + db $ca + db $4f + db $cd + db $b2 + db $b7 + db $c5 + db $7f + db $b6 + db $b5 + db $dd + db $7f + db $bc + db $c3 + db $b2 + db $d9 + db $e7 + db $58 + +sub_374db: + ld hl, text_374e1 + jp PrintText + +text_374e1: + db $0 + db $59 + db $ca + db $7f + db $cf + db $cb + db $bc + db $c3 + db $4f + db $dc + db $2b + db $26 + db $7f + db $33 + db $c6 + db $b8 + db $b8 + db $c5 + db $df + db $c0 + db $e7 + db $58 + +text_374f7: + db $0 + db $59 + db $ca + db $7f + db $4f + db $50 + db $1 + db $26 + db $cd + db $0 + db $33 + db $7f + db $cf + db $d3 + db $d7 + db $da + db $c3 + db $d9 + db $e7 + db $58 + +sub_3750b: + push hl + ld hl, wca43 + ldh a, [hBattleTurn] + and a + jr z, asm_37517 + ld hl, wca3e + +asm_37517: + bit 4, [hl] + pop hl + ret + +asm_3751b: + ld a, 5 + ld [wcccd], a + ld c, 3 + call DelayFrames + ld a, 1 + ld [wca5c], a + call sub_37f0f + ld hl, wca10 + ld de, wca3e + ldh a, [hBattleTurn] + and a + jr z, asm_3753e + ld hl, wcde7 + ld de, wca43 + +asm_3753e: + xor a + ld [hli], a + ld [hli], a + inc hl + ld [hli], a + ld [hl], a + ld a, [de] + res 7, a + ld [de], a + ret + +asm_37549: + ldh a, [hBattleTurn] + and a + ld a, [wcad7] + ld hl, wcac1 + ld de, wc9ef + jr z, asm_37560 + ld a, [wcad6] + ld de, wc9e8 + ld hl, wcac2 + +asm_37560: + cp $77 + jr z, asm_37567 + and a + jr nz, asm_37570 + +asm_37567: + ld hl, text_375a0 + call PrintText + jp asm_357a9 + +asm_37570: + ld [hl], a + ld [wCountSetBitsResult], a + dec a + ld hl, Moves + ld bc, 7 + call AddNTimes + ld a, $10 + call FarCopyBytes + call sub_37ddb + call Unreferenced_GetMoveName + call CopyStringToStringBuffer2 + call sub_37f5f + ldh a, [hBattleTurn] + and a + ld a, [wc9f0] + jr z, asm_3759a + ld a, [wc9e9] + +asm_3759a: + call Function34046 + jp asm_357a9 + +text_375a0: + db $0 + db $bc + db $b6 + db $bc + db $7f + db $84 + db $82 + db $9f + db $26 + db $b4 + db $bc + db $ca + db $4e + db $bc + db $df + db $44 + db $b2 + db $c6 + db $b5 + db $dc + db $df + db $c0 + db $e7 + db $58 + +asm_375b8: + call sub_37f0f + ld de, wc9f0 + ld hl, wcac1 + ldh a, [hBattleTurn] + and a + jr z, asm_375cc + ld de, wc9e9 + ld hl, wcac2 + +asm_375cc: + call BattleRandom + and a + jr z, asm_375cc + cp $fc + jr nc, asm_375cc + cp $76 + jr z, asm_375cc + ld [hl], a + push de + call sub_37ddb + call Function360b1 + pop de + ld a, [de] + call Function34046 + jp asm_357a9 + +asm_375ea: + ldh a, [hBattleTurn] + and a + jr nz, asm_3760f + call sub_37637 + ld a, [hl] + and a + ret nz + call sub_37649 + ld a, [hl] + and a + ret z + ld [wCountSetBitsResult], a + call Function3535c + ret nc + xor a + ld [hl], a + ld [de], a + call sub_37637 + ld a, [wCountSetBitsResult] + ld [hl], a + ld [de], a + jr asm_3762d + +asm_3760f: + call sub_37649 + ld a, [hl] + and a + ret nz + call sub_37637 + ld a, [hl] + and a + ret z + ld [wCountSetBitsResult], a + call Function3535c + ret nc + xor a + ld [hl], a + ld [de], a + call sub_37649 + ld a, [wCountSetBitsResult] + ld [hl], a + ld [de], a + +asm_3762d: + call GetItemName + ld hl, text_3765b + call PrintText + ret + +sub_37637: + ld hl, wPartyMon1Item + ld a, [wcd41] + ld bc, $30 + call AddNTimes + ld d, h + ld e, l + ld hl, wca03 + ret + +sub_37649: + ld hl, wd91c + ld a, [wca36] + ld bc, $30 + call AddNTimes + ld d, h + ld e, l + ld hl, wcdda + ret + +text_3765b: + db $0 + db $5a + db $ca + db $7f + db $59 + db $b6 + db $d7 + db $4f + db $50 + db $1 + dw wStringBuffer1 + db $0 + db $dd + db $7f + db $b3 + db $3a + db $b2 + db $c4 + db $df + db $c0 + db $e7 + db $58 + +asm_37672: + ld hl, wca44 + ldh a, [hBattleTurn] + and a + jr z, asm_3767d + ld hl, wca3f + +asm_3767d: + call sub_37e0d + jr nz, asm_376a0 + bit 7, [hl] + jr nz, asm_376a0 + set 7, [hl] + call sub_37f0f + ld hl, text_37691 + jp PrintText + +text_37691: + db $0 + db $59 + db $ca + db $4f + db $d3 + db $b3 + db $7f + db $c6 + db $29 + db $d7 + db $da + db $c5 + db $b2 + db $e7 + db $58 + +asm_376a0: + call sub_37f5f + jp Function37499 + +asm_376a6: + ld hl, wca40 + ld de, wcde7 + ldh a, [hBattleTurn] + and a + jr z, asm_376b7 + ld hl, wca3b + ld de, wca10 + +asm_376b7: + call sub_37e0d + jr nz, asm_376e0 + ld a, [de] + and 7 + jr z, asm_376e0 + bit 0, [hl] + jr nz, asm_376e0 + set 0, [hl] + call sub_37f0f + ld hl, text_376d0 + jp PrintText + +text_376d0: + db $0 + db $59 + db $ca + db $4f + db $b1 + db $b8 + db $d1 + db $dd + db $7f + db $d0 + db $ca + db $2c + db $d2 + db $c0 + db $e7 + db $58 + +asm_376e0: + call sub_37f5f + jp Function37499 + +asm_376e6: + ld hl, wPartyMon1Status + ld a, [wcd41] + ld bc, $30 + call AddNTimes + ld d, h + ld e, l + ld hl, wca10 + ldh a, [hBattleTurn] + and a + jr z, asm_3770d + ld hl, wd93b + ld a, [wca36] + ld bc, $30 + call AddNTimes + ld d, h + ld e, l + ld hl, wcde7 + +asm_3770d: + bit 5, [hl] + ret z + res 5, [hl] + ld a, [de] + res 5, a + ld [de], a + ld hl, text_3771d + call PrintText + ret + +text_3771d: + db $0 + db $5a + db $c9 + db $4f + db $ba + db $b5 + db $d8 + db $26 + db $7f + db $c4 + db $b9 + db $c0 + db $e7 + db $58 + +asm_3772b: + ld hl, wca40 + ldh a, [hBattleTurn] + and a + jr z, asm_37736 + ld hl, wca3b + +asm_37736: + call sub_37e0d + jr nz, asm_3777a + bit 1, [hl] + jr nz, asm_3777a + set 1, [hl] + call sub_37f0f + callab sub_3c7b0 + callab sub_3c75e + ld hl, text_3775a + jp PrintText + +text_3775a: + db $0 + db $5a + db $ca + db $4f + db $2c + db $3c + db $de + db $c6 + db $7f + db $b8 + db $27 + db $dd + db $7f + db $b3 + db $df + db $c0 + db $51 + db $59 + db $ca + db $4f + db $c9 + db $db + db $b2 + db $dd + db $7f + db $b6 + db $b9 + db $d7 + db $da + db $c0 + db $e7 + db $58 + +asm_3777a: + call sub_37f5f + jp Function37499 + +asm_37780: + ld hl, wca3b + ldh a, [hBattleTurn] + and a + jr z, asm_3778b + ld hl, wca40 + +asm_3778b: + set 2, [hl] + call sub_37f0f + ld hl, text_37796 + jp PrintText + +text_37796: + db $0 + db $5a + db $ca + db $4f + db $cf + db $d3 + db $d8 + db $c9 + db $7f + db $c0 + db $b2 + db $be + db $b2 + db $c6 + db $7f + db $ca + db $b2 + db $df + db $c0 + db $e7 + db $58 + +asm_377ab: + ld hl, wcade + ldh a, [hBattleTurn] + and a + jr z, asm_377b6 + ld hl, wcadd + +asm_377b6: + ld a, [wca3a] + and a + jr nz, asm_377e2 + bit 0, [hl] + jr nz, asm_377e2 + set 0, [hl] + call sub_37f0f + ld hl, text_377cb + jp PrintText + +text_377cb: + db $0 + db $59 + db $c9 + db $7f + db $b1 + db $bc + db $d3 + db $c4 + db $c6 + db $4f + db $cf + db $b7 + db $3b + db $bc + db $26 + db $7f + db $c1 + db $d7 + db $3a + db $df + db $c0 + db $e7 + db $58 + +asm_377e2: + call sub_37f5f + jp Function37499 + +asm_377e8: + ld hl, wca40 + ldh a, [hBattleTurn] + and a + jr z, asm_377f3 + ld hl, wca3b + +asm_377f3: + ld a, [wca3a] + and a + jr nz, asm_37822 + call sub_37e0d + jr nz, asm_37822 + bit 3, [hl] + jr nz, asm_37822 + set 3, [hl] + call sub_37f0f + ld hl, text_3780d + jp PrintText + +text_3780d: + db $0 + db $5a + db $ca + db $7f + db $59 + db $c9 + db $4f + db $bc + db $e2 + db $b3 + db $c0 + db $b2 + db $dd + db $7f + db $d0 + db $d4 + db $3c + db $df + db $c0 + db $e7 + db $58 + +asm_37822: + call sub_37f5f + jp Function37499 + +asm_37828: + ld hl, wca3b + ld de, wca40 + bit 4, [hl] + jr z, asm_37837 + ld a, [de] + bit 4, a + jr nz, asm_37857 + +asm_37837: + bit 4, [hl] + jr nz, asm_37842 + set 4, [hl] + ld a, 4 + ld [wca4a], a + +asm_37842: + ld a, [de] + jr nz, asm_3784d + set 4, a + ld [de], a + ld a, 4 + ld [wca52], a + +asm_3784d: + call sub_37f0f + ld hl, text_3785d + call PrintText + ret + +asm_37857: + call sub_37f5f + jp Function37499 + +text_3785d: + db $0 + db $b5 + db $c0 + db $26 + db $b2 + db $c9 + db $54 + db $ca + db $4f + db $f9 + db $8f + db $e3 + db $ab + db $2a + db $c6 + db $7f + db $ce + db $db + db $3b + db $c3 + db $bc + db $cf + db $b3 + db $e7 + db $58 + +asm_37876: + ld hl, wcade + ldh a, [hBattleTurn] + and a + jr z, asm_37881 + ld hl, wcadd + +asm_37881: + ld a, [wca3a] + and a + jr nz, asm_378a9 + bit 1, [hl] + jr nz, asm_378a9 + set 1, [hl] + call sub_37f0f + ld hl, text_37896 + jp PrintText + +text_37896: + db $0 + db $59 + db $ca + db $4f + db $bd + db $c5 + db $b1 + db $d7 + db $bc + db $c6 + db $7f + db $cf + db $b7 + db $ba + db $cf + db $da + db $c0 + db $e7 + db $58 + +asm_378a9: + call sub_37f5f + jp Function37499 + +asm_378af: + ld hl, wca3b + ldh a, [hBattleTurn] + and a + jr z, asm_378ba + ld hl, wca40 + +asm_378ba: + set 5, [hl] + call sub_37f0f + ld hl, text_378c5 + jp PrintText + +text_378c5: + db $0 + db $5a + db $ca + db $7f + db $ba + db $d7 + db $b4 + db $d9 + db $4f + db $c0 + db $b2 + db $be + db $b2 + db $c6 + db $7f + db $ca + db $b2 + db $df + db $c0 + db $e7 + db $58 + +asm_378da: + ld hl, wca3b + ld de, wca45 + ldh a, [hBattleTurn] + and a + jr z, asm_378eb + ld hl, wca40 + ld de, wca4d + +asm_378eb: + bit 6, [hl] + jr z, asm_378f4 + ld b, 4 + jp asm_37f6b + +asm_378f4: + xor a + ld [de], a + ret + +asm_378f7: + ld hl, wca45 + ld de, wca3b + ldh a, [hBattleTurn] + and a + jr z, asm_37908 + ld hl, wca4d + ld de, wca40 + +asm_37908: + ld a, [wca3a] + and a + jr z, asm_37913 + ld a, [de] + res 6, a + ld [de], a + ret + +asm_37913: + inc [hl] + ld a, [hl] + ld b, a + cp 5 + jr nz, asm_37920 + ld a, [de] + res 6, a + ld [de], a + jr asm_37924 + +asm_37920: + ld a, [de] + set 6, a + ld [de], a + +asm_37924: + dec b + jr z, asm_37935 + ld hl, wce2a + sla [hl] + dec hl + rl [hl] + jr nc, asm_37924 + ld a, $ff + ld [hli], a + ld [hl], a + +asm_37935: + ret + +asm_37936: + ld a, [wca3a] + and a + jr nz, asm_37965 + call sub_37f0f + ld hl, wc9e8 + ldh a, [hBattleTurn] + and a + jr z, asm_3794a + ld hl, wc9ef + +asm_3794a: + push af + xor 1 + ldh [hBattleTurn], a + ld a, [hli] + push af + ld a, [hl] + push af + push hl + ld a, $32 + ld [hld], a + xor a + ld [hl], a + call Function365bf + pop hl + pop af + ld [hld], a + pop af + ld [hl], a + pop af + ldh [hBattleTurn], a + ret + +asm_37965: + call sub_37f5f + call Function37499 + jp asm_357a9 + +asm_3796e: + ld hl, wca4b + ldh a, [hBattleTurn] + and a + jr z, asm_37979 + ld hl, wca53 + +asm_37979: + ld a, [wca3a] + and a + jr z, asm_37983 + call sub_37998 + ret + +asm_37983: + inc [hl] + ld a, [hl] + ld b, a + +asm_37986: + dec b + jr z, asm_37997 + ld hl, wce2a + sla [hl] + dec hl + rl [hl] + jr nc, asm_37986 + ld a, $ff + ld [hli], a + ld [hl], a + +asm_37997: + ret + +sub_37998: + push hl + ld hl, wca4b + ldh a, [hBattleTurn] + and a + jr z, asm_379a4 + ld hl, wca53 + +asm_379a4: + xor a + ld [hl], a + pop hl + ret + +asm_379a8: + ld a, [wca02] + ld [wCurSpecies], a + call GetMonHeader + xor a + ld [wMonType], a + callab Function5069e + push af + ld a, [wcdd9] + ld [wCurSpecies], a + call GetMonHeader + ld a, 3 + ld [wMonType], a + callab Function5069e + push af + pop bc + ld a, c + pop bc + xor c + bit 4, a + jr z, asm_37a0b + ld hl, wca40 + ldh a, [hBattleTurn] + and a + jr z, asm_379e8 + ld hl, wca3b + +asm_379e8: + call sub_37e0d + jr nz, asm_37a0b + bit 7, [hl] + jr nz, asm_37a0b + set 7, [hl] + call sub_37f0f + ld hl, text_379fc + jp PrintText + +text_379fc: + db $0 + db $59 + db $ca + db $4f + db $a0 + db $a8 + db $a0 + db $a8 + db $c6 + db $7f + db $c5 + db $df + db $c0 + db $e7 + db $58 + +asm_37a0b: + call sub_37f5f + jp Function37499 + +asm_37a11: + push bc + ld hl, wca0e + ldh a, [hBattleTurn] + and a + jr z, asm_37a1d + ld hl, wcde5 + +asm_37a1d: + xor a + ldh [hQuotient], a + ldh [hQuotient + 1], a + ld a, [hl] + ldh [hQuotient + 2], a + ld a, $a + ldh [hPrintNumDivisor], a + call Multiply + ld a, $19 + ldh [hPrintNumDivisor], a + ld b, 4 + call Divide + ldh a, [hQuotient + 2] + ld d, a + pop bc + ret + +asm_37a3a: + ld a, [wca3a] + and a + ret nz + push bc + call BattleRandom + ld b, a + ld hl, Data37a85 + ld c, 0 + +asm_37a49: + ld a, [hli] + cp $ff + jr z, asm_37a5f + cp b + jr nc, asm_37a55 + inc c + inc hl + jr asm_37a49 + +asm_37a55: + xor a + ld [wca5c], a + call sub_37f0f + ld d, [hl] + pop bc + ret + +asm_37a5f: + pop bc + ld a, 1 + ld [wca5c], a + call sub_37f0f + ldh a, [hBattleTurn] + push af + xor 1 + ldh [hBattleTurn], a + callab sub_3c7b0 + pop af + ldh [hBattleTurn], a + callab sub_3c808 + jp asm_357a9 + +Data37a85: + db $66 + db $28 + db $b3 + db $50 + db $cc + db $78 + db $ff + +asm_37a8c: + push bc + ld hl, wca0e + ldh a, [hBattleTurn] + and a + jr z, asm_37a98 + ld hl, wcde5 + +asm_37a98: + ld a, [hl] + cp $46 + ld d, $1e + jr nc, asm_37aa4 + ld b, a + ld a, $64 + sub b + ld d, a + +asm_37aa4: + pop bc + ret + +asm_37aa6: + ld hl, wcadd + ld de, wcadf + ldh a, [hBattleTurn] + and a + jr z, asm_37ab7 + ld hl, wcade + ld de, wcae0 + +asm_37ab7: + ld a, [wca3a] + and a + jr nz, asm_37ae3 + bit 2, [hl] + jr nz, asm_37ae3 + set 2, [hl] + ld a, 5 + ld [de], a + call sub_37f0f + ld hl, text_37acf + jp PrintText + +text_37acf: + db $0 + db $5a + db $ca + db $4f + db $bc + db $de + db $45 + db $c9 + db $3d + db $e3 + db $a6 + db $c6 + db $7f + db $c2 + db $c2 + db $cf + db $da + db $c0 + db $e7 + db $58 + +asm_37ae3: + call sub_37f5f + jp Function37499 + +sub_37ae9: + ld hl, wcade + ldh a, [hBattleTurn] + and a + jr z, asm_37af4 + ld hl, wcadd + +asm_37af4: + bit 2, [hl] + ret + +asm_37af7: + ld hl, wcade + ldh a, [hBattleTurn] + and a + jr z, asm_37b02 + ld hl, wcadd + +asm_37b02: + bit 2, [hl] + ret z + ld a, 1 + ld [wca3a], a + call sub_37f5f + ld hl, text_37b13 + jp PrintText + +text_37b13: + db $0 + db $59 + db $ca + db $4f + db $bc + db $de + db $45 + db $c9 + db $3d + db $e3 + db $a6 + db $c6 + db $7f + db $cf + db $d3 + db $d7 + db $da + db $c3 + db $b2 + db $d9 + db $e7 + db $58 + +asm_37b29: + push bc + call BattleRandom + ld b, a + ld hl, Data37b5d + +asm_37b31: + ld a, [hli] + cp b + jr nc, asm_37b39 + inc hl + inc hl + jr asm_37b31 + +asm_37b39: + ld d, [hl] + push de + inc hl + ld a, [hl] + ld [wCountSetBitsResult], a + call sub_37f5f + ld hl, text_37b4c + call PrintText + pop de + pop bc + ret + +text_37b4c: + db $0 + db $9d + db $7 + db $95 + db $90 + db $ae + db $e3 + db $13 + db $50 + db $9 + db $37 + db $ce + db $11 + db $0 + db $e7 + db $e7 + db $58 + +Data37b5d: + db $d + db $a + db $4 + db $26 + db $1e + db $5 + db $59 + db $32 + db $6 + db $a6 + db $46 + db $7 + db $d9 + db $5a + db $8 + db $f2 + db $6e + db $9 + db $ff + db $96 + db $a + +asm_37b72: + ldh a, [hBattleTurn] + and a + jp nz, asm_37c02 + ld de, wPartySpecies + ld hl, wPartyMon1HP + ld bc, 0 + +asm_37b81: + ld a, [de] + inc de + cp $ff + jr z, asm_37b9c + ld a, [wcd41] + cp c + jr z, asm_37b93 + ld a, [hli] + or b + ld b, a + ld a, [hld] + or b + ld b, a + +asm_37b93: + push bc + ld bc, $30 + add hl, bc + pop bc + inc c + jr asm_37b81 + +asm_37b9c: + ld a, b + and a + jp z, asm_37c63 + call sub_37f0f + call LoadStandardMenuHeader + ld a, 2 + ld [wcdb9], a + ld a, $36 + call Predef + +asm_37bb1: + jr c, asm_37bc2 + ld hl, wcd41 + ld a, [wWhichPokemon] + cp [hl] + jr nz, asm_37bc9 + ld hl, text_37c69 + call PrintText + +asm_37bc2: + ld a, $37 + call Predef + jr asm_37bb1 + +asm_37bc9: + callab HasMonFainted + jr z, asm_37bc2 + call ClearPalettes + callab Function3e3a7 + call CloseWindow + call ClearSprites + ld hl, wTileMap + 1 + ld bc, $040a + call ClearBox + ld b, 1 + call GetSGBLayout + call SetPalettes + call sub_37c4c + callab asm_3da1c + jr asm_37c4b + +asm_37c02: + ld a, [wBattleMode] + dec a + jr z, asm_37c63 + ld de, wd913 + 1 + ld hl, wd93d + ld bc, 0 + +asm_37c11: + ld a, [de] + inc de + cp $ff + jr z, asm_37c2c + ld a, [wca36] + cp c + jr z, asm_37c23 + ld a, [hli] + or b + ld b, a + ld a, [hld] + or b + ld b, a + +asm_37c23: + push bc + ld bc, $30 + add hl, bc + pop bc + inc c + jr asm_37c11 + +asm_37c2c: + ld a, b + and a + jr z, asm_37c63 + call sub_37f0f + call sub_37c4c + callab sub_3cd6e + ld a, 1 + ld [wCountSetBitsResult], a + callab sub_3e2c6 + +asm_37c4b: + ret + +sub_37c4c: + ld a, [wLinkMode] + and a + ret z + ld a, 1 + ld [wFieldMoveSucceeded], a + callab sub_3df8b + xor a + ld [wFieldMoveSucceeded], a + ret + +asm_37c63: + call sub_37f5f + jp Function37499 + +text_37c69: + db $1 + dw wEnemyMonNickname + db $0 + db $ca + db $d3 + db $b3 + db $33 + db $c3 + db $b2 + db $cf + db $bd + db $58 + +asm_37c76: + ret + +asm_37c77: + ld hl, wEnemySubStatus3 + ldh a, [hBattleTurn] + and a + jr z, asm_37c82 + ld hl, wPlayerSubStatus3 + +asm_37c82: + bit 5, [hl] + ret z + res 5, [hl] + ld hl, text_37c8e + call PrintText + ret + +text_37c8e: + db $0 + db $5a + db $ca + db $7f + db $59 + db $c9 + db $4f + db $ba + db $b3 + db $29 + db $b7 + db $b6 + db $d7 + db $7f + db $b6 + db $b2 + db $ce + db $b3 + db $bb + db $da + db $c0 + db $e7 + db $58 + +asm_37ca5: + ld de, $0303 + jr asm_37cb2 + +asm_37caa: + ld de, 0 + jr asm_37cb2 + +asm_37caf: + ld de, $0102 + +asm_37cb2: + push de + callab Function3c7f2 + pop de + ld a, [wTimeOfDay] + cp d + jr z, asm_37cd0 + ld a, [wTimeOfDay] + cp e + jr z, asm_37cd0 + callab Function3c7d3 + +asm_37cd0: + call BattleRandom + set 7, a + ldh [hPrintNumDivisor], a + xor a + ldh [hQuotient], a + ld a, b + ldh [hQuotient + 1], a + ld a, c + ldh [hQuotient + 2], a + call Multiply + ld a, $ff + ldh [hPrintNumDivisor], a + ld b, 4 + call Divide + ldh a, [hQuotient + 1] + ld b, a + ldh a, [hQuotient + 2] + ld c, a + call sub_37f0f + ldh a, [hBattleTurn] + push af + xor 1 + ldh [hBattleTurn], a + callab sub_3c808 + pop af + ldh [hBattleTurn], a + ld hl, text_37d0e + call PrintText + ret + +text_37d0e: + db $0 + db $5a + db $ca + db $7f + db $c0 + db $b2 + db $d8 + db $e2 + db $b8 + db $dd + db $4f + db $b6 + db $b2 + db $cc + db $b8 + db $bc + db $c0 + db $e7 + db $58 + +asm_37d21: + ld a, [wca3a] + and a + ret nz + push bc + ld hl, wca08 + ld bc, wc9f2 + ldh a, [hBattleTurn] + and a + jr z, asm_37d38 + ld hl, wcddf + ld bc, wc9eb + +asm_37d38: + push bc + ld a, [hl] + swap a + and 8 + ld b, a + ld a, [hli] + and 8 + srl a + or b + ld b, a + ld a, [hl] + swap a + and 8 + srl a + srl a + or b + ld b, a + ld a, [hl] + and 8 + srl a + srl a + srl a + or b + ld b, a + add a + add a + add b + ld b, a + ld a, [hld] + and 3 + add b + ld d, a + ld a, [hl] + and 3 + ld b, a + ld a, [hl] + and $30 + swap a + sla a + sla a + or b + inc a + cp 6 + jr c, asm_37d7f + inc a + cp $a + jr c, asm_37d7f + add $a + +asm_37d7f: + pop bc + ld [bc], a + pop bc + ret + +asm_37d83: + ld a, [wca3a] + and a + jr nz, asm_37da8 + ld a, 1 + ld [wcae2], a + ld a, 5 + ld [wcae3], a + call sub_37f0f + ld hl, text_37d9c + jp PrintText + +text_37d9c: + db $0 + db $b5 + db $b5 + db $b1 + db $d2 + db $c6 + db $7f + db $c5 + db $df + db $c0 + db $e7 + db $58 + +asm_37da8: + call sub_37f5f + jp Function37499 + +asm_37dae: + ld a, [wca3a] + and a + jr nz, asm_37dd5 + ld a, 2 + ld [wcae2], a + ld a, 5 + ld [wcae3], a + call sub_37f0f + ld hl, text_37dc7 + jp PrintText + +text_37dc7: + db $0 + db $cb + db $2b + db $bc + db $26 + db $7f + db $c2 + db $d6 + db $b8 + db $c5 + db $df + db $c0 + db $e7 + db $58 + +asm_37dd5: + call sub_37f5f + jp Function37499 + +sub_37ddb: + ldh a, [hBattleTurn] + and a + ld hl, wca0a + ld de, wPartyMon1PP + ld a, [wcd40] + jr z, asm_37df2 + ld hl, wcde1 + ld de, wd932 + ld a, [wcac7] + +asm_37df2: + ld b, 0 + ld c, a + add hl, bc + inc [hl] + ld h, d + ld l, e + add hl, bc + ldh a, [hBattleTurn] + and a + ld a, [wcd41] + jr z, asm_37e05 + ld a, [wcde7] + +asm_37e05: + ld bc, $30 + call AddNTimes + inc [hl] + ret + +sub_37e0d: + push hl + ld hl, wEnemySubStatus3 + ldh a, [hBattleTurn] + and a + jr z, asm_37e19 + ld hl, wPlayerSubStatus3 + +asm_37e19: + bit 6, [hl] + pop hl + ret + +Function37e1d: + ld hl, wca03 + ldh a, [hBattleTurn] + and a + jp z, asm_37e29 + ld hl, wcdda + +asm_37e29: + ld b, [hl] + jp Function37e3d + +Function37e2d: + ld hl, wcdda + ldh a, [hBattleTurn] + and a + jp z, asm_37e39 + ld hl, wca03 + +asm_37e39: + ld b, [hl] + jp Function37e3d + +Function37e3d: + ld a, b + and a + ret z + push hl + push bc + ld hl, ItemAttributes + 3 + dec a + ld c, a + ld b, 0 + add hl, bc + add hl, bc + add hl, bc + add hl, bc + add hl, bc + add hl, bc + add hl, bc + ld a, 1 + call GetFarByte + pop bc + ld c, a + dec hl + ld a, 1 + call GetFarByte + ld b, a + pop hl + ret + +Function37e60: + push hl + push de + push bc + ldh a, [hBattleTurn] + and a + ld hl, wd91c + ld de, wcdda + ld a, [wca36] + jr z, asm_37e7a + ld hl, wPartyMon1Item + ld de, wca03 + ld a, [wcd41] + +asm_37e7a: + push hl + push af + ld a, [de] + ld b, a + call Function37e3d + ld hl, Data37eac + +asm_37e84: + ld a, [hli] + cp b + jr z, asm_37e91 + inc a + jr nz, asm_37e84 + pop af + pop hl + pop bc + pop de + pop hl + ret + +asm_37e91: + xor a + ld [de], a + pop af + pop hl + ld bc, $30 + call AddNTimes + ldh a, [hBattleTurn] + and a + jr nz, asm_37ea6 + ld a, [wBattleMode] + dec a + jr z, asm_37ea8 + +asm_37ea6: + ld [hl], 0 + +asm_37ea8: + pop bc + pop de + pop hl + ret + +Data37eac: + db $1 + db $2 + db $5 + db $a + db $b + db $c + db $d + db $e + db $f + db $1e + db $1f + db $20 + db $21 + db $22 + db $23 + db $24 + db $25 + db $26 + db $47 + db $48 + db $49 + db $ff + +sub_37ec2: + push hl + push de + push bc + ld [wCountSetBitsResult], a + call GetItemName + ld hl, text_37ed5 + call PrintText + pop bc + pop de + pop hl + ret + +text_37ed5: + db $0 + db $bf + db $b3 + db $3b + db $bc + db $c3 + db $b2 + db $c0 + db $4f + db $50 + db $1 + dw wStringBuffer1 + db $0 + db $26 + db $7f + db $bb + db $34 + db $b3 + db $bc + db $c0 + db $e7 + db $58 + +sub_37eec: + xor a + ld [wccc1], a + ldh a, [hBattleTurn] + and a + ld a, [wc9ef] + jr z, asm_37efb + ld a, [wc9e8] + +asm_37efb: + and a + ret z + ld [wccc0], a + ldh a, [hBattleTurn] + and a + ld a, 6 + jr z, asm_37f09 + ld a, 3 + +asm_37f09: + ld [wcccd], a + jp asm_37f26 + +sub_37f0f: + xor a + ld [wcccd], a + ld [wccc1], a + ldh a, [hBattleTurn] + and a + ld a, [wc9ef] + jr z, asm_37f21 + ld a, [wc9e8] + +asm_37f21: + and a + ret z + +sub_37f23: + ld [wccc0], a + +asm_37f26: + push hl + push de + push bc + callab PlayBattleAnim + pop bc + pop de + pop hl + ret + +sub_37f35: + ld a, e + ld [wccc0], a + ld a, d + ld [wccc1], a + xor a + ld [wcccd], a + push hl + push de + push bc + ldh a, [hBattleTurn] + push af + xor 1 + ldh [hBattleTurn], a + callab PlayBattleAnim + pop af + ldh [hBattleTurn], a + pop bc + pop de + pop hl + ret + +CallFromBank0F: + ld a, $f + jp FarCall_hl + +sub_37f5f: + ld c, 50 + jp DelayFrames + +asm_37f64: + ld hl, .EmptyString + jp PrintText + +.EmptyString: + db "@" + +asm_37f6b: + ld a, [wca7c] + ld h, a + ld a, [wca7b] + ld l, a + +asm_37f73: + ld a, [hli] + cp b + jr nz, asm_37f73 + ld a, h + ld [wca7c], a + ld a, l + ld [wca7b], a + ret + diff --git a/engine/dumps/bank0f.asm b/engine/dumps/bank0f.asm new file mode 100644 index 00000000..fda1d315 --- /dev/null +++ b/engine/dumps/bank0f.asm @@ -0,0 +1,6583 @@ +INCLUDE "constants.asm" + +SECTION "engine/dumps/bank0f.asm@StartBattle", ROMX +StartBattle: + xor a + ld [wca37], a + ld [wcada], a + ld [wFieldMoveSucceeded], a + inc a + ld [wce36], a + ld hl, wd93d + ld bc, $2f + ld d, 3 +.find_first_enemy_alive_loop + inc d + ld a, [hli] + or [hl] + jr nz, .found_first_enemy_alive + add hl, bc + jr .find_first_enemy_alive_loop +.found_first_enemy_alive + ld a, d + ld [wOtherPlayerLinkAction], a + ld a, [wLinkMode] + and a + jr z, .asm_3c02e + ldh a, [hLinkPlayerNumber] + cp 2 + jr z, .asm_3c03f +.asm_3c02e + ld a, [wBattleMode] + dec a + jr z, .asm_3c03a + call sub_3cd6e + call sub_3d071 +.asm_3c03a + ld c, 40 + call DelayFrames +.asm_3c03f + call BackUpTilesToBuffer +.check_any_alive + call AnyPartyAlive + ld a, d + and a + jp z, asm_3cc56 + call ReloadTilesFromBuffer + ld a, [wBattleType] + and a + jp nz, .asm_3c0d2 + xor a + ld [wWhichPokemon], a +.find_first_alive_loop + call HasMonFainted + jr nz, .found_first_alive + ld hl, wWhichPokemon + inc [hl] + jr .find_first_alive_loop +.found_first_alive + ld a, [wWhichPokemon] + ld [wcd41], a + inc a + ld hl, wPartyCount + ld c, a + ld b, 0 + add hl, bc + ld a, [hl] + ld [wMonDexIndex], a + ld [wcdd8], a + ld hl, $c305 + ld a, 9 + call sub_3cd3b + call BackUpTilesToBuffer + ld a, [wWhichPokemon] + ld c, a + ld b, 1 + push bc + ld hl, wca37 + predef SmallFarFlagAction + ld hl, wcada + pop bc + predef SmallFarFlagAction + call LoadBattleMonFromParty + call ApplyStatMods + call PrintSendOutMonMessage + call sub_3d387 + call Function3d32e + call PrintEmptyString + call BackUpTilesToBuffer + xor a + ldh [hBattleTurn], a + call Function3d3a2 + ld a, [wLinkMode] + and a + jr z, .to_battle + ldh a, [hLinkPlayerNumber] + cp 2 + jr nz, .to_battle + call sub_3cd6e + call sub_3d071 + ld a, 1 + ldh [hBattleTurn], a + call Function3d3a2 +.to_battle + jp asm_3c183 + +.asm_3c0d2 + call DisplayBattleMenu + ret c + ld a, [wFieldMoveSucceeded] + and a + jr z, .asm_3c0d2 + call ReloadTilesFromBuffer + ld hl, SafariZonePAText + jp PrintText + + call sub_3e81b + ld a, [wcdf2] + add a + ld b, a + jp c, asm_3c132 + ld a, [wcace] + and a + jr z, .asm_3c0fa + srl b + srl b +.asm_3c0fa + ld a, [wcacd] + and a + jr z, .asm_3c106 + sla b + jr nc, .asm_3c106 + ld b, $ff +.asm_3c106 + call BattleRandom + cp b + jp nc, .check_any_alive + jr asm_3c132 + +SafariZonePAText: + text "アナウンス『ピンポーン!" + + para "サファり ボールを" + line "ぜんぶ なげました!" + prompt + + +asm_3c132: + call ReloadTilesFromBuffer + ld a, 2 + ld [wcd5d], a + ld a, [wLinkMode] + and a + ld hl, WildPokemonFledText + jr z, asm_3c14a + xor a + ld [wcd5d], a + ld hl, EnemyPokemonFledText + +asm_3c14a: + call PrintText + ld de, $26 + call PlaySFX + xor a + ldh [hBattleTurn], a + jpab Functioncc000 + +WildPokemonFledText: + text "やせいの@" + text_from_ram wBattleMonNickname + text "は にげだした!" + prompt + +EnemyPokemonFledText: + text "てきの@" + text_from_ram wBattleMonNickname + text "は にげだした!" + prompt + +asm_3c183: + call sub_3d3f4 + ldh a, [hLinkPlayerNumber] + cp 1 + jr z, asm_3c1a9 + call sub_3c492 + jp z, asm_3caf3 + call sub_3c48d + jp z, asm_3c883 + call sub_3c61e + call sub_3c492 + jp z, asm_3caf3 + call sub_3c48d + jp z, asm_3c883 + jr asm_3c1c4 + +asm_3c1a9: + call sub_3c48d + jp z, asm_3c883 + call sub_3c492 + jp z, asm_3caf3 + call sub_3c61e + call sub_3c48d + jp z, asm_3c883 + call sub_3c492 + jp z, asm_3caf3 + +asm_3c1c4: + call sub_3c6b8 + call sub_3c704 + call sub_3d50b + call sub_3d40b + call sub_3d3f4 + call BackUpTilesToBuffer + call sub_3c399 + jp c, asm_3c132 + xor a + ld [wce36], a + ld a, [wca3e] + and $60 + jp nz, asm_3c281 + ld hl, wEnemySubStatus3 + res 3, [hl] + ld hl, wPlayerSubStatus3 + res 3, [hl] + ld a, [hl] + and $12 + jp nz, asm_3c281 + ld hl, wca3b + bit 6, [hl] + jp nz, asm_3c281 + +asm_3c200: + call DisplayBattleMenu + ret c + ld a, [wce06] + and a + ret nz + ld hl, wca3f + bit 4, [hl] + jr z, asm_3c246 + ld a, [wca49] + dec a + ld [wca49], a + jr nz, asm_3c229 + +asm_3c219: + ld hl, wca3f + res 4, [hl] + xor a + ldh [hBattleTurn], a + ld hl, Data3dfdd + call PrintText + jr asm_3c246 + +asm_3c229: + ld a, [wcad6] + and a + jr z, asm_3c219 + ld a, [wcd40] + ld c, a + ld b, 0 + ld hl, wca0a + add hl, bc + ld a, [hl] + and $3f + jr z, asm_3c219 + ld a, [wcad6] + ld [wcac1], a + jr asm_3c269 + +asm_3c246: + ld a, [wPlayerSubStatus3] + and $21 + jr nz, asm_3c281 + ld a, [wFieldMoveSucceeded] + and a + jr nz, asm_3c281 + xor a + ld [wcac0], a + inc a + ld [wccc0], a + call Function3daa7 + push af + call ReloadTilesFromBuffer + call DrawHUDsAndHPBars + pop af + jp nz, asm_3c200 + +asm_3c269: + xor a + ldh [hBattleTurn], a + callab Function360b1 + ld a, [wc9f0] + cp $77 + jr z, asm_3c285 + xor a + ld [wca4b], a + jr asm_3c285 + +asm_3c281: + xor a + ld [wca4b], a + +asm_3c285: + call sub_3de6e + ld a, [wLinkMode] + and a + jr z, asm_3c2cd + ld a, [wOtherPlayerLinkAction] + cp $f + jp z, asm_3c132 + cp $e + jr z, asm_3c2cd + cp $d + jr z, asm_3c2cd + sub 4 + jr c, asm_3c2cd + ld a, [wPlayerSubStatus3] + bit 5, a + jr z, asm_3c2bb + ld a, [wcd40] + ld hl, wca04 + ld c, a + ld b, 0 + add hl, bc + ld a, [hl] + cp $76 + jr nz, asm_3c2bb + ld [wcac1], a + +asm_3c2bb: + callab Function38220 + ld a, 1 + ldh [hBattleTurn], a + call Function3d3a2 + jp asm_3c3c7 + +asm_3c2cd: + ld a, [wcac1] + call sub_3c3b8 + cp $67 + jr nz, asm_3c2e4 + ld a, [wcac2] + call sub_3c3b8 + cp $67 + jr z, asm_3c311 + jp asm_3c41d + +asm_3c2e4: + ld a, [wcac2] + call sub_3c3b8 + cp $67 + jp z, asm_3c3c7 + ld a, [wcac1] + call sub_3c3b8 + cp $59 + jr nz, asm_3c306 + ld a, [wcac2] + call sub_3c3b8 + cp $59 + jr z, asm_3c311 + jp asm_3c3c7 + +asm_3c306: + ld a, [wcac2] + call sub_3c3b8 + cp $59 + jp z, asm_3c41d + +asm_3c311: + xor a + ldh [hBattleTurn], a + callab Function37e1d + push bc + callab Function37e2d + pop de + ld a, d + cp $4a + jr nz, asm_3c339 + ld a, b + cp $4a + jr z, asm_3c347 + call BattleRandom + cp e + jr nc, asm_3c36d + jp asm_3c41d + +asm_3c339: + ld a, b + cp $4a + jr nz, asm_3c36d + call BattleRandom + cp c + jr nc, asm_3c36d + jp asm_3c3c7 + +asm_3c347: + ldh a, [hLinkPlayerNumber] + cp 2 + jr z, asm_3c35d + call BattleRandom + cp c + jp c, asm_3c3c7 + call BattleRandom + cp e + jp c, asm_3c41d + jr asm_3c36d + +asm_3c35d: + call BattleRandom + cp e + jp c, asm_3c41d + call BattleRandom + cp c + jp c, asm_3c3c7 + jr asm_3c36d + +asm_3c36d: + ld de, wca1a + ld hl, wcdf1 + ld c, 2 + call memcmp + jr z, asm_3c37f + jp nc, asm_3c41d + jr asm_3c3c7 + +asm_3c37f: + ldh a, [hLinkPlayerNumber] + cp 2 + jr z, asm_3c38f + call BattleRandom + cp $80 + jp c, asm_3c41d + jr asm_3c3c7 + +asm_3c38f: + call BattleRandom + cp $80 + jr c, asm_3c3c7 + jp asm_3c41d + +sub_3c399: + ld a, [wBattleMode] + dec a + jr nz, asm_3c3b6 + ld a, [wDebugFlags] + bit 0, a + jr nz, asm_3c3b6 + ld a, [wca44] + bit 7, a + jr nz, asm_3c3b6 + call BattleRandom + cp $a + jr nc, asm_3c3b6 + scf + ret + +asm_3c3b6: + and a + ret + +sub_3c3b8: + dec a + ld hl, Moves + 1 + ld bc, 7 + call AddNTimes + ld a, BANK(Moves) + jp GetFarByte + +asm_3c3c7: + ld a, 1 + ldh [hBattleTurn], a + callab Function38000 + jr c, asm_3c3eb + callab Function3401c + call sub_3c473 + ld a, [wce06] + and a + ret nz + call sub_3c492 + jp z, asm_3caf3 + +asm_3c3eb: + call sub_3c498 + jp z, asm_3c883 + call DrawHUDsAndHPBars + callab Function34000 + call sub_3c473 + ld a, [wce06] + and a + ret nz + call sub_3c48d + jp z, asm_3c883 + call sub_3c498 + jp z, asm_3caf3 + call DrawHUDsAndHPBars + call sub_3c86d + xor a + ld [wFieldMoveSucceeded], a + jp asm_3c183 + +asm_3c41d: + callab Function34000 + call sub_3c473 + ld a, [wce06] + and a + ret nz + call sub_3c48d + jp z, asm_3c883 + call sub_3c498 + jp z, asm_3caf3 + call DrawHUDsAndHPBars + ld a, 1 + ldh [hBattleTurn], a + callab Function38000 + jr c, asm_3c460 + callab Function3401c + call sub_3c473 + ld a, [wce06] + and a + ret nz + call sub_3c492 + jp z, asm_3caf3 + +asm_3c460: + call sub_3c498 + jp z, asm_3c883 + call DrawHUDsAndHPBars + call sub_3c86d + xor a + ld [wFieldMoveSucceeded], a + jp asm_3c183 + +sub_3c473: + ld hl, wca44 + ld de, wca40 + ldh a, [hBattleTurn] + and a + jr z, asm_3c484 + ld hl, wca3f + ld de, wca3b + +asm_3c484: + res 6, [hl] + ld a, [de] + res 2, a + res 5, a + ld [de], a + ret + +sub_3c48d: + ld hl, wcde9 + jr asm_3c495 + +sub_3c492: + ld hl, wca12 + +asm_3c495: + ld a, [hli] + or [hl] + ret + +sub_3c498: + ld hl, wca10 + ldh a, [hBattleTurn] + and a + jr z, asm_3c4a3 + ld hl, wcde7 + +asm_3c4a3: + ld a, [hl] + and $18 + jr z, asm_3c4eb + ld hl, HurtByPoisonText + ld de, $0106 + and $10 + jr z, asm_3c4b8 + ld hl, HurtByBurnText + ld de, $0105 + +asm_3c4b8: + push de + call PrintText + pop de + xor a + ld [wcccd], a + call PlayMoveAnimation + call sub_3c78b + ld hl, wca3f + ld de, wca47 + ldh a, [hBattleTurn] + and a + jr z, asm_3c4d8 + ld hl, wca44 + ld de, wca4f + +asm_3c4d8: + bit 0, [hl] + jr z, asm_3c4e8 + ld a, [de] + inc a + ld [de], a + ld hl, 0 + +asm_3c4e2: + add hl, bc + dec a + jr nz, asm_3c4e2 + ld b, h + ld c, l + +asm_3c4e8: + call sub_3c75e + +asm_3c4eb: + ld hl, wca3e + ldh a, [hBattleTurn] + and a + jr z, asm_3c4f6 + ld hl, wca43 + +asm_3c4f6: + bit 7, [hl] + jr z, asm_3c51d + ldh a, [hBattleTurn] + push af + xor 1 + ldh [hBattleTurn], a + xor a + ld [wcccd], a + ld de, $0107 + call PlayMoveAnimation + pop af + ldh [hBattleTurn], a + call sub_3c78b + call sub_3c75e + call sub_3c808 + ld hl, LeechSeedSapsText + call PrintText + +asm_3c51d: + ld hl, wca3b + ldh a, [hBattleTurn] + and a + jr z, asm_3c528 + ld hl, wca40 + +asm_3c528: + bit 0, [hl] + jr z, asm_3c542 + xor a + ld [wcccd], a + ld de, $010c + call PlayMoveAnimation + call sub_3c7b0 + call sub_3c75e + ld hl, HasANightmareText + call PrintText + +asm_3c542: + ld hl, wca3b + ldh a, [hBattleTurn] + and a + jr z, asm_3c54d + ld hl, wca40 + +asm_3c54d: + bit 1, [hl] + jr z, asm_3c567 + xor a + ld [wcccd], a + ld de, $010c + call PlayMoveAnimation + call sub_3c7b0 + call sub_3c75e + ld hl, HurtByCurseText + call PrintText + +asm_3c567: + ld hl, wcadd + ldh a, [hBattleTurn] + and a + jr z, asm_3c572 + ld hl, wcade + +asm_3c572: + bit 1, [hl] + jr z, asm_3c596 + ldh a, [hBattleTurn] + push af + xor 1 + ldh [hBattleTurn], a + xor a + ld [wcccd], a + ld de, $010b + call PlayMoveAnimation + pop af + ldh [hBattleTurn], a + call sub_3c78b + call sub_3c75e + ld hl, SandstormHitsText + call PrintText + +asm_3c596: + ld hl, wca12 + ldh a, [hBattleTurn] + and a + jr z, asm_3c5a1 + ld hl, wcde9 + +asm_3c5a1: + ld a, [hli] + or [hl] + ret nz + call DrawHUDsAndHPBars + ld c, 20 + call DelayFrames + xor a + ret + +HurtByPoisonText: + text "は" + line "どくの ダメージを うけている!" + prompt + +HurtByBurnText: + text "は" + line "やけどの ダメージを うけている!" + prompt + +LeechSeedSapsText: + text "やどりぎが の" + line "たいりょくを うばう!" + prompt + +HasANightmareText: + text "は" + line "あくむに うなされている!" + prompt + +HurtByCurseText: + text "は" + line "のろわれている!" + prompt + +SandstormHitsText: + text "すなあらしが を" + line "おそう!" + prompt + +sub_3c61e: + ldh a, [hLinkPlayerNumber] + cp 1 + jr z, asm_3c632 + xor a + ldh [hBattleTurn], a + call sub_3c640 + ld a, 1 + ldh [hBattleTurn], a + call sub_3c640 + ret + +asm_3c632: + ld a, 1 + ldh [hBattleTurn], a + call sub_3c640 + xor a + ldh [hBattleTurn], a + call sub_3c640 + ret + +sub_3c640: + ld hl, wca3b + ld de, wca4a + ldh a, [hBattleTurn] + and a + jr z, asm_3c651 + ld hl, wca40 + ld de, wca52 + +asm_3c651: + bit 4, [hl] + ret z + ld a, [de] + dec a + ld [de], a + ld [wCountSetBitsResult], a + push af + push hl + ld hl, PerishCountText + call PrintText + pop hl + pop af + ret nz + res 4, [hl] + ldh a, [hBattleTurn] + and a + jr nz, asm_3c682 + ld hl, wca12 + xor a + ld [hli], a + ld [hl], a + ld hl, wPartyMon1HP + ld a, [wcd41] + ld bc, $30 + call AddNTimes + xor a + ld [hli], a + ld [hl], a + ret + +asm_3c682: + ld hl, wcde9 + xor a + ld [hli], a + ld [hl], a + ld a, [wBattleMode] + dec a + ret z + ld hl, wd93d + ld a, [wca36] + ld bc, $30 + call AddNTimes + xor a + ld [hli], a + ld [hl], a + ret + +PerishCountText: + text "の ほろびの" + line "カウントが @" + deciram wCountSetBitsResult, 1, 1 + text "になった!" + prompt + +sub_3c6b8: + ld a, [wcadd] + bit 2, a + jr z, asm_3c6ce + ld hl, wcadf + dec [hl] + jr nz, asm_3c6ce + res 2, a + ld [wcadd], a + xor a + call sub_3c6e0 + +asm_3c6ce: + ld a, [wcade] + bit 2, a + ret z + ld hl, wcae0 + dec [hl] + ret nz + res 2, a + ld [wcade], a + ld a, 1 + +sub_3c6e0: + ldh [hBattleTurn], a + ld hl, EndPsychicVeilText + jp PrintText + +EndPsychicVeilText: + text "を つつんでいた" + line "しんぴの べールが なくなった!" + prompt + +sub_3c704: + ld a, [wcae2] + and a + ret z + dec a + ld c, a + ld hl, wcae3 + dec [hl] + ld hl, TextPointers3c726 + jr nz, asm_3c71b + xor a + ld [wcae2], a + ld hl, TextPointers3c72a + +asm_3c71b: + ld b, 0 + add hl, bc + add hl, bc + ld a, [hli] + ld h, [hl] + ld l, a + call PrintText + ret + +TextPointers3c726: + dw RainingText + dw SunlightIsStrongText + +TextPointers3c72a: + dw RainStoppedText + dw SunlightFadedText + +RainingText: + text "あめが ふりつずいている" + prompt + +SunlightIsStrongText: + text "ひざしが つよい" + prompt + +RainStoppedText: + text "あめが やんだ!" + prompt + +SunlightFadedText: + text "ひざしが よわくなった!" + prompt + +sub_3c75e: + ld hl, wca12 + ldh a, [hBattleTurn] + and a + jr z, asm_3c769 + ld hl, wcde9 + +asm_3c769: + inc hl + ld a, [hl] + ld [wHPBarOldHP], a + sub c + ld [hld], a + ld [wHPBarNewHP], a + ld a, [hl] + ld [wReplacementBlock], a + sbc b + ld [hl], a + ld [wcdc8], a + jr nc, asm_3c787 + xor a + ld [hli], a + ld [hl], a + ld [wHPBarNewHP], a + ld [wcdc8], a + +asm_3c787: + call sub_3c854 + ret + +sub_3c78b: + ld hl, wca14 + ldh a, [hBattleTurn] + and a + jr z, asm_3c796 + ld hl, wcdeb + +asm_3c796: + ld a, [hli] + ld [wMapBlocksAddress], a + ld b, a + ld a, [hl] + ld [wHPBarMaxHP], a + ld c, a + srl b + rr c + srl b + rr c + srl c + ld a, c + and a + jr nz, asm_3c7af + inc c + +asm_3c7af: + ret + +sub_3c7b0: + ld hl, wca14 + ldh a, [hBattleTurn] + and a + jr z, .asm_3c7bb + ld hl, wcdeb +.asm_3c7bb + ld a, [hli] + ld [wMapBlocksAddress], a + ld b, a + ld a, [hl] + ld [wHPBarMaxHP], a + ld c, a + srl b + rr c + srl b + rr c + ld a, c + and a + jr nz, .skip + inc c +.skip + ret + +Function3c7d3: + ld hl, wca14 + ldh a, [hBattleTurn] + and a + jr z, .asm_3c7de + ld hl, wcdeb +.asm_3c7de + ld a, [hli] + ld [wMapBlocksAddress], a + ld b, a + ld a, [hl] + ld [wHPBarMaxHP], a + ld c, a + srl b + rr c + ld a, c + and a + jr nz, .skip + inc c +.skip + ret + +Function3c7f2: + ld hl, wca14 + ldh a, [hBattleTurn] + and a + jr z, .asm_3c7fd + ld hl, wcdeb +.asm_3c7fd + ld a, [hli] + ld [wMapBlocksAddress], a + ld b, a + ld a, [hl] + ld [wHPBarMaxHP], a + ld c, a + ret + +sub_3c808: + ld hl, wcdeb + ldh a, [hBattleTurn] + and a + jr z, asm_3c813 + ld hl, wca14 + +asm_3c813: + ld a, [hli] + ld [wMapBlocksAddress], a + ld a, [hld] + ld [wHPBarMaxHP], a + dec hl + ld a, [hl] + ld [wHPBarOldHP], a + add c + ld [hld], a + ld [wHPBarNewHP], a + ld a, [hl] + ld [wReplacementBlock], a + adc b + ld [hli], a + ld [wcdc8], a + ld a, [wHPBarMaxHP] + ld c, a + ld a, [hld] + sub c + ld a, [wMapBlocksAddress] + ld b, a + ld a, [hl] + sbc b + jr c, asm_3c846 + ld a, b + ld [hli], a + ld [wcdc8], a + ld a, c + ld [hl], a + ld [wHPBarNewHP], a + +asm_3c846: + ldh a, [hBattleTurn] + push af + xor 1 + ldh [hBattleTurn], a + call sub_3c854 + pop af + ldh [hBattleTurn], a + ret + +sub_3c854: + ld hl, $c35e + ldh a, [hBattleTurn] + and a + ld a, 1 + jr z, asm_3c862 + ld hl, $c2ca + xor a + +asm_3c862: + push bc + ld [wHPBarType], a + predef UpdateHPBar + pop bc + ret + +sub_3c86d: + ld a, [wca45] + and a + jr nz, asm_3c878 + ld hl, wPlayerSubStatus3 + res 5, [hl] + +asm_3c878: + ld a, [wca4d] + and a + ret nz + ld hl, wEnemySubStatus3 + res 5, [hl] + ret + +asm_3c883: + xor a + ld [wcad5], a + call sub_3c8ca + call AnyPartyAlive + ld a, d + and a + jp z, asm_3cc56 + ld hl, wca12 + ld a, [hli] + or [hl] + call nz, Function3d5ce + ld c, $3c + call DelayFrames + ld a, [wBattleMode] + dec a + ret z + call sub_3c9ad + jp z, asm_3c9fd + ld hl, wca12 + ld a, [hli] + or [hl] + jr nz, asm_3c8b8 + call sub_3cb9d + ret c + call sub_3cbdb + +asm_3c8b8: + ld a, 1 + ld [wFieldMoveSucceeded], a + call sub_3c9c2 + jp z, asm_3c132 + xor a + ld [wFieldMoveSucceeded], a + jp asm_3c183 + +sub_3c8ca: + call sub_3d3f4 + ld a, [wBattleMode] + dec a + jr z, asm_3c8e2 + ld a, [wca36] + ld hl, wd93d + ld bc, $30 + call AddNTimes + xor a + ld [hli], a + ld [hl], a + +asm_3c8e2: + ld hl, wPlayerSubStatus3 + res 2, [hl] + xor a + ld hl, wca55 + ld [hli], a + ld [hli], a + ld [hli], a + ld [hl], a + ld hl, wca40 + ld [hli], a + ld [hli], a + ld [hli], a + ld [hli], a + ld [hl], a + ld [wca50], a + ld [wcad4], a + ld [wcad8], a + ld hl, wcad6 + ld [hli], a + ld [hl], a + ld hl, $c310 + ld de, $c324 + call sub_3ccef + ld hl, $c2a1 + ld bc, $040a + call ClearBox + ld a, [wBattleMode] + dec a + jr z, asm_3c935 + push de + ld de, $33 + call PlaySFX + call WaitSFX + pop de + push de + ld de, $25 + call PlaySFX + call WaitSFX + pop de + jr asm_3c93d + +asm_3c935: + call sub_3c9a8 + ld a, 0 + call sub_3cae1 + +asm_3c93d: + ld hl, wca12 + ld a, [hli] + or [hl] + jr nz, asm_3c94d + ld a, [wcad5] + and a + jr nz, asm_3c94d + call sub_3cb34 + +asm_3c94d: + call AnyPartyAlive + ld a, d + and a + ret z + ld hl, EnemyMonFainted + call PrintText + call PrintEmptyString + call BackUpTilesToBuffer + xor a + ld [wcd5d], a + ld b, $4b + call Function32c8 + push af + jr z, asm_3c976 + ld hl, wcdf9 + ld b, 7 + +asm_3c970: + srl [hl] + inc hl + dec b + jr nz, asm_3c970 + +asm_3c976: + xor a + ld [wHPBarMaxHP], a + call sub_3e421 + pop af + ret z + ld a, 1 + ld [wHPBarMaxHP], a + ld a, [wPartyCount] + ld b, 0 + +asm_3c989: + scf + rl b + dec a + jr nz, asm_3c989 + ld a, b + ld [wca37], a + jp sub_3e421 + +EnemyMonFainted: + text "てきの @" + text_from_ram wBattleMonNickname + text "は たおれた!" + prompt + +sub_3c9a8: + inc a + ld [wcadb], a + ret + +sub_3c9ad: + ld a, [wd913] + ld b, a + xor a + ld hl, wd93d + ld de, $30 + +asm_3c9b8: + or [hl] + inc hl + or [hl] + dec hl + add hl, de + dec b + jr nz, asm_3c9b8 + and a + ret + +sub_3c9c2: + ld hl, wccd2 + ld e, $30 + call sub_3d723 + callab Function3834e + ld a, [wLinkMode] + and a + jr z, asm_3c9e4 + call sub_3df8b + ld a, [wOtherPlayerLinkAction] + cp $f + ret z + call ReloadTilesFromBuffer + +asm_3c9e4: + call sub_3cd6e + call sub_3d071 + ld a, 1 + ldh [hBattleTurn], a + call Function3d3a2 + xor a + ld [wc9e8], a + ld [wFieldMoveSucceeded], a + ld [wcaba], a + inc a + ret + +asm_3c9fd: + call sub_3c9a8 + ld b, 0 + ld a, [wce04] + and a + jr nz, asm_3ca0a + ld b, $b + +asm_3ca0a: + ld a, [wca22] + cp $2b + jr nz, asm_3ca18 + ld b, 0 + ld hl, wDebugFlags + set 1, [hl] + +asm_3ca18: + ld a, [wLinkMode] + and a + ld a, b + call z, sub_3cae1 + callab Function390e9 + ld hl, TrainerDefeatedText + call PrintText + ld a, [wLinkMode] + cp 3 + ret z + call sub_3e201 + ld c, $28 + call DelayFrames + ld a, [wce02] + cp 9 + jr nz, asm_3ca51 + ld hl, RivalLossText + call PrintText + callab HealParty + +asm_3ca51: + ld a, [wca03] + ld b, a + callab Function37e3d + ld a, b + cp $4c + jr nz, asm_3ca74 + ld hl, wca5b + sla [hl] + dec hl + rl [hl] + dec hl + rl [hl] + jr nc, asm_3ca74 + ld a, $ff + ld [hli], a + ld [hli], a + ld [hl], a + +asm_3ca74: + ld de, wd15f + ld hl, wca5b + ld c, 3 + and a + +asm_3ca7d: + ld a, [de] + adc [hl] + ld [de], a + dec de + dec hl + dec c + jr nz, asm_3ca7d + ld hl, PlayerReceivedPrizeMoneyText + call PrintText + ret + +PlayerReceivedPrizeMoneyText: + text "は しょうきんとして" + line "@" + deciram wca59, 3, 6 + text "円 てにいれた!" + prompt + +TrainerDefeatedText: + text_from_ram wca2b + text "の @" + text_from_ram wStringBuffer1 + text "" + line "との しょうぶに かった!" + prompt + +RivalLossText: + text "『あれー?" + line "おまえの #に" + cont "すりゃあ よかったのかなあ?" + prompt + +sub_3cae1: + push de + ld de, MUSIC_NONE + call PlayMusic + call DelayFrame + ld de, MUSIC_VICTORY_TRAINER + call PlayMusic + pop de + ret + +asm_3caf3: + ld a, 1 + ld [wcad5], a + call sub_3cb34 + call AnyPartyAlive + ld a, d + and a + jp z, asm_3cc56 + ld hl, wcde9 + ld a, [hli] + or [hl] + jr nz, asm_3cb18 + call sub_3c8ca + ld a, [wBattleMode] + dec a + ret z + call sub_3c9ad + jp z, asm_3c9fd + +asm_3cb18: + call sub_3cb9d + ret c + call sub_3cbdb + jp nz, asm_3c183 + ld a, 1 + ld [wFieldMoveSucceeded], a + call sub_3c9c2 + jp z, asm_3c132 + xor a + ld [wFieldMoveSucceeded], a + jp asm_3c183 + +sub_3cb34: + ld a, [wcd41] + ld c, a + ld hl, wca37 + ld b, 0 + predef SmallFarFlagAction + ld hl, wEnemySubStatus3 + res 2, [hl] + ld a, [wccc4] + bit 7, a + jr z, asm_3cb56 + ld a, $ff + ld [wccc4], a + call WaitSFX + +asm_3cb56: + ld hl, wTrainerClass + ld [hli], a + ld [hl], a + ld [wca10], a + ld [wca11], a + call sub_3d3f4 + ld hl, $c335 + ld bc, $050b + call ClearBox + ld hl, $c369 + ld de, $c37d + call sub_3ccef + ld a, 1 + ld [wcd5d], a + ld a, [wcad5] + and a + ret z + ld a, $f0 + ld [wCryTracks], a + ld a, [wca02] + call PlayStereoCry + ld hl, FaintedText + jp PrintText + +FaintedText: + text_from_ram wEnemyMonNickname + text "は たおれた!" + prompt + +sub_3cb9d: + call PrintEmptyString + call BackUpTilesToBuffer + ld a, [wBattleMode] + and a + dec a + ret nz + ld hl, UseNextMonText + call PrintText + +asm_3cbaf: + ld bc, $0107 + call asm_1dd5 + ld a, [wMenuCursorY] + jr c, asm_3cbbc + and a + ret + +asm_3cbbc: + ld a, [wMenuCursorY] + cp 1 + jr z, asm_3cbaf + ld hl, wPartyMon1Speed + ld de, wcdf1 + jp TryRunningFromBattle + +UseNextMonText: + text "つぎの #をつかいますか?" + done + +sub_3cbdb: + call LoadStandardMenuHeader + ld a, 2 + ld [wcdb9], a + predef Function50771 + +asm_3cbe8: + jr nc, asm_3cbf1 + +asm_3cbea: + predef Function50774 + jr asm_3cbe8 + +asm_3cbf1: + call HasMonFainted + jr z, asm_3cbea + ld a, [wLinkMode] + cp 3 + jr nz, asm_3cc04 + inc a + ld [wFieldMoveSucceeded], a + call sub_3df8b + +asm_3cc04: + xor a + ld [wFieldMoveSucceeded], a + call ClearSprites + ld a, [wWhichPokemon] + ld [wcd41], a + ld c, a + ld hl, wca37 + ld b, 1 + push bc + predef SmallFarFlagAction + pop bc + ld hl, wcada + predef SmallFarFlagAction + call LoadBattleMonFromParty + call ApplyStatMods + call ClearPalettes + call Function3e3a7 + call CloseWindow + call GetMemSGBLayout + call SetPalettes + call PrintSendOutMonMessage + call sub_3d387 + call Function3d32e + call PrintEmptyString + call BackUpTilesToBuffer + xor a + ldh [hBattleTurn], a + call Function3d3a2 + ld hl, wcde9 + ld a, [hli] + or [hl] + ret + +asm_3cc56: + ld a, [wLinkMode] + and a + jr nz, asm_3cc83 + ld a, [wce02] + cp 9 + jr nz, asm_3cc83 + ld hl, $c2a0 + ld bc, $0815 + call ClearBox + call sub_3e201 + ld c, 40 + call DelayFrames + ld hl, RivalWinText + call PrintText + callab HealParty + ret + +asm_3cc83: + ld b, 0 + call GetSGBLayout + ld hl, OutOfUsableMonsText + ld a, [wLinkMode] + cp 3 + jr nz, asm_3cc95 + ld hl, Data3ccdd + +asm_3cc95: + call PrintText + call ClearTileMap + scf + ret + +RivalWinText: + text "『やった!" + line "いい# えらんだかも!" + prompt + +OutOfUsableMonsText: + text "の てもとには" + line "たたかえる #が いない!" + para "は" + line "めのまえが まっくらに なった!" + prompt + +Data3ccdd: + text_from_ram wca2b + text "との" + line "しょうぶに まけた!" + prompt + +sub_3ccef: + ld a, [wJoypadFlags] + push af + set 6, a + ld [wJoypadFlags], a + ld b, 7 + +asm_3ccfa: + push bc + push de + push hl + ld b, 6 + +asm_3ccff: + push bc + push hl + push de + ld bc, 7 + call CopyBytes + pop de + pop hl + ld bc, hFFEC + add hl, bc + push hl + ld h, d + ld l, e + add hl, bc + ld d, h + ld e, l + pop hl + pop bc + dec b + jr nz, asm_3ccff + ld bc, $14 + add hl, bc + ld de, SevenBlankSpacesString + call PlaceString + ld c, 2 + call DelayFrames + pop hl + pop de + pop bc + dec b + jr nz, asm_3ccfa + pop af + ld [wJoypadFlags], a + ret + +SevenBlankSpacesString: + db "       @" + +sub_3cd3b: + ldh [hTextBoxCursorBlinkInterval], a + ld c, a + +asm_3cd3e: + push bc + push hl + ld b, 7 + +asm_3cd42: + push hl + call sub_3cd59 + pop hl + ld de, $14 + add hl, de + dec b + jr nz, asm_3cd42 + ld c, 2 + call DelayFrames + pop hl + pop bc + dec c + jr nz, asm_3cd3e + ret + +sub_3cd59: + ldh a, [hTextBoxCursorBlinkInterval] + ld c, a + cp 8 + jr nz, asm_3cd67 + +asm_3cd60: + ld a, [hli] + ld [hld], a + dec hl + dec c + jr nz, asm_3cd60 + ret + +asm_3cd67: + ld a, [hld] + ld [hli], a + inc hl + dec c + jr nz, asm_3cd67 + ret + +sub_3cd6e: + ld hl, wca37 + xor a + ld [hl], a + ld a, [wcd41] + ld c, a + ld b, 1 + push bc + predef SmallFarFlagAction + ld hl, wcada + xor a + ld [hl], a + pop bc + predef SmallFarFlagAction + xor a + ld hl, wcad6 + ld [hli], a + ld [hl], a + dec a + ld [wcac4], a + ld hl, wPlayerSubStatus3 + res 5, [hl] + ld hl, $c2b2 + ld a, 8 + call sub_3cd3b + call PrintEmptyString + call LoadStandardMenuHeader + ld a, [wLinkMode] + and a + jr z, FindMonInOTPartyToSwitchIntoBattle + ld a, [wOtherPlayerLinkAction] + sub 4 + ld b, a + jp asm_3cefa + +FindMonInOTPartyToSwitchIntoBattle: + ld a, [wce36] + and a + jp nz, asm_3ced8 + ld b, -1 + ld a, 1 + ld [wEnemyEffectivenessVsPlayerMons], a + ld [wPlayerEffectivenessVsEnemyMons], a +.loop + ld hl, wEnemyEffectivenessVsPlayerMons + sla [hl] + inc hl + sla [hl] + inc b + ld a, [wd913] + cp b + jp z, ScoreMonTypeMatchups + ld a, [wca36] + cp b + jr z, .discourage + ld hl, wd93d + push bc + ld a, b + ld bc, $30 + call AddNTimes + ld a, [hli] + ld c, a + ld a, [hl] + or c + pop bc + jr z, .discourage + call LookUpTheEffectivenessOfEveryMove + call IsThePlayerMonTypesEffectiveAgainstOTMon + jr .loop + +.discourage + ld hl, wPlayerEffectivenessVsEnemyMons + set 0, [hl] + jr .loop + +LookUpTheEffectivenessOfEveryMove: + push bc + ld hl, wd91d + ld a, b + ld bc, $30 + call AddNTimes + pop bc + ld e, 5 +.loop + dec e + jr z, .done + ld a, [hli] + and a + jr z, .done + push hl + push de + push bc + dec a + ld hl, Moves + ld bc, 7 + call AddNTimes + ld de, wc9e8 + ld a, BANK(Moves) + call FarCopyBytes + ld a, 1 + ldh [hBattleTurn], a + callab Function34fff + pop bc + pop de + pop hl + ld a, [wCountSetBitsResult] + cp $b + jr c, .loop + ld hl, wEnemyEffectivenessVsPlayerMons + set 0, [hl] + ret +.done + ret + +IsThePlayerMonTypesEffectiveAgainstOTMon: + push bc + ld hl, wd913 + ld a, b + inc a + ld c, a + ld b, 0 + add hl, bc + ld a, [hl] + dec a + ld hl, asm_3cf17 + ld bc, $1f + call AddNTimes + ld de, wcdf7 + ld bc, 2 + ld a, $14 + call FarCopyBytes + ld a, [wca20] + ld [wc9f2], a + xor a + ldh [hBattleTurn], a + callab Function34fff + ld a, [wCountSetBitsResult] + cp $b + jr nc, .super_effective + ld a, [wca21] + ld [wc9f2], a + callab Function34fff + ld a, [wCountSetBitsResult] + cp $b + jr nc, .super_effective + pop bc + ret + +.super_effective + pop bc + ld hl, wEnemyEffectivenessVsPlayerMons + bit 0, [hl] + jr nz, .reset + inc hl + set 0, [hl] + ret + +.reset + res 0, [hl] + ret + +ScoreMonTypeMatchups: +.loop1 + ld hl, wEnemyEffectivenessVsPlayerMons + sla [hl] + inc hl + sla [hl] + jr nc, .loop1 + ld a, [wd913] + ld b, a + ld c, [hl] +.loop2 + sla c + jr nc, .okay + dec b + jr z, asm_3ced8 + jr .loop2 + +.okay + ld a, [wEnemyEffectivenessVsPlayerMons] + and a + jr z, .okay2 + ld b, -1 + ld c, a +.loop3 + inc b + sla c + jr nc, .loop3 + jr asm_3cefa + +.okay2 + ld b, -1 + ld a, [wPlayerEffectivenessVsEnemyMons] + ld c, a +.loop4 + inc b + sla c + jr c, .loop4 + jr asm_3cefa + +asm_3ced8: + call BattleRandom + and 7 + cp 6 + jr nc, asm_3ced8 + ld b, a + ld a, [wca36] + cp b + jr z, asm_3ced8 + ld hl, wd93d + push bc + ld a, b + ld bc, $30 + call AddNTimes + pop bc + ld a, [hli] + ld c, a + ld a, [hl] + or c + jr z, asm_3ced8 + +asm_3cefa: + ld a, b + ld [wWhichPokemon], a + ld hl, wd93a + ld bc, $30 + call AddNTimes + ld a, [hl] + ld [wCurPartyLevel], a + ld a, [wWhichPokemon] + inc a + ld hl, wd913 + ld c, a + ld b, 0 + add hl, bc + ld a, [hl] + +asm_3cf17: + ld [wcdd7], a + ld [wMonDexIndex], a + call AddPokemonToBox + ld hl, wcde9 + ld a, [hli] + ld [wcac8], a + ld a, [hl] + ld [wcac9], a + ld a, 1 + ld [wMenuCursorY], a + ld a, [wce36] + dec a + jr z, EnemySendOutFirstMon + ld a, [wPartyCount] + dec a + jr z, EnemySendOutFirstMon + ld a, [wLinkMode] + and a + jr nz, EnemySendOutFirstMon + ld a, [wce5f] + bit 6, a + jr nz, EnemySendOutFirstMon + callab Function390e9 + ld hl, TrainerAboutToUseText + call PrintText + ld bc, $0107 + call asm_1dd5 + ld a, [wMenuCursorY] + dec a + jr nz, EnemySendOutFirstMon + ld a, 2 + ld [wcdb9], a + predef Function50771 + +asm_3cf6d: + ld a, 1 + ld [wMenuCursorY], a + jr c, asm_3cf93 + ld hl, wcd41 + ld a, [wWhichPokemon] + cp [hl] + jr nz, asm_3cf8a + ld hl, IsAlreadyOutText + call PrintText + +asm_3cf83: + predef Function50774 + jr asm_3cf6d + +asm_3cf8a: + call HasMonFainted + jr z, asm_3cf83 + xor a + ld [wMenuCursorY], a + +asm_3cf93: + call ClearPalettes + call Function3e3a7 + +EnemySendOutFirstMon: + call CloseWindow + call ClearSprites + ld hl, $c2a1 + ld bc, $040a + call ClearBox + ld b, 1 + call GetSGBLayout + call SetPalettes + callab Function390e9 + ld hl, TrainerSentOutText + call PrintText + ld a, [wcdd7] + ld [wMonDexIndex], a + ld [wCurSpecies], a + call GetMonHeader + ld a, 1 + ld [wMonType], a + predef Function50000 + ld hl, wcd94 + predef Function50ed9 + ld de, vFrontPic + call LoadMonFrontSprite + xor a + ld [wcccd], a + inc a + ldh [hBattleTurn], a + +; Play shiny animation for Sunflora and Pikachu + ld b, 1 + ld a, [wMonDexIndex] + cp DEX_SUNNY + jr z, .apply_animation + cp DEX_PIKACHU + jr z, .apply_animation + +; Play scanline fade animation for Hoothoot + ld b, 2 + cp DEX_HOHO + jr z, .apply_animation + +; Play send out animation for everyone else + ld b, 0 + +.apply_animation + ld a, b + ld [wca5c], a + ld de, $0101 + call PlayMoveAnimation + ld a, $f + ld [wCryTracks], a + ld a, [wcdd7] + call PlayStereoCry + call Function3d67c + ld a, [wMenuCursorY] + and a + ret nz + xor a + ld [wca37], a + ld [wcada], a + call BackUpTilesToBuffer + jp SwitchPlayerMon + +TrainerAboutToUseText: + text_from_ram wca2b + text "の @" + text_from_ram wStringBuffer1 + text "は" + text_from_ram wBattleMonNickname + text "を くりだそうと している" + + para "も #を" + line "とりかえますか?" + done + +TrainerSentOutText: + text_from_ram wca2b + text "の @" + text_from_ram wStringBuffer1 + text "は" + line "@" + text_from_ram wBattleMonNickname + text "を くりだした!" + done + +sub_3d071: + xor a + ld hl, wcad7 + ld [hli], a + ld [hl], a + ld hl, wca40 + ld [hli], a + ld [hli], a + ld [hli], a + ld [hli], a + ld [hl], a + ld [wca50], a + ld [wca53], a + ld [wcad4], a + ld [wcad8], a + ret + +AnyPartyAlive: + ld a, [wPartyCount] + ld e, a + xor a + ld hl, wPartyMon1HP + ld bc, $2f +.loop + or [hl] + inc hl + or [hl] + add hl, bc + dec e + jr nz, .loop + ld d, a + ret + +HasMonFainted: + ld a, [wWhichPokemon] + ld hl, wPartyMon1HP + ld bc, $30 + call AddNTimes + ld a, [hli] + or [hl] + ret nz + ld a, [wce36] + and a + jr nz, .has_hp + ld hl, NoWillText + call PrintText +.has_hp + xor a + ret + +NoWillText: + text "たたかう きりょくが ない!" + prompt + +TryRunningFromBattle: + ld a, [wBattleType] + cp 2 + jp z, .can_escape + ld a, [wLinkMode] + and a + jp nz, .can_escape + ld a, [wBattleMode] + dec a + jp nz, .trainer_battle + ld a, [wca3f] + bit 7, a + jp nz, .cannot_escape + push hl + push de + ld a, [wca03] + ld [wCountSetBitsResult], a + ld b, a + callab Function37e3d + ld a, b + cp $48 + pop de + pop hl + jr nz, .asm_3d10f + call GetItemName + ld hl, EscapedUsingItemText + call PrintText + jp .can_escape + +.asm_3d10f + ld a, [wce39] + inc a + ld [wce39], a + ld a, [hli] + ldh [hMultiplicand + 1], a + ld a, [hl] + ldh [hMultiplicand + 2], a + ld a, [de] + inc de + ldh [hSpriteOffset], a + ld a, [de] + ldh [hFFB2], a + call ReloadTilesFromBuffer + ld de, hMultiplicand + 1 + ld hl, hSpriteOffset + ld c, 2 + call memcmp + jr nc, .can_escape + xor a + ldh [hQuotient], a + ld a, $20 + ldh [hPrintNumDivisor], a + call Multiply + ldh a, [hMultiplicand + 1] + ldh [hProduct], a + ldh a, [hMultiplicand + 2] + ldh [hQuotient], a + ldh a, [hSpriteOffset] + ld b, a + ldh a, [hFFB2] + srl b + rr a + srl b + rr a + and a + jr z, .can_escape + ldh [hPrintNumDivisor], a + ld b, 2 + call Divide + ldh a, [hMultiplicand + 1] + and a + jr nz, .can_escape + ld a, [wce39] + ld c, a +.asm_3d165 + dec c + jr z, .asm_3d173 + ld b, $1e + ldh a, [hMultiplicand + 2] + add b + ldh [hMultiplicand + 2], a + jr c, .can_escape + jr .asm_3d165 + +.asm_3d173 + call BattleRandom + ld b, a + ldh a, [hMultiplicand + 2] + cp b + jr nc, .can_escape + ld a, 1 + ld [wFieldMoveSucceeded], a +.cannot_escape + ld hl, CantEscapeText + jr .print_text + +.trainer_battle + ld hl, NoRunningText +.print_text + call PrintText + ld a, 1 + ld [wce38], a + call BackUpTilesToBuffer + and a + ret + +.can_escape + ld a, [wLinkMode] + and a + ld a, 2 + jr z, .play_sound + call BackUpTilesToBuffer + xor a + ld [wFieldMoveSucceeded], a + ld a, $f + ld [wcd40], a + call sub_3df8b + call ReloadTilesFromBuffer + ld a, [wOtherPlayerLinkAction] + cp $f + ld a, 2 + jr z, .play_sound + dec a +.play_sound + ld [wcd5d], a + push de + ld de, $26 + call WaitPlaySFX + pop de + call WaitSFX + ld hl, GotAwayText + call PrintText + call WaitSFX + call BackUpTilesToBuffer + scf + ret + +CantEscapeText: + text "にげられない!" + prompt + +NoRunningText: + text "ダメだ!" + line "しょうぶの さいちゅうに" + cont "あいてに せなかは みせられない!" + prompt + +GotAwayText: + text "うまく にげきれた!" + prompt + +EscapedUsingItemText: + text "は そうびしていた" + line "@" + text_from_ram wStringBuffer1 + text "を つかって にげた" + prompt + +LoadBattleMonFromParty: + ld a, [wWhichPokemon] + ld bc, $30 + ld hl, wPartyMon1Species + call AddNTimes + ld de, wca02 + ld bc, 6 + call CopyBytes + ld bc, $f + add hl, bc + ld de, wca08 + ld bc, 7 + call CopyBytes + inc hl + inc hl + inc hl + ld de, wca0f + ld bc, $11 + call CopyBytes + ld a, [wcdd8] + ld [wCurSpecies], a + call GetMonHeader + ld a, [wMonHType1] + ld [wca20], a + ld a, [wMonHType2] + ld [wca21], a + ld hl, wPartyMonNicknames + ld a, [wcd41] + call SkipNames + ld de, wEnemyMonNickname + ld bc, 6 + call CopyBytes + ld hl, wca16 + ld de, wca93 + ld bc, $a + call CopyBytes + call sub_3e247 + call sub_3e360 + xor a + ldh [hBattleTurn], a + callab Function95cc + ret + +ApplyStatMods: + ld a, 7 + ld b, 8 + ld hl, wcaa9 +.loop + ld [hli], a + dec b + jr nz, .loop + ret + +LoadEnemyMonFromParty: + ld a, [wWhichPokemon] + ld bc, $30 + ld hl, wWildMons + call AddNTimes + ld de, wcdd9 + ld bc, 6 + call CopyBytes + ld bc, $f + add hl, bc + ld de, wcddf + ld bc, 7 + call CopyBytes + inc hl + inc hl + inc hl + ld de, wcde6 + ld bc, $11 + call CopyBytes + ld a, [wcdd9] + ld [wCurSpecies], a + call GetMonHeader + ld hl, wda5f + ld a, [wWhichPokemon] + call SkipNames + ld de, wBattleMonNickname + ld bc, 6 + call CopyBytes + ld hl, wcded + ld de, wca9e + ld bc, $a + call CopyBytes + call sub_3e24b + ld hl, wMonHType1 + ld de, wcdf7 + ld a, [hli] + ld [de], a + inc de + ld a, [hl] + ld [de], a + ld hl, wMonHBaseStats + ld de, wcdf9 + ld b, 5 +.base_stats_loop + ld a, [hli] + ld [de], a + inc de + dec b + jr nz, .base_stats_loop + ld a, 7 + ld b, 8 + ld hl, wcab1 +.stat_mod_loop + ld [hli], a + dec b + jr nz, .stat_mod_loop + ld a, [wWhichPokemon] + ld [wca36], a + ret + +Function3d32e: + ld hl, wca08 + predef Function50ed9 + ld a, $21 + call Predef + xor a + ldh [hGraphicStartTile], a + ld hl, wStartmenuCursor + ld [hli], a + ld [hl], a + ld [wca38], a + ld [wc9ef], a + ld b, 1 + call GetSGBLayout + ld hl, wEnemySubStatus3 + res 5, [hl] + xor a + ldh [hBattleTurn], a + ld [wcccd], a + +; Play shiny animation for Sunflora and Pikachu + ld b, 1 + ld a, [wMonDexIndex] + cp DEX_SUNNY + jr z, .apply_animation + cp DEX_PIKACHU + jr z, .apply_animation + +; Play scanline fade animation for Hoothoot + ld b, 2 + cp DEX_HOHO + jr z, .apply_animation + +; Play send out animation for everyone else + ld b, 0 + +.apply_animation + ld a, b + ld [wca5c], a + ld de, $0101 + call PlayMoveAnimation + +; mon on the left side + ld a, $f0 + ld [wCryTracks], a + ld a, [wMonDexIndex] + call PlayStereoCry + call Function3d5ce + ret + +sub_3d387: + xor a + ld hl, wcad6 + ld [hli], a + ld [hl], a + ld hl, wca3b + ld [hli], a + ld [hli], a + ld [hli], a + ld [hli], a + ld [hl], a + ld [wca48], a + ld [wca4b], a + ld [wcad3], a + ld [wcadc], a + ret + +Function3d3a2: + ld hl, wcadd + ld de, wca20 + ldh a, [hBattleTurn] + and a + jr z, asm_3d3b3 + ld hl, wcade + ld de, wcdf7 + +asm_3d3b3: + bit 0, [hl] + ret z + ld a, [de] + cp 2 + ret z + inc de + ld a, [de] + cp 2 + ret z + ld hl, HitWithRecoilText + call PrintText + call sub_3c78b + call sub_3c75e + ret + +HitWithRecoilText: + text "は まきびしの" + line "ダメージを うけた!" + prompt + +sub_3d3e1: + ldh a, [hBattleTurn] + push af + xor a + ldh [hBattleTurn], a + ld [wcccd], a + ld de, $0102 + call PlayMoveAnimation + pop af + ldh [hBattleTurn], a + ret + +sub_3d3f4: + ld a, [wcd41] + ld hl, wPartyMon1Level + ld bc, $30 + call AddNTimes + ld d, h + ld e, l + ld hl, wca0f + ld bc, 5 + jp CopyBytes + +sub_3d40b: + ldh a, [hLinkPlayerNumber] + cp 1 + jr z, asm_3d418 + call sub_3d41f + call sub_3d42d + ret + +asm_3d418: + call sub_3d42d + call sub_3d41f + ret + +sub_3d41f: + xor a + ldh [hBattleTurn], a + call sub_3d43b + ld a, 1 + ldh [hBattleTurn], a + call sub_3d43b + ret + +sub_3d42d: + ld a, 1 + ldh [hBattleTurn], a + call sub_3d43b + xor a + ldh [hBattleTurn], a + call sub_3d43b + ret + +sub_3d43b: + callab Function37e2d + ld a, b + cp 1 + ret nz + ld de, wcdea + ld hl, wcdec + ldh a, [hBattleTurn] + and a + jr z, asm_3d458 + ld de, wca13 + ld hl, wIntroTilesPointer + +asm_3d458: + push bc + ld a, [de] + ld [wHPBarOldHP], a + add a + ld c, a + dec de + ld a, [de] + inc de + ld [wReplacementBlock], a + adc a + ld b, a + ld a, c + cp [hl] + dec hl + ld a, b + sbc [hl] + pop bc + ret nc + ld a, [hli] + ld [wMapBlocksAddress], a + ld a, [hl] + ld [wHPBarMaxHP], a + ld a, [de] + add c + ld [wHPBarNewHP], a + ld c, a + dec de + ld a, [de] + adc 0 + ld [wcdc8], a + ld b, a + ld a, [hld] + cp c + ld a, [hl] + sbc b + jr nc, asm_3d492 + ld a, [hli] + ld [wcdc8], a + ld a, [hl] + ld [wHPBarNewHP], a + +asm_3d492: + ld a, [wcdc8] + ld [de], a + inc de + ld a, [wHPBarNewHP] + ld [de], a + call sub_3d4d4 + ldh a, [hBattleTurn] + ld [wHPBarType], a + and a + ld hl, $c2ca + jr z, asm_3d4ac + ld hl, $c35e + +asm_3d4ac: + ld [wHPBarType], a + predef UpdateHPBar + call DrawHUDsAndHPBars + callab Function37e2d + ld a, [hl] + ld [wCountSetBitsResult], a + call GetItemName + callab Function37e60 + ld hl, RecoveredWithItemText + jp PrintText + +sub_3d4d4: + ld a, $69 + ld [wccc0], a + ldh a, [hBattleTurn] + push af + xor 1 + ldh [hBattleTurn], a + xor a + ld [wcccd], a + ld [wccc1], a + ld a, $51 + call Predef + pop af + ldh [hBattleTurn], a + ret + +RecoveredWithItemText: + text "は そうびしていた" + line "@" + text_from_ram wStringBuffer1 + text "で かいふくした!" + prompt + +sub_3d50b: + ldh a, [hLinkPlayerNumber] + cp 1 + jr z, asm_3d518 + call sub_3d51f + call sub_3d537 + ret + +asm_3d518: + call sub_3d537 + call sub_3d51f + ret + +sub_3d51f: + ld hl, wPartyMon1Item + ld a, [wcd41] + ld bc, $30 + call AddNTimes + ld bc, wca03 + ld de, wc9ef + ld a, 0 + call sub_3d54f + ret + +sub_3d537: + ld hl, wd91c + ld a, [wca36] + ld bc, $30 + call AddNTimes + ld bc, wcdda + ld de, wc9e8 + ld a, 1 + call sub_3d54f + ret + +sub_3d54f: + ldh [hBattleTurn], a + push hl + push bc + ld a, [bc] + ld b, a + callab Function37e3d + ld hl, Data3d59f + +asm_3d560: + ld a, [hli] + cp $ff + jr z, asm_3d59c + inc hl + cp b + jr nz, asm_3d560 + pop bc + ld a, [bc] + ld [wCountSetBitsResult], a + xor a + ld [bc], a + dec hl + ld b, [hl] + pop hl + ld [hl], 0 + push de + push bc + call GetItemName + ld hl, UseItemFailedText + call PrintText + pop bc + pop de + ld a, [de] + push af + ld a, $4a + ld [de], a + inc de + ld a, [de] + push af + push de + ld a, b + ld [de], a + callab Function365bf + pop de + pop af + ld [de], a + pop af + dec de + ld [de], a + ret + +asm_3d59c: + pop bc + pop hl + ret + +Data3d59f: + db $1f, $a + db $20, $b + db $21, $c + db $22, $d + db $23, $e + db $24, $f + db $25, $10 + db -1 + +UseItemFailedText: + text "が そうびしていた" + line "@" + text_from_ram wStringBuffer1 + text "が さどうした!" + prompt + +DrawHUDsAndHPBars: + call Function3d5ce + jp Function3d67c + +Function3d5ce: + xor a + ldh [hBGMapMode], a + ld hl, $c335 + ld bc, $050b + call ClearBox + callab Function383cd + ld hl, $c366 + ld [hl], $73 + ld de, wEnemyMonNickname + ld hl, $c34a + call sub_3d72f + call PlaceString + push bc + ld hl, wca02 + ld de, wcd7f + ld bc, 6 + call CopyBytes + ld hl, wca0f + ld de, wLoadedMonLevel + ld bc, $11 + call CopyBytes + ld a, [wcd7f] + ld [wCurSpecies], a + call GetMonHeader + pop hl + push hl + inc hl + ld de, wcd9f + ld a, $34 + call Predef + pop hl + jr nz, asm_3d626 + call PrintLevel + +asm_3d626: + ld a, [wcd7f] + ld [wMonDexIndex], a + ld hl, $c35e + ld b, 1 + ld a, $3c + call Predef + push de + ld a, [wcd41] + ld hl, wPartyMon1Exp + 2 + ld bc, $30 + call AddNTimes + ld d, h + ld e, l + ld hl, $c386 + ld a, [wLoadedMonLevel] + ld b, a + call Function3e874 + ld a, 1 + ldh [hBGMapMode], a + pop de + ld hl, wccd1 + call sub_3d723 + ld hl, wca12 + ld a, [hli] + or [hl] + jr z, asm_3d66d + ld a, [wcadb] + and a + ret nz + ld a, [wccd1] + cp 2 + jr z, asm_3d676 + +asm_3d66d: + ld hl, wccc4 + bit 7, [hl] + ld [hl], 0 + ret z + ret + +asm_3d676: + ld hl, wccc4 + set 7, [hl] + ret + +Function3d67c: + xor a + ldh [hBGMapMode], a + ld hl, $c2a1 + ld bc, $040b + call ClearBox + callab Function383fd + ld de, wBattleMonNickname + ld hl, $c2b6 + call sub_3d72f + call PlaceString + ld h, b + ld l, c + push hl + inc hl + ld de, wcde7 + ld a, $34 + call Predef + pop hl + jr nz, asm_3d6b4 + ld a, [wcde6] + ld [wLoadedMonLevel], a + call PrintLevel + +asm_3d6b4: + ld hl, wcde9 + ld a, [hli] + ldh [hMultiplicand + 1], a + ld a, [hld] + ldh [hMultiplicand + 2], a + or [hl] + jr nz, asm_3d6c7 + ld c, a + ld e, a + ld d, 6 + jp asm_3d710 + +asm_3d6c7: + xor a + ldh [hQuotient], a + ld a, $30 + ldh [hPrintNumDivisor], a + call Multiply + ld hl, wcdeb + ld a, [hli] + ld b, a + ld a, [hl] + ldh [hPrintNumDivisor], a + ld a, b + and a + jr z, asm_3d6fb + ldh a, [hPrintNumDivisor] + srl b + rr a + srl b + rr a + ldh [hPrintNumDivisor], a + ldh a, [hMultiplicand + 1] + ld b, a + srl b + ldh a, [hMultiplicand + 2] + rr a + srl b + rr a + ldh [hMultiplicand + 2], a + ld a, b + ldh [hMultiplicand + 1], a + +asm_3d6fb: + ldh a, [hMultiplicand + 1] + ldh [hProduct], a + ldh a, [hMultiplicand + 2] + ldh [hQuotient], a + ld a, 2 + ld b, a + call Divide + ldh a, [hMultiplicand + 2] + ld e, a + ld a, 6 + ld d, a + ld c, a + +asm_3d710: + xor a + ld [wHPBarType], a + ld hl, $c2ca + ld b, 0 + call DrawBattleHPBar + ld a, 1 + ldh [hBGMapMode], a + ld hl, wccd2 + +sub_3d723: + ld b, [hl] + call SetHPPal + ld a, [hl] + cp b + ret z + ld b, 1 + jp GetSGBLayout + +sub_3d72f: + push de + inc hl + inc hl + ld b, 2 + +asm_3d734: + inc de + ld a, [de] + cp $50 + jr z, asm_3d744 + inc de + ld a, [de] + cp $50 + jr z, asm_3d744 + dec hl + dec b + jr nz, asm_3d734 + +asm_3d744: + pop de + ret + +DisplayBattleMenu: + call ReloadTilesFromBuffer + ld a, [wBattleType] + and a + jr nz, .menu_loop + call DrawHUDsAndHPBars + call PrintEmptyString + call BackUpTilesToBuffer + +.menu_loop: + callab asm_24b06 + jr c, .menu_loop + ld a, [wStartmenuCursor] + cp 1 + jp z, .attack_menu + cp 2 + jp z, .item_menu + cp 3 + jp z, Battle_PartyMenu + cp 4 + jp z, Battle_PickedRun + jr .menu_loop + +.attack_menu: + xor a + ld [wce39], a + call ReloadTilesFromBuffer + and a + ret + +.item_menu: + ld a, [wLinkMode] + and a + jp nz, .cant_use_gear + call LoadStandardMenuHeader + callab GetPocket2Status + xor a + ld [wSelectedSwapPosition], a + call ClearPalettes + callab DrawBackpack + +.item_menu_loop + xor a + ldh [hBGMapMode], a + call ClearSprites + ld hl, $c2ca + ld b, 8 + ld c, $f + call DrawTextBox + call Call_DebugBackpackLoop + jr c, .exit_item_menu + call sub_3d84e + ld a, [wFieldMoveSucceeded] + and a + jr z, .item_menu_loop + call Call_LoadBattleGraphics + call ClearSprites + ld a, 1 + ld [wMenuCursorY], a + call sub_3d832 + ld a, [wce35] + and a + jr nz, .asm_3d7eb + call CloseWindow + call BackUpTilesToBuffer + call DrawHUDsAndHPBars + call WaitBGMap + call ClearWindowData + call SetPalettes + and a + ret + +.asm_3d7eb + xor a + ld [wce35], a + ld a, 2 + ld [wcd5d], a + call ClearWindowData + call SetPalettes + scf + ret + +.exit_item_menu + call ClearPalettes + call DelayFrame + call Call_LoadBattleGraphics + call CloseWindow + call BackUpTilesToBuffer + call SetPalettes + jp DisplayBattleMenu + +.cant_use_gear + ld hl, CantUseGearText + call PrintText + jp DisplayBattleMenu + +CantUseGearText: + text "ここでは どうぐを" + line "つかうことは できません" + prompt + +sub_3d832: + ld a, [wPlayerSubStatus3] + bit 5, a + jr z, .ok + ld hl, wca45 + dec [hl] + jr nz, .ok + ld hl, wPlayerSubStatus3 + res 5, [hl] +.ok + ret + +Call_DebugBackpackLoop: + callab DebugBackpackLoop + ret + +sub_3d84e: + callab ScrollingMenu_ClearLeftColumn + call PlaceHollowCursor + predef LoadItemData + callab CheckItemContext + ld a, [wItemAttributeParamBuffer] + ld hl, Data3d870 + call CallJumptable + ret + +Data3d870: + dw asm_3d87e + dw asm_3d87e + dw asm_3d88b + dw asm_3d89a + dw asm_3d8b9 + dw asm_3d8aa + dw asm_3d8b9 + +asm_3d87e: + callab PrintCantUseText + xor a + ld [wFieldMoveSucceeded], a + ret + +asm_3d88b: + callab BallPocket + jr nc, asm_3d8b9 + xor a + ld [wFieldMoveSucceeded], a + ret + +asm_3d89a: + callab FlipPocket2Status + xor a + ld [wSelectedSwapPosition], a + ld [wFieldMoveSucceeded], a + ret + +asm_3d8aa: + call UseItem + call ClearPalettes + callab DrawBackpack + ret + +asm_3d8b9: + call UseItem + ret + +Battle_PartyMenu: + call LoadStandardMenuHeader + +asm_3d8c0: + call ExitMenu + call LoadStandardMenuHeader + xor a + ld [wcdb9], a + predef Function50771 + jp c, asm_3d918 + jp asm_3d8eb + +asm_3d8d5: + ld hl, $c387 + ld bc, $81 + ld a, " " + call ByteFill + xor a + ld [wcdb9], a + predef Function50774 + jr c, asm_3d918 + +asm_3d8eb: + callab Function_8f1cb + callab asm_24aa9 + jr c, asm_3d8d5 + call PlaceHollowCursor + ld a, [wMenuCursorY] + cp 1 + jp z, asm_3d982 + cp 2 + jr z, asm_3d912 + cp 3 + jr z, asm_3d918 + jr asm_3d8eb + +asm_3d912: + call sub_3d930 + jp asm_3d8c0 + +asm_3d918: + call ClearSprites + call ClearPalettes + call Function3e3a7 + call CloseWindow + call BackUpTilesToBuffer + call GetMemSGBLayout + call SetPalettes + jp DisplayBattleMenu + +sub_3d930: + call DisableLCD + ld hl, $9310 + ld de, vSprites + ld bc, $0110 + call CopyBytes + ld hl, vFrontPic + ld de, $8110 + ld bc, $0310 + call CopyBytes + call EnableLCD + call ClearSprites + call LowVolume + xor a + ld [wMonType], a + ld hl, wPartyMon1Species + predef Function502b5 + call MaxVolume + call DisableLCD + ld hl, vSprites + ld de, $9310 + ld bc, $0110 + call CopyBytes + ld hl, $8110 + ld de, vFrontPic + ld bc, $0310 + call CopyBytes + call EnableLCD + ret + +asm_3d982: + ld a, [wca3f] + bit 7, a + jr z, asm_3d992 + ld hl, CantBringBackText + call PrintText + jp asm_3d8d5 + +asm_3d992: + ld a, [wcd41] + ld d, a + ld a, [wWhichPokemon] + cp d + jr nz, asm_3d9a5 + ld hl, IsAlreadyOutText + call PrintText + jp asm_3d8d5 + +asm_3d9a5: + call HasMonFainted + jp z, asm_3d8d5 + ld a, 1 + ld [wFieldMoveSucceeded], a + call ClearPalettes + call ClearSprites + call Function3e3a7 + call CloseWindow + call GetMemSGBLayout + call SetPalettes + +SwitchPlayerMon: + ld a, [wLinkMode] + and a + jr z, asm_3d9cb + call sub_3df8b + +asm_3d9cb: + call RetreatMon + ld c, $32 + call DelayFrames + call sub_3d3e1 + ld hl, $c335 + ld bc, $050b + call ClearBox + ld a, [wWhichPokemon] + ld [wcd41], a + ld c, a + ld b, 1 + push bc + ld hl, wca37 + predef SmallFarFlagAction + pop bc + ld hl, wcada + predef SmallFarFlagAction + call LoadBattleMonFromParty + call ApplyStatMods + call PrintSendOutMonMessage + call sub_3d387 + call Function3d32e + call PrintEmptyString + call BackUpTilesToBuffer + xor a + ldh [hBattleTurn], a + call Function3d3a2 + ld a, 2 + ld [wMenuCursorY], a + and a + ret + +asm_3da1c: ; unreferenced? + ld c, 50 + call DelayFrames + ld a, [wLinkMode] + and a + jr z, asm_3da2a + call sub_3df8b + +asm_3da2a: + ld hl, $c335 + ld bc, $050b + call ClearBox + ld a, [wWhichPokemon] + ld [wcd41], a + ld c, a + ld b, 1 + push bc + ld hl, wca37 + predef SmallFarFlagAction + pop bc + ld hl, wcada + predef SmallFarFlagAction + call LoadBattleMonFromParty + xor a + ld [wCountSetBitsResult], a + call sub_3e2c6 + call Function3d32e + call PrintEmptyString + call BackUpTilesToBuffer + xor a + ldh [hBattleTurn], a + call Function3d3a2 + ret + +IsAlreadyOutText: + text_from_ram wEnemyMonNickname + text "はもうでています" + prompt + +CantBringBackText: + text_from_ram wEnemyMonNickname + text "を もどすことが" + line "できない!" + prompt + +Battle_PickedRun: + call ReloadTilesFromBuffer + ld a, 3 + ld [wMenuCursorY], a + ld hl, wca1a + ld de, wcdf1 + call TryRunningFromBattle + ld a, 0 + ld [wce38], a + ret c + ld a, [wFieldMoveSucceeded] + and a + ret nz + jp DisplayBattleMenu + +Function3daa7: + ld hl, wcddb + ld a, [wcac0] + dec a + jr z, asm_3dac8 + dec a + jr z, asm_3dabc + call sub_3dce0 + ret z + ld hl, wca04 + jr asm_3dac8 + +asm_3dabc: + ld a, [wWhichPokemon] + ld hl, wPartyMon1Moves + ld bc, $30 + call AddNTimes + +asm_3dac8: + ld de, wce2e + ld bc, 4 + call CopyBytes + xor a + ldh [hBGMapMode], a + ld hl, $c340 + ld b, 8 + ld c, 8 + ld a, [wcac0] + cp 2 + jr nz, asm_3dae9 + ld hl, $c34a + ld b, 8 + ld c, 8 + +asm_3dae9: + call DrawTextBox + ld hl, $c36a + ld a, [wcac0] + cp 2 + jr nz, asm_3daf9 + ld hl, $c374 + +asm_3daf9: + ld a, $28 + ld [wHPBarMaxHP], a + ld a, $32 + call Predef + ld b, 1 + ld a, [wcac0] + cp 2 + jr nz, asm_3db0e + ld b, $b + +asm_3db0e: + ld a, $a + ld [w2DMenuCursorInitY], a + ld a, b + ld [w2DMenuCursorInitX], a + ld a, [wcac0] + cp 1 + jr z, asm_3db22 + ld a, [wcd40] + inc a + +asm_3db22: + ld [wMenuCursorY], a + ld a, 1 + ld [wMenuCursorX], a + ld a, [wcd57] + inc a + ld [w2DMenuNumRows], a + ld a, 1 + ld [w2DMenuNumCols], a + ld c, $2c + ld a, [wcac0] + dec a + ld b, $c1 + jr z, asm_3db59 + dec a + ld b, $c3 + jr z, asm_3db59 + ld a, [wLinkMode] + cp 3 + jr z, asm_3db59 + ld a, [wDebugFlags] + bit 0, a + ld b, $c7 + jr z, asm_3db59 + ld b, $ff + ld c, $2f + +asm_3db59: + ld a, b + ld [wMenuJoypadFilter], a + ld a, c + ld [w2DMenuFlags], a + xor a + ld [w2DMenuFlags + 1], a + ld a, $20 + ld [w2DMenuCursorOffsets], a + +asm_3db6a: + ld a, [wcac0] + and a + jr z, asm_3db7e + dec a + jr nz, asm_3db9a + ld hl, $c3c3 + ld de, Data3dc47 + call PlaceString + jr asm_3db9a + +asm_3db7e: + ld a, [wDebugFlags] + bit 0, a + jr nz, asm_3db9a + call sub_3ddba + ld a, [wSelectedSwapPosition] + and a + jr z, asm_3db9a + ld hl, $c369 + dec a + ld bc, $28 + call AddNTimes + ld [hl], $ec + +asm_3db9a: + call WaitBGMap + ld a, 1 + ldh [hBGMapMode], a + call Get2DMenuJoypad_NoPlaceCursor + bit 6, a + jp nz, asm_3dc55 + bit 7, a + jp nz, asm_3dc66 + bit 2, a + jp nz, asm_3dd31 + bit 3, a + jp nz, asm_3dc7b + bit 4, a + jp nz, asm_3dcaa + bit 5, a + jp nz, asm_3dca4 + bit 1, a + push af + xor a + ld [wSelectedSwapPosition], a + ld a, [wMenuCursorY] + dec a + ld [wMenuCursorY], a + ld b, a + ld a, [wcac0] + dec a + jr nz, asm_3dbd9 + pop af + ret + +asm_3dbd9: + dec a + ld a, b + ld [wcd40], a + jr nz, asm_3dbe2 + pop af + ret + +asm_3dbe2: + pop af + ret nz + ld hl, wca0a + ld a, [wMenuCursorY] + ld c, a + ld b, 0 + add hl, bc + ld a, [hl] + and $3f + jr z, asm_3dc1a + ld a, [wca48] + swap a + and $f + dec a + cp c + jr z, asm_3dc15 + ld a, [wca3f] + bit 3, a + jr nz, asm_3dc05 + +asm_3dc05: + ld a, [wMenuCursorY] + ld hl, wca04 + ld c, a + ld b, 0 + add hl, bc + ld a, [hl] + ld [wcac1], a + xor a + ret + +asm_3dc15: + ld hl, Data3dc38 + jr asm_3dc1d + +asm_3dc1a: + ld hl, Data3dc26 + +asm_3dc1d: + call PrintText + call ReloadTilesFromBuffer + jp Function3daa7 + + + +Data3dc26: + text "わざの のこりポイントが ない!" + +Data3dc38: + text "わざを ふうじられている!" + +Data3dc47: + db "どのわざをものまねする?@" + +asm_3dc55: + ld a, [wMenuCursorY] + and a + jp nz, asm_3db6a + ld a, [wcd57] + inc a + ld [wMenuCursorY], a + jp asm_3db6a + +asm_3dc66: + ld a, [wMenuCursorY] + ld b, a + ld a, [wcd57] + inc a + inc a + cp b + jp nz, asm_3db6a + ld a, 1 + ld [wMenuCursorY], a + jp asm_3db6a + +asm_3dc7b: + bit 3, a + ld a, 0 + jr nz, asm_3dc83 + ld a, 1 + +asm_3dc83: + ldh [hBattleTurn], a + call ReloadTilesFromBuffer + call sub_3dcb7 + ld a, [wcabe] + and a + jp z, Function3daa7 + ld [wccc0], a + xor a + ld [wcccd], a + ld [wccc1], a + ld a, $51 + call Predef + jp Function3daa7 + +asm_3dca4: + ld a, [wcabe] + dec a + jr asm_3dcae + +asm_3dcaa: + ld a, [wcabe] + inc a + +asm_3dcae: + ld [wcabe], a + call sub_3dcb7 + jp Function3daa7 + +sub_3dcb7: + ld hl, $c3ea + ld bc, $020a + call ClearBox + ld hl, $c3fe + ld de, wcabe + ld bc, $8103 + call PrintNumber + ld a, [wcabe] + and a + ret z + cp $fc + ret nc + ld [wCountSetBitsResult], a + call Unreferenced_GetMoveName + ld hl, $c401 + jp PlaceString + +sub_3dce0: + ld a, $a5 + ld [wcac1], a + ld a, [wca48] + and a + ld hl, wca0a + jr nz, asm_3dcf7 + ld a, [hli] + or [hl] + inc hl + or [hl] + inc hl + or [hl] + ret nz + jr asm_3dd0c + +asm_3dcf7: + swap a + and $f + ld b, a + ld d, 5 + xor a + +asm_3dcff: + dec d + jr z, asm_3dd0a + ld c, [hl] + inc hl + dec b + jr z, asm_3dcff + or c + jr asm_3dcff + +asm_3dd0a: + and a + ret nz + +asm_3dd0c: + ld hl, Data3dd19 + call PrintText + ld c, $3c + call DelayFrames + xor a + ret + +Data3dd19: + text_from_ram wEnemyMonNickname + text "は だすことの できるわざが ない!" + +asm_3dd31: + ld a, [wDebugFlags] + bit 0, a + jp nz, asm_3dc7b + ld a, [wSelectedSwapPosition] + and a + jr z, asm_3ddb1 + ld hl, wca04 + call sub_3dd97 + ld hl, wca0a + call sub_3dd97 + ld hl, wca48 + ld a, [hl] + swap a + and $f + ld b, a + ld a, [wMenuCursorY] + cp b + jr nz, asm_3dd67 + ld a, [hl] + and $f + ld b, a + ld a, [wSelectedSwapPosition] + swap a + add b + ld [hl], a + jr asm_3dd78 + +asm_3dd67: + ld a, [wSelectedSwapPosition] + cp b + jr nz, asm_3dd78 + ld a, [hl] + and $f + ld b, a + ld a, [wMenuCursorY] + swap a + add b + ld [hl], a + +asm_3dd78: + ld hl, wPartyMon1Moves + ld a, [wcd41] + ld bc, $30 + call AddNTimes + push hl + call sub_3dd97 + pop hl + ld bc, $15 + add hl, bc + call sub_3dd97 + xor a + ld [wSelectedSwapPosition], a + jp Function3daa7 + +sub_3dd97: + push hl + ld a, [wSelectedSwapPosition] + dec a + ld c, a + ld b, 0 + add hl, bc + ld d, h + ld e, l + pop hl + ld a, [wMenuCursorY] + dec a + ld c, a + ld b, 0 + add hl, bc + ld a, [de] + ld b, [hl] + ld [hl], a + ld a, b + ld [de], a + ret + +asm_3ddb1: + ld a, [wMenuCursorY] + ld [wSelectedSwapPosition], a + jp Function3daa7 + +sub_3ddba: + xor a + ldh [hBGMapMode], a + ld hl, $c399 + ld b, 4 + ld c, 9 + call DrawTextBox + ld a, [wca48] + and a + jr z, asm_3dde3 + swap a + and $f + ld b, a + ld a, [wMenuCursorY] + cp b + jr nz, asm_3dde3 + ld hl, $c3d6 + ld de, DisabledText + call PlaceString + jr asm_3de5b + +asm_3dde3: + ld hl, wMenuCursorY + dec [hl] + xor a + ldh [hBattleTurn], a + ld hl, wca04 + ld a, [wMenuCursorY] + ld c, a + ld b, 0 + add hl, bc + ld a, [hl] + ld [wcac1], a + ld a, [wcd41] + ld [wWhichPokemon], a + ld a, 4 + ld [wMonType], a + callab Functionf960 + ld hl, wMenuCursorY + ld c, [hl] + inc [hl] + ld b, 0 + ld hl, wca0a + add hl, bc + ld a, [hl] + and $3f + ld [wStringBuffer1], a + ld hl, $c3d6 + ld de, MoveTypeText + call PlaceString + ld hl, $c3b4 + ld [hl], $f3 + ld hl, $c3ee + ld [hl], $f3 + ld hl, $c3b2 + ld de, wStringBuffer1 + ld bc, $0102 + call PrintNumber + ld hl, $c3b5 + ld de, wCountSetBitsResult + ld bc, $0102 + call PrintNumber + callab Function360b1 + ld a, [wc9ef] + ld b, a + ld hl, $c3ef + ld a, $3f + call Predef + +asm_3de5b: + jp WaitBGMap + +DisabledText: + db "ふうじられている!@" + +MoveTypeText: + db "わざタイプ@" + +sub_3de6e: + ld a, [wLinkMode] + and a + jr z, asm_3dea0 + call BackUpTilesToBuffer + ld a, [wFieldMoveSucceeded] + and a + call z, sub_3df8b + call ReloadTilesFromBuffer + ld a, [wOtherPlayerLinkAction] + cp $e + jp z, asm_3df82 + cp $d + jr z, asm_3df04 + cp 4 + jp nc, asm_3df86 + ld [wcac7], a + ld c, a + ld hl, wcddb + ld b, 0 + add hl, bc + ld a, [hl] + jp asm_3df68 + +asm_3dea0: + ld hl, wca44 + bit 4, [hl] + jr z, asm_3dedc + ld a, [wca51] + dec a + ld [wca51], a + jr nz, asm_3dec1 + +asm_3deb0: + ld hl, wca44 + res 4, [hl] + ld a, 1 + ldh [hBattleTurn], a + ld hl, Data3dfdd + call PrintText + jr asm_3dedc + +asm_3dec1: + ld a, [wcad7] + and a + jr z, asm_3deb0 + ld hl, wcde1 + ld a, [wcac7] + ld c, a + ld b, 0 + add hl, bc + ld a, [hl] + and $3f + jr z, asm_3deb0 + ld a, [wcad7] + jp asm_3df68 + +asm_3dedc: + ld a, [wca43] + and $60 + jp nz, asm_3df86 + ld hl, wEnemySubStatus3 + ld a, [hl] + and $12 + jp nz, asm_3df86 + ld hl, wca40 + bit 6, [hl] + jp nz, asm_3df86 + ld a, [wEnemySubStatus3] + and $21 + jp nz, asm_3df86 + ld a, [wPlayerSubStatus3] + bit 5, a + jr asm_3df08 + +asm_3df04: + ld a, $ff + jr asm_3df68 + +asm_3df08: + ld hl, wcde1 + ld bc, 0 + +asm_3df0e: + inc b + ld a, b + cp 5 + jr z, asm_3df26 + ld a, [hli] + and $3f + jr z, asm_3df0e + ld a, [wca50] + swap a + and $f + cp b + jr z, asm_3df0e + inc c + jr asm_3df0e + +asm_3df26: + ld a, c + and a + jr z, asm_3df82 + ld a, [wBattleMode] + dec a + jr z, asm_3df3f + ld a, 1 + ld [wca22], a + callab Function384d4 + jr asm_3df6b + +asm_3df3f: + ld hl, wcddb + call BattleRandom + and 3 + ld c, a + ld b, 0 + add hl, bc + ld a, [wca50] + swap a + and $f + dec a + cp c + jr z, asm_3df3f + ld a, [hl] + and a + jr z, asm_3df3f + ld hl, wcde1 + add hl, bc + ld b, a + ld a, [hl] + and a + jr z, asm_3df3f + ld a, c + ld [wcac7], a + ld a, b + +asm_3df68: + ld [wcac2], a + +asm_3df6b: + ld a, 1 + ldh [hBattleTurn], a + callab Function360b1 + ld a, [wc9e9] + cp $77 + ret z + xor a + ld [wca53], a + ret + +asm_3df82: + ld a, $a5 + jr asm_3df68 + +asm_3df86: + xor a + ld [wca53], a + ret + +sub_3df8b: + ld a, $ff + ld [wOtherPlayerLinkAction], a + ld a, [wFieldMoveSucceeded] + and a + jr nz, asm_3dfa8 + ld a, [wcac1] + cp $a5 + ld b, $e + jr z, asm_3dfae + dec b + inc a + jr z, asm_3dfae + ld a, [wcd40] + jr asm_3dfaf + +asm_3dfa8: + ld a, [wWhichPokemon] + add 4 + ld b, a + +asm_3dfae: + ld a, b + +asm_3dfaf: + ld [wPlayerLinkAction], a + callab PlaceWaitingText + +asm_3dfba: + call LinkTransfer + call DelayFrame + ld a, [wOtherPlayerLinkAction] + inc a + jr z, asm_3dfba + ld b, $a + +asm_3dfc8: + call DelayFrame + call LinkTransfer + dec b + jr nz, asm_3dfc8 + ld b, $a + +asm_3dfd3: + call DelayFrame + call LinkDataReceived + dec b + jr nz, asm_3dfd3 + ret + +Data3dfdd: + text "アンコールじょうたいが とけた!" + +asm_3dff2: + ldh a, [hBattleTurn] + and a + ld hl, wcac2 + ld de, wc9ea + ld a, [wcac1] + jr z, asm_3e009 + ld hl, wcac1 + ld de, wc9f1 + ld a, [wcac2] + +asm_3e009: + cp $44 + ret nz + ld a, 1 + ld [wca3a], a + ld a, [hl] + cp $44 + ret z + ld a, [de] + and a + ret z + inc de + ld a, [de] + and a + jr z, asm_3e023 + cp 1 + jr z, asm_3e023 + xor a + ret + +asm_3e023: + ld hl, wce29 + ld a, [hli] + or [hl] + ret z + ld a, [hl] + add a + ld [hld], a + ld a, [hl] + adc a + ld [hl], a + jr nc, asm_3e035 + ld a, $ff + ld [hli], a + ld [hl], a + +asm_3e035: + xor a + ld [wca3a], a + callab Function351d0 + xor a + ret + +AddPokemonToBox: + ld a, [wLinkMode] + and a + jp nz, LoadEnemyMonFromParty + ld a, [wcdd7] + ld [wcdd9], a + ld [wCurSpecies], a + ld [wMonDexIndex], a + call GetMonHeader + ld a, [wBattleMode] + cp 2 + jr nz, asm_3e06f + ld a, [wWhichPokemon] + ld hl, wd91c + ld bc, $30 + call AddNTimes + ld a, [hl] + jr asm_3e07b + +asm_3e06f: + call BattleRandom + cp $c8 + ld a, 0 + jr c, asm_3e07b + ld a, [wMonHItems] + +asm_3e07b: + ld [wcdda], a + ld a, [wca44] + bit 3, a + ld hl, wcad0 + ld a, [hli] + ld b, [hl] + jr nz, asm_3e09c + ld a, [wBattleMode] + cp 2 + ld a, $98 + ld b, $88 + jr z, asm_3e09c + call BattleRandom + ld b, a + call BattleRandom + +asm_3e09c: + ld hl, wcddf + ld [hli], a + ld [hl], b + ld a, [wCurPartyLevel] + ld [wcde6], a + ld de, wcdeb + ld b, 0 + ld hl, wcdd4 + ld a, $18 + call Predef + ld a, [wBattleMode] + cp 2 + jr z, asm_3e0d2 + ld a, [wca44] + bit 3, a + jr nz, asm_3e0f1 + ld hl, wcde7 + xor a + ld [hli], a + ld [hli], a + ld a, [wcdeb] + ld [hli], a + ld a, [wcdec] + ld [hli], a + jr asm_3e0f1 + +asm_3e0d2: + ld hl, wd93e + ld a, [wWhichPokemon] + ld bc, $30 + call AddNTimes + ld a, [hld] + ld [wcdea], a + ld a, [hld] + ld [wcde9], a + ld a, [wWhichPokemon] + ld [wca36], a + dec hl + ld a, [hl] + ld [wcde7], a + +asm_3e0f1: + ld hl, wMonHType1 + ld de, wcdf7 + ld a, [hli] + ld [de], a + inc de + ld a, [hl] + ld [de], a + ld de, wcddb + ld a, [wBattleMode] + cp 2 + jr nz, asm_3e11a + ld hl, wd91d + ld a, [wWhichPokemon] + ld bc, $30 + call AddNTimes + ld bc, 4 + call CopyBytes + jr asm_3e129 + +asm_3e11a: + xor a + ld h, d + ld l, e + ld [hli], a + ld [hli], a + ld [hli], a + ld [hl], a + ld [wHPBarMaxHP], a + ld a, $2a + call Predef + +asm_3e129: + ld hl, wcddb + ld de, wcde1 + ld a, $f + call Predef + ld hl, wMonHBaseStats + ld de, wcdf9 + ld b, 5 + +asm_3e13c: + ld a, [hli] + ld [de], a + inc de + dec b + jr nz, asm_3e13c + ld a, [wMonHCatchRate] + ld [de], a + inc de + ld a, [wMonHBaseEXP] + ld [de], a + ld a, [wcdd7] + ld [wCountSetBitsResult], a + call GetPokemonName + ld hl, wStringBuffer1 + ld de, wBattleMonNickname + ld bc, 6 + call CopyBytes + ld a, [wcdd7] + dec a + ld c, a + ld b, 1 + ld hl, wPokedexOwnedEnd + predef SmallFarFlagAction + ld hl, wcded + ld de, wca9e + ld bc, $a + call CopyBytes + ld a, 7 + ld b, 8 + ld hl, wcab1 + +asm_3e182: + ld [hli], a + dec b + jr nz, asm_3e182 + ld a, 1 + ldh [hBattleTurn], a + callab Function95cc + ret + +asm_3e193: + push bc + ld a, [wca0f] + ld b, a + ld a, [wcde6] + ld [wca0f], a + ld a, b + ld [wcde6], a + pop bc + ret + +Function3e1a4: + call Function3e1aa + jp asm_3e1d1 + +Function3e1aa: + ldh a, [hBattleTurn] + and a + ld a, [wca3b] + ld hl, wca17 + jr z, asm_3e1bb + ld a, [wca40] + ld hl, wcdee + +asm_3e1bb: + ld c, 4 + ld b, a + +asm_3e1be: + srl b + call c, sub_3e1c9 + inc hl + inc hl + dec c + ret z + jr asm_3e1be + +sub_3e1c9: + ld a, [hl] + add a + ld [hld], a + ld a, [hl] + rl a + ld [hli], a + ret + +asm_3e1d1: + ldh a, [hBattleTurn] + and a + ld a, [wca3c] + ld hl, wca16 + jr z, asm_3e1e2 + ld a, [wca41] + ld hl, wcded + +asm_3e1e2: + ld c, 4 + ld b, a + +asm_3e1e5: + srl b + call c, sub_3e1f0 + inc hl + inc hl + dec c + ret z + jr asm_3e1e5 + +sub_3e1f0: + ld a, [hl] + srl a + ld [hli], a + ld d, a + ld a, [hl] + rr a + ld [hl], a + or d + jr nz, asm_3e1ff + ld a, 1 + ld [hl], a + +asm_3e1ff: + dec hl + ret + +sub_3e201: + xor a + ld [wcdd7], a + ld b, 1 + call GetSGBLayout +; Should be a call instead + callab sub_3f003 + ld hl, $c2b3 + ld c, 0 + +asm_3e217: + inc c + ld a, c + cp 7 + ret z + ld d, 0 + push bc + push hl + +asm_3e220: + call sub_3e235 + inc hl + ld a, 7 + add d + ld d, a + dec c + jr nz, asm_3e220 + ld c, 4 + call DelayFrames + pop hl + pop bc + dec hl + jr asm_3e217 + +sub_3e235: + push hl + push de + push bc + ld e, 7 + +asm_3e23a: + ld [hl], d + ld bc, $14 + add hl, bc + inc d + dec e + jr nz, asm_3e23a + pop bc + pop de + pop hl + ret + +sub_3e247: + ld a, 1 + jr asm_3e24c + +sub_3e24b: + xor a + +asm_3e24c: + ldh [hBattleTurn], a + call sub_3e254 + jp asm_3e291 + +sub_3e254: + ldh a, [hBattleTurn] + and a + jr z, asm_3e275 + ld a, [wca10] + and $40 + ret z + ld hl, wca1b + ld a, [hld] + ld b, a + ld a, [hl] + srl a + rr b + srl a + rr b + ld [hli], a + or b + jr nz, asm_3e273 + ld b, 1 + +asm_3e273: + ld [hl], b + ret + +asm_3e275: + ld a, [wcde7] + and $40 + ret z + ld hl, wcdf2 + ld a, [hld] + ld b, a + ld a, [hl] + srl a + rr b + srl a + rr b + ld [hli], a + or b + jr nz, asm_3e28f + ld b, 1 + +asm_3e28f: + ld [hl], b + ret + +asm_3e291: + ldh a, [hBattleTurn] + and a + jr z, asm_3e2ae + ld a, [wca10] + and $10 + ret z + ld hl, wca17 + ld a, [hld] + ld b, a + ld a, [hl] + srl a + rr b + ld [hli], a + or b + jr nz, asm_3e2ac + ld b, 1 + +asm_3e2ac: + ld [hl], b + ret + +asm_3e2ae: + ld a, [wcde7] + and $10 + ret z + ld hl, wcdee + ld a, [hld] + ld b, a + ld a, [hl] + srl a + rr b + ld [hli], a + or b + jr nz, asm_3e2c4 + ld b, 1 + +asm_3e2c4: + ld [hl], b + ret + +sub_3e2c6: + ld c, 0 + +asm_3e2c8: + call sub_3e2d2 + inc c + ld a, c + cp 5 + jr nz, asm_3e2c8 + ret + +sub_3e2d2: + push bc + push bc + ld a, [wCountSetBitsResult] + and a + ld a, c + ld hl, wca16 + ld de, wca93 + ld bc, wcaa9 + jr z, asm_3e2ed + ld hl, wcded + ld de, wca9e + ld bc, wcab1 + +asm_3e2ed: + add c + ld c, a + jr nc, asm_3e2f2 + inc b + +asm_3e2f2: + ld a, [bc] + pop bc + ld b, a + push bc + sla c + ld b, 0 + add hl, bc + ld a, c + add e + ld e, a + jr nc, asm_3e301 + inc d + +asm_3e301: + pop bc + push hl + ld hl, Data3e346 + dec b + sla b + ld c, b + ld b, 0 + add hl, bc + xor a + ldh [hQuotient], a + ld a, [de] + ldh [hMultiplicand + 1], a + inc de + ld a, [de] + ldh [hMultiplicand + 2], a + ld a, [hli] + ldh [hPrintNumDivisor], a + call Multiply + ld a, [hl] + ldh [hPrintNumDivisor], a + ld b, 4 + call Divide + pop hl + ldh a, [hMultiplicand + 2] + sub $e7 + ldh a, [hMultiplicand + 1] + sbc 3 + jp c, asm_3e339 + ld a, 3 + ldh [hMultiplicand + 1], a + ld a, $e7 + ldh [hMultiplicand + 2], a + +asm_3e339: + ldh a, [hMultiplicand + 1] + ld [hli], a + ld b, a + ldh a, [hMultiplicand + 2] + ld [hl], a + or b + jr nz, asm_3e344 + inc [hl] + +asm_3e344: + pop bc + ret + +Data3e346: + dw $6419 + dw $641C + dw $6421 + dw $6428 + dw $6432 + dw $6442 + dw $0101 + dw $0A0F + dw $0102 + dw $0A19 + dw $0103 + dw $0A23 + dw $0104 + +sub_3e360: + ld a, [wLinkMode] + cp 3 + ret z + ld a, [wBadges] + ld b, a + ld hl, wca16 + ld c, 4 + +asm_3e36f: + srl b + call c, sub_3e37c + inc hl + inc hl + srl b + dec c + jr nz, asm_3e36f + ret + +sub_3e37c: + ld a, [hli] + ld d, a + ld e, [hl] + srl d + rr e + srl d + rr e + srl d + rr e + ld a, [hl] + add e + ld [hld], a + ld a, [hl] + adc d + ld [hli], a + ld a, [hld] + sub $e7 + ld a, [hl] + sbc 3 + ret c + ld a, 3 + ld [hli], a + ld a, $e7 + ld [hld], a + ret + +Call_LoadBattleGraphics: + jpab LoadBattleGraphics + +Function3e3a7: + jpab Functionf80d6 + + ld de, $4c22 ; pointing to code? + ld hl, $96c0 + ld bc, $3e04 + call Get1bpp + + ld de, $4c42 ; pointing to code? + ld hl, $9730 + ld bc, $3e06 + call Get1bpp + + ld de, $4c72 ; pointing to code? + ld hl, $9550 + ld bc, $3e08 + jp Get2bpp + +PrintEmptyString: + ld hl, .EmptyString + jp PrintText + +.EmptyString: + db "@" + +SECTION "engine/dumps/bank0f.asm@PlayMoveAnimation", ROMX +PlayMoveAnimation: + ld a, e + ld [wccc0], a + ld a, d + ld [wccc1], a + +asm_3e419: + call WaitBGMap + +asm_3e41c: + ld a, $51 + jp Predef + +sub_3e421: + ld a, [wLinkMode] + and a + ret nz + +asm_3e426: + call sub_3e64b + xor a + ld [wWhichPokemon], a + ld bc, wPartyMon1Species + +asm_3e430: + ld hl, $22 + add hl, bc + ld a, [hli] + or [hl] + jp z, asm_3e613 + push bc + ld hl, wca37 + ld a, [wWhichPokemon] + ld c, a + +asm_3e441: + ld b, 2 + ld d, 0 + predef SmallFarFlagAction + ld a, c + and a + pop bc + jp z, asm_3e613 + ld hl, $c + add hl, bc + ld d, h + ld e, l + ld hl, wcdf9 + push bc + ld c, 5 + +asm_3e45c: + ld a, [hli] + ld b, a + ld a, [de] + add b + ld [de], a + jr nc, asm_3e471 + dec de + ld a, [de] + inc a + jr z, asm_3e46c + ld [de], a + inc de + jr asm_3e471 + +asm_3e46c: + ld a, $ff + ld [de], a + inc de + ld [de], a + +asm_3e471: + dec c + jr z, asm_3e478 + inc de + inc de + jr asm_3e45c + +asm_3e478: + xor a + ldh [hQuotient], a + ldh [hMultiplicand + 1], a + ld a, [wcdff] + ldh [hMultiplicand + 2], a + ld a, [wcde6] + ldh [hPrintNumDivisor], a + call Multiply + ld a, 7 + ldh [hPrintNumDivisor], a + ld b, 4 + call Divide + pop bc + ld hl, 6 + add hl, bc + ld a, [wce73] + cp [hl] + jr nz, asm_3e4a7 + inc hl + ld a, [wce74] + cp [hl] + ld a, 0 + jr z, asm_3e4ac + +asm_3e4a7: + call sub_3e67e + ld a, 1 + +asm_3e4ac: + ld [wcd33], a + ld a, [wBattleMode] + dec a + call nz, sub_3e67e + ld hl, $a + add hl, bc + ld d, [hl] + ldh a, [hMultiplicand + 2] + ld [wcd32], a + add d + ld [hld], a + ld d, [hl] + ldh a, [hMultiplicand + 1] + ld [wStringBuffer2], a + adc d + ld [hl], a + jr nc, asm_3e4ce + dec hl + inc [hl] + +asm_3e4ce: + ld a, [wWhichPokemon] + ld e, a + ld d, 0 + ld hl, wPartySpecies + add hl, de + ld a, [hl] + ld [wCurSpecies], a + call GetMonHeader + push bc + ld d, $64 + callab Function50cd1 + pop bc + ld hl, $a + add hl, bc + push bc + ldh a, [hQuotient] + ld b, a + ldh a, [hMultiplicand + 1] + ld c, a + ldh a, [hMultiplicand + 2] + ld d, a + ld a, [hld] + sub d + ld a, [hld] + sbc c + ld a, [hl] + sbc b + jr c, asm_3e507 + ld a, b + ld [hli], a + ld a, c + ld [hli], a + ld a, d + ld [hld], a + +asm_3e507: + ld a, [wWhichPokemon] + ld hl, wPartyMonNicknames + call GetNick + ld hl, BoostedExpPointsText + call PrintText + xor a + ld [wMonType], a + predef Function50000 + callba Function50caa + pop bc + ld hl, $1f + add hl, bc + ld a, [hl] + cp d + jp z, asm_3e613 + ld a, [wCurPartyLevel] + push af + ld a, d + ld [wCurPartyLevel], a + ld [hl], a + ld hl, 0 + add hl, bc + ld a, [hl] + ld [wCurSpecies], a + ld [wCountSetBitsResult], a + call GetMonHeader + ld hl, $25 + add hl, bc + ld a, [hld] + ld e, a + ld d, [hl] + push de + ld hl, $24 + add hl, bc + ld d, h + ld e, l + ld hl, $a + add hl, bc + push bc + ld b, 1 + ld a, $18 + call Predef + pop bc + pop de + ld hl, $25 + add hl, bc + ld a, [hld] + sub e + ld e, a + ld a, [hl] + sbc d + ld d, a + dec hl + ld a, [hl] + add e + ld [hld], a + ld a, [hl] + adc d + ld [hl], a + ld a, [wcd41] + ld d, a + ld a, [wWhichPokemon] + cp d + jr nz, asm_3e5d3 + ld de, wca12 + ld a, [hli] + ld [de], a + inc de + ld a, [hli] + ld [de], a + ld de, wca14 + push bc + ld bc, $c + call CopyBytes + pop bc + ld hl, $1f + add hl, bc + ld a, [hl] + ld [wca0f], a + ld a, [wca3f] + bit 3, a + jr nz, asm_3e5ae + ld hl, $26 + add hl, bc + ld de, wca93 + ld bc, $a + call CopyBytes + +asm_3e5ae: + xor a + ld [wCountSetBitsResult], a + call sub_3e2c6 +; these three calls should be regular calls + callab sub_3e247 + callab sub_3e360 + callab Function3d5ce + call PrintEmptyString + call BackUpTilesToBuffer + +asm_3e5d3: + ld hl, GrewToLevelText + call PrintText + xor a + ld [wMonType], a + predef Function50000 + ld d, 1 + callab Function50628 + call TextboxWaitPressAorB_BlinkCursor + call ReloadTilesFromBuffer + xor a + ld [wMonType], a + ld a, [wCurSpecies] + ld [wCountSetBitsResult], a + ld a, $29 + call Predef + ld hl, wcdc2 + ld a, [wWhichPokemon] + ld c, a + ld b, 1 + predef SmallFarFlagAction + pop af + ld [wCurPartyLevel], a + +asm_3e613: + ld a, [wPartyCount] + ld b, a + ld a, [wWhichPokemon] + inc a + cp b + jr z, asm_3e62f + ld [wWhichPokemon], a + ld bc, $30 + ld hl, wPartyMon1Species + call AddNTimes + ld b, h + ld c, l + jp asm_3e430 + +asm_3e62f: + ld hl, wca37 + xor a + ld [hl], a + ld a, [wcd41] + ld c, a + ld b, 1 + push bc + predef SmallFarFlagAction + ld hl, wcada + xor a + ld [hl], a + pop bc + ld a, $c + jp Predef + +sub_3e64b: + ld a, [wca37] + ld b, a + xor a + ld c, 8 + ld d, 0 + +asm_3e654: + xor a + srl b + adc d + ld d, a + dec c + jr nz, asm_3e654 + cp 2 + ret c + ld [wCountSetBitsResult], a + ld hl, wcdf9 + ld c, 7 + +asm_3e667: + xor a + ldh [hProduct], a + ld a, [hl] + ldh [hQuotient], a + ld a, [wCountSetBitsResult] + ldh [hPrintNumDivisor], a + ld b, 2 + call Divide + ldh a, [hMultiplicand + 2] + ld [hli], a + dec c + jr nz, asm_3e667 + ret + +sub_3e67e: + push bc + ldh a, [hMultiplicand + 1] + ld b, a + ldh a, [hMultiplicand + 2] + ld c, a + srl b + rr c + add c + ldh [hMultiplicand + 2], a + ldh a, [hMultiplicand + 1] + adc b + ldh [hMultiplicand + 1], a + pop bc + ret + +BoostedExpPointsText: + text_from_ram wStringBuffer1 + text "は@" + start_asm + ld a, [wHPBarMaxHP] + ld hl, .BoostedExpPoints1Text + and a + ret nz + ld hl, .BoostedExpPoints3Text + ld a, [wcd33] + and a + ret z + ld hl, .BoostedExpPoints2Text + ret + +.BoostedExpPoints1Text: + text " がくしゅうそうちで@" + start_asm + ld hl, .BoostedExpPoints3Text + ret + +.BoostedExpPoints2Text: + text " おおめに@" + +.BoostedExpPoints3Text: + text "@" + deciram wStringBuffer2, 2, 4 + text " けいけんちを もらった!" + +GrewToLevelText: + text_from_ram wStringBuffer1 + text "はレべル@" + deciram wCurPartyLevel, 1, 3 + text " に あがった!@" + db "ジ@" + +PrintSendOutMonMessage: + ld a, [wLinkMode] + and a + jr z, .not_link + ld hl, GoText + ld a, [wce36] + and a + jr nz, .print_text + +.not_link + ld hl, wcde9 + ld a, [hli] + or [hl] + ld hl, GoText + jr z, .print_text + xor a + ldh [hQuotient], a +; enemy mon current HP * 25 + ld hl, wcde9 + ld a, [hli] + ld [wcac8], a + ldh [hMultiplicand + 1], a + ld a, [hl] + ld [wcac9], a + ldh [hMultiplicand + 2], a + ld a, 25 + ldh [hPrintNumDivisor], a + call Multiply + ld hl, wcdeb + ld a, [hli] + ld b, [hl] + srl a + rr b + srl a + rr b + ld a, b +; enemy mon max HP divided by 4 + ld b, 4 + ldh [hPrintNumDivisor], a + call Divide + +; (enemy's current HP * 25) / (enemy's max HP / 4) +; approximates current % of max HP + ldh a, [hMultiplicand + 2] +; >= 70% + ld hl, GoText + cp 70 + jr nc, .print_text +; 40% <= HP <= 69% + ld hl, DoItText + cp 40 + jr nc, .print_text +; 10% <= HP <= 39% + ld hl, GetmText + cp 10 + jr nc, .print_text +; < 10% + ld hl, EnemysWeakText +.print_text + jp PrintText + +GoText: + text "ゆけっ! @" + start_asm + jr PrintPlayerMon1Text + +DoItText: + text "いってこい! @" + start_asm + jr PrintPlayerMon1Text + +GetmText: + text "がんばれ! @" + start_asm + jr PrintPlayerMon1Text + +EnemysWeakText: + text "あいてが よわっている!" + line "チャンスだ! @" + start_asm + +PrintPlayerMon1Text: + ld hl, .Text + ret +.Text: + text_from_ram wEnemyMonNickname + text "!" + +RetreatMon: + ld hl, PlayerMon2Text + jp PrintText + +PlayerMon2Text: + text_from_ram wEnemyMonNickname + text " @" + start_asm + push de + push bc + ld hl, wcdea + ld de, wcac9 + ld b, [hl] + dec hl + ld a, [de] + sub b + ldh [hMultiplicand + 2], a + dec de + ld b, [hl] + ld a, [de] + sbc b + ldh [hMultiplicand + 1], a + ld a, 25 + ldh [hPrintNumDivisor], a + call Multiply + ld hl, wcdeb + ld a, [hli] + ld b, [hl] + srl a + rr b + srl a + rr b + ld a, b + ld b, 4 + ldh [hPrintNumDivisor], a + call Divide + pop bc + pop de + ldh a, [hMultiplicand + 2] +; HP stays the same + ld hl, EnoughText + and a + ret z +; HP went down 1% - 29% + ld hl, ComeBackText + cp 30 + ret c +; HP went down 30% - 69% + ld hl, OKExclamationText + cp 70 + ret c +; HP went down 70% or more + ld hl, GoodText + ret + +EnoughText: + text "もういい!@" + start_asm + jr PrintComeBackText + +OKExclamationText: + text "いいぞ!@" + start_asm + jr PrintComeBackText + +GoodText: + text "よくやった!@" + start_asm + jr PrintComeBackText + +PrintComeBackText: + ld hl, ComeBackText + ret + +ComeBackText: + text "" + line "もどれ!" + done + +sub_3e81b: + ld hl, wcace + ld a, [hl] + and a + jr z, asm_3e828 + dec [hl] + ld hl, Data3e84b + jr asm_3e843 + +asm_3e828: + dec hl + ld a, [hl] + and a + ret z + dec [hl] + ld hl, Data3e861 + jr nz, asm_3e843 + push hl + ld a, [wcdd9] + ld [wCurSpecies], a + call GetMonHeader + ld a, [wMonHCatchRate] + ld [wcdfe], a + pop hl + +asm_3e843: + push hl + call ReloadTilesFromBuffer + pop hl + jp PrintText + +Data3e84b: + text "やせいの@" + text_from_ram wBattleMonNickname + text "は" + line "エサを たべてる!" + prompt + +Data3e861: + text "やせいの@" + text_from_ram wBattleMonNickname + text "は" + line "おこってる!" + prompt + +Function3e874: + push hl + push de + ld d, b + push de + callab Function50cd1 + pop de + ld hl, hQuotient + ld a, [hli] + push af + ld a, [hli] + push af + ld a, [hl] + push af + inc d + callab Function50cd1 + ld hl, hMultiplicand + 2 + ld a, [hl] + ldh [hPrintNumTemp], a + pop bc + sub b + ld [hld], a + ld a, [hl] + ldh [hMathBuffer + 1], a + pop bc + sbc b + ld [hld], a + ld a, [hl] + ldh [hMathBuffer], a + pop bc + sbc b + ld [hl], a + pop de + ld hl, hMultiplicand + 1 + ld a, [hli] + push af + ld a, [hl] + push af + ld a, [de] + dec de + ld c, a + ldh a, [hPrintNumTemp] + sub c + ld [hld], a + ld a, [de] + dec de + ld b, a + ldh a, [hMathBuffer + 1] + sbc b + ld [hld], a + ld a, [de] + ld c, a + ldh a, [hMathBuffer] + sbc c + ld [hld], a + xor a + ld [hl], a + ld a, $40 + ldh [hPrintNumDivisor], a + call Multiply + pop af + ld c, a + pop af + ld b, a + +asm_3e8d1: + ld a, b + and a + jr z, asm_3e8e9 + srl b + rr c + ld hl, hProduct + srl [hl] + inc hl + rr [hl] + inc hl + rr [hl] + inc hl + rr [hl] + jr asm_3e8d1 + +asm_3e8e9: + ld a, c + ldh [hPrintNumDivisor], a + ld b, 4 + call Divide + pop hl + ld bc, 7 + add hl, bc + ldh a, [hMultiplicand + 2] + ld b, a + ld a, $40 + sub b + ld b, a + ld c, 8 + +asm_3e8ff: + ld a, b + sub 8 + jr c, asm_3e90d + ld b, a + ld a, $6a + ld [hld], a + dec c + jr z, asm_3e91d + jr asm_3e8ff + +asm_3e90d: + add 8 + jr z, asm_3e915 + add $54 + jr asm_3e917 + +asm_3e915: + ld a, $62 + +asm_3e917: + ld [hld], a + ld a, $62 + dec c + jr nz, asm_3e915 + +asm_3e91d: + ret + +Function3e91e: + ld a, [wca3e] + bit 4, a + ld hl, Functioncc44f + jr nz, asm_3e954 + ld a, [wcadc] + and a + ld hl, Functioncc4d4 + jr nz, asm_3e954 + ld a, [wMonDexIndex] + push af + ld a, [wca02] + ld [wCurSpecies], a + ld [wMonDexIndex], a + call GetMonHeader + ld hl, $14 + call UncompressMonSprite + ld hl, $9310 + ld a, $33 + call Predef + pop af + ld [wMonDexIndex], a + ret + +asm_3e954: + ldh a, [hBattleTurn] + push af + xor a + ldh [hBattleTurn], a + ld a, BANK(Functioncc44f) + call FarCall_hl + pop af + ldh [hBattleTurn], a + ret + +Function3e963: + ld a, [wca43] + bit 4, a + ld hl, Functioncc44f + jr nz, asm_3e999 + ld a, [wcad8] + and a + ld hl, Functioncc4d4 + jr nz, asm_3e999 + ld a, [wMonDexIndex] + push af + ld a, [wcdd9] + ld [wCurSpecies], a + ld [wMonDexIndex], a + call GetMonHeader + ld hl, wcddf + predef Function50ed9 + ld de, vFrontPic + call LoadMonFrontSprite + pop af + ld [wMonDexIndex], a + ret + +asm_3e999: + ldh a, [hBattleTurn] + push af + ld a, 1 + ldh [hBattleTurn], a + ld a, BANK(Functioncc44f) + call FarCall_hl + pop af + ldh [hBattleTurn], a + ret + +_LoadWildMons: + xor a + ld hl, wWildMons + ld bc, $29 + call ByteFill + ld a, [wMapGroup] + ld d, a + ld a, [wMapId] + ld e, a + ld bc, $29 + ld hl, GrassWildMons +.find + ld a, [hl] + cp -1 + ret z + cp d + jr nz, .got_map_group + inc hl + ld a, [hl] + dec hl + cp e + jr z, .got_map +.got_map_group + add hl, bc + jr .find +.got_map + inc hl + inc hl + ld de, wWildMons + ld bc, $27 + jp CopyBytes + +Function3e9dc: + ld hl, $c2a0 + ld bc, $0168 + xor a + call ByteFill + ld hl, GrassWildMons + ld de, $c2a0 + +asm_3e9ec: + ld a, [hl] + cp $ff + jr z, asm_3ea0d + push hl + ld b, a + inc hl + ld c, [hl] + call sub_3ea0e + jr nc, asm_3ea06 + push de + call GetWorldMapLocation + call sub_3ea27 + pop de + jr c, asm_3ea06 + ld [de], a + inc de + +asm_3ea06: + pop hl + ld bc, $29 + add hl, bc + jr asm_3e9ec + +asm_3ea0d: + ret + +sub_3ea0e: + inc hl + inc hl + inc hl + inc hl + inc hl + ld a, $12 + +asm_3ea15: + push af + ld a, [wCountSetBitsResult] + cp [hl] + jr z, asm_3ea24 + inc hl + inc hl + pop af + dec a + jr nz, asm_3ea15 + and a + ret + +asm_3ea24: + pop af + scf + ret + +sub_3ea27: + ld c, a + ld hl, $c2a0 + ld de, $0168 + +asm_3ea2e: + ld a, [hli] + cp c + jr z, asm_3ea3a + dec de + ld a, e + or d + jr nz, asm_3ea2e + ld a, c + and a + ret + +asm_3ea3a: + scf + ret + +SECTION "engine/dumps/bank0f.asm@Function3ee3e", ROMX +Function3ee3e: + ld a, [wce2d] + and a + jr z, asm_3ee4b + dec a + jp z, asm_3eeba + ld [wce2d], a + +asm_3ee4b: + call sub_3eec8 + jr nc, asm_3eebd + call sub_3ef0e + ld c, a + ld b, 0 + ld hl, wWildMons + add hl, bc + ld a, [hl] + ld b, a + call Random + ldh a, [hRandomAdd] + cp b + jr nc, asm_3eebd + call Random + ld b, a + ld hl, Data3eedf + call sub_3ef0e + cp 1 + ld bc, 0 + jr c, asm_3ee7d + ld bc, 6 + jr z, asm_3ee7d + ld bc, $e + +asm_3ee7d: + add hl, bc + +asm_3ee7e: + call Random + cp $64 + jr nc, asm_3ee7e + ld b, a + ld c, 0 + +asm_3ee88: + ld a, [hli] + add c + ld c, a + cp b + jr nc, asm_3ee91 + inc hl + jr asm_3ee88 + +asm_3ee91: + ld c, [hl] + ld b, 0 + ld hl, wd91e + add hl, bc + ld a, [hli] + ld [wCurPartyLevel], a + ld a, [hl] + call sub_3ef03 + jr c, asm_3eebd + ld [wMonDexIndex], a + ld [wcdd7], a + ld a, [wce2d] + and a + jr z, asm_3eec1 + ld a, [wPartyMon1Level] + ld b, a + ld a, [wCurPartyLevel] + cp b + jr c, asm_3eebd + jr asm_3eec1 + +asm_3eeba: + ld [wce2d], a + +asm_3eebd: + ld a, 1 + and a + ret + +asm_3eec1: + ld a, 1 + ld [wBattleMode], a + xor a + ret + +sub_3eec8: + ld a, [wPlayerTile] + ld hl, Data3eed5 + ld de, 1 + call FindItemInTable + ret + +Data3eed5: + db $8 + db $18 + db $28 + db $29 + db $48 + db $49 + db $4a + db $4b + db $4c + db -1 + +Data3eedf: + db $1 + db $0 + db $4 + db $2 + db $5 + db $4 + db $1 + db $6 + db $4 + db $8 + db $f + db $a + db $14 + db $c + db $5 + db $e + db $a + db $10 + db $14 + db $12 + db $f + db $14 + db $5 + db $16 + db $5 + db $18 + db $14 + db $1a + db $a + db $1c + db $5 + db $1e + db $4 + db $20 + db $1 + db $22 + +sub_3ef03: + and a + jr z, .return + cp $fc + jr nc, .return + and a + ret + +.return + scf + ret + +sub_3ef0e: + ld a, [wTimeOfDay] + inc a + and 3 + cp 3 + ret nz + dec a + ret + +Function3ef19: + ld a, [wce02] + and a + jr nz, InitBattleCommon + ld a, [wce01] + and a + jr z, InitBattleCommon + ld [wMonDexIndex], a + ld [wcdd7], a + +InitBattleCommon: + ld a, [wTimeOfDayPal] + push af + ld hl, wTextBoxFlags + ld a, [hl] + push af + res 1, [hl] + ldh a, [hMapAnims] + ld [wce26], a + call PlayBattleMusic + call ShowLinkBattleParticipants + call InitBattleVariables + ld a, [wce02] + and a + jr nz, .asm_3ef4f + call sub_3efdb + jr _InitBattleCommon +.asm_3ef4f + call sub_3ef9a + +_InitBattleCommon: + ld b, 0 + call GetSGBLayout + ld hl, wVramState + res 0, [hl] + call InitBattleDisplay + call BattleStartMessage + xor a + ldh [hBGMapMode], a + call PrintEmptyString + ld hl, $c335 + ld bc, $050a + call ClearBox + ld hl, $c2a1 + ld bc, $040a + call ClearBox + call ClearSprites + ld a, [wBattleMode] + cp 1 + call z, Function3d67c + call StartBattle + call sub_3f13e + pop af + ld [wTextBoxFlags], a + pop af + ld [wTimeOfDayPal], a + ld a, [wce26] + ldh [hMapAnims], a + scf + ret + +sub_3ef9a: + ld [wca22], a + callab LoadTrainerClass + callab Function38f45 + ld a, [wca22] + cp 9 + jr nz, asm_3efb8 + xor a + ld [wd91c], a + +asm_3efb8: + call sub_3f003 + xor a + ld [wcdd7], a + ldh [hGraphicStartTile], a + dec a + ld [wcac4], a + ld hl, $c2ac + ld bc, $0707 + predef PlaceGraphic + ld a, $ff + ld [wca36], a + ld a, 2 + ld [wBattleMode], a + ret + +sub_3efdb: + ld a, 1 + ld [wBattleMode], a + call AddPokemonToBox + ld hl, wcddf + predef Function50ed9 + ld de, vFrontPic + call LoadMonFrontSprite + xor a + ld [wca22], a + ldh [hGraphicStartTile], a + ld hl, $c2ac + ld bc, $0707 + predef PlaceGraphic + ret + +sub_3f003: + ld a, [wca23] + ld e, a + ld a, [wca24] + ld d, a + ld a, $12 + call UncompressSpriteFromDE + ld de, vFrontPic + ld a, $77 + ld c, a + jp LoadUncompressedSpriteData + +PlaceGraphic: + ld de, $14 + ld a, [wSpriteFlipped] + and a + jr nz, asm_3f033 + ldh a, [hGraphicStartTile] + +asm_3f024: + push bc + push hl + +asm_3f026: + ld [hl], a + add hl, de + inc a + dec c + jr nz, asm_3f026 + pop hl + inc hl + pop bc + dec b + jr nz, asm_3f024 + ret + +asm_3f033: + push bc + ld b, 0 + dec c + add hl, bc + pop bc + ldh a, [hGraphicStartTile] + +asm_3f03b: + push bc + push hl + +asm_3f03d: + ld [hl], a + add hl, de + inc a + dec c + jr nz, asm_3f03d + pop hl + dec hl + pop bc + dec b + jr nz, asm_3f03b + ret + +Function3f04a: + ld a, [wcdd8] + ld [wMonDexIndex], a + ld hl, $c305 + ld b, 7 + ld c, 8 + call ClearBox + ld hl, $14 + call UncompressMonSprite + ld hl, $9310 + ld a, $33 + jp Predef + +Function3f068: + ld de, $a203 + ld hl, $a187 + call sub_3f0a5 + call sub_3f07d + ld de, $a38b + ld hl, $a30f + call sub_3f0a5 + +sub_3f07d: + ld b, 3 +asm_3f07f: + ld c, $1c +asm_3f081: + push bc + ld a, [de] + ld bc, $ffc9 + call sub_3f0bf + ld a, [de] + dec de + swap a + ld bc, $37 + call sub_3f0bf + pop bc + dec c + jr nz, asm_3f081 + dec de + dec de + dec de + dec de + ld a, b + ld bc, $ffc8 + add hl, bc + ld b, a + dec b + jr nz, asm_3f07f + ret + +sub_3f0a5: + ld a, $1c + ldh [hTextBoxCursorBlinkInterval], a + ld bc, $ffff + +asm_3f0ac: + ld a, [de] + dec de + swap a + call sub_3f0bf + ldh a, [hTextBoxCursorBlinkInterval] + dec a + ldh [hTextBoxCursorBlinkInterval], a + jr nz, asm_3f0ac + dec de + dec de + dec de + dec de + ret + +sub_3f0bf: + push hl + and $f + ld hl, Data3f0d0 + add l + ld l, a + jr nc, asm_3f0ca + inc h + +asm_3f0ca: + ld a, [hl] + pop hl + ld [hld], a + ld [hl], a + add hl, bc + ret + +Data3f0d0: + db $0 + db $3 + db $c + db $f + db $30 + db $33 + db $3c + db $3f + db $c0 + db $c3 + db $cc + db $cf + db $f0 + db $f3 + db $fc + db $ff + +InitBattleVariables: + xor a + ld [wFieldMoveSucceeded], a + ld [wcd5d], a + ld hl, wcd3c + ld [hli], a + ld [hli], a + ld [hli], a + ld [hl], a + ld [wMenuScrollPosition], a + ld [wca39], a + ld [wca02], a + ld [wca37], a + ld [wcd41], a + ld [wce06], a + ld [wTimeOfDayPal], a + ld [wcaba], a + ld hl, wccd1 + ld [hli], a + ld [hl], a + ld hl, wca08 + ld [hli], a + ld [hl], a + ld hl, wcddf + ld [hli], a + ld [hl], a + ld hl, wc9e8 + ld bc, $012c + xor a + call ByteFill + call ClearWindowData + ld hl, hBGMapAddress + xor a + ld [hli], a + ld [hl], HIGH(vBGMap0) + ld a, $a3 + ldh [rLCDC], a + ld a, [wMapId] + cp $d9 ; SAFARI_ZONE_EAST + jr c, .return + cp $dd ; SAFARI_ZONE_CENTER_REST_HOUSE + jr nc, .return + ld a, 2 + ld [wBattleType], a +.return + ret + +sub_3f13e: + call IsLinkBattle + jr nz, asm_3f148 + call sub_3f1f3 + jr asm_3f151 + +asm_3f148: + ld a, [wcd5d] + and a + jr nz, asm_3f15a + call sub_3f19e + +asm_3f151: + xor a + ld [wcab9], a + ld a, $2b + call Predef + +asm_3f15a: + xor a + ld [wccc4], a + ld [wBattleMode], a + ld [wBattleType], a + ld [wca3a], a + ld [wce01], a + ld [wce02], a + ld [wce38], a + ld [wce39], a + ld [wce06], a + ld hl, wcd3c + ld [hli], a + ld [hli], a + ld [hli], a + ld [hl], a + ld [wMenuScrollPosition], a + ld hl, wca3b + ld b, $18 +.clear + ld [hli], a + dec b + jr nz, .clear + ld hl, wd4a7 + set 0, [hl] + call WaitSFX + ld a, $e3 + ldh [rLCDC], a + ld hl, wd14f + res 7, [hl] + call ClearPalettes + ret + +sub_3f19e: + ld hl, wcaca + ld a, [hli] + or [hl] + inc hl + or [hl] + ret z + ld a, [wca03] + ld b, a + callab Function37e3d + ld a, b + cp $4c + jr nz, AddBattleMoneyToAccount + ld hl, wcacc + sla [hl] + dec hl + rl [hl] + dec hl + rl [hl] + jr nc, AddBattleMoneyToAccount + ld a, $ff + ld [hli], a + ld [hli], a + ld [hl], a + +AddBattleMoneyToAccount: + ld hl, wcacc + ld de, wd15f + ld c, 3 + and a +.loop + ld a, [de] + adc [hl] + ld [de], a + dec de + dec hl + dec c + jr nz, .loop + ld hl, GotMoneyForWinningText + call PrintText + ret + +GotMoneyForWinningText: + text "は @" + deciram wcaca, 3, 6 + text "円" + line "ひろった!" + prompt + +sub_3f1f3: + ld a, [wca36] + ld hl, wd93b + ld bc, $30 + call AddNTimes + ld a, [wcde7] + ld [hl], a + call ClearTileMap + call sub_3f60c + ld a, [wcd5d] + cp 1 + ld de, WonAgainstText + jr c, .print_text + ld de, LostAgainstText + jr z, .print_text + ld de, TiedAgainstText + +.print_text + ld hl, $c346 + call PlaceString + ld c, $c8 + call DelayFrames + ret + +WonAgainstText: + db "あなたの かち@" + +LostAgainstText: + db "あなたの まけ@" + +TiedAgainstText: + db "  ひきわけ@" + +PlayBattleMusic: + push hl + push de + push bc + xor a + ld [wMusicFade], a + ld de, 0 + call PlayMusic + call DelayFrame + call MaxVolume +; plays vs. gym leader music regardless of the battle type + ld de, MUSIC_LEADER_BATTLE + call PlayMusic + pop bc + pop de + pop hl + ret + +InitBattleDisplay: + call InitBackPic + ld hl, $c390 + ld b, 4 + ld c, $12 + call DrawTextBox + ld hl, $c305 + ld bc, $0307 + call ClearBox + call DisableLCD + call LoadFont + call Call_LoadBattleGraphics + ld hl, vBGMap0 + ld bc, $0400 + ld a, $7f + call ByteFill + call LoadMapTimeOfDay.PushAttrMap + call EnableLCD + xor a + ldh [hMapAnims], a + ldh [hSCY], a + ld a, $90 + ldh [hWY], a + ldh [rWY], a + call WaitBGMap + xor a + ldh [hBGMapMode], a + call BattleIntroSlidingPics + ld a, 1 + ldh [hBGMapMode], a + ld a, $31 + ldh [hGraphicStartTile], a + ld hl, $c31a + ld bc, $0606 + predef PlaceGraphic + xor a + ldh [hWY], a + ldh [rWY], a + call WaitBGMap + ld b, 1 + call GetSGBLayout + call HideSprites + ld a, $90 + ldh [hWY], a + xor a + ldh [hSCX], a + ret + + +BattleIntroSlidingPics: + ld b, $70 + ld c, $90 + ld a, c + ldh [hSCX], a + call DelayFrame + ld a, $e4 + ldh [rBGP], a + ldh [rOBP0], a + ldh [rOBP1], a +.loop1 + push bc + ld h, b + ld l, $40 + call .Subfunction2 + ld h, 0 + ld l, $60 + call .Subfunction2 + call .Subfunction1 + pop bc + ld a, c + ldh [hSCX], a + inc b + inc b + dec c + dec c + jr nz, .loop1 + ret + +.Subfunction1: + push bc + ld hl, wShadowOAMSprite00XCoord + ld c, $12 + ld de, 4 +.loop2 + dec [hl] + dec [hl] + add hl, de + dec c + jr nz, .loop2 + pop bc + ret + +.Subfunction2: +.loop3 + ldh a, [rLY] + cp l + jr nz, .loop3 + ld a, h + ldh [rSCX], a +.loop4 + ldh a, [rLY] + cp h + jr z, .loop4 + ret + +InitBackPic: + ld de, PlayerBacksprite + ld a, BANK(PlayerBacksprite) + call UncompressSpriteFromDE + ld hl, vTitleLogo2 + ld a, $33 + call Predef + ld a, 0 + call OpenSRAM + ld hl, vSprites + ld de, sSpriteBuffer1 + ldh a, [hROMBank] + ld b, a + ld c, 7 * 7 + call Request2bpp + call CloseSRAM + call LoadTrainerBackpicAsOAM + ld a, $31 + ldh [hGraphicStartTile], a + ld hl, $c31a + ld bc, $0606 + predef PlaceGraphic + ret + +LoadTrainerBackpicAsOAM: + ld hl, wShadowOAMSprite00 + xor a + ldh [hTextBoxCursorBlinkInterval], a + ld b, 6 + ld e, $a8 + +.outer_loop + ld c, 3 + ld d, $40 + +.inner_loop + ld [hl], d + inc hl + ld [hl], e + inc hl + ldh a, [hTextBoxCursorBlinkInterval] + ld [hli], a + inc a + ldh [hTextBoxCursorBlinkInterval], a + inc hl + ld a, d + add 8 + ld d, a + dec c + jr nz, .inner_loop + ldh a, [hTextBoxCursorBlinkInterval] + add 3 + ldh [hTextBoxCursorBlinkInterval], a + ld a, e + add 8 + ld e, a + dec b + jr nz, .outer_loop + ret + +PlayerBacksprite: +INCBIN "gfx/trainer/protagonist_back.pic" + +Unused_OldManBacksprite: +INCBIN "gfx/trainer/oldman_back.pic" + +BattleStartMessage: + ld a, [wBattleMode] + dec a + jr z, .wild + ld de, $62 ; SFX_SHINE + call PlaySFX + call WaitSFX + ld c, 20 + call DelayFrames + callab Function390e9 + ld hl, WantsToBattleText + jr .PlaceBattleStartText + +.wild + ld a, $f + ld [wCryTracks], a + ld a, [wcdd7] + call PlayStereoCry + ld hl, WildPokemonAppearedText + ld a, [wca3a] + and a + jr z, .PlaceBattleStartText + ld hl, HookedPokemonAttackedText + +.PlaceBattleStartText: + push hl + callab Function38340 + pop hl + call PrintText + ret + +WildPokemonAppearedText: + text "あ! やせいの" + line "@" + text_from_ram wBattleMonNickname + text "が とびだしてきた!" + prompt + +HookedPokemonAttackedText: + text "つりあげた @" + text_from_ram wBattleMonNickname + text "が" + line "とびかかってきた!" + prompt + +WantsToBattleText: + text_from_ram wca2b + text "の @" + text_from_ram wStringBuffer1 + text "が" + line "しょうぶを しかけてきた!" + prompt + +ShowLinkBattleParticipants: + call IsLinkBattle + jr nz, .ok + call sub_3f60c + call ClearTileMap +.ok + call DelayFrame + ld a, $4e + call Predef + call Call_LoadBattleGraphics + ld a, 1 + ldh [hBGMapMode], a + call ClearSprites + call ClearTileMap + xor a + ldh [hBGMapMode], a + ldh [hWY], a + ldh [rWY], a + ldh [hMapAnims], a + ret + +sub_3f60c: + call LoadFontExtra + ld hl, $c2f3 + ld b, 7 + ld c, $c + call DrawTextBox + ld hl, $c31c + ld de, wPlayerName + call PlaceString + ld hl, $c36c + ld de, wd8fe + call PlaceString + ld hl, $c349 + ld a, $69 + ld [hli], a + ld [hl], $6a + callab Function38431 + ld c, 150 + jp DelayFrames + +IsLinkBattle: + push bc + push af + ld a, [wLinkMode] + cp 3 + pop bc + ld a, b + pop bc + ret + diff --git a/engine/menu/start_menu.asm b/engine/menu/start_menu.asm index a8f77735..65ebf6c8 100644 --- a/engine/menu/start_menu.asm +++ b/engine/menu/start_menu.asm @@ -1579,10 +1579,10 @@ PartySelectionInputs: predef Function500a0 ld a, [wCurSpecies] dec a - ld hl, Data4a8b8 - ld bc, $0007 + ld hl, Data418b8 + ld bc, $7 call AddNTimes - ld a, BANK(Data4a8b8) + ld a, BANK(Data418b8) call GetFarByte hlcoord 15, 12 cp 2 diff --git a/gfx/gfx.mk b/gfx/gfx.mk index afc5d10d..3b1665c2 100644 --- a/gfx/gfx.mk +++ b/gfx/gfx.mk @@ -29,3 +29,5 @@ $(BUILD)/gfx/minigames/%.bin: gfx/minigames/%.bin $(BUILD)/gfx/battle_anims/attack_animations_1.2bpp: tools/gfx += --trim-whitespace $(BUILD)/gfx/battle_anims/attack_animations_2.2bpp: tools/gfx += --trim-whitespace + +$(BUILD)/gfx/title/title_logo.2bpp: tools/gfx += --trim-whitespace diff --git a/gfx/title/title_logo.png b/gfx/title/title_logo.png index 79a7184f6d93ab1a423a08d802c7ca81543626ee..fd8f694b66e9d56cbedfd162e15d03ee9e494b7d 100644 GIT binary patch literal 776 zcmV+j1NZ!iP)${7NvDO46 z`&g)wSDj?DsmZ(vBuQ4lwg>_s(*N1Uw8|-IT>qf@bZEf}m|Swl`XHPZX;Cs%ltV*2 z)(eEciKbDp9<2)<@dg-w1ibd^%Tb=q!WG!y*T4Bb9GEgqK0}j1D;JFZwZluF6 zE`3%9K&&1m@G$j5T1C!+*H;4<4GbV@;4&Lrzz0hSz^h_jL)Z!NT9@)32^X#At#g;h z+_qonnHAlhchA0frk#>jDaQ2O+F~f1OC#Ae-TfXvOewizzbnQxVLEwqSHTC?4ztwo zru1W*#U1b3`UZV>($NWjm*fCQoFv3&3-g~$4is%l)BoLwW86Cdq(V}>XIlW0dd3V3 zyKNMbk&f^}B(D; zHkWSjuKQwrH@V;mPb|<69h)lS?jcdqwpJN4ULvaPO|Py(%af5UT>4||D|%8}ss(0` zh;uaP;e}G@)A!5{B=CS3BZsO(b(#w$jpIj68I>oj!Z!TvjdA%S-mKi^f;R=lwFyH7o%vt&(Qwp2+gEpkm;WW@RwSqlWF1pS(Cm3pfTqBPHl5)pvIuU@+LB$9IyxJVw61BcS zIBDnF&f5!tsMJL-A7dP!Y|fAL`ngs*Yu(N}QPqMvF2^D}DznM-&-!_G&9DAue`d-F ze}?f3nSca-f_S9I*KaJG9SuKoDSv~MQvRoihfe;|K>P#m))F2pWV3Am0000fxwTrB~8q!TL0{=oGKOn44DMMfH zmF=Jg0_N}}y?Jl$oq2|hC}5LC0=0kzLV`68h6)jhp|Dp&g3|bjXx<{FA;Tww>5ZBH zOVsW?5+MqnY4D!uzE<=R3bVi+*Z~2_0B^r@Ji+DMYr2e>slKD?rdsF(CcKBSWn@|Y zChc`A6k6t%7?l1Y_C2m;PKg^mX2PwIpSw8B?Zb+BG6pM8(Up|%?7yfrX3m%ed(Sl< zA%%|w6qyeh+?$FyqVkoL2mI+DC4t8?Nn2%BuyULjO*#6`1)wJE4KX+n*%_0nxQ?P- zeL)&dVBL_}MIvDm9gT|OPab+?apze7p%oHgrvksIK9e;0mF=j=Xrw*UYD07*qoM6N<$ Ef;}-CXaE2J diff --git a/gfx/trainer/oldman_back.png b/gfx/trainer/oldman_back.png new file mode 100644 index 0000000000000000000000000000000000000000..6d48000f152213dc47dea78677669ac15687b337 GIT binary patch literal 259 zcmV+e0sQ`nP)?+<0@fVH1cVq60@@bigfdm&bEE!_-ed@@lwEz6)@PCFsp(*?SeCGMj@G&&v{eR=nAV$dU{oFvt(a?}}@7e!?7@^ub z4*vl&v{w8-@t;97G|+3&dS(zKgkiyo{~$)FKR+|rQV77q001dHzDsrj;i&)s002ov JPDHLkV1kWUdE)>8 literal 0 HcmV?d00001 diff --git a/gfx/trainer/protagonist_back.png b/gfx/trainer/protagonist_back.png new file mode 100644 index 0000000000000000000000000000000000000000..7bf3c50dbd3f4312dc6c1a6525cd856b23d58beb GIT binary patch literal 458 zcmV;*0X6=KP)5NsSo^<8Q^$n3nL$5**|jcWjB)51^8QQNc-9 zYXV(Yd|UcDk%17;1}sOa0p?>*O?_+8VXRHI!t)Q>3X#Z06e_#}%=)9smxxv#ogo0$ zILNo-%&O?Rp)w^O9JyH8(_mU8X2FY?<0t*PtlYH-A3p@5Y)J8zD69y82|tP07*qoM6N<$f{qu? AX#fBK literal 0 HcmV?d00001 diff --git a/home/menu.asm b/home/menu.asm index 091dfb9e..68762ffc 100644 --- a/home/menu.asm +++ b/home/menu.asm @@ -99,6 +99,7 @@ CopyNameFromMenu:: YesNoBox:: lb bc, 14, 7 +asm_1dd5:: jr asm_1ddc PlaceGenericTwoOptionBox:: diff --git a/layout.link b/layout.link index 6c2f3a08..e55aa034 100644 --- a/layout.link +++ b/layout.link @@ -250,8 +250,7 @@ ROMX $0c ROMX $0d org $4000 - org $506d - "data/types/type_matchups.asm" + "engine/dumps/bank0d.asm@Function34000" ROMX $0e org $4000 @@ -264,10 +263,11 @@ ROMX $0e ROMX $0f org $4000 - org $63da + "engine/dumps/bank0f.asm@StartBattle" "engine/battle/core.asm" - org $6a3c + "engine/dumps/bank0f.asm@PlayMoveAnimation" "data/wild.asm" + "engine/dumps/bank0f.asm@Function3ee3e" ROMX $10 org $4000 diff --git a/ram/hram.asm b/ram/hram.asm index 0a89696b..a109bab7 100644 --- a/ram/hram.asm +++ b/ram/hram.asm @@ -109,7 +109,8 @@ ENDU hSpriteOffset:: db - db ; TODO +hFFB2:: + db UNION @@ -202,7 +203,9 @@ hBGMapTransferPosition:: hBGMapAddress:: dw - db ; TODO + +hFFE2:: + db hSPTemp:: dw diff --git a/ram/wram.asm b/ram/wram.asm index b6d31800..a1cf54ef 100644 --- a/ram/wram.asm +++ b/ram/wram.asm @@ -373,12 +373,24 @@ ENDU ds $32 wBattleAnimEnd:: - ds $1aa ; TODO - - + ds $1a3 ; TODO + +wc9e8:: ds 1 +wc9e9:: ds 1 +wc9ea:: ds 1 +wc9eb:: ds 1 +wc9ec:: ds 1 +wc9ed:: ds 1 +wc9ee:: ds 1 wc9ef:: ds 1 +wc9f0:: ds 1 +wc9f1:: ds 1 +wc9f2:: ds 1 +wc9f3:: ds 1 - ds 6 + ds 1 + +wc9f5:: ds 1 wBattleMonNickname:: ds 6 wEnemyMonNickname:: ds 6 @@ -386,14 +398,18 @@ wEnemyMonNickname:: ds 6 wca02:: ds 1 wca03:: ds 1 wca04:: ds 1 +wca05:: ds 1 - ds 3 + ds 2 wca08:: ds 1 wca09:: ds 1 wca0a:: ds 1 - ds 5 ; TODO + ds 3 + +wca0e:: ds 1 +wca0f:: ds 1 wIntroJumptableIndex:: wca10:: ds 1 @@ -412,15 +428,37 @@ wca13:: ds 1 wca14:: ds 1 ENDU +UNION wIntroTilesPointer:: ds 2 - wIntroFrameCounter1:: ds 1 +NEXTU + +wca15:: ds 1 +wca16:: ds 1 +wca17:: ds 1 + +ENDU + +wca18:: wIntroFrameCounter2:: ds 1 wIntroSpriteStateFlag:: ds 1 - ds $1d ; TODO - +wca1a:: ds 1 +wca1b:: ds 1 +wca1c:: ds 1 + ds 1 +wca1e:: ds 1 + ds 1 +wca20:: ds 1 +wca21:: ds 1 +wca22:: ds 1 +wca23:: ds 1 +wca24:: ds 1 + ds 6 +wca2b:: ds 1 + ds 10 +wca36:: ds 1 wca37:: ds 1 wca38:: ds 1 wca39:: ds 1 @@ -439,8 +477,30 @@ wEnemySubStatus3:: db wca43:: db wca44:: db +wca45:: db +wca46:: db +wca47:: db +wca48:: db +wca49:: db +wca4a:: db +wca4b:: db + + ds 1 + +wca4d:: db +wca4e:: db + +wca4f:: db +wca50:: db +wca51:: db +wca52:: db +wca53:: db + + ds 1 + +wca55:: db +wca56:: db - ds $12 wTrainerClass:: db @@ -449,12 +509,52 @@ wca59:: ds 1 wca5a:: ds 1 wca5b:: ds 1 wca5c:: ds 1 +wca5d:: ds 1 + + ds $1d + +wca7b:: ds 1 +wca7c:: ds 1 +wca7d:: ds 1 + + ds $15 - ds $5c +wca93:: ds 1 + + ds 10 + +wca9e:: ds 1 + + ds $a + +wcaa9:: ds 1 + + ds 4 + +wcaae:: ds 1 +wcaaf:: ds 1 + + ds 1 + +wcab1:: ds 1 + + ds 4 + +wcab6:: ds 1 +wcab7:: ds 1 + + ds 1 wcab9:: ds 1 +wcaba:: ds 1 - ds 6 + ds 1 + +wcabc:: ds 1 +wcabd:: ds 1 +wcabe:: ds 1 + + ds 1 wcac0:: ds 1 wcac1:: ds 1 @@ -462,17 +562,43 @@ wcac2:: ds 1 wLinkBattleRNCount:: db - ds 12 +wcac4:: ds 1 -wcad0:: ds 1 + ds 2 - ds 9 +wcac7:: ds 1 +wcac8:: ds 1 +wcac9:: ds 1 +wcaca:: ds 1 -wcada:: ds 1 + ds 1 - ds 6 +wcacc:: ds 1 +wcacd:: ds 1 +wcace:: ds 1 + ds 1 + +wcad0:: ds 1 +wcad1:: ds 1 +wcad2:: ds 1 +wcad3:: ds 1 +wcad4:: ds 1 +wcad5:: ds 1 +wcad6:: ds 1 +wcad7:: ds 1 +wcad8:: ds 1 +wcad9:: ds 1 +wcada:: ds 1 +wcadb:: ds 1 +wcadc:: ds 1 +wcadd:: ds 1 +wcade:: ds 1 +wcadf:: ds 1 +wcae0:: ds 1 wcae1:: ds 1 +wcae2:: ds 1 +wcae3:: ds 1 ENDU @@ -771,8 +897,13 @@ wHPBarTempHP:: dw NEXTU wStringBuffer2:: db ; How long is this? -ENDU +NEXTU +wcd31:: db +wcd32:: db +wcd33:: db + +ENDU SECTION "CD3C", WRAM0[$CD3C] @@ -843,13 +974,23 @@ wcd7f:: db wcd80:: db wcd81:: db -SECTION "CD9E", WRAM0 [$CD9E] + ds 7 + +wcd89:: db + + ds 10 + +wcd94:: db + + ds 9 + wLoadedMonLevel:: db +wcd9f:: db + + ds 15 -SECTION "CDAF", WRAM0 [$CDAF] wcdaf:: db -SECTION "CDB0", WRAM0 [$CDB0] wTalkingTargetType:: db ;bit 0 = has engaged NPC in dialogue ;bit 1 = has engaged sign in dialogue @@ -857,13 +998,13 @@ wTalkingTargetType:: db wcdb1:: ds 1 wcdb2:: ds 1 -ds 1 + ds 1 wcdb4:: ds 1 wcdb5:: ds 1 wcdb6:: ds 1 -SECTION "CDB9", WRAM0[$CDB9] + ds 2 wcdb9:: ds 1 @@ -881,7 +1022,7 @@ wNextMapGroup:: db wNextMapId:: db wPrevWarp:: db - ds 1 +wcdc2:: db UNION wFieldMoveScriptID:: db @@ -898,22 +1039,46 @@ NEXTU wcdc3:: db wcdc4:: db wcdc5:: db + +NEXTU + +wEnemyEffectivenessVsPlayerMons:: db +wPlayerEffectivenessVsEnemyMons:: db + + ds 1 + wcdc6:: db ENDU UNION + wHPBarNewHP:: dw + NEXTU + wcdc7:: db wcdc8:: db + ENDU + wHPBarDelta:: db wcdca:: db wHPBarHPDifference:: dw +UNION + wLinkBattleRNs:: ds 10 +NEXTU + + ds 7 + +wcdd4: ds 1 + + ds 1 +ENDU + wcdd7:: ds 1 wcdd8:: ds 1 wcdd9:: ds 1 @@ -935,15 +1100,37 @@ wcde8:: ds 1 wcde9:: ds 1 wcdea:: ds 1 wcdeb:: ds 1 +wcdec:: ds 1 +wcded:: ds 1 +wcdee:: ds 1 +wcdef:: ds 1 + + ds 1 +wcdf1:: ds 1 +wcdf2:: ds 1 +wcdf3:: ds 1 + + ds 1 + +wcdf5:: ds 1 + + ds 1 + +wcdf7:: ds 1 + + ds 1 -SECTION "CDFE", WRAM0[$CDFE] +wcdf9:: ds 1 + + ds 4 wcdfe:: ds 1 wcdff:: ds 1 wBattleMode:: db wce01:: ds 1 wce02:: ds 1 +wBattleType:: wce03:: ds 1 wce04:: ds 1 wce05:: ds 1 @@ -1012,7 +1199,16 @@ wMonHLearnset:: flag_array 50 + 5 ; size = 7 ds 1 -SECTION "CE2D", WRAM0[$CE2D] +SECTION "CE26", WRAM0[$CE26] +wce26:: ds 1 + + ds 2 + +wce29:: ds 1 +wce2a:: ds 1 + + ds 2 + wce2d:: ds 1 wce2e:: ds 1 wce2f:: ds 1 @@ -1029,6 +1225,9 @@ wCountSetBitsResult:: wce37:: db +wce38:: ds 1 +wce39:: ds 1 + SECTION "CE3A", WRAM0[$CE3A] wce3a:: ds 1 @@ -1114,6 +1313,7 @@ for n, 1, NUM_OBJECTS wMap{d:n}Object:: map_object wMap{d:n} endr +wd14f:: wToolgearFlags:: db ; 76543210 ; | | \- show toolgear @@ -1239,8 +1439,9 @@ wd41d:: db ; \--- beat rival in the lab wd41e:: db -SECTION "D4A9", WRAM0[$D4A9] - +SECTION "D4A9", WRAM0[$D4A7] +wd4a7:: db + ds 1 wd4a9:: db ds 1 ; TODO wJoypadFlags:: db @@ -1475,6 +1676,7 @@ wd8e4:: ds 1 SECTION "D8FD", WRAM0[$D8FD] wd8fd:: ds 1 +wd8fe:: ds 1 SECTION "D913", WRAM0[$D913] @@ -1486,10 +1688,19 @@ UNION wWildMons:: ds 41 NEXTU - ds 2 + ds 1 +wd91c:: ds 1 wd91d:: ds 1 - ds 29 +wd91e:: ds 1 + ds 19 +wd932:: ds 1 + ds 7 +wd93a:: ds 1 wd93b:: ds 1 + ds 1 +wd93d:: ds 1 +wd93e:: ds 1 +wd93f:: ds 1 ENDU SECTION "DA3B", WRAM0[$DA3B] diff --git a/shim.sym b/shim.sym old mode 100755 new mode 100644 index 53d8d13d..37c8463b --- a/shim.sym +++ b/shim.sym @@ -35,27 +35,16 @@ ;0E:4BA0 LoadTrainerClassName.got_name 0E:4BA9 LoadTrainerClass -0D:7E3D Function37e3d - -0F:508C Function3d08c -0F:55CE Function3d5ce -0F:567C Function3d67c -0F:5AA7 Function3daa7 -0F:6043 AddPokemonToBox -0F:61A4 Function3e1a4 -0F:63A7 Function3e3a7 -0F:639F Function3e39f -0F:65BF Function3e5bf -0F:6874 Function3e874 -0F:691E Function3e91e -0F:6963 Function3e963 -0F:69A9 _LoadWildMons -0F:69DC Function3e9dc -0F:6E3E Function3ee3e -0F:6F19 Function3ef19 -0F:7019 PlaceGraphic -0F:704A Function3f04a -0F:7068 Function3f068 +0E:4000 Function38000 +0E:4220 Function38220 +0E:4340 Function38340 +0E:434E Function3834e +0E:43CD Function383cd +0E:43FD Function383fd +0E:4431 Function38431 +0E:44D4 Function384d4 +0E:4F45 Function38f45 +0E:50E9 Function390e9 10:4000 Function40000 10:40A6 ShowPokedexMenu @@ -63,11 +52,11 @@ 10:4B07 Function40b07 10:4B45 Function40b45 10:4B5C Function40b5c -10:58B8 Data4a8b8 10:5F93 Function4af93 10:5FA1 Function41fa1 10:61F8 Function421f8 10:6252 Function42252 +10:58B8 Data418b8 14:4000 Function50000 14:4073 Function50073 @@ -119,6 +108,8 @@ 33:4000 Functioncc000 33:4000 Functioncc000_2 33:4001 PlayBattleAnim +33:444F Functioncc44f +33:44D4 Functioncc4d4 33:467B QueueBattleAnimation 33:625D BattleAnim_Sine_e 33:6263 BattleAnim_Cosine_e @@ -129,8 +120,53 @@ 38:4E5F Cursor_AnimateCursor 38:4EA8 Cursor_InterpretJoypad + +; Cry header shims +3C:57C5 CryHeader_f17c5 +3C:57CE CryHeader_f17ce +3C:57D7 CryHeader_f17d7 +3C:57E0 CryHeader_f17e0 +3C:57E9 CryHeader_f17e9 +3C:57F2 CryHeader_f17f2 +3C:57FB CryHeader_f17fb +3C:5804 CryHeader_f1804 +3C:580D CryHeader_f180d +3C:5816 CryHeader_f1816 +3C:581F CryHeader_f181f +3C:5828 CryHeader_f1828 +3C:5831 CryHeader_f1831 +3C:583A CryHeader_f183a +3C:5843 CryHeader_f1843 +3C:584C CryHeader_f184c +3C:5855 CryHeader_f1855 +3C:585E CryHeader_f185e +3C:5867 CryHeader_f1867 +3C:5870 CryHeader_f1870 +3C:5879 CryHeader_f1879 +3C:5882 CryHeader_f1882 +3C:588B CryHeader_f188b +3C:5894 CryHeader_f1894 +3C:589D CryHeader_f189d +3C:58A6 CryHeader_f18a6 +3C:58AF CryHeader_f18af +3C:58B8 CryHeader_f18b8 +3C:58C1 CryHeader_f18c1 +3C:58CA CryHeader_f18ca +3C:58D3 CryHeader_f18d3 +3C:58DC CryHeader_f18dc +3C:58E5 CryHeader_f18e5 +3C:58EE CryHeader_f18ee +3C:58F7 CryHeader_f18f7 +3C:5900 CryHeader_f1900 +3C:5909 CryHeader_f1909 +3C:5912 CryHeader_f1912 + +3E:40D6 Functionf80d6 + +3F:40E9 InGameDebugMenu 3F:4E3E Functionfce3e 3F:5B66 Functionfdb66 3F:64CE MonsterTest 3F:654E PicTest 3F:6750 PicTestMenu +