MAMEWorld >> Programming
View all threads Index   Threaded Mode Threaded  

Pages: 1

baritonomarchetto
MAME Fan
Reged: 11/22/10
Posts: 18
Send PM


Need help with Cruis'n World driver
#294594 - 08/27/12 04:12 PM


Hi All,

I am toying with MAME sources, but I am not a programmer, so I am having some issues while trying to implement the sequential view change in Cruis’n World.

Aaron wrote some helpful code for the gear handling I used as a template, even if I am not a bit by bit guru and most of the code is “supposed to mean” something to me .
Anyhow, I ended up with this code:


Code:


static READ32_HANDLER( port1_r )
{
UINT16 viewval = readinputport(1); //actual value stored in memory
UINT16 viewdiff = viewval ^ last_port1;
if ((viewdiff & 0x0010) && !(viewval & 0x0010)) //the button is pressed (?)
{
if (view_state==0) {view_state = 4;} //1st view
else if (view_state==4) {view_state = 2;} //2nd view
else if (view_state==2) {view_state = 1;} //3rd view
else if (view_state==1) {view_state = 4;} //1st view
}
last_port1 = viewval;
viewval = (viewval | 0x00f0) ^ (view_state << 4);
return (viewval << 16) | viewval;
}



This code (for MAME 0.106 but very similar on more recent devs) somehow works “in-game”, but when the play finishes I cannot insert the name (hiscore) nor I can continue because the game acts like a button (a view change button, I suppose) is kept pressed. Notice that this is not related to PORT_BIT being kept HIGH or LOW. I think that the problem is in that “return (viewval << 16) | viewval;” being returned every single time the code is run.

How can I modify this to let the view change only when the button is pressed, then no other inputs are sent? Any idea?

Thanks for the support



sz72
MAME Fan
Reged: 08/20/07
Posts: 78
Send PM


Re: Need help with Cruis'n World driver new [Re: baritonomarchetto]
#294604 - 08/27/12 08:44 PM


> Hi All,
>
> I am toying with MAME sources, but I am not a programmer, so I am having some issues
> while trying to implement the sequential view change in Cruis’n World.
>
> Aaron wrote some helpful code for the gear handling I used as a template, even if I
> am not a bit by bit guru and most of the code is “supposed to mean” something to me .
>
> Anyhow, I ended up with this code:
>
>
> static READ32_HANDLER( port1_r )
> {
> UINT16 viewval = readinputport(1); //actual value stored in memory
> UINT16 viewdiff = viewval ^ last_port1;
> if ((viewdiff & 0x0010) && !(viewval & 0x0010)) //the button is pressed (?)
> {
> if (view_state==0) {view_state = 4;} //1st view
> else if (view_state==4) {view_state = 2;} //2nd view
> else if (view_state==2) {view_state = 1;} //3rd view
> else if (view_state==1) {view_state = 4;} //1st view
> }
> last_port1 = viewval;
> viewval = (viewval | 0x00f0) ^ (view_state << 4);
> return (viewval << 16) | viewval;
> }
>
>
> This code (for MAME 0.106 but very similar on more recent devs) somehow works
> “in-game”, but when the play finishes I cannot insert the name (hiscore) nor I can
> continue because the game acts like a button (a view change button, I suppose) is
> kept pressed. Notice that this is not related to PORT_BIT being kept HIGH or LOW. I
> think that the problem is in that “return (viewval << 16) | viewval;” being
> returned every single time the code is run.
>
> How can I modify this to let the view change only when the button is pressed, then no
> other inputs are sent? Any idea?
>
> Thanks for the support

In the code you show, the variable view_state changes value only when the number returned by readinputport(1) changes between calls of the port1_r read handler (in particular when bit 4 changes from 1 to 0).
So the view should already change only when the button is pressed.



baritonomarchetto
MAME Fan
Reged: 11/22/10
Posts: 18
Send PM


