Prev: 53628 Up: Map Next: 53766
53694: Read View Key
Sets bit 5 of the controls if Z or SYMBOL SHIFT is pressed, then makes a copy in B in which left and right are never both set, and bits 2 and 3 are never both set.
Input
C The controls
Output
B The controls, with bits 0 and 1, and 2 and 3, made exclusive
C The controls
Read the key which rotates the view.
ReadControls_Rotate 53694 LD A,126 Read from the keyboard;
Port Number Bit
0 1 2 3 4
126 CAPS SHIFT or SPACE Z or SYMBOL SHIFT X or M C or N V or B
53696 CALL ReadKeyboardPort
53699 BIT 1,A Jump to ReadControls_Resolve if neither Z nor SYMBOL SHIFT is pressed.
53701 JR Z,ReadControls_Resolve
53703 SET 5,C Set bit 5.
Make B from the controls so that left and right are never both set, and bits 2 and 3 are never both set.
ReadControls_Resolve 53705 PUSH DE Stash DE on the stack.
53706 LD A,(41543) Fetch LastControls.
53709 LD E,A
53710 LD A,C Fetch the controls.
53711 AND %00000011 Keep left and right.
53713 CP 3 Jump to ReadControls_BothHorizontal if both are set.
53715 JR Z,ReadControls_BothHorizontal
53717 LD B,A Keep them in B.
53718 LD A,E Fetch the last controls.
53719 AND %11111100 Clear their bits for left and right.
53721 OR B Put in the new ones.
53722 LD E,A Keep them in E.
Do the same for bits 2 and 3.
ReadControls_Vertical 53723 LD A,C Fetch the controls.
53724 AND %00001100 Keep bits 2 and 3.
53726 CP 12 Jump to ReadControls_BothVertical if both are set.
53728 JR Z,ReadControls_BothVertical
53730 LD D,A Keep them in D.
53731 OR B Add them to B.
53732 LD B,A Keep them in B.
53733 LD A,E Fetch the last controls.
53734 AND %11110011 Clear their bits for the two controls.
53736 OR D Put in the new ones.
53737 LD E,A Keep them in E.
Store LastControls and add bit 4 to B.
ReadControls_Store 53738 LD A,E Fetch the last controls.
53739 LD (41543),A Set LastControls.
53742 POP DE Restore DE from the stack.
53743 LD A,C Fetch the controls.
53744 AND %00010000 Keep bit 4, for down.
53746 OR B Add it to B.
53747 LD B,A Keep it in B.
53748 RET Return.
Both left and right are set, so use the one which was not set last time.
ReadControls_BothHorizontal 53749 LD A,E Fetch the last controls.
53750 AND %00000011 Keep left and right.
53752 XOR %00000011 Turn the bits round.
53754 LD B,A Keep them in B.
53755 JR ReadControls_Vertical Jump to ReadControls_Vertical.
Bits 2 and 3 are both set, so use the one which was not set last time.
ReadControls_BothVertical 53757 LD A,E Fetch the last controls.
53758 AND %00001100 Keep bits 2 and 3.
53760 XOR %00001100 Turn the bits round.
53762 OR B Add the horizontal controls.
53763 LD B,A Keep them in B.
53764 JR ReadControls_Store Jump to ReadControls_Store.
Prev: 53628 Up: Map Next: 53766