Prev: ADBE Up: Map Next: AE98
ADD8: Find Object Screen Position
Used by the routines at SpawnEnemy and PrepareDraw.
Works out where an object is on the screen from its position on the planet and the position of the part of the planet that is on the screen. If the object is off the screen, its slot is freed. Otherwise the horizontal and vertical screen positions are stored at offsets 11 and 12, and the object is flagged as visible with bit 7 of offset 10. The wrap flag (bit 6 of offset 10) is set if the object has crossed the edge of the part of the planet that is on the screen.
Input
DE Address of the sprite
IX Address of the object
FindObjectScreenPosition ADD8 LD A,(DE) Read DE.
ADD9 ADD A,A Double A.
ADDA ADD A,A Double A.
ADDB ADD A,A Double A.
ADDC LD B,A B=A.
ADDD INC DE Advance DE.
ADDE LD A,(DE) Read DE.
ADDF LD C,A C=A.
ADE0 LD A,($CE45) The position across.
ADE3 LD E,A E=A.
ADE4 LD A,(IX+$02) The horizontal position.
ADE7 AND %11111110 Keep the bits of A that are set in FE.
ADE9 LD L,A L=A.
ADEA LD A,($DDF7) The next column.
ADED CP (IX+$01) Jump to FindObjectScreenPosition_Edge if A is the byte at offset 01 of IX.
ADF0 JP Z,FindObjectScreenPosition_Edge
ADF3 LD A,($CE57) The map position.
ADF6 CP (IX+$01) Jump to FindObjectScreenPosition_Wrap if A is the byte at offset 01 of IX.
ADF9 JR Z,FindObjectScreenPosition_Wrap
ADFB LD A,($A1D7) The rows of the sprite that was drawn.
ADFE AND A Jump to FindObjectScreenPosition_Free if A is zero.
ADFF JP Z,FindObjectScreenPosition_Free
AE02 LD A,L A=L.
AE03 ADD A,$17 Add 17 to A.
AE05 ADD A,B A gains B.
AE06 JP NC,FindObjectScreenPosition_Free Jump to FindObjectScreenPosition_Free if the carry flag is clear.
AE09 LD A,(IX+$02) The horizontal position.
AE0C CP $80 Jump to FindObjectScreenPosition_Free if A is less than 80.
AE0E JP C,FindObjectScreenPosition_Free
AE11 LD A,E A=E.
AE12 ADD A,$B0 Add B0 to A.
AE14 LD E,A E=A.
AE15 LD A,L A=L.
AE16 SUB $30 Subtract 30 from A.
AE18 LD L,A L=A.
FindObjectScreenPosition_Wrap AE19 LD A,L A=L.
AE1A CP E Jump to FindObjectScreenPosition_Horizontal if A is E or more.
AE1B JR NC,FindObjectScreenPosition_Horizontal
AE1D ADD A,B A gains B.
AE1E JR C,FindObjectScreenPosition_Row Jump to FindObjectScreenPosition_Row if the carry flag is set.
AE20 DEC A Step A back.
AE21 CP E Return if A is less than E.
AE22 RET C
FindObjectScreenPosition_Row AE23 LD A,E A=E.
AE24 SUB L Subtract L from A.
AE25 SUB $09 Subtract 09 from A.
AE27 JR C,FindObjectScreenPosition_Horizontal Jump to FindObjectScreenPosition_Horizontal if the carry flag is set.
AE29 SET 6,(IX+$10) Set bit 6 of offset 10 of IX.
AE2D LD A,$01 A=01.
AE2F LD ($A2FA),A The sprite reaches past the right of the screen.
FindObjectScreenPosition_Horizontal AE32 LD A,($CE57) The map position.
AE35 CP (IX+$01) Jump to FindObjectScreenPosition_Same if A is the byte at offset 01 of IX.
AE38 JR Z,FindObjectScreenPosition_Same
AE3A LD A,($DDF7) The next column.
AE3D CP (IX+$01) Jump to FindObjectScreenPosition_Same if A is the byte at offset 01 of IX.
AE40 JR Z,FindObjectScreenPosition_Same
AE42 LD A,L A=L.
AE43 SUB E Subtract E from A.
AE44 ADD A,$08 Add 08 to A.
AE46 LD L,A L=A.
AE47 JR FindObjectScreenPosition_StoreX Jump to FindObjectScreenPosition_StoreX.
FindObjectScreenPosition_Same AE49 LD A,($CE41) The horizontal offset.
AE4C ADD A,L A gains L.
FindObjectScreenPosition_StoreX AE4D LD ($A1D5),A The horizontal screen position.
AE50 LD (IX+$11),A Write the horizontal screen position.
AE53 JP FindObjectScreenPosition_Vertical Jump to FindObjectScreenPosition_Vertical.
FindObjectScreenPosition_Edge AE56 LD A,L A=L.
AE57 CP E Return if A is E or more.
AE58 RET NC
AE59 ADD A,$E0 Add E0 to A.
AE5B LD L,A L=A.
AE5C JR FindObjectScreenPosition_Horizontal Jump to FindObjectScreenPosition_Horizontal.
FindObjectScreenPosition_Vertical AE5E LD L,(IX+$05) The vertical position.
AE61 LD A,($CE46) The position down.
AE64 LD E,A E=A.
AE65 LD A,($CE58) The map row.
AE68 CP (IX+$04) Jump to FindObjectScreenPosition_NextZone if A is not the byte at offset 04 of IX.
AE6B JR NZ,FindObjectScreenPosition_NextZone
AE6D LD A,L A=L.
AE6E DEC A Step A back.
AE6F CP E Return if A is less than E.
AE70 RET C
AE71 ADD A,$61 Add 61 to A.
AE73 LD L,A L=A.
FindObjectScreenPosition_StoreY AE74 LD A,($CE42) The vertical offset.
AE77 ADD A,L A gains L.
AE78 LD ($A1D6),A The vertical screen position.
AE7B LD (IX+$12),A Write the vertical screen position.
AE7E SET 7,(IX+$10) Set bit 7 of offset 10 of IX.
AE82 RET Return.
FindObjectScreenPosition_NextZone AE83 INC A Advance A.
AE84 CP (IX+$04) Jump to FindObjectScreenPosition_Free if A is not the byte at offset 04 of IX.
AE87 JP NZ,FindObjectScreenPosition_Free
AE8A LD A,L A=L.
AE8B SUB C Subtract C from A.
AE8C JR C,FindObjectScreenPosition_StoreY Jump to FindObjectScreenPosition_StoreY if the carry flag is set.
AE8E CP E Return if A is E or more.
AE8F RET NC
AE90 JP FindObjectScreenPosition_StoreY Jump to FindObjectScreenPosition_StoreY.
FindObjectScreenPosition_Free AE93 LD (IX+$00),$FF Store FF at offset 00 of IX.
AE97 RET Return.
Prev: ADBE Up: Map Next: AE98