Prev: 44478 Up: Map Next: 44696
44504: 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 17 and 18, and the object is flagged as visible with bit 7 of offset 16. The wrap flag (bit 6 of offset 16) 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 44504 LD A,(DE) Read DE.
44505 ADD A,A Double A.
44506 ADD A,A Double A.
44507 ADD A,A Double A.
44508 LD B,A B=A.
44509 INC DE Advance DE.
44510 LD A,(DE) Read DE.
44511 LD C,A C=A.
44512 LD A,(52805) The position across.
44515 LD E,A E=A.
44516 LD A,(IX+2) The horizontal position.
44519 AND %11111110 Keep the bits of A that are set in 254.
44521 LD L,A L=A.
44522 LD A,(56823) The next column.
44525 CP (IX+1) Jump to FindObjectScreenPosition_Edge if A is the byte at offset 1 of IX.
44528 JP Z,FindObjectScreenPosition_Edge
44531 LD A,(52823) The map position.
44534 CP (IX+1) Jump to FindObjectScreenPosition_Wrap if A is the byte at offset 1 of IX.
44537 JR Z,FindObjectScreenPosition_Wrap
44539 LD A,(41431) The rows of the sprite that was drawn.
44542 AND A Jump to FindObjectScreenPosition_Free if A is zero.
44543 JP Z,FindObjectScreenPosition_Free
44546 LD A,L A=L.
44547 ADD A,23 Add 23 to A.
44549 ADD A,B A gains B.
44550 JP NC,FindObjectScreenPosition_Free Jump to FindObjectScreenPosition_Free if the carry flag is clear.
44553 LD A,(IX+2) The horizontal position.
44556 CP 128 Jump to FindObjectScreenPosition_Free if A is less than 128.
44558 JP C,FindObjectScreenPosition_Free
44561 LD A,E A=E.
44562 ADD A,176 Add 176 to A.
44564 LD E,A E=A.
44565 LD A,L A=L.
44566 SUB 48 Subtract 48 from A.
44568 LD L,A L=A.
FindObjectScreenPosition_Wrap 44569 LD A,L A=L.
44570 CP E Jump to FindObjectScreenPosition_Horizontal if A is E or more.
44571 JR NC,FindObjectScreenPosition_Horizontal
44573 ADD A,B A gains B.
44574 JR C,FindObjectScreenPosition_Row Jump to FindObjectScreenPosition_Row if the carry flag is set.
44576 DEC A Step A back.
44577 CP E Return if A is less than E.
44578 RET C
FindObjectScreenPosition_Row 44579 LD A,E A=E.
44580 SUB L Subtract L from A.
44581 SUB 9 Subtract 9 from A.
44583 JR C,FindObjectScreenPosition_Horizontal Jump to FindObjectScreenPosition_Horizontal if the carry flag is set.
44585 SET 6,(IX+16) Set bit 6 of offset 16 of IX.
44589 LD A,1 A=1.
44591 LD (41722),A The sprite reaches past the right of the screen.
FindObjectScreenPosition_Horizontal 44594 LD A,(52823) The map position.
44597 CP (IX+1) Jump to FindObjectScreenPosition_Same if A is the byte at offset 1 of IX.
44600 JR Z,FindObjectScreenPosition_Same
44602 LD A,(56823) The next column.
44605 CP (IX+1) Jump to FindObjectScreenPosition_Same if A is the byte at offset 1 of IX.
44608 JR Z,FindObjectScreenPosition_Same
44610 LD A,L A=L.
44611 SUB E Subtract E from A.
44612 ADD A,8 Add 8 to A.
44614 LD L,A L=A.
44615 JR FindObjectScreenPosition_StoreX Jump to FindObjectScreenPosition_StoreX.
FindObjectScreenPosition_Same 44617 LD A,(52801) The horizontal offset.
44620 ADD A,L A gains L.
FindObjectScreenPosition_StoreX 44621 LD (41429),A The horizontal screen position.
44624 LD (IX+17),A Write the horizontal screen position.
44627 JP FindObjectScreenPosition_Vertical Jump to FindObjectScreenPosition_Vertical.
FindObjectScreenPosition_Edge 44630 LD A,L A=L.
44631 CP E Return if A is E or more.
44632 RET NC
44633 ADD A,224 Add 224 to A.
44635 LD L,A L=A.
44636 JR FindObjectScreenPosition_Horizontal Jump to FindObjectScreenPosition_Horizontal.
FindObjectScreenPosition_Vertical 44638 LD L,(IX+5) The vertical position.
44641 LD A,(52806) The position down.
44644 LD E,A E=A.
44645 LD A,(52824) The map row.
44648 CP (IX+4) Jump to FindObjectScreenPosition_NextZone if A is not the byte at offset 4 of IX.
44651 JR NZ,FindObjectScreenPosition_NextZone
44653 LD A,L A=L.
44654 DEC A Step A back.
44655 CP E Return if A is less than E.
44656 RET C
44657 ADD A,97 Add 97 to A.
44659 LD L,A L=A.
FindObjectScreenPosition_StoreY 44660 LD A,(52802) The vertical offset.
44663 ADD A,L A gains L.
44664 LD (41430),A The vertical screen position.
44667 LD (IX+18),A Write the vertical screen position.
44670 SET 7,(IX+16) Set bit 7 of offset 16 of IX.
44674 RET Return.
FindObjectScreenPosition_NextZone 44675 INC A Advance A.
44676 CP (IX+4) Jump to FindObjectScreenPosition_Free if A is not the byte at offset 4 of IX.
44679 JP NZ,FindObjectScreenPosition_Free
44682 LD A,L A=L.
44683 SUB C Subtract C from A.
44684 JR C,FindObjectScreenPosition_StoreY Jump to FindObjectScreenPosition_StoreY if the carry flag is set.
44686 CP E Return if A is E or more.
44687 RET NC
44688 JP FindObjectScreenPosition_StoreY Jump to FindObjectScreenPosition_StoreY.
FindObjectScreenPosition_Free 44691 LD (IX+0),255 Store 255 at offset 0 of IX.
44695 RET Return.
Prev: 44478 Up: Map Next: 44696