Re: Need help with Cruis'n World driver new [Re: sz72]
#294640 - 08/28/12 09:23 AM


Thanks for the answer

If i insert the "return" between braces, like


static READ32_HANDLER( port1_r )
{
UINT16 viewval = readinputport(1);
UINT16 viewdiff = viewval ^ last_port1;
if ((viewdiff & 0x0010) && !(viewval & 0x0010))
{
if (view_state==0) {view_state = 4;} //1st view
else if (view_state==4) {view_state = 2;} //2nd view
else if (view_state==2) {view_state = 1;} //3rd view
else if (view_state==1) {view_state = 4;} //1st view
last_port1 = viewval;
viewval = (viewval | 0x00f0) ^ (view_state << 4);
return (viewval << 16) | viewval;
}
}

While compiling it reports an error to the last line (that with the closing brace): "control reaches end of non-void function"

How should i write it? Maybe it needs something to be returned before closing ?

Thanks a lot



sz72
MAME Fan
Reged: 08/20/07
Posts: 78
Send PM


Re: Need help with Cruis'n World driver new [Re: baritonomarchetto]
#294644 - 08/28/12 01:30 PM


> Thanks for the answer
>
> If i insert the "return" between braces, like
>
>
> static READ32_HANDLER( port1_r )
> {
> UINT16 viewval = readinputport(1);
> UINT16 viewdiff = viewval ^ last_port1;
> if ((viewdiff & 0x0010) && !(viewval & 0x0010))
> {
> if (view_state==0) {view_state = 4;} //1st view
> else if (view_state==4) {view_state = 2;} //2nd view
> else if (view_state==2) {view_state = 1;} //3rd view
> else if (view_state==1) {view_state = 4;} //1st view
> last_port1 = viewval;
> viewval = (viewval | 0x00f0) ^ (view_state << 4);
> return (viewval << 16) | viewval;
> }
> }
>
> While compiling it reports an error to the last line (that with the closing brace):
> "control reaches end of non-void function"
>
> How should i write it? Maybe it needs something to be returned before closing ?
>
> Thanks a lot

"non-void function" means "function that must always return a value"
With your modification port1_r returns a value only when the button is pressed (released), so the compiler gives you that error
READ32_HANDLER generates a function that must return a 32 bit number (as the term "read handler" suggests)



baritonomarchetto
MAME Fan
Reged: 11/22/10
Posts: 18
Send PM


Re: Need help with Cruis'n World driver new [Re: sz72]
#294645 - 08/28/12 02:01 PM


Thanks. So, that function must return a value. Do you have any suggestion on how to solve the problem?

The original code for that port is


Code:


static READ32_HANDLER( port1_r )
{
return (readinputport(1) << 16) | readinputport(1);
}



This works, i mean, it doesnt act like you are continuously pressing view button even if returning a value (readinputport(1) << 16) | readinputport(1)). My code, instead, acts like you are continuously (i suppose with a clock speed) pressing a view button... should i cange function? Could that be written in a different way?

Thank you for the help



sz72
MAME Fan
Reged: 08/20/07
Posts: 78
Send PM


Re: Need help with Cruis'n World driver new [Re: baritonomarchetto]
#294651 - 08/28/12 03:51 PM


> Thanks. So, that function must return a value. Do you have any suggestion on how to
> solve the problem?
>
> The original code for that port is
>
>
> static READ32_HANDLER( port1_r )
> {
> return (readinputport(1) << 16) | readinputport(1);
> }
>
>
> This works, i mean, it doesnt act like you are continuously pressing view button even
> if returning a value (readinputport(1) << 16) | readinputport(1)). My code,
> instead, acts like you are continuously (i suppose with a clock speed) pressing a
> view button... should i cange function? Could that be written in a different way?
>
> Thank you for the help

To answer you i would need to know what you really want to do, what is the current behaviour of the system and how you want to change it.



