drivers.pas 68 KB

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