![]() |
Routines |
| Prev: 48606 | Up: Map | Next: 48909 |
|
Used by the routine at HandlePlayerLegs.
Reads the keyboard or the joystick, according to the control method that was chosen in the menu, and writes what is wanted to ControlsPressed as a set of bits:
With the keyboard, any of several keys do each action. With a joystick, up walks forward, down jumps and fire fires, and a long list of the keys of the keyboard picks up or drops an object.
CAPS SHIFT and SPACE are left alone by this routine, as they pause the game (see PauseGame).
|
||||||||||||||||||||||
|
Find the control method: 0 is the keyboard, 1 is a Kempston joystick, 2 is a cursor joystick and 3 is an Interface II joystick.
|
||||||||||||||||||||||
| ReadControls | 48632 | LD A,(42761) | Fetch the control method. | |||||||||||||||||||
| 48635 | RRCA | Shift the method down to bits 0 and 1... | ||||||||||||||||||||
| 48636 | AND %00000011 | ...and keep only those bits. | ||||||||||||||||||||
| 48638 | JP Z,ReadControls_Keyboard | Jump to ReadControls_Keyboard to read the keyboard if the method is 0. | ||||||||||||||||||||
| 48641 | DEC A | Jump to ReadControls_Kempston to read a Kempston joystick if the method is 1. | ||||||||||||||||||||
| 48642 | JR Z,ReadControls_Kempston | |||||||||||||||||||||
| 48644 | DEC A | Jump to ReadControls_Cursor to read a cursor joystick if the method is 2. | ||||||||||||||||||||
| 48645 | JR Z,ReadControls_Cursor | |||||||||||||||||||||
|
Read an Interface II joystick, which can be either of the two ports of the interface: they are the keys 1 to 5 (left, right, down, up, fire) and the keys 6, 7, 8, 9 and 0 (left, right, down, up, fire).
|
||||||||||||||||||||||
| 48647 | LD A,247 | Read from the keyboard, with a call to ReadKeyboardPort that returns the pressed keys as set bits;
|
||||||||||||||||||||
| 48649 | CALL ReadKeyboardPort | |||||||||||||||||||||
| 48652 | PUSH BC | Stash BC on the stack. | ||||||||||||||||||||
| 48653 | LD B,5 | Set a counter in B of five keys. | ||||||||||||||||||||
| ReadControls_Reverse | 48655 | RRA | Reverse the order of the five bits, so that they line up with the keys of the second port. | |||||||||||||||||||
| 48656 | RL C | |||||||||||||||||||||
| 48658 | DJNZ ReadControls_Reverse | |||||||||||||||||||||
| 48660 | LD A,C | Move the reversed keys to A. | ||||||||||||||||||||
| 48661 | POP BC | Restore BC from the stack. | ||||||||||||||||||||
| 48662 | LD C,A | Move the reversed keys to C. | ||||||||||||||||||||
| 48663 | LD A,239 | Read from the keyboard, with a call to ReadKeyboardPort that returns the pressed keys as set bits;
|
||||||||||||||||||||
| 48665 | CALL ReadKeyboardPort | |||||||||||||||||||||
| 48668 | OR C | Add the keys from the first port to those of the second. | ||||||||||||||||||||
| 48669 | LD C,0 | Start with no controls. | ||||||||||||||||||||
| 48671 | BIT 0,A | Set the bit for fire if fire is pressed. | ||||||||||||||||||||
| 48673 | JR Z,ReadControls_Interface2Up | |||||||||||||||||||||
| 48675 | SET 6,C | |||||||||||||||||||||
| ReadControls_Interface2Up | 48677 | BIT 1,A | Set the bit for walking forward if up is pressed. | |||||||||||||||||||
| 48679 | JR Z,ReadControls_Interface2Down | |||||||||||||||||||||
| 48681 | SET 2,C | |||||||||||||||||||||
| ReadControls_Interface2Down | 48683 | BIT 2,A | Set the bit for jumping if down is pressed. | |||||||||||||||||||
| 48685 | JR Z,ReadControls_Interface2Right | |||||||||||||||||||||
| 48687 | SET 3,C | |||||||||||||||||||||
| ReadControls_Interface2Right | 48689 | BIT 3,A | Set the bit for turning right if right is pressed. | |||||||||||||||||||
| 48691 | JR Z,ReadControls_Interface2Left | |||||||||||||||||||||
| 48693 | SET 1,C | |||||||||||||||||||||
| ReadControls_Interface2Left | 48695 | BIT 4,A | Set the bit for turning left if left is pressed. | |||||||||||||||||||
| 48697 | JR Z,ReadControls_Interface2Keys | |||||||||||||||||||||
| 48699 | SET 0,C | |||||||||||||||||||||
| ReadControls_Interface2Keys | 48701 | JP ReadControls_Keys | Jump to ReadControls_Keys to check the keys for picking up and dropping. | |||||||||||||||||||
|
Read a Kempston joystick, whose bits are right, left, down, up and fire.
|
||||||||||||||||||||||
| ReadControls_Kempston | 48704 | IN A,(31) | Read the joystick. | |||||||||||||||||||
| 48706 | LD C,0 | Start with no controls. | ||||||||||||||||||||
| 48708 | BIT 0,A | Set the bit for turning right if right is pressed. | ||||||||||||||||||||
| 48710 | JR Z,ReadControls_KempstonLeft | |||||||||||||||||||||
| 48712 | SET 1,C | |||||||||||||||||||||
| ReadControls_KempstonLeft | 48714 | BIT 1,A | Set the bit for turning left if left is pressed. | |||||||||||||||||||
| 48716 | JR Z,ReadControls_KempstonDown | |||||||||||||||||||||
| 48718 | SET 0,C | |||||||||||||||||||||
| ReadControls_KempstonDown | 48720 | BIT 2,A | Set the bit for jumping if down is pressed. | |||||||||||||||||||
| 48722 | JR Z,ReadControls_KempstonUp | |||||||||||||||||||||
| 48724 | SET 3,C | |||||||||||||||||||||
| ReadControls_KempstonUp | 48726 | BIT 3,A | Set the bit for walking forward if up is pressed. | |||||||||||||||||||
| 48728 | JR Z,ReadControls_KempstonFire | |||||||||||||||||||||
| 48730 | SET 2,C | |||||||||||||||||||||
| ReadControls_KempstonFire | 48732 | BIT 4,A | Set the bit for fire if fire is pressed. | |||||||||||||||||||
| 48734 | JR Z,ReadControls_KempstonKeys | |||||||||||||||||||||
| 48736 | SET 6,C | |||||||||||||||||||||
| ReadControls_KempstonKeys | 48738 | JP ReadControls_Keys | Jump to ReadControls_Keys to check the keys for picking up and dropping. | |||||||||||||||||||
|
Read a cursor joystick, which is the keys 5 (left), 6 (down), 7 (up), 8 (right) and 0 (fire).
|
||||||||||||||||||||||
| ReadControls_Cursor | 48741 | LD C,0 | Start with no controls. | |||||||||||||||||||
| 48743 | LD A,247 | Read from the keyboard, with a call to ReadKeyboardPort that returns the pressed keys as set bits;
|
||||||||||||||||||||
| 48745 | CALL ReadKeyboardPort | |||||||||||||||||||||
| 48748 | BIT 4,A | Set the bit for turning left if the key 5 is pressed. | ||||||||||||||||||||
| 48750 | JR Z,ReadControls_CursorFire | |||||||||||||||||||||
| 48752 | SET 0,C | |||||||||||||||||||||
| ReadControls_CursorFire | 48754 | LD A,239 | Read from the keyboard, with a call to ReadKeyboardPort that returns the pressed keys as set bits;
|
|||||||||||||||||||
| 48756 | CALL ReadKeyboardPort | |||||||||||||||||||||
| 48759 | BIT 0,A | Set the bit for fire if the key 0 is pressed. | ||||||||||||||||||||
| 48761 | JR Z,ReadControls_CursorUp | |||||||||||||||||||||
| 48763 | SET 6,C | |||||||||||||||||||||
| ReadControls_CursorUp | 48765 | BIT 3,A | Set the bit for walking forward if the key 7 is pressed. | |||||||||||||||||||
| 48767 | JR Z,ReadControls_CursorRight | |||||||||||||||||||||
| 48769 | SET 2,C | |||||||||||||||||||||
| ReadControls_CursorRight | 48771 | BIT 2,A | Set the bit for turning right if the key 8 is pressed. | |||||||||||||||||||
| 48773 | JR Z,ReadControls_CursorDown | |||||||||||||||||||||
| 48775 | SET 1,C | |||||||||||||||||||||
| ReadControls_CursorDown | 48777 | BIT 4,A | Set the bit for jumping if the key 6 is pressed. | |||||||||||||||||||
| 48779 | JR Z,ReadControls_Keys | |||||||||||||||||||||
| 48781 | SET 3,C | |||||||||||||||||||||
| 48783 | JR ReadControls_Keys | Jump to ReadControls_Keys to check the keys for picking up and dropping. | ||||||||||||||||||||
|
Read the keyboard. The keys that turn left are Z, C, M and B and those that turn right are X, V, SYMBOL SHIFT and N.
|
||||||||||||||||||||||
| ReadControls_Keyboard | 48785 | LD A,254 | Read from the keyboard, with a call to ReadKeyboardPort that returns the pressed keys as set bits;
|
|||||||||||||||||||
| 48787 | CALL ReadKeyboardPort | |||||||||||||||||||||
| 48790 | RRCA | Shift the keys down by one, which drops CAPS SHIFT and leaves Z and C for turning left, and X and V for turning right. | ||||||||||||||||||||
| 48791 | LD C,A | Stash them in C. | ||||||||||||||||||||
| 48792 | AND %00000011 | Keep the keys Z and X. | ||||||||||||||||||||
| 48794 | SRL C | Shift the keys C and V down to the same place. | ||||||||||||||||||||
| 48796 | SRL C | |||||||||||||||||||||
| 48798 | OR C | Combine them with the keys Z and X. | ||||||||||||||||||||
| 48799 | AND %00000011 | Keep the two bits for turning left and turning right. | ||||||||||||||||||||
| 48801 | LD C,A | Set the turning bits of the controls. | ||||||||||||||||||||
| 48802 | LD A,127 | Read from the keyboard, with a call to ReadKeyboardPort that returns the pressed keys as set bits;
|
||||||||||||||||||||
| 48804 | CALL ReadKeyboardPort | |||||||||||||||||||||
| 48807 | BIT 1,A | Set the bit for turning right if SYMBOL SHIFT is pressed. | ||||||||||||||||||||
| 48809 | JR Z,ReadControls_KeyboardM | |||||||||||||||||||||
| 48811 | SET 1,C | |||||||||||||||||||||
| ReadControls_KeyboardM | 48813 | BIT 2,A | Set the bit for turning left if M is pressed. | |||||||||||||||||||
| 48815 | JR Z,ReadControls_KeyboardN | |||||||||||||||||||||
| 48817 | SET 0,C | |||||||||||||||||||||
| ReadControls_KeyboardN | 48819 | BIT 3,A | Set the bit for turning right if N is pressed. | |||||||||||||||||||
| 48821 | JR Z,ReadControls_KeyboardB | |||||||||||||||||||||
| 48823 | SET 1,C | |||||||||||||||||||||
| ReadControls_KeyboardB | 48825 | BIT 4,A | Set the bit for turning left if B is pressed. | |||||||||||||||||||
| 48827 | JR Z,ReadControls_KeyboardWalk | |||||||||||||||||||||
| 48829 | SET 0,C | |||||||||||||||||||||
| ReadControls_KeyboardWalk | 48831 | LD A,189 | Read from the keyboard, with a call to ReadKeyboardPort that returns the pressed keys as set bits;
|
|||||||||||||||||||
| 48833 | CALL ReadKeyboardPort | |||||||||||||||||||||
| 48836 | JR Z,ReadControls_KeyboardJumpKeys | Set the bit for walking forward if any of those keys is pressed. | ||||||||||||||||||||
| 48838 | SET 2,C | |||||||||||||||||||||
| ReadControls_KeyboardJumpKeys | 48840 | LD A,223 | Read from the keyboard, with a call to ReadKeyboardPort that returns the pressed keys as set bits;
|
|||||||||||||||||||
| 48842 | CALL ReadKeyboardPort | |||||||||||||||||||||
| 48845 | LD B,A | Stash the keys in B, which is not used. | ||||||||||||||||||||
| 48846 | AND %00001010 | Keep the keys O and U. | ||||||||||||||||||||
| 48848 | JR NZ,ReadControls_KeyboardJump | Jump to ReadControls_KeyboardJump if either of them is pressed. | ||||||||||||||||||||
| 48850 | LD A,251 | Read from the keyboard, with a call to ReadKeyboardPort that returns the pressed keys as set bits;
|
||||||||||||||||||||
| 48852 | CALL ReadKeyboardPort | |||||||||||||||||||||
| 48855 | LD E,A | Stash the keys in E, which is not used. | ||||||||||||||||||||
| 48856 | AND %00010101 | Keep the keys Q, E and T. | ||||||||||||||||||||
| 48858 | JR Z,ReadControls_KeyboardAction | Jump to ReadControls_KeyboardAction if none of them is pressed. | ||||||||||||||||||||
| ReadControls_KeyboardJump | 48860 | SET 3,C | Set the bit for jumping, as one of the keys Q, E, T, O and U is pressed. | |||||||||||||||||||
| ReadControls_KeyboardAction | 48862 | LD A,231 | Read from the keyboard, with a call to ReadKeyboardPort that returns the pressed keys as set bits;
|
|||||||||||||||||||
| 48864 | CALL ReadKeyboardPort | |||||||||||||||||||||
| 48867 | JR Z,ReadControls_KeyboardFire | Jump to ReadControls_KeyboardFire if none of the number keys is pressed. | ||||||||||||||||||||
| 48869 | SET 4,C | Set the bit for picking up and dropping, as a number key is pressed. | ||||||||||||||||||||
| ReadControls_KeyboardFire | 48871 | LD A,223 | Read from the keyboard, with a call to ReadKeyboardPort that returns the pressed keys as set bits;
|
|||||||||||||||||||
| 48873 | CALL ReadKeyboardPort | |||||||||||||||||||||
| 48876 | AND %00010101 | Keep the keys P, I and Y. | ||||||||||||||||||||
| 48878 | JR NZ,ReadControls_KeyboardSetFire | Jump to ReadControls_KeyboardSetFire if one of them is pressed. | ||||||||||||||||||||
| 48880 | LD A,251 | Read from the keyboard, with a call to ReadKeyboardPort that returns the pressed keys as set bits;
|
||||||||||||||||||||
| 48882 | CALL ReadKeyboardPort | |||||||||||||||||||||
| 48885 | AND %00001010 | Keep the keys W and R. | ||||||||||||||||||||
| 48887 | JR Z,ReadControls_Done | Jump to ReadControls_Done if neither is pressed. | ||||||||||||||||||||
| ReadControls_KeyboardSetFire | 48889 | SET 6,C | Set the bit for fire, as one of the keys P, I, Y, W and R is pressed. | |||||||||||||||||||
| 48891 | JR ReadControls_Done | Jump to ReadControls_Done to finish. | ||||||||||||||||||||
|
With a joystick, the keys of the keyboard other than CAPS SHIFT and SPACE are used to pick up and drop an object.
|
||||||||||||||||||||||
| ReadControls_Keys | 48893 | LD A,126 | Read from the keyboard, with a call to ReadKeyboardPort that returns the pressed keys as set bits;
|
|||||||||||||||||||
| 48895 | CALL ReadKeyboardPort | |||||||||||||||||||||
| 48898 | AND %00011110 | Keep the keys other than CAPS SHIFT and SPACE. | ||||||||||||||||||||
| 48900 | JR Z,ReadControls_Done | Jump to ReadControls_Done if none of them is pressed. | ||||||||||||||||||||
| 48902 | SET 4,C | Set the bit for picking up and dropping. | ||||||||||||||||||||
| ReadControls_Done | 48904 | LD A,C | Copy the controls to A. | |||||||||||||||||||
| 48905 | LD (42807),A | Write them to ControlsPressed. | ||||||||||||||||||||
| 48908 | RET | Return. | ||||||||||||||||||||
| Prev: 48606 | Up: Map | Next: 48909 |