3 screen driver for win32
5 Made by Studio Breeze. 2002
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software and associated documentation files (the "Software"), to deal
9 in the Software without restriction, including without limitation the rights
10 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 copies of the Software, and to permit persons to whom the Software is
12 furnished to do so, subject to the following conditions:
14 The above copyright notice and this permission notice shall be included in
15 all copies or substantial portions of the Software.
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27 #include "sted_screen_win32.h"
29 // nofitication from main window
31 CSTedScreenWin32::NotifyKeyPressed(int in_key)
33 fKeyEventNotified = TRUE;
35 if (in_key == fKeyConv[EShift])
36 fKeyShiftPressed = TRUE;
37 else if (in_key == fKeyConv[EControl])
38 fKeyControlPressed = TRUE;
39 else if (in_key == fKeyConv[EOPT1])
40 fKeyOPT1Pressed = TRUE;
41 else if (in_key == fKeyConv[EOPT2])
42 fKeyOPT2Pressed = TRUE;
43 else if (in_key == fKeyConv[EKana])
44 fKeyKanaPressed = TRUE;
45 else if (in_key == fKeyConv[EInsert])
46 fKeyInsertPressed = TRUE;
75 case 0xd8: // for Kigo
76 case 0xd9: // for Toroku
77 fKeyBuffer[fKeyBufferEndPtr] = (in_key | 0x100);
78 fKeyBufferEndPtr = (fKeyBufferEndPtr+1)%fKeyBufferLen;
79 if (fKeyBufferEndPtr==fKeyBufferStartPtr) {
80 fKeyBufferStartPtr = (fKeyBufferStartPtr+1)%fKeyBufferLen;
82 fKeyBufferAvailable++;
83 if (fKeyBufferAvailable>=fKeyBufferLen) {
84 fKeyBufferAvailable = fKeyBufferLen;
88 fKeyEventNotified = FALSE;
95 CSTedScreenWin32::NotifyKeyReleased(int in_key)
97 fKeyEventNotified = TRUE;
99 if (in_key == fKeyConv[EShift])
100 fKeyShiftPressed = FALSE;
101 else if (in_key == fKeyConv[EControl])
102 fKeyControlPressed = FALSE;
103 else if (in_key == fKeyConv[EOPT1])
104 fKeyOPT1Pressed = FALSE;
105 else if (in_key == fKeyConv[EOPT2])
106 fKeyOPT2Pressed = FALSE;
107 else if (in_key == fKeyConv[EKana])
108 fKeyKanaPressed = FALSE;
109 else if (in_key == fKeyConv[EInsert])
110 fKeyInsertPressed = FALSE;
114 CSTedScreenWin32::NotifyChar(int in_char)
118 unsigned char str[6];
121 fKeyEventNotified = TRUE;
127 len = ::WideCharToMultiByte(932, 0, (LPCWSTR)buf, 1, (LPSTR)str, 6, NULL, NULL);
130 str[0] = (unsigned char)in_char;
135 fKeyBuffer[fKeyBufferEndPtr] = str[ptr++];
136 fKeyBufferEndPtr = (fKeyBufferEndPtr+1)%fKeyBufferLen;
137 if (fKeyBufferEndPtr==fKeyBufferStartPtr) {
138 fKeyBufferStartPtr = (fKeyBufferStartPtr+1)%fKeyBufferLen;
140 fKeyBufferAvailable++;
141 if (fKeyBufferAvailable>=fKeyBufferLen) {
142 fKeyBufferAvailable = fKeyBufferLen;
150 CSTedScreenWin32::KeyInit(void)
152 fKeyBufferStartPtr = 0;
153 fKeyBufferEndPtr = 0;
154 fKeyBufferAvailable = 0;
156 fKeyShiftPressed = FALSE;
157 fKeyControlPressed = FALSE;
158 fKeyOPT1Pressed = FALSE;
159 fKeyOPT2Pressed = FALSE;
160 fKeyKanaPressed = FALSE;
161 fKeyInsertPressed = FALSE;
163 fKeyEventNotified = FALSE;
165 // default configuration for IBM-106
167 fKeyConv[EShift] = VK_SHIFT;
168 fKeyConv[EControl] = VK_CONTROL;
169 fKeyConv[EOPT1] = VK_F11;
170 fKeyConv[EOPT2] = VK_F12;
171 fKeyConv[EXF1] = VK_LMENU;
172 fKeyConv[EXF2] = VK_NONCONVERT;
173 fKeyConv[EXF3] = VK_CONVERT;
174 fKeyConv[EXF4] = VK_KANA;
175 fKeyConv[EXF5] = VK_RMENU;
176 fKeyConv[EKana] = VK_LCONTROL;
177 fKeyConv[EKigo] = 0xd8; // unassigned
178 fKeyConv[EToroku] = 0xd9; // unassigned
179 fKeyConv[EInsert] = VK_INSERT;
180 fKeyConv[EDel] = VK_DELETE;
181 fKeyConv[EHome] = VK_HOME;
182 fKeyConv[EUndo] = VK_END;
183 fKeyConv[ERollUp] = VK_PRIOR;
184 fKeyConv[ERollDown] = VK_NEXT;
185 fKeyConv[EF1] = VK_F1;
186 fKeyConv[EF2] = VK_F2;
187 fKeyConv[EF3] = VK_F3;
188 fKeyConv[EF4] = VK_F4;
189 fKeyConv[EF5] = VK_F5;
190 fKeyConv[EF6] = VK_F6;
191 fKeyConv[EF7] = VK_F7;
192 fKeyConv[EF8] = VK_F8;
193 fKeyConv[EF9] = VK_F9;
194 fKeyConv[EF10] = VK_F10;
201 CSTedScreenWin32::KeyIn(int in_code)
207 if (fKeyBufferAvailable<=0) return 0;
209 key = fKeyBuffer[fKeyBufferStartPtr];
210 result = ConvertWinKeyToX68Key(key);
213 fKeyBufferAvailable--;
214 fKeyBufferStartPtr = (fKeyBufferStartPtr+1)%fKeyBufferLen;
220 fKeyBufferAvailable--;
221 fKeyBufferStartPtr = (fKeyBufferStartPtr+1)%fKeyBufferLen;
230 CSTedScreenWin32::KeyInp(void)
238 if (!fKeyEventNotified)
242 fKeyEventNotified = FALSE;
243 } while(fKeyBufferAvailable <= 0);
245 key = fKeyBuffer[fKeyBufferStartPtr];
246 result = ConvertWinKeyToX68Key(key, &ascii, &code);
248 fKeyBufferAvailable--;
249 fKeyBufferStartPtr = (fKeyBufferStartPtr+1)%fKeyBufferLen;
250 if (fKeyBufferAvailable>0)
251 fKeyEventNotified = TRUE;
255 fKeyBufferAvailable--;
256 fKeyBufferStartPtr = (fKeyBufferStartPtr+1)%fKeyBufferLen;
257 if (fKeyBufferAvailable>0) fKeyEventNotified = TRUE;
259 return (ascii | code<<8);
263 CSTedScreenWin32::SftSense(void)
267 if (fKeyShiftPressed) ret|=1;
268 if (fKeyControlPressed) ret|=2;
269 if (fKeyOPT1Pressed) ret|=4;
270 if (fKeyOPT2Pressed) ret|=8;
271 if (fKeyKanaPressed) ret|=16+256;
272 if (fKeyInsertPressed) ret|=4096;
274 if (!(::GetKeyState(VK_SHIFT)&0xff00)) {
275 fKeyShiftPressed = FALSE;
282 CSTedScreenWin32::CheckKeyBuffer(int in_key)
285 val = ::GetKeyState(in_key);
286 if (val&0xff00) return TRUE;
291 CSTedScreenWin32::BitSense(int in_group)
295 switch ( in_group ) {
297 if (CheckKeyBuffer('1')) ret|=4;
298 if (CheckKeyBuffer('2')) ret|=8;
299 if (CheckKeyBuffer('3')) ret|=16;
300 if (CheckKeyBuffer('4')) ret|=32;
301 if (CheckKeyBuffer('5')) ret|=64;
302 if (CheckKeyBuffer('6')) ret|=128;
306 if (CheckKeyBuffer('7')) ret|=1;
307 if (CheckKeyBuffer('8')) ret|=2;
308 if (CheckKeyBuffer('9')) ret|=4;
309 if (CheckKeyBuffer('0')) ret|=8;
310 if (CheckKeyBuffer('-')) ret|=16;
311 if (CheckKeyBuffer('^')) ret|=32;
312 if (CheckKeyBuffer('\\')) ret|=64;
313 if (CheckKeyBuffer(VK_BACK)) ret|=128;
317 if (CheckKeyBuffer(VK_TAB)) ret|=1;
318 if (CheckKeyBuffer('Q')) ret|=2;
319 if (CheckKeyBuffer('W')) ret|=4;
320 if (CheckKeyBuffer('E')) ret|=8;
321 if (CheckKeyBuffer('R')) ret|=16;
322 if (CheckKeyBuffer('T')) ret|=32;
323 if (CheckKeyBuffer('Y')) ret|=64;
324 if (CheckKeyBuffer('U')) ret|=128;
328 if (CheckKeyBuffer('I')) ret|=1;
329 if (CheckKeyBuffer('O')) ret|=2;
330 if (CheckKeyBuffer('P')) ret|=4;
331 if (CheckKeyBuffer('@')) ret|=8;
332 if (CheckKeyBuffer('[')) ret|=16;
333 if (CheckKeyBuffer(VK_RETURN)) ret|=32;
334 if (CheckKeyBuffer('A')) ret|=64;
335 if (CheckKeyBuffer('S')) ret|=128;
339 if (CheckKeyBuffer('D')) ret|=1;
340 if (CheckKeyBuffer('F')) ret|=2;
341 if (CheckKeyBuffer('G')) ret|=4;
342 if (CheckKeyBuffer('H')) ret|=8;
343 if (CheckKeyBuffer('J')) ret|=16;
344 if (CheckKeyBuffer('K')) ret|=32;
345 if (CheckKeyBuffer('L')) ret|=64;
346 if (CheckKeyBuffer(';')) ret|=128;
350 if (CheckKeyBuffer(':')) ret|=1;
351 if (CheckKeyBuffer(']')) ret|=2;
352 if (CheckKeyBuffer('Z')) ret|=4;
353 if (CheckKeyBuffer('X')) ret|=8;
354 if (CheckKeyBuffer('C')) ret|=16;
355 if (CheckKeyBuffer('V')) ret|=32;
356 if (CheckKeyBuffer('B')) ret|=64;
357 if (CheckKeyBuffer('N')) ret|=128;
361 if (CheckKeyBuffer('M')) ret|=1;
362 if (CheckKeyBuffer(',')) ret|=2;
363 if (CheckKeyBuffer('.')) ret|=4;
364 if (CheckKeyBuffer('/')) ret|=8;
365 if (CheckKeyBuffer('\\')) ret|=16;
366 if (CheckKeyBuffer(' ')) ret|=32;
369 case 7: /* R_UP,R_DOWN, Cursors */
370 if (CheckKeyBuffer(VK_PRIOR)) ret|=1;
371 if (CheckKeyBuffer(VK_NEXT)) ret|=2;
372 if (CheckKeyBuffer(VK_END)) ret|=4;
373 if (CheckKeyBuffer(VK_LEFT)) ret|=8;
374 if (CheckKeyBuffer(VK_UP)) ret|=16;
375 if (CheckKeyBuffer(VK_RIGHT)) ret|=32;
376 if (CheckKeyBuffer(VK_DOWN)) ret|=64;
379 case 0x0a: /* XF1-XF3 */
380 if (check_keycode(k_xf1 , key_buffer)) ret|=32;
381 if (check_keycode(k_xf2 , key_buffer)) ret|=64;
382 if (check_keycode(k_xf3 , key_buffer)) ret|=128;
385 case 0x0b: /* XF4-XF5 */
386 if (check_keycode(k_xf4 , key_buffer)) ret|=1;
387 if (check_keycode(k_xf5 , key_buffer)) ret|=2;
390 case 0x0c: /* F0-F4 */
391 if (CheckKeyBuffer(VK_F1)) ret|=8;
392 if (CheckKeyBuffer(VK_F2)) ret|=16;
393 if (CheckKeyBuffer(VK_F3)) ret|=32;
394 if (CheckKeyBuffer(VK_F4)) ret|=64;
395 if (CheckKeyBuffer(VK_F5)) ret|=128;
398 case 0x0d: /* F5-F9 */
399 if (CheckKeyBuffer(VK_F6)) ret|=1;
400 if (CheckKeyBuffer(VK_F7)) ret|=2;
401 if (CheckKeyBuffer(VK_F8)) ret|=4;
402 if (CheckKeyBuffer(VK_F9)) ret|=8;
403 if (CheckKeyBuffer(VK_F10)) ret|=16;
406 case 0x0e: /* OPT.1-OPT.2 */
407 if (CheckKeyBuffer(VK_F11)) ret|=4;
408 if (CheckKeyBuffer(VK_F12)) ret|=8;
419 CSTedScreenWin32::KeySense(void)
421 if (fKeyBufferAvailable==0) return 0;
426 CSTedScreenWin32::KeyWait(void)
428 while (!fKeyEventNotified && fKeyBufferAvailable==0) {
431 fKeyEventNotified = FALSE;
435 CSTedScreenWin32::LedMode(int in_code, int in_onoff)
440 CSTedScreenWin32::ClearKeyBuffer(void)
442 fKeyBufferAvailable = 0;
443 fKeyBufferStartPtr = 0;
444 fKeyBufferEndPtr = 0;
449 CSTedScreenWin32::ConvertWinKeyToX68Key(int in_winkey)
453 if (in_winkey<0x100) { // char
460 result = fFncKey[4][0];
463 result = fFncKey[7][0];
466 result = fFncKey[5][0];
469 result = fFncKey[6][0];
475 if (in_winkey == fKeyConv[EHome])
476 result = fFncKey[10][0];
477 else if (in_winkey == fKeyConv[EUndo])
478 result = fFncKey[11][0];
479 else if (in_winkey == fKeyConv[EDel])
480 result = fFncKey[3][0];
481 else if (in_winkey == fKeyConv[EInsert])
482 result = fFncKey[2][0];
483 else if (in_winkey == fKeyConv[ERollDown])
484 result = fFncKey[0][0];
485 else if (in_winkey == fKeyConv[ERollUp])
486 result = fFncKey[1][0];
497 CSTedScreenWin32::ConvertWinKeyToX68Key(int in_winkey, int* out_ascii, int* out_code)
502 if (in_winkey<0x100) {
503 if (in_winkey>=0x20 && in_winkey<=0x7f) {
504 code = fX68ScanCode[in_winkey-0x20];
507 case 0x1b: code = 0x01;break;
508 case 0x0d: code = 0x1d;break;
509 case 0x09: code = 0x10;break;
510 default: code = 0; break;
513 if (out_ascii) *out_ascii = in_winkey;
514 if (out_code) *out_code = code;
522 ascii=0; code=0x3c; break;
525 ascii=0; code=0x3e; break;
528 ascii=0; code=0x3b; break;
531 ascii=0; code=0x3d; break;
534 ascii=0; code=0x0f; break;
537 ascii=0x0d; code=0x1d; break;
540 ascii=0x1b; code=0x01; break;
543 ascii=0x09; code=0x10; break;
547 ascii=0x00; code=fKeyShiftPressed?0x70:0xf0; break;
550 ascii=0x00; code=fKeyControlPressed?0x71:0xf1; break;
553 if (in_winkey == fKeyConv[EF1]) {
554 ascii=0x00; code=0x63;
555 } else if (in_winkey == fKeyConv[EF2]) {
556 ascii=0x00; code=0x64;
557 } else if (in_winkey == fKeyConv[EF3]) {
558 ascii=0x00; code=0x65;
559 } else if (in_winkey == fKeyConv[EF4]) {
560 ascii=0x00; code=0x66;
561 } else if (in_winkey == fKeyConv[EF5]) {
562 ascii=0x00; code=0x67;
563 } else if (in_winkey == fKeyConv[EF6]) {
564 ascii=0x00; code=0x68;
565 } else if (in_winkey == fKeyConv[EF7]) {
566 ascii=0x00; code=0x69;
567 } else if (in_winkey == fKeyConv[EF8]) {
568 ascii=0x00; code=0x6a;
569 } else if (in_winkey == fKeyConv[EF9]) {
570 ascii=0x00; code=0x6b;
571 } else if (in_winkey == fKeyConv[EF10]) {
572 ascii=0x00; code=0x6c;
574 } else if (in_winkey == fKeyConv[EKigo]) {
575 ascii=0x00; code=0x52;
576 } else if (in_winkey == fKeyConv[EToroku]) {
577 ascii=0x00; code=0x53;
579 } else if (in_winkey == fKeyConv[EXF1]) {
580 ascii=0x00; code=0x55;
581 } else if (in_winkey == fKeyConv[EXF2]) {
582 ascii=0x00; code=0x56;
583 } else if (in_winkey == fKeyConv[EXF3]) {
584 ascii=0x00; code=0x57;
585 } else if (in_winkey == fKeyConv[EXF4]) {
586 ascii=0x00; code=0x58;
587 } else if (in_winkey == fKeyConv[EXF5]) {
588 ascii=0x00; code=0x59;
590 } else if (in_winkey == fKeyConv[EHome]) {
591 ascii=0x00; code=0x36;
592 } else if (in_winkey == fKeyConv[EDel]) {
593 ascii=0x00; code=0x37;
594 } else if (in_winkey == fKeyConv[EInsert]) {
595 ascii=0x00; code=0x5e;
596 } else if (in_winkey == fKeyConv[ERollDown]) {
597 ascii=0x00; code=0x38;
598 } else if (in_winkey == fKeyConv[ERollUp]) {
599 ascii=0x00; code=0x39;
600 } else if (in_winkey == fKeyConv[EUndo]) {
601 ascii=0x00; code=0x3a;
602 } else if (in_winkey == fKeyConv[EOPT1]) {
603 ascii=0x00; code=(fKeyOPT1Pressed)?0x72:0xf2;
604 } else if (in_winkey == fKeyConv[EOPT2]) {
605 ascii=0x00; code=(fKeyOPT2Pressed)?0x72:0xf2;
607 } else if (in_winkey == VK_NUMPAD0) {
608 ascii='0'; code=0x4f;
609 } else if (in_winkey == VK_NUMPAD1) {
610 ascii='1'; code=0x4b;
611 } else if (in_winkey == VK_NUMPAD2) {
612 ascii='2'; code=0x4c;
613 } else if (in_winkey == VK_NUMPAD3) {
614 ascii='3'; code=0x4d;
615 } else if (in_winkey == VK_NUMPAD4) {
616 ascii='4'; code=0x47;
617 } else if (in_winkey == VK_NUMPAD5) {
618 ascii='5'; code=0x48;
619 } else if (in_winkey == VK_NUMPAD6) {
620 ascii='6'; code=0x49;
621 } else if (in_winkey == VK_NUMPAD7) {
622 ascii='7'; code=0x43;
623 } else if (in_winkey == VK_NUMPAD8) {
624 ascii='8'; code=0x44;
625 } else if (in_winkey == VK_NUMPAD9) {
626 ascii='9'; code=0x45;
627 } else if (in_winkey == VK_DECIMAL) {
628 ascii='.'; code=0x51;
629 } else if (in_winkey == VK_DIVIDE) {
630 ascii='/'; code=0x40;
631 } else if (in_winkey == VK_MULTIPLY) {
632 ascii='*'; code=0x41;
633 } else if (in_winkey == VK_SUBTRACT) {
634 ascii='-'; code=0x42;
635 } else if (in_winkey == VK_ADD) {
636 ascii='+'; code=0x46;
638 } else if (in_winkey == VK_OEM_2) {
639 ascii='/'; code=fX68ScanCode[ascii-0x20];
640 } else if (in_winkey == VK_OEM_102) {
641 ascii='\\'; code=fX68ScanCode[ascii-0x20];
643 } else if (in_winkey>=0x20 && in_winkey<0x7f) {
645 code = fX68ScanCode[in_winkey-0x20];
654 if (out_ascii) *out_ascii = ascii;
655 if (out_code) *out_code = code;