drivers.pas 69 KB

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