Author Topic: (Solved) Technical question regarding the Nintendo Game Boy input/hardware...  (Read 148 times)

Offline Daniel

  • Feldwebel
  • ***
  • Posts: 2313
  • Thanked: 491 times
edit - Oh, wait, never mind. I think I've completely misunderstood the documentation. Looking back at the example code, it seems that what it's saying that the game first needs to tell the hardware what it wants to check for (the game does this by resetting bit 4 if it wants to check for the D-pad, or by resetting bit 5 if it wants to check for the other buttons). The hardware then checks the corresponding buttons and then updates bits 0 through 3 accordingly. Which I guess is the reason why the manual refers to bits 4 and 5 as "out"... because the game sends them out to the button-checking hardware.

---

I'm not sure whether anyone here would know this, but maybe someone could take a guess. (I also don't know much about hardware or circuitry in general, so I don't know how similar this is to other devices...)

But as I understand it, in the Nintendo Game Boy's memory there exists a byte whose bits are to be interpreted as flags which correspond to the user input which the Game Boy receives through the Game Boy's joypad/buttons. Except for some reason it's not as simple or straightforward as one bit flag per button (even though the Game Boy has exactly 8 buttons...)

Bit 0 (referred to as "P10") signifies that D-right or A is pressed (depending upon the value of P14 and P15).
Bit 1 (referred to as "P11") signifies that D-left or B is pressed (depending upon the value of P14 and P15).
Bit 2 (referred to as "P12") signifies that D-up or Select is pressed (depending upon the value of P14 and P15).
Bit 3 (referred to as "P13") signifies that D-down or Start is pressed (depending upon the value of P14 and P15).
Bit 4 (referred to as "P14") signifies that at least one of the D buttons is pressed.
Bit 5 (referred to as "P15") signifies that at least one of the other buttons (besides the D-pad) is pressed.
Bits 6 and 7 don't do anything.

And apparently the bits are inverted for some reason (i.e. 0 means the button is pressed and 1 means it's not pressed).

Further explanation:
This document - http://marc.rawer.de/Gameboy/Docs/GBCPUman.pdf (beginning at the bottom of page 35)
Also this video (beginning at around 6:18) is very nice -
(though the guy who made the video accidentally got bits 4 and 5 mixed up)


I think I understand this all correctly, but maybe I don't, because I'm wondering what would happen if e.g. the player simultaneously presses D-right and Select? If I understand how it works, the P1 register (i.e. the byte at memory address $FF00) would then have a value of %00001010. But if that is the case, then how does the game know what the actual input is? For all the game knows, the player might be pressing A and D-up, not D-right and Select.

It seems that there's simply not enough information to get the user's actual input through this method. And yet there must be enough information, seeing as there are hundreds of Game Boy games out there that have managed to do it.

Or I'm wondering, is it possible that maybe the Game Boy prioritizes the D-pad over the other buttons, such that bits 4 and 5 can never both be reset at the same time? So in my previous example, the value would not be %00001010 but %00100010? (The game would then know that the player is pressing D-right, and the game would simply not detect the Select)?
edit - On second thought, that can't be it either, because in games like Mario you can press the A button while holding D...
« Last Edit: October 05, 2018, 06:56:25 AM by Daniel »