Prev: 9020 Up: Map Next: 915C
907B: Apply Jetman Speed
Use the horizontal speed in *IX+05 to update Jetman's world position.
Input
IX Actor slot
ApplyJetmanSpeed 907B LD A,(IX+$05) Fetch the horizontal speed.
907E SRA A Divide it by 10.
9080 SRA A
9082 SRA A
9084 SRA A
9086 LD E,A Store the pixel step in E.
9087 LD D,$00 Clear D for a positive step.
9089 JP P,ApplyJetmanSpeed_AddWorldX Jump to ApplyJetmanSpeed_AddWorldX if the step is positive.
908C LD D,$FF Set D=FF for a negative step.
Add the step to the world X and wrap it to the planet width.
ApplyJetmanSpeed_AddWorldX 908E LD H,(IX+$03) Fetch the high byte of the world X.
9091 LD L,(IX+$02) Fetch the low byte of the world X.
9094 LD A,L Fetch the fine X.
9095 AND %00000111 Keep only bits 0-2.
Draw a new terrain column on a cell boundary, then scroll the terrain bitmap by the step.
9097 PUSH HL Stash the world X and the step on the stack.
9098 PUSH DE
9099 CALL Z,DrawNewColumn Call DrawNewColumn if Jetman is on a cell boundary.
909C POP DE Restore the step from the stack.
909D CALL ApplyJetmanSpeed_ScrollLeft Call ApplyJetmanSpeed_ScrollLeft.
Add the step to the world X and write it back.
90A0 POP HL Restore the world X from the stack.
90A1 ADD HL,DE Add the step to the world X.
90A2 LD A,H Fetch the high byte.
90A3 AND %00011111 Keep only bits 0-4.
90A5 LD (IX+$03),A Write the high byte back to *IX+03.
90A8 LD (IX+$02),L Write the low byte back to *IX+02.
90AB RET Return.
Scroll the terrain bitmap left or right by the pixel step.
ApplyJetmanSpeed_ScrollLeft 90AC LD HL,$50C0 HL=50C0.
90AF LD C,$08 Set a pixel row counter in C for 08 loops.
90B1 LD A,E Return if there is no horizontal movement.
90B2 AND A
90B3 RET Z
90B4 JP P,ApplyJetmanSpeed_ScrollRight Jump to ApplyJetmanSpeed_ScrollRight if Jetman is moving right.
When Jetman is moving left, shift the terrain bitmap right.
90B7 NEG Negate the leftward step.
90B9 DEC A Jump to ApplyJetmanSpeed_RotateRowRight if the step is 01.
90BA JR Z,ApplyJetmanSpeed_RotateRowRight
90BC DEC A Jump to ApplyJetmanSpeed_TestOddPixel if the step is 02.
90BD JR Z,ApplyJetmanSpeed_TestOddPixel
90BF LD A,(IX+$02) Fetch the low byte of the world X.
90C2 AND %00000011 Keep only bits 0-1.
90C4 JR NZ,ApplyJetmanSpeed_TestOddPixel Jump to ApplyJetmanSpeed_TestOddPixel if Jetman is not on a 4-pixel boundary.
Rotate each pixel row right by four bits.
ApplyJetmanSpeed_Loop 90C6 XOR A Clear the accumulator.
90C7 LD B,$20 Set a column counter in B for 20 loops.
90C9 PUSH HL Stash the row start on the stack.
ApplyJetmanSpeed_RotateNibbleRight 90CA RRD Rotate the nibble through the current byte.
90CC INC HL Move onto the next column.
90CD DJNZ ApplyJetmanSpeed_RotateNibbleRight Decrease the column counter by one and loop back to ApplyJetmanSpeed_RotateNibbleRight until the row is done.
90CF POP HL Restore the row start from the stack.
90D0 INC H Move down one pixel row.
90D1 DEC C Decrease the row counter by one and loop back to ApplyJetmanSpeed_Loop until all eight rows are done.
90D2 JR NZ,ApplyJetmanSpeed_Loop
Return the step actually scrolled (-04) in DE.
90D4 LD DE,$FFFC DE=FFFC.
90D7 RET Return.
Rotate each pixel row right by one bit.
ApplyJetmanSpeed_RotateRowRight 90D8 XOR A Clear the accumulator.
90D9 LD B,$20 Set a column counter in B for 20 loops.
90DB PUSH HL Stash the row start on the stack.
ApplyJetmanSpeed_RotateByteRight 90DC RR (HL) Rotate the current byte right.
90DE INC HL Move onto the next column.
90DF DJNZ ApplyJetmanSpeed_RotateByteRight Decrease the column counter by one and loop back to ApplyJetmanSpeed_RotateByteRight until the row is done.
90E1 POP HL Restore the row start from the stack.
90E2 INC H Move down one pixel row.
90E3 DEC C Decrease the row counter by one and loop back to ApplyJetmanSpeed_RotateRowRight until all eight rows are done.
90E4 JR NZ,ApplyJetmanSpeed_RotateRowRight
Return the step actually scrolled (-01) in DE.
90E6 LD DE,$FFFF DE=FFFF.
90E9 RET Return.
Use a one-bit rotate if Jetman is on an odd pixel, otherwise fall through to a two-bit rotate.
ApplyJetmanSpeed_TestOddPixel 90EA LD A,(IX+$02) Fetch the low byte of the world X.
90ED AND %00000001 Keep only bit 0.
90EF JR NZ,ApplyJetmanSpeed_RotateRowRight Jump to ApplyJetmanSpeed_RotateRowRight if Jetman is on an odd pixel.
Rotate each pixel row right by two bits.
ApplyJetmanSpeed_RotateRowRight2 90F1 XOR A Clear both accumulators.
90F2 EX AF,AF'
90F3 XOR A
90F4 PUSH HL Stash the row start on the stack.
90F5 LD B,$20 Set a column counter in B for 20 loops.
ApplyJetmanSpeed_RotateByteRight2 90F7 RR (HL) Rotate the current byte right twice.
90F9 EX AF,AF'
90FA RR (HL)
90FC EX AF,AF'
90FD INC L Move onto the next column.
90FE DJNZ ApplyJetmanSpeed_RotateByteRight2 Decrease the column counter by one and loop back to ApplyJetmanSpeed_RotateByteRight2 until the row is done.
9100 POP HL Restore the row start from the stack.
9101 INC H Move down one pixel row.
9102 DEC C Decrease the row counter by one and loop back to ApplyJetmanSpeed_RotateRowRight2 until all eight rows are done.
9103 JR NZ,ApplyJetmanSpeed_RotateRowRight2
Return the step actually scrolled (-02) in DE.
9105 LD DE,$FFFE DE=FFFE.
9108 RET Return.
When Jetman is moving right, shift the terrain bitmap left.
ApplyJetmanSpeed_ScrollRight 9109 LD HL,$50DF HL=50DF.
910C DEC A Jump to ApplyJetmanSpeed_RotateRowLeft if the step is 01.
910D JR Z,ApplyJetmanSpeed_RotateRowLeft
910F DEC A Jump to ApplyJetmanSpeed_TestOddPixelRight if the step is 02.
9110 JR Z,ApplyJetmanSpeed_TestOddPixelRight
9112 LD A,(IX+$02) Fetch the low byte of the world X.
9115 AND %00000011 Keep only bits 0-1.
9117 JR NZ,ApplyJetmanSpeed_TestOddPixelRight Jump to ApplyJetmanSpeed_TestOddPixelRight if Jetman is not on a 4-pixel boundary.
Rotate each pixel row left by four bits.
ApplyJetmanSpeed_RotateRowLeft4 9119 XOR A Clear the accumulator.
911A LD B,$20 Set a column counter in B for 20 loops.
911C PUSH HL Stash the row start on the stack.
ApplyJetmanSpeed_RotateNibbleLeft 911D RLD Rotate the nibble through the current byte.
911F DEC L Move onto the previous column.
9120 DJNZ ApplyJetmanSpeed_RotateNibbleLeft Decrease the column counter by one and loop back to ApplyJetmanSpeed_RotateNibbleLeft until the row is done.
9122 POP HL Restore the row start from the stack.
9123 INC H Move down one pixel row.
9124 DEC C Decrease the row counter by one and loop back to ApplyJetmanSpeed_RotateRowLeft4 until all eight rows are done.
9125 JR NZ,ApplyJetmanSpeed_RotateRowLeft4
9127 LD DE,$0004 DE=0004.
912A RET Return.
Rotate each pixel row left by one bit.
ApplyJetmanSpeed_RotateRowLeft 912B XOR A Clear the accumulator.
912C LD B,$20 Set a column counter in B for 20 loops.
912E PUSH HL Stash the row start on the stack.
ApplyJetmanSpeed_RotateByteLeft 912F RL (HL) Rotate the current byte left.
9131 DEC L Move onto the previous column.
9132 DJNZ ApplyJetmanSpeed_RotateByteLeft Decrease the column counter by one and loop back to ApplyJetmanSpeed_RotateByteLeft until the row is done.
9134 POP HL Restore the row start from the stack.
9135 INC H Move down one pixel row.
9136 DEC C Decrease the row counter by one and loop back to ApplyJetmanSpeed_RotateRowLeft until all eight rows are done.
9137 JR NZ,ApplyJetmanSpeed_RotateRowLeft
9139 LD DE,$0001 DE=0001.
913C RET Return.
Rotate by one bit if Jetman is on an odd pixel, else by two.
ApplyJetmanSpeed_TestOddPixelRight 913D LD A,(IX+$02) Fetch the low byte of the world X.
9140 AND %00000001 Keep only bit 0.
9142 JR NZ,ApplyJetmanSpeed_RotateRowLeft Jump to ApplyJetmanSpeed_RotateRowLeft if Jetman is on an odd pixel.
Rotate each pixel row left by two bits.
ApplyJetmanSpeed_RotateRowLeft2 9144 XOR A Clear both accumulators.
9145 EX AF,AF'
9146 XOR A
9147 PUSH HL Stash the row start on the stack.
9148 LD B,$20 Set a column counter in B for 20 loops.
ApplyJetmanSpeed_RotateByteLeft2 914A RL (HL) Rotate the current byte left twice.
914C EX AF,AF'
914D RL (HL)
914F EX AF,AF'
9150 DEC L Move onto the previous column.
9151 DJNZ ApplyJetmanSpeed_RotateByteLeft2 Decrease the column counter by one and loop back to ApplyJetmanSpeed_RotateByteLeft2 until the row is done.
9153 POP HL Restore the row start from the stack.
9154 INC H Move down one pixel row.
9155 DEC C Decrease the row counter by one and loop back to ApplyJetmanSpeed_RotateRowLeft2 until all eight rows are done.
9156 JR NZ,ApplyJetmanSpeed_RotateRowLeft2
9158 LD DE,$0002 DE=0002.
915B RET Return.
Prev: 9020 Up: Map Next: 915C