baritonomarchetto
MAME Fan
Reged: 11/22/10
Posts: 18
Send PM


Re: Need help with Cruis'n World driver new [Re: sz72]
#294655 - 08/28/12 04:19 PM


Well,

in Cruis'n World/USA the 4 view positions are mapped to 4 buttons. What i am trying to code is the cycling between the 4 views by using a single button, in this case the first view (0x0010).

The "working" code i wrote in the first post is good up to the "continue" screen: while there the countdown is extra fast (like you are pressing again and again a view button) makeing impossible t continue the game (in the clean driver, exactly like in the real arcade machine, if you reach the "continue game" screen, pressing repeately a "view" button makes the countdown going faster.

I am trying to modify the "working" code in first post in order to give the view change input, but avoiding the continuos press of the view button thus allowing the player to continue the game...

hope i wrote it better now, sorry if i waas not clear before

If you are asking what this could be used for, well, in Racing Cabinets not always you have 4 buttons, one for each view, so it would be useful for a Racing MAME Cab to have a feature like this.



sz72
MAME Fan
Reged: 08/20/07
Posts: 78
Send PM


Re: Need help with Cruis'n World driver new [Re: baritonomarchetto]
#294681 - 08/28/12 06:55 PM


> Well,
>
> in Cruis'n World/USA the 4 view positions are mapped to 4 buttons. What i am trying
> to code is the cycling between the 4 views by using a single button, in this case the
> first view (0x0010).
>
> The "working" code i wrote in the first post is good up to the "continue" screen:
> while there the countdown is extra fast (like you are pressing again and again a view
> button) makeing impossible t continue the game (in the clean driver, exactly like in
> the real arcade machine, if you reach the "continue game" screen, pressing repeately
> a "view" button makes the countdown going faster.
>
> I am trying to modify the "working" code in first post in order to give the view
> change input, but avoiding the continuos press of the view button thus allowing the
> player to continue the game...
>
> hope i wrote it better now, sorry if i waas not clear before
>
> If you are asking what this could be used for, well, in Racing Cabinets not always
> you have 4 buttons, one for each view, so it would be useful for a Racing MAME Cab to
> have a feature like this.

So you need something where when the user presses the first view button for the first time the game thinks that the user has pressed the first view button,when the user presses the first view button for the second time the game thinks that the user has pressed the second view button,when the user presses the first view button for the third time the game thinks that the user has pressed the third view button,when the user presses the first view button for the fourth time the game thinks that the user has pressed the fourth view button,when the user presses the first view button for the fifth time the game thinks that the user has pressed the first view button, and so on.

One way to do it is to rotate bits 4-7 of the value returned by readinputport(1) by N, where N is a number betwen 0 and 3 that represents the currently selected view, and update N every time the first view button is pressed.



baritonomarchetto
MAME Fan
Reged: 11/22/10
Posts: 18
Send PM


Re: Need help with Cruis'n World driver new [Re: sz72]
#294752 - 08/29/12 02:27 PM


You got the point

unfortunately i don't know how to implement the feature the way you suggested ... could you post some code to teach me something? It would be very appreciated



etabeta
Reged: 08/25/04
Posts: 2036
Send PM


Re: Need help with Cruis'n World driver new [Re: baritonomarchetto]
#294757 - 08/29/12 04:04 PM


I think that the problem with the original code was that you were still returning the view_state bit even when the button was not pressed and the game was not expecting that (input_port reads the corresponding bit as 1 only when you press the button, then it reads 0... it's the internal game code that takes care of checking frequently enough if the bit is 0 or 1)

> You got the point
>
> unfortunately i don't know how to implement the feature the way you suggested ...
> could you post some code to teach me something? It would be very appreciated

1. change the input port to get only a single bit (say 0x10) [i.e. remove the other button inputs]

2. assuming the input is 1 when button is pressed and 0 when is de-pressed (if not, you have to slightly modify the parts where you test the 0x10 bit...), use something along the lines of


Code:


static READ32_HANDLER( port1_r )
{
static UINT8 cur_view = 0;
UINT16 viewval = readinputport(1); //actual value stored in memory
UINT8 button_pressed = viewval & 0x0010;

if (button_pressed) // check if button is pressed
{
cur_view++;
if (cur_view == 4)
cur_view = 0;
}
viewval = (viewval & ~0x10) | (button_pressed << cur_view); // remove the fake button bit and add the correct view bit to the input
return (viewval << 16) | viewval;
}



notice that in more recent versions cur_value would become an element of the driver class, but given you talk about very old MAME, a static variable should do the job



baritonomarchetto
MAME Fan
Reged: 11/22/10
Posts: 18
Send PM


Re: Need help with Cruis'n World driver new [Re: etabeta]
#294760 - 08/29/12 04:37 PM


Thank you for the help

Your code is very clean and helpful. There should be something wrong unfortunately, because there's still the "continuous press" problem AND there's no more view change by using the 0x0010 button... could there be some error in the line removing the fake button bit?


Code:


viewval = (viewval & ~0x10) | (button_pressed << cur_view); // remove the fake button bit and add the correct view bit to the input
return (viewval << 16) | viewval;



I essentially copied and pasted your code and changed the original PORT_START from:


Code:


PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(2) /* view 1 */
PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_PLAYER(2) /* view 2 */
PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_PLAYER(2) /* view 3 */
PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_BUTTON5 ) PORT_PLAYER(2) /* view 4 */



to


Code:


PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(2) PORT_NAME("View Change") /* view 1 */
PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_UNUSED ) PORT_PLAYER(2) /* view 2 */
PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_UNUSED ) PORT_PLAYER(2) /* view 3 */
PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_UNUSED ) PORT_PLAYER(2) /* view 4 */



