Prev: 39044 Up: Map Next: 39174
39086: Clear Terrain Under Actor
Clear the play-area pixels under the actor and return with the Z flag set, or return with it unset if the actor is off-screen.
Input
IX Actor slot
ClearTerrainUnderActor 39086 LD H,(IX+3) Fetch the high byte of the world X.
39089 LD L,(IX+2) Fetch the low byte of the world X.
39092 LD DE,(24698) Fetch Jetman_Position.
39096 AND A Subtract the scroll position.
39097 SBC HL,DE
39099 LD DE,120 Add a 120 tolerance.
39102 ADD HL,DE
39103 LD A,H Fetch the high byte of the gap.
39104 AND %00011111 Keep only bits 0-4.
39106 RET NZ Return if the actor is not on this screen.
Build the pixel mask for the fine scroll position.
39107 EX DE,HL Switch the gap into DE.
39108 LD A,(24698) Fetch Jetman_Position.
39111 AND %00000111 Keep only bits 0-2.
39113 LD B,A Store the fine scroll in B.
39114 LD A,0 A=0.
39116 LD HL,255 HL=0255.
39119 JR Z,ClearTerrainUnderActor_StoreMask Jump to ClearTerrainUnderActor_StoreMask if there is no fine scroll.
ClearTerrainUnderActor_ShiftMask 39121 ADD HL,HL Shift the mask left by one pixel.
39122 RLA
39123 DJNZ ClearTerrainUnderActor_ShiftMask Decrease the fine-scroll counter by one and loop back to ClearTerrainUnderActor_ShiftMask until the shift is done.
ClearTerrainUnderActor_StoreMask 39125 EX DE,HL Store the mask in DE and the overflow in C.
39126 LD C,A
Work out the screen column under the actor.
39127 LD A,(24698) Fetch Jetman_Position.
39130 RRA Divide the scroll by 8.
39131 RRA
39132 RRA
39133 AND %00011111 Keep only bits 0-4.
39135 LD L,A Store the scroll column in L.
Work out the actor's column relative to the scroll column.
39136 LD A,(IX+2) Fetch the low byte of the world X.
39139 RRA Divide it by 8.
39140 RRA
39141 RRA
39142 AND %00011111 Keep only bits 0-4.
39144 SUB L Subtract the scroll column.
39145 ADD A,14 Add 14.
39147 AND %00011111 Keep only bits 0-4.
39149 LD HL,20672 HL=20672.
39152 ADD A,L Point HL at that screen column.
39153 LD L,A
39154 LD B,8 Set a pixel row counter in B for 8 loops.
Clear the masked pixels one pixel row at a time.
ClearTerrainUnderActor_MaskRow 39156 PUSH HL Stash the row start on the stack.
39157 LD A,E Mask the first screen byte.
39158 AND (HL)
39159 LD (HL),A
39160 INC L
39161 LD A,C Mask the middle screen byte.
39162 AND (HL)
39163 LD (HL),A
39164 INC L
39165 LD A,D Mask the third screen byte.
39166 AND (HL)
39167 LD (HL),A
39168 POP HL Restore the row start from the stack.
39169 INC H Move down one pixel row.
39170 DJNZ ClearTerrainUnderActor_MaskRow Decrease the row counter by one and loop back to ClearTerrainUnderActor_MaskRow until the column is cleared.
39172 XOR A Return with the Z flag set.
39173 RET
Prev: 39044 Up: Map Next: 39174