2
0

keymap.pas 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. {
  2. This file is part of the Free Pascal run time library.
  3. A file in Amiga system run time library.
  4. Copyright (c) 1998-2003 by Nils Sjoholm
  5. member of the Amiga RTL development team.
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. {
  13. keymap.resource definitions and console.device key map definitions
  14. }
  15. {
  16. History:
  17. Added the defines use_amiga_smartlink and
  18. use_auto_openlib. Implemented autoopening
  19. of the library.
  20. 14 Jan 2003.
  21. Changed integer > smallint,
  22. cardinal > longword.
  23. 09 Feb 2003.
  24. [email protected] Nils Sjoholm
  25. }
  26. {$I useamigasmartlink.inc}
  27. {$ifdef use_amiga_smartlink}
  28. {$smartlink on}
  29. {$endif use_amiga_smartlink}
  30. unit keymap;
  31. INTERFACE
  32. uses exec, inputevent;
  33. Type
  34. pKeyMap = ^tKeyMap;
  35. tKeyMap = record
  36. km_LoKeyMapTypes : Pointer;
  37. km_LoKeyMap : Pointer;
  38. km_LoCapsable : Pointer;
  39. km_LoRepeatable : Pointer;
  40. km_HiKeyMapTypes : Pointer;
  41. km_HiKeyMap : Pointer;
  42. km_HiCapsable : Pointer;
  43. km_HiRepeatable : Pointer;
  44. end;
  45. pKeymapNode = ^tKeyMapNode;
  46. tKeyMapNode = record
  47. kn_Node : tNode; { including name of keymap }
  48. kn_KeyMap : tKeyMap;
  49. end;
  50. { the structure of keymap.resource }
  51. pKeyMapResource = ^tKeyMapResource;
  52. tKeyMapResource = record
  53. kr_Node : tNode;
  54. kr_List : tList; { a list of KeyMapNodes }
  55. end;
  56. Const
  57. { Key Map Types }
  58. KC_NOQUAL = 0;
  59. KC_VANILLA = 7; { note that SHIFT+ALT+CTRL is VANILLA }
  60. KCB_SHIFT = 0;
  61. KCF_SHIFT = $01;
  62. KCB_ALT = 1;
  63. KCF_ALT = $02;
  64. KCB_CONTROL = 2;
  65. KCF_CONTROL = $04;
  66. KCB_DOWNUP = 3;
  67. KCF_DOWNUP = $08;
  68. KCB_DEAD = 5; { may be dead or modified by dead key: }
  69. KCF_DEAD = $20; { use dead prefix bytes }
  70. KCB_STRING = 6;
  71. KCF_STRING = $40;
  72. KCB_NOP = 7;
  73. KCF_NOP = $80;
  74. { Dead Prefix Bytes }
  75. DPB_MOD = 0;
  76. DPF_MOD = $01;
  77. DPB_DEAD = 3;
  78. DPF_DEAD = $08;
  79. DP_2DINDEXMASK = $0f; { mask for index for 1st of two dead keys }
  80. DP_2DFACSHIFT = 4; { shift for factor for 1st of two dead keys }
  81. VAR KeymapBase : pLibrary;
  82. const
  83. KEYMAPNAME : PChar = 'keymap.library';
  84. FUNCTION AskKeyMapDefault : pKeyMap;
  85. FUNCTION MapANSI(thestring : pCHAR; count : LONGINT; buffer : pCHAR; length : LONGINT; keyMap : pKeyMap) : LONGINT;
  86. FUNCTION MapRawKey(event : pInputEvent; buffer : pCHAR; length : LONGINT; keyMap : pKeyMap) : smallint;
  87. PROCEDURE SetKeyMapDefault(keyMap : pKeyMap);
  88. IMPLEMENTATION
  89. uses msgbox;
  90. FUNCTION AskKeyMapDefault : pKeyMap;
  91. BEGIN
  92. ASM
  93. MOVE.L A6,-(A7)
  94. MOVEA.L KeymapBase,A6
  95. JSR -036(A6)
  96. MOVEA.L (A7)+,A6
  97. MOVE.L D0,@RESULT
  98. END;
  99. END;
  100. FUNCTION MapANSI(thestring : pCHAR; count : LONGINT; buffer : pCHAR; length : LONGINT; keyMap : pKeyMap) : LONGINT;
  101. BEGIN
  102. ASM
  103. MOVE.L A6,-(A7)
  104. MOVEA.L thestring,A0
  105. MOVE.L count,D0
  106. MOVEA.L buffer,A1
  107. MOVE.L length,D1
  108. MOVEA.L keyMap,A2
  109. MOVEA.L KeymapBase,A6
  110. JSR -048(A6)
  111. MOVEA.L (A7)+,A6
  112. MOVE.L D0,@RESULT
  113. END;
  114. END;
  115. FUNCTION MapRawKey(event : pInputEvent; buffer : pCHAR; length : LONGINT; keyMap : pKeyMap) : smallint;
  116. BEGIN
  117. ASM
  118. MOVE.L A6,-(A7)
  119. MOVEA.L event,A0
  120. MOVEA.L buffer,A1
  121. MOVE.L length,D1
  122. MOVEA.L keyMap,A2
  123. MOVEA.L KeymapBase,A6
  124. JSR -042(A6)
  125. MOVEA.L (A7)+,A6
  126. MOVE.L D0,@RESULT
  127. END;
  128. END;
  129. PROCEDURE SetKeyMapDefault(keyMap : pKeyMap);
  130. BEGIN
  131. ASM
  132. MOVE.L A6,-(A7)
  133. MOVEA.L keyMap,A0
  134. MOVEA.L KeymapBase,A6
  135. JSR -030(A6)
  136. MOVEA.L (A7)+,A6
  137. END;
  138. END;
  139. {$I useautoopenlib.inc}
  140. {$ifdef use_auto_openlib}
  141. {$Info Compiling autoopening of keymap.library}
  142. var
  143. keymap_exit : Pointer;
  144. procedure ClosekeymapLibrary;
  145. begin
  146. ExitProc := keymap_exit;
  147. if KeymapBase <> nil then begin
  148. CloseLibrary(KeymapBase);
  149. KeymapBase := nil;
  150. end;
  151. end;
  152. const
  153. { Change VERSION and LIBVERSION to proper values }
  154. VERSION : string[2] = '0';
  155. LIBVERSION : longword = 0;
  156. begin
  157. KeymapBase := nil;
  158. KeymapBase := OpenLibrary(KEYMAPNAME,LIBVERSION);
  159. if KeymapBase <> nil then begin
  160. keymap_exit := ExitProc;
  161. ExitProc := @ClosekeymapLibrary
  162. end else begin
  163. MessageBox('FPC Pascal Error',
  164. 'Can''t open keymap.library version ' + VERSION + #10 +
  165. 'Deallocating resources and closing down',
  166. 'Oops');
  167. halt(20);
  168. end;
  169. {$else}
  170. {$Warning No autoopening of keymap.library compiled}
  171. {$Info Make sure you open keymap.library yourself}
  172. {$endif use_auto_openlib}
  173. END. (* UNIT KEYMAP *)