drivers.pas 67 KB

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