Prev: 51551 Up: Map Next: 51702
51611: Check for an on-screen door being opened or closed
Used by the routine at 51420.
This routine follows the previous one - it runs each game cycle and checks any doors that are currently on-screen.
The next instructions set an event check number in the C register, which is later used in the CALL at 51670 (to 57301) for the door's collision/event check
51611 LD A,(60238) Get door properties byte
51614 AND 8 Check bit 3 (8) - open/closed flag. 1 if the door is open, 0 if it's closed
51616 LD C,1
51618 JR NZ,51627 If it's open, set C register value to 1 and jump a few instructions to 51627
51620 LD HL,(60228) Address pointer to door table sets at 26512
51623 INC HL
51624 INC HL
51625 INC HL
51626 LD C,(HL) Door is closed - load C register with 4th byte from door data set at 26512
C register (for event/collision detection) now contains:
  • Door OPEN = 1 - can be closed by Maroc, creatures, servant, creature missile, or
  • Door CLOSED = 4th byte of relevant door set at 26512 (door closed). This will be 0 = can be 'bumped' open by Maroc, 1 = openable by Maroc/servant/creature missile, or other event number which corresponds to an object (e.g. a key) or a spell (e.g. OPEN)
The next instructions identify the door's handle position, the 'hit box' to check for collisions. This will vary depending on the door graphic, position and whether it's open or closed.
51627 LD HL,(60241) Get address pointer to door graphics in table at 38851
51630 LD E,(HL)
51631 INC HL
51632 LD D,(HL) Get the address pointing directly at the door graphics from this table
51633 EX DE,HL ...and switch back into HL register pair
51634 INC HL
51635 LD A,(HL) Get the graphic's horizontal pixel graphic offset
51636 LD B,A Store in B register
51637 INC HL
51638 LD H,(HL) Get the graphic's vertical pixel graphic offset
51639 LD (60079),A ...store
51642 LD A,(60115) Graphic's horizontal position in pixels
51645 ADD A,B Add horizontal pixel offset
51646 LD D,A Store in D register
51647 LD A,(60114) Graphic vertical pixel position
51650 ADD A,H Add vertical pixel offset
51651 ADD A,24 We need to work out the door handle's 'hit box' for opening/closing.
The graphic position, plus vertical offset, gives us the co-ordinates at the top of the graphic. We need to define its 'hit box' more towards its middle, so add 24 pixels.
Otherwise, the door would have to be opened/closed by touching the top of it.
51653 LD E,A Store in E register
51654 LD A,(60238) Get door properties byte
51657 AND 8 Check bit 3 (8) - this is 1 if the door is open, 0 if it's closed
51659 JR Z,51670 If it's closed, skip the next few instructions and jump to 51670
Maroc opens and closes doors by bumping into the bit of the door near its handle. The position is slightly different depending on the door alignment.
The 'hit box' on the handle of OPEN doors needs to be slightly adjusted.
DOOR IS OPEN. Adjust collision area as handle may be somewhere other than its default position.
closed door on side wall open door on side wall closed door on back wall open door on back wall
51661 LD A,B Retrieve graphic's horizontal pixel graphic offset
51662 CP 248 The only door frame with this offset is the back wall open door
51664 JR Z,51670 Don't need to adjust anything if it's this one
51666 LD A,E For all other doors, subtract 8 pixels from the vertical 'hit box' position
51667 SUB 8
51669 LD E,A Store in E register - this is used for the vertical pixel collision checks in a moment at 51670
Run a collision detection check against the calculated door handle position (creatures, Maroc, servant, key, open spell, etc.).
The C register contains a value determining the type of event check to make - loaded with the 4th byte from the door data sets at 26512 - this is typically 0, occasionally 1 (meaning this door can be opened by the servant or deflected missiles), or if a door is locked its acting key event number, or spell number (e.g. OPEN).
51670 CALL 57301 Collision check routine
51673 CP 1 A register returned with either 1 (collision) or 0 (no collision)
51675 JR NZ,51687
Collision with door detected
51677 LD A,(60238) Get door properties byte
51680 AND 15 Keep bits 0-3
51682 OR 32 Set bit 5 (32) - this is a flag/trigger to indicate the door needs to be opened or closed when checked (at 51420) during the next game cycle
51684 JP 51955 Skip out to end of routine
No collision with door detected
51687 LD A,(60238) Get door properties byte
51690 LD C,A Temp store in C register
51691 AND 1 Check bit 1 - is the door visible on-screen?
51693 JP Z,53885 If not, can skip out of routine - nothing needs doing
51696 LD A,C Retrieve door properties byte
51697 AND 8 Check bit 4 (8) - 1 if door is open, 0 if closed
51699 JP Z,51958 If it's closed, jump out to the end of the routine
Prev: 51551 Up: Map Next: 51702