Prev: E0F5 Up: Map Next: E1D7
E16A: Set up data for creature/warlock appearing in Maroc's room
Used by the routines at C460, D5FE, D67B and D6A4.
Input
A | Creature type/number (see EB46)
This routine is triggered:
  • when Maroc enters a room that contains a creature
  • when a creature enters the current room
  • when a warlock appears on the wall of Maroc's room
E16A LD ($EB46),A Creature type (also creature type number in data set at 6C7C)
E16D LD C,A
E16E LD A,$00
E170 LD ($EB43),A Type of graphic to draw (reset to 0 but will be set shortly)
E173 LD A,($EBB6) Number of creatures in current room
E176 CP $03 Are there 3 already?
E178 JR Z,$E1D6 If so, can't have any more, so jump straight to RET
E17A INC A Less than 3 creatures, so increase count of creatures in room by 1
E17B LD ($EBB6),A
E17E LD HL,($EBC3) Address pointer to warlock/creature information at 6C7C
Get offset to determine correct data set for particular warlock/creature:
E181 LD A,C Creature type/number (from EB46)
E182 DEC A Count starts from zero (for first set) so subtract 1
E183 RLA Each set is 8 bytes so multiply by 8
E184 RLA
E185 RLA
E186 AND $F8 Filter out unnecessary bits 0-2
E188 LD E,A Create offset in DE register
E189 LD D,$00
E18B ADD HL,DE Add to 6C7C to get to relevant data set
E18C LD ($EB44),HL ...and store
Set up creature's data:
E18F LD A,$03 Set graphic type to 3 (indicates a creature)
E191 LD ($EB43),A
E194 LD A,$00
E196 LD ($EB47),A Creatures appearing in the room will be on screen, so set low byte of horizontal position to zero...
E199 LD ($EB49),A ...and also vertical position. This indicates the creature is in the current 'viewport' and not off-screen to the right or left.
Any creatures appearing in the room will do so within the current viewport.
E19C LD ($EB4D),A Set creature's vertical movement speed to zero
E19F LD ($EB4C),A Set creature's horizontal movement speed to zero
E1A2 LD A,$40
E1A4 LD ($EB4B),A 64 = room item (as opposed to a tunnel). This forms the byte 9 in data sets at 7C00, but is otherwise unused.
Randomize the creature's horizontal & vertical co-ordinates in the room
Horizontal position:
E1A7 CALL $DB06 Generate pseudo-random number in A register
E1AA AND $1F Keep bits 0-4 (values = 0 - 31)
E1AC SUB $0F Values now vary between -15 and +16 (or 241 to 16)
E1AE LD E,A Temp store in E register
E1AF LD A,($EB7C) Get 1st room data byte which indicates room size
E1B2 RLA Multiply by 4 - this puts the base horizontal (X) co-ordinate at the centre of the room (half of the room size)
E1B3 RLA
E1B4 AND $FC (Filter out unwanted bits 0 & 1)
E1B6 ADD A,E Add the random number generated earlier to vary horizontal (X) co-ordinate somewhere between -15 and +16 earlier.
These are half-character (4-pixel) values so can mean up to 8 character squares (or 64 pixels) left or right of centre
E1B7 LD ($EB48),A ...And store
Vertical position:
E1BA CALL $DB06 Generate pseudo-random number in A register
E1BD AND $1F Keep bits 0-4 (values = 0 - 31)
E1BF ADD A,$40 Add 64. This puts the vertical position somewhere between 64 and 95 pixels from the top of the playing area, which is somewhere between the middle and bottom of the room area.
E1C1 LD ($EB4A),A Store vertical co-ordinate
Some more creature data:
E1C4 LD A,$05 Bit 0 set = creature on-screen. Bit 2 set = creature will need erasing
E1C6 LD ($EB4E),A Store in creature properties byte
E1C9 LD A,$11 Graphics address pointer frame offset. In the later calculation bit 4 is ignored however, so the offset will be [n-1]*2, i.e. no offset
E1CB LD ($EB50),A
E1CE LD DE,$0006 Move along to the 7th of the 8 bytes in the creature data set at 6C7C/6CB4
E1D1 ADD HL,DE
E1D2 LD A,(HL) Get creature graphic number (used as an offset for the graphic address table at 97C3)
E1D3 CALL $E0C2 Set up the graphics for this creature
E1D6 RET
Prev: E0F5 Up: Map Next: E1D7