Prev: 6a35 Up: Map Next: 6beb
6ab8: Update UFO alien -- this alien is a chaser!
TODO: annotations are really messy/wrong here, needs lots more work to understand how the movement is calculated.
Input
IX Alien object.
6ab8 ld hl,$5dcb Increment current alien number
6abb inc (hl)
6abc call $6cb0 Update actor direction
6abf call $6e1b Fire laser beam (returns C)
6ac2 dec c
6ac3 jp z,$6beb Add the points for a kill if alien is dead
6ac6 call $6de9 Alien collision check (returns E)
6ac9 dec e
6aca jp z,$6456 Alien killed by collision if E is zero
6acd xor a
6ace ld ($5dc9),a Reset alien new direction flag
Check which direction alien is travelling after hitting a platform.
6ad1 call $75e8 Platform collision (returns E)
6ad4 bit 2,e Update alien X position if bit-2 is reset
6ad6 jr z,$6af1
6ad8 bit 7,e Set alien direction to up if bit-7 set
6ada jp nz,$6bcd
6add bit 4,e Set alien direction to down if bit-4 set
6adf jp nz,$6bd4
Move the flying saucer in a slightly more erratic way (the XOR), rather than just heading directly for the Jetman.
6ae2 ld a,e Update alien "moving" value
6ae3 and $40
6ae5 xor $40
6ae7 ld e,a
6ae8 ld a,(ix+$04)
6aeb and $bf
6aed or e
6aee ld (ix+$04),a
Calculate new horizontal position and speed.
6af1 ld a,(ix+$05) Alien X speed
6af4 ld b,a Calculate new speed?
6af5 and $0f
6af7 ld c,a
6af8 ld a,b
6af9 and $f0
6afb ld b,a
6afc ld a,($5d01) Jetman X position
6aff sub (ix+$01) Subtract alien X position
6b02 jp p,$6b74 If Jetman X > alien X, then jump
6b05 bit 6,(ix+$04) If alien is moving left, then jump
6b09 jp z,$6b96
6b0c ld a,c If current speed is less than max, then increment
6b0d cp $0f
6b0f jr nc,$6b12
6b11 inc a
Calculate new X position.
6b12 ld c,a C=current speed
6b13 ld h,(ix+$01) H=X position
6b16 call $6bdb Calculates and returns DE, new position offset
6b19 and a Clear the carry flag
6b1a sbc hl,de
Update the X position and speed
6b1c ld (ix+$01),h Update X position
6b1f ld a,l Calculate and update X speed
6b20 and $f0
6b22 or c
6b23 ld (ix+$05),a
Calculate new Y position and speed.
6b26 ld a,(ix+$06) Alien Y speed
6b29 ld b,a
6b2a and $0f
6b2c ld c,a
6b2d ld a,b
6b2e and $f0
6b30 ld b,a
6b31 ld a,($5d02) Jetman Y position
6b34 sub (ix+$02) Subtract alien Y position
6b37 jp p,$6ba2 If Jetman Y > alien Y, then jump
6b3a bit 7,(ix+$04) If alien is moving up then increment Y position (if not at top of screen) and jump to 6b49
6b3e jp z,$6bc3
6b41 ld a,c Calculate new down Y position if C > 0 (presumably above the ground)
6b42 dec a
6b43 jr nz,$6bae
6b45 res 7,(ix+$04) else moving direction must be set to up...
6b49 ld c,a ..and C will have been decremented here
6b4a ld h,(ix+$02) H=Y position
6b4d call $6bdb Calculates and returns DE, new position offset
6b50 and a Clear the carry flag
6b51 sbc hl,de
6b53 ld a,h Set moving direction as down if at top of screen
6b54 cp $28
6b56 jr nc,$6b5c
6b58 set 7,(ix+$04)
6b5c ld (ix+$02),a Update Y position
6b5f ld a,l Update Y speed
6b60 and $f0
6b62 or c
6b63 ld (ix+$06),a
Draw the alien if a new direction is set, otherwise repeat platform collision check again.
6b66 ld a,($5dc9) Draw the alien if the new direction flag is set,
6b69 and a otherwise, increment it
6b6a jp nz,$6d43
6b6d inc a
6b6e ld ($5dc9),a }
6b71 jp $6ad1 Jump back and repeat collision check
Check moving direction and update.
6b74 bit 6,(ix+$04) Check moving left/right bit
6b78 jr z,$6b8e If moving left, increment speed (via jump)
6b7a ld a,c
6b7b dec a
6b7c jp nz,$6b12 If not zero, calculate X direction/speed
6b7f res 6,(ix+$04) else set X moving to "right"
6b83 ld c,a A (speed) was decremented from 0, so will now be FF
6b84 ld h,(ix+$01) H=X position
6b87 call $6bdb Calculates and returns DE, new position offset
6b8a add hl,de
6b8b jp $6b1c Update the X position and speed
6b8e ld a,c If current speed is less than max, then increment
6b8f cp $0f
6b91 jr nc,$6b83
6b93 inc a
6b94 jr $6b83 Update position
6b96 ld a,c A=speed
6b97 dec a
6b98 jp nz,$6b83 Update X position and speed unless zero
6b9b set 6,(ix+$04) Set moving direction to "right"
6b9f jp $6b12 Update X direction/speed
6ba2 bit 7,(ix+$04) Check Jetman moving direction
6ba6 jr z,$6bb9 Jump if top bit not set
6ba8 ld a,c Jump if C >= 15
6ba9 cp $0f
6bab jr nc,$6bae
6bad inc a else increment it
6bae ld c,a (will be C = C - 1)
6baf ld h,(ix+$02)
6bb2 call $6bdb Calculates and returns DE, new position offset
6bb5 add hl,de
6bb6 jp $6b53 Update Y position and speed
6bb9 ld a,c A=speed
6bba dec a
6bbb jr nz,$6b49 If speed > 0 move upwards
6bbd set 7,(ix+$04) else set moving direction to "down"
6bc1 jr $6bae ...and update Y position and speed
6bc3 ld a,c If current speed is less than max, then increment it, and update position
6bc4 cp $0f
6bc6 jp nc,$6b49
6bc9 inc a
6bca jp $6b49
Change alien moving direction to up.
6bcd res 7,(ix+$04)
6bd1 jp $6af1
Change alien moving direction to down.
6bd4 set 7,(ix+$04)
6bd8 jp $6af1
Returns DE (new position) as calculated from the speed (C).
6bdb ld l,b
6bdc ld a,c C should be <= 15. Example, if value is $0F:
6bdd rla 0 00011110
6bde rla 0 00111100
6bdf rla 0 01111000
6be0 rla 0 11110000
6be1 and $f0 Clear lower 4 bits...just in case!
6be3 ld e,a
6be4 ld d,$00
6be6 sla e 1 11100000
6be8 rl d If E >= 8, then bit-0 of D is set
6bea ret
Prev: 6a35 Up: Map Next: 6beb