diff options
-rwxr-xr-x | engine/map_objects.asm | 825 | ||||
-rw-r--r-- | main.asm | 15 |
2 files changed, 825 insertions, 15 deletions
diff --git a/engine/map_objects.asm b/engine/map_objects.asm index 3572435b..12527597 100755 --- a/engine/map_objects.asm +++ b/engine/map_objects.asm @@ -25,7 +25,7 @@ DeleteMapObject:: ; 4358 (1:4358) pop bc ret -Function4442: +Function437c: call .CheckObjectStillVisible ret c call .HandleStepType @@ -639,11 +639,818 @@ Function5558: ; 5558 (1:5558) ld [hl], $ff ret -Function557f:: - dr $557f, $5730 -Function5730:: - dr $5730, $5795 -StopFollow:: - dr $5795, $5896 -UpdateSprites_:: - dr $5896, $58c5 +Function557f:: ; 557f (1:557f) + ld a, [wVramState] + bit 0, a + ret z + ld bc, wPlayerStruct + xor a +.asm_5589 + ld [hConnectionStripLength], a + call DoesObjectHaveASprite + jr z, .asm_5593 + call Function55ef +.asm_5593 + ld hl, $28 + add hl, bc + ld b, h + ld c, l + ld a, [hMapObjectIndexBuffer] + inc a + cp $d + jr nz, .asm_5589 + ret + +Function55a1 + call Function55d8 + ld a, $0 + call Function55bc + ld a, [wd180] + bit 7, a + jr z, .asm_55b8 + ld a, [hLastTalked] + and a + jr z, .asm_55b8 + call Function55bc +.asm_55b8 + call UpdateSprites_ + ret + +Function55bc: ; 55bc (1:55bc) + cp $10 + ret nc + call GetMapObject + ld hl, $0 + add hl, bc + ld a, [hl] + cp $ff + ret z + cp $d + ret nc + call GetObjectStruct + call DoesObjectHaveASprite + ret z + call Function5606 + ret + +Function55d8: ; 55d8 (1:55d8) + xor a + ld bc, wPlayerStruct +.asm_55dc + ld [hMapObjectIndexBuffer], a + call Function5613 + ld hl, $28 + add hl, bc + ld b, h + ld c, l + ld a, [hConnectionStripLength] + inc a + cp $d + jr nz, .asm_55dc + ret + +Function55ef: ; 55ef (1:55ef) + push bc + call Function5660 + pop bc + jr c, Function5613 + call Function5636 + jr c, Function5613 + call Function561b + callba Function4441 ; same bank + xor a + ret + +Function5606: ; 5606 (1:5606) + call Function5636 + jr c, Function5613 + callba Function4441 ; same bank + xor a + ret + +Function5613: ; 5613 (1:5613) + ld hl, $d + add hl, bc + ld [hl], $ff + scf + ret + +Function561b: ; 561b (1:561b) + push bc + ld hl, $10 + add hl, bc + ld d, [hl] + ld hl, $11 + add hl, bc + ld e, [hl] + call GetCoordTile + pop bc + ld hl, $e + add hl, bc + ld [hl], a + callba UpdateGrassPriority ; same bank + ret + +Function5636: ; 5636 (1:5636) + ld hl, $10 + add hl, bc + ld d, [hl] + ld hl, $11 + add hl, bc + ld e, [hl] + inc d + inc e + ld a, [wda03] + cp d + jr z, .asm_564f + jr nc, .asm_565e + add $b + cp d + jr c, .asm_565e +.asm_564f + ld a, [wda02] + cp e + jr z, .asm_565c + jr nc, .asm_565e + add $a + cp e + jr c, .asm_565e +.asm_565c + xor a + ret + +.asm_565e + scf + ret + +Function5660: ; 5660 (1:5660) + ld a, [wce81] + ld d, a + ld hl, $19 + add hl, bc + ld a, [hl] + ld hl, $17 + add hl, bc + add [hl] + add d + cp $f0 + jr nc, .asm_5678 + cp $a0 + jp nc, Function56fb +.asm_5678 + and $7 + ld d, $2 + cp $4 + jr c, .asm_5682 + ld d, $3 +.asm_5682 + ld a, [hl] + srl a + srl a + srl a + cp $14 + jr c, .asm_568f + sub $20 +.asm_568f + ld [hUsedSpriteIndex], a + ld a, [wce82] + ld e, a + ld hl, $1a + add hl, bc + ld a, [hl] + ld hl, $18 + add hl, bc + add [hl] + add e + cp $f0 + jr nc, .asm_56a8 + cp $90 + jr nc, Function56fb +.asm_56a8 + and $7 + ld e, $2 + cp $4 + jr c, .asm_56b2 + ld e, $3 +.asm_56b2 + ld a, [hl] + srl a + srl a + srl a + cp $12 + jr c, .asm_56bf + sub $20 +.asm_56bf + ld [hUsedSpriteTile], a + ld hl, $6 + add hl, bc + bit 7, [hl] + jr z, .asm_56d1 + ld a, d + add $2 + ld d, a + ld a, e + add $2 + ld e, a +.asm_56d1 + ld a, d + ld [hFFC1], a +.asm_56d4 + ld a, [hFFC1] + ld d, a + ld a, [hUsedSpriteTile] + add e + dec a + cp $12 + jr nc, .asm_56f6 + ld b, a +.asm_56e0 + ld a, [hUsedSpriteIndex] + add d + dec a + cp $14 + jr nc, .asm_56f3 + ld c, a + push bc + call Coord2Tile + pop bc + ld a, [hl] + cp $60 + jr nc, Function56fb +.asm_56f3 + dec d + jr nz, .asm_56e0 +.asm_56f6 + dec e + jr nz, .asm_56d4 + and a + ret + +Function56fb: ; 56fb (1:56fb) + scf + ret + +HandleNPCStep:: + call Function5704 + call Function5714 + ret + +Function5704: ; 5704 (1:5704) + xor a + ld [wPlayerStepVectorX], a + ld [wPlayerStepVectorY], a + ld [wPlayerStepFlags], a + ld a, $ff + ld [wPlayerStepDirection], a + ret + +Function5714: ; 5714 (1:5714) + ld bc, wPlayerSprite + xor a +.asm_5718 + ld [hMapObjectIndexBuffer], a + call DoesObjectHaveASprite + jr z, .asm_5722 + call Function437c +.asm_5722 + ld hl, $28 + add hl, bc + ld b, h + ld c, l + ld a, [hConnectionStripLength] + inc a + cp $d + jr nz, .asm_5718 + ret + +Function5730:: ; 5730 (1:5730) + ld a, $3e + ld [wce87], a + ld [wce88], a + xor a + ld [wcf39], a + ld [wPlayerObjectStepFrame], a + call Function574f + callba Function14a44 + call c, Function5770 + call Function5761 + ret + +Function574f: ; 574f (1:574f) + ld hl, wd182 + bit 7, [hl] + jr nz, .asm_575b + bit 6, [hl] + jr nz, .asm_575b + ret + +.asm_575b + ld a, $0 + ld [wPlayerAction], a + ret + +Function5761: ; 5761 (1:5761) + ld hl, wd182 + bit 5, [hl] + ret z + ld a, [wd182] + and $3 + add a + add a + jr asm_5772 + +Function5770: ; 5770 (1:5770) + ld a, $0 +asm_5772 + ld bc, wObjectStructs + call SetSpriteDirection + ret + +StartFollow:: + push bc + ld a, b + call Function578b + pop bc + ret c + ld a, c + call Function57a2 + callba QueueFollowerFirstStep + ret + +Function578b: ; 578b (1:578b) + call CheckObjectVisibility + ret c + ld a, [hObjectStructIndexBuffer] + ld [wObjectFollow_Leader], a + ret + +StopFollow:: ; 5795 (1:5795) + call Function579c + call Function57bd + ret + +Function579c: ; 579c (1:579c) + ld a, $ff + ld [wObjectFollow_Leader], a + ret + +Function57a2: ; 57a2 (1:57a2) + push af + call Function57bd + pop af + call CheckObjectVisibility + ret c + ld hl, $3 + add hl, bc + ld [hl], $13 + ld hl, $9 + add hl, bc + ld [hl], $0 + ld a, [hConnectedMapWidth] + ld [wObjectFollow_Follower], a + ret + +Function57bd: ; 57bd (1:57bd) + ld a, [wObjectFollow_Follower] + cp $ff + ret z + call GetObjectStruct + callba Function5859 ; same bank + ld a, $ff + ld [wObjectFollow_Follower], a + ret + +Function57d2: + ld a, c + call CheckObjectVisibility + ret c + push bc + call Function57f0 + pop bc + ld hl, $5 + add hl, bc + res 5, [hl] + xor a + ret + +Function57e4: + call CheckObjectVisibility + ret c + ld hl, $5 + add hl, bc + set 5, [hl] + xor a + ret + +Function57f0: ; 57f0 (1:57f0) + ld bc, wPlayerStruct + xor a +.asm_57f4 + push af + call DoesObjectHaveASprite + jr z, .asm_5800 + ld hl, $5 + add hl, bc + set 5, [hl] +.asm_5800 + ld hl, $28 + add hl, bc + ld b, h + ld c, l + pop af + inc a + cp $d + jr nz, .asm_57f4 + ret + +Function580d: + ld a, [wObjectFollow_Leader] + cp $ff + ret z + push bc + call GetObjectStruct + ld hl, $1 + add hl, bc + ld a, [hl] + pop bc + cp c + ret nz + ld a, [wObjectFollow_Follower] + cp $ff + ret z + call GetObjectStruct + ld hl, $5 + add hl, bc + res 5, [hl] + ret + +Function582f: + push bc + ld bc, wPlayerSprite + xor a +.asm_5834 + push af + call DoesObjectHaveASprite + jr z, .asm_5840 + ld hl, $5 + add hl, bc + res 5, [hl] +.asm_5840 + ld hl, $28 + add hl, bc + ld b, h + ld c, l + pop af + inc a + cp $d + jr nz, .asm_5834 + pop bc + ret + +Function584e: + call CheckObjectVisibility + ret c + ld hl, $5 + add hl, bc + res 5, [hl] + ret + +Function5859: + ld hl, $1 + add hl, bc + ld a, [hl] + cp $ff + jp z, Function5879 + push bc + call GetMapObject + ld hl, $4 + add hl, bc + ld a, [hl] + pop bc + ld hl, $3 + add hl, bc + ld [hl], a + ld hl, $9 + add hl, bc + ld [hl], $0 + ret + +Function5879: ; 5879 (1:5879) + call GetSpriteDirection + rrca + rrca + ld e, a + ld d, $0 + ld hl, .data + add hl, de + ld a, [hl] + ld hl, $3 + add hl, bc + ld [hl], a + ld hl, $9 + add hl, bc + ld [hl], $0 + ret + +.data db 6,7,8,9 + +UpdateSprites_:: ; 5896 (1:5896) + ld a, [wVramState] + bit 0, a + ret z + xor a + ld [hUsedSpriteIndex], a + ld a, [hOAMUpdate] + push af + ld a, $1 + ld [hOAMUpdate], a + call Function58fe + call Function58b0 + pop af + ld [hOAMUpdate], a + ret + +Function58b0: ; 58b0 (1:58b0) + ld b, $a0 + ld a, [hUsedSpriteIndex] + cp b + ret nc + ld l, a + ld h, wOAMBuffer / $100 + ld de, $4 + ld a, b + ld c, $a0 +.asm_58bf + ld [hl], c + add hl, de + cp l + jr nz, .asm_58bf + ret + +Function58c5:: ; 58c5 (1:58c5) + push hl + push de + push bc + ld a, [wce81] + ld d, a + ld a, [wce82] + ld e, a + ld bc, wPlayerStruct + ld a, $d +.asm_58d5 + push af + call DoesObjectHaveASprite + jr z, .asm_58e9 + ld hl, $17 + add hl, bc + ld a, [hl] + add d + ld [hl], a + ld hl, $18 + add hl, bc + ld a, [hl] + add e + ld [hl], a +.asm_58e9 + ld hl, $28 + add hl, bc + ld b, h + ld c, l + pop af + dec a + jr nz, .asm_58d5 + xor a + ld [wce81], a + ld [wce82], a + pop bc + pop de + pop hl + ret + +Function58fe: ; 58fe (1:58fe) + call Function5911 + ld c, $30 + call Function5960 + ld c, $20 + call Function5960 + ld c, $10 + call Function5960 + ret + +Function5911: ; 5911 (1:5911) + xor a + ld hl, wce94 + ld bc, $d + call ByteFill + ld d, $0 + ld bc, wObjectStructs + ld hl, wce94 +.asm_5923 + push hl + call DoesObjectHaveASprite + jr z, .asm_5946 + ld hl, $d + add hl, bc + ld a, [hl] + cp $ff + jr z, .asm_5946 + ld e, $10 + ld hl, $5 + add hl, bc + bit 0, [hl] + jr nz, .asm_594f + ld e, $20 + bit 1, [hl] + jr z, .asm_594f + ld e, $30 + jr .asm_594f + +.asm_5946 + ld hl, $28 + add hl, bc + ld b, h + ld c, l + pop hl + jr .asm_5959 + +.asm_594f + ld hl, $28 + add hl, bc + ld b, h + ld c, l + pop hl + ld a, d + or e + ld [hli], a +.asm_5959 + inc d + ld a, d + cp $d + jr nz, .asm_5923 + ret + +Function5960: ; 5960 (1:5960) + ld hl, wce94 +.asm_5963 + ld a, [hli] + ld d, a + and $f0 + ret z + cp c + jr nz, .asm_5963 + push bc + push hl + ld a, d + and $f + call Function5a27 + call Function597a + pop hl + pop bc + jr .asm_5963 + +Function597a: ; 597a (1:597a) + xor a + ld hl, $5 + add hl, bc + ld e, [hl] + bit 7, e + jr z, .asm_5986 + or $80 +.asm_5986 + bit 4, e + jr z, .asm_598c + or $10 +.asm_598c + ld hl, $6 + add hl, bc + ld d, a + ld a, [hl] + and $7 + or d + ld d, a + xor a + bit 3, e + jr z, .asm_599d + or $80 +.asm_599d + ld [hFFC4], a + ld hl, $2 + add hl, bc + ld a, [hl] + ld [hFFC3], a + ld hl, $17 + add hl, bc + ld a, [hl] + ld hl, $19 + add hl, bc + add [hl] + add $8 + ld e, a + ld a, [wce81] + add e + ld [hFFC1], a + ld hl, $18 + add hl, bc + ld a, [hl] + ld hl, $1a + add hl, bc + add [hl] + add $c + ld e, a + ld a, [wce82] + add e + ld [hFFC2], a + ld hl, $d + add hl, bc + ld a, [hl] + cp $ff + jp z, .asm_5a23 + cp $20 + jp nc, .asm_5a23 + ld l, a + ld h, $0 + add hl, hl + ld bc, PushOAMEnd + add hl, bc + ld a, [hli] + ld h, [hl] + ld l, a + ld a, [hUsedSpriteIndex] + ld c, a + ld b, $c3 + ld a, [hli] + ld [hUsedSpriteTile], a + add c + cp $a0 + jr nc, .asm_5a25 +.asm_59f3 + ld a, [hFFC2] + add [hl] + inc hl + ld [bc], a + inc c + ld a, [hFFC1] + add [hl] + inc hl + ld [bc], a + inc c + ld e, [hl] + inc hl + ld a, [hFFC3] + bit 2, e + jr z, .asm_5a08 + xor a +.asm_5a08 + add [hl] + inc hl + ld [bc], a + inc c + ld a, e + bit 1, a + jr z, .asm_5a14 + ld a, [hFFC4] + or e +.asm_5a14 + and $f0 + or d + ld [bc], a + inc c + ld a, [hUsedSpriteTile] + dec a + ld [hUsedSpriteTile], a + jr nz, .asm_59f3 + ld a, c + ld [hUsedSpriteIndex], a +.asm_5a23 + xor a + ret + +.asm_5a25 + scf + ret + +Function5a27: ; 5a27 (1:5a27) + ld c, a + ld b, $0 + ld hl, ObjectStructPointers + add hl, bc + add hl, bc + ld c, [hl] + inc hl + ld b, [hl] + ret + +ObjectStructPointers: + dw wPlayerStruct + dw wObject1Struct + dw wObject2Struct + dw wObject3Struct + dw wObject4Struct + dw wObject5Struct + dw wObject6Struct + dw wObject7Struct + dw wObject8Struct + dw wObject9Struct + dw wObject10Struct + dw wObject11Struct + dw wObject12Struct @@ -49,10 +49,9 @@ PushOAMEnd INCLUDE "engine/map_objects.asm" -Function58c5:: - +MainMenu_: ; 5a4d IF DEF(GOLD) - dr $58c5, $6545 + dr $5a4d, $6545 GameInit:: ; 6545 dr $6545, $6551 ReanchorBGMap_NoOAMUpdate:: ; 6551 @@ -70,7 +69,7 @@ CheckNPCMovementPermissions: ; 6fa0 ENDC IF DEF(SILVER) - dr $58c5, $650b + dr $5a4d, $650b GameInit:: ; 650b dr $650b, $6517 ReanchorBGMap_NoOAMUpdate:: ; 6517 @@ -97,7 +96,9 @@ CopyDECoordsToMapObject: CopyObjectStruct_:: dr $86d7, $8876 CopyTempObjectToObjectStruct: - dr $8876, $8ac9 + dr $8876, $8a7a +QueueFollowerFirstStep: + dr $8a7a, $8ac9 Sine_e:: dr $8ac9, $8b3b GetPredefPointer:: @@ -170,7 +171,9 @@ GetSpritePalette_:: ; 14334 Function14a18:: ; 14a18 dr $14a18, $14a2d Function14a2d:: ; 14a2d - dr $14a2d, $15484 + dr $14a2d, $14a44 +Function14a44: ; 14a44 + dr $14a44, $15484 RunMapSetupScript:: dr $15484, $15612 Function15612:: ; 15612 |