From a80832dce09f5da3f8f952b7583a85014ecd1df2 Mon Sep 17 00:00:00 2001 From: IIMarckus Date: Thu, 16 Aug 2018 04:08:15 -0600 Subject: Shuffle around a couple of files to match pokecrystal. --- engine/map_object_action.asm | 260 ------ engine/map_objects.asm | 1456 -------------------------------- engine/movement.asm | 776 ----------------- engine/npc_movement.asm | 525 ------------ engine/overworld/map_object_action.asm | 260 ++++++ engine/overworld/map_objects.asm | 1456 ++++++++++++++++++++++++++++++++ engine/overworld/movement.asm | 776 +++++++++++++++++ engine/overworld/npc_movement.asm | 525 ++++++++++++ engine/overworld/player_movement.asm | 735 ++++++++++++++++ engine/overworld/player_object.asm | 786 +++++++++++++++++ engine/overworld/player_step.asm | 265 ++++++ engine/overworld/time.asm | 378 +++++++++ engine/player_movement.asm | 735 ---------------- engine/player_object.asm | 786 ----------------- engine/player_step.asm | 265 ------ engine/time.asm | 378 --------- 16 files changed, 5181 insertions(+), 5181 deletions(-) delete mode 100755 engine/map_object_action.asm delete mode 100755 engine/map_objects.asm delete mode 100755 engine/movement.asm delete mode 100755 engine/npc_movement.asm create mode 100755 engine/overworld/map_object_action.asm create mode 100755 engine/overworld/map_objects.asm create mode 100755 engine/overworld/movement.asm create mode 100755 engine/overworld/npc_movement.asm create mode 100755 engine/overworld/player_movement.asm create mode 100755 engine/overworld/player_object.asm create mode 100755 engine/overworld/player_step.asm create mode 100755 engine/overworld/time.asm delete mode 100755 engine/player_movement.asm delete mode 100755 engine/player_object.asm delete mode 100755 engine/player_step.asm delete mode 100755 engine/time.asm (limited to 'engine') diff --git a/engine/map_object_action.asm b/engine/map_object_action.asm deleted file mode 100755 index 40499b50..00000000 --- a/engine/map_object_action.asm +++ /dev/null @@ -1,260 +0,0 @@ - ld hl, $b - add hl, bc - ld a, [hl] - ld l, a - ld h, $0 - add hl, hl - add hl, hl - add hl, de - ld a, [hli] - ld h, [hl] - ld l, a - call jp_hl - ret - -Pointers4460: - dw Function44a0, Function44a0 - dw Function44b2, Function44a7 - dw Function44be, Function44a7 - dw Function44e1, Function44a7 - dw Function4502, Function44a7 - dw Function4512, Function44a0 - dw Function4547, Function4547 - dw Function4554, Function44a0 - dw Function455b, Function455b - dw Function4562, Function4562 - dw Function4569, Function457d - dw Function4584, Function44a7 - dw Function4597, Function4597 - dw Function459e, Function459e - dw Function45b3, Function44a0 - dw Function45c6, Function44a0 - -Function44a0 - ld hl, $d - add hl, bc - ld [hl], $ff - ret - -Function44a7: ; 44a7 (1:44a7) - call GetSpriteDirection - or $0 - ld hl, $d - add hl, bc - ld [hl], a - ret - -Function44b2: - ld hl, $d - add hl, bc - ld a, [hl] - and $1 - jr nz, Function44be - jp Function44a7 - -Function44be: - ld hl, $4 - add hl, bc - bit 3, [hl] - jp nz, Function44a7 - ld hl, $c - add hl, bc - ld a, [hl] - inc a - and $f - ld [hl], a - rrca - rrca - and $3 - ld d, a - call GetSpriteDirection - or $0 - or d - ld hl, $d - add hl, bc - ld [hl], a - ret - -Function44e1: - ld hl, $4 - add hl, bc - bit 3, [hl] - jp nz, Function44a7 - ld hl, $c - add hl, bc - inc [hl] - ld a, [hl] - rrca - rrca - rrca - and $3 - ld d, a - call GetSpriteDirection - or $0 - or d - ld hl, $d - add hl, bc - ld [hl], a - ret - -Function4502: - call Function4518 - ld hl, $8 - add hl, bc - ld a, [hl] - or $0 - ld hl, $d - add hl, bc - ld [hl], a - ret - -Function4512: - call Function4518 - jp Function44a0 - -Function4518: ; 4518 (1:4518) - ld hl, $c - add hl, bc - ld a, [hl] - and $f0 - ld e, a - ld a, [hl] - inc a - and $f - ld d, a - cp $4 - jr c, .asm_4531 - ld d, $0 - ld a, e - add $10 - and $30 - ld e, a -.asm_4531 - ld a, d - or e - ld [hl], a - swap e - ld d, $0 - ld hl, .directions - add hl, de - ld a, [hl] - ld hl, $8 - add hl, bc - ld [hl], a - ret - -.directions - db OW_DOWN, OW_RIGHT, OW_UP, OW_LEFT - -Function4547: - call GetSpriteDirection - rrca - rrca - add $10 - ld hl, $d - add hl, bc - ld [hl], a - ret - -Function4554: - ld hl, $d - add hl, bc - ld [hl], $15 - ret - -Function455b: - ld hl, $d - add hl, bc - ld [hl], $14 - ret - -Function4562: - ld hl, $d - add hl, bc - ld [hl], $17 - ret - -Function4569: - ld hl, $c - add hl, bc - ld a, [hl] - inc a - and $f - ld [hl], a - and $8 - jr z, Function457d - ld hl, $d - add hl, bc - ld [hl], $4 - ret - -Function457d: - ld hl, $d - add hl, bc - ld [hl], $0 - ret - -Function4584: - ld hl, $c - add hl, bc - ld a, [hl] - inc a - ld [hl], a - and $c - rrca - rrca - add $18 - ld hl, $d - add hl, bc - ld [hl], a - ret - -Function4597: - ld hl, $d - add hl, bc - ld [hl], $16 - ret - -Function459e: - ld a, [wd558] - ld d, $17 - cp $33 - jr z, .asm_45ad - cp $47 - jr z, .asm_45ad - ld d, $16 -.asm_45ad - ld hl, $d - add hl, bc - ld [hl], d - ret - -Function45b3: - ld hl, $c - add hl, bc - inc [hl] - ld a, [hl] - ld hl, $d - add hl, bc - and $2 - ld a, $1c - jr z, .asm_45c4 - inc a -.asm_45c4 - ld [hl], a - ret - -Function45c6: - ld hl, $c - add hl, bc - inc [hl] - ld a, [hl] - ld hl, $d - add hl, bc - and $4 - ld a, $1e - jr z, .asm_45d7 - inc a -.asm_45d7 - ld [hl], a - ret diff --git a/engine/map_objects.asm b/engine/map_objects.asm deleted file mode 100755 index 20d75238..00000000 --- a/engine/map_objects.asm +++ /dev/null @@ -1,1456 +0,0 @@ -INCLUDE "engine/facings.asm" -SpriteMovementData:: INCLUDE "data/map_objects.asm" - -DeleteMapObject:: ; 4358 (1:4358) - push bc - ld hl, $1 - add hl, bc - ld a, [hl] - push af - ld h, b - ld l, c - ld bc, $28 - xor a - call ByteFill - pop af - cp $ff - jr z, .asm_437a - bit 7, a - jr nz, .asm_437a - call GetMapObject - ld hl, $0 - add hl, bc - ld [hl], $ff -.asm_437a - pop bc - ret - -Function437c: - call .CheckObjectStillVisible - ret c - call .HandleStepType - call .HandleObjectAction - ret - -.CheckObjectStillVisible: ; 4387 (1:4387) - ld hl, $5 - add hl, bc - res 6, [hl] - ld a, [wXCoord] - ld e, a - ld hl, $10 - add hl, bc - ld a, [hl] - add $1 - sub e - jr c, .asm_43b3 - cp $c - jr nc, .asm_43b3 - ld a, [wYCoord] - ld e, a - ld hl, $11 - add hl, bc - ld a, [hl] - add $1 - sub e - jr c, .asm_43b3 - cp $b - jr nc, .asm_43b3 - jr .asm_43dd - -.asm_43b3 - ld hl, $5 - add hl, bc - set 6, [hl] - ld a, [wXCoord] - ld e, a - ld hl, $14 - add hl, bc - ld a, [hl] - add $1 - sub e - jr c, .asm_43df - cp $c - jr nc, .asm_43df - ld a, [wYCoord] - ld e, a - ld hl, $15 - add hl, bc - ld a, [hl] - add $1 - sub e - jr c, .asm_43df - cp $b - jr nc, .asm_43df -.asm_43dd - and a - ret - -.asm_43df - ld hl, $4 - add hl, bc - bit 1, [hl] - jr nz, .asm_43ec - call DeleteMapObject - scf - ret - -.asm_43ec - ld hl, $5 - add hl, bc - set 6, [hl] - and a - ret - -.HandleStepType: ; 43f4 (1:43f4) - ld hl, $9 - add hl, bc - ld a, [hl] - and a - jr z, .asm_440a - ld hl, $5 - add hl, bc - bit 5, [hl] - jr nz, .asm_4427 - cp $1 - jr z, .asm_4415 - jr .asm_4422 - -.asm_440a - call ObjectMovementReset - ld hl, $5 - add hl, bc - bit 5, [hl] - jr nz, .asm_4427 -.asm_4415 - call MapObjectMovementPattern - ld hl, $9 - add hl, bc - ld a, [hl] - and a - ret z - cp $1 - ret z -.asm_4422 - ld hl, StepTypesJumptable - rst JumpTable - ret - -.asm_4427 - ret - -.HandleObjectAction: ; 4428 (1:4428) - ld hl, $4 - add hl, bc - bit 0, [hl] - jr nz, Function44a0 - ld hl, $5 - add hl, bc - bit 6, [hl] - jr nz, Function44a0 - bit 5, [hl] - jr nz, asm_4449 - ld de, Pointers4460 - jr asm_444e - -Function4441: - ld hl, $4 - add hl, bc - bit 0, [hl] - jr nz, Function44a0 -asm_4449 - ld de, Pointers4460 + 2 - jr asm_444e - -asm_444e -INCLUDE "engine/map_object_action.asm" - -CopyNextCoordsTileToStandingCoordsTile: ; 45d9 (1:45d9) - ld hl, $10 - add hl, bc - ld a, [hl] - ld hl, $12 - add hl, bc - ld [hl], a - ld hl, $11 - add hl, bc - ld a, [hl] - ld hl, $13 - add hl, bc - ld [hl], a - ld hl, $e - add hl, bc - ld a, [hl] - ld hl, $f - add hl, bc - ld [hl], a - call SetGrassPriority - ld hl, $e - add hl, bc - ld a, [hl] - call UselessAndA - ret - -Function4603: - ld hl, $12 - add hl, bc - ld a, [hl] - ld hl, $10 - add hl, bc - ld [hl], a - ld hl, $13 - add hl, bc - ld a, [hl] - ld hl, $11 - add hl, bc - ld [hl], a - ret - -UpdateGrassPriority: - ld hl, $5 - add hl, bc - bit 3, [hl] - jr z, .asm_4628 - ld hl, $e - add hl, bc - ld a, [hl] - call SetGrassPriority -.asm_4628 - ld hl, $e - add hl, bc - ld a, [hl] - call UselessAndA - ret c - ld hl, $f - add hl, bc - ld a, [hl] - call UselessAndA - ret - -SetGrassPriority: ; 463a (1:463a) - call CheckSuperTallGrassTile - jr z, .asm_4644 - call CheckGrassTile - jr c, .asm_464b -.asm_4644 - ld hl, $5 - add hl, bc - set 3, [hl] - ret - -.asm_464b - ld hl, $5 - add hl, bc - res 3, [hl] - ret - -UselessAndA: ; 4652 (1:4652) - and a - ret - -EndSpriteMovement: - xor a - ld hl, $c - add hl, bc - ld [hl], a - ld hl, $1b - add hl, bc - ld [hli], a - ld [hli], a - ld [hli], a - ld [hl], a - ld hl, $7 - add hl, bc - ld [hl], $ff - ret - -InitStep: - ld hl, $7 - add hl, bc - ld [hl], a - ld hl, $4 - add hl, bc - bit 2, [hl] - jr nz, GetNextTile - add a - add a - and $c - ld hl, $8 - add hl, bc - ld [hl], a -GetNextTile: - call GetStepVector - ld hl, $a - add hl, bc - ld [hl], a - ld a, d - call GetStepVectorSign - ld hl, $12 - add hl, bc - add [hl] - ld hl, $10 - add hl, bc - ld [hl], a - ld d, a - ld a, e - call GetStepVectorSign - ld hl, $13 - add hl, bc - add [hl] - ld hl, $11 - add hl, bc - ld [hl], a - ld e, a - push bc - call GetCoordTile - pop bc - ld hl, $e - add hl, bc - ld [hl], a - ret - -AddStepVector: ; 46b0 (1:46b0) - call GetStepVector - 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 - ret - -GetStepVector: ; 46c2 (1:46c2) - ld hl, $7 - add hl, bc - ld a, [hl] - and $f - add a - add a - ld l, a - ld h, $0 - ld de, StepVectors - add hl, de - ld d, [hl] - inc hl - ld e, [hl] - inc hl - ld a, [hli] - ld h, [hl] - ret - -StepVectors: ; 46d9 -; x, y, duration, speed - ; slow - db 0, 1, 16, 1 - db 0, -1, 16, 1 - db -1, 0, 16, 1 - db 1, 0, 16, 1 - ; normal - db 0, 2, 8, 2 - db 0, -2, 8, 2 - db -2, 0, 8, 2 - db 2, 0, 8, 2 - ; fast - db 0, 4, 4, 4 - db 0, -4, 4, 4 - db -4, 0, 4, 4 - db 4, 0, 4, 4 - -GetStepVectorSign: ; 4709 (1:4709) - add a - ret z - ld a, $1 - ret nc - ld a, $ff - ret - -UpdatePlayerStep: - ld hl, $7 - add hl, bc - ld a, [hl] - and $3 - ld [wPlayerStepDirection], a - call AddStepVector - ld a, [wPlayerStepVectorX] - add d - ld [wPlayerStepVectorX], a - ld a, [wPlayerStepVectorY] - add e - ld [wPlayerStepVectorY], a - ld hl, wPlayerStepFlags - set 5, [hl] - ret - -Function4732: - push bc - ld e, a - ld d, $0 - ld hl, $1 - add hl, bc - ld a, [hl] - call GetMapObject - add hl, de - ld a, [hl] - pop bc - ret - -INCLUDE "engine/movement_pattern.asm" -INCLUDE "engine/step_types.asm" -INCLUDE "engine/movement.asm" - -Function5429: ; 5429 (1:5429) - call InitStep - ld hl, $1f - add hl, bc - ld [hl], $0 - ld hl, $5 - add hl, bc - res 3, [hl] - ld hl, $b - add hl, bc - ld [hl], $2 - call Function54c8 - ld hl, wCenteredObject - ld a, [hMapObjectIndexBuffer] - cp [hl] - jr z, .asm_5450 - ld hl, $9 - add hl, bc - ld [hl], $8 - ret - -.asm_5450 - ld hl, $9 - add hl, bc - ld [hl], $9 - ret -Function5457: ; 5457 (1:5457) - ld e, a - ld a, [wObjectFollow_Follower] - cp $ff - ret z - ld a, [wObjectFollow_Leader] - ld d, a - ld a, [hMapObjectIndexBuffer] - cp d - ret nz - ld a, e - cp $3e - ret z - cp $47 - ret z - cp $4b - ret z - cp $50 - ret z - cp $8 - ret c - push af - ld hl, wFollowerMovementQueueLength - inc [hl] - ld e, [hl] - ld d, $0 - ld hl, wFollowMovementQueue - add hl, de - pop af - ld [hl], a - ret - -GetFollowerNextMovementByte: - ld hl, wFollowerMovementQueueLength - ld a, [hl] - and a - jr z, .asm_54a2 - cp $ff - jr z, .asm_54a2 - dec [hl] - ld e, a - ld d, $0 - ld hl, wFollowMovementQueue - add hl, de - inc e - ld a, $ff -.asm_549b - ld d, [hl] - ld [hld], a - ld a, d - dec e - jr nz, .asm_549b - ret - -.asm_54a2 - call Function54a9 - ret c - ld a, $3e - ret - -Function54a9: ; 54a9 (1:54a9) - ld a, [wObjectFollow_Leader] - cp $ff - jr z, .asm_54bf - push bc - call GetObjectStruct - ld hl, $0 - add hl, bc - ld a, [hl] - pop bc - and a - jr z, .asm_54bf - and a - ret - -.asm_54bf - ld a, $ff - ld [wObjectFollow_Follower], a - ld a, $47 - scf - ret - -Function54c8: ; 54c8 (1:54c8) - push bc - ld de, .data - call Function5558 - call Function554b - pop bc - ret - -.data db $fc, PAL_OW_SILVER, SPRITEMOVEDATA_SHADOW - -Function54d7: ; 54d7 (1:54d7) - push bc - ld de, .data - call Function5558 - call Function554b - pop bc - ret - -.data db $fe, PAL_OW_SILVER, SPRITEMOVEDATA_BOULDERDUST - -Function54e6: ; 54e6 (1:54e6) - push bc - ld de, .data - call Function5558 - call Function554b - pop bc - ret - -.data db $f8, PAL_OW_SILVER, SPRITEMOVEDATA_EMOTE - -Function54f5: ; 54f5 (1:54f5) - push bc - ld de, .data - call Function5558 - call Function554b - pop bc - ret - -.data db $fe, PAL_OW_TREE, SPRITEMOVEDATA_GRASS - -Function5504: ; 5504 (1:5504) - push bc - push af - ld de, .data - call Function5558 - pop af - ld [wce9e], a - call Function554b - pop bc - ret - -.data db $00, PAL_OW_SILVER, SPRITEMOVEDATA_SCREENSHAKE - -Function5518: ; 5518 (1:5518) - push bc - ld a, [hMapObjectIndexBuffer] - ld c, a - call Function5521 - pop bc - ret - -Function5521: ; 5521 (1:5521) - ld de, wPlayerStruct - ld a, $d -.asm_5526 - push af - ld hl, $4 - add hl, de - bit 7, [hl] - jr z, .asm_5540 - ld hl, $0 - add hl, de - ld a, [hl] - and a - jr z, .asm_5540 - push bc - xor a - ld bc, $28 - call ByteFill - pop bc -.asm_5540 - ld hl, $28 - add hl, de - ld d, h - ld e, l - pop af - dec a - jr nz, .asm_5526 - ret - -Function554b: ; 554b (1:554b) - call FindFirstEmptyObjectStruct - ret nc - ld d, h - ld e, l - callba CopyTempObjectToObjectStruct - ret - -Function5558: ; 5558 (1:5558) - ld hl, wce99 - ld [hl], $ff - inc hl - ld [hl], $ff - inc hl - ld a, [de] - inc de - ld [hli], a - ld a, [de] - inc de - ld [hli], a - ld a, [de] - ld [hli], a - ld a, [hMapObjectIndexBuffer] - ld [hli], a - push hl - ld hl, $10 - add hl, bc - ld d, [hl] - ld hl, $11 - add hl, bc - ld e, [hl] - pop hl - ld [hl], d - inc hl - ld [hl], e - inc hl - ld [hl], $ff - ret - -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, [wXCoord] - cp d - jr z, .asm_564f - jr nc, .asm_565e - add $b - cp d - jr c, .asm_565e -.asm_564f - ld a, [wYCoord] - 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 - -ApplyBGMapAnchorToObjects:: ; 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 diff --git a/engine/movement.asm b/engine/movement.asm deleted file mode 100755 index 74e44cd3..00000000 --- a/engine/movement.asm +++ /dev/null @@ -1,776 +0,0 @@ -GetMovementByte: - ld hl, wMovementDataPointerBank - call GetMovementByte_ - ret - -Function4fbd: - ld hl, $1b - add hl, bc - ld e, [hl] - inc [hl] - ld d, $0 - ld hl, wMovementPerson - ld a, [hli] - ld h, [hl] - ld l, a - add hl, de - ld a, [hl] - ret - -Function4fce: - ld hl, $1b - add hl, bc - ld e, [hl] - inc [hl] - ld d, $0 - ld hl, wce8f - ld a, [hli] - ld h, [hl] - ld l, a - add hl, de - ld a, [hl] - ret - -Function4fdf: ; 4fdf (1:4fdf) - ld hl, GetMovementPerson - jp Function4fe9 - -GetMovementPerson - ld a, [wMovementPerson] - ret - -Function4fe9: ; 4fe9 (1:4fe9) - call Function4ffd -.asm_4fec - xor a - ld [wce93], a - call Function5006 - call Function5013 - ld a, [wce93] - and a - jr nz, .asm_4fec - ret - -Function4ffd: ; 4ffd (1:4ffd) - ld a, l - ld [wce94], a - ld a, h - ld [wce95], a - ret - -Function5006: ; 5006 (1:5006) - ld hl, wce94 - ld a, [hli] - ld h, [hl] - ld l, a - jp hl - -Function500d: ; 500d (1:500d) - ld a, $1 - ld [wce93], a - ret - -Function5013: ; 5013 (1:5013) - push af - call Function5457 - pop af - ld hl, MovementPointers - rst JumpTable - ret - -MovementPointers: ; 501d - dw Function527d - dw Function5281 - dw Function5285 - dw Function5289 - dw Function538f - dw Function5393 - dw Function5397 - dw Function539b - dw Function529f - dw Function52a4 - dw Function52a9 - dw Function52ae - dw Function52b3 - dw Function52b8 - dw Function52bd - dw Function52c2 - dw Function52c7 - dw Function52cc - dw Function52d1 - dw Function52d6 - dw Function5317 - dw Function531c - dw Function5321 - dw Function5326 - dw Function532b - dw Function5330 - dw Function5335 - dw Function533a - dw Function533f - dw Function5344 - dw Function5349 - dw Function534e - dw Function52db - dw Function52e0 - dw Function52e5 - dw Function52ea - dw Function52ef - dw Function52f4 - dw Function52f9 - dw Function52fe - dw Function5303 - dw Function5308 - dw Function530d - dw Function5312 - dw Function5353 - dw Function5358 - dw Function535d - dw Function5362 - dw Function5367 - dw Function536c - dw Function5371 - dw Function5376 - dw Function537b - dw Function5380 - dw Function5385 - dw Function538a - dw Function5232 - dw Function523b - dw Function5244 - dw Function524d - dw Function5256 - dw Function525f - dw Function51c1 - dw Function51c5 - dw Function51c9 - dw Function51cd - dw Function51d1 - dw Function51d5 - dw Function51d9 - dw Function51dd - dw Function51e1 - dw Function5160 - dw Function517a - dw Function519c - dw Function5157 - dw Function51af - dw Function50cf - dw Function50d6 - dw Function50dd - dw Function50e4 - dw Function51fe - dw Function5128 - dw Function514a - dw Function5268 - dw Function526e - dw Function5274 - dw Function5218 - dw Function5135 - dw Function5109 - -Function50cf: ; 50cf (1:50cf) - ld hl, $9 - add hl, bc - ld [hl], $c - ret - -Function50d6: ; 50d6 (1:50d6) - ld hl, $9 - add hl, bc - ld [hl], $d - ret - -Function50dd: ; 50dd (1:50dd) - ld hl, $9 - add hl, bc - ld [hl], $e - ret - -Function50e4: ; 50e4 (1:50e4) - call GetSpriteDirection - rlca - rlca - ld hl, $c - add hl, bc - ld [hl], a - ld hl, $b - add hl, bc - ld [hl], $4 - call Function5006 - ld hl, $a - add hl, bc - ld [hl], a - ld hl, $9 - add hl, bc - ld [hl], $3 - ld hl, $7 - add hl, bc - ld [hl], $ff - ret - -Function5109: ; 5109 (1:5109) - call GetSpriteDirection - rlca - rlca - ld hl, $c - add hl, bc - ld [hl], a - call Function5006 - ld hl, $a - add hl, bc - ld [hl], a - ld hl, $7 - add hl, bc - ld [hl], $ff - ld hl, $9 - add hl, bc - ld [hl], $12 - ret - -Function5128: ; 5128 (1:5128) - ld hl, $b - add hl, bc - ld [hl], $6 - ld hl, $9 - add hl, bc - ld [hl], $10 - ret - -Function5135: ; 5135 (1:5135) - call Function5006 - ld hl, $a - add hl, bc - ld [hl], a - ld hl, $b - add hl, bc - ld [hl], $1 - ld hl, $9 - add hl, bc - ld [hl], $11 - ret - -Function514a: ; 514a (1:514a) - ld hl, $b - add hl, bc - ld [hl], $6 - ld hl, $9 - add hl, bc - ld [hl], $1 - ret - -Function5157: ; 5157 (1:5157) - ld hl, $1b - add hl, bc - ld [hl], $0 - jp Function500d - -Function5160: ; 5160 (1:5160) - call RestoreDefaultMovement - ld hl, $3 - add hl, bc - ld [hl], a - ld hl, $1b - add hl, bc - ld [hl], $0 - ld hl, wVramState - res 7, [hl] - ld hl, $9 - add hl, bc - ld [hl], $1 - ret - -Function517a: ; 517a (1:517a) - call RestoreDefaultMovement - ld hl, $3 - add hl, bc - ld [hl], a - ld hl, $1b - add hl, bc - ld [hl], $0 - call Function5006 - ld hl, $a - add hl, bc - ld [hl], a - ld hl, $9 - add hl, bc - ld [hl], $3 - ld hl, wVramState - res 7, [hl] - ret - -Function519c: ; 519c (1:519c) - call DeleteMapObject - ld hl, wObjectFollow_Leader - ld a, [hMapObjectIndexBuffer] - cp [hl] - jr nz, .asm_51a9 - ld [hl], $ff -.asm_51a9 - ld hl, wVramState - res 7, [hl] - ret - -Function51af: ; 51af (1:51af) - ld hl, $b - add hl, bc - ld [hl], $1 - ld hl, $9 - add hl, bc - ld [hl], $4 - ld hl, wVramState - res 7, [hl] - ret - -Function51c1: ; 51c1 (1:51c1) - ld a, $1 - jr asm_51e6 - -Function51c5: ; 51c5 (1:51c5) - ld a, $2 - jr asm_51e6 - -Function51c9: ; 51c9 (1:51c9) - ld a, $3 - jr asm_51e6 - -Function51cd: ; 51cd (1:51cd) - ld a, $4 - jr asm_51e6 - -Function51d1: ; 51d1 (1:51d1) - ld a, $5 - jr asm_51e6 - -Function51d5: ; 51d5 (1:51d5) - ld a, $6 - jr asm_51e6 - -Function51d9: ; 51d9 (1:51d9) - ld a, $7 - jr asm_51e6 - -Function51dd: ; 51dd (1:51dd) - ld a, $8 - jr asm_51e6 - -Function51e1: ; 51e1 (1:51e1) - call Function5006 - jr asm_51e6 - -asm_51e6 - ld hl, $a - add hl, bc - ld [hl], a - ld hl, $9 - add hl, bc - ld [hl], $3 - ld hl, $b - add hl, bc - ld [hl], $1 - ld hl, $7 - add hl, bc - ld [hl], $ff - ret - -Function51fe: ; 51fe (1:51fe) - ld a, $1 - ld hl, $a - add hl, bc - ld [hl], a - ld hl, $9 - add hl, bc - ld [hl], $b - ld hl, $b - add hl, bc - ld [hl], $3 - ld hl, $7 - add hl, bc - ld [hl], $ff - ret - -Function5218: ; 5218 (1:5218) - ld a, $18 - ld hl, $a - add hl, bc - ld [hl], a - ld hl, $9 - add hl, bc - ld [hl], $3 - ld hl, $b - add hl, bc - ld [hl], $b - ld hl, $7 - add hl, bc - ld [hl], $ff - ret - -Function5232: ; 5232 (1:5232) - ld hl, $4 - add hl, bc - res 3, [hl] - jp Function500d - -Function523b: ; 523b (1:523b) - ld hl, $4 - add hl, bc - set 3, [hl] - jp Function500d - -Function5244: ; 5244 (1:5244) - ld hl, $4 - add hl, bc - res 2, [hl] - jp Function500d - -Function524d: ; 524d (1:524d) - ld hl, $4 - add hl, bc - set 2, [hl] - jp Function500d - -Function5256: ; 5256 (1:5256) - ld hl, $4 - add hl, bc - res 0, [hl] - jp Function500d - -Function525f: ; 525f (1:525f) - ld hl, $4 - add hl, bc - set 0, [hl] - jp Function500d - -Function5268: ; 5268 (1:5268) - call Function5518 - jp Function500d - -Function526e: ; 526e (1:526e) - call Function54e6 - jp Function500d - -Function5274: ; 5274 (1:5274) - call Function5006 - call Function5504 - jp Function500d - -Function527d: ; 527d (1:527d) - ld a, $0 - jr asm_528d - -Function5281: ; 5281 (1:5281) - ld a, $4 - jr asm_528d - -Function5285: ; 5285 (1:5285) - ld a, $8 - jr asm_528d - -Function5289: ; 5289 (1:5289) - ld a, $c - jr asm_528d - -asm_528d - ld hl, $8 - add hl, bc - ld [hl], a - ld hl, $b - add hl, bc - ld [hl], $1 - ld hl, $7 - add hl, bc - ld [hl], $ff - ret - -Function529f: ; 529f (1:529f) - ld a, $0 - jp Function53b1 - -Function52a4: ; 52a4 (1:52a4) - ld a, $1 - jp Function53b1 - -Function52a9: ; 52a9 (1:52a9) - ld a, $2 - jp Function53b1 - -Function52ae: ; 52ae (1:52ae) - ld a, $3 - jp Function53b1 - -Function52b3: ; 52b3 (1:52b3) - ld a, $4 - jp Function53b1 - -Function52b8: ; 52b8 (1:52b8) - ld a, $5 - jp Function53b1 - -Function52bd: ; 52bd (1:52bd) - ld a, $6 - jp Function53b1 - -Function52c2: ; 52c2 (1:52c2) - ld a, $7 - jp Function53b1 - -Function52c7: ; 52c7 (1:52c7) - ld a, $8 - jp Function53b1 - -Function52cc: ; 52cc (1:52cc) - ld a, $9 - jp Function53b1 - -Function52d1: ; 52d1 (1:52d1) - ld a, $a - jp Function53b1 - -Function52d6: ; 52d6 (1:52d6) - ld a, $b - jp Function53b1 - -Function52db: ; 52db (1:52db) - ld a, $0 - jp Function53e5 - -Function52e0: ; 52e0 (1:52e0) - ld a, $1 - jp Function53e5 - -Function52e5: ; 52e5 (1:52e5) - ld a, $2 - jp Function53e5 - -Function52ea: ; 52ea (1:52ea) - ld a, $3 - jp Function53e5 - -Function52ef: ; 52ef (1:52ef) - ld a, $4 - jp Function53e5 - -Function52f4: ; 52f4 (1:52f4) - ld a, $5 - jp Function53e5 - -Function52f9: ; 52f9 (1:52f9) - ld a, $6 - jp Function53e5 - -Function52fe: ; 52fe (1:52fe) - ld a, $7 - jp Function53e5 - -Function5303: ; 5303 (1:5303) - ld a, $8 - jp Function53e5 - -Function5308: ; 5308 (1:5308) - ld a, $9 - jp Function53e5 - -Function530d: ; 530d (1:530d) - ld a, $a - jp Function53e5 - -Function5312: ; 5312 (1:5312) - ld a, $b - jp Function53e5 - -Function5317: ; 5317 (1:5317) - ld a, $0 - jp Function5407 - -Function531c: ; 531c (1:531c) - ld a, $1 - jp Function5407 - -Function5321: ; 5321 (1:5321) - ld a, $2 - jp Function5407 - -Function5326: ; 5326 (1:5326) - ld a, $3 - jp Function5407 - -Function532b: ; 532b (1:532b) - ld a, $4 - jp Function5407 - -Function5330: ; 5330 (1:5330) - ld a, $5 - jp Function5407 - -Function5335: ; 5335 (1:5335) - ld a, $6 - jp Function5407 - -Function533a: ; 533a (1:533a) - ld a, $7 - jp Function5407 - -Function533f: ; 533f (1:533f) - ld a, $8 - jp Function5407 - -Function5344: ; 5344 (1:5344) - ld a, $9 - jp Function5407 - -Function5349: ; 5349 (1:5349) - ld a, $a - jp Function5407 - -Function534e: ; 534e (1:534e) - ld a, $b - jp Function5407 - -Function5353: ; 5353 (1:5353) - ld a, $0 - jp Function5429 - -Function5358: ; 5358 (1:5358) - ld a, $1 - jp Function5429 - -Function535d: ; 535d (1:535d) - ld a, $2 - jp Function5429 - -Function5362: ; 5362 (1:5362) - ld a, $3 - jp Function5429 - -Function5367: ; 5367 (1:5367) - ld a, $4 - jp Function5429 - -Function536c: ; 536c (1:536c) - ld a, $5 - jp Function5429 - -Function5371: ; 5371 (1:5371) - ld a, $6 - jp Function5429 - -Function5376: ; 5376 (1:5376) - ld a, $7 - jp Function5429 - -Function537b: ; 537b (1:537b) - ld a, $8 - jp Function5429 - -Function5380: ; 5380 (1:5380) - ld a, $9 - jp Function5429 - -Function5385: ; 5385 (1:5385) - ld a, $a - jp Function5429 - -Function538a: ; 538a (1:538a) - ld a, $b - jp Function5429 - -Function538f: ; 538f (1:538f) - ld a, $0 - jr asm_539f - -Function5393: ; 5393 (1:5393) - ld a, $4 - jr asm_539f - -Function5397: ; 5397 (1:5397) - ld a, $8 - jr asm_539f - -Function539b: ; 539b (1:539b) - ld a, $c - jr asm_539f - -asm_539f - ld hl, $1d - add hl, bc - ld [hl], a - ld hl, $b - add hl, bc - ld [hl], $2 - ld hl, $9 - add hl, bc - ld [hl], $a - ret - -Function53b1: ; 53b1 (1:53b1) - call InitStep - call UpdateGrassPriority - ld hl, $b - add hl, bc - ld [hl], $2 - ld hl, $e - add hl, bc - ld a, [hl] - call CheckSuperTallGrassTile - jr z, .asm_53cc - call CheckGrassTile - jr c, .asm_53cf -.asm_53cc - call Function54f5 -.asm_53cf - ld hl, wCenteredObject - ld a, [hConnectionStripLength] - cp [hl] - jr z, .asm_53de - ld hl, $9 - add hl, bc - ld [hl], $2 - ret - -.asm_53de - ld hl, $9 - add hl, bc - ld [hl], $6 - ret - -Function53e5: ; 53e5 (1:53e5) - call InitStep - call UpdateGrassPriority - ld hl, $b - add hl, bc - ld [hl], $4 - ld hl, wCenteredObject - ld a, [hMapObjectIndexBuffer] - cp [hl] - jr z, .asm_5400 - ld hl, $9 - add hl, bc - ld [hl], $2 - ret - -.asm_5400 - ld hl, $9 - add hl, bc - ld [hl], $6 - ret - -Function5407: ; 5407 (1:5407) - call InitStep - call UpdateGrassPriority - ld hl, $b - add hl, bc - ld [hl], $1 - ld hl, wCenteredObject - ld a, [hConnectionStripLength] - cp [hl] - jr z, .asm_5422 - ld hl, $9 - add hl, bc - ld [hl], $2 - ret - -.asm_5422 - ld hl, $9 - add hl, bc - ld [hl], $6 - ret diff --git a/engine/npc_movement.asm b/engine/npc_movement.asm deleted file mode 100755 index e776402a..00000000 --- a/engine/npc_movement.asm +++ /dev/null @@ -1,525 +0,0 @@ -CheckNPCMovementPermissions: ; 6fa0 (1:6fa0) - ld hl, $6 - add hl, bc - bit 5, [hl] - jr z, .asm_6fb8 - ld hl, $4 - add hl, bc - bit 4, [hl] - push hl - push bc - call Function700b - pop bc - pop hl - ret c - jr .asm_6fc8 - -.asm_6fb8 - ld hl, $4 - add hl, bc - bit 4, [hl] - jr nz, .asm_6fc8 - push hl - push bc - call Function6fe6 - pop bc - pop hl - ret c -.asm_6fc8 - bit 6, [hl] - jr nz, .asm_6fd4 - push hl - push bc - call WillPersonBumpIntoSomeoneElse - pop bc - pop hl - ret c -.asm_6fd4 - bit 5, [hl] - jr nz, .asm_6fe4 - push hl - call HasPersonReachedMovementLimit - pop hl - ret c - push hl - call IsPersonMovingOffEdgeOfScreen - pop hl - ret c -.asm_6fe4 - and a - ret - -Function6fe6: ; 6fe6 (1:6fe6) - call Function703e - ret c - ld hl, $10 - add hl, bc - ld d, [hl] - ld hl, $11 - add hl, bc - ld e, [hl] - ld hl, $6 - add hl, bc - bit 7, [hl] - jp nz, Function7080 - ld hl, $e - add hl, bc - ld a, [hl] - ld d, a - call GetTileCollision - and a - jr z, Function701d - scf - ret - -Function700b: ; 700b (1:700b) - call Function703e - ret c - ld hl, $e - add hl, bc - ld a, [hl] - call GetTileCollision - cp $1 - jr z, Function701d - scf - ret - -Function701d - ld hl, $e - add hl, bc - ld a, [hl] - call Function705e - ret nc - push af - ld hl, $7 - add hl, bc - ld a, [hl] - and $3 - ld e, a - ld d, $0 - ld hl, .data_703a - add hl, de - pop af - and [hl] - ret z - scf - ret - -.data_703a - db 1 << DOWN, 1 << UP, 1 << RIGHT, 1 << LEFT - -Function703e: ; 703e (1:703e) - ld hl, $f - add hl, bc - ld a, [hl] - call Function705e - ret nc - push af - ld hl, $7 - add hl, bc - and $3 - ld e, a - ld d, $0 - ld hl, .data_705a - add hl, de - pop af - and [hl] - ret z - scf - ret - -.data_705a - db 1 << UP, 1 << DOWN, 1 << LEFT, 1 << RIGHT - -Function705e: ; 705e (1:705e) - ld d, a - and $f0 - cp $b0 - jr z, .asm_706b - cp $c0 - jr z, .asm_706b - xor a - ret - -.asm_706b - ld a, d - and $7 - ld e, a - ld d, $0 - ld hl, .data_7078 - add hl, de - ld a, [hl] - scf - ret - -.data_7078 - db 8, 4, 1, 2 - db 10, 6, 9, 5 - -Function7080: ; 7080 (1:7080) - ld hl, $7 - add hl, bc - ld a, [hl] - and $3 - jr z, .asm_7091 - dec a - jr z, .asm_7096 - dec a - jr z, .asm_709a - jr .asm_709e - -.asm_7091 - inc e - push de - inc d - jr .asm_70a1 - -.asm_7096 - push de - inc d - jr .asm_70a1 - -.asm_709a - push de - inc e - jr .asm_70a1 - -.asm_709e - inc d - push de - inc e -.asm_70a1 - call GetCoordTile - call GetTileCollision - pop de - and a - jr nz, .asm_70b6 - call GetCoordTile - call GetTileCollision - and a - jr nz, .asm_70b6 - xor a - ret - -.asm_70b6 - scf - ret - -CheckFacingObject: - call GetFacingTileCoord - call CheckCounterTile - jr nz, .asm_70d0 - ld a, [wPlayerStandingMapX] - sub d - cpl - inc a - add d - ld d, a - ld a, [wPlayerStandingMapY] - sub e - cpl - inc a - add e - ld e, a -.asm_70d0 - ld bc, wObjectStructs - ld a, $0 - ld [hMapObjectIndexBuffer], a - call Function7120 - ret nc - ld hl, $7 - add hl, bc - ld a, [hl] - cp $ff - jr z, .asm_70e6 - xor a - ret - -.asm_70e6 - scf - ret - -WillPersonBumpIntoSomeoneElse: ; 70e8 (1:70e8) - ld hl, $10 - add hl, bc - ld d, [hl] - ld hl, $11 - add hl, bc - ld e, [hl] - jr Function7120 - -Function70f4: - ld a, [hMapObjectIndexBuffer] - call GetObjectStruct - call Function7100 - call Function7120 - ret - -Function7100: ; 7100 (1:7100) - ld hl, $10 - add hl, bc - ld d, [hl] - ld hl, $11 - add hl, bc - ld e, [hl] - call GetSpriteDirection - and a - jr z, .asm_711a - cp $4 - jr z, .asm_711c - cp $8 - jr z, .asm_711e - inc d - ret - -.asm_711a - inc e - ret - -.asm_711c - dec e - ret - -.asm_711e - dec d - ret - -Function7120: ; 7120 (1:7120) - ld bc, wPlayerStruct - xor a -.asm_7124 - ld [hObjectStructIndexBuffer], a - call DoesObjectHaveASprite - jr z, .asm_7172 - ld hl, $4 - add hl, bc - bit 7, [hl] - jr nz, .asm_7172 - ld hl, $6 - add hl, bc - bit 7, [hl] - jr z, .asm_7142 - call Function7250 - jr nc, .asm_715a - jr .asm_7152 - -.asm_7142 - ld hl, $10 - add hl, bc - ld a, [hl] - cp d - jr nz, .asm_715a - ld hl, $11 - add hl, bc - ld a, [hl] - cp e - jr nz, .asm_715a -.asm_7152 - ld a, [hMapObjectIndexBuffer] - ld l, a - ld a, [hConnectedMapWidth] - cp l - jr nz, .asm_7181 -.asm_715a - ld hl, $12 - add hl, bc - ld a, [hl] - cp d - jr nz, .asm_7172 - ld hl, $13 - add hl, bc - ld a, [hl] - cp e - jr nz, .asm_7172 - ld a, [hConnectionStripLength] - ld l, a - ld a, [hObjectStructIndexBuffer] - cp l - jr nz, .asm_7181 -.asm_7172 - ld hl, $28 - add hl, bc - ld b, h - ld c, l - ld a, [hConnectedMapWidth] - inc a - cp $d - jr nz, .asm_7124 - and a - ret - -.asm_7181 - scf - ret - -HasPersonReachedMovementLimit: ; 7183 (1:7183) - ld hl, $16 - add hl, bc - ld a, [hl] - and a - jr z, .asm_71c8 - and $f - jr z, .asm_71a6 - ld e, a - ld d, a - ld hl, $14 - add hl, bc - ld a, [hl] - sub d - ld d, a - ld a, [hl] - add e - ld e, a - ld hl, $10 - add hl, bc - ld a, [hl] - cp d - jr z, .asm_71ca - cp e - jr z, .asm_71ca -.asm_71a6 - ld hl, $16 - add hl, bc - ld a, [hl] - swap a - and $f - jr z, .asm_71c8 - ld e, a - ld d, a - ld hl, $15 - add hl, bc - ld a, [hl] - sub d - ld d, a - ld a, [hl] - add e - ld e, a - ld hl, $11 - add hl, bc - ld a, [hl] - cp d - jr z, .asm_71ca - cp e - jr z, .asm_71ca -.asm_71c8 - xor a - ret - -.asm_71ca - scf - ret - -IsPersonMovingOffEdgeOfScreen: ; 71cc (1:71cc) - ld hl, $10 - add hl, bc - ld a, [wXCoord] - cp [hl] - jr z, .asm_71dd - jr nc, .asm_71f0 - add $9 - cp [hl] - jr c, .asm_71f0 -.asm_71dd - ld hl, $11 - add hl, bc - ld a, [wYCoord] - cp [hl] - jr z, .asm_71ee - jr nc, .asm_71f0 - add $8 - cp [hl] - jr c, .asm_71f0 -.asm_71ee - and a - ret - -.asm_71f0 - scf - ret - -Function71f2 - ld a, [wPlayerStandingMapX] - ld d, a - ld a, [wPlayerStandingMapY] - ld e, a - ld bc, wObjectStructs - xor a -.asm_71fe - ld [hConnectedMapWidth], a - call DoesObjectHaveASprite - jr z, .asm_723f - ld hl, $3 - add hl, bc - ld a, [hl] - cp $15 - jr nz, .asm_7215 - call Function7250 - jr c, .asm_724e - jr .asm_723f - -.asm_7215 - ld hl, $11 - add hl, bc - ld a, [hl] - cp e - jr nz, .asm_722d - ld hl, $10 - add hl, bc - ld a, [hl] - cp d - jr nz, .asm_722d - ld a, [hObjectStructIndexBuffer] - cp $0 - jr z, .asm_723f - jr .asm_724e - -.asm_722d - ld hl, $13 - add hl, bc - ld a, [hl] - cp e - jr nz, .asm_723f - ld hl, $12 - add hl, bc - ld a, [hl] - cp d - jr nz, .asm_723f - jr .asm_724e - -.asm_723f - ld hl, $28 - add hl, bc - ld b, h - ld c, l - ld a, [hConnectedMapWidth] - inc a - cp $d - jr nz, .asm_71fe - xor a - ret - -.asm_724e - scf - ret - -Function7250: ; 7250 (1:7250) - ld hl, $10 - add hl, bc - ld a, d - sub [hl] - jr c, .asm_726a - cp $2 - jr nc, .asm_726a - ld hl, $11 - add hl, bc - ld a, e - sub [hl] - jr c, .asm_726a - cp $2 - jr nc, .asm_726a - scf - ret - -.asm_726a - and a - ret diff --git a/engine/overworld/map_object_action.asm b/engine/overworld/map_object_action.asm new file mode 100755 index 00000000..40499b50 --- /dev/null +++ b/engine/overworld/map_object_action.asm @@ -0,0 +1,260 @@ + ld hl, $b + add hl, bc + ld a, [hl] + ld l, a + ld h, $0 + add hl, hl + add hl, hl + add hl, de + ld a, [hli] + ld h, [hl] + ld l, a + call jp_hl + ret + +Pointers4460: + dw Function44a0, Function44a0 + dw Function44b2, Function44a7 + dw Function44be, Function44a7 + dw Function44e1, Function44a7 + dw Function4502, Function44a7 + dw Function4512, Function44a0 + dw Function4547, Function4547 + dw Function4554, Function44a0 + dw Function455b, Function455b + dw Function4562, Function4562 + dw Function4569, Function457d + dw Function4584, Function44a7 + dw Function4597, Function4597 + dw Function459e, Function459e + dw Function45b3, Function44a0 + dw Function45c6, Function44a0 + +Function44a0 + ld hl, $d + add hl, bc + ld [hl], $ff + ret + +Function44a7: ; 44a7 (1:44a7) + call GetSpriteDirection + or $0 + ld hl, $d + add hl, bc + ld [hl], a + ret + +Function44b2: + ld hl, $d + add hl, bc + ld a, [hl] + and $1 + jr nz, Function44be + jp Function44a7 + +Function44be: + ld hl, $4 + add hl, bc + bit 3, [hl] + jp nz, Function44a7 + ld hl, $c + add hl, bc + ld a, [hl] + inc a + and $f + ld [hl], a + rrca + rrca + and $3 + ld d, a + call GetSpriteDirection + or $0 + or d + ld hl, $d + add hl, bc + ld [hl], a + ret + +Function44e1: + ld hl, $4 + add hl, bc + bit 3, [hl] + jp nz, Function44a7 + ld hl, $c + add hl, bc + inc [hl] + ld a, [hl] + rrca + rrca + rrca + and $3 + ld d, a + call GetSpriteDirection + or $0 + or d + ld hl, $d + add hl, bc + ld [hl], a + ret + +Function4502: + call Function4518 + ld hl, $8 + add hl, bc + ld a, [hl] + or $0 + ld hl, $d + add hl, bc + ld [hl], a + ret + +Function4512: + call Function4518 + jp Function44a0 + +Function4518: ; 4518 (1:4518) + ld hl, $c + add hl, bc + ld a, [hl] + and $f0 + ld e, a + ld a, [hl] + inc a + and $f + ld d, a + cp $4 + jr c, .asm_4531 + ld d, $0 + ld a, e + add $10 + and $30 + ld e, a +.asm_4531 + ld a, d + or e + ld [hl], a + swap e + ld d, $0 + ld hl, .directions + add hl, de + ld a, [hl] + ld hl, $8 + add hl, bc + ld [hl], a + ret + +.directions + db OW_DOWN, OW_RIGHT, OW_UP, OW_LEFT + +Function4547: + call GetSpriteDirection + rrca + rrca + add $10 + ld hl, $d + add hl, bc + ld [hl], a + ret + +Function4554: + ld hl, $d + add hl, bc + ld [hl], $15 + ret + +Function455b: + ld hl, $d + add hl, bc + ld [hl], $14 + ret + +Function4562: + ld hl, $d + add hl, bc + ld [hl], $17 + ret + +Function4569: + ld hl, $c + add hl, bc + ld a, [hl] + inc a + and $f + ld [hl], a + and $8 + jr z, Function457d + ld hl, $d + add hl, bc + ld [hl], $4 + ret + +Function457d: + ld hl, $d + add hl, bc + ld [hl], $0 + ret + +Function4584: + ld hl, $c + add hl, bc + ld a, [hl] + inc a + ld [hl], a + and $c + rrca + rrca + add $18 + ld hl, $d + add hl, bc + ld [hl], a + ret + +Function4597: + ld hl, $d + add hl, bc + ld [hl], $16 + ret + +Function459e: + ld a, [wd558] + ld d, $17 + cp $33 + jr z, .asm_45ad + cp $47 + jr z, .asm_45ad + ld d, $16 +.asm_45ad + ld hl, $d + add hl, bc + ld [hl], d + ret + +Function45b3: + ld hl, $c + add hl, bc + inc [hl] + ld a, [hl] + ld hl, $d + add hl, bc + and $2 + ld a, $1c + jr z, .asm_45c4 + inc a +.asm_45c4 + ld [hl], a + ret + +Function45c6: + ld hl, $c + add hl, bc + inc [hl] + ld a, [hl] + ld hl, $d + add hl, bc + and $4 + ld a, $1e + jr z, .asm_45d7 + inc a +.asm_45d7 + ld [hl], a + ret diff --git a/engine/overworld/map_objects.asm b/engine/overworld/map_objects.asm new file mode 100755 index 00000000..1c118ed6 --- /dev/null +++ b/engine/overworld/map_objects.asm @@ -0,0 +1,1456 @@ +INCLUDE "engine/facings.asm" +SpriteMovementData:: INCLUDE "data/map_objects.asm" + +DeleteMapObject:: ; 4358 (1:4358) + push bc + ld hl, $1 + add hl, bc + ld a, [hl] + push af + ld h, b + ld l, c + ld bc, $28 + xor a + call ByteFill + pop af + cp $ff + jr z, .asm_437a + bit 7, a + jr nz, .asm_437a + call GetMapObject + ld hl, $0 + add hl, bc + ld [hl], $ff +.asm_437a + pop bc + ret + +Function437c: + call .CheckObjectStillVisible + ret c + call .HandleStepType + call .HandleObjectAction + ret + +.CheckObjectStillVisible: ; 4387 (1:4387) + ld hl, $5 + add hl, bc + res 6, [hl] + ld a, [wXCoord] + ld e, a + ld hl, $10 + add hl, bc + ld a, [hl] + add $1 + sub e + jr c, .asm_43b3 + cp $c + jr nc, .asm_43b3 + ld a, [wYCoord] + ld e, a + ld hl, $11 + add hl, bc + ld a, [hl] + add $1 + sub e + jr c, .asm_43b3 + cp $b + jr nc, .asm_43b3 + jr .asm_43dd + +.asm_43b3 + ld hl, $5 + add hl, bc + set 6, [hl] + ld a, [wXCoord] + ld e, a + ld hl, $14 + add hl, bc + ld a, [hl] + add $1 + sub e + jr c, .asm_43df + cp $c + jr nc, .asm_43df + ld a, [wYCoord] + ld e, a + ld hl, $15 + add hl, bc + ld a, [hl] + add $1 + sub e + jr c, .asm_43df + cp $b + jr nc, .asm_43df +.asm_43dd + and a + ret + +.asm_43df + ld hl, $4 + add hl, bc + bit 1, [hl] + jr nz, .asm_43ec + call DeleteMapObject + scf + ret + +.asm_43ec + ld hl, $5 + add hl, bc + set 6, [hl] + and a + ret + +.HandleStepType: ; 43f4 (1:43f4) + ld hl, $9 + add hl, bc + ld a, [hl] + and a + jr z, .asm_440a + ld hl, $5 + add hl, bc + bit 5, [hl] + jr nz, .asm_4427 + cp $1 + jr z, .asm_4415 + jr .asm_4422 + +.asm_440a + call ObjectMovementReset + ld hl, $5 + add hl, bc + bit 5, [hl] + jr nz, .asm_4427 +.asm_4415 + call MapObjectMovementPattern + ld hl, $9 + add hl, bc + ld a, [hl] + and a + ret z + cp $1 + ret z +.asm_4422 + ld hl, StepTypesJumptable + rst JumpTable + ret + +.asm_4427 + ret + +.HandleObjectAction: ; 4428 (1:4428) + ld hl, $4 + add hl, bc + bit 0, [hl] + jr nz, Function44a0 + ld hl, $5 + add hl, bc + bit 6, [hl] + jr nz, Function44a0 + bit 5, [hl] + jr nz, asm_4449 + ld de, Pointers4460 + jr asm_444e + +Function4441: + ld hl, $4 + add hl, bc + bit 0, [hl] + jr nz, Function44a0 +asm_4449 + ld de, Pointers4460 + 2 + jr asm_444e + +asm_444e +INCLUDE "engine/overworld/map_object_action.asm" + +CopyNextCoordsTileToStandingCoordsTile: ; 45d9 (1:45d9) + ld hl, $10 + add hl, bc + ld a, [hl] + ld hl, $12 + add hl, bc + ld [hl], a + ld hl, $11 + add hl, bc + ld a, [hl] + ld hl, $13 + add hl, bc + ld [hl], a + ld hl, $e + add hl, bc + ld a, [hl] + ld hl, $f + add hl, bc + ld [hl], a + call SetGrassPriority + ld hl, $e + add hl, bc + ld a, [hl] + call UselessAndA + ret + +Function4603: + ld hl, $12 + add hl, bc + ld a, [hl] + ld hl, $10 + add hl, bc + ld [hl], a + ld hl, $13 + add hl, bc + ld a, [hl] + ld hl, $11 + add hl, bc + ld [hl], a + ret + +UpdateGrassPriority: + ld hl, $5 + add hl, bc + bit 3, [hl] + jr z, .asm_4628 + ld hl, $e + add hl, bc + ld a, [hl] + call SetGrassPriority +.asm_4628 + ld hl, $e + add hl, bc + ld a, [hl] + call UselessAndA + ret c + ld hl, $f + add hl, bc + ld a, [hl] + call UselessAndA + ret + +SetGrassPriority: ; 463a (1:463a) + call CheckSuperTallGrassTile + jr z, .asm_4644 + call CheckGrassTile + jr c, .asm_464b +.asm_4644 + ld hl, $5 + add hl, bc + set 3, [hl] + ret + +.asm_464b + ld hl, $5 + add hl, bc + res 3, [hl] + ret + +UselessAndA: ; 4652 (1:4652) + and a + ret + +EndSpriteMovement: + xor a + ld hl, $c + add hl, bc + ld [hl], a + ld hl, $1b + add hl, bc + ld [hli], a + ld [hli], a + ld [hli], a + ld [hl], a + ld hl, $7 + add hl, bc + ld [hl], $ff + ret + +InitStep: + ld hl, $7 + add hl, bc + ld [hl], a + ld hl, $4 + add hl, bc + bit 2, [hl] + jr nz, GetNextTile + add a + add a + and $c + ld hl, $8 + add hl, bc + ld [hl], a +GetNextTile: + call GetStepVector + ld hl, $a + add hl, bc + ld [hl], a + ld a, d + call GetStepVectorSign + ld hl, $12 + add hl, bc + add [hl] + ld hl, $10 + add hl, bc + ld [hl], a + ld d, a + ld a, e + call GetStepVectorSign + ld hl, $13 + add hl, bc + add [hl] + ld hl, $11 + add hl, bc + ld [hl], a + ld e, a + push bc + call GetCoordTile + pop bc + ld hl, $e + add hl, bc + ld [hl], a + ret + +AddStepVector: ; 46b0 (1:46b0) + call GetStepVector + 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 + ret + +GetStepVector: ; 46c2 (1:46c2) + ld hl, $7 + add hl, bc + ld a, [hl] + and $f + add a + add a + ld l, a + ld h, $0 + ld de, StepVectors + add hl, de + ld d, [hl] + inc hl + ld e, [hl] + inc hl + ld a, [hli] + ld h, [hl] + ret + +StepVectors: ; 46d9 +; x, y, duration, speed + ; slow + db 0, 1, 16, 1 + db 0, -1, 16, 1 + db -1, 0, 16, 1 + db 1, 0, 16, 1 + ; normal + db 0, 2, 8, 2 + db 0, -2, 8, 2 + db -2, 0, 8, 2 + db 2, 0, 8, 2 + ; fast + db 0, 4, 4, 4 + db 0, -4, 4, 4 + db -4, 0, 4, 4 + db 4, 0, 4, 4 + +GetStepVectorSign: ; 4709 (1:4709) + add a + ret z + ld a, $1 + ret nc + ld a, $ff + ret + +UpdatePlayerStep: + ld hl, $7 + add hl, bc + ld a, [hl] + and $3 + ld [wPlayerStepDirection], a + call AddStepVector + ld a, [wPlayerStepVectorX] + add d + ld [wPlayerStepVectorX], a + ld a, [wPlayerStepVectorY] + add e + ld [wPlayerStepVectorY], a + ld hl, wPlayerStepFlags + set 5, [hl] + ret + +Function4732: + push bc + ld e, a + ld d, $0 + ld hl, $1 + add hl, bc + ld a, [hl] + call GetMapObject + add hl, de + ld a, [hl] + pop bc + ret + +INCLUDE "engine/movement_pattern.asm" +INCLUDE "engine/step_types.asm" +INCLUDE "engine/overworld/movement.asm" + +Function5429: ; 5429 (1:5429) + call InitStep + ld hl, $1f + add hl, bc + ld [hl], $0 + ld hl, $5 + add hl, bc + res 3, [hl] + ld hl, $b + add hl, bc + ld [hl], $2 + call Function54c8 + ld hl, wCenteredObject + ld a, [hMapObjectIndexBuffer] + cp [hl] + jr z, .asm_5450 + ld hl, $9 + add hl, bc + ld [hl], $8 + ret + +.asm_5450 + ld hl, $9 + add hl, bc + ld [hl], $9 + ret +Function5457: ; 5457 (1:5457) + ld e, a + ld a, [wObjectFollow_Follower] + cp $ff + ret z + ld a, [wObjectFollow_Leader] + ld d, a + ld a, [hMapObjectIndexBuffer] + cp d + ret nz + ld a, e + cp $3e + ret z + cp $47 + ret z + cp $4b + ret z + cp $50 + ret z + cp $8 + ret c + push af + ld hl, wFollowerMovementQueueLength + inc [hl] + ld e, [hl] + ld d, $0 + ld hl, wFollowMovementQueue + add hl, de + pop af + ld [hl], a + ret + +GetFollowerNextMovementByte: + ld hl, wFollowerMovementQueueLength + ld a, [hl] + and a + jr z, .asm_54a2 + cp $ff + jr z, .asm_54a2 + dec [hl] + ld e, a + ld d, $0 + ld hl, wFollowMovementQueue + add hl, de + inc e + ld a, $ff +.asm_549b + ld d, [hl] + ld [hld], a + ld a, d + dec e + jr nz, .asm_549b + ret + +.asm_54a2 + call Function54a9 + ret c + ld a, $3e + ret + +Function54a9: ; 54a9 (1:54a9) + ld a, [wObjectFollow_Leader] + cp $ff + jr z, .asm_54bf + push bc + call GetObjectStruct + ld hl, $0 + add hl, bc + ld a, [hl] + pop bc + and a + jr z, .asm_54bf + and a + ret + +.asm_54bf + ld a, $ff + ld [wObjectFollow_Follower], a + ld a, $47 + scf + ret + +Function54c8: ; 54c8 (1:54c8) + push bc + ld de, .data + call Function5558 + call Function554b + pop bc + ret + +.data db $fc, PAL_OW_SILVER, SPRITEMOVEDATA_SHADOW + +Function54d7: ; 54d7 (1:54d7) + push bc + ld de, .data + call Function5558 + call Function554b + pop bc + ret + +.data db $fe, PAL_OW_SILVER, SPRITEMOVEDATA_BOULDERDUST + +Function54e6: ; 54e6 (1:54e6) + push bc + ld de, .data + call Function5558 + call Function554b + pop bc + ret + +.data db $f8, PAL_OW_SILVER, SPRITEMOVEDATA_EMOTE + +Function54f5: ; 54f5 (1:54f5) + push bc + ld de, .data + call Function5558 + call Function554b + pop bc + ret + +.data db $fe, PAL_OW_TREE, SPRITEMOVEDATA_GRASS + +Function5504: ; 5504 (1:5504) + push bc + push af + ld de, .data + call Function5558 + pop af + ld [wce9e], a + call Function554b + pop bc + ret + +.data db $00, PAL_OW_SILVER, SPRITEMOVEDATA_SCREENSHAKE + +Function5518: ; 5518 (1:5518) + push bc + ld a, [hMapObjectIndexBuffer] + ld c, a + call Function5521 + pop bc + ret + +Function5521: ; 5521 (1:5521) + ld de, wPlayerStruct + ld a, $d +.asm_5526 + push af + ld hl, $4 + add hl, de + bit 7, [hl] + jr z, .asm_5540 + ld hl, $0 + add hl, de + ld a, [hl] + and a + jr z, .asm_5540 + push bc + xor a + ld bc, $28 + call ByteFill + pop bc +.asm_5540 + ld hl, $28 + add hl, de + ld d, h + ld e, l + pop af + dec a + jr nz, .asm_5526 + ret + +Function554b: ; 554b (1:554b) + call FindFirstEmptyObjectStruct + ret nc + ld d, h + ld e, l + callba CopyTempObjectToObjectStruct + ret + +Function5558: ; 5558 (1:5558) + ld hl, wce99 + ld [hl], $ff + inc hl + ld [hl], $ff + inc hl + ld a, [de] + inc de + ld [hli], a + ld a, [de] + inc de + ld [hli], a + ld a, [de] + ld [hli], a + ld a, [hMapObjectIndexBuffer] + ld [hli], a + push hl + ld hl, $10 + add hl, bc + ld d, [hl] + ld hl, $11 + add hl, bc + ld e, [hl] + pop hl + ld [hl], d + inc hl + ld [hl], e + inc hl + ld [hl], $ff + ret + +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, [wXCoord] + cp d + jr z, .asm_564f + jr nc, .asm_565e + add $b + cp d + jr c, .asm_565e +.asm_564f + ld a, [wYCoord] + 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 + +ApplyBGMapAnchorToObjects:: ; 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 diff --git a/engine/overworld/movement.asm b/engine/overworld/movement.asm new file mode 100755 index 00000000..74e44cd3 --- /dev/null +++ b/engine/overworld/movement.asm @@ -0,0 +1,776 @@ +GetMovementByte: + ld hl, wMovementDataPointerBank + call GetMovementByte_ + ret + +Function4fbd: + ld hl, $1b + add hl, bc + ld e, [hl] + inc [hl] + ld d, $0 + ld hl, wMovementPerson + ld a, [hli] + ld h, [hl] + ld l, a + add hl, de + ld a, [hl] + ret + +Function4fce: + ld hl, $1b + add hl, bc + ld e, [hl] + inc [hl] + ld d, $0 + ld hl, wce8f + ld a, [hli] + ld h, [hl] + ld l, a + add hl, de + ld a, [hl] + ret + +Function4fdf: ; 4fdf (1:4fdf) + ld hl, GetMovementPerson + jp Function4fe9 + +GetMovementPerson + ld a, [wMovementPerson] + ret + +Function4fe9: ; 4fe9 (1:4fe9) + call Function4ffd +.asm_4fec + xor a + ld [wce93], a + call Function5006 + call Function5013 + ld a, [wce93] + and a + jr nz, .asm_4fec + ret + +Function4ffd: ; 4ffd (1:4ffd) + ld a, l + ld [wce94], a + ld a, h + ld [wce95], a + ret + +Function5006: ; 5006 (1:5006) + ld hl, wce94 + ld a, [hli] + ld h, [hl] + ld l, a + jp hl + +Function500d: ; 500d (1:500d) + ld a, $1 + ld [wce93], a + ret + +Function5013: ; 5013 (1:5013) + push af + call Function5457 + pop af + ld hl, MovementPointers + rst JumpTable + ret + +MovementPointers: ; 501d + dw Function527d + dw Function5281 + dw Function5285 + dw Function5289 + dw Function538f + dw Function5393 + dw Function5397 + dw Function539b + dw Function529f + dw Function52a4 + dw Function52a9 + dw Function52ae + dw Function52b3 + dw Function52b8 + dw Function52bd + dw Function52c2 + dw Function52c7 + dw Function52cc + dw Function52d1 + dw Function52d6 + dw Function5317 + dw Function531c + dw Function5321 + dw Function5326 + dw Function532b + dw Function5330 + dw Function5335 + dw Function533a + dw Function533f + dw Function5344 + dw Function5349 + dw Function534e + dw Function52db + dw Function52e0 + dw Function52e5 + dw Function52ea + dw Function52ef + dw Function52f4 + dw Function52f9 + dw Function52fe + dw Function5303 + dw Function5308 + dw Function530d + dw Function5312 + dw Function5353 + dw Function5358 + dw Function535d + dw Function5362 + dw Function5367 + dw Function536c + dw Function5371 + dw Function5376 + dw Function537b + dw Function5380 + dw Function5385 + dw Function538a + dw Function5232 + dw Function523b + dw Function5244 + dw Function524d + dw Function5256 + dw Function525f + dw Function51c1 + dw Function51c5 + dw Function51c9 + dw Function51cd + dw Function51d1 + dw Function51d5 + dw Function51d9 + dw Function51dd + dw Function51e1 + dw Function5160 + dw Function517a + dw Function519c + dw Function5157 + dw Function51af + dw Function50cf + dw Function50d6 + dw Function50dd + dw Function50e4 + dw Function51fe + dw Function5128 + dw Function514a + dw Function5268 + dw Function526e + dw Function5274 + dw Function5218 + dw Function5135 + dw Function5109 + +Function50cf: ; 50cf (1:50cf) + ld hl, $9 + add hl, bc + ld [hl], $c + ret + +Function50d6: ; 50d6 (1:50d6) + ld hl, $9 + add hl, bc + ld [hl], $d + ret + +Function50dd: ; 50dd (1:50dd) + ld hl, $9 + add hl, bc + ld [hl], $e + ret + +Function50e4: ; 50e4 (1:50e4) + call GetSpriteDirection + rlca + rlca + ld hl, $c + add hl, bc + ld [hl], a + ld hl, $b + add hl, bc + ld [hl], $4 + call Function5006 + ld hl, $a + add hl, bc + ld [hl], a + ld hl, $9 + add hl, bc + ld [hl], $3 + ld hl, $7 + add hl, bc + ld [hl], $ff + ret + +Function5109: ; 5109 (1:5109) + call GetSpriteDirection + rlca + rlca + ld hl, $c + add hl, bc + ld [hl], a + call Function5006 + ld hl, $a + add hl, bc + ld [hl], a + ld hl, $7 + add hl, bc + ld [hl], $ff + ld hl, $9 + add hl, bc + ld [hl], $12 + ret + +Function5128: ; 5128 (1:5128) + ld hl, $b + add hl, bc + ld [hl], $6 + ld hl, $9 + add hl, bc + ld [hl], $10 + ret + +Function5135: ; 5135 (1:5135) + call Function5006 + ld hl, $a + add hl, bc + ld [hl], a + ld hl, $b + add hl, bc + ld [hl], $1 + ld hl, $9 + add hl, bc + ld [hl], $11 + ret + +Function514a: ; 514a (1:514a) + ld hl, $b + add hl, bc + ld [hl], $6 + ld hl, $9 + add hl, bc + ld [hl], $1 + ret + +Function5157: ; 5157 (1:5157) + ld hl, $1b + add hl, bc + ld [hl], $0 + jp Function500d + +Function5160: ; 5160 (1:5160) + call RestoreDefaultMovement + ld hl, $3 + add hl, bc + ld [hl], a + ld hl, $1b + add hl, bc + ld [hl], $0 + ld hl, wVramState + res 7, [hl] + ld hl, $9 + add hl, bc + ld [hl], $1 + ret + +Function517a: ; 517a (1:517a) + call RestoreDefaultMovement + ld hl, $3 + add hl, bc + ld [hl], a + ld hl, $1b + add hl, bc + ld [hl], $0 + call Function5006 + ld hl, $a + add hl, bc + ld [hl], a + ld hl, $9 + add hl, bc + ld [hl], $3 + ld hl, wVramState + res 7, [hl] + ret + +Function519c: ; 519c (1:519c) + call DeleteMapObject + ld hl, wObjectFollow_Leader + ld a, [hMapObjectIndexBuffer] + cp [hl] + jr nz, .asm_51a9 + ld [hl], $ff +.asm_51a9 + ld hl, wVramState + res 7, [hl] + ret + +Function51af: ; 51af (1:51af) + ld hl, $b + add hl, bc + ld [hl], $1 + ld hl, $9 + add hl, bc + ld [hl], $4 + ld hl, wVramState + res 7, [hl] + ret + +Function51c1: ; 51c1 (1:51c1) + ld a, $1 + jr asm_51e6 + +Function51c5: ; 51c5 (1:51c5) + ld a, $2 + jr asm_51e6 + +Function51c9: ; 51c9 (1:51c9) + ld a, $3 + jr asm_51e6 + +Function51cd: ; 51cd (1:51cd) + ld a, $4 + jr asm_51e6 + +Function51d1: ; 51d1 (1:51d1) + ld a, $5 + jr asm_51e6 + +Function51d5: ; 51d5 (1:51d5) + ld a, $6 + jr asm_51e6 + +Function51d9: ; 51d9 (1:51d9) + ld a, $7 + jr asm_51e6 + +Function51dd: ; 51dd (1:51dd) + ld a, $8 + jr asm_51e6 + +Function51e1: ; 51e1 (1:51e1) + call Function5006 + jr asm_51e6 + +asm_51e6 + ld hl, $a + add hl, bc + ld [hl], a + ld hl, $9 + add hl, bc + ld [hl], $3 + ld hl, $b + add hl, bc + ld [hl], $1 + ld hl, $7 + add hl, bc + ld [hl], $ff + ret + +Function51fe: ; 51fe (1:51fe) + ld a, $1 + ld hl, $a + add hl, bc + ld [hl], a + ld hl, $9 + add hl, bc + ld [hl], $b + ld hl, $b + add hl, bc + ld [hl], $3 + ld hl, $7 + add hl, bc + ld [hl], $ff + ret + +Function5218: ; 5218 (1:5218) + ld a, $18 + ld hl, $a + add hl, bc + ld [hl], a + ld hl, $9 + add hl, bc + ld [hl], $3 + ld hl, $b + add hl, bc + ld [hl], $b + ld hl, $7 + add hl, bc + ld [hl], $ff + ret + +Function5232: ; 5232 (1:5232) + ld hl, $4 + add hl, bc + res 3, [hl] + jp Function500d + +Function523b: ; 523b (1:523b) + ld hl, $4 + add hl, bc + set 3, [hl] + jp Function500d + +Function5244: ; 5244 (1:5244) + ld hl, $4 + add hl, bc + res 2, [hl] + jp Function500d + +Function524d: ; 524d (1:524d) + ld hl, $4 + add hl, bc + set 2, [hl] + jp Function500d + +Function5256: ; 5256 (1:5256) + ld hl, $4 + add hl, bc + res 0, [hl] + jp Function500d + +Function525f: ; 525f (1:525f) + ld hl, $4 + add hl, bc + set 0, [hl] + jp Function500d + +Function5268: ; 5268 (1:5268) + call Function5518 + jp Function500d + +Function526e: ; 526e (1:526e) + call Function54e6 + jp Function500d + +Function5274: ; 5274 (1:5274) + call Function5006 + call Function5504 + jp Function500d + +Function527d: ; 527d (1:527d) + ld a, $0 + jr asm_528d + +Function5281: ; 5281 (1:5281) + ld a, $4 + jr asm_528d + +Function5285: ; 5285 (1:5285) + ld a, $8 + jr asm_528d + +Function5289: ; 5289 (1:5289) + ld a, $c + jr asm_528d + +asm_528d + ld hl, $8 + add hl, bc + ld [hl], a + ld hl, $b + add hl, bc + ld [hl], $1 + ld hl, $7 + add hl, bc + ld [hl], $ff + ret + +Function529f: ; 529f (1:529f) + ld a, $0 + jp Function53b1 + +Function52a4: ; 52a4 (1:52a4) + ld a, $1 + jp Function53b1 + +Function52a9: ; 52a9 (1:52a9) + ld a, $2 + jp Function53b1 + +Function52ae: ; 52ae (1:52ae) + ld a, $3 + jp Function53b1 + +Function52b3: ; 52b3 (1:52b3) + ld a, $4 + jp Function53b1 + +Function52b8: ; 52b8 (1:52b8) + ld a, $5 + jp Function53b1 + +Function52bd: ; 52bd (1:52bd) + ld a, $6 + jp Function53b1 + +Function52c2: ; 52c2 (1:52c2) + ld a, $7 + jp Function53b1 + +Function52c7: ; 52c7 (1:52c7) + ld a, $8 + jp Function53b1 + +Function52cc: ; 52cc (1:52cc) + ld a, $9 + jp Function53b1 + +Function52d1: ; 52d1 (1:52d1) + ld a, $a + jp Function53b1 + +Function52d6: ; 52d6 (1:52d6) + ld a, $b + jp Function53b1 + +Function52db: ; 52db (1:52db) + ld a, $0 + jp Function53e5 + +Function52e0: ; 52e0 (1:52e0) + ld a, $1 + jp Function53e5 + +Function52e5: ; 52e5 (1:52e5) + ld a, $2 + jp Function53e5 + +Function52ea: ; 52ea (1:52ea) + ld a, $3 + jp Function53e5 + +Function52ef: ; 52ef (1:52ef) + ld a, $4 + jp Function53e5 + +Function52f4: ; 52f4 (1:52f4) + ld a, $5 + jp Function53e5 + +Function52f9: ; 52f9 (1:52f9) + ld a, $6 + jp Function53e5 + +Function52fe: ; 52fe (1:52fe) + ld a, $7 + jp Function53e5 + +Function5303: ; 5303 (1:5303) + ld a, $8 + jp Function53e5 + +Function5308: ; 5308 (1:5308) + ld a, $9 + jp Function53e5 + +Function530d: ; 530d (1:530d) + ld a, $a + jp Function53e5 + +Function5312: ; 5312 (1:5312) + ld a, $b + jp Function53e5 + +Function5317: ; 5317 (1:5317) + ld a, $0 + jp Function5407 + +Function531c: ; 531c (1:531c) + ld a, $1 + jp Function5407 + +Function5321: ; 5321 (1:5321) + ld a, $2 + jp Function5407 + +Function5326: ; 5326 (1:5326) + ld a, $3 + jp Function5407 + +Function532b: ; 532b (1:532b) + ld a, $4 + jp Function5407 + +Function5330: ; 5330 (1:5330) + ld a, $5 + jp Function5407 + +Function5335: ; 5335 (1:5335) + ld a, $6 + jp Function5407 + +Function533a: ; 533a (1:533a) + ld a, $7 + jp Function5407 + +Function533f: ; 533f (1:533f) + ld a, $8 + jp Function5407 + +Function5344: ; 5344 (1:5344) + ld a, $9 + jp Function5407 + +Function5349: ; 5349 (1:5349) + ld a, $a + jp Function5407 + +Function534e: ; 534e (1:534e) + ld a, $b + jp Function5407 + +Function5353: ; 5353 (1:5353) + ld a, $0 + jp Function5429 + +Function5358: ; 5358 (1:5358) + ld a, $1 + jp Function5429 + +Function535d: ; 535d (1:535d) + ld a, $2 + jp Function5429 + +Function5362: ; 5362 (1:5362) + ld a, $3 + jp Function5429 + +Function5367: ; 5367 (1:5367) + ld a, $4 + jp Function5429 + +Function536c: ; 536c (1:536c) + ld a, $5 + jp Function5429 + +Function5371: ; 5371 (1:5371) + ld a, $6 + jp Function5429 + +Function5376: ; 5376 (1:5376) + ld a, $7 + jp Function5429 + +Function537b: ; 537b (1:537b) + ld a, $8 + jp Function5429 + +Function5380: ; 5380 (1:5380) + ld a, $9 + jp Function5429 + +Function5385: ; 5385 (1:5385) + ld a, $a + jp Function5429 + +Function538a: ; 538a (1:538a) + ld a, $b + jp Function5429 + +Function538f: ; 538f (1:538f) + ld a, $0 + jr asm_539f + +Function5393: ; 5393 (1:5393) + ld a, $4 + jr asm_539f + +Function5397: ; 5397 (1:5397) + ld a, $8 + jr asm_539f + +Function539b: ; 539b (1:539b) + ld a, $c + jr asm_539f + +asm_539f + ld hl, $1d + add hl, bc + ld [hl], a + ld hl, $b + add hl, bc + ld [hl], $2 + ld hl, $9 + add hl, bc + ld [hl], $a + ret + +Function53b1: ; 53b1 (1:53b1) + call InitStep + call UpdateGrassPriority + ld hl, $b + add hl, bc + ld [hl], $2 + ld hl, $e + add hl, bc + ld a, [hl] + call CheckSuperTallGrassTile + jr z, .asm_53cc + call CheckGrassTile + jr c, .asm_53cf +.asm_53cc + call Function54f5 +.asm_53cf + ld hl, wCenteredObject + ld a, [hConnectionStripLength] + cp [hl] + jr z, .asm_53de + ld hl, $9 + add hl, bc + ld [hl], $2 + ret + +.asm_53de + ld hl, $9 + add hl, bc + ld [hl], $6 + ret + +Function53e5: ; 53e5 (1:53e5) + call InitStep + call UpdateGrassPriority + ld hl, $b + add hl, bc + ld [hl], $4 + ld hl, wCenteredObject + ld a, [hMapObjectIndexBuffer] + cp [hl] + jr z, .asm_5400 + ld hl, $9 + add hl, bc + ld [hl], $2 + ret + +.asm_5400 + ld hl, $9 + add hl, bc + ld [hl], $6 + ret + +Function5407: ; 5407 (1:5407) + call InitStep + call UpdateGrassPriority + ld hl, $b + add hl, bc + ld [hl], $1 + ld hl, wCenteredObject + ld a, [hConnectionStripLength] + cp [hl] + jr z, .asm_5422 + ld hl, $9 + add hl, bc + ld [hl], $2 + ret + +.asm_5422 + ld hl, $9 + add hl, bc + ld [hl], $6 + ret diff --git a/engine/overworld/npc_movement.asm b/engine/overworld/npc_movement.asm new file mode 100755 index 00000000..e776402a --- /dev/null +++ b/engine/overworld/npc_movement.asm @@ -0,0 +1,525 @@ +CheckNPCMovementPermissions: ; 6fa0 (1:6fa0) + ld hl, $6 + add hl, bc + bit 5, [hl] + jr z, .asm_6fb8 + ld hl, $4 + add hl, bc + bit 4, [hl] + push hl + push bc + call Function700b + pop bc + pop hl + ret c + jr .asm_6fc8 + +.asm_6fb8 + ld hl, $4 + add hl, bc + bit 4, [hl] + jr nz, .asm_6fc8 + push hl + push bc + call Function6fe6 + pop bc + pop hl + ret c +.asm_6fc8 + bit 6, [hl] + jr nz, .asm_6fd4 + push hl + push bc + call WillPersonBumpIntoSomeoneElse + pop bc + pop hl + ret c +.asm_6fd4 + bit 5, [hl] + jr nz, .asm_6fe4 + push hl + call HasPersonReachedMovementLimit + pop hl + ret c + push hl + call IsPersonMovingOffEdgeOfScreen + pop hl + ret c +.asm_6fe4 + and a + ret + +Function6fe6: ; 6fe6 (1:6fe6) + call Function703e + ret c + ld hl, $10 + add hl, bc + ld d, [hl] + ld hl, $11 + add hl, bc + ld e, [hl] + ld hl, $6 + add hl, bc + bit 7, [hl] + jp nz, Function7080 + ld hl, $e + add hl, bc + ld a, [hl] + ld d, a + call GetTileCollision + and a + jr z, Function701d + scf + ret + +Function700b: ; 700b (1:700b) + call Function703e + ret c + ld hl, $e + add hl, bc + ld a, [hl] + call GetTileCollision + cp $1 + jr z, Function701d + scf + ret + +Function701d + ld hl, $e + add hl, bc + ld a, [hl] + call Function705e + ret nc + push af + ld hl, $7 + add hl, bc + ld a, [hl] + and $3 + ld e, a + ld d, $0 + ld hl, .data_703a + add hl, de + pop af + and [hl] + ret z + scf + ret + +.data_703a + db 1 << DOWN, 1 << UP, 1 << RIGHT, 1 << LEFT + +Function703e: ; 703e (1:703e) + ld hl, $f + add hl, bc + ld a, [hl] + call Function705e + ret nc + push af + ld hl, $7 + add hl, bc + and $3 + ld e, a + ld d, $0 + ld hl, .data_705a + add hl, de + pop af + and [hl] + ret z + scf + ret + +.data_705a + db 1 << UP, 1 << DOWN, 1 << LEFT, 1 << RIGHT + +Function705e: ; 705e (1:705e) + ld d, a + and $f0 + cp $b0 + jr z, .asm_706b + cp $c0 + jr z, .asm_706b + xor a + ret + +.asm_706b + ld a, d + and $7 + ld e, a + ld d, $0 + ld hl, .data_7078 + add hl, de + ld a, [hl] + scf + ret + +.data_7078 + db 8, 4, 1, 2 + db 10, 6, 9, 5 + +Function7080: ; 7080 (1:7080) + ld hl, $7 + add hl, bc + ld a, [hl] + and $3 + jr z, .asm_7091 + dec a + jr z, .asm_7096 + dec a + jr z, .asm_709a + jr .asm_709e + +.asm_7091 + inc e + push de + inc d + jr .asm_70a1 + +.asm_7096 + push de + inc d + jr .asm_70a1 + +.asm_709a + push de + inc e + jr .asm_70a1 + +.asm_709e + inc d + push de + inc e +.asm_70a1 + call GetCoordTile + call GetTileCollision + pop de + and a + jr nz, .asm_70b6 + call GetCoordTile + call GetTileCollision + and a + jr nz, .asm_70b6 + xor a + ret + +.asm_70b6 + scf + ret + +CheckFacingObject: + call GetFacingTileCoord + call CheckCounterTile + jr nz, .asm_70d0 + ld a, [wPlayerStandingMapX] + sub d + cpl + inc a + add d + ld d, a + ld a, [wPlayerStandingMapY] + sub e + cpl + inc a + add e + ld e, a +.asm_70d0 + ld bc, wObjectStructs + ld a, $0 + ld [hMapObjectIndexBuffer], a + call Function7120 + ret nc + ld hl, $7 + add hl, bc + ld a, [hl] + cp $ff + jr z, .asm_70e6 + xor a + ret + +.asm_70e6 + scf + ret + +WillPersonBumpIntoSomeoneElse: ; 70e8 (1:70e8) + ld hl, $10 + add hl, bc + ld d, [hl] + ld hl, $11 + add hl, bc + ld e, [hl] + jr Function7120 + +Function70f4: + ld a, [hMapObjectIndexBuffer] + call GetObjectStruct + call Function7100 + call Function7120 + ret + +Function7100: ; 7100 (1:7100) + ld hl, $10 + add hl, bc + ld d, [hl] + ld hl, $11 + add hl, bc + ld e, [hl] + call GetSpriteDirection + and a + jr z, .asm_711a + cp $4 + jr z, .asm_711c + cp $8 + jr z, .asm_711e + inc d + ret + +.asm_711a + inc e + ret + +.asm_711c + dec e + ret + +.asm_711e + dec d + ret + +Function7120: ; 7120 (1:7120) + ld bc, wPlayerStruct + xor a +.asm_7124 + ld [hObjectStructIndexBuffer], a + call DoesObjectHaveASprite + jr z, .asm_7172 + ld hl, $4 + add hl, bc + bit 7, [hl] + jr nz, .asm_7172 + ld hl, $6 + add hl, bc + bit 7, [hl] + jr z, .asm_7142 + call Function7250 + jr nc, .asm_715a + jr .asm_7152 + +.asm_7142 + ld hl, $10 + add hl, bc + ld a, [hl] + cp d + jr nz, .asm_715a + ld hl, $11 + add hl, bc + ld a, [hl] + cp e + jr nz, .asm_715a +.asm_7152 + ld a, [hMapObjectIndexBuffer] + ld l, a + ld a, [hConnectedMapWidth] + cp l + jr nz, .asm_7181 +.asm_715a + ld hl, $12 + add hl, bc + ld a, [hl] + cp d + jr nz, .asm_7172 + ld hl, $13 + add hl, bc + ld a, [hl] + cp e + jr nz, .asm_7172 + ld a, [hConnectionStripLength] + ld l, a + ld a, [hObjectStructIndexBuffer] + cp l + jr nz, .asm_7181 +.asm_7172 + ld hl, $28 + add hl, bc + ld b, h + ld c, l + ld a, [hConnectedMapWidth] + inc a + cp $d + jr nz, .asm_7124 + and a + ret + +.asm_7181 + scf + ret + +HasPersonReachedMovementLimit: ; 7183 (1:7183) + ld hl, $16 + add hl, bc + ld a, [hl] + and a + jr z, .asm_71c8 + and $f + jr z, .asm_71a6 + ld e, a + ld d, a + ld hl, $14 + add hl, bc + ld a, [hl] + sub d + ld d, a + ld a, [hl] + add e + ld e, a + ld hl, $10 + add hl, bc + ld a, [hl] + cp d + jr z, .asm_71ca + cp e + jr z, .asm_71ca +.asm_71a6 + ld hl, $16 + add hl, bc + ld a, [hl] + swap a + and $f + jr z, .asm_71c8 + ld e, a + ld d, a + ld hl, $15 + add hl, bc + ld a, [hl] + sub d + ld d, a + ld a, [hl] + add e + ld e, a + ld hl, $11 + add hl, bc + ld a, [hl] + cp d + jr z, .asm_71ca + cp e + jr z, .asm_71ca +.asm_71c8 + xor a + ret + +.asm_71ca + scf + ret + +IsPersonMovingOffEdgeOfScreen: ; 71cc (1:71cc) + ld hl, $10 + add hl, bc + ld a, [wXCoord] + cp [hl] + jr z, .asm_71dd + jr nc, .asm_71f0 + add $9 + cp [hl] + jr c, .asm_71f0 +.asm_71dd + ld hl, $11 + add hl, bc + ld a, [wYCoord] + cp [hl] + jr z, .asm_71ee + jr nc, .asm_71f0 + add $8 + cp [hl] + jr c, .asm_71f0 +.asm_71ee + and a + ret + +.asm_71f0 + scf + ret + +Function71f2 + ld a, [wPlayerStandingMapX] + ld d, a + ld a, [wPlayerStandingMapY] + ld e, a + ld bc, wObjectStructs + xor a +.asm_71fe + ld [hConnectedMapWidth], a + call DoesObjectHaveASprite + jr z, .asm_723f + ld hl, $3 + add hl, bc + ld a, [hl] + cp $15 + jr nz, .asm_7215 + call Function7250 + jr c, .asm_724e + jr .asm_723f + +.asm_7215 + ld hl, $11 + add hl, bc + ld a, [hl] + cp e + jr nz, .asm_722d + ld hl, $10 + add hl, bc + ld a, [hl] + cp d + jr nz, .asm_722d + ld a, [hObjectStructIndexBuffer] + cp $0 + jr z, .asm_723f + jr .asm_724e + +.asm_722d + ld hl, $13 + add hl, bc + ld a, [hl] + cp e + jr nz, .asm_723f + ld hl, $12 + add hl, bc + ld a, [hl] + cp d + jr nz, .asm_723f + jr .asm_724e + +.asm_723f + ld hl, $28 + add hl, bc + ld b, h + ld c, l + ld a, [hConnectedMapWidth] + inc a + cp $d + jr nz, .asm_71fe + xor a + ret + +.asm_724e + scf + ret + +Function7250: ; 7250 (1:7250) + ld hl, $10 + add hl, bc + ld a, d + sub [hl] + jr c, .asm_726a + cp $2 + jr nc, .asm_726a + ld hl, $11 + add hl, bc + ld a, e + sub [hl] + jr c, .asm_726a + cp $2 + jr nc, .asm_726a + scf + ret + +.asm_726a + and a + ret diff --git a/engine/overworld/player_movement.asm b/engine/overworld/player_movement.asm new file mode 100755 index 00000000..61b45a72 --- /dev/null +++ b/engine/overworld/player_movement.asm @@ -0,0 +1,735 @@ +DoPlayerMovement:: ; 10000 (4:4000) + call Function10017 + ld a, movement_step_sleep + ld [wcf2d], a + xor a + ld [wcf2c], a + call Function1002d + ld c, a + ld a, [wcf2d] + ld [wce87], a + ret + +Function10017: ; 10017 (4:4017) + ld a, [hJoyDown] + ld [wcf29], a + CheckFlagHL ENGINE_DOWNHILL + ret z + ld c, a + and $f0 + ret nz + ld a, c + or $80 + ld [wcf29], a + ret + +Function1002d: ; 1002d (4:402d) + ld a, [wPlayerBikeSurfState] + cp PLAYER_NORMAL + jr z, .asm_10044 + cp PLAYER_SURF + jr z, .asm_10060 + cp PLAYER_SURF_PIKA + jr z, .asm_10060 + cp PLAYER_BIKE + jr z, .asm_10044 + cp PLAYER_SLIP + jr z, .asm_10074 +.asm_10044 + call Function102cb + call Function102ec + call Function100b7 + ret c + call Function10147 + ret c + call Function1016b + ret c + call Function101f3 + ret c + call Function10226 + ret c + jr .asm_1009d + +.asm_10060 + call Function102cb + call Function102ec + call Function100b7 + ret c + call Function10147 + ret c + call Function101c0 + ret c + jr .asm_1009d + +.asm_10074 + call Function102cb + call Function102ec + call Function100b7 + ret c + call Function10147 + ret c + call Function1016b + ret c + call Function101f3 + ret c + call Function10226 + ret c + ld a, [wcf2e] + cp $ff + jr z, .asm_10098 + call Function103ee +.asm_10098 + call Function102b3 + xor a + ret + +.asm_1009d + ld a, [wcf2e] + cp $ff + jr z, .asm_100b2 + ld a, [wTempTrainerHeader] + and a + jr nz, .asm_100ad + call Function103ee +.asm_100ad + call Function102bf + xor a + ret + +.asm_100b2 + call Function102b3 + xor a + ret + +Function100b7: ; 100b7 (4:40b7) + ld a, [wPlayerStandingTile] + ld c, a + call CheckWhirlpoolTile + jr c, .asm_100c4 + ld a, $3 + scf + ret + +.asm_100c4 + and $f0 + cp $30 + jr z, .asm_100d8 + cp $40 + jr z, .asm_100ec + cp $50 + jr z, .asm_10108 + cp $70 + jr z, .asm_10124 + jr .asm_1013c + +.asm_100d8 + ld a, c + and $3 + ld c, a + ld b, $0 + ld hl, .water_table + add hl, bc + ld a, [hl] + ld [wcf2e], a + jr .asm_1013e + +.water_table + db RIGHT + db LEFT + db UP + db DOWN + +.asm_100ec + ld a, c + and $7 + ld c, a + ld b, $0 + ld hl, .land1_table + add hl, bc + ld a, [hl] + cp $ff + jr z, .asm_1013c + ld [wcf2e], a + jr .asm_1013e + +.land1_table + db STANDING + db RIGHT + db LEFT + db UP + db DOWN + db STANDING + db STANDING + db STANDING + +.asm_10108 + ld a, c + and $7 + ld c, a + ld b, $0 + ld hl, .land2_table + add hl, bc + ld a, [hl] + cp $ff + jr z, .asm_1013c + ld [wcf2e], a + jr .asm_1013e + +.land2_table + db RIGHT + db LEFT + db UP + db DOWN + db STANDING + db STANDING + db STANDING + db STANDING + +.asm_10124 + ld a, c + cp $71 + jr z, .asm_10135 + cp $79 + jr z, .asm_10135 + cp $7a + jr z, .asm_10135 + cp $7b + jr nz, .asm_1013c +.asm_10135 + ld a, $0 + ld [wcf2e], a + jr .asm_1013e + +.asm_1013c + xor a + ret + +.asm_1013e + ld a, $1 + call Function1025f + ld a, $5 + scf + ret + +Function10147: ; 10147 (4:4147) + ld a, [wcf39] + cp $0 + jr nz, .asm_10169 + ld a, [wcf2e] + cp $ff + jr z, .asm_10169 + ld e, a + ld a, [wPlayerDirection] + rrca + rrca + and $3 + cp e + jr z, .asm_10169 + ld a, $5 + call Function1025f + ld a, $2 + scf + ret + +.asm_10169 + xor a + ret + +Function1016b: ; 1016b (4:416b) + ld a, [wPlayerBikeSurfState] + cp $4 + jr z, Function101c0 + cp $8 + jr z, Function101c0 + call Function1039e + jr c, .asm_101be + call Function10341 + and a + jr z, .asm_101be + cp $2 + jr z, .asm_101be + ld a, [wPlayerStandingTile] + call CheckIceTile + jr nc, .asm_101b5 + call Function103ca + jr nz, .asm_101ae + ld hl, wBikeFlags + bit 2, [hl] + jr z, .asm_101a7 + ld a, [wcf2e] + cp $0 + jr z, .asm_101a7 + ld a, $1 + call Function1025f + scf + ret + +.asm_101a7 + ld a, $2 + call Function1025f + scf + ret + +.asm_101ae + ld a, $1 + call Function1025f + scf + ret + +.asm_101b5 + ld a, $4 + call Function1025f + scf + ret + + xor a + ret + +.asm_101be + xor a + ret + +Function101c0: ; 101c0 (4:41c0) + call Function103b4 + ld [wcf2b], a + jr c, .asm_101f1 + call Function10341 + ld [wcf2a], a + and a + jr z, .asm_101f1 + cp $2 + jr z, .asm_101f1 + ld a, [wcf2b] + and a + jr nz, .asm_101e2 + ld a, $1 + call Function1025f + scf + ret + +.asm_101e2 + call Function103f9 + call PlayMapMusic + ld a, $1 + call Function1025f + ld a, $6 + scf + ret + +.asm_101f1 + xor a + ret + +Function101f3: ; 101f3 (4:41f3) + ld a, [wPlayerStandingTile] + ld e, a + and $f0 + cp $a0 + jr nz, .asm_1021c + ld a, e + and $7 + ld e, a + ld d, $0 + ld hl, .data_1021e + add hl, de + ld a, [wcf2f] + and [hl] + jr z, .asm_1021c + ld de, $16 + call PlaySFX + ld a, $3 + call Function1025f + ld a, $7 + scf + ret + +.asm_1021c + xor a + ret + +.data_1021e + db FACE_RIGHT + db FACE_LEFT + db FACE_UP + db FACE_DOWN + db FACE_RIGHT | FACE_DOWN + db FACE_DOWN | FACE_LEFT + db FACE_UP | FACE_RIGHT + db FACE_UP | FACE_LEFT + +Function10226: ; 10226 (4:4226) + ld a, [wcf2e] + ld e, a + ld d, $0 + ld hl, .edge_warps + add hl, de + ld a, [wPlayerStandingTile] + cp [hl] + jr nz, .asm_10259 + ld a, $1 + ld [wTempTrainerHeader], a + ld a, [wcf2e] + cp $ff + jr z, .asm_10259 + ld e, a + ld a, [wPlayerDirection] + rrca + rrca + and $3 + cp e + jr nz, .asm_10259 + call Function22a5 + jr nc, .asm_10259 + call Function102b3 + scf + ld a, $1 + ret + +.asm_10259 + xor a + ret + +.edge_warps + db $70, $78, $76, $7e + +Function1025f: ; 1025f (4:425f) + ld e, a + ld d, $0 + ld hl, .Steps + add hl, de + add hl, de + ld a, [hli] + ld h, [hl] + ld l, a + ld a, [wcf2e] + ld e, a + cp $ff + jp z, Function102b3 + add hl, de + ld a, [hl] + ld [wcf2d], a + ld hl, $42af + add hl, de + ld a, [hl] + ld [wcf39], a + ld a, $4 + ret + +.Steps: + dw .SlowStep + dw .NormalStep + dw .FastStep + dw .JumpStep + dw .SlideStep + dw .TurningStep + dw .BackJumpStep + dw .FinishFacing + +.SlowStep: + slow_step DOWN + slow_step UP + slow_step LEFT + slow_step RIGHT +.NormalStep: + step DOWN + step UP + step LEFT + step RIGHT +.FastStep: + big_step DOWN + big_step UP + big_step LEFT + big_step RIGHT +.JumpStep: + jump_step DOWN + jump_step UP + jump_step LEFT + jump_step RIGHT +.SlideStep: + fast_slide_step DOWN + fast_slide_step UP + fast_slide_step LEFT + fast_slide_step RIGHT +.BackJumpStep: + jump_step UP + jump_step DOWN + jump_step RIGHT + jump_step LEFT +.TurningStep: + turn_step DOWN + turn_step UP + turn_step LEFT + turn_step RIGHT +.FinishFacing: + db $80 + DOWN + db $80 + UP + db $80 + LEFT + db $80 + RIGHT + +Function102b3: ; 102b3 (4:42b3) + ld a, $0 + ld [wcf39], a + ld a, $3e + ld [wcf2d], a + xor a + ret + +Function102bf: ; 102bf (4:42bf) + ld a, $0 + ld [wTempTrainerHeaderEnd], a + ld a, $50 + ld [wcf2d], a + xor a + ret + +Function102cb: ; 102cb (4:42cb) + call Function10404 + ret nc + ld a, [wTempTrainerHeaderEnd] +.asm_102d2 + cp $0 + ret z + and $3 + ld e, a + ld d, $0 + ld hl, .forced_dpad + add hl, de + ld a, [wcf29] + and $f + or [hl] + ld [wcf29], a + ret + +.forced_dpad + db D_DOWN, D_UP, D_LEFT, D_RIGHT + +Function102ec: ; 102ec (4:42ec) + ld hl, .table + ld de, .table2 - .table1 + ld a, [wcf29] + bit 7, a + jr nz, .asm_10307 + bit 6, a + jr nz, .asm_10308 +.asm_102fc + bit 5, a + jr nz, .asm_10309 + bit 4, a + jr nz, .asm_1030a + jr .asm_1030b + +.asm_10307 + add hl, de +.asm_10308 + add hl, de +.asm_10309 + add hl, de +.asm_1030a + add hl, de +.asm_1030b + ld a, [hli] + ld [wcf2e], a + ld a, [hli] + ld [wcf2f], a + ld a, [hli] + ld [wcf30], a + ld a, [hli] + ld [wcf31], a + ld a, [hli] + ld h, [hl] + ld l, a + ld a, [hl] + ld [wWinTextPointer], a + ret + +.table +; struct: +; walk direction +; facing +; x movement +; y movement +; tile collision pointer +.table1 + db STANDING, FACE_CURRENT, 0, 0 + dw wPlayerStandingTile +.table2 + db RIGHT, FACE_RIGHT, 1, 0 + dw wTileRight + db LEFT, FACE_LEFT, -1, 0 + dw wTileLeft + db UP, FACE_UP, 0, -1 + dw wTileUp + db DOWN, FACE_DOWN, 0, 1 + dw wTileDown + +Function10341: ; 10341 (4:4341) + ld a, 0 + ld [hMapObjectIndexBuffer], a + ld a, [wPlayerStandingMapX] + ld d, a + ld a, [wcf30] + add d + ld d, a + ld a, [wPlayerStandingMapY] + ld e, a + ld a, [wcf31] + add e + ld e, a + ld bc, wPlayerSprite + callba Function7120 + jr nc, .asm_10369 + call Function1036f + jr c, .asm_1036c + xor a + ret + +.asm_10369 + ld a, $1 + ret + +.asm_1036c + ld a, $2 + ret + +Function1036f: ; 1036f (4:436f) + ld hl, wBikeFlags + bit 0, [hl] + jr z, .asm_1039c + ld hl, $7 + add hl, bc + ld a, [hl] + cp $ff + jr nz, .asm_1039c + ld hl, $6 + add hl, bc + bit 6, [hl] + jr z, .asm_1039c + ld hl, $5 + add hl, bc + set 2, [hl] + ld a, [wcf2e] + ld d, a + ld hl, $20 + add hl, bc + ld a, [hl] + and $fc + or d + ld [hl], a + scf + ret + +.asm_1039c + xor a + ret + +Function1039e: ; 1039e (4:439e) + ld a, [wTilePermissions] + ld d, a + ld a, [wcf2f] + and d + jr nz, .asm_103b2 + ld a, [wWinTextPointer] + call Function103d3 + jr c, .asm_103b2 + xor a + ret + +.asm_103b2 + scf + ret + +Function103b4: ; 103b4 (4:43b4) + ld a, [wTilePermissions] + ld d, a + ld a, [wcf2f] + and d + jr nz, .asm_103c8 + ld a, [wWinTextPointer] + call Function103da + jr c, .asm_103c8 + and a + ret + +.asm_103c8 + scf + ret + +Function103ca: ; 103ca (4:43ca) + ld a, [wPlayerBikeSurfState] + cp $1 + ret z + cp $2 + ret + +Function103d3: ; 103d3 (4:43d3) + call GetTileCollision + and a + ret z + scf + ret + +Function103da: ; 103da (4:43da) + call GetTileCollision + cp $1 + jr z, .asm_103e6 + and a + jr z, .asm_103e8 + jr .asm_103ec + +.asm_103e6 + xor a + ret + +.asm_103e8 + ld a, $1 + and a + ret + +.asm_103ec + scf + ret + +Function103ee: ; 103ee (4:43ee) + call CheckSFX + ret c + ld de, $24 + call PlaySFX + ret + +Function103f9: ; 103f9 (4:43f9) + push bc + ld a, $0 + ld [wPlayerBikeSurfState], a + call ReplacePlayerSprite + pop bc + ret + +Function10404: ; 10404 (4:4404) + ld a, [wTempTrainerHeaderEnd] + cp $0 + jr z, .asm_10420 + cp $f0 + jr z, .asm_10420 + ld a, [wPlayerStandingTile] + call CheckIceTile + jr nc, .asm_1041e + ld a, [wPlayerBikeSurfState] + cp $2 + jr nz, .asm_10420 +.asm_1041e + scf + ret + +.asm_10420 + and a + ret + +StopPlayerForEvent:: + ld hl, wce87 + ld a, $3e + cp [hl] + ret z + ld [hl], a + ld a, $0 + ld [wcf39], a + ret diff --git a/engine/overworld/player_object.asm b/engine/overworld/player_object.asm new file mode 100755 index 00000000..45562e8e --- /dev/null +++ b/engine/overworld/player_object.asm @@ -0,0 +1,786 @@ +BlankScreen: + call DisableSpriteUpdates + xor a + ld [hBGMapMode], a + call ClearBGPalettes + call ClearSprites + ld hl, wTileMap + ld bc, SCREEN_HEIGHT * SCREEN_WIDTH + ld a, " " + call ByteFill + ld hl, wAttrMap + ld bc, SCREEN_HEIGHT * SCREEN_WIDTH + ld a, $7 + call ByteFill + call Function3456 + call SetPalettes + ret + +SpawnPlayer: ; 861a (2:461a) + ld a, $ff + ld [wObjectFollow_Leader], a + ld [wObjectFollow_Follower], a + ld a, $0 + ld hl, .PlayerObjectTemplate + call CopyPlayerObjectTemplate + ld b, $0 + call PlayerSpawn_ConvertCoords + ld a, $0 + ld [hObjectStructIndexBuffer], a + ld de, wObjectStructs + ld a, $0 + ld [hMapObjectIndexBuffer], a + ld bc, wMapObjects + call CopyMapObjectToObjectStruct + ld a, $0 + ld [wCenteredObject], a + ret + +.PlayerObjectTemplate + person_event SPRITE_CHRIS, -4, -4, SPRITEMOVEDATA_PLAYER, 15, 15, -1, -1, 0, PERSONTYPE_SCRIPT, 0, 0, -1 + +CopyDECoordsToMapObject: ; 8653 (2:4653) + push de + ld a, b + call GetMapObject + pop de + ld hl, $3 + add hl, bc + ld [hl], d + ld hl, $2 + add hl, bc + ld [hl], e + ret + +PlayerSpawn_ConvertCoords: ; 8664 (2:4664) + push bc + ld a, [wXCoord] + add $4 + ld d, a + ld a, [wYCoord] + add $4 + ld e, a + pop bc + call CopyDECoordsToMapObject + ret + +WritePersonXY: + ld a, b + call CheckObjectVisibility + ret c + ld hl, $10 + add hl, bc + ld d, [hl] + ld hl, $11 + add hl, bc + ld e, [hl] + ld a, [hConnectionStripLength] + ld b, a + call CopyDECoordsToMapObject + and a + ret + +RefreshPlayerCoords: + ld a, [wXCoord] + add $4 + ld d, a + ld hl, wPlayerStandingMapX + sub [hl] + ld [hl], d + ld hl, wPlayerObjectXCoord + ld [hl], d + ld hl, wPlayerLastMapX + ld [hl], d + ld d, a + ld a, [wYCoord] + add $4 + ld e, a + ld hl, wPlayerStandingMapY + sub [hl] + ld [hl], e + ld hl, wPlayerObjectYCoord + ld [hl], e + ld hl, wPlayerLastMapY + ld [hl], e + ld e, a + ld a, [wObjectFollow_Leader] + cp $0 + ret nz + ret + +SpawnPlayer2: + ld a, $1 + ld hl, .PlayerObjectTemplate + call CopyPlayerObjectTemplate + ld b, $1 + call PlayerSpawn_ConvertCoords + ret + +.PlayerObjectTemplate: + person_event SPRITE_CHRIS, -4, -4, SPRITEMOVEDATA_12, 15, 15, -1, -1, 0, PERSONTYPE_SCRIPT, 0, 0, -1 + +CopyObjectStruct_:: ; 86d7 (2:46d7) + call CheckObjectMask + and a + ret nz + ld hl, wPlayerStructEnd + ld a, $1 + ld de, $28 +.asm_86e4 + ld [hObjectStructIndexBuffer], a + ld a, [hl] + and a + jr z, .asm_86f4 + add hl, de + ld a, [hConnectedMapWidth] + inc a + cp $d + jr nz, .asm_86e4 + scf + ret + +.asm_86f4 + ld d, h + ld e, l + call CopyMapObjectToObjectStruct + ld a, [wVramState] + bit 7, a + ret z + ld hl, $5 + add hl, de + set 5, [hl] + ret + +CopyMapObjectToObjectStruct: ; 8706 (2:4706) + call CopyMapObjectToTempObject + call CopyTempObjectToObjectStruct + ret + +CopyMapObjectToTempObject: ; 870d (2:470d) + ld a, [hConnectedMapWidth] + ld hl, $0 + add hl, bc + ld [hl], a + ld a, [hMapObjectIndexBuffer] + ld [wce99], a + ld hl, $1 + add hl, bc + ld a, [hl] + ld [wce9a], a + call GetSpriteVTile + ld [wce9b], a + ld a, [hl] + call GetSpritePalette + ld [wce9c], a + ld hl, $8 + add hl, bc + ld a, [hl] + and $f0 + jr z, .asm_873e + swap a + and $7 + ld [wce9c], a +.asm_873e + ld hl, $4 + add hl, bc + ld a, [hl] + ld [wce9d], a + ld hl, $9 + add hl, bc + ld a, [hl] + ld [wce9e], a + ld hl, $3 + add hl, bc + ld a, [hl] + ld [wce9f], a + ld hl, $2 + add hl, bc + ld a, [hl] + ld [wcea0], a + ld hl, $5 + add hl, bc + ld a, [hl] + ld [wcea1], a + ret + +InitializeVariableSprites: + ld bc, wMap2Object + ld a, $2 +.asm_876c + ld [hConnectionStripLength], a + ld hl, $1 + add hl, bc + ld a, [hl] + and a + jr z, .asm_87ab + ld hl, $0 + add hl, bc + ld a, [hl] + cp $ff + jr nz, .asm_87ab + ld a, [wXCoord] + ld d, a + ld a, [wYCoord] + ld e, a + ld hl, $3 + add hl, bc + ld a, [hl] + add $1 + sub d + jr c, .asm_87ab + cp $c + jr nc, .asm_87ab + ld hl, $2 + add hl, bc + ld a, [hl] + add $1 + sub e + jr c, .asm_87ab + cp $b + jr nc, .asm_87ab + push bc + call CopyObjectStruct_ + pop bc + jp c, Function87b9 +.asm_87ab + ld hl, $10 + add hl, bc + ld b, h + ld c, l + ld a, [hMapObjectIndexBuffer] + inc a + cp $10 + jr nz, .asm_876c + ret + +Function87b9: ; 87b9 (2:47b9) + ret + +CheckObjectEnteringVisibleRange: + nop + ld a, [wPlayerStepDirection] + cp $ff + ret z + ld hl, .Jumptable + rst JumpTable + ret + +.Jumptable: + dw Function87d5 + dw Function87ce + dw Function8822 + dw Function8829 + +Function87ce: + ld a, [wYCoord] + sub $1 + jr asm_87da + +Function87d5: + ld a, [wYCoord] + add $9 +asm_87da + ld d, a + ld a, [wXCoord] + ld e, a + ld bc, wMap2Object + ld a, $2 +.asm_87e4 + ld [hConnectionStripLength], a + ld hl, $1 + add hl, bc + ld a, [hl] + and a + jr z, .asm_8814 + ld hl, $2 + add hl, bc + ld a, d + cp [hl] + jr nz, .asm_8814 + ld hl, $0 + add hl, bc + ld a, [hl] + cp $ff + jr nz, .asm_8814 + ld hl, $3 + add hl, bc + ld a, [hl] + add $1 + sub e + jr c, .asm_8814 + cp $c + jr nc, .asm_8814 + push de + push bc + call CopyObjectStruct_ + pop bc + pop de +.asm_8814 + ld hl, $10 + add hl, bc + ld b, h + ld c, l + ld a, [hMapObjectIndexBuffer] + inc a + cp $10 + jr nz, .asm_87e4 + ret + +Function8822: + ld a, [wXCoord] + sub $1 + jr asm_882e + +Function8829: + ld a, [wXCoord] + add $a +asm_882e + ld e, a + ld a, [wYCoord] + ld d, a + ld bc, wMap2Object + ld a, $2 +.asm_8838 + ld [hConnectionStripLength], a + ld hl, $1 + add hl, bc + ld a, [hl] + and a + jr z, .asm_8868 + ld hl, $3 + add hl, bc + ld a, e + cp [hl] + jr nz, .asm_8868 + ld hl, $0 + add hl, bc + ld a, [hl] + cp $ff + jr nz, .asm_8868 + ld hl, $2 + add hl, bc + ld a, [hl] + add $1 + sub d + jr c, .asm_8868 + cp $b + jr nc, .asm_8868 + push de + push bc + call CopyObjectStruct_ + pop bc + pop de +.asm_8868 + ld hl, $10 + add hl, bc + ld b, h + ld c, l + ld a, [hConnectionStripLength] + inc a + cp $10 + jr nz, .asm_8838 + ret + +CopyTempObjectToObjectStruct: ; 8876 (2:4876) + ld a, [wce99] + ld hl, $1 + add hl, de + ld [hl], a + ld a, [wce9d] + call CopySpriteMovementData + ld a, [wce9c] + ld hl, $6 + add hl, de + or [hl] + ld [hl], a + ld a, [wcea0] + call InitTempObjectYCoord + ld a, [wce9f] + call InitTempObjectXCoord + ld a, [wce9a] + ld hl, $0 + add hl, de + ld [hl], a + ld a, [wce9b] + ld hl, $2 + add hl, de + ld [hl], a + ld hl, $9 + add hl, de + ld [hl], $0 + ld hl, $d + add hl, de + ld [hl], $ff + ld a, [wcea1] + call InitTempObjectRadius + ld a, [wce9e] + ld hl, $20 + add hl, de + ld [hl], a + and a + ret + +InitTempObjectYCoord: ; 88c5 (2:48c5) + ld hl, $15 + add hl, de + ld [hl], a + ld hl, $11 + add hl, de + ld [hl], a + ld hl, wYCoord + sub [hl] + and $f + swap a + ld hl, wce82 + sub [hl] + ld hl, $18 + add hl, de + ld [hl], a + ret + +InitTempObjectXCoord: ; 88e1 (2:48e1) + ld hl, $14 + add hl, de + ld [hl], a + ld hl, $10 + add hl, de + ld [hl], a + ld hl, wXCoord + sub [hl] + and $f + swap a + ld hl, wce81 + sub [hl] + ld hl, $17 + add hl, de + ld [hl], a + ret + +InitTempObjectRadius: ; 88fd (2:48fd) + ld h, a + inc a + and $f + ld l, a + ld a, h + add $10 + and $f0 + or l + ld hl, $16 + add hl, de + ld [hl], a + ret + +TrainerWalkToPlayer: + ld a, [hLastTalked] + call InitMovementBuffer + ld a, movement_step_sleep + call AppendToMovementBuffer + ld a, [wcf2a] + dec a + jr z, .asm_892b + ld a, [hLastTalked] + ld b, a + ld c, PLAYER + ld d, $1 + call GetTrainerPathToPlayer + call DecrementMovementBufferCount +.asm_892b + ld a, movement_step_end + call AppendToMovementBuffer + ret + +GetTrainerPathToPlayer: ; 8931 (2:4931) + push de + push bc + ld a, c + call GetMapObject + ld hl, $0 + add hl, bc + ld a, [hl] + call GetObjectStruct + ld d, b + ld e, c + pop bc + ld a, b + call GetMapObject + ld hl, $0 + add hl, bc + ld a, [hl] + call GetObjectStruct + ld hl, $10 + add hl, bc + ld a, [hl] + ld hl, $11 + add hl, bc + ld c, [hl] + ld b, a + ld hl, $10 + add hl, de + ld a, [hl] + ld hl, $11 + add hl, de + ld e, [hl] + ld d, a + pop af + call ComputePathToWalkToPlayer + ret + +Special_SurfStartStep: ; 8969 (2:4969) + call InitMovementBuffer + call GetInitialSurfStep + call AppendToMovementBuffer + ld a, movement_step_end + call AppendToMovementBuffer + ret + +GetInitialSurfStep: ; 8978 (2:4978) + ld a, [wPlayerDirection] + srl a + srl a + and $3 + ld e, a + ld d, $0 + ld hl, .Data ; $498a + add hl, de + ld a, [hl] + ret + +.Data + slow_step DOWN + slow_step UP + slow_step LEFT + slow_step RIGHT + +FollowNotExact: + push bc + ld a, c + call CheckObjectVisibility + ld d, b + ld e, c + pop bc + ret c + ld a, b + call CheckObjectVisibility + ret c + ld hl, $10 + add hl, bc + ld a, [hl] + ld hl, $11 + add hl, bc + ld c, [hl] + ld b, a + ld hl, $10 + add hl, de + ld a, [hl] + cp b + jr z, .asm_89b7 + jr c, .asm_89b4 + inc b + jr .asm_89c5 + +.asm_89b4 + dec b + jr .asm_89c5 + +.asm_89b7 + ld hl, $11 + add hl, de + ld a, [hl] + cp c + jr z, .asm_89c5 + jr c, .asm_89c4 + inc c + jr .asm_89c5 + +.asm_89c4 + dec c +.asm_89c5 + ld hl, $10 + add hl, de + ld [hl], b + ld a, b + ld hl, wXCoord + sub [hl] + and $f + swap a + ld hl, wce81 + sub [hl] + ld hl, $17 + add hl, de + ld [hl], a + ld hl, $11 + add hl, de + ld [hl], c + ld a, c + ld hl, wYCoord + sub [hl] + and $f + swap a + ld hl, wce82 + sub [hl] + ld hl, $18 + add hl, de + ld [hl], a + ld a, [hObjectStructIndexBuffer] + ld hl, $20 + add hl, de + ld [hl], a + ld hl, $3 + add hl, de + ld [hl], $1a + ld hl, $9 + add hl, de + ld [hl], $0 + ret + +GetRelativeFacing: + ld a, d + call GetMapObject + ld hl, $0 + add hl, bc + ld a, [hl] + cp $d + jr nc, .asm_8a27 + ld d, a + ld a, e + call GetMapObject + ld hl, $0 + add hl, bc + ld a, [hl] + cp $d + jr nc, .asm_8a27 + ld e, a + call GetFacing_e_relativeto_d + ret + +.asm_8a27 + scf + ret + +GetFacing_e_relativeto_d: ; 8a29 (2:4a29) + ld a, d + call GetObjectStruct + ld hl, $10 + add hl, bc + ld a, [hl] + ld hl, $11 + add hl, bc + ld c, [hl] + ld b, a + push bc + ld a, e + call GetObjectStruct + ld hl, $10 + add hl, bc + ld d, [hl] + ld hl, $11 + add hl, bc + ld e, [hl] + pop bc + ld a, b + sub d + jr z, .asm_8a5c + jr nc, .asm_8a50 + cpl + inc a +.asm_8a50 + ld h, a + ld a, c + sub e + jr z, .asm_8a6a + jr nc, .asm_8a59 + cpl + inc a +.asm_8a59 + sub h + jr c, .asm_8a6a +.asm_8a5c + ld a, c + cp e + jr z, .asm_8a78 + jr c, .asm_8a66 + ld d, $0 + and a + ret + +.asm_8a66 + ld d, $1 + and a + ret + +.asm_8a6a + ld a, b + cp d + jr z, .asm_8a78 + jr c, .asm_8a74 + ld d, $3 + and a + ret + +.asm_8a74 + ld d, $2 + and a + ret + +.asm_8a78 + scf + ret + +QueueFollowerFirstStep: ; 8a7a (2:4a7a) + call Function8a8d + jr c, .asm_8a87 + ld [wFollowMovementQueue], a + xor a + ld [wFollowerMovementQueueLength], a + ret + +.asm_8a87 + ld a, $ff + ld [wFollowerMovementQueueLength], a + ret + +Function8a8d: ; 8a8d (2:4a8d) + ld a, [wObjectFollow_Leader] + call GetObjectStruct + ld hl, $10 + add hl, bc + ld d, [hl] + ld hl, $11 + add hl, bc + ld e, [hl] + ld a, [wObjectFollow_Follower] + call GetObjectStruct + ld hl, $10 + add hl, bc + ld a, d + cp [hl] + jr z, .asm_8ab5 + jr c, .asm_8ab1 + and a + ld a, $f + ret + +.asm_8ab1 + and a + ld a, $e + ret + +.asm_8ab5 + ld hl, $11 + add hl, bc + ld a, e + cp [hl] + jr z, .asm_8ac7 + jr c, .asm_8ac3 + and a + ld a, $c + ret + +.asm_8ac3 + and a + ld a, $d + ret + +.asm_8ac7 + scf + ret diff --git a/engine/overworld/player_step.asm b/engine/overworld/player_step.asm new file mode 100755 index 00000000..c856a78a --- /dev/null +++ b/engine/overworld/player_step.asm @@ -0,0 +1,265 @@ +HandlePlayerStep_:: + ld a, [wPlayerStepFlags] + and a + ret z + bit 7, a + jr nz, .asm_d4b6 + bit 6, a + jr nz, .asm_d4c0 + bit 5, a + jr nz, .asm_d4c5 + ret + +.asm_d4b6 + ld a, $4 + ld [wd03c], a + call Functiond53c + jr .asm_d4c5 + +.asm_d4c0 + call Functiond517 + jr .asm_d4c5 + +.asm_d4c5 + call Functiond4f2 + ld a, [wPlayerStepVectorX] + ld d, a + ld a, [wPlayerStepVectorY] + ld e, a + ld a, [wce81] + sub d + ld [wce81], a + ld a, [wce82] + sub e + ld [wce82], a + ret + +ScrollScreen:: + ld a, [wPlayerStepVectorX] + ld d, a + ld a, [wPlayerStepVectorY] + ld e, a + ld a, [hSCX] + add d + ld [hSCX], a + ld a, [hSCY] + add e + ld [hSCY], a + ret + +Functiond4f2: ; d4f2 (3:54f2) + ld hl, wd03c + ld a, [hl] + and a + ret z + dec [hl] + ld a, [hl] + ld hl, .Jumptable + rst JumpTable + ret + +.Jumptable + dw GetMovementPermissions + dw BufferScreen + dw Functiond515 + dw Functiond516 + dw Functiond515 + dw Functiond515 + dw Functiond515 + dw Functiond515 + dw Functiond515 + dw Functiond515 + dw Functiond515 + +Functiond515: + ret + +Functiond516: + ret + +Functiond517: ; d517 (3:5517) + ld a, [wPlayerStepDirection] + and a + jr nz, .asm_d522 + ld hl, wYCoord + inc [hl] + ret + +.asm_d522 + cp $1 + jr nz, .asm_d52b + ld hl, wYCoord + dec [hl] + ret + +.asm_d52b + cp $2 + jr nz, .asm_d534 + ld hl, wXCoord + dec [hl] + ret + +.asm_d534 + cp $3 + ret nz + ld hl, wXCoord + inc [hl] + ret + +Functiond53c: ; d53c (3:553c) + ld a, [wPlayerStepDirection] + and a + jr z, .asm_d54f + cp $1 + jr z, .asm_d559 + cp $2 + jr z, .asm_d563 + cp $3 + jr z, .asm_d56d + ret + +.asm_d54f + call Functiond577 + call LoadMapPart + call ScrollMapUp + ret + +.asm_d559 + call Functiond5a8 + call LoadMapPart + call ScrollMapDown + ret + +.asm_d563 + call Functiond5db + call LoadMapPart + call ScrollMapRight + ret + +.asm_d56d + call Functiond604 + call LoadMapPart + call ScrollMapLeft + ret + +Functiond577: ; d577 (3:5577) + ld a, [wd05b] + add $40 + ld [wd05b], a + jr nc, .asm_d58c + ld a, [wd05c] + inc a + and $3 + or $98 + ld [wd05c], a +.asm_d58c + ld hl, wd07f + inc [hl] + ld a, [hl] + cp $2 + jr nz, .asm_d59a + ld [hl], $0 + call Functiond59b +.asm_d59a + ret + +Functiond59b: ; d59b (3:559b) + ld hl, wOverworldMapAnchor + ld a, [wMapWidth] + add $6 + add [hl] + ld [hli], a + ret nc + inc [hl] + ret + +Functiond5a8: ; d5a8 (3:55a8) + ld a, [wd05b] + sub $40 + ld [wd05b], a + jr nc, .asm_d5bd + ld a, [wd05c] + dec a + and $3 + or $98 + ld [wd05c], a +.asm_d5bd + ld hl, wd07f + dec [hl] + ld a, [hl] + cp $ff + jr nz, .asm_d5cb + ld [hl], $1 + call Functiond5cc +.asm_d5cb + ret + +Functiond5cc: ; d5cc (3:55cc) + ld hl, wOverworldMapAnchor + ld a, [wMapWidth] + add $6 + ld b, a + ld a, [hl] + sub b + ld [hli], a + ret nc + dec [hl] + ret + +Functiond5db: ; d5db (3:55db) + ld a, [wd05b] + ld e, a + and $e0 + ld d, a + ld a, e + sub $2 + and $1f + or d + ld [wd05b], a + ld hl, wd080 + dec [hl] + ld a, [hl] + cp $ff + jr nz, .asm_d5f9 + ld [hl], $1 + call Functiond5fa +.asm_d5f9 + ret + +Functiond5fa: ; d5fa (3:55fa) + ld hl, wOverworldMapAnchor + ld a, [hl] + sub $1 + ld [hli], a + ret nc + dec [hl] + ret + +Functiond604: ; d604 (3:5604) + ld a, [wd05b] + ld e, a + and $e0 + ld d, a + ld a, e + add $2 + and $1f + or d + ld [wd05b], a + ld hl, wd080 + inc [hl] + ld a, [hl] + cp $2 + jr nz, .asm_d622 + ld [hl], $0 + call Functiond623 +.asm_d622 + ret + +Functiond623: ; d623 (3:5623) + ld hl, wOverworldMapAnchor + ld a, [hl] + add $1 + ld [hli], a + ret nc + inc [hl] + ret diff --git a/engine/overworld/time.asm b/engine/overworld/time.asm new file mode 100755 index 00000000..7ad065fc --- /dev/null +++ b/engine/overworld/time.asm @@ -0,0 +1,378 @@ +InitializeStartDay_: ; 117f1 (4:57f1) + call Function118c9 + ret + +ClearDailyTimers: + xor a + ld [wLuckyNumberDayBuffer], a + ld [wUnusedTwoDayTimer], a + ld [wDailyResetTimer], a + ret + +InitCallReceiveDelay: + xor a + ld [wTimeCyclesSinceLastCall], a +Function11804: ; 11804 (4:5804) + ld a, [wTimeCyclesSinceLastCall] + cp $3 + jr c, .asm_1180d + ld a, $3 +.asm_1180d + ld e, a + ld d, $0 + ld hl, .ReceiveCallDelays + add hl, de + ld a, [hl] + jp Function11849 + +.ReceiveCallDelays: + db 20, 10, 5, 3 + +CheckReceiveCallTimer: + call Function11857 + ret nc + ld hl, wTimeCyclesSinceLastCall + ld a, [hl] + cp $3 + jr nc, .asm_11829 + inc [hl] +.asm_11829 + call Function11804 + scf + ret + +Function1182e: ; 1182e (4:582e) + ld a, $1 +Function11830: + ld [hl], a + push hl + call UpdateTime + pop hl + inc hl + call CopyDayToHL + ret + +Function1183b: ; 1183b (4:583b) + inc hl + push hl + call CalcDaysSince + call Function119b4 + pop hl + dec hl + call Function11972 + ret + +Function11849: ; 11849 (4:5849) + ld hl, wReceiveCallDelay_MinsRemaining + ld [hl], a + call UpdateTime + ld hl, wReceiveCallDelay_StartTime + call CopyDayHourMinToHL + ret + +Function11857: ; 11857 (4:5857) + ld hl, wReceiveCallDelay_StartTime + call CalcMinsHoursDaysSince + call Function1199a + ld hl, wReceiveCallDelay_MinsRemaining + call Function11972 + ret + +asm_11867 + ld hl, wDailyResetTimer + jp Function1182e + +CheckDailyResetTimer: + ld hl, wDailyResetTimer + call Function1183b + ret nc + xor a + ld hl, wDailyFlags + ld [hli], a + ld [hl], a + jr asm_11867 + +StartBugContestTimer: + ld a, 20 + ld [wBugContestMinsRemaining], a + ld a, 0 + ld [wBugContestSecsRemaining], a + call UpdateTime + ld hl, wBugContestStartTime + call CopyDayHourMinSecToHL + ret + +CheckBugContestTimer: + ld hl, wBugContestStartTime + call CalcSecsMinsHoursDaysSince + ld a, [wDaysSince] + and a + jr nz, .asm_118c0 + ld a, [wHoursSince] + and a + jr nz, .asm_118c0 + ld a, [wSecsSince] + ld b, a + ld a, [wBugContestSecsRemaining] + sub b + jr nc, .asm_118ae + add 60 +.asm_118ae + ld [wBugContestSecsRemaining], a + ld a, [wMinsSince] + ld b, a + ld a, [wBugContestMinsRemaining] + sbc b + ld [wBugContestMinsRemaining], a + jr c, .asm_118c0 + and a + ret + +.asm_118c0 + xor a + ld [wBugContestMinsRemaining], a + ld [wBugContestSecsRemaining], a + scf + ret + +Function118c9: ; 118c9 (4:58c9) + call UpdateTime + ld hl, wStartDay + call CopyDayToHL + ret + +CheckPokerusTick: + ld hl, wStartDay + call CalcDaysSince + call Function119b4 + and a + jr z, .asm_118e6 + ld b, a + callba ApplyPokerusTick ; same bank +.asm_118e6 + xor a + ret + +SetUnusedTwoDayTimer: + ld a, $2 + ld hl, wUnusedTwoDayTimer + ld [hl], a + call UpdateTime + ld hl, wUnusedTwoDayTimerStartDate + call CopyDayToHL + ret + +Function118f8: ; 118f8 (4:58f8) + ld hl, wUnusedTwoDayTimerStartDate + call CalcDaysSince + call Function119b4 + ld hl, wUnusedTwoDayTimer + call Function11972 + ret + + ld hl, wDailyFlags + set 2, [hl] + ret + + and a + ld hl, wDailyFlags + bit 2, [hl] + ret nz + scf + ret + +Function11917: ; 11917 (4:5917) + call Function11920 + ld hl, wLuckyNumberDayBuffer + jp Function11830 + +Function11920: ; 11920 (4:5920) + call GetWeekday + ld c, a + ld a, $5 + sub c + jr z, .asm_1192b + jr nc, .asm_1192d +.asm_1192b + add $7 +.asm_1192d + ret + +Function1192e: ; 1192e (4:592e) + ld hl, wLuckyNumberDayBuffer + jp Function1183b + +Function11934: ; 11934 (4:5934) + ld a, BANK(sMysteryGiftTimer) + call OpenSRAM + ld hl, sMysteryGiftTimer + ld a, [hli] + ld [wCurHPAnimMaxHP], a + ld a, [hl] + ld [wBuffer2], a + call CloseSRAM + ld hl, wCurHPAnimMaxHP + call Function1183b + jr nc, .asm_1195e + ld hl, wCurHPAnimMaxHP + call Function1182e + call CloseSRAM + callba Function2a4f6 +.asm_1195e + ld a, BANK(sMysteryGiftTimer) + call OpenSRAM + ld hl, wBuffer1 + ld a, [hli] + ld [sMysteryGiftTimer], a + ld a, [hl] + ld [sMysteryGiftTimer + 1], a + call CloseSRAM + ret + +Function11972: ; 11972 (4:5972) + cp $ff + jr z, .asm_11981 + ld c, a + ld a, [hl] + sub c + jr nc, .asm_1197c + xor a +.asm_1197c + ld [hl], a + jr z, .asm_11981 + xor a + ret + +.asm_11981 + xor a + ld [hl], a + scf + ret + +GetSecondsSinceIfLessThan60: + ld a, [wDaysSince] + and a + jr nz, asm_119b8 + ld a, [wHoursSince] + and a + jr nz, asm_119b8 + ld a, [wMinsSince] + jr nz, asm_119b8 + ld a, [wSecsSince] + ret + +Function1199a: ; 1199a (4:599a) + ld a, [wDaysSince] + and a + jr nz, asm_119b8 + ld a, [wHoursSince] + and a + jr nz, asm_119b8 + ld a, [wMinsSince] + ret + +GetHoursSinceIfLessThan24: + ld a, [wDaysSince] + and a + jr nz, asm_119b8 + ld a, [wHoursSince] + ret + +Function119b4: ; 119b4 (4:59b4) + ld a, [wDaysSince] + ret + +asm_119b8 + ld a, $ff + ret + +CalcDaysSince: ; 119bb (4:59bb) + xor a + jr CalcDaysSince_ + +CalcHoursDaysSince: + inc hl + xor a + jr CalcHoursDaysSince_ + +CalcMinsHoursDaysSince: ; 119c2 (4:59c2) + inc hl + inc hl + xor a + jr CalcMinsHoursDaysSince_ + +CalcSecsMinsHoursDaysSince: ; 119c7 (4:59c7) + inc hl + inc hl + inc hl + ld a, [hSeconds] + ld c, a + sub [hl] + jr nc, .asm_119d2 + add 60 +.asm_119d2 + ld [hl], c + dec hl + ld [wSecsSince], a +CalcMinsHoursDaysSince_ + ld a, [hMinutes] + ld c, a + sbc [hl] + jr nc, .asm_119df + add 60 +.asm_119df + ld [hl], c + dec hl + ld [wMinsSince], a +CalcHoursDaysSince_ + ld a, [hHours] + ld c, a + sbc [hl] + jr nc, .asm_119ec + add 24 +.asm_119ec + ld [hl], c + dec hl + ld [wHoursSince], a +CalcDaysSince_: + ld a, [wCurDay] + ld c, a + sbc [hl] + jr nc, .asm_119fa + add 20 * 7 +.asm_119fa + ld [hl], c + ld [wDaysSince], a + ret + +CopyDayHourMinSecToHL: ; 119ff (4:59ff) + ld a, [wCurDay] + ld [hli], a + ld a, [hHours] + ld [hli], a + ld a, [hMinutes] + ld [hli], a + ld a, [hSeconds] + ld [hli], a + ret + +CopyDayToHL: ; 11a0d (4:5a0d) + ld a, [wCurDay] + ld [hl], a + ret + +CopyDayHourToHL: + ld a, [wCurDay] + ld [hli], a + ld a, [hHours] + ld [hli], a + ret + +CopyDayHourMinToHL: ; 11a1a (4:5a1a) + ld a, [wCurDay] + ld [hli], a + ld a, [hHours] + ld [hli], a + ld a, [hMinutes] + ld [hli], a + ret diff --git a/engine/player_movement.asm b/engine/player_movement.asm deleted file mode 100755 index 61b45a72..00000000 --- a/engine/player_movement.asm +++ /dev/null @@ -1,735 +0,0 @@ -DoPlayerMovement:: ; 10000 (4:4000) - call Function10017 - ld a, movement_step_sleep - ld [wcf2d], a - xor a - ld [wcf2c], a - call Function1002d - ld c, a - ld a, [wcf2d] - ld [wce87], a - ret - -Function10017: ; 10017 (4:4017) - ld a, [hJoyDown] - ld [wcf29], a - CheckFlagHL ENGINE_DOWNHILL - ret z - ld c, a - and $f0 - ret nz - ld a, c - or $80 - ld [wcf29], a - ret - -Function1002d: ; 1002d (4:402d) - ld a, [wPlayerBikeSurfState] - cp PLAYER_NORMAL - jr z, .asm_10044 - cp PLAYER_SURF - jr z, .asm_10060 - cp PLAYER_SURF_PIKA - jr z, .asm_10060 - cp PLAYER_BIKE - jr z, .asm_10044 - cp PLAYER_SLIP - jr z, .asm_10074 -.asm_10044 - call Function102cb - call Function102ec - call Function100b7 - ret c - call Function10147 - ret c - call Function1016b - ret c - call Function101f3 - ret c - call Function10226 - ret c - jr .asm_1009d - -.asm_10060 - call Function102cb - call Function102ec - call Function100b7 - ret c - call Function10147 - ret c - call Function101c0 - ret c - jr .asm_1009d - -.asm_10074 - call Function102cb - call Function102ec - call Function100b7 - ret c - call Function10147 - ret c - call Function1016b - ret c - call Function101f3 - ret c - call Function10226 - ret c - ld a, [wcf2e] - cp $ff - jr z, .asm_10098 - call Function103ee -.asm_10098 - call Function102b3 - xor a - ret - -.asm_1009d - ld a, [wcf2e] - cp $ff - jr z, .asm_100b2 - ld a, [wTempTrainerHeader] - and a - jr nz, .asm_100ad - call Function103ee -.asm_100ad - call Function102bf - xor a - ret - -.asm_100b2 - call Function102b3 - xor a - ret - -Function100b7: ; 100b7 (4:40b7) - ld a, [wPlayerStandingTile] - ld c, a - call CheckWhirlpoolTile - jr c, .asm_100c4 - ld a, $3 - scf - ret - -.asm_100c4 - and $f0 - cp $30 - jr z, .asm_100d8 - cp $40 - jr z, .asm_100ec - cp $50 - jr z, .asm_10108 - cp $70 - jr z, .asm_10124 - jr .asm_1013c - -.asm_100d8 - ld a, c - and $3 - ld c, a - ld b, $0 - ld hl, .water_table - add hl, bc - ld a, [hl] - ld [wcf2e], a - jr .asm_1013e - -.water_table - db RIGHT - db LEFT - db UP - db DOWN - -.asm_100ec - ld a, c - and $7 - ld c, a - ld b, $0 - ld hl, .land1_table - add hl, bc - ld a, [hl] - cp $ff - jr z, .asm_1013c - ld [wcf2e], a - jr .asm_1013e - -.land1_table - db STANDING - db RIGHT - db LEFT - db UP - db DOWN - db STANDING - db STANDING - db STANDING - -.asm_10108 - ld a, c - and $7 - ld c, a - ld b, $0 - ld hl, .land2_table - add hl, bc - ld a, [hl] - cp $ff - jr z, .asm_1013c - ld [wcf2e], a - jr .asm_1013e - -.land2_table - db RIGHT - db LEFT - db UP - db DOWN - db STANDING - db STANDING - db STANDING - db STANDING - -.asm_10124 - ld a, c - cp $71 - jr z, .asm_10135 - cp $79 - jr z, .asm_10135 - cp $7a - jr z, .asm_10135 - cp $7b - jr nz, .asm_1013c -.asm_10135 - ld a, $0 - ld [wcf2e], a - jr .asm_1013e - -.asm_1013c - xor a - ret - -.asm_1013e - ld a, $1 - call Function1025f - ld a, $5 - scf - ret - -Function10147: ; 10147 (4:4147) - ld a, [wcf39] - cp $0 - jr nz, .asm_10169 - ld a, [wcf2e] - cp $ff - jr z, .asm_10169 - ld e, a - ld a, [wPlayerDirection] - rrca - rrca - and $3 - cp e - jr z, .asm_10169 - ld a, $5 - call Function1025f - ld a, $2 - scf - ret - -.asm_10169 - xor a - ret - -Function1016b: ; 1016b (4:416b) - ld a, [wPlayerBikeSurfState] - cp $4 - jr z, Function101c0 - cp $8 - jr z, Function101c0 - call Function1039e - jr c, .asm_101be - call Function10341 - and a - jr z, .asm_101be - cp $2 - jr z, .asm_101be - ld a, [wPlayerStandingTile] - call CheckIceTile - jr nc, .asm_101b5 - call Function103ca - jr nz, .asm_101ae - ld hl, wBikeFlags - bit 2, [hl] - jr z, .asm_101a7 - ld a, [wcf2e] - cp $0 - jr z, .asm_101a7 - ld a, $1 - call Function1025f - scf - ret - -.asm_101a7 - ld a, $2 - call Function1025f - scf - ret - -.asm_101ae - ld a, $1 - call Function1025f - scf - ret - -.asm_101b5 - ld a, $4 - call Function1025f - scf - ret - - xor a - ret - -.asm_101be - xor a - ret - -Function101c0: ; 101c0 (4:41c0) - call Function103b4 - ld [wcf2b], a - jr c, .asm_101f1 - call Function10341 - ld [wcf2a], a - and a - jr z, .asm_101f1 - cp $2 - jr z, .asm_101f1 - ld a, [wcf2b] - and a - jr nz, .asm_101e2 - ld a, $1 - call Function1025f - scf - ret - -.asm_101e2 - call Function103f9 - call PlayMapMusic - ld a, $1 - call Function1025f - ld a, $6 - scf - ret - -.asm_101f1 - xor a - ret - -Function101f3: ; 101f3 (4:41f3) - ld a, [wPlayerStandingTile] - ld e, a - and $f0 - cp $a0 - jr nz, .asm_1021c - ld a, e - and $7 - ld e, a - ld d, $0 - ld hl, .data_1021e - add hl, de - ld a, [wcf2f] - and [hl] - jr z, .asm_1021c - ld de, $16 - call PlaySFX - ld a, $3 - call Function1025f - ld a, $7 - scf - ret - -.asm_1021c - xor a - ret - -.data_1021e - db FACE_RIGHT - db FACE_LEFT - db FACE_UP - db FACE_DOWN - db FACE_RIGHT | FACE_DOWN - db FACE_DOWN | FACE_LEFT - db FACE_UP | FACE_RIGHT - db FACE_UP | FACE_LEFT - -Function10226: ; 10226 (4:4226) - ld a, [wcf2e] - ld e, a - ld d, $0 - ld hl, .edge_warps - add hl, de - ld a, [wPlayerStandingTile] - cp [hl] - jr nz, .asm_10259 - ld a, $1 - ld [wTempTrainerHeader], a - ld a, [wcf2e] - cp $ff - jr z, .asm_10259 - ld e, a - ld a, [wPlayerDirection] - rrca - rrca - and $3 - cp e - jr nz, .asm_10259 - call Function22a5 - jr nc, .asm_10259 - call Function102b3 - scf - ld a, $1 - ret - -.asm_10259 - xor a - ret - -.edge_warps - db $70, $78, $76, $7e - -Function1025f: ; 1025f (4:425f) - ld e, a - ld d, $0 - ld hl, .Steps - add hl, de - add hl, de - ld a, [hli] - ld h, [hl] - ld l, a - ld a, [wcf2e] - ld e, a - cp $ff - jp z, Function102b3 - add hl, de - ld a, [hl] - ld [wcf2d], a - ld hl, $42af - add hl, de - ld a, [hl] - ld [wcf39], a - ld a, $4 - ret - -.Steps: - dw .SlowStep - dw .NormalStep - dw .FastStep - dw .JumpStep - dw .SlideStep - dw .TurningStep - dw .BackJumpStep - dw .FinishFacing - -.SlowStep: - slow_step DOWN - slow_step UP - slow_step LEFT - slow_step RIGHT -.NormalStep: - step DOWN - step UP - step LEFT - step RIGHT -.FastStep: - big_step DOWN - big_step UP - big_step LEFT - big_step RIGHT -.JumpStep: - jump_step DOWN - jump_step UP - jump_step LEFT - jump_step RIGHT -.SlideStep: - fast_slide_step DOWN - fast_slide_step UP - fast_slide_step LEFT - fast_slide_step RIGHT -.BackJumpStep: - jump_step UP - jump_step DOWN - jump_step RIGHT - jump_step LEFT -.TurningStep: - turn_step DOWN - turn_step UP - turn_step LEFT - turn_step RIGHT -.FinishFacing: - db $80 + DOWN - db $80 + UP - db $80 + LEFT - db $80 + RIGHT - -Function102b3: ; 102b3 (4:42b3) - ld a, $0 - ld [wcf39], a - ld a, $3e - ld [wcf2d], a - xor a - ret - -Function102bf: ; 102bf (4:42bf) - ld a, $0 - ld [wTempTrainerHeaderEnd], a - ld a, $50 - ld [wcf2d], a - xor a - ret - -Function102cb: ; 102cb (4:42cb) - call Function10404 - ret nc - ld a, [wTempTrainerHeaderEnd] -.asm_102d2 - cp $0 - ret z - and $3 - ld e, a - ld d, $0 - ld hl, .forced_dpad - add hl, de - ld a, [wcf29] - and $f - or [hl] - ld [wcf29], a - ret - -.forced_dpad - db D_DOWN, D_UP, D_LEFT, D_RIGHT - -Function102ec: ; 102ec (4:42ec) - ld hl, .table - ld de, .table2 - .table1 - ld a, [wcf29] - bit 7, a - jr nz, .asm_10307 - bit 6, a - jr nz, .asm_10308 -.asm_102fc - bit 5, a - jr nz, .asm_10309 - bit 4, a - jr nz, .asm_1030a - jr .asm_1030b - -.asm_10307 - add hl, de -.asm_10308 - add hl, de -.asm_10309 - add hl, de -.asm_1030a - add hl, de -.asm_1030b - ld a, [hli] - ld [wcf2e], a - ld a, [hli] - ld [wcf2f], a - ld a, [hli] - ld [wcf30], a - ld a, [hli] - ld [wcf31], a - ld a, [hli] - ld h, [hl] - ld l, a - ld a, [hl] - ld [wWinTextPointer], a - ret - -.table -; struct: -; walk direction -; facing -; x movement -; y movement -; tile collision pointer -.table1 - db STANDING, FACE_CURRENT, 0, 0 - dw wPlayerStandingTile -.table2 - db RIGHT, FACE_RIGHT, 1, 0 - dw wTileRight - db LEFT, FACE_LEFT, -1, 0 - dw wTileLeft - db UP, FACE_UP, 0, -1 - dw wTileUp - db DOWN, FACE_DOWN, 0, 1 - dw wTileDown - -Function10341: ; 10341 (4:4341) - ld a, 0 - ld [hMapObjectIndexBuffer], a - ld a, [wPlayerStandingMapX] - ld d, a - ld a, [wcf30] - add d - ld d, a - ld a, [wPlayerStandingMapY] - ld e, a - ld a, [wcf31] - add e - ld e, a - ld bc, wPlayerSprite - callba Function7120 - jr nc, .asm_10369 - call Function1036f - jr c, .asm_1036c - xor a - ret - -.asm_10369 - ld a, $1 - ret - -.asm_1036c - ld a, $2 - ret - -Function1036f: ; 1036f (4:436f) - ld hl, wBikeFlags - bit 0, [hl] - jr z, .asm_1039c - ld hl, $7 - add hl, bc - ld a, [hl] - cp $ff - jr nz, .asm_1039c - ld hl, $6 - add hl, bc - bit 6, [hl] - jr z, .asm_1039c - ld hl, $5 - add hl, bc - set 2, [hl] - ld a, [wcf2e] - ld d, a - ld hl, $20 - add hl, bc - ld a, [hl] - and $fc - or d - ld [hl], a - scf - ret - -.asm_1039c - xor a - ret - -Function1039e: ; 1039e (4:439e) - ld a, [wTilePermissions] - ld d, a - ld a, [wcf2f] - and d - jr nz, .asm_103b2 - ld a, [wWinTextPointer] - call Function103d3 - jr c, .asm_103b2 - xor a - ret - -.asm_103b2 - scf - ret - -Function103b4: ; 103b4 (4:43b4) - ld a, [wTilePermissions] - ld d, a - ld a, [wcf2f] - and d - jr nz, .asm_103c8 - ld a, [wWinTextPointer] - call Function103da - jr c, .asm_103c8 - and a - ret - -.asm_103c8 - scf - ret - -Function103ca: ; 103ca (4:43ca) - ld a, [wPlayerBikeSurfState] - cp $1 - ret z - cp $2 - ret - -Function103d3: ; 103d3 (4:43d3) - call GetTileCollision - and a - ret z - scf - ret - -Function103da: ; 103da (4:43da) - call GetTileCollision - cp $1 - jr z, .asm_103e6 - and a - jr z, .asm_103e8 - jr .asm_103ec - -.asm_103e6 - xor a - ret - -.asm_103e8 - ld a, $1 - and a - ret - -.asm_103ec - scf - ret - -Function103ee: ; 103ee (4:43ee) - call CheckSFX - ret c - ld de, $24 - call PlaySFX - ret - -Function103f9: ; 103f9 (4:43f9) - push bc - ld a, $0 - ld [wPlayerBikeSurfState], a - call ReplacePlayerSprite - pop bc - ret - -Function10404: ; 10404 (4:4404) - ld a, [wTempTrainerHeaderEnd] - cp $0 - jr z, .asm_10420 - cp $f0 - jr z, .asm_10420 - ld a, [wPlayerStandingTile] - call CheckIceTile - jr nc, .asm_1041e - ld a, [wPlayerBikeSurfState] - cp $2 - jr nz, .asm_10420 -.asm_1041e - scf - ret - -.asm_10420 - and a - ret - -StopPlayerForEvent:: - ld hl, wce87 - ld a, $3e - cp [hl] - ret z - ld [hl], a - ld a, $0 - ld [wcf39], a - ret diff --git a/engine/player_object.asm b/engine/player_object.asm deleted file mode 100755 index 45562e8e..00000000 --- a/engine/player_object.asm +++ /dev/null @@ -1,786 +0,0 @@ -BlankScreen: - call DisableSpriteUpdates - xor a - ld [hBGMapMode], a - call ClearBGPalettes - call ClearSprites - ld hl, wTileMap - ld bc, SCREEN_HEIGHT * SCREEN_WIDTH - ld a, " " - call ByteFill - ld hl, wAttrMap - ld bc, SCREEN_HEIGHT * SCREEN_WIDTH - ld a, $7 - call ByteFill - call Function3456 - call SetPalettes - ret - -SpawnPlayer: ; 861a (2:461a) - ld a, $ff - ld [wObjectFollow_Leader], a - ld [wObjectFollow_Follower], a - ld a, $0 - ld hl, .PlayerObjectTemplate - call CopyPlayerObjectTemplate - ld b, $0 - call PlayerSpawn_ConvertCoords - ld a, $0 - ld [hObjectStructIndexBuffer], a - ld de, wObjectStructs - ld a, $0 - ld [hMapObjectIndexBuffer], a - ld bc, wMapObjects - call CopyMapObjectToObjectStruct - ld a, $0 - ld [wCenteredObject], a - ret - -.PlayerObjectTemplate - person_event SPRITE_CHRIS, -4, -4, SPRITEMOVEDATA_PLAYER, 15, 15, -1, -1, 0, PERSONTYPE_SCRIPT, 0, 0, -1 - -CopyDECoordsToMapObject: ; 8653 (2:4653) - push de - ld a, b - call GetMapObject - pop de - ld hl, $3 - add hl, bc - ld [hl], d - ld hl, $2 - add hl, bc - ld [hl], e - ret - -PlayerSpawn_ConvertCoords: ; 8664 (2:4664) - push bc - ld a, [wXCoord] - add $4 - ld d, a - ld a, [wYCoord] - add $4 - ld e, a - pop bc - call CopyDECoordsToMapObject - ret - -WritePersonXY: - ld a, b - call CheckObjectVisibility - ret c - ld hl, $10 - add hl, bc - ld d, [hl] - ld hl, $11 - add hl, bc - ld e, [hl] - ld a, [hConnectionStripLength] - ld b, a - call CopyDECoordsToMapObject - and a - ret - -RefreshPlayerCoords: - ld a, [wXCoord] - add $4 - ld d, a - ld hl, wPlayerStandingMapX - sub [hl] - ld [hl], d - ld hl, wPlayerObjectXCoord - ld [hl], d - ld hl, wPlayerLastMapX - ld [hl], d - ld d, a - ld a, [wYCoord] - add $4 - ld e, a - ld hl, wPlayerStandingMapY - sub [hl] - ld [hl], e - ld hl, wPlayerObjectYCoord - ld [hl], e - ld hl, wPlayerLastMapY - ld [hl], e - ld e, a - ld a, [wObjectFollow_Leader] - cp $0 - ret nz - ret - -SpawnPlayer2: - ld a, $1 - ld hl, .PlayerObjectTemplate - call CopyPlayerObjectTemplate - ld b, $1 - call PlayerSpawn_ConvertCoords - ret - -.PlayerObjectTemplate: - person_event SPRITE_CHRIS, -4, -4, SPRITEMOVEDATA_12, 15, 15, -1, -1, 0, PERSONTYPE_SCRIPT, 0, 0, -1 - -CopyObjectStruct_:: ; 86d7 (2:46d7) - call CheckObjectMask - and a - ret nz - ld hl, wPlayerStructEnd - ld a, $1 - ld de, $28 -.asm_86e4 - ld [hObjectStructIndexBuffer], a - ld a, [hl] - and a - jr z, .asm_86f4 - add hl, de - ld a, [hConnectedMapWidth] - inc a - cp $d - jr nz, .asm_86e4 - scf - ret - -.asm_86f4 - ld d, h - ld e, l - call CopyMapObjectToObjectStruct - ld a, [wVramState] - bit 7, a - ret z - ld hl, $5 - add hl, de - set 5, [hl] - ret - -CopyMapObjectToObjectStruct: ; 8706 (2:4706) - call CopyMapObjectToTempObject - call CopyTempObjectToObjectStruct - ret - -CopyMapObjectToTempObject: ; 870d (2:470d) - ld a, [hConnectedMapWidth] - ld hl, $0 - add hl, bc - ld [hl], a - ld a, [hMapObjectIndexBuffer] - ld [wce99], a - ld hl, $1 - add hl, bc - ld a, [hl] - ld [wce9a], a - call GetSpriteVTile - ld [wce9b], a - ld a, [hl] - call GetSpritePalette - ld [wce9c], a - ld hl, $8 - add hl, bc - ld a, [hl] - and $f0 - jr z, .asm_873e - swap a - and $7 - ld [wce9c], a -.asm_873e - ld hl, $4 - add hl, bc - ld a, [hl] - ld [wce9d], a - ld hl, $9 - add hl, bc - ld a, [hl] - ld [wce9e], a - ld hl, $3 - add hl, bc - ld a, [hl] - ld [wce9f], a - ld hl, $2 - add hl, bc - ld a, [hl] - ld [wcea0], a - ld hl, $5 - add hl, bc - ld a, [hl] - ld [wcea1], a - ret - -InitializeVariableSprites: - ld bc, wMap2Object - ld a, $2 -.asm_876c - ld [hConnectionStripLength], a - ld hl, $1 - add hl, bc - ld a, [hl] - and a - jr z, .asm_87ab - ld hl, $0 - add hl, bc - ld a, [hl] - cp $ff - jr nz, .asm_87ab - ld a, [wXCoord] - ld d, a - ld a, [wYCoord] - ld e, a - ld hl, $3 - add hl, bc - ld a, [hl] - add $1 - sub d - jr c, .asm_87ab - cp $c - jr nc, .asm_87ab - ld hl, $2 - add hl, bc - ld a, [hl] - add $1 - sub e - jr c, .asm_87ab - cp $b - jr nc, .asm_87ab - push bc - call CopyObjectStruct_ - pop bc - jp c, Function87b9 -.asm_87ab - ld hl, $10 - add hl, bc - ld b, h - ld c, l - ld a, [hMapObjectIndexBuffer] - inc a - cp $10 - jr nz, .asm_876c - ret - -Function87b9: ; 87b9 (2:47b9) - ret - -CheckObjectEnteringVisibleRange: - nop - ld a, [wPlayerStepDirection] - cp $ff - ret z - ld hl, .Jumptable - rst JumpTable - ret - -.Jumptable: - dw Function87d5 - dw Function87ce - dw Function8822 - dw Function8829 - -Function87ce: - ld a, [wYCoord] - sub $1 - jr asm_87da - -Function87d5: - ld a, [wYCoord] - add $9 -asm_87da - ld d, a - ld a, [wXCoord] - ld e, a - ld bc, wMap2Object - ld a, $2 -.asm_87e4 - ld [hConnectionStripLength], a - ld hl, $1 - add hl, bc - ld a, [hl] - and a - jr z, .asm_8814 - ld hl, $2 - add hl, bc - ld a, d - cp [hl] - jr nz, .asm_8814 - ld hl, $0 - add hl, bc - ld a, [hl] - cp $ff - jr nz, .asm_8814 - ld hl, $3 - add hl, bc - ld a, [hl] - add $1 - sub e - jr c, .asm_8814 - cp $c - jr nc, .asm_8814 - push de - push bc - call CopyObjectStruct_ - pop bc - pop de -.asm_8814 - ld hl, $10 - add hl, bc - ld b, h - ld c, l - ld a, [hMapObjectIndexBuffer] - inc a - cp $10 - jr nz, .asm_87e4 - ret - -Function8822: - ld a, [wXCoord] - sub $1 - jr asm_882e - -Function8829: - ld a, [wXCoord] - add $a -asm_882e - ld e, a - ld a, [wYCoord] - ld d, a - ld bc, wMap2Object - ld a, $2 -.asm_8838 - ld [hConnectionStripLength], a - ld hl, $1 - add hl, bc - ld a, [hl] - and a - jr z, .asm_8868 - ld hl, $3 - add hl, bc - ld a, e - cp [hl] - jr nz, .asm_8868 - ld hl, $0 - add hl, bc - ld a, [hl] - cp $ff - jr nz, .asm_8868 - ld hl, $2 - add hl, bc - ld a, [hl] - add $1 - sub d - jr c, .asm_8868 - cp $b - jr nc, .asm_8868 - push de - push bc - call CopyObjectStruct_ - pop bc - pop de -.asm_8868 - ld hl, $10 - add hl, bc - ld b, h - ld c, l - ld a, [hConnectionStripLength] - inc a - cp $10 - jr nz, .asm_8838 - ret - -CopyTempObjectToObjectStruct: ; 8876 (2:4876) - ld a, [wce99] - ld hl, $1 - add hl, de - ld [hl], a - ld a, [wce9d] - call CopySpriteMovementData - ld a, [wce9c] - ld hl, $6 - add hl, de - or [hl] - ld [hl], a - ld a, [wcea0] - call InitTempObjectYCoord - ld a, [wce9f] - call InitTempObjectXCoord - ld a, [wce9a] - ld hl, $0 - add hl, de - ld [hl], a - ld a, [wce9b] - ld hl, $2 - add hl, de - ld [hl], a - ld hl, $9 - add hl, de - ld [hl], $0 - ld hl, $d - add hl, de - ld [hl], $ff - ld a, [wcea1] - call InitTempObjectRadius - ld a, [wce9e] - ld hl, $20 - add hl, de - ld [hl], a - and a - ret - -InitTempObjectYCoord: ; 88c5 (2:48c5) - ld hl, $15 - add hl, de - ld [hl], a - ld hl, $11 - add hl, de - ld [hl], a - ld hl, wYCoord - sub [hl] - and $f - swap a - ld hl, wce82 - sub [hl] - ld hl, $18 - add hl, de - ld [hl], a - ret - -InitTempObjectXCoord: ; 88e1 (2:48e1) - ld hl, $14 - add hl, de - ld [hl], a - ld hl, $10 - add hl, de - ld [hl], a - ld hl, wXCoord - sub [hl] - and $f - swap a - ld hl, wce81 - sub [hl] - ld hl, $17 - add hl, de - ld [hl], a - ret - -InitTempObjectRadius: ; 88fd (2:48fd) - ld h, a - inc a - and $f - ld l, a - ld a, h - add $10 - and $f0 - or l - ld hl, $16 - add hl, de - ld [hl], a - ret - -TrainerWalkToPlayer: - ld a, [hLastTalked] - call InitMovementBuffer - ld a, movement_step_sleep - call AppendToMovementBuffer - ld a, [wcf2a] - dec a - jr z, .asm_892b - ld a, [hLastTalked] - ld b, a - ld c, PLAYER - ld d, $1 - call GetTrainerPathToPlayer - call DecrementMovementBufferCount -.asm_892b - ld a, movement_step_end - call AppendToMovementBuffer - ret - -GetTrainerPathToPlayer: ; 8931 (2:4931) - push de - push bc - ld a, c - call GetMapObject - ld hl, $0 - add hl, bc - ld a, [hl] - call GetObjectStruct - ld d, b - ld e, c - pop bc - ld a, b - call GetMapObject - ld hl, $0 - add hl, bc - ld a, [hl] - call GetObjectStruct - ld hl, $10 - add hl, bc - ld a, [hl] - ld hl, $11 - add hl, bc - ld c, [hl] - ld b, a - ld hl, $10 - add hl, de - ld a, [hl] - ld hl, $11 - add hl, de - ld e, [hl] - ld d, a - pop af - call ComputePathToWalkToPlayer - ret - -Special_SurfStartStep: ; 8969 (2:4969) - call InitMovementBuffer - call GetInitialSurfStep - call AppendToMovementBuffer - ld a, movement_step_end - call AppendToMovementBuffer - ret - -GetInitialSurfStep: ; 8978 (2:4978) - ld a, [wPlayerDirection] - srl a - srl a - and $3 - ld e, a - ld d, $0 - ld hl, .Data ; $498a - add hl, de - ld a, [hl] - ret - -.Data - slow_step DOWN - slow_step UP - slow_step LEFT - slow_step RIGHT - -FollowNotExact: - push bc - ld a, c - call CheckObjectVisibility - ld d, b - ld e, c - pop bc - ret c - ld a, b - call CheckObjectVisibility - ret c - ld hl, $10 - add hl, bc - ld a, [hl] - ld hl, $11 - add hl, bc - ld c, [hl] - ld b, a - ld hl, $10 - add hl, de - ld a, [hl] - cp b - jr z, .asm_89b7 - jr c, .asm_89b4 - inc b - jr .asm_89c5 - -.asm_89b4 - dec b - jr .asm_89c5 - -.asm_89b7 - ld hl, $11 - add hl, de - ld a, [hl] - cp c - jr z, .asm_89c5 - jr c, .asm_89c4 - inc c - jr .asm_89c5 - -.asm_89c4 - dec c -.asm_89c5 - ld hl, $10 - add hl, de - ld [hl], b - ld a, b - ld hl, wXCoord - sub [hl] - and $f - swap a - ld hl, wce81 - sub [hl] - ld hl, $17 - add hl, de - ld [hl], a - ld hl, $11 - add hl, de - ld [hl], c - ld a, c - ld hl, wYCoord - sub [hl] - and $f - swap a - ld hl, wce82 - sub [hl] - ld hl, $18 - add hl, de - ld [hl], a - ld a, [hObjectStructIndexBuffer] - ld hl, $20 - add hl, de - ld [hl], a - ld hl, $3 - add hl, de - ld [hl], $1a - ld hl, $9 - add hl, de - ld [hl], $0 - ret - -GetRelativeFacing: - ld a, d - call GetMapObject - ld hl, $0 - add hl, bc - ld a, [hl] - cp $d - jr nc, .asm_8a27 - ld d, a - ld a, e - call GetMapObject - ld hl, $0 - add hl, bc - ld a, [hl] - cp $d - jr nc, .asm_8a27 - ld e, a - call GetFacing_e_relativeto_d - ret - -.asm_8a27 - scf - ret - -GetFacing_e_relativeto_d: ; 8a29 (2:4a29) - ld a, d - call GetObjectStruct - ld hl, $10 - add hl, bc - ld a, [hl] - ld hl, $11 - add hl, bc - ld c, [hl] - ld b, a - push bc - ld a, e - call GetObjectStruct - ld hl, $10 - add hl, bc - ld d, [hl] - ld hl, $11 - add hl, bc - ld e, [hl] - pop bc - ld a, b - sub d - jr z, .asm_8a5c - jr nc, .asm_8a50 - cpl - inc a -.asm_8a50 - ld h, a - ld a, c - sub e - jr z, .asm_8a6a - jr nc, .asm_8a59 - cpl - inc a -.asm_8a59 - sub h - jr c, .asm_8a6a -.asm_8a5c - ld a, c - cp e - jr z, .asm_8a78 - jr c, .asm_8a66 - ld d, $0 - and a - ret - -.asm_8a66 - ld d, $1 - and a - ret - -.asm_8a6a - ld a, b - cp d - jr z, .asm_8a78 - jr c, .asm_8a74 - ld d, $3 - and a - ret - -.asm_8a74 - ld d, $2 - and a - ret - -.asm_8a78 - scf - ret - -QueueFollowerFirstStep: ; 8a7a (2:4a7a) - call Function8a8d - jr c, .asm_8a87 - ld [wFollowMovementQueue], a - xor a - ld [wFollowerMovementQueueLength], a - ret - -.asm_8a87 - ld a, $ff - ld [wFollowerMovementQueueLength], a - ret - -Function8a8d: ; 8a8d (2:4a8d) - ld a, [wObjectFollow_Leader] - call GetObjectStruct - ld hl, $10 - add hl, bc - ld d, [hl] - ld hl, $11 - add hl, bc - ld e, [hl] - ld a, [wObjectFollow_Follower] - call GetObjectStruct - ld hl, $10 - add hl, bc - ld a, d - cp [hl] - jr z, .asm_8ab5 - jr c, .asm_8ab1 - and a - ld a, $f - ret - -.asm_8ab1 - and a - ld a, $e - ret - -.asm_8ab5 - ld hl, $11 - add hl, bc - ld a, e - cp [hl] - jr z, .asm_8ac7 - jr c, .asm_8ac3 - and a - ld a, $c - ret - -.asm_8ac3 - and a - ld a, $d - ret - -.asm_8ac7 - scf - ret diff --git a/engine/player_step.asm b/engine/player_step.asm deleted file mode 100755 index c856a78a..00000000 --- a/engine/player_step.asm +++ /dev/null @@ -1,265 +0,0 @@ -HandlePlayerStep_:: - ld a, [wPlayerStepFlags] - and a - ret z - bit 7, a - jr nz, .asm_d4b6 - bit 6, a - jr nz, .asm_d4c0 - bit 5, a - jr nz, .asm_d4c5 - ret - -.asm_d4b6 - ld a, $4 - ld [wd03c], a - call Functiond53c - jr .asm_d4c5 - -.asm_d4c0 - call Functiond517 - jr .asm_d4c5 - -.asm_d4c5 - call Functiond4f2 - ld a, [wPlayerStepVectorX] - ld d, a - ld a, [wPlayerStepVectorY] - ld e, a - ld a, [wce81] - sub d - ld [wce81], a - ld a, [wce82] - sub e - ld [wce82], a - ret - -ScrollScreen:: - ld a, [wPlayerStepVectorX] - ld d, a - ld a, [wPlayerStepVectorY] - ld e, a - ld a, [hSCX] - add d - ld [hSCX], a - ld a, [hSCY] - add e - ld [hSCY], a - ret - -Functiond4f2: ; d4f2 (3:54f2) - ld hl, wd03c - ld a, [hl] - and a - ret z - dec [hl] - ld a, [hl] - ld hl, .Jumptable - rst JumpTable - ret - -.Jumptable - dw GetMovementPermissions - dw BufferScreen - dw Functiond515 - dw Functiond516 - dw Functiond515 - dw Functiond515 - dw Functiond515 - dw Functiond515 - dw Functiond515 - dw Functiond515 - dw Functiond515 - -Functiond515: - ret - -Functiond516: - ret - -Functiond517: ; d517 (3:5517) - ld a, [wPlayerStepDirection] - and a - jr nz, .asm_d522 - ld hl, wYCoord - inc [hl] - ret - -.asm_d522 - cp $1 - jr nz, .asm_d52b - ld hl, wYCoord - dec [hl] - ret - -.asm_d52b - cp $2 - jr nz, .asm_d534 - ld hl, wXCoord - dec [hl] - ret - -.asm_d534 - cp $3 - ret nz - ld hl, wXCoord - inc [hl] - ret - -Functiond53c: ; d53c (3:553c) - ld a, [wPlayerStepDirection] - and a - jr z, .asm_d54f - cp $1 - jr z, .asm_d559 - cp $2 - jr z, .asm_d563 - cp $3 - jr z, .asm_d56d - ret - -.asm_d54f - call Functiond577 - call LoadMapPart - call ScrollMapUp - ret - -.asm_d559 - call Functiond5a8 - call LoadMapPart - call ScrollMapDown - ret - -.asm_d563 - call Functiond5db - call LoadMapPart - call ScrollMapRight - ret - -.asm_d56d - call Functiond604 - call LoadMapPart - call ScrollMapLeft - ret - -Functiond577: ; d577 (3:5577) - ld a, [wd05b] - add $40 - ld [wd05b], a - jr nc, .asm_d58c - ld a, [wd05c] - inc a - and $3 - or $98 - ld [wd05c], a -.asm_d58c - ld hl, wd07f - inc [hl] - ld a, [hl] - cp $2 - jr nz, .asm_d59a - ld [hl], $0 - call Functiond59b -.asm_d59a - ret - -Functiond59b: ; d59b (3:559b) - ld hl, wOverworldMapAnchor - ld a, [wMapWidth] - add $6 - add [hl] - ld [hli], a - ret nc - inc [hl] - ret - -Functiond5a8: ; d5a8 (3:55a8) - ld a, [wd05b] - sub $40 - ld [wd05b], a - jr nc, .asm_d5bd - ld a, [wd05c] - dec a - and $3 - or $98 - ld [wd05c], a -.asm_d5bd - ld hl, wd07f - dec [hl] - ld a, [hl] - cp $ff - jr nz, .asm_d5cb - ld [hl], $1 - call Functiond5cc -.asm_d5cb - ret - -Functiond5cc: ; d5cc (3:55cc) - ld hl, wOverworldMapAnchor - ld a, [wMapWidth] - add $6 - ld b, a - ld a, [hl] - sub b - ld [hli], a - ret nc - dec [hl] - ret - -Functiond5db: ; d5db (3:55db) - ld a, [wd05b] - ld e, a - and $e0 - ld d, a - ld a, e - sub $2 - and $1f - or d - ld [wd05b], a - ld hl, wd080 - dec [hl] - ld a, [hl] - cp $ff - jr nz, .asm_d5f9 - ld [hl], $1 - call Functiond5fa -.asm_d5f9 - ret - -Functiond5fa: ; d5fa (3:55fa) - ld hl, wOverworldMapAnchor - ld a, [hl] - sub $1 - ld [hli], a - ret nc - dec [hl] - ret - -Functiond604: ; d604 (3:5604) - ld a, [wd05b] - ld e, a - and $e0 - ld d, a - ld a, e - add $2 - and $1f - or d - ld [wd05b], a - ld hl, wd080 - inc [hl] - ld a, [hl] - cp $2 - jr nz, .asm_d622 - ld [hl], $0 - call Functiond623 -.asm_d622 - ret - -Functiond623: ; d623 (3:5623) - ld hl, wOverworldMapAnchor - ld a, [hl] - add $1 - ld [hli], a - ret nc - inc [hl] - ret diff --git a/engine/time.asm b/engine/time.asm deleted file mode 100755 index 7ad065fc..00000000 --- a/engine/time.asm +++ /dev/null @@ -1,378 +0,0 @@ -InitializeStartDay_: ; 117f1 (4:57f1) - call Function118c9 - ret - -ClearDailyTimers: - xor a - ld [wLuckyNumberDayBuffer], a - ld [wUnusedTwoDayTimer], a - ld [wDailyResetTimer], a - ret - -InitCallReceiveDelay: - xor a - ld [wTimeCyclesSinceLastCall], a -Function11804: ; 11804 (4:5804) - ld a, [wTimeCyclesSinceLastCall] - cp $3 - jr c, .asm_1180d - ld a, $3 -.asm_1180d - ld e, a - ld d, $0 - ld hl, .ReceiveCallDelays - add hl, de - ld a, [hl] - jp Function11849 - -.ReceiveCallDelays: - db 20, 10, 5, 3 - -CheckReceiveCallTimer: - call Function11857 - ret nc - ld hl, wTimeCyclesSinceLastCall - ld a, [hl] - cp $3 - jr nc, .asm_11829 - inc [hl] -.asm_11829 - call Function11804 - scf - ret - -Function1182e: ; 1182e (4:582e) - ld a, $1 -Function11830: - ld [hl], a - push hl - call UpdateTime - pop hl - inc hl - call CopyDayToHL - ret - -Function1183b: ; 1183b (4:583b) - inc hl - push hl - call CalcDaysSince - call Function119b4 - pop hl - dec hl - call Function11972 - ret - -Function11849: ; 11849 (4:5849) - ld hl, wReceiveCallDelay_MinsRemaining - ld [hl], a - call UpdateTime - ld hl, wReceiveCallDelay_StartTime - call CopyDayHourMinToHL - ret - -Function11857: ; 11857 (4:5857) - ld hl, wReceiveCallDelay_StartTime - call CalcMinsHoursDaysSince - call Function1199a - ld hl, wReceiveCallDelay_MinsRemaining - call Function11972 - ret - -asm_11867 - ld hl, wDailyResetTimer - jp Function1182e - -CheckDailyResetTimer: - ld hl, wDailyResetTimer - call Function1183b - ret nc - xor a - ld hl, wDailyFlags - ld [hli], a - ld [hl], a - jr asm_11867 - -StartBugContestTimer: - ld a, 20 - ld [wBugContestMinsRemaining], a - ld a, 0 - ld [wBugContestSecsRemaining], a - call UpdateTime - ld hl, wBugContestStartTime - call CopyDayHourMinSecToHL - ret - -CheckBugContestTimer: - ld hl, wBugContestStartTime - call CalcSecsMinsHoursDaysSince - ld a, [wDaysSince] - and a - jr nz, .asm_118c0 - ld a, [wHoursSince] - and a - jr nz, .asm_118c0 - ld a, [wSecsSince] - ld b, a - ld a, [wBugContestSecsRemaining] - sub b - jr nc, .asm_118ae - add 60 -.asm_118ae - ld [wBugContestSecsRemaining], a - ld a, [wMinsSince] - ld b, a - ld a, [wBugContestMinsRemaining] - sbc b - ld [wBugContestMinsRemaining], a - jr c, .asm_118c0 - and a - ret - -.asm_118c0 - xor a - ld [wBugContestMinsRemaining], a - ld [wBugContestSecsRemaining], a - scf - ret - -Function118c9: ; 118c9 (4:58c9) - call UpdateTime - ld hl, wStartDay - call CopyDayToHL - ret - -CheckPokerusTick: - ld hl, wStartDay - call CalcDaysSince - call Function119b4 - and a - jr z, .asm_118e6 - ld b, a - callba ApplyPokerusTick ; same bank -.asm_118e6 - xor a - ret - -SetUnusedTwoDayTimer: - ld a, $2 - ld hl, wUnusedTwoDayTimer - ld [hl], a - call UpdateTime - ld hl, wUnusedTwoDayTimerStartDate - call CopyDayToHL - ret - -Function118f8: ; 118f8 (4:58f8) - ld hl, wUnusedTwoDayTimerStartDate - call CalcDaysSince - call Function119b4 - ld hl, wUnusedTwoDayTimer - call Function11972 - ret - - ld hl, wDailyFlags - set 2, [hl] - ret - - and a - ld hl, wDailyFlags - bit 2, [hl] - ret nz - scf - ret - -Function11917: ; 11917 (4:5917) - call Function11920 - ld hl, wLuckyNumberDayBuffer - jp Function11830 - -Function11920: ; 11920 (4:5920) - call GetWeekday - ld c, a - ld a, $5 - sub c - jr z, .asm_1192b - jr nc, .asm_1192d -.asm_1192b - add $7 -.asm_1192d - ret - -Function1192e: ; 1192e (4:592e) - ld hl, wLuckyNumberDayBuffer - jp Function1183b - -Function11934: ; 11934 (4:5934) - ld a, BANK(sMysteryGiftTimer) - call OpenSRAM - ld hl, sMysteryGiftTimer - ld a, [hli] - ld [wCurHPAnimMaxHP], a - ld a, [hl] - ld [wBuffer2], a - call CloseSRAM - ld hl, wCurHPAnimMaxHP - call Function1183b - jr nc, .asm_1195e - ld hl, wCurHPAnimMaxHP - call Function1182e - call CloseSRAM - callba Function2a4f6 -.asm_1195e - ld a, BANK(sMysteryGiftTimer) - call OpenSRAM - ld hl, wBuffer1 - ld a, [hli] - ld [sMysteryGiftTimer], a - ld a, [hl] - ld [sMysteryGiftTimer + 1], a - call CloseSRAM - ret - -Function11972: ; 11972 (4:5972) - cp $ff - jr z, .asm_11981 - ld c, a - ld a, [hl] - sub c - jr nc, .asm_1197c - xor a -.asm_1197c - ld [hl], a - jr z, .asm_11981 - xor a - ret - -.asm_11981 - xor a - ld [hl], a - scf - ret - -GetSecondsSinceIfLessThan60: - ld a, [wDaysSince] - and a - jr nz, asm_119b8 - ld a, [wHoursSince] - and a - jr nz, asm_119b8 - ld a, [wMinsSince] - jr nz, asm_119b8 - ld a, [wSecsSince] - ret - -Function1199a: ; 1199a (4:599a) - ld a, [wDaysSince] - and a - jr nz, asm_119b8 - ld a, [wHoursSince] - and a - jr nz, asm_119b8 - ld a, [wMinsSince] - ret - -GetHoursSinceIfLessThan24: - ld a, [wDaysSince] - and a - jr nz, asm_119b8 - ld a, [wHoursSince] - ret - -Function119b4: ; 119b4 (4:59b4) - ld a, [wDaysSince] - ret - -asm_119b8 - ld a, $ff - ret - -CalcDaysSince: ; 119bb (4:59bb) - xor a - jr CalcDaysSince_ - -CalcHoursDaysSince: - inc hl - xor a - jr CalcHoursDaysSince_ - -CalcMinsHoursDaysSince: ; 119c2 (4:59c2) - inc hl - inc hl - xor a - jr CalcMinsHoursDaysSince_ - -CalcSecsMinsHoursDaysSince: ; 119c7 (4:59c7) - inc hl - inc hl - inc hl - ld a, [hSeconds] - ld c, a - sub [hl] - jr nc, .asm_119d2 - add 60 -.asm_119d2 - ld [hl], c - dec hl - ld [wSecsSince], a -CalcMinsHoursDaysSince_ - ld a, [hMinutes] - ld c, a - sbc [hl] - jr nc, .asm_119df - add 60 -.asm_119df - ld [hl], c - dec hl - ld [wMinsSince], a -CalcHoursDaysSince_ - ld a, [hHours] - ld c, a - sbc [hl] - jr nc, .asm_119ec - add 24 -.asm_119ec - ld [hl], c - dec hl - ld [wHoursSince], a -CalcDaysSince_: - ld a, [wCurDay] - ld c, a - sbc [hl] - jr nc, .asm_119fa - add 20 * 7 -.asm_119fa - ld [hl], c - ld [wDaysSince], a - ret - -CopyDayHourMinSecToHL: ; 119ff (4:59ff) - ld a, [wCurDay] - ld [hli], a - ld a, [hHours] - ld [hli], a - ld a, [hMinutes] - ld [hli], a - ld a, [hSeconds] - ld [hli], a - ret - -CopyDayToHL: ; 11a0d (4:5a0d) - ld a, [wCurDay] - ld [hl], a - ret - -CopyDayHourToHL: - ld a, [wCurDay] - ld [hli], a - ld a, [hHours] - ld [hli], a - ret - -CopyDayHourMinToHL: ; 11a1a (4:5a1a) - ld a, [wCurDay] - ld [hli], a - ld a, [hHours] - ld [hli], a - ld a, [hMinutes] - ld [hli], a - ret -- cgit v1.2.3