diff options
author | 2Tie <foxman95@ymail.com> | 2018-06-16 18:27:10 -0600 |
---|---|---|
committer | 2Tie <foxman95@ymail.com> | 2018-06-16 18:27:10 -0600 |
commit | a9149c6cc3be2a1cab6a374b2c10f359ce5f29f5 (patch) | |
tree | 4448e34794db9d2781c5db3c5cc58b978059222b | |
parent | f7f29000a85389291798ec5d97b51dc65e7b500e (diff) |
work on talk_to_npc done, naming of some overworld logic and wram values.
-rw-r--r-- | home/map.asm | 10 | ||||
-rw-r--r-- | home/map_objects.asm | 14 | ||||
-rw-r--r-- | home/talk_to_npc.asm | 260 | ||||
-rw-r--r-- | home/unknown_388f.asm | 14 | ||||
-rw-r--r-- | home/util.asm | 5 | ||||
-rw-r--r-- | home/window.asm | 2 | ||||
-rw-r--r-- | shim.sym | 7 | ||||
-rw-r--r-- | tools/make_shim.py | 38 | ||||
-rw-r--r-- | wram.asm | 16 |
9 files changed, 285 insertions, 81 deletions
diff --git a/home/map.asm b/home/map.asm index aac770c..1f7c27d 100644 --- a/home/map.asm +++ b/home/map.asm @@ -1593,7 +1593,7 @@ Function2a8d:: ; 00:2a8d dbbw $05, $33, Function14777 Function2ae5:: -.asm_2ae5: ; 00:2ae5 +.loop: ; 00:2ae5 ld hl, wJoypadFlags set 4, [hl] set 6, [hl] @@ -1608,7 +1608,7 @@ Function2ae5:: bit 7, [hl] res 7, [hl] ret nz - call Function38e3 + call TestWildBattleStart ret nz call OverworldStartButtonCheck ret nz @@ -1619,16 +1619,16 @@ Function2ae5:: and a ret nz call Function2c4a - jr nc, .asm_2ae5 + jr nc, .loop callba Function824c ld a, [wc5ed] bit 6, a - jr nz, .asm_2ae5 + jr nz, .loop call CheckMovingOffEdgeOfMap ret c call WarpCheck ret c - jr .asm_2ae5 + jr .loop Function2b39:: ld hl, wJoypadFlags diff --git a/home/map_objects.asm b/home/map_objects.asm index 70cba50..ca7ca0b 100644 --- a/home/map_objects.asm +++ b/home/map_objects.asm @@ -315,6 +315,7 @@ UpdateSprites:: ; 00:17a8 ret GetObjectStruct:: ; 00:17bf +; Puts the start of the a'th object struct into bc ld bc, $28 ld hl, wObjectStructs call AddNTimes @@ -334,26 +335,27 @@ Function17cb:: call Bankswitch ret -Function17de:: +CheckNonTurningSprite:: ; 00:17de + ; sets carry flag if a is equal to any of the sprites below push hl push bc ld c, a ld b, $ff ld hl, .Data -.asm_17e6: ; 00:17e6 +.loop: ; 00:17e6 ld a, [hli] cp b - jr z, .asm_17ee + jr z, .escape ; if a == $FF, escape cp c - jr nz, .asm_17e6 + jr nz, .loop ; if a != c, loop scf -.asm_17ee: ; 00:17ee +.escape: ; 00:17ee pop bc pop hl ret .Data: ; 00:17f1 - db $51, $55, $56, $57, $58, $5a, $5b, $ff + db SPRITE_KABIGON, SPRITE_POKE_BALL, SPRITE_POKEDEX, SPRITE_PAPER, SPRITE_OLD_LINK_RECEPTIONIST, SPRITE_EGG, SPRITE_BOULDER, $ff Function17f9:: call GetMapObject diff --git a/home/talk_to_npc.asm b/home/talk_to_npc.asm index 9ef5dd3..1820692 100644 --- a/home/talk_to_npc.asm +++ b/home/talk_to_npc.asm @@ -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 - ld de, hFFEA - jr .asm_309e + jr z, .CheckSign + ld de, hFFEA ; address if we're talking to an NPC + jr .PrintNum -.asm_3097: ; 00:3097 +.CheckSign: ; 00:3097 bit 1, a - jr z, .asm_309e - ld de, hFFEE -.asm_309e: ; 00:309e + jr z, .PrintNum + ld de, hFFEE ; address if we're talking to a sign + +.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 + 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,213 @@ 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 + +Function3111:: ; 00:3111 + push hl + call PrepareTextbox + ld a, [wce63] + bit 1, a + call nz, PrintTextboxDebugNumbers ; if debug, print text IDs + pop hl + call TextboxIdle + ret + +Function3122:: ; 00:3122 + push hl + call PrepareTextbox + pop hl + +TextboxIdle:: ; 00:3127 + call PrintTextBoxText +.loop + ld a, [wJoypadFlags] + bit 5, a + res 5, a + ld [wJoypadFlags], a + jr nz, .escape ; if bit 5 of joyflags is set, escape + call GetJoypad + ldh a, [hJoyDown] + and A_BUTTON | B_BUTTON + jr nz, .escape ; if A or B are down, 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 + ld hl, $C390 ;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 ;reset this + ld a, $90 + ldh [hWY], a ;set window Y to $90 + call Function318f + ld hl, wToolgearFlags + res 7, [hl] ; show toolgear + call InitToolgearBuffer + ret + +Function318f ; 00:318f + callab Function140ea + call Function0d02 + ret + +TurnNPCTalkingTo:: ; 00:319b + ldh a, [hObjectStructIndexBuffer] + call GetObjectStruct + ld hl, $0000 + add hl, bc ; bc is the address of the a'th object struct + ld a, [hl] + call CheckNonTurningSprite + jr c, .jump ;if it's a non-turning sprite, skip this + ld a, [wPlayerWalking] ; shouldn't this be direction? + xor 04 ; get opposite direction from player + ld hl, $0007 + add hl, bc ; get NPC's direction + ld [hl], a ; overwrite it + push bc + call UpdateSprites + pop bc +.jump + ld hl, $0001 + add hl, bc + ld a, [hl] + sub 02 + ldh [hFFEA], a + ret + +Function31C3:: ; 00:31C3 + ret + +CheckInlineTrainer:: ; 00:31C4 + ; passed de is the start of a map_object struct. if it's an inline trainer, write to relevant wram region. + ld hl, $0000 + add hl, de + ld a, [hl] + call GetObjectStruct ; de is the address of the number of object we want + call $31EB + jr nc, .escape ; if c flag isn't set, leave + ld hl, $000B ; map_object script + add hl, de + ld a, [hl] + cp b + jr c, .escape ;if action is less than b, return + ld hl, $0000 ; obj id + add hl, de + ld a, [hl] + add a, a ; objid*2 + ld hl, wCurrMapInlineTrainers + add a, l + ld l, a + jr nc, .noCarry + inc h +.noCarry + ld [hl], b ; store bc (distance, direction) in new hl + 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, $0010 ; offset for StandingMapX + add hl, bc + ld a, [wPlayerStandingMapX] + cp [hl] + jr z, .equalX ; if player x == object x + ld hl, $0011 ; offset for StandingMapY + add hl, bc + ld a, [wPlayerStandingMapY] + cp [hl] + jr z, .equalY ; if player y == object y and px != ox, jump + and a ; clears c for the ret + ret +.equalX ; player x == object x + ld hl, $0011 + add hl, bc + ld a, [wPlayerStandingMapY] + sub [hl] ; py - oy + jr z, .reset ; if py == oy, jump + jr nc, .setDown ; if py > oy, jump + cpl + inc a + ld b, a + ld c, 01 ; 1 in c means player has smaller Y, same x + scf ; sets c for the ret + ret +.setDown ; 3214 + ld b, a ; b is difference in y + ld c, 00 ; 0 in c means player has bigger Y, same x + scf ; set c + ret +.equalY ; 3219 + ld hl, $0010 + add hl, bc + ld a, [wPlayerStandingMapX] + sub [hl] + jr z, .reset ; if px == ox, jump (this is impossible) + jr nc, .setRight ; if px > ox, jump + cpl + inc a + ld b, a + ld c, 02 ; 2 in c means player has smaller x, equal y + scf + ret +.setRight ; 322C + ld b, a + ld c, 03 ; 3 in c means player has bigger x, equal y scf ret +.reset ; 3231 + and a ; clear c + ret + +CheckAPressedDebug ; 3233 + ld a, [wce63] + bit 1, a + ret z ; return if not debug + ldh a, [hJoyState] + bit A_BUTTON, a + ret + +ClearAccumulator:: ; 323E + xor a ; clear a + ret + +SetFFInAccumulator:: ; 3240 + xor a + dec a + ret + +; 3243
\ No newline at end of file diff --git a/home/unknown_388f.asm b/home/unknown_388f.asm index 453c2f8..bf99129 100644 --- a/home/unknown_388f.asm +++ b/home/unknown_388f.asm @@ -49,19 +49,19 @@ Function38d8:: ld [wd637], a ret -Function38e3:: +TestWildBattleStart:: ldh a, [hJoyState] - and $f0 - ret z - call Function3233 - jp nz, Function323e + and D_PAD + ret z ; if no directions are down, don't try and trigger a wild encounter + call CheckAPressedDebug + jp nz, ClearAccumulator ; if b button is down, clear acc callab Function3ee3e ld a, [wBattleMode] and a - ret z + ret z ; if no battle, return ld a, $3 call WriteIntod637 - call Function3240 + call SetFFInAccumulator ret Function3904:: diff --git a/home/util.asm b/home/util.asm index 880513b..ccc990a 100644 --- a/home/util.asm +++ b/home/util.asm @@ -65,12 +65,13 @@ SkipNames:: ; 341f ret AddNTimes:: ; 3429 (0:3429) +; Adds bc to hl, a times and a ret z -.asm_342b +.loop add hl, bc dec a - jr nz, .asm_342b + jr nz, .loop ret ; 0x3430 diff --git a/home/window.asm b/home/window.asm index c2dc212..9e86453 100644 --- a/home/window.asm +++ b/home/window.asm @@ -17,7 +17,7 @@ RefreshScreen:: ret Function1fea:: - call Function3171 + call TextboxCleanup call ClearWindowData call InitToolgearBuffer ret @@ -1,10 +1,4 @@ ; ROM0 -00:3111 Function3111 -00:3171 Function3171 -00:319B Function319b -00:3233 Function3233 -00:323E Function323e -00:3240 Function3240 00:3CA8 InitSpriteAnimStruct 00:3D86 WaitSFX 00:3D87 WaitSFX.wait @@ -100,6 +94,7 @@ 05:405B AddIndoorSprites 05:40AA AddOutdoorSprites 05:40D9 Function140d9 +05:40EA Function140ea 05:40FB LoadUsedSpritesGfx ; TODO: maybe there's a better name 05:43B6 InitAllSRAMBanks 05:43E0 Function143e0 diff --git a/tools/make_shim.py b/tools/make_shim.py index 65d9362..e2e4bf2 100644 --- a/tools/make_shim.py +++ b/tools/make_shim.py @@ -5,19 +5,19 @@ import argparse from sys import stderr from collections import OrderedDict, namedtuple -Section = namedtuple('Section', ('end', 'invalud', 'banked')) -section_list = OrderedDict( - ROM0=Section(0x4000, False, False), - ROMX=Section(0x8000, False, True), - VRAM=Section(0xA000, False, True), - SRAM=Section(0xC000, False, True), - WRAM0=Section(0xD000, False, False), - WRAMX=Section(0xE000, False, True), - EchoRAM=Section(0xFE00, True, False), - OAM=Section(0xFEA0, False, False), - IO=Section(0xFF80, True, False), - HRAM=Section(0xFFFF, False, False) -) +Section = namedtuple('Section', ('end', 'invalid', 'banked')) +section_list = OrderedDict(( + ('ROM0', Section(0x4000, False, False)), + ('ROMX', Section(0x8000, False, True)), + ('VRAM', Section(0xA000, False, True)), + ('SRAM', Section(0xC000, False, True)), + ('WRAM0', Section(0xD000, False, False)), + ('WRAMX', Section(0xE000, False, True)), + ('EchoRAM', Section(0xFE00, True, False)), + ('OAM', Section(0xFEA0, False, False)), + ('IO', Section(0xFF80, True, False)), + ('HRAM', Section(0xFFFF, False, False)) +)) parser = argparse.ArgumentParser() parser.add_argument('files', nargs='+', type=argparse.FileType()) @@ -28,14 +28,14 @@ args = parser.parse_args() if args.w or args.d: - section_list['WRAM0'].end = 0xE000 + section_list['WRAM0'] = Section(0xE000, *section_list['WRAM0'][1:]) if args.t: - section_list['ROM0'].end = 0x8000 + section_list['ROM0'] = Section(0x8000, *section_list['ROM0'][1:]) -for file_name in args.files: - for line in open(file_name, "rt"): +for f in args.files: + for line in f: # Strip out the comment line = line.split(";")[0].strip() @@ -50,13 +50,13 @@ for file_name in args.files: pointer = int(pointer, 16) except ValueError: print("Error: Cannot parse line: %s" % line, file=stderr) - raise from None + raise section = None for name, section_type in section_list.items(): if pointer < section_type.end: if section_type.invalid: - print("Warning: cannot shim '%s' in section type '%s'" % (symbol, section_type['name']), file=stderr) + print("Warning: cannot shim '%s' in section type '%s'" % (symbol, name), file=stderr) section = False else: section = name @@ -108,7 +108,7 @@ wMapScriptNumber:: db ; c5e8 wMapScriptNumberLocation:: dw ; c5e9 wUnknownMapPointer:: dw ; c5eb ; TODO wc5ed:: db ; c5ed - ds 18 ; TODO + ds 18 wMapBufferEnd:: ; c600 @@ -445,8 +445,9 @@ wcd9e:: db SECTION "CDB0", WRAM0 [$CDB0] -wcdb0:: ; bit 0 = has engaged NPC in dialogue (?) - db +wTalkingTargetType:: db ; cdb0 +;bit 0 = has engaged NPC in dialogue +;bit 1 = has engaged sign in dialogue SECTION "CDBA", WRAM0[$CDBA] @@ -726,10 +727,15 @@ ENDR wCurrMapObjectCount:: ; d5f6 db + +wCurrMapInlineTrainers:: ; d5f7 +REPT 32 ; TODO: confirm this + ds 2 ; inline trainers. each pair of bytes is direction, distance +ENDR SECTION "D637", WRAM0[$D637] -wd637:: db ; d637 -wd638:: db ; d638 +wd637:: db ; d637 ;OW battle state? $3 wild battle, $8 is trainer battle $4 is left battle, $B is load overworld? $0 is in overworld +wd638:: db ; d638 ;wd637's last written-to value SECTION "Used sprites", WRAM0[$D643] |