0x20 = 0b100000 which sounds like the bit 6 for me.
Bits are usually numbered from lowest to highest significance. It's basically place-value notation, so the least significant bit is
bit 0, not bit 1. That will clear that up.
Why P14?
The code gets direction keys first, then gets button presses after that. Remember, the pin that is selected is the one that is
LOW (0). The return values (bits 3 to 0) will be
LOW (0) for pressed buttons and
HIGH (1) for released buttons.
The example code is incorrect, here's the real deal:
Example code:
Game: Ms. Pacman
Address: $3b1
LD A,$20 <- bit 5 = $20
LD ($FF00),A <- select P14 by setting it low
LD A,($FF00)
LD A,($FF00) <- wait a few cycles
CPL <- complement A
AND $0F <- get only first 4 bits
SWAP A <- swap it
LD B,A <- store A in B
LD A,$10
LD ($FF00),A <- select P15 by setting it low
LD A,($FF00)
LD A,($FF00)
LD A,($FF00)
LD A,($FF00)
LD A,($FF00)
LD A,($FF00) <- Wait a few MORE cycles
CPL <- complement (invert)
AND $0F <- get first 4 bits
OR B <- put A and B together
LD D,A <- store A in D
LD A,($FF8B) <- read old joy data from ram
XOR D <- toggle w/current button bit
AND D <- get current button bit back
LD ($FF8C),A <- save in new Joydata storage
LD A,D <- put original value in A
LD ($FF8B),A <- store it as old joy data
LD A,$30 <- deselect P14 and P15
LD ($FF00),A <- RESET Joypad
RET <- Return from Subroutine
The button values using the above method are such:
$8 - Start $80 - Down
$4 - Select $40 - Up
$2 - B $20 - Left
$1 - A $10 - Right
Let's say we held down A, Start, and Up.
The value returned in accumulator A would be $49
Back to your original question.
As it's the only way I know, I tried to simulate the A key press event by putting 10 in "a" register (after a break)
This should work, however, the game might be making sure that it doesn't read noise. That's why Ms. Pac-Man has the value read from the run before stored at $FF8B. It makes sure that it doesn't act on button presses that lasted less than the reading interval of one execution of the button routine, that way filtering out noise (though I do not know how common it is to actually get false positives for the joypad).
Thus, you should use a conditional breakpoint in BGB. To do that, go to Debug --> Breakpoints. Point PC where you want it, the last read of joypad data for P15, and put in as condition
A=$01 if your data is complemented (CPL) and the first four bits are cut off (AND A, $0F). If the game doesn't do that for you, you will have to set the condition to
A=$DE for the same effect. Mind you, this will only get button presses of A that are standalone (no B, Start, Select pressed at the same time).
I hope this clears things up for you.
cYa,
Tauwasser