Prev: 85AC Up: Map Next: 8684
85AE: Action : Handles the 'enter' action.
Used by the routine at Game_Main.
Input
Output
Action_Enter 85AE LD A,(Camera_Compass)
85B1 BIT 0,A
85B3 JR NZ,Action_Enter_0
85B5 LD DE,(Coords_EW)
85B9 JR Action_Enter_1
Action_Enter_0 85BB LD DE,(Coords_NS)
Action_Enter_1 85BF LD IX,Door_cache Data on possible exits.
85C3 LD A,$06 Number of possible exits.
85C5 LD BC,$0004 Bytes in data structure.
Action_Enter_2 85C8 PUSH AF Get next exit and check distance from current coords allowing for an error of 4 units.
85C9 LD L,(IX+$00)
85CC LD H,(IX+$01)
85CF CALL sub_abs
85D2 AND A
85D3 SBC HL,BC
85D5 JR C,Action_Enter_3
85D7 ADD IX,BC
85D9 POP AF
85DA DEC A
85DB JR NZ,Action_Enter_2
85DD RET
Exit Found
Action_Enter_3 85DE POP AF Remove unwanted data.
85DF PUSH IX Make a copy of the exit data.
85E1 POP HL
85E2 LD DE,ExitFound_Coords
85E5 LDIR
85E7 LD IX,Room_MainData Get Room address based on room index held within exit found data.
85EB LD A,(ExitFound_RoomIndex)
85EE AND A
85EF JR Z,Action_Enter_5
85F1 LD B,A
85F2 LD D,$00
Action_Enter_4 85F4 LD E,(IX+$00) Skip through data, using the size byte of each one until we hit the room required.
85F7 ADD IX,DE
85F9 DJNZ Action_Enter_4
Room found
Action_Enter_5 85FB LD (RoomEntered_DataPtr),IX Store address of the room data required.
85FF LD C,(IX+$01) Get room's data flags.
8602 LD A,C Get room type.
8603 RRA
8604 RRA
8605 RRA
8606 RRA
8607 AND $0F
8609 LD L,A Get the size of the data based on the type number.
860A LD H,$00
860C LD DE,Room_DataSizes
860F ADD HL,DE
8610 LD E,(HL)
8611 LD D,$00
See if exit, enter through, exists in data.
8613 ADD IX,DE Move indexing onto exits.
8615 LD A,C Check the exit flags (lower half of data flags). If zero (no exits) use special exit data.
8616 AND $0F
8618 JR NZ,Action_Enter_6
861A LD IX,Exit_SimpleData
Action_Enter_6 861E LD (RoomEnter_ExitDataPtr),IX Store the address for exit data.
8622 LD A,(Camera_Compass) Flip the direction of the hero, to get the exit's true direction within the room being entered.
8625 XOR $02
8627 JR Z,Action_Enter_10
8629 LD B,A Using that direction (index), search through exits to see if there is any data.
Action_Enter_7 862A RRC C Each bit in the flag represents an exit.
862C JR NC,Action_Enter_9 Skip onto next exit if bit clear.
862E LD DE,$0007 Calculate the size of exit data from type and skip onto next exit data.
8631 LD A,(IX+$00)
8634 AND $0F
8636 JR Z,Action_Enter_8
8638 LD DE,$0003
863B CP $01
863D JR Z,Action_Enter_8
863F LD DE,$0002
Action_Enter_8 8642 ADD IX,DE
Action_Enter_9 8644 DJNZ Action_Enter_7 Keep going until we have reached the exit based on the index calculated earlier.
Exit found, check if locked.
Action_Enter_10 8646 LD A,(IX+$01) Does the door require a key?
8649 AND A
864A JR Z,Action_Enter_11
864C LD HL,Inv_Pocket1 See if 'key' is being carried.
864F LD BC,$0003
8652 CPIR
8654 JR Z,Action_Enter_11
8656 CALL Message_Display If not display 'locked' on message line.
8659 DEFM "locked"
865F DEFB $5E
8660 RET
Through door.
Action_Enter_11 8661 LD (RoomEntered_EntryPtr),IX
8665 LD HL,(CurrentRoom_JP_Vector)
8668 CALL JP_HL
866B RET NZ
866C CALL Event_CreateDoor
866F RET Z
8670 LD A,$01
8672 LD (Flag_DoorEntry),A
8675 LD A,(Camera_Compass)
8678 LD (Hero_CompassFacing),A
867B LD A,$12
867D LD (Hero_Frame),A
8680 POP HL
8681 JP Stage_Draw_0
Prev: 85AC Up: Map Next: 8684