PCem
changeset 124:457f666b38c1
Keyboard now uses raw input. Should fix international keyboard. Based on patch from Battler.
| author | TomW |
|---|---|
| date | Fri Jul 11 20:35:37 2014 +0100 |
| parents | fdffe4113922 |
| children | 0aa71a22757b |
| files | src/keyboard.c src/plat-keyboard.h src/win-joystick.cc src/win-keyboard.cc src/win-mouse.cc src/win.c |
| diffstat | 6 files changed, 239 insertions(+), 130 deletions(-) [+] |
line diff
1.1 --- a/src/keyboard.c Thu Jul 10 21:32:49 2014 +0100 1.2 +++ b/src/keyboard.c Fri Jul 11 20:35:37 2014 +0100 1.3 @@ -10,7 +10,8 @@ 1.4 int scancodes_break[8]; 1.5 } scancode; 1.6 1.7 -static scancode scancode_set1[256] = 1.8 +/*272 = 256 + 16 fake interim scancodes for disambiguation purposes.*/ 1.9 +static scancode scancode_set1[272] = 1.10 { 1.11 { {-1}, {-1} }, { {0x01, -1}, {0x81, -1} }, { {0x02, -1}, {0x82, -1} }, { {0x03, -1}, {0x83, -1} }, 1.12 { {0x04, -1}, {0x84, -1} }, { {0x05, -1}, {0x85, -1} }, { {0x06, -1}, {0x86, -1} }, { {0x07, -1}, {0x87, -1} }, 1.13 @@ -45,42 +46,46 @@ 1.14 { {0x78, -1}, {0xf8, -1} }, { {0x79, -1}, {0xf9, -1} }, { {0x7a, -1}, {0xfa, -1} }, { {0x7b, -1}, {0xfb, -1} }, 1.15 { {0x7c, -1}, {0xfc, -1} }, { {0x7d, -1}, {0xfd, -1} }, { {0x7e, -1}, {0xfe, -1} }, { {0x7f, -1}, {0xff, -1} }, 1.16 1.17 - { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, /*80*/ 1.18 - { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, /*84*/ 1.19 - { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, /*88*/ 1.20 - { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, /*8c*/ 1.21 - { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, /*90*/ 1.22 - { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, /*94*/ 1.23 - { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, /*98*/ 1.24 - { {0xe0, 0x1c, -1}, {0xe0, 0x9c, -1} }, { {0xe0, 0x1d, -1}, {0xe0, 0x9d, -1} }, { {-1}, {-1} }, { {-1}, {-1} }, /*9c*/ 1.25 - { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, /*a0*/ 1.26 - { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, /*a4*/ 1.27 - { {-1}, {-1} }, { {-1}, {-1} }, { {0xe0, 0x2a, -1}, {0xe0, 0x8a, -1} }, { {-1}, {-1} }, /*a8*/ 1.28 - { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, /*ac*/ 1.29 - { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, /*b0*/ 1.30 - { {-1}, {-1} }, { {0xe0, 0x35, -1}, {0xe0, 0xb5, -1} }, { {0xe0, 0x36, -1}, {0xe0, 0xb6, -1} }, { {0xe0, 0x37, -1}, {0xe0, 0xb7, -1} }, /*b4*/ 1.31 - { {0xe0, 0x38, -1}, {0xe0, 0xb8, -1} }, { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, /*b8*/ 1.32 - { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, /*bc*/ 1.33 - { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, /*c0*/ 1.34 - { {-1}, {-1} }, { {-1}, {-1} }, { {0xe0, 0x46, -1}, {0xe0, 0xc6, -1} }, { {0xe0, 0x47, -1}, {0xe0, 0xc7, -1} }, /*c4*/ 1.35 + { {0x80, -1}, {-1} }, { {0x81, -1}, {-1} }, { {0x82, -1}, {-1} }, { {0xe0, 0x03, -1}, {0xe0, 0x83, -1} }, /*80*/ 1.36 + { {0xe0, 0x04, -1}, {0xe0, 0x84, -1} }, { {0x85, -1}, {-1} }, { {0x86, -1}, {-1} }, { {0x87, -1}, {-1} }, /*84*/ 1.37 + { {0xe0, 0x08, -1}, {0xe0, 0x88, -1} }, { {0xe0, 0x09, -1}, {0xe0, 0x89, -1} }, { {0xe0, 0x0a, -1}, {0xe0, 0x8a, -1} }, { {0xe0, 0x0b, -1}, {0xe0, 0x8b, -1} }, /*88*/ 1.38 + { {0xe0, 0x0c, -1}, {0xe0, 0x8c, -1} }, { {-1}, {-1} }, { {0xe0, 0x0e, -1}, {0xe0, 0x8e, -1} }, { {0xe0, 0x0f, -1}, {0xe0, 0x8f, -1} }, /*8c*/ 1.39 + { {0xe0, 0x10, -1}, {0xe0, 0x90, -1} }, { {0xe0, 0x11, -1}, {0xe0, 0x91, -1} }, { {0xe0, 0x12, -1}, {0xe0, 0x92, -1} }, { {0xe0, 0x13, -1}, {0xe0, 0x93, -1} }, /*90*/ 1.40 + { {0xe0, 0x14, -1}, {0xe0, 0x94, -1} }, { {0xe0, 0x15, -1}, {0xe0, 0x95, -1} }, { {0xe0, 0x16, -1}, {0xe0, 0x96, -1} }, { {0xe0, 0x17, -1}, {0xe0, 0x97, -1} }, /*94*/ 1.41 + { {0xe0, 0x18, -1}, {0xe0, 0x98, -1} }, { {0xe0, 0x19, -1}, {0xe0, 0x99, -1} }, { {0xe0, 0x1a, -1}, {0xe0, 0x9a, -1} }, { {0xe0, 0x1b, -1}, {0xe0, 0x9b, -1} }, /*98*/ 1.42 + { {0xe0, 0x1c, -1}, {0xe0, 0x9c, -1} }, { {0xe0, 0x1d, -1}, {0xe0, 0x9d, -1} }, { {0xe0, 0x1e, -1}, {0xe0, 0x9e, -1} }, { {0xe0, 0x1f, -1}, {0xe0, 0x9f, -1} }, /*9c*/ 1.43 + { {0xe0, 0x20, -1}, {0xe0, 0xa0, -1} }, { {0xe0, 0x21, -1}, {0xe0, 0xa1, -1} }, { {0xe0, 0x22, -1}, {0xe0, 0xa2, -1} }, { {0xe0, 0x23, -1}, {0xe0, 0xa3, -1} }, /*a0*/ 1.44 + { {0xe0, 0x24, -1}, {0xe0, 0xa4, -1} }, { {0xe0, 0x25, -1}, {0xe0, 0xa5, -1} }, { {0xe0, 0x26, -1}, {0xe0, 0xa6, -1} }, { {-1}, {-1} }, /*a4*/ 1.45 + { {-1}, {-1} }, { {-1}, {-1} }, { {0xe0, 0x2a, -1}, {0xe0, 0xaa, -1} }, { {-1}, {-1} }, /*a8*/ 1.46 + { {0xe0, 0x2c, -1}, {0xe0, 0xac, -1} }, { {0xe0, 0x2d, -1}, {0xe0, 0xad, -1} }, { {0xe0, 0x2e, -1}, {0xe0, 0xae, -1} }, { {0xe0, 0x2f, -1}, {0xe0, 0xaf, -1} }, /*ac*/ 1.47 + { {0xe0, 0x30, -1}, {0xe0, 0xb0, -1} }, { {0xe0, 0x31, -1}, {0xe0, 0xb1, -1} }, { {0xe0, 0x32, -1}, {0xe0, 0xb2, -1} }, { {-1}, {-1} }, /*b0*/ 1.48 + { {0xe0, 0x34, -1}, {0xe0, 0xb4, -1} }, { {0xe0, 0x35, -1}, {0xe0, 0xb5, -1} }, { {0xe0, 0x36, -1}, {0xe0, 0xb6, -1} }, { {0xe0, 0x37, -1}, {0xe0, 0xb7, -1} }, /*b4*/ 1.49 + { {0xe0, 0x38, -1}, {0xe0, 0xb8, -1} }, { {-1}, {-1} }, { {0xe0, 0x3a, -1}, {0xe0, 0xba, -1} }, { {0xe0, 0x3b, -1}, {0xe0, 0xbb, -1} }, /*b8*/ 1.50 + { {0xe0, 0x3c, -1}, {0xe0, 0xbc, -1} }, { {0xe0, 0x3d, -1}, {0xe0, 0xbd, -1} }, { {0xe0, 0x3e, -1}, {0xe0, 0xbe, -1} }, { {0xe0, 0x3f, -1}, {0xe0, 0xbf, -1} }, /*bc*/ 1.51 + { {0xe0, 0x40, -1}, {0xe0, 0xc0, -1} }, { {0xe0, 0x41, -1}, {0xe0, 0xc1, -1} }, { {0xe0, 0x42, -1}, {0xe0, 0xc2, -1} }, { {0xe0, 0x43, -1}, {0xe0, 0xc3, -1} }, /*c0*/ 1.52 + { {0xe0, 0x44, -1}, {0xe0, 0xc4, -1} }, { {-1}, {-1} }, { {0xe0, 0x46, -1}, {0xe0, 0xc6, -1} }, { {0xe0, 0x47, -1}, {0xe0, 0xc7, -1} }, /*c4*/ 1.53 { {0xe0, 0x48, -1}, {0xe0, 0xc8, -1} }, { {0xe0, 0x49, -1}, {0xe0, 0xc9, -1} }, { {-1}, {-1} }, { {0xe0, 0x4b, -1}, {0xe0, 0xcb, -1} }, /*c8*/ 1.54 - { {-1}, {-1} }, { {0xe0, 0x4d, -1}, {0xe0, 0xcd, -1} }, { {-1}, {-1} }, { {0xe0, 0x4f, -1}, {0xe0, 0xcf, -1} }, /*cc*/ 1.55 + { {0xe0, 0x4c, -1}, {0xe0, 0xcc, -1} }, { {0xe0, 0x4d, -1}, {0xe0, 0xcd, -1} }, { {0xe0, 0x4e, -1}, {0xe0, 0xce, -1} }, { {0xe0, 0x4f, -1}, {0xe0, 0xcf, -1} }, /*cc*/ 1.56 { {0xe0, 0x50, -1}, {0xe0, 0xd0, -1} }, { {0xe0, 0x51, -1}, {0xe0, 0xd1, -1} }, { {0xe0, 0x52, -1}, {0xe0, 0xd2, -1} }, { {0xe0, 0x53, -1}, {0xe0, 0xd3, -1} }, /*d0*/ 1.57 - { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, /*d4*/ 1.58 - { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, /*d8*/ 1.59 - { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, /*dc*/ 1.60 - { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, /*e0*/ 1.61 - { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, /*e4*/ 1.62 - { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, /*e8*/ 1.63 - { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, /*ec*/ 1.64 - { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, /*f0*/ 1.65 - { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, /*f4*/ 1.66 - { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, /*f8*/ 1.67 - { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, { {0xe1, 0x1d, 0x45, 0xe1, 0x9d, 0xc5, -1}, {-1} } /*fc*/ 1.68 + { {0xd4, -1}, {-1} }, { {0xe0, 0x55, -1}, {0xe0, 0xd5, -1} }, { {-1}, {-1} }, { {0xe0, 0x57, -1}, {0xe0, 0xd7, -1} }, /*d4*/ 1.69 + { {0xe0, 0x58, -1}, {0xe0, 0xd8, -1} }, { {0xe0, 0x59, -1}, {0xe0, 0xd9, -1} }, { {0xe0, 0x5a, -1}, {0xe0, 0xaa, -1} }, { {0xe0, 0x5b, -1}, {0xe0, 0xdb, -1} }, /*d8*/ 1.70 + { {0xe0, 0x5c, -1}, {0xe0, 0xdc, -1} }, { {0xe0, 0x5d, -1}, {0xe0, 0xdd, -1} }, { {0xe0, 0x5e, -1}, {0xe0, 0xee, -1} }, { {0xe0, 0x5f, -1}, {0xe0, 0xdf, -1} }, /*dc*/ 1.71 + { {-1}, {-1} }, { {0xe0, 0x61, -1}, {0xe0, 0xe1, -1} }, { {0xe0, 0x62, -1}, {0xe0, 0xe2, -1} }, { {0xe0, 0x63, -1}, {0xe0, 0xe3, -1} }, /*e0*/ 1.72 + { {0xe0, 0x64, -1}, {0xe0, 0xe4, -1} }, { {0xe0, 0x65, -1}, {0xe0, 0xe5, -1} }, { {0xe0, 0x66, -1}, {0xe0, 0xe6, -1} }, { {0xe0, 0x67, -1}, {0xe0, 0xe7, -1} }, /*e4*/ 1.73 + { {0xe0, 0x68, -1}, {0xe0, 0xe8, -1} }, { {0xe0, 0x69, -1}, {0xe0, 0xe9, -1} }, { {0xe0, 0x6a, -1}, {0xe0, 0xea, -1} }, { {0xe0, 0x6b, -1}, {0xe0, 0xeb, -1} }, /*e8*/ 1.74 + { {0xe0, 0x6c, -1}, {0xe0, 0xec, -1} }, { {0xe0, 0x6d, -1}, {0xe0, 0xed, -1} }, { {0xe0, 0x6e, -1}, {0xe0, 0xee, -1} }, { {-1}, {-1} }, /*ec*/ 1.75 + { {0xe0, 0x70, -1}, {0xe0, 0xf0, -1} }, { {0xf1, -1}, {-1} }, { {0xf2, -1}, {-1} }, { {0xe0, 0x73, -1}, {0xe0, 0xf3, -1} }, /*f0*/ 1.76 + { {0xe0, 0x74, -1}, {0xe0, 0xf4, -1} }, { {0xe0, 0x75, -1}, {0xe0, 0xf5, -1} }, { {-1}, {-1} }, { {0xe0, 0x77, -1}, {0xe0, 0xf7, -1} }, /*f4*/ 1.77 + { {0xe0, 0x78, -1}, {0xe0, 0xf8, -1} }, { {0xe0, 0x79, -1}, {0xe0, 0xf9, -1} }, { {0xe0, 0x7a, -1}, {0xe0, 0xfa, -1} }, { {0xe0, 0x7b, -1}, {0xe0, 0xfb, -1} }, /*f8*/ 1.78 + { {0xe0, 0x7c, -1}, {0xe0, 0xfc, -1} }, { {0xe0, 0x7d, -1}, {0xe0, 0xfd, -1} }, { {0xe0, 0x7e, -1}, {0xe0, 0xfe, -1} }, { {0xe1, 0x1d, 0x45, 0xe1, 0x9d, 0xc5, -1}, {-1} }, /*fc*/ 1.79 + { {-1}, {-1} }, { {0xe0, 0x01, -1}, {0xe0, 0x81, -1} }, { {0xe0, 0x02, -1}, {0xe0, 0x82, -1} }, { {-1}, {-1} }, /*100*/ 1.80 + { {-1}, {-1} }, { {0xe0, 0x05, -1}, {0xe0, 0x85, -1} }, { {0xe0, 0x06, -1}, {0xe0, 0x86, -1} }, { {0xe0, 0x07, -1}, {0xe0, 0x87, -1} }, /*104*/ 1.81 + { {0xe0, 0x71, -1}, {0xe0, 0xf1, -1} }, { {0xe0, 0x72, -1}, {0xe0, 0xf2, -1} }, { {0xe0, 0x7f, -1}, {0xe0, 0xff, -1} }, { {0xe0, 0xe1, -1}, {-1} }, /*108*/ 1.82 + { {0xe0, 0xee, -1}, {-1} }, { {0xe0, 0xf1, -1}, {-1} }, { {0xe0, 0xfe, -1}, {-1} }, { {0xe0, 0xff, -1}, {-1} } /*10c*/ 1.83 }; 1.84 1.85 /*XT keyboard has no escape scancodes, and no scancodes beyond 53*/ 1.86 -static scancode scancode_xt[256] = 1.87 +static scancode scancode_xt[272] = 1.88 { 1.89 { {-1}, {-1} }, { {0x01, -1}, {0x81, -1} }, { {0x02, -1}, {0x82, -1} }, { {0x03, -1}, {0x83, -1} }, 1.90 { {0x04, -1}, {0x84, -1} }, { {0x05, -1}, {0x85, -1} }, { {0x06, -1}, {0x86, -1} }, { {0x07, -1}, {0x87, -1} }, 1.91 @@ -125,7 +130,7 @@ 1.92 { {0x1c, -1}, {0x9c, -1} }, { {0x1d, -1}, {0x9d, -1} }, { {-1}, {-1} }, { {-1}, {-1} }, /*9c*/ 1.93 { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, /*a0*/ 1.94 { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, /*a4*/ 1.95 - { {-1}, {-1} }, { {-1}, {-1} }, { {0x2a, -1}, {0x8a, -1} }, { {-1}, {-1} }, /*a8*/ 1.96 + { {-1}, {-1} }, { {-1}, {-1} }, { {0x2a, -1}, {0xaa, -1} }, { {-1}, {-1} }, /*a8*/ 1.97 { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, /*ac*/ 1.98 { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, /*b0*/ 1.99 { {-1}, {-1} }, { {0x35, -1}, {0xb5, -1} }, { {0x36, -1}, {0xb6, -1} }, { {0x37, -1}, {0xb7, -1} }, /*b4*/ 1.100 @@ -147,10 +152,14 @@ 1.101 { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, /*f4*/ 1.102 { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, /*f8*/ 1.103 { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, /*fc*/ 1.104 + { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, /*100*/ 1.105 + { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, /*104*/ 1.106 + { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, /*108*/ 1.107 + { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, /*10c*/ 1.108 }; 1.109 1.110 /*Tandy keyboard has slightly different scancodes to XT*/ 1.111 -static scancode scancode_tandy[256] = 1.112 +static scancode scancode_tandy[272] = 1.113 { 1.114 { {-1}, {-1} }, { {0x01, -1}, {0x81, -1} }, { {0x02, -1}, {0x82, -1} }, { {0x03, -1}, {0x83, -1} }, 1.115 { {0x04, -1}, {0x84, -1} }, { {0x05, -1}, {0x85, -1} }, { {0x06, -1}, {0x86, -1} }, { {0x07, -1}, {0x87, -1} }, 1.116 @@ -195,7 +204,7 @@ 1.117 { {0x57, -1}, {0xd7, -1} }, { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, /*9c*/ 1.118 { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, /*a0*/ 1.119 { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, /*a4*/ 1.120 - { {-1}, {-1} }, { {-1}, {-1} }, { {0x2a, -1}, {0x8a, -1} }, { {-1}, {-1} }, /*a8*/ 1.121 + { {-1}, {-1} }, { {-1}, {-1} }, { {0x2a, -1}, {0xaa, -1} }, { {-1}, {-1} }, /*a8*/ 1.122 { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, /*ac*/ 1.123 { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, /*b0*/ 1.124 { {-1}, {-1} }, { {0x35, -1}, {0xb5, -1} }, { {0x36, -1}, {0xb6, -1} }, { {0x37, -1}, {0xb7, -1} }, /*b4*/ 1.125 @@ -217,9 +226,13 @@ 1.126 { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, /*f4*/ 1.127 { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, /*f8*/ 1.128 { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, /*fc*/ 1.129 + { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, /*100*/ 1.130 + { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, /*104*/ 1.131 + { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, /*108*/ 1.132 + { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, { {-1}, {-1} }, /*10c*/ 1.133 }; 1.134 -static int oldkey[256]; 1.135 -static int keydelay[256]; 1.136 +static int oldkey[272]; 1.137 +static int keydelay[272]; 1.138 1.139 void (*keyboard_send)(uint8_t val); 1.140 void (*keyboard_poll)(); 1.141 @@ -233,13 +246,13 @@ 1.142 if (!keyboard_scan) return; 1.143 if (TANDY) scancodes = scancode_tandy; 1.144 1.145 - for (c = 0; c < 256; c++) 1.146 + for (c = 0; c < 272; c++) 1.147 { 1.148 if (key[c]) keydelay[c]++; 1.149 else keydelay[c] = 0; 1.150 } 1.151 1.152 - for (c = 0; c < 256; c++) 1.153 + for (c = 0; c < 272; c++) 1.154 { 1.155 if (key[c] != oldkey[c]) 1.156 { 1.157 @@ -263,7 +276,7 @@ 1.158 } 1.159 } 1.160 1.161 - for (c = 0; c < 256; c++) 1.162 + for (c = 0; c < 272; c++) 1.163 { 1.164 if (keydelay[c] >= 30) 1.165 {
2.1 --- a/src/plat-keyboard.h Thu Jul 10 21:32:49 2014 +0100 2.2 +++ b/src/plat-keyboard.h Fri Jul 11 20:35:37 2014 +0100 2.3 @@ -4,8 +4,9 @@ 2.4 void keyboard_init(); 2.5 void keyboard_close(); 2.6 void keyboard_poll_host(); 2.7 - int key[256]; 2.8 - 2.9 + int key[272]; 2.10 + int rawinputkey[272]; 2.11 + 2.12 #define KEY_LCONTROL 0x1d 2.13 #define KEY_RCONTROL (0x1d | 0x80) 2.14 #define KEY_END (0x4f | 0x80) 2.15 @@ -13,3 +14,4 @@ 2.16 } 2.17 #endif 2.18 2.19 +
3.1 --- a/src/win-joystick.cc Thu Jul 10 21:32:49 2014 +0100 3.2 +++ b/src/win-joystick.cc Fri Jul 11 20:35:37 2014 +0100 3.3 @@ -1,7 +1,6 @@ 3.4 #define DIRECTINPUT_VERSION 0x0700 3.5 #include <dinput.h> 3.6 #include "plat-joystick.h" 3.7 -#include "plat-dinput.h" 3.8 #include "win.h" 3.9 3.10 extern "C" int video_fullscreen; 3.11 @@ -15,6 +14,7 @@ 3.12 3.13 joystick_t joystick_state[2]; 3.14 3.15 +static LPDIRECTINPUT lpdi; 3.16 static LPDIRECTINPUTDEVICE2 lpdi_joystick[2] = {NULL, NULL}; 3.17 3.18 int joysticks_present = 0; 3.19 @@ -43,6 +43,9 @@ 3.20 3.21 joysticks_present = 0; 3.22 3.23 + if (FAILED(DirectInputCreate(hinstance, DIRECTINPUT_VERSION, &lpdi, NULL))) 3.24 + fatal("joystick_init : DirectInputCreate failed\n"); 3.25 + 3.26 if (FAILED(lpdi->EnumDevices(DIDEVTYPE_JOYSTICK, joystick_enum_callback, NULL, DIEDFL_ATTACHEDONLY))) 3.27 fatal("joystick_init : EnumDevices failed\n"); 3.28 3.29 @@ -125,7 +128,7 @@ 3.30 joystick_state[c].b[2] = joystate.rgbButtons[2] & 0x80; 3.31 joystick_state[c].b[3] = joystate.rgbButtons[3] & 0x80; 3.32 3.33 - pclog("joystick %i - x=%i y=%i b[0]=%i b[1]=%i %i\n", c, joystick_state[c].x, joystick_state[c].y, joystick_state[c].b[0], joystick_state[c].b[1], joysticks_present); 3.34 +// pclog("joystick %i - x=%i y=%i b[0]=%i b[1]=%i %i\n", c, joystick_state[c].x, joystick_state[c].y, joystick_state[c].b[0], joystick_state[c].b[1], joysticks_present); 3.35 } 3.36 } 3.37
4.1 --- a/src/win-keyboard.cc Thu Jul 10 21:32:49 2014 +0100 4.2 +++ b/src/win-keyboard.cc Fri Jul 11 20:35:37 2014 +0100 4.3 @@ -1,16 +1,15 @@ 4.4 +#define UNICODE 4.5 #include <stdio.h> 4.6 #include <string.h> 4.7 #include <stdint.h> 4.8 -#define DIRECTINPUT_VERSION 0x0700 4.9 #define BITMAP WINDOWS_BITMAP 4.10 -#include <dinput.h> 4.11 +#include <windows.h> 4.12 #undef BITMAP 4.13 #include "plat-keyboard.h" 4.14 #include "win.h" 4.15 #include "video.h" 4.16 4.17 -extern "C" int key[256]; 4.18 -uint8_t dinput_key[256]; 4.19 +extern "C" int key[272]; 4.20 4.21 extern "C" void fatal(const char *format, ...); 4.22 extern "C" void pclog(const char *format, ...); 4.23 @@ -19,99 +18,28 @@ 4.24 extern "C" void keyboard_close(); 4.25 extern "C" void keyboard_poll(); 4.26 4.27 -LPDIRECTINPUT lpdi = NULL; 4.28 -LPDIRECTINPUTDEVICE lpdi_key = NULL; 4.29 - 4.30 -static int keyboard_lookup[256] = 4.31 -{ 4.32 - -1, DIK_ESCAPE, DIK_1, DIK_2, DIK_3, DIK_4, DIK_5, DIK_6, /*00*/ 4.33 - DIK_7, DIK_8, DIK_9, DIK_0, DIK_MINUS, DIK_EQUALS, DIK_BACKSPACE, DIK_TAB, /*08*/ 4.34 - DIK_Q, DIK_W, DIK_E, DIK_R, DIK_T, DIK_Y, DIK_U, DIK_I, /*10*/ 4.35 - DIK_O, DIK_P, DIK_LBRACKET, DIK_RBRACKET, DIK_RETURN, DIK_LCONTROL, DIK_A, DIK_S, /*18*/ 4.36 - DIK_D, DIK_F, DIK_G, DIK_H, DIK_J, DIK_K, DIK_L, DIK_SEMICOLON,/*20*/ 4.37 - DIK_APOSTROPHE, DIK_GRAVE, DIK_LSHIFT, DIK_BACKSLASH, DIK_Z, DIK_X, DIK_C, DIK_V, /*28*/ 4.38 - DIK_B, DIK_N, DIK_M, DIK_COMMA, DIK_PERIOD, DIK_SLASH, DIK_RSHIFT, DIK_MULTIPLY, /*30*/ 4.39 - DIK_LMENU, DIK_SPACE, DIK_CAPSLOCK, DIK_F1, DIK_F2, DIK_F3, DIK_F4, DIK_F5, /*38*/ 4.40 - DIK_F6, DIK_F7, DIK_F8, DIK_F9, DIK_F10, DIK_NUMLOCK, DIK_SCROLL, DIK_NUMPAD7, /*40*/ 4.41 - DIK_NUMPAD8, DIK_NUMPAD9, DIK_NUMPADMINUS, DIK_NUMPAD4, DIK_NUMPAD5, DIK_NUMPAD6, DIK_NUMPADPLUS, DIK_NUMPAD1, /*48*/ 4.42 - DIK_NUMPAD2, DIK_NUMPAD3, DIK_NUMPAD0, DIK_DECIMAL, DIK_SYSRQ, -1, DIK_OEM_102, DIK_F11, /*50*/ 4.43 - DIK_F12, -1, -1, DIK_LWIN, DIK_RWIN, DIK_LMENU, -1, -1, /*58*/ 4.44 - -1, -1, -1, -1, -1, -1, -1, -1, /*60*/ 4.45 - -1, -1, -1, -1, -1, -1, -1, -1, /*68*/ 4.46 - -1, -1, -1, -1, -1, -1, -1, -1, /*70*/ 4.47 - -1, -1, -1, -1, -1, -1, -1, -1, /*78*/ 4.48 - 4.49 - -1, -1, -1, -1, -1, -1, -1, -1, /*80*/ 4.50 - -1, -1, -1, -1, -1, -1, -1, -1, /*88*/ 4.51 - -1, -1, -1, -1, -1, -1, -1, -1, /*90*/ 4.52 - -1, -1, -1, -1, DIK_NUMPADENTER, DIK_RCONTROL, -1, -1, /*98*/ 4.53 - -1, -1, -1, -1, -1, -1, -1, -1, /*a0*/ 4.54 - -1, -1, -1, -1, -1, -1, -1, -1, /*a8*/ 4.55 - -1, -1, -1, -1, -1, -1, -1, -1, /*b0*/ 4.56 - DIK_RMENU, -1, -1, -1, -1, -1, -1, -1, /*b8*/ 4.57 - -1, -1, -1, -1, -1, -1, -1, DIK_HOME, /*c0*/ 4.58 - DIK_UP, DIK_PRIOR, -1, DIK_LEFT, -1, DIK_RIGHT, -1, DIK_END, /*c8*/ 4.59 - DIK_DOWN, DIK_NEXT, DIK_INSERT, DIK_DELETE, -1, -1, -1, -1, /*d0*/ 4.60 - -1, -1, -1, -1, -1, -1, -1, -1, /*d8*/ 4.61 - -1, -1, -1, -1, -1, -1, -1, -1, /*e0*/ 4.62 - -1, -1, -1, -1, -1, -1, -1, -1, /*e8*/ 4.63 - -1, -1, -1, -1, -1, -1, -1, -1, /*f0*/ 4.64 - -1, -1, -1, -1, -1, -1, -1, DIK_PAUSE, /*f8*/ 4.65 - 4.66 -}; 4.67 - 4.68 void keyboard_init() 4.69 { 4.70 atexit(keyboard_close); 4.71 4.72 - if (FAILED(DirectInputCreate(hinstance, DIRECTINPUT_VERSION, &lpdi, NULL))) 4.73 - fatal("install_keyboard : DirectInputCreate failed\n"); 4.74 - if (FAILED(lpdi->CreateDevice(GUID_SysKeyboard, &lpdi_key, NULL))) 4.75 - fatal("install_keyboard : CreateDevice failed\n"); 4.76 - if (FAILED(lpdi_key->SetCooperativeLevel(ghwnd, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE))) 4.77 - fatal("install_keyboard : SetCooperativeLevel failed\n"); 4.78 - if (FAILED(lpdi_key->SetDataFormat(&c_dfDIKeyboard))) 4.79 - fatal("install_keyboard : SetDataFormat failed\n"); 4.80 - if (FAILED(lpdi_key->Acquire())) 4.81 - fatal("install_keyboard : Acquire failed\n"); 4.82 - 4.83 memset(key, 0, sizeof(key)); 4.84 + pclog("Keyboard initialized!\n"); 4.85 } 4.86 4.87 void keyboard_close() 4.88 { 4.89 - if (lpdi_key) 4.90 - { 4.91 - lpdi_key->Release(); 4.92 - lpdi_key = NULL; 4.93 - } 4.94 - if (lpdi) 4.95 - { 4.96 - lpdi->Release(); 4.97 - lpdi = NULL; 4.98 - } 4.99 } 4.100 4.101 void keyboard_poll_host() 4.102 { 4.103 int c; 4.104 - if (FAILED(lpdi_key->GetDeviceState(256, (LPVOID)dinput_key))) 4.105 - { 4.106 - lpdi_key->Acquire(); 4.107 - lpdi_key->GetDeviceState(256, (LPVOID)dinput_key); 4.108 - } 4.109 - for (c = 0; c < 256; c++) 4.110 - { 4.111 -// if (dinput_key[c] & 0x80) pclog("Dinput key down %i %02X\n", c, c); 4.112 - if (keyboard_lookup[c] != -1) 4.113 - { 4.114 - key[c] = dinput_key[keyboard_lookup[c]] & 0x80; 4.115 -// if (key[c]) pclog("Key down %i %02X %i %02X\n", c, c, keyboard_lookup[c], keyboard_lookup[c]); 4.116 - } 4.117 - } 4.118 - if (((dinput_key[DIK_LCONTROL] | dinput_key[DIK_RCONTROL]) & 0x80) && 4.119 - ((dinput_key[DIK_LMENU] | dinput_key[DIK_RMENU]) & 0x80) && 4.120 - (dinput_key[DIK_NEXT] & 0x80) && 4.121 - video_fullscreen) 4.122 - leave_fullscreen(); 4.123 + 4.124 + for (c = 0; c < 272; c++) 4.125 + key[c] = rawinputkey[c]; 4.126 + 4.127 + if ((rawinputkey[0x1D] || rawinputkey[0x9D]) && 4.128 + (rawinputkey[0x38] || rawinputkey[0xB8]) && 4.129 + (rawinputkey[0x51] || rawinputkey[0xD1]) && 4.130 + video_fullscreen) 4.131 + leave_fullscreen(); 4.132 }
5.1 --- a/src/win-mouse.cc Thu Jul 10 21:32:49 2014 +0100 5.2 +++ b/src/win-mouse.cc Fri Jul 11 20:35:37 2014 +0100 5.3 @@ -1,6 +1,6 @@ 5.4 +#define DIRECTINPUT_VERSION 0x0700 5.5 #include <dinput.h> 5.6 #include "plat-mouse.h" 5.7 -#include "plat-dinput.h" 5.8 #include "win.h" 5.9 5.10 extern "C" int video_fullscreen; 5.11 @@ -14,6 +14,7 @@ 5.12 extern "C" void position_mouse(int x, int y); 5.13 extern "C" void get_mouse_mickeys(int *x, int *y); 5.14 5.15 +static LPDIRECTINPUT lpdi; 5.16 static LPDIRECTINPUTDEVICE lpdi_mouse = NULL; 5.17 static DIMOUSESTATE mousestate; 5.18 static int mouse_x = 0, mouse_y = 0; 5.19 @@ -23,6 +24,8 @@ 5.20 { 5.21 atexit(mouse_close); 5.22 5.23 + if (FAILED(DirectInputCreate(hinstance, DIRECTINPUT_VERSION, &lpdi, NULL))) 5.24 + fatal("mouse_init : DirectInputCreate failed\n"); 5.25 if (FAILED(lpdi->CreateDevice(GUID_SysMouse, &lpdi_mouse, NULL))) 5.26 fatal("mouse_init : CreateDevice failed\n"); 5.27 if (FAILED(lpdi_mouse->SetCooperativeLevel(ghwnd, DISCL_FOREGROUND | (video_fullscreen ? DISCL_EXCLUSIVE : DISCL_NONEXCLUSIVE))))
6.1 --- a/src/win.c Thu Jul 10 21:32:49 2014 +0100 6.2 +++ b/src/win.c Fri Jul 11 20:35:37 2014 +0100 6.3 @@ -1,3 +1,4 @@ 6.4 +#define _WIN32_WINNT 0x0501 6.5 #define BITMAP WINDOWS_BITMAP 6.6 #include <windows.h> 6.7 #include <windowsx.h> 6.8 @@ -31,8 +32,15 @@ 6.9 #include "win-d3d-fs.h" 6.10 //#include "win-opengl.h" 6.11 6.12 +#ifndef MAPVK_VK_TO_VSC 6.13 +#define MAPVK_VK_TO_VSC 0 6.14 +#endif 6.15 + 6.16 uint64_t timer_freq; 6.17 6.18 +static RAWINPUTDEVICE device; 6.19 +static uint16_t scancode_map[65536]; 6.20 + 6.21 static struct 6.22 { 6.23 void (*init)(HWND h); 6.24 @@ -215,6 +223,95 @@ 6.25 return qpc_time.QuadPart; 6.26 } 6.27 6.28 +/* This is so we can disambiguate scan codes that would otherwise conflict and get 6.29 + passed on incorrectly. */ 6.30 +UINT16 convert_scan_code(UINT16 scan_code) 6.31 +{ 6.32 + switch (scan_code) 6.33 + { 6.34 + case 0xE001: 6.35 + return 0xF001; 6.36 + case 0xE002: 6.37 + return 0xF002; 6.38 + case 0xE005: 6.39 + return 0xF005; 6.40 + case 0xE006: 6.41 + return 0xF006; 6.42 + case 0xE007: 6.43 + return 0xF007; 6.44 + case 0xE071: 6.45 + return 0xF008; 6.46 + case 0xE072: 6.47 + return 0xF009; 6.48 + case 0xE07F: 6.49 + return 0xF00A; 6.50 + case 0xE0E1: 6.51 + return 0xF00B; 6.52 + case 0xE0EE: 6.53 + return 0xF00C; 6.54 + case 0xE0F1: 6.55 + return 0xF00D; 6.56 + case 0xE0FE: 6.57 + return 0xF00E; 6.58 + case 0xE0EF: 6.59 + return 0xF00F; 6.60 + 6.61 + default: 6.62 + return scan_code; 6.63 + } 6.64 +} 6.65 + 6.66 +void get_registry_key_map() 6.67 +{ 6.68 + char *keyName = "SYSTEM\\CurrentControlSet\\Control\\Keyboard Layout"; 6.69 + char *valueName = "Scancode Map"; 6.70 + char buf[32768]; 6.71 + DWORD bufSize; 6.72 + HKEY hKey; 6.73 + int j; 6.74 + 6.75 + /* First, prepare the default scan code map list which is 1:1. 6.76 + Remappings will be inserted directly into it. 6.77 + 65536 bytes so scan codes fit in easily and it's easy to find what each maps too, 6.78 + since each array element is a scan code and provides for E0, etc. ones too. */ 6.79 + for (j = 0; j < 65536; j++) 6.80 + scancode_map[j] = convert_scan_code(j); 6.81 + 6.82 + bufSize = 32768; 6.83 + pclog("Preparing scan code map list...\n"); 6.84 + /* Get the scan code remappings from: 6.85 + HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout */ 6.86 + if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, keyName, 0, 1, &hKey) == ERROR_SUCCESS) 6.87 + { 6.88 + if(RegQueryValueEx(hKey, valueName, NULL, NULL, buf, &bufSize) == ERROR_SUCCESS) 6.89 + { 6.90 + UINT32 *bufEx2 = (UINT32 *) buf; 6.91 + int scMapCount = bufEx2[2]; 6.92 + pclog("%lu scan code mappings found!\n", scMapCount); 6.93 + if ((bufSize != 0) && (scMapCount != 0)) 6.94 + { 6.95 + UINT16 *bufEx = (UINT16 *) (buf + 12); 6.96 + pclog("More than zero scan code mappings found, processing...\n"); 6.97 + for (j = 0; j < scMapCount*2; j += 2) 6.98 + { 6.99 + /* Each scan code is 32-bit: 16 bits of remapped scan code, 6.100 + and 16 bits of original scan code. */ 6.101 + int scancode_unmapped = bufEx[j + 1]; 6.102 + int scancode_mapped = bufEx[j]; 6.103 + 6.104 + scancode_mapped = convert_scan_code(scancode_mapped); 6.105 + 6.106 + scancode_map[scancode_unmapped] = scancode_mapped; 6.107 + pclog("Scan code mapping %u detected: %X -> %X\n", scancode_unmapped, scancode_mapped, scancode_map[scancode_unmapped]); 6.108 + } 6.109 + pclog("Done processing!\n"); 6.110 + } 6.111 + } 6.112 + RegCloseKey(hKey); 6.113 + } 6.114 + pclog("Done preparing!\n"); 6.115 +} 6.116 + 6.117 int WINAPI WinMain (HINSTANCE hThisInstance, 6.118 HINSTANCE hPrevInstance, 6.119 LPSTR lpszArgument, 6.120 @@ -279,6 +376,19 @@ 6.121 6.122 // win_set_window(hwnd); 6.123 6.124 + memset(rawinputkey, 0, sizeof(rawinputkey)); 6.125 + device.usUsagePage = 0x01; 6.126 + device.usUsage = 0x06; 6.127 + device.dwFlags = RIDEV_NOLEGACY; 6.128 + device.hwndTarget = hwnd; 6.129 + 6.130 + if (RegisterRawInputDevices(&device, 1, sizeof(device))) 6.131 + pclog("Raw input registered!\n"); 6.132 + else 6.133 + pclog("Raw input registration failed!\n"); 6.134 + 6.135 + get_registry_key_map(); 6.136 + 6.137 ghwnd=hwnd; 6.138 6.139 midi_init(); 6.140 @@ -729,6 +839,56 @@ 6.141 } 6.142 return 0; 6.143 6.144 + case WM_INPUT: 6.145 + { 6.146 + UINT size; 6.147 + RAWINPUT *raw; 6.148 + 6.149 + GetRawInputData((HRAWINPUT)lParam, RID_INPUT, NULL, &size, sizeof(RAWINPUTHEADER)); 6.150 + 6.151 + raw = malloc(size); 6.152 + 6.153 + /* Here we read the raw input data for the keyboard */ 6.154 + GetRawInputData((HRAWINPUT)(lParam), RID_INPUT, raw, &size, sizeof(RAWINPUTHEADER)); 6.155 + 6.156 + /* If the input is keyboard, we process it */ 6.157 + if (raw->header.dwType == RIM_TYPEKEYBOARD) 6.158 + { 6.159 + const RAWKEYBOARD rawKB = raw->data.keyboard; 6.160 + USHORT scancode = rawKB.MakeCode; 6.161 + 6.162 + // pclog("Keyboard input received: S:%X VK:%X F:%X\n", c, d, e); 6.163 + 6.164 + if (rawKB.VKey == VK_NUMLOCK) 6.165 + { 6.166 + /* This is for proper handling of Pause/Break and Num Lock */ 6.167 + scancode = (MapVirtualKey(rawKB.VKey, MAPVK_VK_TO_VSC) | 0x100); 6.168 + } 6.169 + /* If it's not a scan code that starts with 0xE1 */ 6.170 + if (!(rawKB.Flags & RI_KEY_E1)) 6.171 + { 6.172 + if (rawKB.Flags & RI_KEY_E0) 6.173 + scancode |= (0xE0 << 8); 6.174 + 6.175 + /* Remap it according to the list from the Registry */ 6.176 + scancode = scancode_map[scancode]; 6.177 + 6.178 + if ((scancode >> 8) == 0xF0) 6.179 + scancode |= 0x100; /* Extended key code in disambiguated format */ 6.180 + else if ((scancode >> 8) == 0xE0) 6.181 + scancode |= 0x80; /* Normal extended key code */ 6.182 + 6.183 + /* If it's not 0 (therefore not 0xE1, 0xE2, etc), 6.184 + then pass it on to the rawinputkey array */ 6.185 + if (!(scancode & 0xf00)) 6.186 + rawinputkey[scancode & 0x1ff] = !(rawKB.Flags & RI_KEY_BREAK); 6.187 + } 6.188 + } 6.189 + free(raw); 6.190 + 6.191 + } 6.192 + break; 6.193 + 6.194 case WM_SETFOCUS: 6.195 infocus=1; 6.196 // QueryPerformanceCounter(&counter_posold);
