drivers.pas 69 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563
  1. { $Id$ }
  2. {********[ SOURCE FILE OF GRAPHICAL FREE VISION ]**********}
  3. { }
  4. { System independent clone of DRIVERS.PAS }
  5. { }
  6. { Interface Copyright (c) 1992 Borland International }
  7. { }
  8. { Copyright (c) 1996, 1997, 1998, 1999, 2000 }
  9. { by Leon de Boer }
  10. { [email protected] - primary e-mail addr }
  11. { [email protected] - backup e-mail addr }
  12. { }
  13. { Original FormatStr kindly donated by Marco Schmidt }
  14. { }
  15. { Mouse callback hook under FPC with kind assistance of }
  16. { Pierre Muller, Gertjan Schouten & Florian Klaempfl. }
  17. { }
  18. {****************[ THIS CODE IS FREEWARE ]*****************}
  19. { }
  20. { This sourcecode is released for the purpose to }
  21. { promote the pascal language on all platforms. You may }
  22. { redistribute it and/or modify with the following }
  23. { DISCLAIMER. }
  24. { }
  25. { This SOURCE CODE is distributed "AS IS" WITHOUT }
  26. { WARRANTIES AS TO PERFORMANCE OF MERCHANTABILITY OR }
  27. { ANY OTHER WARRANTIES WHETHER EXPRESSED OR IMPLIED. }
  28. { }
  29. {*****************[ SUPPORTED PLATFORMS ]******************}
  30. { }
  31. { Only Free Pascal Compiler supported }
  32. { }
  33. {**********************************************************}
  34. UNIT Drivers;
  35. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  36. INTERFACE
  37. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  38. {====Include file to sort compiler platform out =====================}
  39. {$I Platform.inc}
  40. {====================================================================}
  41. {==== Compiler directives ===========================================}
  42. {$X+} { Extended syntax is ok }
  43. {$R-} { Disable range checking }
  44. {$IFNDEF OS_UNIX}
  45. {$S-} { Disable Stack Checking }
  46. {$ENDIF}
  47. {$I-} { Disable IO Checking }
  48. {$Q-} { Disable Overflow Checking }
  49. {$V-} { Turn off strict VAR strings }
  50. {====================================================================}
  51. {$ifdef CPU68K}
  52. {$DEFINE ENDIAN_BIG}
  53. {$endif CPU68K}
  54. USES
  55. {$IFDEF OS_WINDOWS} { WIN/NT CODE }
  56. Windows, { Standard unit }
  57. {$ENDIF}
  58. {$ifdef OS_DOS}
  59. Dos,
  60. {$endif OS_DOS}
  61. {$IFDEF OS_OS2} { OS2 CODE }
  62. {$IFDEF PPC_Virtual} { VIRTUAL PASCAL UNITS }
  63. OS2Def, OS2Base, OS2PMAPI, { Standard units }
  64. {$ENDIF}
  65. {$IFDEF PPC_Speed} { SPEED PASCAL UNITS }
  66. BseDos, Os2Def, { Standard units }
  67. {$ENDIF}
  68. {$IFDEF PPC_FPC} { FPC UNITS }
  69. DosCalls, Os2Def, { Standard units }
  70. {$ENDIF}
  71. {$ENDIF}
  72. {$IFDEF OS_UNIX}
  73. {$ifdef VER1_0}
  74. linux,
  75. {$else}
  76. baseunix,unix,
  77. {$endif}
  78. {$ENDIF}
  79. {$IFDEF OS_NETWARE_LIBC}
  80. libc,
  81. {$ENDIF}
  82. {$IFDEF OS_NETWARE_CLIB}
  83. nwserv,
  84. {$ENDIF}
  85. video,
  86. SysMsg,
  87. FVCommon, Objects; { GFV standard units }
  88. {***************************************************************************}
  89. { PUBLIC CONSTANTS }
  90. {***************************************************************************}
  91. {---------------------------------------------------------------------------}
  92. { EVENT TYPE MASKS }
  93. {---------------------------------------------------------------------------}
  94. CONST
  95. evMouseDown = $0001; { Mouse down event }
  96. evMouseUp = $0002; { Mouse up event }
  97. evMouseMove = $0004; { Mouse move event }
  98. evMouseAuto = $0008; { Mouse auto event }
  99. evKeyDown = $0010; { Key down event }
  100. evCommand = $0100; { Command event }
  101. evBroadcast = $0200; { Broadcast event }
  102. {---------------------------------------------------------------------------}
  103. { EVENT CODE MASKS }
  104. {---------------------------------------------------------------------------}
  105. CONST
  106. evNothing = $0000; { Empty event }
  107. evMouse = $000F; { Mouse event }
  108. evKeyboard = $0010; { Keyboard event }
  109. evMessage = $FF00; { Message event }
  110. {---------------------------------------------------------------------------}
  111. { EXTENDED KEY CODES }
  112. {---------------------------------------------------------------------------}
  113. CONST
  114. kbNoKey = $0000; kbAltEsc = $0100; kbEsc = $011B;
  115. kbAltSpace = $0200; kbCtrlIns = $0400; kbShiftIns = $0500;
  116. kbCtrlDel = $0600; kbShiftDel = $0700; kbAltBack = $0800;
  117. kbAltShiftBack= $0900; kbBack = $0E08; kbCtrlBack = $0E7F;
  118. kbShiftTab = $0F00; kbTab = $0F09; kbAltQ = $1000;
  119. kbCtrlQ = $1011; kbAltW = $1100; kbCtrlW = $1117;
  120. kbAltE = $1200; kbCtrlE = $1205; kbAltR = $1300;
  121. kbCtrlR = $1312; kbAltT = $1400; kbCtrlT = $1414;
  122. kbAltY = $1500; kbCtrlY = $1519; kbAltU = $1600;
  123. kbCtrlU = $1615; kbAltI = $1700; kbCtrlI = $1709;
  124. kbAltO = $1800; kbCtrlO = $180F; kbAltP = $1900;
  125. kbCtrlP = $1910; kbAltLftBrack = $1A00; kbAltRgtBrack = $1B00;
  126. kbCtrlEnter = $1C0A; kbEnter = $1C0D; kbAltA = $1E00;
  127. kbCtrlA = $1E01; kbAltS = $1F00; kbCtrlS = $1F13;
  128. kbAltD = $2000; kbCtrlD = $2004; kbAltF = $2100;
  129. kbCtrlF = $2106; kbAltG = $2200; kbCtrlG = $2207;
  130. kbAltH = $2300; kbCtrlH = $2308; kbAltJ = $2400;
  131. kbCtrlJ = $240A; kbAltK = $2500; kbCtrlK = $250B;
  132. kbAltL = $2600; kbCtrlL = $260C; kbAltSemiCol = $2700;
  133. kbAltQuote = $2800; kbAltOpQuote = $2900; kbAltBkSlash = $2B00;
  134. kbAltZ = $2C00; kbCtrlZ = $2C1A; kbAltX = $2D00;
  135. kbCtrlX = $2D18; kbAltC = $2E00; kbCtrlC = $2E03;
  136. kbAltV = $2F00; kbCtrlV = $2F16; kbAltB = $3000;
  137. kbCtrlB = $3002; kbAltN = $3100; kbCtrlN = $310E;
  138. kbAltM = $3200; kbCtrlM = $320D; kbAltComma = $3300;
  139. kbAltPeriod = $3400; kbAltSlash = $3500; kbAltGreyAst = $3700;
  140. kbSpaceBar = $3920; kbF1 = $3B00; kbF2 = $3C00;
  141. kbF3 = $3D00; kbF4 = $3E00; kbF5 = $3F00;
  142. kbF6 = $4000; kbF7 = $4100; kbF8 = $4200;
  143. kbF9 = $4300; kbF10 = $4400; kbHome = $4700;
  144. kbUp = $4800; kbPgUp = $4900; kbGrayMinus = $4A2D;
  145. kbLeft = $4B00; kbCenter = $4C00; kbRight = $4D00;
  146. kbAltGrayPlus = $4E00; kbGrayPlus = $4E2B; kbEnd = $4F00;
  147. kbDown = $5000; kbPgDn = $5100; kbIns = $5200;
  148. kbDel = $5300; kbShiftF1 = $5400; kbShiftF2 = $5500;
  149. kbShiftF3 = $5600; kbShiftF4 = $5700; kbShiftF5 = $5800;
  150. kbShiftF6 = $5900; kbShiftF7 = $5A00; kbShiftF8 = $5B00;
  151. kbShiftF9 = $5C00; kbShiftF10 = $5D00; kbCtrlF1 = $5E00;
  152. kbCtrlF2 = $5F00; kbCtrlF3 = $6000; kbCtrlF4 = $6100;
  153. kbCtrlF5 = $6200; kbCtrlF6 = $6300; kbCtrlF7 = $6400;
  154. kbCtrlF8 = $6500; kbCtrlF9 = $6600; kbCtrlF10 = $6700;
  155. kbAltF1 = $6800; kbAltF2 = $6900; kbAltF3 = $6A00;
  156. kbAltF4 = $6B00; kbAltF5 = $6C00; kbAltF6 = $6D00;
  157. kbAltF7 = $6E00; kbAltF8 = $6F00; kbAltF9 = $7000;
  158. kbAltF10 = $7100; kbCtrlPrtSc = $7200; kbCtrlLeft = $7300;
  159. kbCtrlRight = $7400; kbCtrlEnd = $7500; kbCtrlPgDn = $7600;
  160. kbCtrlHome = $7700; kbAlt1 = $7800; kbAlt2 = $7900;
  161. kbAlt3 = $7A00; kbAlt4 = $7B00; kbAlt5 = $7C00;
  162. kbAlt6 = $7D00; kbAlt7 = $7E00; kbAlt8 = $7F00;
  163. kbAlt9 = $8000; kbAlt0 = $8100; kbAltMinus = $8200;
  164. kbAltEqual = $8300; kbCtrlPgUp = $8400; kbF11 = $8500;
  165. kbF12 = $8600; kbShiftF11 = $8700; kbShiftF12 = $8800;
  166. kbCtrlF11 = $8900; kbCtrlF12 = $8A00; kbAltF11 = $8B00;
  167. kbAltF12 = $8C00; kbCtrlUp = $8D00; kbCtrlMinus = $8E00;
  168. kbCtrlCenter = $8F00; kbCtrlGreyPlus= $9000; kbCtrlDown = $9100;
  169. kbCtrlTab = $9400; kbAltHome = $9700; kbAltUp = $9800;
  170. kbAltPgUp = $9900; kbAltLeft = $9B00; kbAltRight = $9D00;
  171. kbAltEnd = $9F00; kbAltDown = $A000; kbAltPgDn = $A100;
  172. kbAltIns = $A200; kbAltDel = $A300; kbAltTab = $A500;
  173. { ------------------------------- REMARK ------------------------------ }
  174. { New keys not initially defined by Borland in their unit interface. }
  175. { ------------------------------ END REMARK --- Leon de Boer, 15May96 - }
  176. kbFullStop = $342E; kbComma = $332C; kbBackSlash = $352F;
  177. kbApostrophe = $2827; kbSemiColon = $273B; kbEqual = $0D3D;
  178. kbGreaterThan = $343E; kbLessThan = $333C; kbQuestion = $353F;
  179. kbQuote = $2822; kbColon = $273A; kbPlus = $0D2B;
  180. kbPipe = $2B7C; kbSlash = $2B5C; kbExclaim = $0221;
  181. kbAt = $0340; kbNumber = $0423; kbPercent = $0625;
  182. kbCaret = $075E; kbAmpersand = $0826; kbAsterix = $092A;
  183. kbLeftBracket = $0A28; kbRightBracket= $0B29; kbApprox = $2960;
  184. kbTilde = $297E; kbDollar = $0524; kbMinus = $0C2D;
  185. kbUnderline = $0C5F; kbLeftSqBr = $1A5B; kbRightSqBr = $1B5D;
  186. kbLeftCurlyBr = $1A7B; kbRightCurlyBr= $1B7D;
  187. {---------------------------------------------------------------------------}
  188. { KEYBOARD STATE AND SHIFT MASKS }
  189. {---------------------------------------------------------------------------}
  190. CONST
  191. kbRightShift = $0001; { Right shift key }
  192. kbLeftShift = $0002; { Left shift key }
  193. kbCtrlShift = $0004; { Control key down }
  194. kbAltShift = $0008; { Alt key down }
  195. kbScrollState = $0010; { Scroll lock on }
  196. kbNumState = $0020; { Number lock on }
  197. kbCapsState = $0040; { Caps lock on }
  198. kbInsState = $0080; { Insert mode on }
  199. kbBothShifts = kbRightShift + kbLeftShift; { Right & Left shifts }
  200. {---------------------------------------------------------------------------}
  201. { MOUSE BUTTON STATE MASKS }
  202. {---------------------------------------------------------------------------}
  203. CONST
  204. mbLeftButton = $01; { Left mouse button }
  205. mbRightButton = $02; { Right mouse button }
  206. mbMiddleButton = $04; { Middle mouse button }
  207. {---------------------------------------------------------------------------}
  208. { SCREEN CRT MODE CONSTANTS }
  209. {---------------------------------------------------------------------------}
  210. CONST
  211. smBW80 = $0002; { Black and white }
  212. smCO80 = $0003; { Colour mode }
  213. smMono = $0007; { Monochrome mode }
  214. smFont8x8 = $0100; { 8x8 font mode }
  215. {***************************************************************************}
  216. { PUBLIC TYPE DEFINITIONS }
  217. {***************************************************************************}
  218. { ******************************* REMARK ****************************** }
  219. { The TEvent definition is completely compatable with all existing }
  220. { code but adds two new fields ID and Data into the message record }
  221. { which helps with WIN/NT and OS2 message processing. }
  222. { ****************************** END REMARK *** Leon de Boer, 11Sep97 * }
  223. {---------------------------------------------------------------------------}
  224. { EVENT RECORD DEFINITION }
  225. {---------------------------------------------------------------------------}
  226. TYPE
  227. TEvent =
  228. {$ifndef FPC_REQUIRES_PROPER_ALIGNMENT}
  229. PACKED
  230. {$endif FPC_REQUIRES_PROPER_ALIGNMENT}
  231. RECORD
  232. What: Sw_Word; { Event type }
  233. Case Sw_Word Of
  234. evNothing: (); { ** NO EVENT ** }
  235. evMouse: (
  236. Buttons: Byte; { Mouse buttons }
  237. Double: Boolean; { Double click state }
  238. Where: TPoint); { Mouse position }
  239. evKeyDown: (
  240. { ** KEY EVENT ** }
  241. Case Sw_Integer Of
  242. 0: (KeyCode: Word); { Full key code }
  243. 1: (
  244. {$ifdef ENDIAN_BIG}
  245. ScanCode: Byte;
  246. CharCode: Char;
  247. {$else not ENDIAN_BIG}
  248. CharCode: Char; { Char code }
  249. ScanCode: Byte; { Scan code }
  250. {$endif not ENDIAN_BIG}
  251. KeyShift: byte)); { Shift states }
  252. evMessage: ( { ** MESSAGE EVENT ** }
  253. Command: Sw_Word; { Message command }
  254. Id : Sw_Word; { Message id }
  255. Data : Real; { Message data }
  256. Case Sw_Word Of
  257. 0: (InfoPtr: Pointer); { Message pointer }
  258. 1: (InfoLong: Longint); { Message longint }
  259. 2: (InfoWord: Word); { Message Sw_Word }
  260. 3: (InfoInt: Integer); { Message Sw_Integer }
  261. 4: (InfoByte: Byte); { Message byte }
  262. 5: (InfoChar: Char)); { Message character }
  263. END;
  264. PEvent = ^TEvent;
  265. TVideoMode = Video.TVideoMode; { Screen mode }
  266. {---------------------------------------------------------------------------}
  267. { ERROR HANDLER FUNCTION DEFINITION }
  268. {---------------------------------------------------------------------------}
  269. TYPE
  270. TSysErrorFunc = FUNCTION (ErrorCode: Sw_Integer; Drive: Byte): Sw_Integer;
  271. {***************************************************************************}
  272. { INTERFACE ROUTINES }
  273. {***************************************************************************}
  274. { Get Dos counter ticks }
  275. Function GetDosTicks:longint; { returns ticks at 18.2 Hz, just like DOS }
  276. procedure GiveUpTimeSlice;
  277. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  278. { BUFFER MOVE ROUTINES }
  279. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  280. {-CStrLen------------------------------------------------------------
  281. Returns the length of string S, where S is a control string using tilde
  282. characters ('~') to designate shortcut characters. The tildes are
  283. excluded from the length of the string, as they will not appear on
  284. the screen. For example, given the string '~B~roccoli' as its
  285. parameter, CStrLen returns 8.
  286. 25May96 LdB
  287. ---------------------------------------------------------------------}
  288. FUNCTION CStrLen (Const S: String): Sw_Integer;
  289. {-MoveStr------------------------------------------------------------
  290. Moves a string into a buffer for use with a view's WriteBuf or WriteLine.
  291. Dest must be a TDrawBuffer (or an equivalent array of Sw_Words). The
  292. characters in Str are moved into the low bytes of corresponding Sw_Words
  293. in Dest. The high bytes of the Sw_Words are set to Attr, or remain
  294. unchanged if Attr is zero.
  295. 25May96 LdB
  296. ---------------------------------------------------------------------}
  297. PROCEDURE MoveStr (Var Dest; Const Str: String; Attr: Byte);
  298. {-MoveCStr-----------------------------------------------------------
  299. The characters in Str are moved into the low bytes of corresponding
  300. Sw_Words in Dest. The high bytes of the Sw_Words are set to Lo(Attr) or
  301. Hi(Attr). Tilde characters (~) in the string toggle between the two
  302. attribute bytes passed in the Attr Sw_Word.
  303. 25May96 LdB
  304. ---------------------------------------------------------------------}
  305. PROCEDURE MoveCStr (Var Dest; Const Str: String; Attrs: Word);
  306. {-MoveBuf------------------------------------------------------------
  307. Count bytes are moved from Source into the low bytes of corresponding
  308. Sw_Words in Dest. The high bytes of the Sw_Words in Dest are set to Attr,
  309. or remain unchanged if Attr is zero.
  310. 25May96 LdB
  311. ---------------------------------------------------------------------}
  312. PROCEDURE MoveBuf (Var Dest, Source; Attr: Byte; Count: Sw_Word);
  313. {-MoveChar------------------------------------------------------------
  314. Moves characters into a buffer for use with a view's WriteBuf or
  315. WriteLine. Dest must be a TDrawBuffer (or an equivalent array of Sw_Words).
  316. The low bytes of the first Count Sw_Words of Dest are set to C, or
  317. remain unchanged if Ord(C) is zero. The high bytes of the Sw_Words are
  318. set to Attr, or remain unchanged if Attr is zero.
  319. 25May96 LdB
  320. ---------------------------------------------------------------------}
  321. PROCEDURE MoveChar (Var Dest; C: Char; Attr: Byte; Count: Sw_Word);
  322. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  323. { KEYBOARD SUPPORT ROUTINES }
  324. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  325. {-GetAltCode---------------------------------------------------------
  326. Returns the scancode corresponding to Alt+Ch key that is given.
  327. 25May96 LdB
  328. ---------------------------------------------------------------------}
  329. FUNCTION GetAltCode (Ch: Char): Word;
  330. {-GetCtrlCode--------------------------------------------------------
  331. Returns the scancode corresponding to Alt+Ch key that is given.
  332. 25May96 LdB
  333. ---------------------------------------------------------------------}
  334. FUNCTION GetCtrlCode (Ch: Char): Word;
  335. {-GetAltChar---------------------------------------------------------
  336. Returns the ascii character for the Alt+Key scancode that was given.
  337. 25May96 LdB
  338. ---------------------------------------------------------------------}
  339. FUNCTION GetAltChar (KeyCode: Word): Char;
  340. {-GetCtrlChar--------------------------------------------------------
  341. Returns the ascii character for the Ctrl+Key scancode that was given.
  342. 25May96 LdB
  343. ---------------------------------------------------------------------}
  344. FUNCTION GetCtrlChar (KeyCode: Word): Char;
  345. {-CtrlToArrow--------------------------------------------------------
  346. Converts a WordStar-compatible control key code to the corresponding
  347. cursor key code.
  348. 25May96 LdB
  349. ---------------------------------------------------------------------}
  350. FUNCTION CtrlToArrow (KeyCode: Word): Word;
  351. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  352. { KEYBOARD CONTROL ROUTINES }
  353. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  354. {-GetShiftState------------------------------------------------------
  355. Returns a byte containing the current Shift key state. The return
  356. value contains a combination of the kbXXXX constants for shift states.
  357. 08Jul96 LdB
  358. ---------------------------------------------------------------------}
  359. FUNCTION GetShiftState: Byte;
  360. {-GetKeyEvent--------------------------------------------------------
  361. Checks whether a keyboard event is available. If a key has been pressed,
  362. Event.What is set to evKeyDown and Event.KeyCode is set to the scan
  363. code of the key. Otherwise, Event.What is set to evNothing.
  364. 19May98 LdB
  365. ---------------------------------------------------------------------}
  366. PROCEDURE GetKeyEvent (Var Event: TEvent);
  367. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  368. { MOUSE CONTROL ROUTINES }
  369. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  370. {-ShowMouse----------------------------------------------------------
  371. Decrements the hide counter and if zero the mouse is shown on screen.
  372. 30Jun98 LdB
  373. ---------------------------------------------------------------------}
  374. PROCEDURE ShowMouse;
  375. {-HideMouse----------------------------------------------------------
  376. If mouse hide counter is zero it removes the cursor from the screen.
  377. The hide counter is then incremented by one count.
  378. 30Jun98 LdB
  379. ---------------------------------------------------------------------}
  380. PROCEDURE HideMouse;
  381. {-GetMouseEvent------------------------------------------------------
  382. Checks whether a mouse event is available. If a mouse event has occurred,
  383. Event.What is set to evMouseDown, evMouseUp, evMouseMove, or evMouseAuto
  384. and the button and double click variables are set appropriately.
  385. 06Jan97 LdB
  386. ---------------------------------------------------------------------}
  387. PROCEDURE GetMouseEvent (Var Event: TEvent);
  388. {-GetSystemEvent------------------------------------------------------
  389. Checks whether a system event is available. If a system event has occurred,
  390. Event.What is set to evCommand appropriately
  391. 10Oct2000 PM
  392. ---------------------------------------------------------------------}
  393. procedure GetSystemEvent (Var Event: TEvent);
  394. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  395. { EVENT HANDLER CONTROL ROUTINES }
  396. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  397. {-InitEvents---------------------------------------------------------
  398. Initializes the event manager, enabling the mouse handler routine and
  399. under DOS/DPMI shows the mouse on screen. It is called automatically
  400. by TApplication.Init.
  401. 02May98 LdB
  402. ---------------------------------------------------------------------}
  403. PROCEDURE InitEvents;
  404. {-DoneEvents---------------------------------------------------------
  405. Terminates event manager and disables the mouse and under DOS hides
  406. the mouse. It is called automatically by TApplication.Done.
  407. 02May98 LdB
  408. ---------------------------------------------------------------------}
  409. PROCEDURE DoneEvents;
  410. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  411. { VIDEO CONTROL ROUTINES }
  412. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  413. {-InitVideo---------------------------------------------------------
  414. Initializes the video manager, Saves the current screen mode in
  415. StartupMode, and switches to the mode indicated by ScreenMode.
  416. 19May98 LdB
  417. ---------------------------------------------------------------------}
  418. PROCEDURE InitVideo;
  419. {-DoneVideo---------------------------------------------------------
  420. Terminates the video manager by restoring the initial screen mode
  421. (given by StartupMode), clearing the screen, and restoring the cursor.
  422. Called automatically by TApplication.Done.
  423. 03Jan97 LdB
  424. ---------------------------------------------------------------------}
  425. PROCEDURE DoneVideo;
  426. {-ClearScreen--------------------------------------------------------
  427. Does nothing provided for compatability purposes only.
  428. 04Jan97 LdB
  429. ---------------------------------------------------------------------}
  430. PROCEDURE ClearScreen;
  431. {-SetVideoMode-------------------------------------------------------
  432. Does nothing provided for compatability purposes only.
  433. 04Jan97 LdB
  434. ---------------------------------------------------------------------}
  435. PROCEDURE SetVideoMode (Mode: Sw_Word);
  436. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  437. { ERROR CONTROL ROUTINES }
  438. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  439. {-InitSysError-------------------------------------------------------
  440. Error handling is not yet implemented so this simply sets
  441. SysErrActive=True (ie it lies) and exits.
  442. 20May98 LdB
  443. ---------------------------------------------------------------------}
  444. PROCEDURE InitSysError;
  445. {-DoneSysError-------------------------------------------------------
  446. Error handling is not yet implemented so this simply sets
  447. SysErrActive=False and exits.
  448. 20May98 LdB
  449. ---------------------------------------------------------------------}
  450. PROCEDURE DoneSysError;
  451. {-SystemError---------------------------------------------------------
  452. Error handling is not yet implemented so this simply drops through.
  453. 20May98 LdB
  454. ---------------------------------------------------------------------}
  455. FUNCTION SystemError (ErrorCode: Sw_Integer; Drive: Byte): Sw_Integer;
  456. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  457. { STRING FORMAT ROUTINES }
  458. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  459. {-PrintStr-----------------------------------------------------------
  460. Does nothing provided for compatability purposes only.
  461. 30Jun98 LdB
  462. ---------------------------------------------------------------------}
  463. PROCEDURE PrintStr (CONST S: String);
  464. {-FormatStr----------------------------------------------------------
  465. A string formatting routine that given a string that includes format
  466. specifiers and a list of parameters in Params, FormatStr produces a
  467. formatted output string in Result.
  468. 18Feb99 LdB
  469. ---------------------------------------------------------------------}
  470. PROCEDURE FormatStr (Var Result: String; CONST Format: String; Var Params);
  471. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  472. { >> NEW QUEUED EVENT HANDLER ROUTINES << }
  473. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  474. {-PutEventInQueue-----------------------------------------------------
  475. If there is room in the queue the event is placed in the next vacant
  476. position in the queue manager.
  477. 17Mar98 LdB
  478. ---------------------------------------------------------------------}
  479. FUNCTION PutEventInQueue (Var Event: TEvent): Boolean;
  480. {-NextQueuedEvent----------------------------------------------------
  481. If there are queued events the next event is loaded into event else
  482. evNothing is returned.
  483. 17Mar98 LdB
  484. ---------------------------------------------------------------------}
  485. PROCEDURE NextQueuedEvent(Var Event: TEvent);
  486. {***************************************************************************}
  487. { INITIALIZED PUBLIC VARIABLES }
  488. {***************************************************************************}
  489. PROCEDURE HideMouseCursor;
  490. PROCEDURE ShowMouseCursor;
  491. {---------------------------------------------------------------------------}
  492. { INITIALIZED DOS/DPMI/WIN/NT/OS2 VARIABLES }
  493. {---------------------------------------------------------------------------}
  494. CONST
  495. CheckSnow : Boolean = False; { Compatability only }
  496. MouseEvents : Boolean = False; { Mouse event state }
  497. MouseReverse : Boolean = False; { Mouse reversed }
  498. HiResScreen : Boolean = False; { Compatability only }
  499. CtrlBreakHit : Boolean = False; { Compatability only }
  500. SaveCtrlBreak: Boolean = False; { Compatability only }
  501. SysErrActive : Boolean = False; { Compatability only }
  502. FailSysErrors: Boolean = False; { Compatability only }
  503. ButtonCount : Byte = 0; { Mouse button count }
  504. DoubleDelay : Sw_Word = 8; { Double click delay }
  505. RepeatDelay : Sw_Word = 8; { Auto mouse delay }
  506. SysColorAttr : Sw_Word = $4E4F; { System colour attr }
  507. SysMonoAttr : Sw_Word = $7070; { System mono attr }
  508. StartupMode : Sw_Word = $FFFF; { Compatability only }
  509. CursorLines : Sw_Word = $FFFF; { Compatability only }
  510. ScreenBuffer : Pointer = Nil; { Compatability only }
  511. SaveInt09 : Pointer = Nil; { Compatability only }
  512. SysErrorFunc : TSysErrorFunc = {$ifdef FPC}@{$endif}SystemError; { System error ptr }
  513. {***************************************************************************}
  514. { UNINITIALIZED PUBLIC VARIABLES }
  515. {***************************************************************************}
  516. {---------------------------------------------------------------------------}
  517. { UNINITIALIZED DOS/DPMI/WIN/NT/OS2 VARIABLES }
  518. {---------------------------------------------------------------------------}
  519. VAR
  520. MouseIntFlag: Byte; { Mouse in int flag }
  521. MouseButtons: Byte; { Mouse button state }
  522. ScreenWidth : Byte; { Screen text width }
  523. ScreenHeight: Byte; { Screen text height }
  524. ScreenMode : TVideoMode; { Screen mode }
  525. MouseWhere : TPoint; { Mouse position }
  526. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  527. IMPLEMENTATION
  528. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  529. { API Units }
  530. USES
  531. FVConsts,
  532. Keyboard,Mouse;
  533. {***************************************************************************}
  534. { PRIVATE INTERNAL CONSTANTS }
  535. {***************************************************************************}
  536. {---------------------------------------------------------------------------}
  537. { DOS/DPMI MOUSE INTERRUPT EVENT QUEUE SIZE }
  538. {---------------------------------------------------------------------------}
  539. CONST EventQSize = 16; { Default int bufsize }
  540. {---------------------------------------------------------------------------}
  541. { DOS/DPMI/WIN/NT/OS2 NEW EVENT QUEUE MAX SIZE }
  542. {---------------------------------------------------------------------------}
  543. CONST QueueMax = 64; { Max new queue size }
  544. {---------------------------------------------------------------------------}
  545. { MAX WIEW WIDTH to avoid TDrawBuffer overrun in views unit }
  546. {---------------------------------------------------------------------------}
  547. CONST MaxViewWidth = 255; { Max view width }
  548. {***************************************************************************}
  549. { PRIVATE INTERNAL TYPES }
  550. {***************************************************************************}
  551. {***************************************************************************}
  552. { PRIVATE INTERNAL INITIALIZED VARIABLES }
  553. {***************************************************************************}
  554. {---------------------------------------------------------------------------}
  555. { DOS/DPMI/WIN/NT/OS2 ALT KEY SCANCODES FROM KEYS (0-127) }
  556. {---------------------------------------------------------------------------}
  557. CONST AltCodes: Array [0..127] Of Byte = (
  558. $00, $00, $00, $00, $00, $00, $00, $00, { $00 - $07 }
  559. $00, $00, $00, $00, $00, $00, $00, $00, { $08 - $0F }
  560. $00, $00, $00, $00, $00, $00, $00, $00, { $10 - $17 }
  561. $00, $00, $00, $00, $00, $00, $00, $00, { $18 - $1F }
  562. $00, $00, $00, $00, $00, $00, $00, $00, { $20 - $27 }
  563. $00, $00, $00, $00, $00, $82, $00, $00, { $28 - $2F }
  564. $81, $78, $79, $7A, $7B, $7C, $7D, $7E, { $30 - $37 }
  565. $7F, $80, $00, $00, $00, $83, $00, $00, { $38 - $3F }
  566. $00, $1E, $30, $2E, $20, $12, $21, $22, { $40 - $47 }
  567. $23, $17, $24, $25, $26, $32, $31, $18, { $48 - $4F }
  568. $19, $10, $13, $1F, $14, $16, $2F, $11, { $50 - $57 }
  569. $2D, $15, $2C, $00, $00, $00, $00, $00, { $58 - $5F }
  570. $00, $00, $00, $00, $00, $00, $00, $00, { $60 - $67 }
  571. $00, $00, $00, $00, $00, $00, $00, $00, { $68 - $6F }
  572. $00, $00, $00, $00, $00, $00, $00, $00, { $70 - $77 }
  573. $00, $00, $00, $00, $00, $00, $00, $00); { $78 - $7F }
  574. {***************************************************************************}
  575. { PRIVATE INTERNAL INITIALIZED VARIABLES }
  576. {***************************************************************************}
  577. {---------------------------------------------------------------------------}
  578. { NEW CONTROL VARIABLES }
  579. {---------------------------------------------------------------------------}
  580. CONST
  581. HideCount : Sw_Integer = 0; { Cursor hide count }
  582. QueueCount: Sw_Word = 0; { Queued message count }
  583. QueueHead : Sw_Word = 0; { Queue head pointer }
  584. QueueTail : Sw_Word = 0; { Queue tail pointer }
  585. {***************************************************************************}
  586. { PRIVATE INTERNAL UNINITIALIZED VARIABLES }
  587. {***************************************************************************}
  588. {---------------------------------------------------------------------------}
  589. { UNINITIALIZED DOS/DPMI/API VARIABLES }
  590. {---------------------------------------------------------------------------}
  591. VAR
  592. LastDouble : Boolean; { Last double buttons }
  593. LastButtons: Byte; { Last button state }
  594. DownButtons: Byte; { Last down buttons }
  595. EventCount : Sw_Word; { Events in queue }
  596. AutoDelay : Sw_Word; { Delay time count }
  597. DownTicks : Sw_Word; { Down key tick count }
  598. AutoTicks : Sw_Word; { Held key tick count }
  599. LastWhereX : Sw_Word; { Last x position }
  600. LastWhereY : Sw_Word; { Last y position }
  601. DownWhereX : Sw_Word; { Last x position }
  602. DownWhereY : Sw_Word; { Last y position }
  603. LastWhere : TPoint; { Last mouse position }
  604. DownWhere : TPoint; { Last down position }
  605. EventQHead : Pointer; { Head of queue }
  606. EventQTail : Pointer; { Tail of queue }
  607. EventQueue : Array [0..EventQSize - 1] Of TEvent; { Event queue }
  608. EventQLast : RECORD END; { Simple end marker }
  609. StartupScreenMode : TVideoMode;
  610. {---------------------------------------------------------------------------}
  611. { GetDosTicks (18.2 Hz) }
  612. {---------------------------------------------------------------------------}
  613. Function GetDosTicks:longint; { returns ticks at 18.2 Hz, just like DOS }
  614. {$IFDEF OS_OS2}
  615. const
  616. QSV_MS_COUNT = 14;
  617. var
  618. L: longint;
  619. begin
  620. DosQuerySysInfo (QSV_MS_COUNT, QSV_MS_COUNT, L, 4);
  621. GetDosTicks := L div 55;
  622. end;
  623. {$ENDIF}
  624. {$IFDEF OS_UNIX}
  625. var
  626. tv : TimeVal;
  627. { tz : TimeZone;}
  628. begin
  629. {$ifdef ver1_0}
  630. GetTimeOfDay(tv{,tz});
  631. GetDosTicks:=((tv.Sec mod 86400) div 60)*1092+((tv.Sec mod 60)*1000000+tv.USec) div 54945;
  632. {$else}
  633. FPGetTimeOfDay(@tv,nil{,tz});
  634. GetDosTicks:=((tv.tv_Sec mod 86400) div 60)*1092+((tv.tv_Sec mod 60)*1000000+tv.tv_USec) div 54945;
  635. {$endif}
  636. end;
  637. {$ENDIF OS_UNIX}
  638. {$IFDEF OS_WINDOWS}
  639. begin
  640. GetDosTicks:=GetTickCount div 55;
  641. end;
  642. {$ENDIF OS_WINDOWS}
  643. {$IFDEF OS_DOS}
  644. begin
  645. GetDosTicks:=MemL[$40:$6c];
  646. end;
  647. {$ENDIF OS_DOS}
  648. {$IFDEF OS_NETWARE_LIBC}
  649. var
  650. tv : TTimeVal;
  651. tz : TTimeZone;
  652. begin
  653. fpGetTimeOfDay(tv,tz);
  654. GetDosTicks:=((tv.tv_sec mod 86400) div 60)*1092+((tv.tv_Sec mod 60)*1000000+tv.tv_USec) div 549
  655. end;
  656. {$ENDIF}
  657. {$IFDEF OS_NETWARE_CLIB}
  658. begin
  659. GetDosTicks := Nwserv.GetCurrentTicks;
  660. end;
  661. {$ENDIF}
  662. procedure GiveUpTimeSlice;
  663. {$IFDEF OS_DOS}
  664. var r: registers;
  665. begin
  666. Intr ($28, R); (* This is supported everywhere. *)
  667. r.ax:=$1680;
  668. intr($2f,r);
  669. end;
  670. {$ENDIF}
  671. {$IFDEF OS_UNIX}
  672. var
  673. req,rem : timespec;
  674. begin
  675. req.tv_sec:=0;
  676. req.tv_nsec:=10000000;{ 10 ms }
  677. {$ifdef ver1_0}nanosleep(req,rem){$else}fpnanosleep(@req,@rem){$endif};
  678. end;
  679. {$ENDIF}
  680. {$IFDEF OS_OS2}
  681. begin
  682. DosSleep (5);
  683. end;
  684. {$ENDIF}
  685. {$IFDEF OS_WINDOWS}
  686. begin
  687. { if the return value of this call is non zero then
  688. it means that a ReadFileEx or WriteFileEx have completed
  689. unused for now ! }
  690. { wait for 10 ms }
  691. if SleepEx(10,true)=WAIT_IO_COMPLETION then
  692. begin
  693. { here we should handle the completion of the routines
  694. if we use them }
  695. end;
  696. end;
  697. {$ENDIF}
  698. {$IFDEF OS_NETWARE_LIBC}
  699. begin
  700. Delay (10);
  701. end;
  702. {$ENDIF}
  703. {$IFDEF OS_NETWARE_CLIB}
  704. begin
  705. Delay (10);
  706. end;
  707. {$ENDIF}
  708. {---------------------------------------------------------------------------}
  709. { UNINITIALIZED DOS/DPMI/WIN/NT/OS2 VARIABLES }
  710. {---------------------------------------------------------------------------}
  711. VAR
  712. SaveExit: Pointer; { Saved exit pointer }
  713. Queue : Array [0..QueueMax-1] Of TEvent; { New message queue }
  714. {***************************************************************************}
  715. { PRIVATE INTERNAL ROUTINES }
  716. {***************************************************************************}
  717. PROCEDURE ShowMouseCursor;
  718. BEGIN
  719. ShowMouse;
  720. END;
  721. PROCEDURE HideMouseCursor;
  722. BEGIN
  723. HideMouse;
  724. END;
  725. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  726. { DOS/DPMI/WIN/NT/OS2 PRIVATE INTERNAL ROUTINES }
  727. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  728. {---------------------------------------------------------------------------}
  729. { ExitDrivers -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 08Jun98 LdB }
  730. {---------------------------------------------------------------------------}
  731. PROCEDURE ExitDrivers; {$IFNDEF PPC_FPC}{$IFNDEF OS_UNIX} FAR; {$ENDIF}{$ENDIF}
  732. BEGIN
  733. DoneSysError; { Relase error trap }
  734. DoneEvents; { Close event driver }
  735. DoneKeyboard;
  736. DoneVideo;
  737. ExitProc := SaveExit; { Restore old exit }
  738. END;
  739. {---------------------------------------------------------------------------}
  740. { DetectVideo -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 19May98 LdB }
  741. {---------------------------------------------------------------------------}
  742. procedure DetectVideo;
  743. VAR
  744. CurrMode : TVideoMode;
  745. begin
  746. { Video.InitVideo; Incompatible with BP
  747. and forces a screen clear which is often a bad thing PM }
  748. GetVideoMode(CurrMode);
  749. ScreenMode:=CurrMode;
  750. end;
  751. {---------------------------------------------------------------------------}
  752. { DetectMouse -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 19May98 LdB }
  753. FUNCTION DetectMouse: Byte;
  754. begin
  755. DetectMouse:=Mouse.DetectMouse;
  756. end;
  757. {***************************************************************************}
  758. { INTERFACE ROUTINES }
  759. {***************************************************************************}
  760. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  761. { BUFFER MOVE ROUTINES }
  762. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  763. {---------------------------------------------------------------------------}
  764. { CStrLen -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 25May96 LdB }
  765. {---------------------------------------------------------------------------}
  766. FUNCTION CStrLen (Const S: String): Sw_Integer;
  767. VAR I, J: Sw_Integer;
  768. BEGIN
  769. J := 0; { Set result to zero }
  770. For I := 1 To Length(S) Do
  771. If (S[I] <> '~') Then Inc(J); { Inc count if not ~ }
  772. CStrLen := J; { Return length }
  773. END;
  774. {---------------------------------------------------------------------------}
  775. { MoveStr -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 10Jul99 LdB }
  776. {---------------------------------------------------------------------------}
  777. PROCEDURE MoveStr (Var Dest; Const Str: String; Attr: Byte);
  778. VAR I: Word; P: PWord;
  779. BEGIN
  780. For I := 1 To Length(Str) Do Begin { For each character }
  781. P := @TWordArray(Dest)[I-1]; { Pointer to Sw_Word }
  782. If (Attr <> 0) Then WordRec(P^).Hi := Attr; { Copy attribute }
  783. WordRec(P^).Lo := Byte(Str[I]); { Copy string char }
  784. End;
  785. END;
  786. {---------------------------------------------------------------------------}
  787. { MoveCStr -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 10Jul99 LdB }
  788. {---------------------------------------------------------------------------}
  789. PROCEDURE MoveCStr (Var Dest; Const Str: String; Attrs: Word);
  790. VAR B: Byte; I, J: Sw_Word; P: PWord;
  791. BEGIN
  792. J := 0; { Start position }
  793. For I := 1 To Length(Str) Do Begin { For each character }
  794. If (Str[I] <> '~') Then Begin { Not tilde character }
  795. P := @TWordArray(Dest)[J]; { Pointer to Sw_Word }
  796. If (Lo(Attrs) <> 0) Then
  797. WordRec(P^).Hi := Lo(Attrs); { Copy attribute }
  798. WordRec(P^).Lo := Byte(Str[I]); { Copy string char }
  799. Inc(J); { Next position }
  800. End Else Begin
  801. B := Hi(Attrs); { Hold attribute }
  802. WordRec(Attrs).Hi := Lo(Attrs); { Copy low to high }
  803. WordRec(Attrs).Lo := B; { Complete exchange }
  804. End;
  805. End;
  806. END;
  807. {---------------------------------------------------------------------------}
  808. { MoveBuf -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 10Jul99 LdB }
  809. {---------------------------------------------------------------------------}
  810. PROCEDURE MoveBuf (Var Dest, Source; Attr: Byte; Count: Sw_Word);
  811. VAR I: Word; P: PWord;
  812. BEGIN
  813. For I := 1 To Count Do Begin
  814. P := @TWordArray(Dest)[I-1]; { Pointer to Sw_Word }
  815. If (Attr <> 0) Then WordRec(P^).Hi := Attr; { Copy attribute }
  816. WordRec(P^).Lo := TByteArray(Source)[I-1]; { Copy source data }
  817. End;
  818. END;
  819. {---------------------------------------------------------------------------}
  820. { MoveChar -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 10Jul99 LdB }
  821. {---------------------------------------------------------------------------}
  822. PROCEDURE MoveChar (Var Dest; C: Char; Attr: Byte; Count: Sw_Word);
  823. VAR I: Word; P: PWord;
  824. BEGIN
  825. For I := 1 To Count Do Begin
  826. P := @TWordArray(Dest)[I-1]; { Pointer to Sw_Word }
  827. If (Attr <> 0) Then WordRec(P^).Hi := Attr; { Copy attribute }
  828. If (Ord(C) <> 0) Then WordRec(P^).Lo := Byte(C); { Copy character }
  829. End;
  830. END;
  831. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  832. { KEYBOARD SUPPORT ROUTINES }
  833. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  834. {---------------------------------------------------------------------------}
  835. { GetAltCode -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 25May96 LdB }
  836. {---------------------------------------------------------------------------}
  837. FUNCTION GetAltCode (Ch: Char): Word;
  838. BEGIN
  839. GetAltCode := 0; { Preset zero return }
  840. Ch := UpCase(Ch); { Convert upper case }
  841. If (Ch < #128) Then
  842. GetAltCode := AltCodes[Ord(Ch)] SHL 8 { Return code }
  843. Else If (Ch = #240) Then GetAltCode := $0200 { Return code }
  844. Else GetAltCode := 0; { Return zero }
  845. END;
  846. {---------------------------------------------------------------------------}
  847. { GetCtrlCode -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 25May96 LdB }
  848. {---------------------------------------------------------------------------}
  849. FUNCTION GetCtrlCode (Ch: Char): Word;
  850. BEGIN
  851. GetCtrlCode := GetAltCode(Ch) OR (Ord(Ch) - $40); { Ctrl+key code }
  852. END;
  853. {---------------------------------------------------------------------------}
  854. { GetAltChar -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 25May96 LdB }
  855. {---------------------------------------------------------------------------}
  856. FUNCTION GetAltChar (KeyCode: Word): Char;
  857. VAR I: Sw_Integer;
  858. BEGIN
  859. GetAltChar := #0; { Preset fail return }
  860. If (Lo(KeyCode) = 0) Then Begin { Extended key }
  861. If (Hi(KeyCode) <= $83) Then Begin { Highest value in list }
  862. I := 0; { Start at first }
  863. While (I < 128) AND (Hi(KeyCode) <> AltCodes[I])
  864. Do Inc(I); { Search for match }
  865. If (I < 128) Then GetAltChar := Chr(I); { Return character }
  866. End Else
  867. If (Hi(KeyCode)=$02) Then GetAltChar := #240; { Return char }
  868. End;
  869. END;
  870. {---------------------------------------------------------------------------}
  871. { GetCtrlChar -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 25May96 LdB }
  872. {---------------------------------------------------------------------------}
  873. FUNCTION GetCtrlChar (KeyCode: Word): Char;
  874. VAR C: Char;
  875. BEGIN
  876. C := #0; { Preset #0 return }
  877. If (Lo(KeyCode) > 0) AND (Lo(KeyCode) <= 26) Then { Between 1-26 }
  878. C := Chr(Lo(KeyCode) + $40); { Return char A-Z }
  879. GetCtrlChar := C; { Return result }
  880. END;
  881. {---------------------------------------------------------------------------}
  882. { CtrlToArrow -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 25May96 LdB }
  883. {---------------------------------------------------------------------------}
  884. FUNCTION CtrlToArrow (KeyCode: Word): Word;
  885. CONST NumCodes = 11;
  886. CtrlCodes : Array [0..NumCodes-1] Of Char =
  887. (#19, #4, #5, #24, #1, #6, #7, #22, #18, #3, #8);
  888. ArrowCodes: Array [0..NumCodes-1] Of Sw_Word =
  889. (kbLeft, kbRight, kbUp, kbDown, kbHome, kbEnd, kbDel, kbIns,
  890. kbPgUp, kbPgDn, kbBack);
  891. VAR I: Sw_Integer;
  892. BEGIN
  893. CtrlToArrow := KeyCode; { Preset key return }
  894. For I := 0 To NumCodes - 1 Do
  895. If WordRec(KeyCode).Lo = Byte(CtrlCodes[I]) { Matches a code }
  896. Then Begin
  897. CtrlToArrow := ArrowCodes[I]; { Return key stroke }
  898. Exit; { Now exit }
  899. End;
  900. END;
  901. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  902. { KEYBOARD CONTROL ROUTINES }
  903. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  904. {---------------------------------------------------------------------------}
  905. { GetShiftState -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 08Jul96 LdB }
  906. {---------------------------------------------------------------------------}
  907. FUNCTION GetShiftState: Byte;
  908. begin
  909. GetShiftState:=Keyboard.GetKeyEventShiftState(Keyboard.PollShiftStateEvent);
  910. end;
  911. {---------------------------------------------------------------------------}
  912. { GetKeyEvent -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 19May98 LdB }
  913. {---------------------------------------------------------------------------}
  914. procedure GetKeyEvent (Var Event: TEvent);
  915. var
  916. key : TKeyEvent;
  917. keycode : Word;
  918. keyshift : byte;
  919. begin
  920. if Keyboard.PollKeyEvent<>0 then
  921. begin
  922. key:=Keyboard.GetKeyEvent;
  923. keycode:=Keyboard.GetKeyEventCode(key);
  924. keyshift:=KeyBoard.GetKeyEventShiftState(key);
  925. { fixup shift-keys }
  926. if keyshift and kbShift<>0 then
  927. begin
  928. case keycode of
  929. $5200 : keycode:=kbShiftIns;
  930. $5300 : keycode:=kbShiftDel;
  931. $8500 : keycode:=kbShiftF1;
  932. $8600 : keycode:=kbShiftF2;
  933. end;
  934. end
  935. { fixup ctrl-keys }
  936. else if keyshift and kbCtrl<>0 then
  937. begin
  938. case keycode of
  939. $5200,
  940. $9200 : keycode:=kbCtrlIns;
  941. $5300,
  942. $9300 : keycode:=kbCtrlDel;
  943. end;
  944. end
  945. { fixup alt-keys }
  946. else if keyshift and kbAlt<>0 then
  947. begin
  948. case keycode of
  949. $0e08,
  950. $0e00 : keycode:=kbAltBack;
  951. end;
  952. end
  953. { fixup normal keys }
  954. else
  955. begin
  956. case keycode of
  957. $e00d : keycode:=kbEnter;
  958. end;
  959. end;
  960. Event.What:=evKeyDown;
  961. Event.KeyCode:=keycode;
  962. {$ifdef ENDIAN_LITTLE}
  963. Event.CharCode:=chr(keycode and $ff);
  964. Event.ScanCode:=keycode shr 8;
  965. {$endif ENDIAN_LITTLE}
  966. Event.KeyShift:=keyshift;
  967. end
  968. else
  969. Event.What:=evNothing;
  970. end;
  971. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  972. { MOUSE CONTROL ROUTINES }
  973. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  974. {---------------------------------------------------------------------------}
  975. { HideMouse -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 30Jun98 LdB }
  976. {---------------------------------------------------------------------------}
  977. procedure HideMouse;
  978. begin
  979. { Is mouse hidden yet?
  980. If (HideCount = 0) Then}
  981. Mouse.HideMouse;
  982. { Inc(HideCount);}
  983. end;
  984. {---------------------------------------------------------------------------}
  985. { ShowMouse -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 30Jun98 LdB }
  986. {---------------------------------------------------------------------------}
  987. procedure ShowMouse;
  988. begin
  989. { if HideCount>0 then
  990. dec(HideCount);
  991. if (HideCount=0) then}
  992. Mouse.ShowMouse;
  993. end;
  994. {---------------------------------------------------------------------------}
  995. { GetMouseEvent -> Platforms DOS/DPMI/WINDOWS/OS2 - Updated 30Jun98 LdB }
  996. {---------------------------------------------------------------------------}
  997. procedure GetMouseEvent (Var Event: TEvent);
  998. var
  999. e : Mouse.TMouseEvent;
  1000. begin
  1001. if Mouse.PollMouseEvent(e) then
  1002. begin
  1003. Mouse.GetMouseEvent(e);
  1004. MouseWhere.X:=e.x;
  1005. MouseWhere.Y:=e.y;
  1006. Event.Double:=false;
  1007. case e.Action of
  1008. MouseActionMove :
  1009. Event.What:=evMouseMove;
  1010. MouseActionDown :
  1011. begin
  1012. Event.What:=evMouseDown;
  1013. if (DownButtons=e.Buttons) and (LastWhere.X=MouseWhere.X) and (LastWhere.Y=MouseWhere.Y) and
  1014. (GetDosTicks-DownTicks<=DoubleDelay) then
  1015. Event.Double:=true;
  1016. DownButtons:=e.Buttons;
  1017. DownWhere.X:=MouseWhere.x;
  1018. DownWhere.Y:=MouseWhere.y;
  1019. DownTicks:=GetDosTicks;
  1020. AutoTicks:=GetDosTicks;
  1021. if AutoTicks=0 then
  1022. AutoTicks:=1;
  1023. AutoDelay:=RepeatDelay;
  1024. end;
  1025. MouseActionUp :
  1026. begin
  1027. AutoTicks:=0;
  1028. Event.What:=evMouseUp;
  1029. AutoTicks:=0;
  1030. end;
  1031. end;
  1032. Event.Buttons:=e.Buttons;
  1033. Event.Where.X:=MouseWhere.x;
  1034. Event.Where.Y:=MouseWhere.y;
  1035. LastButtons:=Event.Buttons;
  1036. LastWhere.x:=Event.Where.x;
  1037. LastWhere.y:=Event.Where.y;
  1038. end
  1039. else if (AutoTicks <> 0) and (GetDosTicks >= AutoTicks + AutoDelay) then
  1040. begin
  1041. Event.What:=evMouseAuto;
  1042. Event.Buttons:=LastButtons;
  1043. Event.Where.X:=LastWhere.x;
  1044. Event.Where.Y:=LastWhere.y;
  1045. AutoTicks:=GetDosTicks;
  1046. AutoDelay:=1;
  1047. end
  1048. else
  1049. FillChar(Event,sizeof(TEvent),0);
  1050. end;
  1051. {---------------------------------------------------------------------------}
  1052. { GetSystemEvent }
  1053. {---------------------------------------------------------------------------}
  1054. procedure GetSystemEvent (Var Event: TEvent);
  1055. var
  1056. SysEvent : TsystemEvent;
  1057. begin
  1058. if PollSystemEvent(SysEvent) then
  1059. begin
  1060. SysMsg.GetSystemEvent(SysEvent);
  1061. case SysEvent.typ of
  1062. SysNothing :
  1063. Event.What:=evNothing;
  1064. SysSetFocus :
  1065. begin
  1066. Event.What:=evBroadcast;
  1067. Event.Command:=cmReceivedFocus;
  1068. end;
  1069. SysReleaseFocus :
  1070. begin
  1071. Event.What:=evBroadcast;
  1072. Event.Command:=cmReleasedFocus;
  1073. end;
  1074. SysClose :
  1075. begin
  1076. Event.What:=evCommand;
  1077. Event.Command:=cmQuitApp;
  1078. end;
  1079. SysResize :
  1080. begin
  1081. Event.What:=evCommand;
  1082. Event.Command:=cmResizeApp;
  1083. Event.Id:=SysEvent.x;
  1084. Event.InfoWord:=SysEvent.y;
  1085. end;
  1086. else
  1087. Event.What:=evNothing;
  1088. end;
  1089. end
  1090. else
  1091. Event.What:=evNothing;
  1092. end;
  1093. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  1094. { EVENT HANDLER CONTROL ROUTINES }
  1095. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  1096. {---------------------------------------------------------------------------}
  1097. { InitEvents -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 07Sep99 LdB }
  1098. {---------------------------------------------------------------------------}
  1099. PROCEDURE InitEvents;
  1100. BEGIN
  1101. If (ButtonCount <> 0) Then
  1102. begin { Mouse is available }
  1103. Mouse.InitMouse; { Hook the mouse }
  1104. { this is required by the use of HideCount variable }
  1105. Mouse.ShowMouse; { visible by default }
  1106. { HideCount:=0; }
  1107. LastButtons := 0; { Clear last buttons }
  1108. DownButtons := 0; { Clear down buttons }
  1109. MouseWhere.X:=Mouse.GetMouseX;
  1110. MouseWhere.Y:=Mouse.GetMouseY; { Get mouse position }
  1111. LastWhere.x:=MouseWhere.x;
  1112. LastWhereX:=MouseWhere.x;
  1113. LastWhere.y:=MouseWhere.y;
  1114. LastWhereY:=MouseWhere.y;
  1115. MouseEvents := True; { Set initialized flag }
  1116. end;
  1117. InitSystemMsg;
  1118. END;
  1119. {---------------------------------------------------------------------------}
  1120. { DoneEvents -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 30Jul99 LdB }
  1121. {---------------------------------------------------------------------------}
  1122. PROCEDURE DoneEvents;
  1123. BEGIN
  1124. DoneSystemMsg;
  1125. Mouse.DoneMouse;
  1126. MouseEvents:=false;
  1127. END;
  1128. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  1129. { VIDEO CONTROL ROUTINES }
  1130. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  1131. const
  1132. VideoInitialized : boolean = false;
  1133. {---------------------------------------------------------------------------}
  1134. { InitVideo -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 26Nov99 LdB }
  1135. {---------------------------------------------------------------------------}
  1136. PROCEDURE InitVideo;
  1137. VAR
  1138. StoreScreenMode : TVideoMode;
  1139. BEGIN
  1140. if VideoInitialized then
  1141. begin
  1142. StoreScreenMode:=ScreenMode;
  1143. DoneVideo;
  1144. end
  1145. else
  1146. StoreScreenMode.Col:=0;
  1147. Video.InitVideo;
  1148. GetVideoMode(StartupScreenMode);
  1149. GetVideoMode(ScreenMode);
  1150. {$ifdef win32}
  1151. { Force the console to the current screen mode }
  1152. Video.SetVideoMode(ScreenMode);
  1153. {$endif win32}
  1154. If (StoreScreenMode.Col<>0) and
  1155. ((StoreScreenMode.color<>ScreenMode.color) or
  1156. (StoreScreenMode.row<>ScreenMode.row) or
  1157. (StoreScreenMode.col<>ScreenMode.col)) then
  1158. begin
  1159. Video.SetVideoMode(StoreScreenMode);
  1160. GetVideoMode(ScreenMode);
  1161. end;
  1162. if ScreenWidth > MaxViewWidth then
  1163. ScreenWidth := MaxViewWidth;
  1164. ScreenWidth:=Video.ScreenWidth;
  1165. ScreenHeight:=Video.ScreenHeight;
  1166. VideoInitialized:=true;
  1167. END;
  1168. {---------------------------------------------------------------------------}
  1169. { DoneVideo -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 19May98 LdB }
  1170. {---------------------------------------------------------------------------}
  1171. PROCEDURE DoneVideo;
  1172. BEGIN
  1173. if not VideoInitialized then
  1174. exit;
  1175. Video.SetVideoMode(StartupScreenMode);
  1176. Video.ClearScreen;
  1177. Video.SetCursorPos(0,0);
  1178. Video.DoneVideo;
  1179. VideoInitialized:=false;
  1180. END;
  1181. {---------------------------------------------------------------------------}
  1182. { ClearScreen -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 04Jan97 LdB }
  1183. {---------------------------------------------------------------------------}
  1184. PROCEDURE ClearScreen;
  1185. BEGIN
  1186. Video.ClearScreen;
  1187. END;
  1188. {---------------------------------------------------------------------------}
  1189. { SetVideoMode -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 10Nov99 LdB }
  1190. {---------------------------------------------------------------------------}
  1191. PROCEDURE SetVideoMode (Mode: Sw_Word);
  1192. BEGIN
  1193. END;
  1194. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  1195. { ERROR CONTROL ROUTINES }
  1196. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  1197. {---------------------------------------------------------------------------}
  1198. { InitSysError -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 20May98 LdB }
  1199. {---------------------------------------------------------------------------}
  1200. PROCEDURE InitSysError;
  1201. BEGIN
  1202. SysErrActive := True; { Set active flag }
  1203. END;
  1204. {---------------------------------------------------------------------------}
  1205. { DoneSysError -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 20May98 LdB }
  1206. {---------------------------------------------------------------------------}
  1207. PROCEDURE DoneSysError;
  1208. BEGIN
  1209. SysErrActive := False; { Clear active flag }
  1210. END;
  1211. {---------------------------------------------------------------------------}
  1212. { SystemError -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 20May98 LdB }
  1213. {---------------------------------------------------------------------------}
  1214. FUNCTION SystemError (ErrorCode: Sw_Integer; Drive: Byte): Sw_Integer;
  1215. BEGIN
  1216. If (FailSysErrors = False) Then Begin { Check error ignore }
  1217. End Else SystemError := 1; { Return 1 for ignored }
  1218. END;
  1219. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  1220. { STRING FORMAT ROUTINES }
  1221. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  1222. {---------------------------------------------------------------------------}
  1223. { PrintStr -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18Feb99 LdB }
  1224. {---------------------------------------------------------------------------}
  1225. PROCEDURE PrintStr (CONST S: String);
  1226. BEGIN
  1227. Write(S); { Write to screen }
  1228. END;
  1229. {---------------------------------------------------------------------------}
  1230. { FormatStr -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 13Jul99 LdB }
  1231. {---------------------------------------------------------------------------}
  1232. procedure FormatStr (Var Result: String; CONST Format: String; Var Params);
  1233. TYPE TLongArray = Array[0..0] Of PtrInt;
  1234. VAR W, ResultLength : integer;
  1235. FormatIndex, Justify, Wth: Byte;
  1236. Fill: Char; S: String;
  1237. FUNCTION LongToStr (L: Longint; Radix: Byte): String;
  1238. CONST HexChars: Array[0..15] Of Char =
  1239. ('0', '1', '2', '3', '4', '5', '6', '7',
  1240. '8', '9', 'A', 'B', 'C', 'D', 'E', 'F');
  1241. VAR I: LongInt; S: String; Sign: String[1];
  1242. begin
  1243. LongToStr := ''; { Preset empty return }
  1244. If (L < 0) Then begin { If L is negative }
  1245. Sign := '-'; { Sign is negative }
  1246. L := Abs(L); { Convert to positive }
  1247. end Else Sign := ''; { Sign is empty }
  1248. S := ''; { Preset empty string }
  1249. Repeat
  1250. I := L MOD Radix; { Radix mod of value }
  1251. S := HexChars[I] + S; { Add char to string }
  1252. L := L DIV Radix; { Divid by radix }
  1253. Until (L = 0); { Until no remainder }
  1254. LongToStr := Sign + S; { Return result }
  1255. end;
  1256. procedure HandleParameter (I : LongInt);
  1257. begin
  1258. While (FormatIndex <= Length(Format)) Do begin { While length valid }
  1259. if ResultLength>=High(Result) then
  1260. exit;
  1261. While (FormatIndex <= Length(Format)) and
  1262. (Format[FormatIndex] <> '%') { Param char not found }
  1263. Do begin
  1264. Result[ResultLength+1] := Format[FormatIndex]; { Transfer character }
  1265. Inc(ResultLength); { One character added }
  1266. Inc(FormatIndex); { Next param char }
  1267. end;
  1268. If (FormatIndex < Length(Format)) and { Not last char and }
  1269. (Format[FormatIndex] = '%') Then begin { '%' char found }
  1270. Fill := ' '; { Default fill char }
  1271. Justify := 0; { Default justify }
  1272. Wth := 0; { Default 0=no width }
  1273. Inc(FormatIndex); { Next character }
  1274. If (Format[FormatIndex] = '0') Then
  1275. Fill := '0'; { Fill char to zero }
  1276. If (Format[FormatIndex] = '-') Then begin { Optional just char }
  1277. Justify := 1; { Right justify }
  1278. Inc(FormatIndex); { Next character }
  1279. end;
  1280. While ((FormatIndex <= Length(Format)) and { Length still valid }
  1281. (Format[FormatIndex] >= '0') and
  1282. (Format[FormatIndex] <= '9')) Do begin { Numeric character }
  1283. Wth := Wth * 10; { Multiply x10 }
  1284. Wth := Wth + Ord(Format[FormatIndex])-$30; { Add numeric value }
  1285. Inc(FormatIndex); { Next character }
  1286. end;
  1287. If ((FormatIndex <= Length(Format)) and { Length still valid }
  1288. (Format[FormatIndex] = '#')) Then begin { Parameter marker }
  1289. Inc(FormatIndex); { Next character }
  1290. HandleParameter(Wth); { Width is param idx }
  1291. end;
  1292. If (FormatIndex <= Length(Format)) Then begin{ Length still valid }
  1293. Case Format[FormatIndex] Of
  1294. '%': begin { Literal % }
  1295. S := '%';
  1296. Inc(FormatIndex);
  1297. Move(S[1], Result[ResultLength+1], 1);
  1298. Inc(ResultLength,Length(S));
  1299. Continue;
  1300. end;
  1301. 'c': S := Char(TLongArray(Params)[I]); { Character parameter }
  1302. 'd': S := LongToStr(TLongArray(Params)[I],
  1303. 10); { Decimal parameter }
  1304. 's': S := PString(TLongArray(Params)[I])^;{ String parameter }
  1305. 'x': S := LongToStr(TLongArray(Params)[I],
  1306. 16); { Hex parameter }
  1307. end;
  1308. Inc(FormatIndex); { Next character }
  1309. If (Wth > 0) Then begin { Width control active }
  1310. If (Length(S) > Wth) Then begin { We must shorten S }
  1311. If (Justify=1) Then { Check right justify }
  1312. S := Copy(S, Length(S)-Wth+1, Wth) { Take right side data }
  1313. Else S := Copy(S, 1, Wth); { Take left side data }
  1314. end Else begin { We must pad out S }
  1315. If (Justify=1) Then { Right justify }
  1316. While (Length(S) < Wth) Do
  1317. S := S+Fill Else { Right justify fill }
  1318. While (Length(S) < Wth) Do
  1319. S := Fill + S; { Left justify fill }
  1320. end;
  1321. end;
  1322. W:=Length(S);
  1323. if W+ResultLength+1>High(Result) then
  1324. W:=High(Result)-ResultLength;
  1325. Move(S[1], Result[ResultLength+1],
  1326. W); { Move data to result }
  1327. Inc(ResultLength,W); { Adj result length }
  1328. Inc(I);
  1329. end;
  1330. end;
  1331. end;
  1332. end;
  1333. begin
  1334. ResultLength := 0; { Zero result length }
  1335. FormatIndex := 1; { Format index to 1 }
  1336. HandleParameter(0); { Handle parameter }
  1337. Result[0] := Chr(ResultLength); { Set string length }
  1338. end;
  1339. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  1340. { NEW QUEUED EVENT HANDLER ROUTINES }
  1341. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  1342. {---------------------------------------------------------------------------}
  1343. { PutEventInQueue -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 17Mar98 LdB }
  1344. {---------------------------------------------------------------------------}
  1345. FUNCTION PutEventInQueue (Var Event: TEvent): Boolean;
  1346. BEGIN
  1347. If (QueueCount < QueueMax) Then Begin { Check room in queue }
  1348. Queue[QueueHead] := Event; { Store event }
  1349. Inc(QueueHead); { Inc head position }
  1350. If (QueueHead = QueueMax) Then QueueHead := 0; { Roll to start check }
  1351. Inc(QueueCount); { Inc queue count }
  1352. PutEventInQueue := True; { Return successful }
  1353. End Else PutEventInQueue := False; { Return failure }
  1354. END;
  1355. {---------------------------------------------------------------------------}
  1356. { NextQueuedEvent -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 17Mar98 LdB }
  1357. {---------------------------------------------------------------------------}
  1358. PROCEDURE NextQueuedEvent(Var Event: TEvent);
  1359. BEGIN
  1360. If (QueueCount > 0) Then Begin { Check queued event }
  1361. Event := Queue[QueueTail]; { Fetch next event }
  1362. Inc(QueueTail); { Inc tail position }
  1363. If (QueueTail = QueueMax) Then QueueTail := 0; { Roll to start check }
  1364. Dec(QueueCount); { Dec queue count }
  1365. End Else Event.What := evNothing; { Return empty event }
  1366. END;
  1367. {***************************************************************************}
  1368. { UNIT INITIALIZATION ROUTINE }
  1369. {***************************************************************************}
  1370. BEGIN
  1371. ButtonCount := DetectMouse; { Detect mouse }
  1372. DetectVideo; { Detect video }
  1373. InitKeyboard;
  1374. InitSystemMsg;
  1375. {$ifdef win32}
  1376. SetFileApisToOEM;
  1377. {$endif}
  1378. SaveExit := ExitProc; { Save old exit }
  1379. ExitProc := @ExitDrivers; { Set new exit }
  1380. END.
  1381. {
  1382. $Log$
  1383. Revision 1.51 2004-12-23 16:19:57 peter
  1384. add uses dos for OS_DOS
  1385. Revision 1.50 2004/12/22 15:27:30 peter
  1386. * call giveuptimeslice to prevent busy loop with idle
  1387. Revision 1.49 2004/12/18 16:18:47 peter
  1388. win32 fixes
  1389. Revision 1.48 2004/12/06 19:23:55 peter
  1390. don't set CP 437
  1391. Revision 1.47 2004/12/04 23:06:52 peter
  1392. * fix valgrind warning in formatstr
  1393. Revision 1.46 2004/12/04 18:40:47 peter
  1394. * FormatStr fixed to prevent buffer overflows
  1395. Revision 1.45 2004/11/24 21:03:05 florian
  1396. * increased max. possible screen/view width to 255
  1397. Revision 1.44 2004/11/06 19:19:30 armin
  1398. * added targets netware and netwlibc
  1399. Revision 1.43 2004/11/06 17:08:48 peter
  1400. * drawing of tview merged from old fv code
  1401. }