diff options
Diffstat (limited to 'home/talk_to_npc.asm')
-rw-r--r-- | home/talk_to_npc.asm | 268 |
1 files changed, 236 insertions, 32 deletions
diff --git a/home/talk_to_npc.asm b/home/talk_to_npc.asm index 9ef5dd3..7f4452c 100644 --- a/home/talk_to_npc.asm +++ b/home/talk_to_npc.asm @@ -6,9 +6,9 @@ else SECTION "Unknown 3025", ROM0 [$2fe9] endc -Function3025:: +MapDefaultText:: ld hl, .Text - call Function3111 + call OpenTextbox ret .Text: ; 00:302c @@ -22,8 +22,8 @@ Function3036:: ; 3036 .Text: ; 00:303a db "@" -CallMapTextSubroutine:: - ld a, [wcdb0] +CallMapTextSubroutine:: ; 00:303b + ld a, [wTalkingTargetType] bit 0, a jr z, asm_3062 call Function3055 @@ -43,16 +43,16 @@ CallMapTextSubroutine:: Function3055:: ; 00:3055 ldh a, [hFFEA] ld b, a -.asm_3058: ; 00:3058 +.Loop: ; 00:3058 ld a, [hli] cp $ff ret z cp b - jp z, Function3240 - jr .asm_3058 + jp z, SetFFInAccumulator + jr .Loop asm_3062: ; 00:3062 - ld a, [wcdb0] + ld a, [wTalkingTargetType] bit 1, a ret z ld h, d @@ -71,28 +71,29 @@ asm_3062: ; 00:3062 jp hl Function307a:: ; 00:307a - ld hl, wcdb0 + ld hl, wTalkingTargetType res 0, [hl] res 1, [hl] - call Function3240 + call SetFFInAccumulator ret -Function3085:: ; 00:3085 +PrintTextboxDebugNumbers:: ; 00:3085 push hl push de push bc - ld de, $99 - ld a, [wcdb0] + ld de, $0099 ; default address to print from (not a sign or NPC) + ld a, [wTalkingTargetType] bit 0, a - jr z, .asm_3097 + jr z, .CheckSign ld de, hFFEA - jr .asm_309e + jr .PrintNum -.asm_3097: ; 00:3097 +.CheckSign: ; 00:3097 bit 1, a - jr z, .asm_309e + jr z, .PrintNum ld de, hFFEE -.asm_309e: ; 00:309e + +.PrintNum: ; 00:309e hlcoord 4, 12 lb bc, PRINTNUM_LEADINGZEROS | 1, 2 call PrintNumber @@ -105,17 +106,17 @@ Function3085:: ; 00:3085 pop hl ret -QueueMapTextSubroutine:: +QueueMapTextSubroutine:: ; 00:30b7 ldh a, [hJoyState] bit A_BUTTON_F, a - jp z, Function323e + jp z, ClearAccumulator ; if we didn't press a call GetFacingPersonText - jp nc, Function30e8 + jp nc, Function30e8 ; if not talking to a person ld d, $0 ld e, a - ld a, [wce63] - bit 1, a - call nz, Function3085 + ld a, [wDebugFlags] + bit DEBUG_FIELD_F, a + call nz, PrintTextboxDebugNumbers ; if debug, print these ld hl, wMapTextPtr ld a, [hli] ld h, [hl] @@ -128,14 +129,14 @@ QueueMapTextSubroutine:: inc de ld a, [hl] ld [de], a - ld hl, wcdb0 - set 0, [hl] - call Function3240 + ld hl, wTalkingTargetType + set 0, [hl] ; we're talking to an NPC + call SetFFInAccumulator ret Function30e8:: ; 00:30e8 call GetFacingSignpost - jp nc, Function323e + jp nc, ClearAccumulator ; if not facing person or sign ld a, e ldh [hFFEB], a ld a, d @@ -144,14 +145,217 @@ Function30e8:: ; 00:30e8 ldh [hFFED], a ld a, [hl] ldh [hFFEE], a - ld hl, wcdb0 - set 1, [hl] - call Function3240 + ld hl, wTalkingTargetType + set 1, [hl] ; we're talking to a sign + call SetFFInAccumulator ret GetFacingPersonText:: ; 00:3103 callba Function776e ret nc - call Function319b + call TurnNPCTalkingTo scf ret + +OpenTextbox:: ; 00:3111 + ; Opens a textbox and waits for input + push hl + call PrepareTextbox + ld a, [wDebugFlags] + bit DEBUG_FIELD_F, a + call nz, PrintTextboxDebugNumbers + pop hl + call TextboxIdle + ret + +OpenTextboxNoInput:: ; 00:3122 + push hl + call PrepareTextbox + pop hl + +TextboxIdle:: ; 00:3127 + ; Prints text, then waits for A or B to be pressed, unless bit 5 of JoypadFlags is set. + call PrintTextBoxText +.Loop + ld a, [wJoypadFlags] + bit 5, a + res 5, a + ld [wJoypadFlags], a + jr nz, .Escape + call GetJoypad + ldh a, [hJoyDown] + and A_BUTTON | B_BUTTON + jr nz, .Escape + call UpdateTime + call UpdateTimeOfDayPalettes + call DelayFrame + jr .Loop +.Escape + call TextboxCleanup + ret + +PrepareTextbox:: ; 00:314E + call ClearWindowData + ldh a, [hROMBank] + push af + ld a, 01 + call Bankswitch + call ReanchorBGMap_NoOAMUpdate + hlcoord 0, 12 ;in the tilemap in WRAM + ld b, 04 + ld c, $12 + call DrawTextBox + call WaitBGMap + call LoadFonts_NoOAMUpdate + pop af + call Bankswitch + ret + +TextboxCleanup: ; 00:3171 + callab ReanchorBGMap_NoOAMUpdate + call UpdateSprites + xor a + ldh [hBGMapMode], a + ld a, $90 + ldh [hWY], a + call Function318f + ld hl, wToolgearFlags + res 7, [hl] + call InitToolgearBuffer + ret + +Function318f: ; 00:318f + callab Function140ea + call Function0d02 + ret + +TurnNPCTalkingTo:: ; 00:319b + ; If an NPC is allowed to turn when talked to, turn it. + ldh a, [hObjectStructIndexBuffer] + call GetObjectStruct + ld hl, OBJECT_SPRITE + add hl, bc + ld a, [hl] + call CheckNonTurningSprite + jr c, .Jump + ld a, [wPlayerWalking] + xor 04 + ld hl, OBJECT_DIRECTION_WALKING + add hl, bc + ld [hl], a + push bc + call UpdateSprites + pop bc +.Jump + ld hl, OBJECT_MAP_OBJECT_INDEX + add hl, bc + ld a, [hl] + sub 02 + ldh [hFFEA], a + ret + +Function31C3:: ; 00:31C3 + ret + +CheckInlineTrainer:: ; 00:31C4 + ; Passed de is the pointer to a map_object struct. If it's an inline trainer, write to relevant wram region. + ld hl, MAPOBJECT_OBJECT_STRUCT_ID + add hl, de + ld a, [hl] + call GetObjectStruct + call GetInlineMapObject + jr nc, .Escape + ld hl, MAPOBJECT_POINTER_HI + add hl, de + ld a, [hl] + cp b + jr c, .Escape + ld hl, MAPOBJECT_OBJECT_STRUCT_ID + add hl, de + ld a, [hl] + add a, a + ld hl, wCurrMapInlineTrainers + add a, l + ld l, a + jr nc, .NoCarry + inc h +.NoCarry + ld [hl], b + inc hl + ld [hl], c +.Escape + ret + +GetInlineMapObject:: ; 00:31EB + ;bc is start of object struct. if c flag set, returns distance in B and direction in C + ld hl, OBJECT_NEXT_MAP_X + add hl, bc + ld a, [wPlayerStandingMapX] + cp [hl] + jr z, .EqualX + ld hl, OBJECT_NEXT_MAP_Y + add hl, bc + ld a, [wPlayerStandingMapY] + cp [hl] + jr z, .EqualY + and a + ret +.EqualX + ld hl, OBJECT_NEXT_MAP_Y + add hl, bc + ld a, [wPlayerStandingMapY] + sub [hl] + jr z, .Reset + jr nc, .SetDown + cpl + inc a + ld b, a + ld c, UP + scf + ret +.SetDown ; 3214 + ld b, a + ld c, DOWN + scf + ret +.EqualY ; 3219 + ld hl, OBJECT_NEXT_MAP_X + add hl, bc + ld a, [wPlayerStandingMapX] + sub [hl] + jr z, .Reset ; (this condition is impossible to meet) + jr nc, .SetRight + cpl + inc a + ld b, a + ld c, LEFT + scf + ret +.SetRight ; 322C + ld b, a + ld c, RIGHT + scf + ret +.Reset ; 3231 + and a + ret + +CheckBPressedDebug: ; 3233 + ; If in debug mode, returns a check on the B button. + ld a, [wDebugFlags] + bit DEBUG_FIELD_F, a + ret z + ldh a, [hJoyState] + bit B_BUTTON_F, a + ret + +ClearAccumulator:: ; 323E + xor a + ret + +SetFFInAccumulator:: ; 3240 + xor a + dec a + ret + +; 3243 |