Prev: 44537 Up: Map Next: 44720
44557: Project Entity
Works out the screen position of an entity from its coordinates, relative to the view origin held in ViewOriginSum and ViewOriginDifference. The results are stored in fields 14 and 15 of the entity. If any part of the entity is out of view then it is hidden by setting bit 7 of field 1 and when it is visible the hidden bit is only set if the entity is waiting to appear (see the wanted heading in fields 36 and 37). Purpose of the individual tests is not yet known.
Input
IX The entity
Find the screen column of the entity. This is the sum of its x and y coordinates, less the horizontal origin of the view.
ProjectEntity 44557 LD H,(IX+2) Fetch the x coordinate of the entity into HL.
44560 LD L,(IX+3)
44563 LD D,(IX+5) Fetch the y coordinate of the entity into DE.
44566 LD E,(IX+6)
44569 ADD HL,DE Add them together.
44570 LD DE,(23783) Fetch the horizontal origin of the view.
44574 XOR A Clear A.
44575 SBC HL,DE Subtract the origin from the sum.
44577 OR H Combine A with H.
44578 JP NZ,ProjectEntity_Hidden Jump to ProjectEntity_Hidden if the column is more than one byte, so that the entity is hidden.
44581 LD A,L Copy the column into A.
44582 CP 176 Jump to ProjectEntity_Hidden if the entity starts beyond the right edge of the view.
44584 JP NC,ProjectEntity_Hidden
44587 LD (IX+14),A Set the column.
Check that the right edge of the entity is not off the left or right edge of the view.
44590 LD A,(IX+22) Read field 22 of the entity.
44593 AND %00001111 Keep the width of the sprite in bytes, which is held in bits 0-3.
44595 ADD A,A Multiply the width by eight to find it in pixels.
44596 ADD A,A
44597 ADD A,A
44598 ADD A,L Add the column to find the right edge of the entity.
44599 CP 193 Jump to ProjectEntity_Hidden if the right edge is beyond the right of the view.
44601 JP NC,ProjectEntity_Hidden
44604 CP 17 Jump to ProjectEntity_Hidden if the right edge is before the left of the view.
44606 JP C,ProjectEntity_Hidden
Find the screen row of the entity. This is half of the difference between its x and y coordinates, less its height (z coordinate), plus an offset for its size, less the vertical origin of the view.
44609 LD H,(IX+2) Fetch the x coordinate of the entity into HL.
44612 LD L,(IX+3)
44615 SRL H Halve the x coordinate.
44617 RR L
44619 LD D,(IX+5) Fetch the y coordinate of the entity into DE.
44622 LD E,(IX+6)
44625 SRL D Halve the y coordinate.
44627 RR E
44629 XOR A Clear A.
44630 SBC HL,DE Subtract half of the y coordinate from half of the x coordinate.
44632 LD D,(IX+8) Fetch the high byte of the z coordinate, less one, into D.
44635 DEC D
44636 LD E,(IX+9) Fetch the low byte of the z coordinate into E.
44639 AND A Subtract the z coordinate, so that a higher entity is drawn higher up.
44640 SBC HL,DE
44642 LD BC,64 Fetch the offset 64.
44645 ADD HL,BC Add the offset.
44646 LD C,(IX+11) Fetch the x extent, which is its size.
44649 SRL C Halve it.
44651 ADD HL,BC Add it, so that the row is that of the bottom of the entity.
44652 XOR A Clear A.
44653 LD BC,(23790) Fetch the vertical origin of the view.
44657 SBC HL,BC Subtract the origin.
44659 OR H Combine A with H.
44660 JR NZ,ProjectEntity_Hidden Jump to ProjectEntity_Hidden if the row is more than one byte, so that the entity is hidden.
44662 LD (IX+15),L Set the row.
Decide whether the entity is shown yet. An entity that is turning towards its wanted heading is hidden until it has faced the right way.
44665 LD A,(IX+36) Read field 36 of the entity.
44668 AND %11000000 Use bits 6-7.
44670 JR Z,ProjectEntity_Delay Jump to ProjectEntity_Delay if both are reset.
44672 CP 64 Jump to ProjectEntity_Show if they are not set to that value, to show the entity.
44674 JR NZ,ProjectEntity_Show
ProjectEntity_Delay 44676 LD A,(IX+37) Read field 37 of the entity.
44679 AND A Test it.
44680 JR Z,ProjectEntity_Show Jump to ProjectEntity_Show if it is zero, to show the entity.
44682 AND %00000111 Use bits 0-2.
44684 JR NZ,ProjectEntity_Hide Jump to ProjectEntity_Hide if any of them is set, to hide the entity.
44686 LD A,(IX+37) Read field 37 of the entity.
44689 CP 56 Jump to ProjectEntity_Show if it is 56 or more, to show the entity.
44691 JR NC,ProjectEntity_Show
ProjectEntity_Hide 44693 SET 7,(IX+1) Set bit 7 of field 1 of the entity, to hide it.
44697 JR ProjectEntity_Size Jump to ProjectEntity_Size.
ProjectEntity_Show 44699 RES 7,(IX+1) Reset bit 7 of field 1 of the entity, to show it.
Hide the entity if the top of it is off the bottom of the view.
ProjectEntity_Size 44703 LD A,(IX+23) Read field 23 of the entity.
44706 AND %00111111 Keep the height of the sprite in bits 0-5.
44708 LD B,A Copy it into B.
44709 LD A,L Copy the row into A.
44710 SUB B Subtract the height of the sprite to find the top row.
44711 RET C Return if the top row is above the view, as the entity is partly in view.
44712 INC A Move onto the row below and shift it into the carry flag.
44713 RLA
44714 RET NC Return if the entity is within the first half of the view.
ProjectEntity_Hidden 44715 SET 7,(IX+1) Set bit 7 of field 1 of the entity, to hide it.
44719 RET Return.
Prev: 44537 Up: Map Next: 44720