Prev: C95F Up: Map Next: C9F6
C99B: Check for an on-screen door being opened or closed
Used by the routine at C8DC.
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 C9D6 (to DFD5) for the door's collision/event check
C99B LD A,($EB4E) Get door properties byte
C99E AND $08 Check bit 3 (8) - open/closed flag. 1 if the door is open, 0 if it's closed
C9A0 LD C,$01
C9A2 JR NZ,$C9AB If it's open, set C register value to 1 and jump a few instructions to C9AB
C9A4 LD HL,($EB44) Address pointer to door table sets at 6790
C9A7 INC HL
C9A8 INC HL
C9A9 INC HL
C9AA LD C,(HL) Door is closed - load C register with 4th byte from door data set at 6790
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 6790 (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.
C9AB LD HL,($EB51) Get address pointer to door graphics in table at 97C3
C9AE LD E,(HL)
C9AF INC HL
C9B0 LD D,(HL) Get the address pointing directly at the door graphics from this table
C9B1 EX DE,HL ...and switch back into HL register pair
C9B2 INC HL
C9B3 LD A,(HL) Get the graphic's horizontal pixel graphic offset
C9B4 LD B,A Store in B register
C9B5 INC HL
C9B6 LD H,(HL) Get the graphic's vertical pixel graphic offset
C9B7 LD ($EAAF),A ...store
C9BA LD A,($EAD3) Graphic's horizontal position in pixels
C9BD ADD A,B Add horizontal pixel offset
C9BE LD D,A Store in D register
C9BF LD A,($EAD2) Graphic vertical pixel position
C9C2 ADD A,H Add vertical pixel offset
C9C3 ADD A,$18 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.
C9C5 LD E,A Store in E register
C9C6 LD A,($EB4E) Get door properties byte
C9C9 AND $08 Check bit 3 (8) - this is 1 if the door is open, 0 if it's closed
C9CB JR Z,$C9D6 If it's closed, skip the next few instructions and jump to C9D6
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
C9CD LD A,B Retrieve graphic's horizontal pixel graphic offset
C9CE CP $F8 The only door frame with this offset is the back wall open door
C9D0 JR Z,$C9D6 Don't need to adjust anything if it's this one
C9D2 LD A,E For all other doors, subtract 8 pixels from the vertical 'hit box' position
C9D3 SUB $08
C9D5 LD E,A Store in E register - this is used for the vertical pixel collision checks in a moment at C9D6
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 6790 - 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).
C9D6 CALL $DFD5 Collision check routine
C9D9 CP $01 A register returned with either 1 (collision) or 0 (no collision)
C9DB JR NZ,$C9E7
Collision with door detected
C9DD LD A,($EB4E) Get door properties byte
C9E0 AND $0F Keep bits 0-3
C9E2 OR $20 Set bit 5 (32) - this is a flag/trigger to indicate the door needs to be opened or closed when checked (at C8DC) during the next game cycle
C9E4 JP $CAF3 Skip out to end of routine
No collision with door detected
C9E7 LD A,($EB4E) Get door properties byte
C9EA LD C,A Temp store in C register
C9EB AND $01 Check bit 1 - is the door visible on-screen?
C9ED JP Z,$D27D If not, can skip out of routine - nothing needs doing
C9F0 LD A,C Retrieve door properties byte
C9F1 AND $08 Check bit 4 (8) - 1 if door is open, 0 if closed
C9F3 JP Z,$CAF6 If it's closed, jump out to the end of the routine
Prev: C95F Up: Map Next: C9F6