Jet Set Willy: Routine at 34620

| Routines

34620: Read the keyboard during code entry

Used by the routine at 34499. Waits for '1', '2', '3', '4' or ENTER to be pressed and either prints a coloured block or validates the entered code. Returns to the routine at 34463 if ENTER is being pressed, with the zero flag reset if the entered code is correct.
Input
IX | Attribute file address of the flashing 2x2 block
34620 | LD BC,63486 | Read keys 1-2-3-4-5
34623 | IN A,(C)
34625 | AND 15 | Is '1', '2', '3' or '4' (still) being pressed?
34627 | CP 15
34629 | JR NZ,34620 | Jump back if so
34631 | LD B,191 | Read keys H-J-K-L-ENTER
34633 | IN A,(C)
34635 | BIT 0,A | Is ENTER being pressed?
34637 | JR NZ,34693 | Jump if not
34639 | LD A,(22873) | Pick up the attribute byte of the fourth 2x2 block at (10,25)
34642 | AND 127 | Has the fourth digit been entered yet?
34644 | CP 7
34646 | JR Z,34693 | Jump if not
We have four coloured blocks, and ENTER is being pressed. Time to validate the entered code.
34648 | SUB 8 | Compute bits 0 and 1 of the entered code from the attribute byte of the fourth coloured block at (10,25) and store them in C
34650 | AND 24
34652 | RRCA
34653 | RRCA
34654 | RRCA
34655 | LD C,A
34656 | LD A,(22867) | Compute bits 4 and 5 of the entered code from the attribute byte of the second coloured block at (10,19) and store them in C (alongside bits 0 and 1)
34659 | SUB 8
34661 | AND 24
34663 | RLCA
34664 | OR C
34665 | LD C,A
34666 | LD A,(22870) | Compute bits 2 and 3 of the entered code from the attribute byte of the third coloured block at (10,22) and store them in C (alongside bits 0, 1, 4 and 5)
34669 | SUB 8
34671 | AND 24
34673 | RRCA
34674 | OR C
34675 | LD C,A
34676 | LD A,(22864) | Compute bits 6 and 7 of the entered code from the attribute byte of the first coloured block at (10,16) in A
34679 | SUB 8
34681 | AND 24
34683 | RLCA
34684 | RLCA
34685 | RLCA
34686 | POP HL | Drop the return address from the stack
34687 | OR C | Merge bits 0-5 of the entered code into A; now A holds all 8 bits of the entered code
34688 | LD HL,34276 | Point HL at 34276 (where the correct entry code is stored)
34691 | CP (HL) | Set the zero flag if the entered code matches
34692 | RET | Return to the routine at 34463
Here we check whether '1', '2', '3' or '4' is being pressed.
34693 | SET 7,(IX+0) | Make sure the current 2x2 block is flashing
34697 | SET 7,(IX+1)
34701 | SET 7,(IX+32)
34705 | SET 7,(IX+33)
34709 | LD BC,63486 | Read keys 1-2-3-4-5
34712 | IN A,(C)
34714 | AND 15 | Keep only bits 0-3 (keys 1-2-3-4)
34716 | LD E,8 | E=8 (INK 0: PAPER 1)
34718 | CP 14 | Is '1' alone being pressed?
34720 | JR Z,34741 | Jump if so
34722 | LD E,16 | E=16 (INK 0: PAPER 2)
34724 | CP 13 | Is '2' alone being pressed?
34726 | JR Z,34741 | Jump if so
34728 | LD E,24 | E=24 (INK 0: PAPER 3)
34730 | CP 11 | Is '3' alone being pressed?
34732 | JR Z,34741 | Jump if so
34734 | LD E,32 | E=32 (INK 0: PAPER 4)
34736 | CP 7 | Is '4' alone being pressed?
34738 | JP NZ,34631 | If not, jump back to check the ENTER key
Exactly one of the number keys '1', '2', '3' or '4' is being pressed. E holds the corresponding attribute byte to use for the coloured block.
34741 | LD (IX+0),E | Set the colour of the 2x2 block (no longer flashing)
34744 | LD (IX+1),E
34747 | LD (IX+32),E
34750 | LD (IX+33),E
34753 | LD BC,24 | Pause for about 0.02s
34756 | DJNZ 34756
34758 | DEC C
34759 | JR NZ,34756
34761 | RET |