Prev: ADF9 Up: Map Next: AEB0
AE0D: 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 0E and 0F of the entity. If any part of the entity is out of view then it is hidden by setting bit 7 of field 01 and when it is visible the hidden bit is only set if the entity is waiting to appear (see the wanted heading in fields 24 and 25). 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 AE0D LD H,(IX+$02) Fetch the x coordinate of the entity into HL.
AE10 LD L,(IX+$03)
AE13 LD D,(IX+$05) Fetch the y coordinate of the entity into DE.
AE16 LD E,(IX+$06)
AE19 ADD HL,DE Add them together.
AE1A LD DE,($5CE7) Fetch the horizontal origin of the view.
AE1E XOR A Clear A.
AE1F SBC HL,DE Subtract the origin from the sum.
AE21 OR H Combine A with H.
AE22 JP NZ,ProjectEntity_Hidden Jump to ProjectEntity_Hidden if the column is more than one byte, so that the entity is hidden.
AE25 LD A,L Copy the column into A.
AE26 CP $B0 Jump to ProjectEntity_Hidden if the entity starts beyond the right edge of the view.
AE28 JP NC,ProjectEntity_Hidden
AE2B LD (IX+$0E),A Set the column.
Check that the right edge of the entity is not off the left or right edge of the view.
AE2E LD A,(IX+$16) Read field 16 of the entity.
AE31 AND %00001111 Keep the width of the sprite in bytes, which is held in bits 0-3.
AE33 ADD A,A Multiply the width by eight to find it in pixels.
AE34 ADD A,A
AE35 ADD A,A
AE36 ADD A,L Add the column to find the right edge of the entity.
AE37 CP $C1 Jump to ProjectEntity_Hidden if the right edge is beyond the right of the view.
AE39 JP NC,ProjectEntity_Hidden
AE3C CP $11 Jump to ProjectEntity_Hidden if the right edge is before the left of the view.
AE3E 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.
AE41 LD H,(IX+$02) Fetch the x coordinate of the entity into HL.
AE44 LD L,(IX+$03)
AE47 SRL H Halve the x coordinate.
AE49 RR L
AE4B LD D,(IX+$05) Fetch the y coordinate of the entity into DE.
AE4E LD E,(IX+$06)
AE51 SRL D Halve the y coordinate.
AE53 RR E
AE55 XOR A Clear A.
AE56 SBC HL,DE Subtract half of the y coordinate from half of the x coordinate.
AE58 LD D,(IX+$08) Fetch the high byte of the z coordinate, less one, into D.
AE5B DEC D
AE5C LD E,(IX+$09) Fetch the low byte of the z coordinate into E.
AE5F AND A Subtract the z coordinate, so that a higher entity is drawn higher up.
AE60 SBC HL,DE
AE62 LD BC,$0040 Fetch the offset 40.
AE65 ADD HL,BC Add the offset.
AE66 LD C,(IX+$0B) Fetch the x extent, which is its size.
AE69 SRL C Halve it.
AE6B ADD HL,BC Add it, so that the row is that of the bottom of the entity.
AE6C XOR A Clear A.
AE6D LD BC,($5CEE) Fetch the vertical origin of the view.
AE71 SBC HL,BC Subtract the origin.
AE73 OR H Combine A with H.
AE74 JR NZ,ProjectEntity_Hidden Jump to ProjectEntity_Hidden if the row is more than one byte, so that the entity is hidden.
AE76 LD (IX+$0F),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.
AE79 LD A,(IX+$24) Read field 24 of the entity.
AE7C AND %11000000 Use bits 6-7.
AE7E JR Z,ProjectEntity_Delay Jump to ProjectEntity_Delay if both are reset.
AE80 CP $40 Jump to ProjectEntity_Show if they are not set to that value, to show the entity.
AE82 JR NZ,ProjectEntity_Show
ProjectEntity_Delay AE84 LD A,(IX+$25) Read field 25 of the entity.
AE87 AND A Test it.
AE88 JR Z,ProjectEntity_Show Jump to ProjectEntity_Show if it is zero, to show the entity.
AE8A AND %00000111 Use bits 0-2.
AE8C JR NZ,ProjectEntity_Hide Jump to ProjectEntity_Hide if any of them is set, to hide the entity.
AE8E LD A,(IX+$25) Read field 25 of the entity.
AE91 CP $38 Jump to ProjectEntity_Show if it is 38 or more, to show the entity.
AE93 JR NC,ProjectEntity_Show
ProjectEntity_Hide AE95 SET 7,(IX+$01) Set bit 7 of field 01 of the entity, to hide it.
AE99 JR ProjectEntity_Size Jump to ProjectEntity_Size.
ProjectEntity_Show AE9B RES 7,(IX+$01) Reset bit 7 of field 01 of the entity, to show it.
Hide the entity if the top of it is off the bottom of the view.
ProjectEntity_Size AE9F LD A,(IX+$17) Read field 17 of the entity.
AEA2 AND %00111111 Keep the height of the sprite in bits 0-5.
AEA4 LD B,A Copy it into B.
AEA5 LD A,L Copy the row into A.
AEA6 SUB B Subtract the height of the sprite to find the top row.
AEA7 RET C Return if the top row is above the view, as the entity is partly in view.
AEA8 INC A Move onto the row below and shift it into the carry flag.
AEA9 RLA
AEAA RET NC Return if the entity is within the first half of the view.
ProjectEntity_Hidden AEAB SET 7,(IX+$01) Set bit 7 of field 01 of the entity, to hide it.
AEAF RET Return.
Prev: ADF9 Up: Map Next: AEB0