Thank you all for the help
I was sure that the table had something weird, only i coudn't see what ... the question rises anyhow: why should those bits be counted from right to left? By convention?
The code works and it's very clear: essentially you "flatten" all the 4 view bits (5th to 8th) to "1111" with viewval = (viewval | 0xf0) and then assign the zero to the desired view bit with viewval = viewval & 0xef for bit 5, and so on.
To complete it it should be introduced some flag to avoid the view "shaking" while keeping the button pressed. I made a try, even if it doesn't work (it detects the first press, then nothing)
Code:
static READ32_HANDLER( port1_r ) { static UINT8 cur_view = 0; UINT16 viewval = readinputport(1); //actual values stored in memory UINT8 button_pressed = viewval & 0x0010; int diff=1; //the flag if (button_pressed){diff=0;}//if you release the button, the cycle is ready to be triggered by button press
if (!button_pressed && diff==0) // button is pressed and the button was released { diff=1; //this should stop the cycling untill the button is released ... cur_view++; if (cur_view == 4){cur_view = 0;}
switch (cur_view) { case 0: viewval = (viewval | 0xf0) & 0xef; break; case 1: viewval = (viewval | 0xf0) & 0xdf; break; case 2: viewval = (viewval | 0xf0) & 0xbf; break; case 3: viewval = (viewval | 0xf0) & 0x7f; break; } } return (viewval << 16) | viewval; }
Any idea on what's wrong here?
Thanks!!
|