Rebinding keys to different keys

Par brakenwagen

Rookie (17)

Portrait de brakenwagen

05-02-2022, 06:22

So I want I want to try Coleco games on Open msx but I was wondering if there is any way to rebind the keys to something different right now it the controls are

1 = numpad 1
2 = numpad 2
3 = numpad 3
4 = numpad 4
5 = numpad 5
6 = numpad 6
7 = numpad 7
8 = numpad 8
9 = numpad 9
0 = numpad 0
* = - numpad *, numpad -
# = =, numpad /, numpad +
Fire left = space, R-CTRL
Fire right = L-ALT, R-ALT, R-SHIFT
up = up arrow
down = down arrow
left = left arrow
right = right arrow

However I want to change to inputs so they look like this

1 = numpad 7
2 = numpad 8
3 = numpad 9
4 = numpad 4
5 = numpad 5
6 = numpad 6
7 = numpad 1
8 = numpad 2
9 = numpad 3
0 = numpad period
* = numpad 0
# = numpad enter
Fire left = key A
Fire right = Key D
up = up arrow
down = down arrow
left = left arrow
right = right arrow

!login ou Inscrivez-vous pour poster

Par Manuel

Ascended (19678)

Portrait de Manuel

05-02-2022, 23:50

So, you want to use a different mapping from your PC keyboard to the Colecovision?

Par Manuel

Ascended (19678)

Portrait de Manuel

06-02-2022, 00:00

Note that there is a fake keyboard matrix in the emulated colecovision:

// The hardware consists of 2 controllers that each have 2 triggers
// and a 12-key keypad. They're not actually connected in a matrix,
// but a ghosting-free matrix is the easiest way to model it in openMSX.
//
// row/bit  7     6     5     4     3     2     1     0
//       +-----+-----+-----+-----+-----+-----+-----+-----+
//   0   |TRIGB|TRIGA|     |     |LEFT |DOWN |RIGHT| UP  |  controller 1
//   1   |TRIGB|TRIGA|     |     |LEFT |DOWN |RIGHT| UP  |  controller 2
//   2   |  7  |  6  |  5  |  4  |  3  |  2  |  1  |  0  |  controller 1
//   3   |     |     |     |     |  #  |  *  |  9  |  8  |  controller 1
//   4   |  7  |  6  |  5  |  4  |  3  |  2  |  1  |  0  |  controller 2
//   5   |     |     |     |     |  #  |  *  |  9  |  8  |  controller 2
//       +-----+-----+-----+-----+-----+-----+-----+-----+

This information can be used to use keymatrixdown/keymatrixup commands in a binding.

For example, to bind A to trigger 1 of controller 1:

bind A "keymatrixdown 0 64"
bind A,release "keymatrixup 0 64"

Par mth

Champion (507)

Portrait de mth

06-02-2022, 17:44

Is that alternative mapping a personal preference or are there games that are hard to play with the default mapping?

I made the original mapping after trying only a handful of games and those just used the number keys to select the play mode. For those games having the PC "1" map to Coleco "1" was more convenient, since the PC button labels then match the screen prompts. But if there are games that control based on position, the flipped mapping might be better.

Par brakenwagen

Rookie (17)

Portrait de brakenwagen

07-02-2022, 05:37

Ok that makes sense but how do you go about getting the keycodes how did you know to use 0 64? is there a list of keycodes I can download. Wait is that table you posted the key codes I having trouble understanding it, I’m guessing the 0 comes from row 0 but were does the 64 come from?

Par Manuel

Ascended (19678)

Portrait de Manuel

07-02-2022, 07:47

TrigA is bit 6, so 1 << 6 or 2^6 = 64

Par brakenwagen

Rookie (17)

Portrait de brakenwagen

07-02-2022, 09:19

I’m afraid you’ve lost me how do you get 2^6 from 6? Is it that the bit is always 2 raised to the power of the bit. seems to be the case since i tried

bind KP7 "keymatrixdown 2 2"
bind KP7,release "keymatrixup 2 2"

and it worked to rebind Coleco-numbad1 to numbad7. But why do it like that wouldn't be easier to have the numbers be the bit number?

Par turbor

Hero (529)

Portrait de turbor

07-02-2022, 10:34

brakenwagen wrote:

I’m afraid you’ve lost me how do you get 2^6 from 6? Is it that the bit is always 2 raised to the power of the bit. seems to be the case

yes, it is 2 raised to the power of the bit. This is done when converting a binary number to a decimal number.
Where most humans use a decimal system(10 based) if you use a binary (2 based) you can convert between them this way. Explaining it all would take up too much space here but I recommend you look up a basic tutorial about converting between binary,decimal en hexadecimal. Most beginner programming tutorials will have a chapter about this.

brakenwagen wrote:

But why do it like that wouldn't be easier to have the numbers be the bit number?

The number you give is used as a bitmask (another programmers term) so you can have one bind press(unpress) multiple bits at the same time. so you can press trigA and trigB at the same time by using 192. 192 is the result from bit 7 and bit 6. So 2^7 + 2^6 = 128+64 =192.
Thinking in binary and hexadecimal is something that most hobby programmers get quickly used to :-)

if you want to avoid al these conversions you can also type in the binary numbers themself

bind KP7 "keymatrixdown 2 0b00000010"

the 0b tells the computer that the rest is a binary number so you can type in the 8 bits directly after them.