Prev: 57589 Up: Map Next: 57815
57706: Set up data for creature/warlock appearing in Maroc's room
Used by the routines at 50272, 54782, 54907 and 54948.
Input
A | Creature type/number (see 60230)
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
57706 LD (60230),A Creature type (also creature type number in data set at 27772)
57709 LD C,A
57710 LD A,0
57712 LD (60227),A Type of graphic to draw (reset to 0 but will be set shortly)
57715 LD A,(60342) Number of creatures in current room
57718 CP 3 Are there 3 already?
57720 JR Z,57814 If so, can't have any more, so jump straight to RET
57722 INC A Less than 3 creatures, so increase count of creatures in room by 1
57723 LD (60342),A
57726 LD HL,(60355) Address pointer to warlock/creature information at 27772
Get offset to determine correct data set for particular warlock/creature:
57729 LD A,C Creature type/number (from 60230)
57730 DEC A Count starts from zero (for first set) so subtract 1
57731 RLA Each set is 8 bytes so multiply by 8
57732 RLA
57733 RLA
57734 AND 248 Filter out unnecessary bits 0-2
57736 LD E,A Create offset in DE register
57737 LD D,0
57739 ADD HL,DE Add to 27772 to get to relevant data set
57740 LD (60228),HL ...and store
Set up creature's data:
57743 LD A,3 Set graphic type to 3 (indicates a creature)
57745 LD (60227),A
57748 LD A,0
57750 LD (60231),A Creatures appearing in the room will be on screen, so set low byte of horizontal position to zero...
57753 LD (60233),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.
57756 LD (60237),A Set creature's vertical movement speed to zero
57759 LD (60236),A Set creature's horizontal movement speed to zero
57762 LD A,64
57764 LD (60235),A 64 = room item (as opposed to a tunnel). This forms the byte 9 in data sets at 31744, but is otherwise unused.
Randomize the creature's horizontal & vertical co-ordinates in the room
Horizontal position:
57767 CALL 56070 Generate pseudo-random number in A register
57770 AND 31 Keep bits 0-4 (values = 0 - 31)
57772 SUB 15 Values now vary between -15 and +16 (or 241 to 16)
57774 LD E,A Temp store in E register
57775 LD A,(60284) Get 1st room data byte which indicates room size
57778 RLA Multiply by 4 - this puts the base horizontal (X) co-ordinate at the centre of the room (half of the room size)
57779 RLA
57780 AND 252 (Filter out unwanted bits 0 & 1)
57782 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
57783 LD (60232),A ...And store
Vertical position:
57786 CALL 56070 Generate pseudo-random number in A register
57789 AND 31 Keep bits 0-4 (values = 0 - 31)
57791 ADD A,64 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.
57793 LD (60234),A Store vertical co-ordinate
Some more creature data:
57796 LD A,5 Bit 0 set = creature on-screen. Bit 2 set = creature will need erasing
57798 LD (60238),A Store in creature properties byte
57801 LD A,17 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
57803 LD (60240),A
57806 LD DE,6 Move along to the 7th of the 8 bytes in the creature data set at 27772/27828
57809 ADD HL,DE
57810 LD A,(HL) Get creature graphic number (used as an offset for the graphic address table at 38851)
57811 CALL 57538 Set up the graphics for this creature
57814 RET
Prev: 57589 Up: Map Next: 57815