![]() |
Routines |
| Prev: 47012 | Up: Map | Next: 47325 |
|
Used by the routine at UpdateExtraRecords.
Builds the extra record for an entity, and fills the temporary entity at TemporaryEntity so that SetEntitySize can measure its sprite. Field 31 chooses the size class: below 23 is class 0, below 37 is class 1, and any higher value is class 2. A size index of zero or 255 leaves the record unset.
Bit 6 of the flags in field 30 selects the higher frame. The frame written for the temporary entity is the class when the bit is clear, and the class plus three when it is set. The same bit is copied into bit 7 of byte 12 of the extra record. Purpose of the flag beyond that choice is not yet known. The instructions at UpdateExtraRecord_Unused would step the shape bits of the height and then start a burst, but they are not reached: the class is only 0, 1 or 2, so the jump at UpdateExtraRecord_HigherFrame is always taken. The saved zero flag then makes the height adjustment subtract field 31 rather than add the z extent.
The adjusted x coordinate is the entity's x plus half of field 11 its x extent, and the adjusted y coordinate is the entity's y plus half of field 12 its y extent. Both are reduced by a margin taken from the class. The z coordinate is the entity's z less field 31 or 256 when that would leave the high byte zero. Bytes 2 and 3 of the extra record receive the adjusted x, bytes 4 and 5 the adjusted y, and bytes 6 and 7 the adjusted z. Byte 11 holds the width in bits 0-3 and the frame in bits 4-7. Byte 12 holds the height in bits 0-5.
|
||||||||||||||
|
Leave the record unset when the size index is zero or 255.
|
||||||||||||||
| UpdateExtraRecord | 47054 | LD A,(IX+31) | Fetch the size index. | |||||||||||
| 47057 | AND A | Jump to UpdateExtraRecord_Start if the size index is not zero. | ||||||||||||
| 47058 | JR NZ,UpdateExtraRecord_Start | |||||||||||||
| UpdateExtraRecord_Return | 47060 | OR %00000001 | Report that the record was not set up. | |||||||||||
| 47062 | RET | Return. | ||||||||||||
| UpdateExtraRecord_Start | 47063 | INC A | Advance the size index. | |||||||||||
| 47064 | JR Z,UpdateExtraRecord_Return | Leave the record unset if the size index was 255. | ||||||||||||
| 47066 | LD D,0 | Take class 0. | ||||||||||||
| 47068 | CP 24 | Use class 0 when the size index is below 23. | ||||||||||||
| 47070 | JR C,UpdateExtraRecord_Class | |||||||||||||
| 47072 | INC D | Take the next class. | ||||||||||||
| 47073 | CP 38 | Use class 1 when the size index is below 37. | ||||||||||||
| 47075 | JR C,UpdateExtraRecord_Class | |||||||||||||
| 47077 | INC D | Take class 2. | ||||||||||||
|
Remember a clear zero flag, so the height adjustment later subtracts the size index. Then choose the higher frame when bit 6 of the flags is set.
|
||||||||||||||
| UpdateExtraRecord_Class | 47078 | XOR A | Clear the alternate flags. | |||||||||||
| 47079 | EX AF,AF' | Save the alternate flags. | ||||||||||||
| 47080 | LD A,D | Take the class as the frame. | ||||||||||||
| 47081 | BIT 6,(IX+30) | Jump to UpdateExtraRecord_Position to keep this frame if bit 6 is clear. | ||||||||||||
| 47085 | JR Z,UpdateExtraRecord_Position | |||||||||||||
| 47087 | LD A,(IX+31) | Fetch the size index again. | ||||||||||||
| 47090 | CP 5 | Compare the size index with 5. The result is not used. | ||||||||||||
| 47092 | LD A,D | Take the class again. | ||||||||||||
| 47093 | INC A | Advance to the higher frame. | ||||||||||||
| UpdateExtraRecord_HigherFrame | 47094 | JR NC,UpdateExtraRecord_Size | Use the higher frame. This jump is always taken. | |||||||||||
|
These instructions are not reached. They would cycle bits 6-7 of the height, play the medium buzz the first time, and start a burst when the cycle wraps, clearing bit 6 of the flags.
|
||||||||||||||
| UpdateExtraRecord_Unused | 47096 | EX AF,AF' | Restore the alternate flags. | |||||||||||
| 47097 | LD A,(IX+23) | Fetch the height byte. | ||||||||||||
| 47100 | AND %11000000 | Keep the shape bits of the height. | ||||||||||||
| 47102 | JR NZ,UpdateExtraRecord_Frame | Step the shape if it has already started. | ||||||||||||
| 47104 | SET 6,(IX+23) | Set the first shape bit of the height. | ||||||||||||
| 47108 | CALL PlayMediumBuzz | Play the medium buzz. | ||||||||||||
| 47111 | JR UpdateExtraRecord_Shape | Join the shape calculation. | ||||||||||||
| UpdateExtraRecord_Frame | 47113 | LD A,(41693) | Fetch the frame counter. | |||||||||||
| 47116 | AND %00000011 | Act on every fourth frame. | ||||||||||||
| 47118 | JR NZ,UpdateExtraRecord_Shape | Leave the shape as it is on the other frames. | ||||||||||||
| 47120 | LD A,(IX+23) | Fetch the height byte. | ||||||||||||
| 47123 | ADD A,64 | Step the shape bits. | ||||||||||||
| 47125 | JR NC,UpdateExtraRecord_Store | Store the new shape if it has not wrapped. | ||||||||||||
| 47127 | CALL StartBurst | Start a burst. | ||||||||||||
| 47130 | RES 6,(IX+30) | Clear bit 6 of the flags. | ||||||||||||
| 47134 | RES 7,(IX+23) | Clear the upper shape bit of the height. | ||||||||||||
| 47138 | RES 6,(IX+23) | Clear the lower shape bit of the height. | ||||||||||||
| 47142 | JR UpdateExtraRecord_Return | Leave the record unset. | ||||||||||||
| UpdateExtraRecord_Store | 47144 | LD (IX+23),A | Store the stepped height byte. | |||||||||||
| UpdateExtraRecord_Shape | 47147 | LD A,(IX+23) | Fetch the height byte. | |||||||||||
| 47150 | RLCA | Move the shape bits down. | ||||||||||||
| 47151 | RLCA | |||||||||||||
| 47152 | NEG | Make the shape number negative. | ||||||||||||
| 47154 | AND %00000011 | Keep the two shape bits. | ||||||||||||
| UpdateExtraRecord_Size | 47156 | ADD A,2 | Move up by two frames from the shape, or from the higher frame. | |||||||||||
| 47158 | LD D,2 | Use a fixed margin for the higher frame. | ||||||||||||
|
Write the frame, then the x extent of the temporary entity, which is four times the complement of the class margin.
|
||||||||||||||
| UpdateExtraRecord_Position | 47160 | LD (47013),A | Store the frame in the temporary entity. | |||||||||||
| 47163 | LD A,D | Take the class, or the fixed margin of the higher frame. | ||||||||||||
| 47164 | ADD A,252 | Subtract four. | ||||||||||||
| 47166 | CPL | Complement the margin. | ||||||||||||
| 47167 | ADD A,A | Double the margin. | ||||||||||||
| 47168 | LD D,A | Keep the doubled margin. | ||||||||||||
| 47169 | ADD A,A | Double it again. | ||||||||||||
| 47170 | LD (47023),A | Store the x extent of the temporary entity. | ||||||||||||
|
Move the x coordinate by half of the x extent, less the margin.
|
||||||||||||||
| 47173 | LD H,(IX+2) | Fetch the high byte of the x coordinate. | ||||||||||||
| 47176 | LD L,(IX+3) | Fetch the low byte of the x coordinate. | ||||||||||||
| 47179 | LD A,(IX+11) | Fetch the x extent. | ||||||||||||
| 47182 | SRL A | Halve the x extent. | ||||||||||||
| 47184 | DEC A | Reduce it by one. | ||||||||||||
| 47185 | SUB D | Subtract the margin. | ||||||||||||
| 47186 | LD C,A | Keep the adjustment. | ||||||||||||
| 47187 | LD B,0 | Take a positive adjustment. | ||||||||||||
| 47189 | JR NC,UpdateExtraRecord_AddX | Keep the positive adjustment. | ||||||||||||
| 47191 | LD B,255 | Take a negative adjustment. | ||||||||||||
| UpdateExtraRecord_AddX | 47193 | ADD HL,BC | Add the adjustment to the x coordinate. | |||||||||||
| 47194 | LD A,L | Swap the bytes of the x coordinate. | ||||||||||||
| 47195 | LD L,H | |||||||||||||
| 47196 | LD H,A | |||||||||||||
| 47197 | LD (47014),HL | Store the adjusted x coordinate in the temporary entity. | ||||||||||||
| 47200 | LD (IY+2),L | Store the high byte of the adjusted x coordinate in the extra record. | ||||||||||||
| 47203 | LD (IY+3),H | Store the low byte of the adjusted x coordinate in the extra record. | ||||||||||||
|
Move the y coordinate by half of the y extent, less the same margin.
|
||||||||||||||
| 47206 | LD H,(IX+5) | Fetch the high byte of the y coordinate. | ||||||||||||
| 47209 | LD L,(IX+6) | Fetch the low byte of the y coordinate. | ||||||||||||
| 47212 | LD A,(IX+12) | Fetch the y extent. | ||||||||||||
| 47215 | SRL A | Halve the y extent. | ||||||||||||
| 47217 | DEC A | Reduce it by one. | ||||||||||||
| 47218 | SUB D | Subtract the margin. | ||||||||||||
| 47219 | LD B,0 | Take a positive adjustment. | ||||||||||||
| 47221 | JR NC,UpdateExtraRecord_AddY | Keep the positive adjustment. | ||||||||||||
| 47223 | LD B,255 | Take a negative adjustment. | ||||||||||||
| UpdateExtraRecord_AddY | 47225 | ADD HL,BC | Add the adjustment to the y coordinate. | |||||||||||
| 47226 | LD A,L | Swap the bytes of the y coordinate. | ||||||||||||
| 47227 | LD L,H | |||||||||||||
| 47228 | LD H,A | |||||||||||||
| 47229 | LD (47017),HL | Store the adjusted y coordinate in the temporary entity. | ||||||||||||
| 47232 | LD (IY+4),L | Store the high byte of the adjusted y coordinate in the extra record. | ||||||||||||
| 47235 | LD (IY+5),H | Store the low byte of the adjusted y coordinate in the extra record. | ||||||||||||
|
Lower the z coordinate by the size index. The saved zero flag makes this the path that is taken. The other path would add the z extent.
|
||||||||||||||
| 47238 | LD H,(IX+8) | Fetch the top byte of the z coordinate. | ||||||||||||
| 47241 | LD L,(IX+9) | Fetch the middle byte of the z coordinate. | ||||||||||||
| 47244 | LD D,0 | Clear the high byte of the subtraction. | ||||||||||||
| 47246 | EX AF,AF' | Restore the saved zero flag. | ||||||||||||
| 47247 | JR Z,UpdateExtraRecord_Height | Subtract the size index. This jump is always taken. | ||||||||||||
| 47249 | LD E,(IX+13) | Fetch the z extent. | ||||||||||||
| 47252 | ADD HL,DE | Add the z extent. This path is not taken. | ||||||||||||
| 47253 | JR UpdateExtraRecord_Finish | Join the stored height. | ||||||||||||
| UpdateExtraRecord_Height | 47255 | LD E,(IX+31) | Fetch the size index. | |||||||||||
| 47258 | XOR A | Clear the carry. | ||||||||||||
| 47259 | SBC HL,DE | Subtract the size index from the z coordinate. | ||||||||||||
| 47261 | OR H | Test the high byte of the result. | ||||||||||||
| 47262 | JR NZ,UpdateExtraRecord_Finish | Keep the result when the high byte is not zero. | ||||||||||||
| 47264 | LD HL,256 | Use a height of 256 when the result is zero. | ||||||||||||
| UpdateExtraRecord_Finish | 47267 | LD (IY+6),H | Store the high byte of the adjusted z coordinate in the extra record. | |||||||||||
| 47270 | LD (IY+7),L | Store the low byte of the adjusted z coordinate in the extra record. | ||||||||||||
| 47273 | LD A,L | Swap the bytes of the z coordinate. | ||||||||||||
| 47274 | LD L,H | |||||||||||||
| 47275 | LD H,A | |||||||||||||
| 47276 | LD (47020),HL | Store the adjusted z coordinate in the temporary entity. | ||||||||||||
| 47279 | LD IX,47012 | Use the temporary entity. | ||||||||||||
| 47283 | LD (IX+23),0 | Clear the height byte of the temporary entity. | ||||||||||||
| 47287 | CALL SetEntitySize | Measure the sprite. | ||||||||||||
| 47290 | LD A,(IX+1) | Fetch the frame of the temporary entity. | ||||||||||||
| 47293 | ADD A,A | Move the frame into the high nibble. | ||||||||||||
| 47294 | ADD A,A | |||||||||||||
| 47295 | ADD A,A | |||||||||||||
| 47296 | ADD A,A | |||||||||||||
| 47297 | LD B,A | |||||||||||||
| 47298 | LD A,(IX+22) | Fetch the width of the temporary entity. | ||||||||||||
| 47301 | AND %00001111 | Keep the width. | ||||||||||||
| 47303 | OR B | Combine the frame with the width. | ||||||||||||
| 47304 | LD (IY+11),A | Store the frame and the width in the extra record. | ||||||||||||
| 47307 | LD A,(IX+23) | Fetch the height of the temporary entity. | ||||||||||||
| 47310 | AND %00111111 | Keep the height. | ||||||||||||
| 47312 | LD B,A | Keep the height aside. | ||||||||||||
| 47313 | LD A,(IX+30) | Fetch the flags. | ||||||||||||
| 47316 | ADD A,A | Move bit 6 of the flags up to bit 7. | ||||||||||||
| 47317 | AND %10000000 | Keep that bit. | ||||||||||||
| 47319 | OR B | Combine it with the height. | ||||||||||||
| 47320 | LD (IY+12),A | Store the height in the extra record. | ||||||||||||
| 47323 | XOR A | Report that the record was set up. | ||||||||||||
| 47324 | RET | Return. | ||||||||||||
| Prev: 47012 | Up: Map | Next: 47325 |