![]() |
Routines |
Prev: 35770 | Up: Map |
Used by the routine at 35515. This routine checks the keyboard and joystick, and moves Willy left or right if necessary.
|
||||||||||
35805 | LD A,(32875) | Pick up the airborne status indicator from 32875 | ||||||||
35808 | CP 12 | Has Willy just landed after falling from too great a height? | ||||||||
35810 | JP NC,36102 | If so, kill him | ||||||||
35813 | LD E,255 | Initialise E to 255 (all bits set); it will be used to hold keyboard and joystick readings | ||||||||
35815 | XOR A | Reset the airborne status indicator at 32875 (Willy has landed safely) | ||||||||
35816 | LD (32875),A | |||||||||
35819 | LD A,(32836) | Pick up the attribute byte of the conveyor tile for the current cavern from 32836 | ||||||||
35822 | CP (HL) | Does the attribute byte of the left-hand cell below Willy's sprite match that of the conveyor tile? | ||||||||
35823 | JR Z,35829 | Jump if so | ||||||||
35825 | INC HL | Point HL at the right-hand cell below Willy's sprite | ||||||||
35826 | CP (HL) | Does the attribute byte of the right-hand cell below Willy's sprite match that of the conveyor tile? | ||||||||
35827 | JR NZ,35835 | Jump if not | ||||||||
35829 | LD A,(32879) | Pick up the direction byte of the conveyor definition from 32879 (0=left, 1=right) | ||||||||
35832 | SUB 3 | Now E=253 (bit 1 reset) if the conveyor is moving left, or 254 (bit 0 reset) if it's moving right | ||||||||
35834 | LD E,A | |||||||||
35835 | LD BC,57342 | Read keys P-O-I-U-Y (right, left, right, left, right) into bits 0-4 of A | ||||||||
35838 | IN A,(C) | |||||||||
35840 | AND 31 | Set bit 5 and reset bits 6 and 7 | ||||||||
35842 | OR 32 | |||||||||
35844 | AND E | Reset bit 0 if the conveyor is moving right, or bit 1 if it's moving left | ||||||||
35845 | LD E,A | Save the result in E | ||||||||
35846 | LD BC,64510 | Read keys Q-W-E-R-T (left, right, left, right, left) into bits 0-4 of A | ||||||||
35849 | IN A,(C) | |||||||||
35851 | AND 31 | Keep only bits 0-4, shift them into bits 1-5, and set bit 0 | ||||||||
35853 | RLC A | |||||||||
35855 | OR 1 | |||||||||
35857 | AND E | Merge this keyboard reading into bits 1-5 of E | ||||||||
35858 | LD E,A | |||||||||
35859 | LD B,247 | Read keys 1-2-3-4-5 ('5' is left) into bits 0-4 of A | ||||||||
35861 | IN A,(C) | |||||||||
35863 | RRCA | Rotate the result right and set bits 0-2 and 4-7; this ignores every key except '5' (left) | ||||||||
35864 | OR 247 | |||||||||
35866 | AND E | Merge this reading of the '5' key into bit 3 of E | ||||||||
35867 | LD E,A | |||||||||
35868 | LD B,239 | Read keys 0-9-8-7-6 ('8' is right) into bits 0-4 of A | ||||||||
35870 | IN A,(C) | |||||||||
35872 | OR 251 | Set bits 0, 1 and 3-7; this ignores every key except '8' (right) | ||||||||
35874 | AND E | Merge this reading of the '8' key into bit 2 of E | ||||||||
35875 | LD E,A | |||||||||
35876 | LD A,(33881) | Collect the Kempston joystick indicator from 33881 | ||||||||
35879 | OR A | Is the joystick connected? | ||||||||
35880 | JR Z,35892 | Jump if not | ||||||||
35882 | LD BC,31 | Collect input from the joystick | ||||||||
35885 | IN A,(C) | |||||||||
35887 | AND 3 | Keep only bits 0 (right) and 1 (left) and flip them | ||||||||
35889 | CPL | |||||||||
35890 | AND E | Merge this reading of the joystick right and left buttons into bits 0 and 1 of E | ||||||||
35891 | LD E,A | |||||||||
At this point, bits 0-5 in E indicate the direction in which Willy is being moved or trying to move. If bit 0, 2 or 4 is reset, Willy is being moved or trying to move right; if bit 1, 3 or 5 is reset, Willy is being moved or trying to move left.
|
||||||||||
35892 | LD C,0 | Initialise C to 0 (no movement) | ||||||||
35894 | LD A,E | Copy the movement bits into A | ||||||||
35895 | AND 42 | Keep only bits 1, 3 and 5 (the 'left' bits) | ||||||||
35897 | CP 42 | Are any of these bits reset? | ||||||||
35899 | JR Z,35903 | Jump if not | ||||||||
35901 | LD C,4 | Set bit 2 of C: Willy is moving left | ||||||||
35903 | LD A,E | Copy the movement bits into A | ||||||||
35904 | AND 21 | Keep only bits 0, 2 and 4 (the 'right' bits) | ||||||||
35906 | CP 21 | Are any of these bits reset? | ||||||||
35908 | JR Z,35912 | Jump if not | ||||||||
35910 | SET 3,C | Set bit 3 of C: Willy is moving right | ||||||||
35912 | LD A,(32874) | Pick up Willy's direction and movement flags from 32874 | ||||||||
35915 | ADD A,C | Point HL at the entry in the left-right movement table at 33800 that corresponds to the direction Willy is facing, and the direction in which he is being moved or trying to move | ||||||||
35916 | LD C,A | |||||||||
35917 | LD B,0 | |||||||||
35919 | LD HL,33800 | |||||||||
35922 | ADD HL,BC | |||||||||
35923 | LD A,(HL) | Update Willy's direction and movement flags at 32874 with the entry from the left-right movement table | ||||||||
35924 | LD (32874),A | |||||||||
That is left-right movement taken care of. Now check the jump keys.
|
||||||||||
35927 | LD BC,32510 | Read keys SHIFT-Z-X-C-V and B-N-M-SS-SPACE | ||||||||
35930 | IN A,(C) | |||||||||
35932 | AND 31 | Are any of these keys being pressed? | ||||||||
35934 | CP 31 | |||||||||
35936 | JR NZ,35963 | Jump if so | ||||||||
35938 | LD B,239 | Read keys 0-9-8-7-6 into bits 0-4 of A | ||||||||
35940 | IN A,(C) | |||||||||
35942 | AND 9 | Keep only bits 0 (the '0' key) and 3 (the '7' key) | ||||||||
35944 | CP 9 | Is '0' or '7' being pressed? | ||||||||
35946 | JR NZ,35963 | Jump if so | ||||||||
35948 | LD A,(33881) | Collect the Kempston joystick indicator from 33881 | ||||||||
35951 | OR A | Is the joystick connected? | ||||||||
35952 | JR Z,35971 | Jump if not | ||||||||
35954 | LD BC,31 | Collect input from the joystick | ||||||||
35957 | IN A,(C) | |||||||||
35959 | BIT 4,A | Is the fire button being pressed? | ||||||||
35961 | JR Z,35971 | Jump if not | ||||||||
A jump key or the fire button is being pressed. Time to make Willy jump.
|
||||||||||
35963 | XOR A | Initialise the jumping animation counter at 32878 | ||||||||
35964 | LD (32878),A | |||||||||
35967 | INC A | Set the airborne status indicator at 32875 to 1: Willy is jumping | ||||||||
35968 | LD (32875),A | |||||||||
This entry point is used by the routine at 35515.
|
||||||||||
35971 | LD A,(32874) | Pick up Willy's direction and movement flags from 32874 | ||||||||
35974 | AND 2 | Is Willy moving? | ||||||||
35976 | RET Z | Return if not | ||||||||
35977 | LD A,(32874) | Pick up Willy's direction and movement flags from 32874 | ||||||||
35980 | AND 1 | Is Willy facing right? | ||||||||
35982 | JP Z,36042 | Jump if so | ||||||||
Willy is moving left.
|
||||||||||
35985 | LD A,(32873) | Pick up Willy's animation frame from 32873 | ||||||||
35988 | OR A | Is it 0? | ||||||||
35989 | JR Z,35996 | If so, jump to move Willy's sprite left across a cell boundary | ||||||||
35991 | DEC A | Decrement Willy's animation frame at 32873 | ||||||||
35992 | LD (32873),A | |||||||||
35995 | RET | |||||||||
Willy's sprite is moving left across a cell boundary. In the comments that follow, (x,y) refers to the coordinates of the top-left cell currently occupied by Willy's sprite.
|
||||||||||
35996 | LD HL,(32876) | Collect Willy's attribute buffer coordinates from 32876 | ||||||||
35999 | DEC HL | Point HL at the cell at (x-1,y+1) | ||||||||
36000 | LD DE,32 | |||||||||
36003 | ADD HL,DE | |||||||||
36004 | LD A,(32827) | Pick up the attribute byte of the wall tile for the current cavern from 32827 | ||||||||
36007 | CP (HL) | Is there a wall tile in the cell pointed to by HL? | ||||||||
36008 | RET Z | Return if so without moving Willy (his path is blocked) | ||||||||
36009 | LD A,(32872) | Pick up Willy's pixel y-coordinate from 32872 | ||||||||
36012 | AND 15 | Does Willy's sprite currently occupy only two rows of cells? | ||||||||
36014 | JR Z,36025 | Jump if so | ||||||||
36016 | LD A,(32827) | Pick up the attribute byte of the wall tile for the current cavern from 32827 | ||||||||
36019 | ADD HL,DE | Point HL at the cell at (x-1,y+2) | ||||||||
36020 | CP (HL) | Is there a wall tile in the cell pointed to by HL? | ||||||||
36021 | RET Z | Return if so without moving Willy (his path is blocked) | ||||||||
36022 | OR A | Clear the carry flag for subtraction | ||||||||
36023 | SBC HL,DE | Point HL at the cell at (x-1,y+1) | ||||||||
36025 | LD A,(32827) | Pick up the attribute byte of the wall tile for the current cavern from 32827 | ||||||||
36028 | OR A | Clear the carry flag for subtraction | ||||||||
36029 | SBC HL,DE | Point HL at the cell at (x-1,y) | ||||||||
36031 | CP (HL) | Is there a wall tile in the cell pointed to by HL? | ||||||||
36032 | RET Z | Return if so without moving Willy (his path is blocked) | ||||||||
36033 | LD (32876),HL | Save Willy's new attribute buffer coordinates (in HL) at 32876 | ||||||||
36036 | LD A,3 | Change Willy's animation frame at 32873 from 0 to 3 | ||||||||
36038 | LD (32873),A | |||||||||
36041 | RET | |||||||||
Willy is moving right.
|
||||||||||
36042 | LD A,(32873) | Pick up Willy's animation frame from 32873 | ||||||||
36045 | CP 3 | Is it 3? | ||||||||
36047 | JR Z,36054 | If so, jump to move Willy's sprite right across a cell boundary | ||||||||
36049 | INC A | Increment Willy's animation frame at 32873 | ||||||||
36050 | LD (32873),A | |||||||||
36053 | RET | |||||||||
Willy's sprite is moving right across a cell boundary. In the comments that follow, (x,y) refers to the coordinates of the top-left cell currently occupied by Willy's sprite.
|
||||||||||
36054 | LD HL,(32876) | Collect Willy's attribute buffer coordinates from 32876 | ||||||||
36057 | INC HL | Point HL at the cell at (x+2,y) | ||||||||
36058 | INC HL | |||||||||
36059 | LD DE,32 | Prepare DE for addition | ||||||||
36062 | LD A,(32827) | Pick up the attribute byte of the wall tile for the current cavern from 32827 | ||||||||
36065 | ADD HL,DE | Point HL at the cell at (x+2,y+1) | ||||||||
36066 | CP (HL) | Is there a wall tile in the cell pointed to by HL? | ||||||||
36067 | RET Z | Return if so without moving Willy (his path is blocked) | ||||||||
36068 | LD A,(32872) | Pick up Willy's pixel y-coordinate from 32872 | ||||||||
36071 | AND 15 | Does Willy's sprite currently occupy only two rows of cells? | ||||||||
36073 | JR Z,36084 | Jump if so | ||||||||
36075 | LD A,(32827) | Pick up the attribute byte of the wall tile for the current cavern from 32827 | ||||||||
36078 | ADD HL,DE | Point HL at the cell at (x+2,y+2) | ||||||||
36079 | CP (HL) | Is there a wall tile in the cell pointed to by HL? | ||||||||
36080 | RET Z | Return if so without moving Willy (his path is blocked) | ||||||||
36081 | OR A | Clear the carry flag for subtraction | ||||||||
36082 | SBC HL,DE | Point HL at the cell at (x+2,y+1) | ||||||||
36084 | LD A,(32827) | Pick up the attribute byte of the wall tile for the current cavern from 32827 | ||||||||
36087 | OR A | Clear the carry flag for subtraction | ||||||||
36088 | SBC HL,DE | Point HL at the cell at (x+2,y) | ||||||||
36090 | CP (HL) | Is there a wall tile in the cell pointed to by HL? | ||||||||
36091 | RET Z | Return if so without moving Willy (his path is blocked) | ||||||||
36092 | DEC HL | Point HL at the cell at (x+1,y) | ||||||||
36093 | LD (32876),HL | Save Willy's new attribute buffer coordinates (in HL) at 32876 | ||||||||
36096 | XOR A | Change Willy's animation frame at 32873 from 3 to 0 | ||||||||
36097 | LD (32873),A | |||||||||
36100 | RET |
Prev: 35770 | Up: Map |