JOYSTICK
Note : The following text is based on coleco library by Marcel de Kogel.
The joystick is divided in two parts : keypad and joypad.
JOYPAD
Use joypad_1 and joypad_2 to know the direction and the (pressed) fire button(s). The joypad_1 is for the joystick at the port#1. The joypad_2 is for the joystick at the port#2.
How to use the joypad_1 and joypad_2 values?
The value is a byte and each bit in this byte represent a fire button or a direction.
F4|F3|F2|F1|LT|DN|RT|UP
UP : Up
RT : Right
DN : Down
LT : Left
F1 : Fire #1
F2 : Fire #2
F3 : Fire #3
F4 : Fire #4
So, you need to use a mask (AND MASK) to extract the value you need.
Example : I want to do nothing until a fire button is pressed on port#1.
Answer : The fire buttons bits are the four(4) highest bits in the joypad byte. So, you need to do a mask with four(4) bits 1 and four(4) bits 0 like this : 11110000 (F0 in HEX value).
KEYPADwhile((joypad_1&0xf0)==0); /* loop if no fire button is pressed (port#1) */
Use keypad_1 and keypad_2 to know which number was pressed. The keypad_1 is for the keypad on port#1. The keypad_2 is for the keypad on port#2.
Note : The first time you call keypad_1 and keypad_2, the result will be 0 but it doesn't mean the number 0 was pressed. After this first time, the keypad value will match with the number key pressed.
0-9 = 0-9
10 = * (standard to pause the game and replay game with the same game option)
11 = # (standard to return to menu after the game)
12-15 = ... (no key pressed)
Have fun!