drivers.pas 75 KB

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