Prev: C32D Up: Map Next: C42A
C349: New room - door setup
Used by the routine at C32D.
Follows previous routine if a door is found in one of the room item data sets.
This routine:
  • Identifies each of the doors in the new room
  • Determines which one Maroc entered from, and set his entry co-ordinates and direction accordingly
  • Calculates and stores each door's orientation, position, graphic address, and number of animation frames
C349 LD HL,($EB7A) Pointer to the current data byte for the room (from the room data set at 61A9)
C34C LD A,(HL) Get byte from room data
C34D INC HL Increment pointer
C34E LD ($EB7A),HL ...and re-store
C351 LD C,A Temp store of connecting door set number (6790) in C register
C352 LD A,($EB46) Flag indicating where this door appears in the room:
0 = Back wall door
1 = Right wall door
2 = Left wall door
C355 LD ($EB7F),A Copy this byte to working data buffer
C358 LD A,C Retrieve connecting door set number
C359 LD ($EB46),A ...and store (replace) in room element data buffer
C35C LD A,($EAB4) Current/existing connecting door set
C35F CP C Compare with the set for this door - is this the door that Maroc has entered from?
C360 JR NZ,$C38E If not, jump over the next two sets of instructions (which set Maroc's room position based on this door)
Maroc entered the room through this door, so set his new room position accordingly.
C362 LD A,($EB48) Horizontal position of door within current room, in half character (4 pixel) steps.
C365 LD ($EB75),A Copy to Maroc's horizontal room entry position store
C368 LD A,($EB4A) Vertical position within current room, in pixels, from top of room playing area
C36B SUB $0C Slight height adjustment for the new room height entry point, so that Maroc enters through the lower part of right/left doors, or near the top of the room for vertical room entry
C36D LD ($EB76),A Copy to Maroc's vertical room entry position store
Next, set his vertical/horizontal facing direction
The next conditional checks use the door's wall location byte at EB7F is used for this check:
  • 0 = Back wall door - set EAAC (vertical direction) to 254 (down)
  • 1 = Right wall door - set EAAB (horizontal direction) to 2 (left)
  • 2 = Left wall door - set EAAB (horizontal direction) to 254 (right)
C370 LD A,($EB7F)
C373 CP $00
C375 JR Z,$C389
C377 CP $01
C379 JR Z,$C382
C37B LD A,$FE
C37D LD ($EAAB),A Maroc is entering the room through a door on the left wall
C380 JR $C38E
C382 LD A,$02
C384 LD ($EAAB),A Maroc is entering the room through a door on the right wall
C387 JR $C38E
C389 LD A,$FE
C38B LD ($EAAC),A Maroc is entering the room through a door on the back wall
Calculate the address pointer to this door's connecting door set (at 6790), using the set number x 4 (as each set contains 4 bytes)
C38E LD HL,($DAF5) Address pointer to the start of the connecting door sets - 6790
C391 LD A,C Retrieve the connecting door data set number
C392 LD D,$00 The offset will be calculated in the DE register pair, so set the high byte (D) to zero
C394 RLA x2
C395 RL D
C397 RLA x4
C398 RL D If this causes a carry, rotate it into the D register
C39A AND $FC Offset will be a multiple of 4, so filter out bits 0 & 1 as not needed
C39C LD E,A
C39D ADD HL,DE Add the offset, so HL now points to the connecting door set for this door in the tables at 6790
C39E LD ($EB44),HL Store this address pointer in the door data buffer
C3A1 INC HL Move along to byte 3 of 4 in the set (door properties)
C3A2 INC HL
C3A3 LD A,(HL)
C3A4 OR $05 Set bits 0 (item visible on-screen) and 2 (item will need erasing before re-drawing)
C3A6 AND $FD Filter out bit 1 (2) - (assume door is not hidden)
C3A8 LD ($EB4E),A ...and re-store
The byte at EB7F is now used to determine which door graphic need to be set up/mirrored when Maroc enters a room.
  • This depends on which wall the door is in (back/left/right) and whether it's open or closed
  • There are 6 possible door graphics. These correspond to the 6 graphic addresses pointers stored from 97D3
  • Door 3 is only used for opening/closing animations, though its mirrored version (Door 4) is the open version of the door on the back wall.
For each door identified, the following routine sets the following registers:
Register Contents
H Door number/type (1-6)
B Horizontal position offset in 4-pixel/half-character steps
L Vertical position offset in pixels
D Positive/negative offset for door graphic frame (used in routine at CAB4)
Indicates number of frames (bits 0-2) and opening/closing direction
E Number of animation frames needed to open/close for the door (used in routine at CAB4)
C3AB LD C,A Store filtered byte in C register
C3AC LD D,$11 Default frame offset value
C3AE LD E,$05 Default value - total number of animation frames needed for door opening/closing. Back wall doors have 4 animation frames, side wall doors 5.
C3B0 LD L,$00 Height position offset of door (in pixels)
C3B2 LD A,($EB7F) 0 = Back wall door
1 = Right wall door
2 = Left wall door
C3B5 CP $01
C3B7 JR Z,$C3D0
C3B9 CP $00
C3BB JR Z,$C3E1
Door on LEFT wall - set graphic address offset and door position offset
C3BD LD B,$02 Horizontal position offset (in half-characters/4-pixel increments)
C3BF LD L,$F6 Height pixel position offset of door (-10)
C3C1 LD H,$05 Door 5 - closed door on left wall. Mirrored version of Door 2.
C3C3 LD D,$F5
C3C5 LD A,C Check bit 3 (open/closed)
C3C6 AND $08
C3C8 JR Z,$C3F2
C3CA LD D,$11
C3CC LD H,$01 Door 1 - open door on left wall.
C3CE JR $C3F2
Door on RIGHT wall - set graphic address offset and door position offset
C3D0 LD B,$FE Horizontal position offset (in half-characters/4-pixel increments)
C3D2 LD L,$F6 Height pixel position offset of door (-10)
C3D4 LD H,$02 Door 2 - closed door on right wall.
C3D6 LD A,C Check bit 3 (open/closed)
C3D7 AND $08
C3D9 JR Z,$C3F2
C3DB LD D,$F5
C3DD LD H,$06 Door 6 - open door on right wall. Mirrored version of Door 1.
C3DF JR $C3F2
Door on BACK wall - set graphic address offset and door position offset
C3E1 LD B,$FD Horizontal position offset (in half-characters/4-pixel increments)
C3E3 LD E,$04 Number of animation frames needed for door opening/closing. Back wall doors have 4, side wall doors 5.
C3E5 LD H,$04 Door 4 - open door on back wall. Mirrored version of Door 3.
C3E7 LD D,$F4
C3E9 LD A,C Check bit 3 (open/closed)
C3EA AND $08
C3EC JR NZ,$C3F2
C3EE LD D,$11
C3F0 LD H,$01 Door 1 - closed door on back wall.
Store door graphic address and position offsets
C3F2 LD A,($EB48) Horizontal (X) position of door in room (half-character/4 pixel increments)
C3F5 ADD A,B Add calculated horizontal offset
C3F6 LD ($EB48),A ...and store
C3F9 LD A,($EB4A) Vertical (Y) position of door in room (in pixels)
C3FC ADD A,L Add calculated vertical offset
C3FD LD ($EB4A),A ...and store
C400 LD A,D Door frame byte for particular door - indicates graphic offset and open/close direction, i.e. which way to advance through the graphic pointers
C401 LD ($EB80),A
C404 LD A,E Number of animation frames needed for door. Back wall doors have 4, side wall doors 5.
C405 LD ($EB81),A
C408 LD A,H Offset for the calculated door graphic frame number (1-6)
C409 LD ($EB50),A
C40C LD A,$09 Offset for base door graphics address (97C3) [offset = (17-1)*2]. Door graphic addresses start from 97D3.
C40E CALL $E0C2 Prep/mirror door graphics
Update pre-graphic byte with the number of (animation) frames for this door (4 for back wall doors, 5 for side doors)
C411 LD A,($EB4F) Get pre-graphics data byte
C414 AND $F0 Filter out bits 0-3 (the default number of frames in the byte)
C416 LD C,A
C417 LD A,($EB81) Add the number of animation frames needed for the door
C41A OR C
C41B LD ($EB4F),A Re-store amended pre-graphics byte
C41E LD A,($EB80) Copy graphic frame address offset into working data buffer
C421 LD ($EB50),A
C424 CALL $E0B0 Copy the 16 bytes of door data from EB43 into a room item data set at 7C00.
C427 JP $C32D Keep checking if there are any more doors to set up in this room
Prev: C32D Up: Map Next: C42A