Thanks for the help. I hope i am not annoying with my noob questions



etabeta
Reged: 08/25/04
Posts: 2036
Send PM


Re: Need help with Cruis'n World driver new [Re: baritonomarchetto]
#294785 - 08/30/12 07:32 AM


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



baritonomarchetto
MAME Fan
Reged: 11/22/10
Posts: 18
Send PM


Re: Need help with Cruis'n World driver new [Re: etabeta]
#294796 - 08/30/12 05:54 PM


Thanks for your help

I checked the new code and there still are the same problems: the button is seen as being repeatedly pressed and released. With the new code, anyhow, it works somehow: i can cycle between the views, even if the view button press is not recorded all the times.

Having not practice with bitwise operations, I cannot be of any help to find out a working code actually. Even if i read some basic info with the help of google, i cannot see practical uses of bitwise operators in MAME.

Being this code more or less 10 lines, may i ask you to explain some topical line?

Essentially, if i am correct, we are dealing with a 4 byte long memory region in whitch the current view AND the button position is stored, right?

i.e how this line:


Code:

UINT8 button_pressed = viewval & 0x0010;



defines a button press? because only if the two values are the same it will return 0x0010?

How this line


Code:

 viewval = (viewval & ~0x10) | (button_pressed << cur_view); 


removes the fake button and adds the correct button?

Are there some examples of bitwise common operations used in MAME "out there"?

Thanks, hope this will be of some help to other people approaching MAME coding, not only to me...



etabeta
Reged: 08/25/04
Posts: 2036
Send PM


Re: Need help with Cruis'n World driver new [Re: baritonomarchetto]
#294842 - 08/31/12 08:27 AM


> I checked the new code and there still are the same problems: the button is seen as
> being repeatedly pressed and released. With the new code, anyhow, it works somehow: i
> can cycle between the views, even if the view button press is not recorded all the
> times.

whoops, I have just notice a mistake in the "removes the fake button and adds the correct button". the code was ok for IP_ACTIVE_HIGH but not IP_ACTIVE_LOW, sorry. try with this line, instead


