Prev: 59424 Up: Map Next: 59865
59425: Handler: Lifts
Used by the routine at InitialiseGame.
Only action lifts every other frame.
Handler_Lifts 59425 LD A,(62260) A=*LiftsPiratesFrameSkip (lifts/ pirates frame skip).
59428 INC A Increment A by one.
59429 AND %00000001 Ensure A is either 0 or 1.
59431 LD (62260),A Write A back to *LiftsPiratesFrameSkip.
59434 CP 1 Return if this is a skipped frame.
59436 RET NZ
Point the UDG graphics at the lift frames.
59437 LD HL,61819 Write 61819 to *CHARS.
59440 LD (23606),HL
Walk the lift table.
59443 LD IX,(23524) IX=*ReferenceLifts.
Walk each lift in *ReferenceLifts.
Handler_Lifts_Loop 59447 LD A,(IX+0) Return if this lift entry is the terminator (255).
59450 CP 255
59452 RET Z
59453 LD A,(IX+4) Jump to Handler_Lifts_Stationary if this lift is not moving horizontally.
59456 CP 0
59458 JP Z,Handler_Lifts_Stationary
Test whether the player is standing on this lift.
59461 LD A,(62016) Jump to Handler_Lifts_Next if the player's previous vertical offset is not 3.
59464 CP 3
59466 JR NZ,Handler_Lifts_Next
59468 LD E,(IX+7) E=the lift width.
59471 LD C,(IX+0) C=the lift horizontal co-ordinate.
59474 LD B,(IX+1) B=the lift vertical co-ordinate.
59477 LD A,(62015) A=the player's previous vertical co-ordinate.
59480 SUB 3 Move up three rows to the player's feet.
59482 CP B Jump to Handler_Lifts_Next if the player is not on this lift's row.
59483 JR NZ,Handler_Lifts_Next
59485 LD C,(IX+0) C=the lift horizontal co-ordinate.
59488 LD B,(IX+1) B=the lift vertical co-ordinate.
59491 PUSH BC Stash the lift co-ordinates on the stack.
59492 CALL 3545 Call CL_SET.
59495 LD HL,(23684) HL=*DF_CC.
59498 POP BC Restore the lift co-ordinates from the stack.
59499 INC B Move one row down.
59500 PUSH HL Stash the first screen address on the stack.
59501 CALL 3545 Call CL_SET.
59504 POP HL Restore the first screen address from the stack.
59505 LD DE,(23684) DE=*DF_CC.
59509 LD A,D Move DE down seven pixel rows.
59510 ADD A,7
59512 LD D,A
59513 LD B,(IX+7) B=the lift width.
59516 LD A,(IX+2) Jump to Handler_Lifts_OverlapLoop if the lift horizontal offset is higher than 2.
59519 CP 2
59521 JR NC,Handler_Lifts_OverlapLoop
59523 INC B Widen the overlap test by one.
Handler_Lifts_OverlapLoop 59524 LD A,(DE) A=a byte from the lower scanline.
59525 AND (HL) AND it with the matching byte from the lift.
59526 JR NZ,Handler_Lifts_PlayerOnLift Jump to Handler_Lifts_PlayerOnLift if the player overlaps this lift.
59528 INC HL Advance the lift screen pointer.
59529 INC DE Advance the player screen pointer.
59530 DJNZ Handler_Lifts_OverlapLoop Decrease counter by one and loop back to Handler_Lifts_OverlapLoop until the whole lift width has been tested.
59532 JR Handler_Lifts_Next Jump to Handler_Lifts_Next.
Handler_Lifts_PlayerOnLift 59534 LD A,2 Set *FlagLiftCollision; the player is on this lift.
59536 LD (59424),A
59539 LD A,(IX+4) Jump to Handler_Lifts_NudgeVertical if this lift is not moving horizontally.
59542 CP 0
59544 JR Z,Handler_Lifts_NudgeVertical
59546 CP 255 Compare the overlap byte with 255.
59548 PUSH AF Stash AF on the stack.
59549 CALL Z,Handler_Lifts_NudgePlayerRight Nudge the player right if the overlap is solid.
59552 POP AF Restore AF from the stack.
59553 CALL NZ,Handler_Lifts_NudgePlayerLeft Nudge the player left if the overlap is not solid.
Handler_Lifts_NudgeVertical 59556 LD A,(IX+5) Jump to Handler_Lifts_Next if this lift is not moving vertically.
59559 CP 0
59561 JR Z,Handler_Lifts_Next
59563 CP 255 Compare the overlap byte with 255.
59565 PUSH AF Stash AF on the stack.
59566 CALL Z,Handler_Lifts_NudgePlayerDown Nudge the player down if the overlap is solid.
59569 POP AF Restore AF from the stack.
59570 CALL NZ,Handler_Lifts_NudgePlayerUp Nudge the player up if the overlap is not solid.
Handler_Lifts_Next 59573 CALL ApplyMovementDeltas Apply this lift's movement deltas.
59576 LD A,(IX+4) Test whether the lift is moving horizontally.
59579 CP 0
59581 PUSH AF Stash AF on the stack.
59582 CALL Z,Handler_Lifts_ReverseVertical Reverse or clamp horizontal travel if it is stationary.
59585 POP AF Restore AF from the stack.
59586 CALL NZ,Handler_Lifts_ReverseHorizontal Reverse or clamp horizontal travel if it is moving.
59589 LD (IX+0),C Write the new horizontal co-ordinate back to the lift.
59592 LD (IX+1),B Write the new vertical co-ordinate back to the lift.
59595 LD (IX+2),E Write the new horizontal offset back to the lift.
59598 LD (IX+3),D Write the new vertical offset back to the lift.
59601 CALL PrintShiftedSprite Print the lift.
59604 LD DE,16 Move IX on to the next sixteen-byte lift entry.
59607 ADD IX,DE
59609 JP Handler_Lifts_Loop Jump to Handler_Lifts_Loop.
Reverse horizontal travel when the lift hits a bound.
Handler_Lifts_ReverseHorizontal 59612 LD A,(IX+4) Jump to Handler_Lifts_ReverseHorizontalRight if the lift is moving right.
59615 CP 255
59617 JR Z,Handler_Lifts_ReverseHorizontalRight
59619 LD A,(IX+10) Return if the horizontal co-ordinate is not the left bound.
59622 CP C
59623 RET NZ
59624 LD A,(IX+11) Return if the horizontal offset is not the left bound.
59627 CP E
59628 RET NZ
59629 LD (IX+4),255 Reverse horizontal movement to the right.
59633 RET Return.
Handler_Lifts_ReverseHorizontalRight 59634 LD A,(IX+12) Return if the horizontal co-ordinate is not the right bound.
59637 CP C
59638 RET NZ
59639 LD A,(IX+13) Return if the horizontal offset is not the right bound.
59642 CP E
59643 RET NZ
59644 LD (IX+4),1 Reverse horizontal movement to the left.
59648 RET Return.
Reverse vertical travel when the lift hits a bound.
Handler_Lifts_ReverseVertical 59649 LD A,(IX+5) Jump to Handler_Lifts_ReverseVerticalDown if the lift is moving down.
59652 CP 255
59654 JR Z,Handler_Lifts_ReverseVerticalDown
59656 LD A,(IX+10) Return if the vertical co-ordinate is not the top bound.
59659 CP B
59660 RET NZ
59661 LD A,(IX+11) Return if the vertical offset is not the top bound.
59664 CP D
59665 RET NZ
59666 LD (IX+5),255 Reverse vertical movement to down.
59670 RET Return.
Handler_Lifts_ReverseVerticalDown 59671 LD A,(IX+12) Return if the vertical co-ordinate is not the bottom bound.
59674 CP B
59675 RET NZ
59676 LD A,(IX+13) Return if the vertical offset is not the bottom bound.
59679 CP D
59680 RET NZ
59681 LD (IX+5),1 Reverse vertical movement to up.
59685 RET Return.
Handler_Lifts_NudgePlayerLeft 59686 LD A,(62005) Nudge the player's horizontal movement left.
59689 INC A
59690 LD (62005),A
59693 RET Return.
Handler_Lifts_NudgePlayerRight 59694 LD A,(62005) Nudge the player's horizontal movement right.
59697 DEC A
59698 LD (62005),A
59701 RET Return.
Handler_Lifts_NudgePlayerUp 59702 LD A,(62006) Nudge the player's vertical movement up.
59705 INC A
59706 LD (62006),A
59709 RET Return.
Handler_Lifts_NudgePlayerDown 59710 LD A,(62006) Nudge the player's vertical movement down.
59713 DEC A
59714 LD (62006),A
59717 RET Return.
Stationary lift: still test whether the player is standing on it.
Handler_Lifts_Stationary 59718 LD A,(62016) A=the player's previous vertical offset.
59721 INC A Increment A by one.
59722 AND %00000011 Keep only bits 0-1.
59724 CP (IX+3) Jump to Handler_Lifts_Next if A is not equal to *IX+3.
59727 JP NZ,Handler_Lifts_Next
59730 LD C,(IX+0) C=*IX+0.
59733 LD B,(IX+1) B=*IX+1.
59736 LD A,(IX+3) A=*IX+3.
Handler_Lifts_StationaryCompareOffset 59739 CP 0 Compare A with 0.
59741 LD A,(62015) A=*PlayerPreviousVerticalCoordinate.
59744 JR Z,Handler_Lifts_StationaryCompareRow Jump to Handler_Lifts_StationaryCompareRow if A was equal to 0 on line Handler_Lifts_StationaryCompareOffset.
59746 DEC A Decrease A by one.
Handler_Lifts_StationaryCompareRow 59747 SUB 2 A-=2.
59749 CP B Jump to Handler_Lifts_Next if A is not equal to B.
59750 JP NZ,Handler_Lifts_Next
59753 LD A,(IX+3) A=*IX+3.
59756 LD C,(IX+0) C=*IX+0.
59759 LD B,(IX+1) B=*IX+1.
59762 PUSH AF Stash AF on the stack.
59763 CP 3 Call Handler_Lifts_ScanlineOffsetThree if A is equal to 3.
59765 CALL Z,Handler_Lifts_ScanlineOffsetThree
59768 POP AF Restore AF from the stack.
59769 PUSH AF Stash AF on the stack.
59770 CP 2 Call Handler_Lifts_ScanlineOffsetTwo if A is equal to 2.
59772 CALL Z,Handler_Lifts_ScanlineOffsetTwo
59775 POP AF Restore AF from the stack.
59776 PUSH AF Stash AF on the stack.
59777 CP 1 Call Handler_Lifts_ScanlineOffsetOne if A is equal to 1.
59779 CALL Z,Handler_Lifts_ScanlineOffsetOne
59782 POP AF Restore AF from the stack.
59783 CP 0 Call Handler_Lifts_ScanlineOffsetZero if A is equal to 0.
59785 CALL Z,Handler_Lifts_ScanlineOffsetZero
59788 LD B,(IX+7) B=*IX+7.
Handler_Lifts_StationaryOverlapLoop 59791 LD A,(DE) A=*DE.
59792 AND (HL) Merge the bits from *HL.
59793 JP NZ,Handler_Lifts_PlayerOnLift Jump to Handler_Lifts_PlayerOnLift if the result is not zero.
59796 INC HL Increment HL by one.
59797 INC DE Increment DE by one.
59798 DJNZ Handler_Lifts_StationaryOverlapLoop Decrease counter by one and loop back to Handler_Lifts_StationaryOverlapLoop until counter is zero.
59800 JP Handler_Lifts_Next Jump to Handler_Lifts_Next.
Handler_Lifts_ScanlineOffsetOne 59803 CALL 3545 Call CL_SET.
59806 LD HL,(23684) HL=*DF_CC.
59809 INC H Increment H by five.
59810 INC H
59811 INC H
59812 INC H
59813 INC H
59814 PUSH HL DE=HL (using the stack).
59815 POP DE
59816 INC H Increment H by one.
59817 RET Return.
Handler_Lifts_ScanlineOffsetTwo 59818 CALL 3545 Call CL_SET.
59821 LD HL,(23684) HL=*DF_CC.
59824 INC H Increment H by three.
59825 INC H
59826 INC H
59827 PUSH HL DE=HL (using the stack).
59828 POP DE
59829 INC H Increment H by one.
59830 RET Return.
Handler_Lifts_ScanlineOffsetThree 59831 CALL 3545 Call CL_SET.
59834 LD HL,(23684) HL=*DF_CC.
59837 INC H Increment H by one.
59838 PUSH HL DE=HL (using the stack).
59839 POP DE
59840 INC H Increment H by one.
59841 RET Return.
Handler_Lifts_ScanlineOffsetZero 59842 PUSH BC Stash BC on the stack.
59843 CALL 3545 Call CL_SET.
59846 POP BC Restore BC from the stack.
59847 LD DE,(23684) DE=*DF_CC.
59851 LD A,D D+=7.
59852 ADD A,7
59854 LD D,A
59855 PUSH DE Stash DE on the stack.
59856 DEC B Decrease B by one.
59857 CALL 3545 Call CL_SET.
59860 POP DE Restore DE from the stack.
59861 LD HL,(23684) HL=*DF_CC.
59864 RET Return.
Prev: 59424 Up: Map Next: 59865