Prev: EDF4 Up: Map Next: EE29
EE00: Read Cursor Keys
Used by the routine at ReadControls.
Reads the cursor keys and puts the state of the controls in B, to be completed by ReadControls_Bottom_Row (see ReadControls). The keys are 5 (left), 6 (down), 7 (up), 8 (right) and 0 (fire), and a bit is reset when its key is pressed.
Output
B The state of the controls
Read_Cursor_Keys EE00 LD A,$EF Read from the keyboard;
Port Number Bit
0 1 2 3 4
EF 0 9 8 7 6
EE02 OUT ($FD),A
EE04 IN A,($FE)
EE06 LD C,A Stash the state of the keys in C.
EE07 AND %00001000 Keep only bit 3, which is the key 7 (up).
EE09 LD E,A Store it in E.
EE0A LD A,C Fetch the state of the keys.
EE0B RRCA Rotate the keys right twice, which moves the key 0 into bit 6, the key 6 into bit 2 and the key 8 into bit 0.
EE0C RRCA
EE0D AND %01000101 Keep only those three bits.
EE0F OR E Combine them with up.
EE10 LD E,A Store the result in E.
EE11 RRCA Rotate the result right twice, which moves fire from bit 6 into bit 4.
EE12 RRCA
EE13 AND %00010000 Keep only bit 4.
EE15 OR E Combine it with the other directions.
EE16 AND %00011111 Keep only the five low bits, which are right, down, up and fire (the bit for left is not set yet).
EE18 LD E,A Store the result in E.
EE19 LD A,$F7 Read from the keyboard;
Port Number Bit
0 1 2 3 4
F7 1 2 3 4 5
EE1B OUT ($FD),A
EE1D IN A,($FE)
EE1F RRA Rotate the keys right three times, which moves the key 5 into bit 1.
EE20 RRA
EE21 RRA
EE22 AND %00000010 Keep only that bit (left).
EE24 OR E Combine it with the other controls.
EE25 LD B,A Store the state of the controls in B.
EE26 JP ReadControls_Bottom_Row Jump to ReadControls_Bottom_Row to read the bottom row of the keyboard.
Prev: EDF4 Up: Map Next: EE29