Code:

viewval = (viewval | 0x10) & ((button_pressed | 0xef) << cur_view); // remove the fake button bit and add the correct view bit to the input



> Essentially, if i am correct, we are dealing with a 4 byte long memory region in
> whitch the current view AND the button position is stored, right?

well no (or better not exactly). maybe the easier way to see this is from the perspective of the game itself: the game knows (because it has been programmed in that way) that at the memory location where "port1_r" (the memory handler we are modifying) is located he will find a 32bit value such that
* bits 0-15 are equal to bits 16-31
* bits 4-7 (and its copy 20-23) are "1" if no view button is pressed, or contain a single "0" if one of the view buttons is pressed

hence the game keeps checking those bits and depending to the position of the "0" (if any), it chooses which view has to be displayed. so for MAME those bits are just the input bits and it depends on the game code how the bits get interpreted

therefore the original code does the following: it reads the 16bit inputs from your controllers and returns it in the 32bit format expected by the game, i.e. copying the value both in the lower half of the number *and* in the upper half (in the real cabinets, it would be the wiring between the PCB and the controller of the cabinet to communicate the proper values)

since we want to have a single button cycling through the views, we have to intercept the input bits and modifying them before they "reach the game"


>
> i.e how this line:
>
> UINT8 button_pressed = viewval & 0x0010;
>
> defines a button press? because only if the two values are the same it will return
> 0x0010?
>

viewval is the whole value of the inputs: bits 4-7 for the view buttons, bits 0-3 might have different functions, like accessing service mode or whatever (we don't care about them here, but in the end we have to send them unmodified to the game, to be sure we don't interfere with the process... that's why at the end we return "(viewval)<<16 | viewval")

with the original code, we could check: bit 4 (masking & 0x10) to see if the first view button has been pressed; bit 5 (masking & 0x20) to see if the 2nd view button has been pressed; bit 6 (masking & 0x40) to see if the 3rd view button has been pressed; bit 7 (masking & 0x80) to see if the 4th view button has been pressed.

with our modified code we only have a single button, so bits 5-7 of viewval are always "1" (nothing can be pressed by the user since you put IPT_UNUSED in those bits ) and only bit 4 can change between "0" and "1"

so "viewval & 0x10" will be "0x10" if bit 4 of viewval is "1" (i.e. button de-pressed) and will be "0x00" if bit 4 is "0" (i.e. button pressed). so, rather than "defines a button press" the code "detects a button press"
the definition is in the input port of the driver


the game anyway still expects that different view buttons are communicated in bits 4-7 not only 4 (we never modify the game code here, just fake the data that get sent), that is why we need the "if" part which counts how many times you have pressed the (now unique) view button so that we can later put the "0" in the right bit corresponding to the view button we want to be pressed.

> How this line
>
> viewval = (viewval & ~0x10) | (button_pressed << cur_view);
> removes the fake button and adds the correct button?

premise, this code was only correct for my original interpretation of "1" button pressed and "0" button de-pressed, so I will explain all the three versions of this line to (hopefully) shred some light on the bitwise ops

what the line you quoted did is to:
- set bit 4 in viewval to zero, which I thought it was button de-pressed, by masking with ~0x10=0xef (all bits 1 except for bit 4)
- "add" the button_pressed bit (which is bit 4 only, in our modified code) shifted of the proper amount of bits, because the game expects it to be in bits 4-7 depending on the view button (the "or" operator ensures that if button_pressed was 0x10, the one is put in the right position and the other bits remain 0)

my later proposal to cope with the right interpretation of "1" button de-pressed and "0" button pressed was

> viewval = (viewval | 0x10) & (button_pressed << cur_view); // remove the fake button bit and add the correct view bit to the input

which does basically the same as the original with inverted 0-1. namely,
- set bit 4 in viewval to 1, which is button de-pressed, by using "| 0x10"
- try to add the button_pressed 0 in the correct position

the problem in this code is that if we pressed the button, button_pressed is not only zero in bit 4 as we would like, but also in bits 0-3 and 5-7 (you remember that button_pressed was only 0x00 or 0x10, right? ), so when we shift it we send not a single "0" (i.e. a single button pressed) as we would like, but multiple ones.

the final version of the code (the one at the top of this reply) attempts to fix this by adding to button_pressed all other bits as "1" so that only a single zero gets set

I hope this was of help



baritonomarchetto
MAME Fan
Reged: 11/22/10
Posts: 18
Send PM


Re: Need help with Cruis'n World driver new [Re: etabeta]
#294983 - 09/03/12 07:21 PM


First of all: thank you for the clear explanation and for the time spent for me (grazie mille!).

Sorry for the delay, but i had to study your previous answer before posting just to avoid stupid questions

This is the latest code tested:


Code:


static READ32_HANDLER( port1_r )
{
static UINT8 cur_view = 0;
UINT16 viewval = readinputport(1); //total actual values stored in memory
UINT8 button_pressed = viewval & 0x0010;

if (!button_pressed) // check if button is pressed
{
cur_view++;
if (cur_view == 4)
cur_view = 0;
}
viewval = (viewval | 0x0010) & ((button_pressed | 0x00ef) << cur_view); // remove the fake view button bit and add the correct view bit to the input
return (viewval << 16) | viewval;
}




Now, with this code somehow works even if it doesn’t cycle in a predictable way, and there’s some interaction with the “radio” button: it’s also pressed when the view button is pressed (I know, it is almost impossible for you to write a working code without compiling and testing, but this “trial and error” is helping me understanding something more on this so please keep this up even if frustrating).

Before proceeding with welcome new checks, help me understand a thing that for sure will help solving the “radio button press” problem: how can I say that bits 4-7 are those where the view selection are changed? Is it related to the declarations in the INPUT_PORTS_START region of the driver? Consider that the (partial but of interest) code is:


Code:


PORT_START
PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_UNKNOWN )
PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_BUTTON6 ) PORT_NAME("Radio")/* radio */
PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_UNKNOWN )
PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_UNKNOWN )
PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(2) PORT_NAME("View Change") /* view 1 */
PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_UNUSED ) /* view 2 */
PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_UNUSED ) /* view 3 */
PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_UNUSED ) /* view 4 */
PORT_BIT( 0xff00, IP_ACTIVE_LOW, IPT_UNUSED )



