From the symptoms (and the IP_ACTIVE_LOW ), I'd say the game expects the input bit to default to "1" as unpressed button and be "0" for pressed button. hence, the "& ~0x10" causes the game to see the first button as always pressed + button_pressed is always 1 causing the if condition to be always verified.
I would expect that replacing the masking line with
Code:
viewval = (viewval | 0x10) & (button_pressed << cur_view); // remove the fake button bit and add the correct view bit to the input
and replacing "if (button_pressed)" with "if (!button_pressed)" might help, because in this way -you only increase cur_view when the button bit is zero and -then you put the back "1" in the fourth bit and set as zero the correct 'view bit' only when the button is pressed (and hence button_pressed==0)
I hope that in this way we get closer to the wanted effect