Prev: 56070 Up: Map Next: 56216
56095: Set up missile data and calculate trajectory
Used by the routine at 55188.
Input
A Missile number (see table at 27868)
Calculates and puts missile data into room object sets at 31744 for missiles fired by Maroc at creatures, and vice versa. Also calculates trajectory based on origin/target co-ordinates.
First, calculate the address pointer to the missile set (table at 27868) using the missile number:
56095 LD C,A Temp store missile number in C register
56096 LD HL,(60353) Address pointer to missile data table at 27868
56099 DEC A Offset needed is 0-8 (not 1-9) so decrement missile number
56100 LD D,0 Store offset in DE register pair
56102 LD E,A
56103 LD B,8 8 bytes in each missile data set
56105 ADD HL,DE
56106 DJNZ 56105 Continue adding until HL is pointing at the start of this missile's data set in the table at 27868
56108 LD (60315),HL Store missile table address pointer
Create a new room item data set for the missile at 31744, and copy a few variables from the missile-related data at 27868 and 60305 into it.
56111 INC HL
56112 LD A,(HL) Get missile properties byte (second byte in missile data set at 27868)
56113 LD (60318),A ...and copy into the missile data buffer (starts from 60305)
56116 DEC HL
56117 EX DE,HL Swap (start of) data set pointer into DE register pair
56118 LD HL,(60274) Address pointer to next data bank at 31744
56121 LD A,(60314) Item type. 5 = missile fired by creature/warlock, or 8 = missile fired by Maroc
56124 LD (HL),A Put in first byte of room item data set at 31744
56125 INC HL
56126 LD (HL),E Store address pointer to start of missile table at 27868 in bytes 2 & 3 of room item data set (at 31744)
56127 INC HL
56128 LD (HL),D
56129 INC HL
56130 LD (HL),C Store missile number (table at 27868) as byte 4 of room item data set (at 31744)
56131 INC HL
56132 LD B,4 Copy 4 bytes of data to room item (missile) data set at 31744:
  • 60308 --> byte 5 of set (horizontal position precision/fraction byte)
  • 60309 --> byte 6 of set (horizontal position in 4-pixel steps)
  • 60310 --> byte 7 of set (vertical position precision/fraction byte)
  • 60311 --> byte 8 of set (vertical pixel position)
56134 LD DE,60308
56137 LD A,(DE)
56138 LD (HL),A
56139 INC DE
56140 INC HL
56141 DJNZ 56137
56143 LD (HL),64 9th data byte in room item data sets at 31744 - this is 64 for 'standard' room items (rather than 254/255 for 'tunnel' room items)
56145 INC HL Advance address pointer one byte along
Calculate difference between positions of missile origin and target, in 2-pixel steps. Then store this calculation in the missile data set in the room sets at 31744.
Horizontal position difference (between origin and target) calculation:
56146 LD A,(60309) Horizontal position of missile origin (half-character steps)
56149 LD C,A
56150 LD A,(60312) Horizontal position of target (half-character steps)
56153 SUB C Subtract to get the difference
56154 ADD A,A Double the difference to get the horizontal difference (either positive or negative) in 2-pixel increments
56155 LD (HL),A ...and store in data set (byte 10 of data set)
56156 INC HL
Vertical position difference (between origin and target) calculation:
56157 LD A,(60311) Vertical screen position of missile origin (in pixels)
56160 LD C,A
56161 LD A,(60313) Vertical screen position of missile target (in pixels)
56164 SUB C Subtract to get the difference
56165 SRA A Halve to get difference in 2-pixel increments
56167 LD (HL),A ...and store in data set (byte 11 of data set)
56168 INC HL
Finally, copy missile graphics properties and pointers into room data set at 31744.
56169 LD A,1 Missile graphic frame offset (frame 1 = no offset)
56171 LD (60240),A
56174 LD DE,(60315) Retrieve address pointer to missile data table at 27868
56178 LD A,(DE) Get graphic number for the missile graphics for use in the following CALL
56179 LD (60274),HL Temp store for address pointer current position in the data at 31744
56182 CALL 57538 Set up missile graphics
56185 LD HL,(60274) Retrieve data set address pointer stored before the CALL
56188 LD A,(60318) Missile properties byte
56191 LD (HL),A Store as 12th byte of room item data set
56192 INC HL
56193 LD A,(60239) Missile pre-graphics data byte
56196 LD (HL),A Store as 13th byte of set
56197 INC HL
56198 LD A,17 Graphic frame offset. Only bits 0-3 will be used to calculate the graphics animation frame, so the value is effectively 1 (= no offset). Stored in 14th byte of set at 31744
56200 LD (HL),A
56201 INC HL
56202 LD DE,(60241) Missile graphics address pointer (table at 38851)
56206 LD (HL),E Store as the last two byes in the data set
56207 INC HL
56208 LD (HL),D
56209 INC HL
56210 LD (HL),255 Put end-of-data marker at start of next data set...
56212 LD (60274),HL ...and store data set pointer
56215 RET
Prev: 56070 Up: Map Next: 56216