Then, going to a basic level and taking visual advantage from the following table:



Yellowed is the memory region we are dealing with (that’s where view button presses are detected) and question marked areas are those we want to keep unchanged (because controlled by other buttons and rely with other things). Considering that the other “view button press” (view 2, 3 and 4) positions are located in memory 0x20, 0x40 and 0x80, shouldn’t I conclude that the first 4 bits are those related to view presses and not bits 4-7? Isn’t the 0x0002 bit the same of 0x0020 and couldn't this be the culript of the radio button interference?



any
Lead on, adventurer. Your quest awaits!
Reged: 03/21/06
Posts: 23
Send PM


Re: Need help with Cruis'n World driver new [Re: baritonomarchetto]
#295155 - 09/06/12 06:04 AM Attachment: test.jpg 19 KB (1 downloads)



Quote:



with this code somehow works even if it doesn’t cycle in a predictable way





you cannot prevent this, the game read the input faster then you finger can release the key, so the game read that you are pressing the button more than one time and cycle through the views


UGLY code, but working

static READ32_HANDLER( port1_r )
{
static UINT8 cur_view = 0;
UINT16 viewval = readinputport(1); //total actual values stored in memory
UINT8 button_pressed = viewval & 0x0010;

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;
}
}

return (viewval << 16) | viewval;
}


there is something wrong in that table
the correct one is the follow

[ATTACHED IMAGE]

Attachment



