any |
Lead on, adventurer. Your quest awaits!
|
|
|
Reged: 03/21/06
|
Posts: 23
|
|
|
Send PM
|
|
Re: Need help with Cruis'n World driver
09/07/12 05:52 AM
|
|
|
> question rises anyhow: why should those bits be counted from right to left? By > convention? 0x0f for example mean that the first 4 bits are set (1) ane the last 4 are not (0), the first bit is the rightmost
> 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.
It's not the best looking one to see, but in this way it's easy to understand how it work
> Any idea on what's wrong here?
In your code you never reset to 1 the "flag".
Code:
static READ32_HANDLER( port1_r ) { static UINT8 cur_view = 0; static UINT8 last_val = 0; static UINT16 last_data = 0;
UINT16 viewval = readinputport(1); //total actual values stored in memory UINT8 button_pressed = viewval & 0x0010;
if (last_val==button_pressed) return ((last_data << 16) | last_data);
if (!button_pressed ) // check if button is pressed { cur_view++; if (cur_view == 4) cur_view = 0; viewval = (viewval | 0xf0); switch (cur_view){ case 0: viewval = viewval & 0xef; break; case 1: viewval = viewval & 0xdf; break; case 2: viewval = viewval & 0xbf; break; case 3: viewval = viewval & 0x7f; break; }
} last_val=button_pressed; last_data = viewval; return (viewval << 16) | viewval; }
this shoud work, as you can see I keep a copy of last input read and if it's the same I just return old value, if not i return new data and copy new data to my stored value.
|
|