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