baritonomarchetto
MAME Fan
Reged: 11/22/10
Posts: 18
Send PM


Re: Need help with Cruis'n World driver new [Re: any]
#295168 - 09/06/12 02:52 PM


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!!



any
Lead on, adventurer. Your quest awaits!
Reged: 03/21/06
Posts: 23
Send PM


Re: Need help with Cruis'n World driver new [Re: baritonomarchetto]
#295204 - 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.



baritonomarchetto
MAME Fan
Reged: 11/22/10
Posts: 18
Send PM


Re: Need help with Cruis'n World driver new [Re: any]
#295464 - 09/10/12 02:19 PM


Thank you, the code now works 100% !!

One step further: what if i want the first button to cicle between wievs (like it does) AND i want button 2, 3 and 4 work again?

I made some (unsuccesful ) trials. First of all, i tried by re-defining the 3 buttons:


Code:


PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(2) PORT_NAME("View Change/View 1") /* view 1 */
PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_PLAYER(2) PORT_NAME("View 2")/* view 2 */
PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_PLAYER(2) PORT_NAME("View 3")/* view 3 */
PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_BUTTON5 ) PORT_PLAYER(2) PORT_NAME("View 4")/* view 4 */



This, alone, doesn't work (like expected): the function "port1_r" only controls one button.

Then i made a first try (here is the full function with only one button defined but can be easily ported to all the buttons):


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;
UINT8 button2_pressed = viewval & 0x0020;
// UINT8 button3_pressed = viewval & 0x0040;
// UINT8 button4_pressed = viewval & 0x0080;

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;

if (!button2_pressed ) // check if button "view 2" is pressed
{
cur_view = 1;
viewval = (viewval | 0xf0) & 0xdf;
}
return (viewval << 16) | viewval;
}




Not working: only the "old" cycling is detected.

I made a second try, with the code section controlling the button press like:


Code:


if (!button2_pressed ) // check if button "view 2" is pressed
{
cur_view = 1;
viewval = (viewval | 0xf0) & 0xdf;
}
return (readinputport(1) << 16) | readinputport(1);



Still not working, like before ... consider that the original code (the "4 buttons, one for each view")was


Code:


static READ32_HANDLER( port1_r )
{
return (readinputport(1) << 16) | readinputport(1);
}



What's wrong? Thanks for the lesson !



baritonomarchetto
MAME Fan
Reged: 11/22/10
Posts: 18
Send PM


Re: Need help with Cruis'n World driver new [Re: baritonomarchetto]
#295679 - 09/13/12 05:05 PM


(sorry for doubleposting)

no idea on what could be wrong?




R. Belmont
Cuckoo for IGAvania
Reged: 09/21/03
Posts: 9716
Loc: ECV-197 The Orville
Send PM


Re: Need help with Cruis'n World driver new [Re: baritonomarchetto]
#296058 - 09/18/12 05:05 PM


> (sorry for doubleposting)
>
> no idea on what could be wrong?

You're trying to make the code do two conflicting things at the same time. Settle for your victory with the single-button shifter and move on



baritonomarchetto
MAME Fan
Reged: 11/22/10
Posts: 18
Send PM


Re: Need help with Cruis'n World driver new [Re: R. Belmont]
#296060 - 09/18/12 05:28 PM


My "victory" would be being able to code MAME myself without any help, but i need much more examples and case study so, how could i settle at this point? :P

Joking aside, i thought the function "port1_r" was the one controlling that input/memory region so what are the two conflicting things i am trying to make the code?

[OT] Are there code studies/resources that could help better understanding how to deal with MAME drivers?[/OT]


Pages: 1

MAMEWorld >> Programming
View all threads Index   Threaded Mode Threaded  

Extra information Permissions
Moderator:  Pi 
0 registered and 57 anonymous users are browsing this forum.
You cannot start new topics
You cannot reply to topics
HTML is enabled
UBBCode is enabled
Thread views: 4485