MAMEWorld >> MAME Artwork: Official
Previous thread Previous  View all threads Index   Next thread Next   Flat Mode Flat  

MooglyGuy
Renegade MAME Dev
Reged: 09/01/05
Posts: 2081
Send PM
Re: Vas Crabb or Mr. Do: Request for Input
12/03/20 10:06 PM


> PORT_START("IN0")
> PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_8WAY
> PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_8WAY
> PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_8WAY
> PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_8WAY
>
> The default state and inputmask is the sum of all the port_bits that you are grouping
> together; in this case, u/r/d/l... 1+2+4+8=15, which is f in hex (10=a, 11=b, etc.)
>
> The state in the element for each position is the sum of all the inputs, minus the
> input you are defining... so RIGHT = 15-2 = 13 = d... UP+LEFT = 15-1-8 = 6

This is not strictly true.

It's true for Bosconian, but your "subtraction" method only holds true if the input definition uses IP_ACTIVE_LOW.

The part that I think you're missing here, and might be helpful to know, is to think of things not in terms of decimal values, or even hexadecimal values to start with, and consider the underlying binary instead.

Modern convention when writing binary numbers is to have the most significant (highest-value) bit to the left, and the least significant (lowest-value) bit to the right. Just like writing any other number, really.

The difference between IP_ACTIVE_HIGH and IP_ACTIVE_LOW is simply which value (0 or 1, respectively) is used to represent a given input "at rest" within the overall port.

Here's where thinking of it as a binary number comes in handy. You can write yourself out a little chart, like this (using Bosconian's input definition as a template):


Code:


LDRU
1111



This represents the state of the input port at rest, because as said above, IP_ACTIVE_LOW means that the corresponding bit will have a value of 1 when at rest.

Just like how each successive digit in a decimal number is worth 10 times the one to the right, each successive digit in a binary number is worth 2 times the one to the right. Just as with decimal, the rightmost position is the "one's" digit. So, going from right to left, we can calculate:

1 + 1*2 + 1*2*2 + 1*2*2*2

Simplifying:
1 + 1*2 + 1*4 + 1*8

Simplifying further:
1 + 2 + 4 + 8 = 15

Now, let's use the chart method to represent Down-Right on the joystick:


Code:


LDRU
1001



As before:
1 + 0*2 + 0*2*2 + 1*2*2*2
1 + 0*2 + 0*4 + 1*8
1 + 1*8
1 + 8 = 9

Lastly, the reason for my suggestion to go with a binary representation in your head is that it makes it much easier to convert between binary and hexadecimal. Why? Because rather than having weirdness when representing digits - where a single-digit hex value of "F" becomes a two-digit decimal value of "15", you can convert every group of four bits into a single hex digit:


Code:


0000: 0
0001: 1
0010: 2
0011: 3
0100: 4
0101: 5
0110: 6
0111: 7
1000: 8
1001: 9
1010: A
1011: B
1100: C
1101: D
1110: E
1111: F



This same property holds true for longer strings of binary numbers:

Code:


1101 1110 1010 1101 1011 1110 1110 1111
D E A D B E E F



Anyway, I don't know if any of this helps to demystify the underlying principles any, or if I've just managed to confuse you more, but hey.







Entire thread
Subject Posted by Posted on
* Vas Crabb or Mr. Do: Request for Input Nightvoice 12/03/20 10:22 AM
. * Re: Vas Crabb or Mr. Do: Request for Input Mr. DoAdministrator  12/03/20 02:51 PM
. * Re: Vas Crabb or Mr. Do: Request for Input MooglyGuy  12/03/20 10:06 PM
. * Re: Vas Crabb or Mr. Do: Request for Input Mr. DoAdministrator  12/04/20 01:39 AM
. * Re: Vas Crabb or Mr. Do: Request for Input Vas Crabb  12/05/20 07:46 AM
. * Re: Vas Crabb or Mr. Do: Request for Input Vas Crabb  12/04/20 05:19 AM
. * Re: Vas Crabb or Mr. Do: Request for Input Nightvoice  12/31/20 02:36 PM
. * Re: Vas Crabb or Mr. Do: Request for Input Mr. DoAdministrator  12/31/20 06:25 PM
. * Re: Vas Crabb or Mr. Do: Request for Input Vas Crabb  12/31/20 09:47 PM
. * Re: Vas Crabb or Mr. Do: Request for Input Nightvoice  01/01/21 01:31 AM
. * Re: Vas Crabb or Mr. Do: Request for Input Vas Crabb  01/01/21 09:02 AM
. * Re: Vas Crabb or Mr. Do: Request for Input Nightvoice  12/04/20 09:34 AM
. * Re: Vas Crabb or Mr. Do: Request for Input Vas Crabb  12/04/20 10:36 PM
. * Re: Vas Crabb or Mr. Do: Request for Input Nightvoice  12/03/20 04:04 PM
. * Re: Vas Crabb or Mr. Do: Request for Input Nightvoice  12/03/20 10:23 AM

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