Prev: 34533 Up: Map Next: 34667
34553: Start Level
Used by the routine at RestoreBottles.
Finds the data of the current level and, when it is entered at StartLevel, places the player at the start of the level (or at the position where the player last restarted) and sets the view to match.
Input
C 1 to place the player, otherwise only find the level data
StartLevel 34553 LD C,1 Set the placement flag in C to 1.
This entry point is used by the routines at SwitchPlayer and CollectBottle.
StartLevel_FindData 34555 LD A,(57055) Fetch the number of the current level from LevelNumber.
34558 ADD A,A Multiply it by four, as there are four bytes for each level in the table at LevelTable.
34559 ADD A,A
34560 LD E,A Move it into E.
34561 LD D,0 Clear D.
34563 LD HL,34533 Point HL at LevelTable.
34566 ADD HL,DE Add the offset of the level to find its entry.
34567 LD E,(HL) Fetch the low byte of the address of the data of the level.
34568 INC HL Move onto the high byte.
34569 LD D,(HL) Fetch the high byte of the address of the data of the level.
34570 LD (23806),DE Store the address in LevelHeaderAddress.
34574 DEC C Decrease the placement flag by one.
34575 RET NZ Return unless the player is to be placed.
Place the player at the start position of the level, or at the position of the last restart.
34576 PUSH DE Copy the address of the start position of the level into IX (using the stack).
34577 POP IX
34579 PUSH DE Stash the address of the start position of the level on the stack.
34580 LD A,(57079) Fetch the restart flag from 57079.
34583 AND A Test it.
34584 JR Z,StartLevel_Place Jump to StartLevel_Place if the player has not restarted.
34586 LD IX,57077 Point IX at the position of the last restart at RestartPosition instead.
StartLevel_Place 34590 LD A,(IX+0) Fetch the first byte of the start position.
34593 AND %11110000 Keep the upper four bits.
34595 LD H,A Copy them into H.
34596 LD L,1 L is 1.
34598 LD C,H Copy the upper four bits into C.
34599 LD B,0 Clear B.
34601 LD (46408),HL Write HL in the player entity at 46408.
34604 LD A,(IX+0) Fetch the first byte of the start position again.
34607 AND %00001111 Keep the lower four bits.
34609 ADD A,32 Add 32.
34611 LD L,A Copy the result into L.
34612 LD H,(IX+1) Fetch the second byte of the start position into H.
34615 LD (46402),HL Write HL in the player entity at 46402.
34618 LD A,L L moves into A.
34619 LD L,H H moves into L.
34620 LD H,A A moves into H.
34621 LD DE,65432 DE is 65432 (minus 104).
34624 ADD HL,DE Subtract 104 from the swapped position.
34625 AND A Subtract the upper four bits of the first byte of the start position.
34626 SBC HL,BC
34628 LD (23778),HL Store the result in ViewPosition.
34631 LD L,(IX+2) Fetch the third byte of the start position into L.
34634 LD H,(IX+3) Fetch the fourth byte of the start position into H.
34637 LD (46405),HL Write HL in the player entity at 46405.
34640 LD A,L L moves into A.
34641 LD L,H H moves into L.
34642 LD H,A A moves into H.
34643 ADD HL,DE Subtract 104 from the swapped position.
34644 ADD HL,BC Add the upper four bits of the first byte of the start position.
34645 LD (23780),HL Store the result in 23780.
34648 LD A,(46406) Fetch the byte of the player entity at 46406.
34651 ADD A,4 Add 4 to it.
34653 LD (46406),A Store it again.
34656 LD A,(46403) Fetch the byte of the player entity at 46403.
34659 ADD A,2 Add 2 to it.
34661 LD (46403),A Store it again.
34664 POP IX Bring back IX from the stack.
34666 RET Return.
Prev: 34533 Up: Map Next: 34667