Manic Miner: Routine at 35515

| Routines

35515: Move Willy (1)

Used by the routine at 34574. This routine deals with Willy if he's jumping or falling.
35515 | LD A,(32875) | Pick up the airborne status indicator from 32875
35518 | CP 1 | Is Willy jumping?
35520 | JR NZ,35600 | Jump if not
Willy is currently jumping. Your browser doesn't support HTML5 audio. Here is a link to the audio instead.
35522 | LD A,(32878) | Pick up the jumping animation counter (0-17) from 32878
35525 | RES 0,A | Now -8<=A<=8 (and A is even)
35527 | SUB 8
35529 | LD HL,32872 | Adjust Willy's y-coordinate at 32872 depending on where Willy is in the jump
35532 | ADD A,(HL)
35533 | LD (HL),A
35534 | CALL 35714 | Adjust Willy's attribute buffer location at 32876 depending on his y-coordinate
35537 | LD A,(32827) | Pick up the attribute byte of the wall tile for the current cavern from 32827
35540 | CP (HL) | Is the top-left cell of Willy's sprite overlapping a wall tile?
35541 | JP Z,35746 | Jump if so
35544 | INC HL | Point HL at the top-right cell occupied by Willy's sprite
35545 | CP (HL) | Is the top-right cell of Willy's sprite overlapping a wall tile?
35546 | JP Z,35746 | Jump if so
35549 | LD A,(32878) | Increment the jumping animation counter at 32878
35552 | INC A
35553 | LD (32878),A
35556 | SUB 8 | A=J-8, where J (1-18) is the new value of the jumping animation counter
35558 | JP P,35563 | Jump if J>=8
35561 | NEG | A=8-J (1<=J<=7, 1<=A<=7)
35563 | INC A | A=1+ABS(J-8)
35564 | RLCA | D=8*(1+ABS(J-8)); this value determines the pitch of the jumping sound effect (rising as Willy rises, falling as Willy falls)
35565 | RLCA
35566 | RLCA
35567 | LD D,A
35568 | LD C,32 | This value determines the duration of the jumping sound effect
35570 | LD A,(32883) | Pick up the border colour for the current cavern from 32883
35573 | OUT (254),A | Make a jumping sound effect
35575 | XOR 24
35577 | LD B,D
35578 | DJNZ 35578
35580 | DEC C
35581 | JR NZ,35573
35583 | LD A,(32878) | Pick up the jumping animation counter (1-18) from 32878
35586 | CP 18 | Has Willy reached the end of the jump?
35588 | JP Z,35734 | Jump if so
35591 | CP 16 | Is the jumping animation counter now 16?
35593 | JR Z,35600 | Jump if so
35595 | CP 13 | Is the jumping animation counter now 13?
35597 | JP NZ,35971 | Jump if not
If we get here, then Willy is standing on the floor, or he's falling, or his jumping animation counter is 13 (at which point Willy is on his way down and is exactly two cell-heights above where he started the jump) or 16 (at which point Willy is on his way down and is exactly one cell-height above where he started the jump).
35600 | LD A,(32872) | Pick up Willy's y-coordinate from 32872
35603 | AND 15 | Does Willy's sprite occupy six cells at the moment?
35605 | JR NZ,35665 | Jump if so
35607 | LD HL,(32876) | Pick up Willy's attribute buffer coordinates from 32876
35610 | LD DE,64 | Point HL at the left-hand cell below Willy's sprite
35613 | ADD HL,DE
35614 | LD A,(32818) | Pick up the attribute byte of the crumbling floor tile for the current cavern from 32818
35617 | CP (HL) | Does the left-hand cell below Willy's sprite contain a crumbling floor tile?
35618 | CALL Z,35770 | If so, make it crumble
35621 | LD A,(32845) | Pick up the attribute byte of the first nasty tile for the current cavern from 32845
35624 | CP (HL) | Does the left-hand cell below Willy's sprite contain a nasty tile?
35625 | JR Z,35665 | Jump if so
35627 | LD A,(32854) | Pick up the attribute byte of the second nasty tile for the current cavern from 32854
35630 | CP (HL) | Does the left-hand cell below Willy's sprite contain a nasty tile?
35631 | JR Z,35665 | Jump if so
35633 | INC HL | Point HL at the right-hand cell below Willy's sprite
35634 | LD A,(32818) | Pick up the attribute byte of the crumbling floor tile for the current cavern from 32818
35637 | CP (HL) | Does the right-hand cell below Willy's sprite contain a crumbling floor tile?
35638 | CALL Z,35770 | If so, make it crumble
35641 | LD A,(32845) | Pick up the attribute byte of the first nasty tile for the current cavern from 32845
35644 | CP (HL) | Does the right-hand cell below Willy's sprite contain a nasty tile?
35645 | JR Z,35665 | Jump if so
35647 | LD A,(32854) | Pick up the attribute byte of the second nasty tile for the current cavern from 32854
35650 | CP (HL) | Does the right-hand cell below Willy's sprite contain a nasty tile?
35651 | JR Z,35665 | Jump if so
35653 | LD A,(32800) | Pick up the attribute byte of the background tile for the current cavern from 32800
35656 | CP (HL) | Set the zero flag if the right-hand cell below Willy's sprite is empty
35657 | DEC HL | Point HL at the left-hand cell below Willy's sprite
35658 | JP NZ,35805 | Jump if the right-hand cell below Willy's sprite is not empty
35661 | CP (HL) | Is the left-hand cell below Willy's sprite empty?
35662 | JP NZ,35805 | Jump if not
35665 | LD A,(32875) | Pick up the airborne status indicator from 32875
35668 | CP 1 | Is Willy jumping?
35670 | JP Z,35971 | Jump if so
If we get here, then Willy is either in the process of falling or just about to start falling. Your browser doesn't support HTML5 audio. Here is a link to the audio instead.
35673 | LD HL,32874 | Reset bit 1 at 32874: Willy is not moving left or right
35676 | RES 1,(HL)
35678 | OR A | Is Willy already falling?
35679 | JP Z,35740 | Jump if not
35682 | INC A | Increment the airborne status indicator at 32875
35683 | LD (32875),A
35686 | RLCA | The value of D determines the pitch of the falling sound effect
35687 | RLCA
35688 | RLCA
35689 | RLCA
35690 | LD D,A
35691 | LD C,32 | This value determines the duration of the falling sound effect
35693 | LD A,(32883) | Pick up the border colour for the current cavern from 32883
35696 | OUT (254),A | Make a falling sound effect
35698 | XOR 24
35700 | LD B,D
35701 | DJNZ 35701
35703 | DEC C
35704 | JR NZ,35696
35706 | LD A,(32872) | Add 8 to Willy's y-coordinate at 32872; this moves Willy downwards by 4 pixels
35709 | ADD A,8
35711 | LD (32872),A
35714 | AND 240 | L=16*Y, where Y is Willy's screen y-coordinate (0-14)
35716 | LD L,A
35717 | XOR A | Clear A and the carry flag
35718 | RL L | Now L=32*(Y-8*INT(Y/8)), and the carry flag is set if Willy is in the lower half of the cavern (Y>=8)
35720 | ADC A,92 | H=92 or 93 (MSB of the address of Willy's location in the attribute buffer)
35722 | LD H,A
35723 | LD A,(32876) | Pick up Willy's screen x-coordinate (1-29) from bits 0-4 at 32876
35726 | AND 31
35728 | OR L | Now L holds the LSB of Willy's attribute buffer address
35729 | LD L,A
35730 | LD (32876),HL | Store Willy's updated attribute buffer location at 32876
35733 | RET |
Willy has just finished a jump.
35734 | LD A,6 | Set the airborne status indicator at 32875 to 6: Willy will continue to fall unless he's landed on a wall or floor block
35736 | LD (32875),A
35739 | RET |
Willy has just started falling.
35740 | LD A,2 | Set the airborne status indicator at 32875 to 2
35742 | LD (32875),A
35745 | RET |
The top-left or top-right cell of Willy's sprite is overlapping a wall tile.
35746 | LD A,(32872) | Adjust Willy's y-coordinate at 32872 so that the top row of cells of his sprite is just below the wall tile
35749 | ADD A,16
35751 | AND 240
35753 | LD (32872),A
35756 | CALL 35714 | Adjust Willy's attribute buffer location at 32876 to account for this new y-coordinate
35759 | LD A,2 | Set the airborne status indicator at 32875 to 2: Willy has started falling
35761 | LD (32875),A
35764 | LD HL,32874 | Reset bit 1 at 32874: Willy is not moving left or right
35767 | RES 1,(HL)
35769 | RET |