drivers.pas 82 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816
  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. video,
  77. {$ifdef HasSysMsgUnit}
  78. SysMsg,
  79. {$endif HasSysMsgUnit}
  80. {$IFDEF GRAPH_API} { GRAPH CODE }
  81. Graph, { Standard unit }
  82. {$ENDIF}
  83. GFVGraph, { GFV graphics unit }
  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 = PACKED RECORD
  225. What: Sw_Word; { Event type }
  226. Case Sw_Word Of
  227. evNothing: (); { ** NO EVENT ** }
  228. evMouse: (
  229. Buttons: Byte; { Mouse buttons }
  230. Double: Boolean; { Double click state }
  231. Where: TPoint); { Mouse position }
  232. evKeyDown: (
  233. { ** KEY EVENT ** }
  234. Case Sw_Integer Of
  235. 0: (KeyCode: Word); { Full key code }
  236. 1: (
  237. {$ifdef ENDIAN_BIG}
  238. ScanCode: Byte;
  239. CharCode: Char;
  240. {$else not ENDIAN_BIG}
  241. CharCode: Char; { Char code }
  242. ScanCode: Byte; { Scan code }
  243. {$endif not ENDIAN_BIG}
  244. KeyShift: byte)); { Shift states }
  245. evMessage: ( { ** MESSAGE EVENT ** }
  246. Command: Sw_Word; { Message command }
  247. Id : Sw_Word; { Message id }
  248. Data : Real; { Message data }
  249. Case Sw_Word Of
  250. 0: (InfoPtr: Pointer); { Message pointer }
  251. 1: (InfoLong: Longint); { Message longint }
  252. 2: (InfoWord: Word); { Message Sw_Word }
  253. 3: (InfoInt: Integer); { Message Sw_Integer }
  254. 4: (InfoByte: Byte); { Message byte }
  255. 5: (InfoChar: Char)); { Message character }
  256. END;
  257. PEvent = ^TEvent;
  258. {$ifdef USE_VIDEO_API}
  259. TVideoMode = Video.TVideoMode; { Screen mode }
  260. {$else not USE_VIDEO_API}
  261. TVideoMode = Sw_Word; { Screen mode }
  262. {$endif USE_VIDEO_API}
  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. {$ifdef HasSysMsgUnit}
  385. {-GetSystemEvent------------------------------------------------------
  386. Checks whether a system event is available. If a system event has occurred,
  387. Event.What is set to evCommand appropriately
  388. 10Oct2000 PM
  389. ---------------------------------------------------------------------}
  390. procedure GetSystemEvent (Var Event: TEvent);
  391. {$endif HasSysMsgUnit}
  392. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  393. { EVENT HANDLER CONTROL ROUTINES }
  394. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  395. {-InitEvents---------------------------------------------------------
  396. Initializes the event manager, enabling the mouse handler routine and
  397. under DOS/DPMI shows the mouse on screen. It is called automatically
  398. by TApplication.Init.
  399. 02May98 LdB
  400. ---------------------------------------------------------------------}
  401. PROCEDURE InitEvents;
  402. {-DoneEvents---------------------------------------------------------
  403. Terminates event manager and disables the mouse and under DOS hides
  404. the mouse. It is called automatically by TApplication.Done.
  405. 02May98 LdB
  406. ---------------------------------------------------------------------}
  407. PROCEDURE DoneEvents;
  408. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  409. { VIDEO CONTROL ROUTINES }
  410. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  411. {-InitVideo---------------------------------------------------------
  412. Initializes the video manager, Saves the current screen mode in
  413. StartupMode, and switches to the mode indicated by ScreenMode.
  414. 19May98 LdB
  415. ---------------------------------------------------------------------}
  416. PROCEDURE InitVideo;
  417. {-DoneVideo---------------------------------------------------------
  418. Terminates the video manager by restoring the initial screen mode
  419. (given by StartupMode), clearing the screen, and restoring the cursor.
  420. Called automatically by TApplication.Done.
  421. 03Jan97 LdB
  422. ---------------------------------------------------------------------}
  423. PROCEDURE DoneVideo;
  424. {-ClearScreen--------------------------------------------------------
  425. Does nothing provided for compatability purposes only.
  426. 04Jan97 LdB
  427. ---------------------------------------------------------------------}
  428. PROCEDURE ClearScreen;
  429. {-SetVideoMode-------------------------------------------------------
  430. Does nothing provided for compatability purposes only.
  431. 04Jan97 LdB
  432. ---------------------------------------------------------------------}
  433. PROCEDURE SetVideoMode (Mode: Sw_Word);
  434. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  435. { ERROR CONTROL ROUTINES }
  436. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  437. {-InitSysError-------------------------------------------------------
  438. Error handling is not yet implemented so this simply sets
  439. SysErrActive=True (ie it lies) and exits.
  440. 20May98 LdB
  441. ---------------------------------------------------------------------}
  442. PROCEDURE InitSysError;
  443. {-DoneSysError-------------------------------------------------------
  444. Error handling is not yet implemented so this simply sets
  445. SysErrActive=False and exits.
  446. 20May98 LdB
  447. ---------------------------------------------------------------------}
  448. PROCEDURE DoneSysError;
  449. {-SystemError---------------------------------------------------------
  450. Error handling is not yet implemented so this simply drops through.
  451. 20May98 LdB
  452. ---------------------------------------------------------------------}
  453. FUNCTION SystemError (ErrorCode: Sw_Integer; Drive: Byte): Sw_Integer;
  454. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  455. { STRING FORMAT ROUTINES }
  456. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  457. {-PrintStr-----------------------------------------------------------
  458. Does nothing provided for compatability purposes only.
  459. 30Jun98 LdB
  460. ---------------------------------------------------------------------}
  461. PROCEDURE PrintStr (CONST S: String);
  462. {-FormatStr----------------------------------------------------------
  463. A string formatting routine that given a string that includes format
  464. specifiers and a list of parameters in Params, FormatStr produces a
  465. formatted output string in Result.
  466. 18Feb99 LdB
  467. ---------------------------------------------------------------------}
  468. PROCEDURE FormatStr (Var Result: String; CONST Format: String; Var Params);
  469. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  470. { >> NEW QUEUED EVENT HANDLER ROUTINES << }
  471. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  472. {-PutEventInQueue-----------------------------------------------------
  473. If there is room in the queue the event is placed in the next vacant
  474. position in the queue manager.
  475. 17Mar98 LdB
  476. ---------------------------------------------------------------------}
  477. FUNCTION PutEventInQueue (Var Event: TEvent): Boolean;
  478. {-NextQueuedEvent----------------------------------------------------
  479. If there are queued events the next event is loaded into event else
  480. evNothing is returned.
  481. 17Mar98 LdB
  482. ---------------------------------------------------------------------}
  483. PROCEDURE NextQueuedEvent(Var Event: TEvent);
  484. {***************************************************************************}
  485. { INITIALIZED PUBLIC VARIABLES }
  486. {***************************************************************************}
  487. PROCEDURE HideMouseCursor;
  488. PROCEDURE ShowMouseCursor;
  489. {---------------------------------------------------------------------------}
  490. { INITIALIZED DOS/DPMI/WIN/NT/OS2 VARIABLES }
  491. {---------------------------------------------------------------------------}
  492. CONST
  493. CheckSnow : Boolean = False; { Compatability only }
  494. MouseEvents : Boolean = False; { Mouse event state }
  495. MouseReverse : Boolean = False; { Mouse reversed }
  496. HiResScreen : Boolean = False; { Compatability only }
  497. CtrlBreakHit : Boolean = False; { Compatability only }
  498. SaveCtrlBreak: Boolean = False; { Compatability only }
  499. SysErrActive : Boolean = False; { Compatability only }
  500. FailSysErrors: Boolean = False; { Compatability only }
  501. ButtonCount : Byte = 0; { Mouse button count }
  502. DoubleDelay : Sw_Word = 8; { Double click delay }
  503. RepeatDelay : Sw_Word = 8; { Auto mouse delay }
  504. SysColorAttr : Sw_Word = $4E4F; { System colour attr }
  505. SysMonoAttr : Sw_Word = $7070; { System mono attr }
  506. StartupMode : Sw_Word = $FFFF; { Compatability only }
  507. CursorLines : Sw_Word = $FFFF; { Compatability only }
  508. ScreenBuffer : Pointer = Nil; { Compatability only }
  509. SaveInt09 : Pointer = Nil; { Compatability only }
  510. SysErrorFunc : TSysErrorFunc = {$ifdef FPC}@{$endif}SystemError; { System error ptr }
  511. {---------------------------------------------------------------------------}
  512. { >>> NEW INITIALIZED DOS/DPMI/WIN/NT/OS2 VARIABLES <<< }
  513. {---------------------------------------------------------------------------}
  514. CONST
  515. TextModeGFV : Boolean = False; { DOS/DPMI textmode op }
  516. UseFixedFont : Boolean = True;
  517. DefLineNum : Sw_Integer = 25; { Default line number }
  518. DefFontHeight : Sw_Integer = 0; { Default font height }
  519. SysFontWidth : Sw_Integer = 8; { System font width }
  520. SysFontHeight : Sw_Integer = 16; { System font height }
  521. {***************************************************************************}
  522. { UNINITIALIZED PUBLIC VARIABLES }
  523. {***************************************************************************}
  524. {---------------------------------------------------------------------------}
  525. { UNINITIALIZED DOS/DPMI/WIN/NT/OS2 VARIABLES }
  526. {---------------------------------------------------------------------------}
  527. VAR
  528. MouseIntFlag: Byte; { Mouse in int flag }
  529. MouseButtons: Byte; { Mouse button state }
  530. ScreenWidth : Byte; { Screen text width }
  531. ScreenHeight: Byte; { Screen text height }
  532. {$IFNDEF Use_Video_API}
  533. ScreenMode : Sw_Word; { Screen mode }
  534. {$Else Use_Video_API}
  535. ScreenMode : TVideoMode; { Screen mode }
  536. {$Endif Use_Video_API}
  537. MouseWhere : TPoint; { Mouse position }
  538. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  539. IMPLEMENTATION
  540. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  541. { API Units }
  542. USES
  543. FVConsts,
  544. {$IFDEF GRAPH_API} { GRAPH CODE }
  545. {$ifdef win32}
  546. win32gr,
  547. {$endif}
  548. {$ENDIF GRAPH_API} { GRAPH CODE }
  549. Keyboard,Mouse;
  550. {***************************************************************************}
  551. { PRIVATE INTERNAL CONSTANTS }
  552. {***************************************************************************}
  553. {---------------------------------------------------------------------------}
  554. { DOS/DPMI MOUSE INTERRUPT EVENT QUEUE SIZE }
  555. {---------------------------------------------------------------------------}
  556. CONST EventQSize = 16; { Default int bufsize }
  557. {---------------------------------------------------------------------------}
  558. { DOS/DPMI/WIN/NT/OS2 NEW EVENT QUEUE MAX SIZE }
  559. {---------------------------------------------------------------------------}
  560. CONST QueueMax = 64; { Max new queue size }
  561. {---------------------------------------------------------------------------}
  562. { MAX WIEW WIDTH to avoid TDrawBuffer overrun in views unit }
  563. {---------------------------------------------------------------------------}
  564. CONST MaxViewWidth = 132; { Max view width }
  565. {***************************************************************************}
  566. { PRIVATE INTERNAL TYPES }
  567. {***************************************************************************}
  568. {***************************************************************************}
  569. { PRIVATE INTERNAL INITIALIZED VARIABLES }
  570. {***************************************************************************}
  571. {---------------------------------------------------------------------------}
  572. { DOS/DPMI/WIN/NT/OS2 ALT KEY SCANCODES FROM KEYS (0-127) }
  573. {---------------------------------------------------------------------------}
  574. CONST AltCodes: Array [0..127] Of Byte = (
  575. $00, $00, $00, $00, $00, $00, $00, $00, { $00 - $07 }
  576. $00, $00, $00, $00, $00, $00, $00, $00, { $08 - $0F }
  577. $00, $00, $00, $00, $00, $00, $00, $00, { $10 - $17 }
  578. $00, $00, $00, $00, $00, $00, $00, $00, { $18 - $1F }
  579. $00, $00, $00, $00, $00, $00, $00, $00, { $20 - $27 }
  580. $00, $00, $00, $00, $00, $82, $00, $00, { $28 - $2F }
  581. $81, $78, $79, $7A, $7B, $7C, $7D, $7E, { $30 - $37 }
  582. $7F, $80, $00, $00, $00, $83, $00, $00, { $38 - $3F }
  583. $00, $1E, $30, $2E, $20, $12, $21, $22, { $40 - $47 }
  584. $23, $17, $24, $25, $26, $32, $31, $18, { $48 - $4F }
  585. $19, $10, $13, $1F, $14, $16, $2F, $11, { $50 - $57 }
  586. $2D, $15, $2C, $00, $00, $00, $00, $00, { $58 - $5F }
  587. $00, $00, $00, $00, $00, $00, $00, $00, { $60 - $67 }
  588. $00, $00, $00, $00, $00, $00, $00, $00, { $68 - $6F }
  589. $00, $00, $00, $00, $00, $00, $00, $00, { $70 - $77 }
  590. $00, $00, $00, $00, $00, $00, $00, $00); { $78 - $7F }
  591. {***************************************************************************}
  592. { PRIVATE INTERNAL INITIALIZED VARIABLES }
  593. {***************************************************************************}
  594. {---------------------------------------------------------------------------}
  595. { NEW CONTROL VARIABLES }
  596. {---------------------------------------------------------------------------}
  597. CONST
  598. HideCount : Sw_Integer = 0; { Cursor hide count }
  599. QueueCount: Sw_Word = 0; { Queued message count }
  600. QueueHead : Sw_Word = 0; { Queue head pointer }
  601. QueueTail : Sw_Word = 0; { Queue tail pointer }
  602. {***************************************************************************}
  603. { PRIVATE INTERNAL UNINITIALIZED VARIABLES }
  604. {***************************************************************************}
  605. {---------------------------------------------------------------------------}
  606. { UNINITIALIZED DOS/DPMI/API VARIABLES }
  607. {---------------------------------------------------------------------------}
  608. VAR
  609. LastDouble : Boolean; { Last double buttons }
  610. LastButtons: Byte; { Last button state }
  611. DownButtons: Byte; { Last down buttons }
  612. EventCount : Sw_Word; { Events in queue }
  613. AutoDelay : Sw_Word; { Delay time count }
  614. DownTicks : Sw_Word; { Down key tick count }
  615. AutoTicks : Sw_Word; { Held key tick count }
  616. LastWhereX : Sw_Word; { Last x position }
  617. LastWhereY : Sw_Word; { Last y position }
  618. DownWhereX : Sw_Word; { Last x position }
  619. DownWhereY : Sw_Word; { Last y position }
  620. LastWhere : TPoint; { Last mouse position }
  621. DownWhere : TPoint; { Last down position }
  622. EventQHead : Pointer; { Head of queue }
  623. EventQTail : Pointer; { Tail of queue }
  624. EventQueue : Array [0..EventQSize - 1] Of TEvent; { Event queue }
  625. EventQLast : RECORD END; { Simple end marker }
  626. {---------------------------------------------------------------------------}
  627. { GetDosTicks (18.2 Hz) }
  628. {---------------------------------------------------------------------------}
  629. Function GetDosTicks:longint; { returns ticks at 18.2 Hz, just like DOS }
  630. {$IFDEF OS_OS2}
  631. const
  632. QSV_MS_COUNT = 14;
  633. var
  634. L: longint;
  635. begin
  636. DosQuerySysInfo (QSV_MS_COUNT, QSV_MS_COUNT, L, 4);
  637. GetDosTicks := L div 55;
  638. end;
  639. {$ENDIF}
  640. {$IFDEF OS_UNIX}
  641. var
  642. tv : TimeVal;
  643. { tz : TimeZone;}
  644. begin
  645. {$ifdef ver1_0}
  646. GetTimeOfDay(tv{,tz});
  647. GetDosTicks:=((tv.Sec mod 86400) div 60)*1092+((tv.Sec mod 60)*1000000+tv.USec) div 54945;
  648. {$else}
  649. FPGetTimeOfDay(@tv,nil{,tz});
  650. GetDosTicks:=((tv.tv_Sec mod 86400) div 60)*1092+((tv.tv_Sec mod 60)*1000000+tv.tv_USec) div 54945;
  651. {$endif}
  652. end;
  653. {$ENDIF OS_UNIX}
  654. {$IFDEF OS_WINDOWS}
  655. begin
  656. GetDosTicks:=GetTickCount div 55;
  657. end;
  658. {$ENDIF OS_WINDOWS}
  659. {$IFDEF OS_DOS}
  660. begin
  661. GetDosTicks:=MemL[$40:$6c];
  662. end;
  663. {$ENDIF OS_DOS}
  664. {---------------------------------------------------------------------------}
  665. { UNINITIALIZED DOS/DPMI/WIN/NT/OS2 VARIABLES }
  666. {---------------------------------------------------------------------------}
  667. VAR
  668. SaveExit: Pointer; { Saved exit pointer }
  669. Queue : Array [0..QueueMax-1] Of TEvent; { New message queue }
  670. {***************************************************************************}
  671. { PRIVATE INTERNAL ROUTINES }
  672. {***************************************************************************}
  673. PROCEDURE ShowMouseCursor;
  674. BEGIN
  675. ShowMouse;
  676. END;
  677. PROCEDURE HideMouseCursor;
  678. BEGIN
  679. HideMouse;
  680. END;
  681. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  682. { DOS/DPMI/WIN/NT/OS2 PRIVATE INTERNAL ROUTINES }
  683. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  684. {---------------------------------------------------------------------------}
  685. { ExitDrivers -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 08Jun98 LdB }
  686. {---------------------------------------------------------------------------}
  687. PROCEDURE ExitDrivers; {$IFNDEF PPC_FPC}{$IFNDEF OS_UNIX} FAR; {$ENDIF}{$ENDIF}
  688. BEGIN
  689. DoneSysError; { Relase error trap }
  690. DoneEvents; { Close event driver }
  691. DoneKeyboard;
  692. DoneVideo;
  693. ExitProc := SaveExit; { Restore old exit }
  694. END;
  695. {---------------------------------------------------------------------------}
  696. { DetectVideo -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 19May98 LdB }
  697. {---------------------------------------------------------------------------}
  698. {$IFDEF Use_Video_API}
  699. procedure DetectVideo;
  700. VAR
  701. CurrMode : TVideoMode;
  702. begin
  703. { Video.InitVideo; Incompatible with BP
  704. and forces a screen clear which is often a bad thing PM }
  705. GetVideoMode(CurrMode);
  706. ScreenMode:=CurrMode;
  707. end;
  708. {$else not Use_Video_API}
  709. PROCEDURE DetectVideo;
  710. {$IFDEF OS_DOS} { DOS/DPMI CODE }
  711. ASSEMBLER;
  712. {$IFDEF ASM_BP} { BP COMPATABLE ASM }
  713. ASM
  714. MOV AH, $0F; { Set function id }
  715. PUSH BP; { Safety!! save reg }
  716. INT $10; { Get current crt mode }
  717. POP BP; { Restore register }
  718. PUSH AX; { Hold result }
  719. MOV AX, $1130; { Set function id }
  720. MOV BH, 0; { Zero register }
  721. MOV DL, 0; { Zero register }
  722. PUSH BP; { Safety!! save reg }
  723. INT $10; { Get ext-video mode }
  724. POP BP; { Restore register }
  725. POP AX; { Recover held value }
  726. MOV DH, AH; { Transfer high mode }
  727. CMP DL, 25; { Check screen ht }
  728. SBB AH, AH; { Subtract borrow }
  729. INC AH; { Make #1 if in high }
  730. MOV CL, 1; { Preset value of 1 }
  731. OR DL, DL; { Test for zero }
  732. JNZ @@1; { Branch if not zero }
  733. MOV CL, 0 { Set value to zero }
  734. MOV DL, 24; { Zero = 24 lines }
  735. @@1:
  736. INC DL; { Add one line }
  737. MOV ScreenWidth, DH; { Hold screen width }
  738. MOV ScreenHeight, DL; { Hold screen height }
  739. MOV HiResScreen, CL; { Set hires mask }
  740. CMP AL, smMono; { Is screen mono }
  741. JZ @@Exit1; { Exit of mono }
  742. CMP AL, smBW80; { Is screen B&W }
  743. JZ @@Exit1; { Exit if B&W }
  744. MOV AX, smCO80; { Else set to colour }
  745. @@Exit1:
  746. MOV ScreenMode, AX; { Hold screen mode }
  747. END;
  748. {$ENDIF}
  749. {$IFDEF ASM_FPC} { FPC COMPATABLE ASM }
  750. ASM
  751. MOVB $0x0F, %AH; { Set function id }
  752. PUSHL %EBP; { Save register }
  753. INT $0x10; { Get current crt mode }
  754. POPL %EBP; { Restore register }
  755. PUSHL %EAX; { Hold result }
  756. MOVW $0x1130, %AX; { Set function id }
  757. MOVB $0, %BH; { Zero register }
  758. MOVB $0, %DL; { Zero register }
  759. PUSHL %EBP; { Safety!! save reg }
  760. INT $0x10; { Get ext-video mode }
  761. POPL %EBP; { Restore register }
  762. POPL %EAX; { Recover held value }
  763. MOVB %AH, %DH; { Transfer high mode }
  764. CMPB $25, %DL; { Check screen ht }
  765. SBB %AH, %AH; { Subtract borrow }
  766. INCB %AH; { Make #1 if in high }
  767. MOVB $1, %CL; { Preset value of 1 }
  768. ORB %DL, %DL; { Test for zero }
  769. JNZ .L_JMP1; { Branch if not zero }
  770. MOVB $0, %CL; { Set value to zero }
  771. MOVB $24, %DL; { Zero = 24 lines }
  772. .L_JMP1:
  773. INCB %DL; { Add one line }
  774. MOVB %DH, SCREENWIDTH; { Hold screen width }
  775. MOVB %DL, SCREENHEIGHT; { Hold screen height }
  776. MOVB %CL, HIRESSCREEN; { Set hires mask }
  777. CMPB $07, %AL; { Is screen mono }
  778. JZ .L_Exit1; { Exit of mono }
  779. CMPB $02, %AL; { Is screen B&W }
  780. JZ .L_Exit1; { Exit if B&W }
  781. MOVW $03, %AX; { Else set to colour }
  782. .L_Exit1:
  783. MOVW %AX, SCREENMODE; { Hold screen mode }
  784. END;
  785. {$ENDIF}
  786. {$ENDIF}
  787. {$IFDEF OS_WINDOWS} { WIN/NT CODE }
  788. VAR Dc: HDC;
  789. BEGIN
  790. Dc := GetDc(0); { Get screen context }
  791. If ((GetDeviceCaps(Dc, BitsPixel) > 1) OR { Colour capacity }
  792. (GetDeviceCaps(Dc, Planes) > 1)) Then { Colour capacity }
  793. ScreenMode := smCO80 Else ScreenMode := smMono; { Screen mode }
  794. ReleaseDc(0, Dc); { Release context }
  795. END;
  796. {$ENDIF}
  797. {$IFDEF OS_OS2} { OS2 CODE }
  798. VAR Ps: Hps; Dc: Hdc; Colours: LongInt;
  799. BEGIN
  800. Ps := WinGetPS(HWND_Desktop); { Get desktop PS }
  801. Dc := GpiQueryDevice(Ps); { Get gpi context }
  802. DevQueryCaps(Dc, Caps_Phys_Colors, 1, Colours); { Colour capacity }
  803. If (Colours> 2) Then ScreenMode := smCO80 { Colour screen }
  804. Else ScreenMode := smMono; { Mono screen }
  805. WinReleasePS(Ps); { Release desktop PS }
  806. END;
  807. {$ENDIF}
  808. {$endif not Use_Video_API}
  809. {---------------------------------------------------------------------------}
  810. { DetectMouse -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 19May98 LdB }
  811. FUNCTION DetectMouse: Byte;
  812. begin
  813. DetectMouse:=Mouse.DetectMouse;
  814. end;
  815. {***************************************************************************}
  816. { INTERFACE ROUTINES }
  817. {***************************************************************************}
  818. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  819. { BUFFER MOVE ROUTINES }
  820. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  821. {---------------------------------------------------------------------------}
  822. { CStrLen -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 25May96 LdB }
  823. {---------------------------------------------------------------------------}
  824. FUNCTION CStrLen (Const S: String): Sw_Integer;
  825. VAR I, J: Sw_Integer;
  826. BEGIN
  827. J := 0; { Set result to zero }
  828. For I := 1 To Length(S) Do
  829. If (S[I] <> '~') Then Inc(J); { Inc count if not ~ }
  830. CStrLen := J; { Return length }
  831. END;
  832. {---------------------------------------------------------------------------}
  833. { MoveStr -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 10Jul99 LdB }
  834. {---------------------------------------------------------------------------}
  835. PROCEDURE MoveStr (Var Dest; Const Str: String; Attr: Byte);
  836. VAR I: Word; P: PWord;
  837. BEGIN
  838. For I := 1 To Length(Str) Do Begin { For each character }
  839. P := @TWordArray(Dest)[I-1]; { Pointer to Sw_Word }
  840. If (Attr <> 0) Then WordRec(P^).Hi := Attr; { Copy attribute }
  841. WordRec(P^).Lo := Byte(Str[I]); { Copy string char }
  842. End;
  843. END;
  844. {---------------------------------------------------------------------------}
  845. { MoveCStr -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 10Jul99 LdB }
  846. {---------------------------------------------------------------------------}
  847. PROCEDURE MoveCStr (Var Dest; Const Str: String; Attrs: Word);
  848. VAR B: Byte; I, J: Sw_Word; P: PWord;
  849. BEGIN
  850. J := 0; { Start position }
  851. For I := 1 To Length(Str) Do Begin { For each character }
  852. If (Str[I] <> '~') Then Begin { Not tilde character }
  853. P := @TWordArray(Dest)[J]; { Pointer to Sw_Word }
  854. If (Lo(Attrs) <> 0) Then
  855. WordRec(P^).Hi := Lo(Attrs); { Copy attribute }
  856. WordRec(P^).Lo := Byte(Str[I]); { Copy string char }
  857. Inc(J); { Next position }
  858. End Else Begin
  859. B := Hi(Attrs); { Hold attribute }
  860. WordRec(Attrs).Hi := Lo(Attrs); { Copy low to high }
  861. WordRec(Attrs).Lo := B; { Complete exchange }
  862. End;
  863. End;
  864. END;
  865. {---------------------------------------------------------------------------}
  866. { MoveBuf -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 10Jul99 LdB }
  867. {---------------------------------------------------------------------------}
  868. PROCEDURE MoveBuf (Var Dest, Source; Attr: Byte; Count: Sw_Word);
  869. VAR I: Word; P: PWord;
  870. BEGIN
  871. For I := 1 To Count Do Begin
  872. P := @TWordArray(Dest)[I-1]; { Pointer to Sw_Word }
  873. If (Attr <> 0) Then WordRec(P^).Hi := Attr; { Copy attribute }
  874. WordRec(P^).Lo := TByteArray(Source)[I-1]; { Copy source data }
  875. End;
  876. END;
  877. {---------------------------------------------------------------------------}
  878. { MoveChar -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 10Jul99 LdB }
  879. {---------------------------------------------------------------------------}
  880. PROCEDURE MoveChar (Var Dest; C: Char; Attr: Byte; Count: Sw_Word);
  881. VAR I: Word; P: PWord;
  882. BEGIN
  883. For I := 1 To Count Do Begin
  884. P := @TWordArray(Dest)[I-1]; { Pointer to Sw_Word }
  885. If (Attr <> 0) Then WordRec(P^).Hi := Attr; { Copy attribute }
  886. If (Ord(C) <> 0) Then WordRec(P^).Lo := Byte(C); { Copy character }
  887. End;
  888. END;
  889. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  890. { KEYBOARD SUPPORT ROUTINES }
  891. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  892. {---------------------------------------------------------------------------}
  893. { GetAltCode -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 25May96 LdB }
  894. {---------------------------------------------------------------------------}
  895. FUNCTION GetAltCode (Ch: Char): Word;
  896. BEGIN
  897. GetAltCode := 0; { Preset zero return }
  898. Ch := UpCase(Ch); { Convert upper case }
  899. If (Ch < #128) Then
  900. GetAltCode := AltCodes[Ord(Ch)] SHL 8 { Return code }
  901. Else If (Ch = #240) Then GetAltCode := $0200 { Return code }
  902. Else GetAltCode := 0; { Return zero }
  903. END;
  904. {---------------------------------------------------------------------------}
  905. { GetCtrlCode -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 25May96 LdB }
  906. {---------------------------------------------------------------------------}
  907. FUNCTION GetCtrlCode (Ch: Char): Word;
  908. BEGIN
  909. GetCtrlCode := GetAltCode(Ch) OR (Ord(Ch) - $40); { Ctrl+key code }
  910. END;
  911. {---------------------------------------------------------------------------}
  912. { GetAltChar -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 25May96 LdB }
  913. {---------------------------------------------------------------------------}
  914. FUNCTION GetAltChar (KeyCode: Word): Char;
  915. VAR I: Sw_Integer;
  916. BEGIN
  917. GetAltChar := #0; { Preset fail return }
  918. If (Lo(KeyCode) = 0) Then Begin { Extended key }
  919. If (Hi(KeyCode) <= $83) Then Begin { Highest value in list }
  920. I := 0; { Start at first }
  921. While (I < 128) AND (Hi(KeyCode) <> AltCodes[I])
  922. Do Inc(I); { Search for match }
  923. If (I < 128) Then GetAltChar := Chr(I); { Return character }
  924. End Else
  925. If (Hi(KeyCode)=$02) Then GetAltChar := #240; { Return char }
  926. End;
  927. END;
  928. {---------------------------------------------------------------------------}
  929. { GetCtrlChar -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 25May96 LdB }
  930. {---------------------------------------------------------------------------}
  931. FUNCTION GetCtrlChar (KeyCode: Word): Char;
  932. VAR C: Char;
  933. BEGIN
  934. C := #0; { Preset #0 return }
  935. If (Lo(KeyCode) > 0) AND (Lo(KeyCode) <= 26) Then { Between 1-26 }
  936. C := Chr(Lo(KeyCode) + $40); { Return char A-Z }
  937. GetCtrlChar := C; { Return result }
  938. END;
  939. {---------------------------------------------------------------------------}
  940. { CtrlToArrow -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 25May96 LdB }
  941. {---------------------------------------------------------------------------}
  942. FUNCTION CtrlToArrow (KeyCode: Word): Word;
  943. CONST NumCodes = 11;
  944. CtrlCodes : Array [0..NumCodes-1] Of Char =
  945. (#19, #4, #5, #24, #1, #6, #7, #22, #18, #3, #8);
  946. ArrowCodes: Array [0..NumCodes-1] Of Sw_Word =
  947. (kbLeft, kbRight, kbUp, kbDown, kbHome, kbEnd, kbDel, kbIns,
  948. kbPgUp, kbPgDn, kbBack);
  949. VAR I: Sw_Integer;
  950. BEGIN
  951. CtrlToArrow := KeyCode; { Preset key return }
  952. For I := 0 To NumCodes - 1 Do
  953. If WordRec(KeyCode).Lo = Byte(CtrlCodes[I]) { Matches a code }
  954. Then Begin
  955. CtrlToArrow := ArrowCodes[I]; { Return key stroke }
  956. Exit; { Now exit }
  957. End;
  958. END;
  959. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  960. { KEYBOARD CONTROL ROUTINES }
  961. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  962. {---------------------------------------------------------------------------}
  963. { GetShiftState -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 08Jul96 LdB }
  964. {---------------------------------------------------------------------------}
  965. FUNCTION GetShiftState: Byte;
  966. begin
  967. GetShiftState:=Keyboard.GetKeyEventShiftState(Keyboard.PollShiftStateEvent);
  968. end;
  969. {---------------------------------------------------------------------------}
  970. { GetKeyEvent -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 19May98 LdB }
  971. {---------------------------------------------------------------------------}
  972. procedure GetKeyEvent (Var Event: TEvent);
  973. var
  974. key : TKeyEvent;
  975. keycode : Word;
  976. keyshift : byte;
  977. begin
  978. if Keyboard.PollKeyEvent<>0 then
  979. begin
  980. key:=Keyboard.GetKeyEvent;
  981. keycode:=Keyboard.GetKeyEventCode(key);
  982. keyshift:=KeyBoard.GetKeyEventShiftState(key);
  983. { fixup shift-keys }
  984. if keyshift and kbShift<>0 then
  985. begin
  986. case keycode of
  987. $5200 : keycode:=kbShiftIns;
  988. $5300 : keycode:=kbShiftDel;
  989. $8500 : keycode:=kbShiftF1;
  990. $8600 : keycode:=kbShiftF2;
  991. end;
  992. end
  993. { fixup ctrl-keys }
  994. else if keyshift and kbCtrl<>0 then
  995. begin
  996. case keycode of
  997. $5200,
  998. $9200 : keycode:=kbCtrlIns;
  999. $5300,
  1000. $9300 : keycode:=kbCtrlDel;
  1001. end;
  1002. end
  1003. { fixup alt-keys }
  1004. else if keyshift and kbAlt<>0 then
  1005. begin
  1006. case keycode of
  1007. $0e08,
  1008. $0e00 : keycode:=kbAltBack;
  1009. end;
  1010. end
  1011. { fixup normal keys }
  1012. else
  1013. begin
  1014. case keycode of
  1015. $e00d : keycode:=kbEnter;
  1016. end;
  1017. end;
  1018. Event.What:=evKeyDown;
  1019. Event.KeyCode:=keycode;
  1020. {$ifdef ENDIAN_LITTLE}
  1021. Event.CharCode:=chr(keycode and $ff);
  1022. Event.ScanCode:=keycode shr 8;
  1023. {$endif ENDIAN_LITTLE}
  1024. Event.KeyShift:=keyshift;
  1025. end
  1026. else
  1027. Event.What:=evNothing;
  1028. end;
  1029. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  1030. { MOUSE CONTROL ROUTINES }
  1031. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  1032. {---------------------------------------------------------------------------}
  1033. { HideMouse -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 30Jun98 LdB }
  1034. {---------------------------------------------------------------------------}
  1035. procedure HideMouse;
  1036. begin
  1037. { Is mouse hidden yet?
  1038. If (HideCount = 0) Then}
  1039. Mouse.HideMouse;
  1040. { Inc(HideCount);}
  1041. end;
  1042. {---------------------------------------------------------------------------}
  1043. { ShowMouse -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 30Jun98 LdB }
  1044. {---------------------------------------------------------------------------}
  1045. procedure ShowMouse;
  1046. begin
  1047. { if HideCount>0 then
  1048. dec(HideCount);
  1049. if (HideCount=0) then}
  1050. Mouse.ShowMouse;
  1051. end;
  1052. {---------------------------------------------------------------------------}
  1053. { GetMouseEvent -> Platforms DOS/DPMI/WINDOWS/OS2 - Updated 30Jun98 LdB }
  1054. {---------------------------------------------------------------------------}
  1055. procedure GetMouseEvent (Var Event: TEvent);
  1056. var
  1057. e : Mouse.TMouseEvent;
  1058. begin
  1059. if Mouse.PollMouseEvent(e) then
  1060. begin
  1061. Mouse.GetMouseEvent(e);
  1062. MouseWhere.X:=e.x * SysFontWidth;
  1063. MouseWhere.Y:=e.y * SysFontHeight;
  1064. Event.Double:=false;
  1065. case e.Action of
  1066. MouseActionMove :
  1067. Event.What:=evMouseMove;
  1068. MouseActionDown :
  1069. begin
  1070. Event.What:=evMouseDown;
  1071. if (DownButtons=e.Buttons) and (LastWhere.X=MouseWhere.X) and (LastWhere.Y=MouseWhere.Y) and
  1072. (GetDosTicks-DownTicks<=DoubleDelay) then
  1073. Event.Double:=true;
  1074. DownButtons:=e.Buttons;
  1075. DownWhere.X:=MouseWhere.x;
  1076. DownWhere.Y:=MouseWhere.y;
  1077. DownTicks:=GetDosTicks;
  1078. AutoTicks:=GetDosTicks;
  1079. if AutoTicks=0 then
  1080. AutoTicks:=1;
  1081. AutoDelay:=RepeatDelay;
  1082. end;
  1083. MouseActionUp :
  1084. begin
  1085. AutoTicks:=0;
  1086. Event.What:=evMouseUp;
  1087. AutoTicks:=0;
  1088. end;
  1089. end;
  1090. Event.Buttons:=e.Buttons;
  1091. Event.Where.X:=MouseWhere.x;
  1092. Event.Where.Y:=MouseWhere.y;
  1093. LastButtons:=Event.Buttons;
  1094. LastWhere.x:=Event.Where.x;
  1095. LastWhere.y:=Event.Where.y;
  1096. end
  1097. else if (AutoTicks <> 0) and (GetDosTicks >= AutoTicks + AutoDelay) then
  1098. begin
  1099. Event.What:=evMouseAuto;
  1100. Event.Buttons:=LastButtons;
  1101. Event.Where.X:=LastWhere.x;
  1102. Event.Where.Y:=LastWhere.y;
  1103. AutoTicks:=GetDosTicks;
  1104. AutoDelay:=1;
  1105. end
  1106. else
  1107. FillChar(Event,sizeof(TEvent),0);
  1108. end;
  1109. {$ifdef HasSysMsgUnit}
  1110. {---------------------------------------------------------------------------}
  1111. { GetSystemEvent }
  1112. {---------------------------------------------------------------------------}
  1113. procedure GetSystemEvent (Var Event: TEvent);
  1114. var
  1115. SysEvent : TsystemEvent;
  1116. begin
  1117. if PollSystemEvent(SysEvent) then
  1118. begin
  1119. SysMsg.GetSystemEvent(SysEvent);
  1120. case SysEvent.typ of
  1121. SysNothing :
  1122. Event.What:=evNothing;
  1123. SysSetFocus :
  1124. begin
  1125. Event.What:=evBroadcast;
  1126. Event.Command:=cmReceivedFocus;
  1127. end;
  1128. SysReleaseFocus :
  1129. begin
  1130. Event.What:=evBroadcast;
  1131. Event.Command:=cmReleasedFocus;
  1132. end;
  1133. SysClose :
  1134. begin
  1135. Event.What:=evCommand;
  1136. Event.Command:=cmQuitApp;
  1137. end;
  1138. SysResize :
  1139. begin
  1140. Event.What:=evCommand;
  1141. Event.Command:=cmResizeApp;
  1142. Event.Id:=SysEvent.x;
  1143. Event.InfoWord:=SysEvent.y;
  1144. end;
  1145. else
  1146. Event.What:=evNothing;
  1147. end;
  1148. end
  1149. else
  1150. Event.What:=evNothing;
  1151. end;
  1152. {$endif HasSysMsgUnit}
  1153. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  1154. { EVENT HANDLER CONTROL ROUTINES }
  1155. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  1156. {---------------------------------------------------------------------------}
  1157. { InitEvents -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 07Sep99 LdB }
  1158. {---------------------------------------------------------------------------}
  1159. PROCEDURE InitEvents;
  1160. BEGIN
  1161. If (ButtonCount <> 0) Then
  1162. begin { Mouse is available }
  1163. Mouse.InitMouse; { Hook the mouse }
  1164. { this is required by the use of HideCount variable }
  1165. Mouse.ShowMouse; { visible by default }
  1166. { HideCount:=0; }
  1167. LastButtons := 0; { Clear last buttons }
  1168. DownButtons := 0; { Clear down buttons }
  1169. MouseWhere.X:=Mouse.GetMouseX;
  1170. MouseWhere.Y:=Mouse.GetMouseY; { Get mouse position }
  1171. LastWhere.x:=MouseWhere.x;
  1172. LastWhereX:=MouseWhere.x;
  1173. LastWhere.y:=MouseWhere.y;
  1174. LastWhereY:=MouseWhere.y;
  1175. MouseEvents := True; { Set initialized flag }
  1176. end;
  1177. {$ifdef HasSysMsgUnit}
  1178. InitSystemMsg;
  1179. {$endif HasSysMsgUnit}
  1180. END;
  1181. {---------------------------------------------------------------------------}
  1182. { DoneEvents -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 30Jul99 LdB }
  1183. {---------------------------------------------------------------------------}
  1184. PROCEDURE DoneEvents;
  1185. BEGIN
  1186. {$ifdef HasSysMsgUnit}
  1187. DoneSystemMsg;
  1188. {$endif HasSysMsgUnit}
  1189. Mouse.DoneMouse;
  1190. MouseEvents:=false;
  1191. END;
  1192. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  1193. { VIDEO CONTROL ROUTINES }
  1194. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  1195. const
  1196. VideoInitialized : boolean = false;
  1197. {---------------------------------------------------------------------------}
  1198. { InitVideo -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 26Nov99 LdB }
  1199. {---------------------------------------------------------------------------}
  1200. PROCEDURE InitVideo;
  1201. VAR
  1202. {$ifdef GRAPH_API}
  1203. I, J: Integer;
  1204. Ts : TextSettingsType;
  1205. {$else not GRAPH_API}
  1206. I, J: Integer;
  1207. {$IFDEF OS_WINDOWS}
  1208. Dc, Mem: HDc; TempFont: TLogFont; Tm: TTextmetric;
  1209. {$ENDIF}
  1210. {$IFDEF OS_OS2}
  1211. Ts, Fs: Sw_Integer; Ps: HPs; Tm: FontMetrics;
  1212. {$ENDIF}
  1213. {$ENDIF}
  1214. {$ifdef USE_VIDEO_API}
  1215. StoreScreenMode : TVideoMode;
  1216. {$endif USE_VIDEO_API}
  1217. BEGIN
  1218. if VideoInitialized then
  1219. begin
  1220. {$ifdef USE_VIDEO_API}
  1221. StoreScreenMode:=ScreenMode;
  1222. {$endif USE_VIDEO_API}
  1223. DoneVideo;
  1224. {$ifdef USE_VIDEO_API}
  1225. end
  1226. else
  1227. begin
  1228. StoreScreenMode.Col:=0;
  1229. {$endif USE_VIDEO_API}
  1230. end;
  1231. {$ifdef GRAPH_API}
  1232. if Not TextmodeGFV then
  1233. begin
  1234. {$ifdef go32v2}
  1235. I := VGA;
  1236. J := VGAHi;
  1237. {$else not go32v2}
  1238. {$ifdef win32}
  1239. I := VESA;
  1240. J := mLargestWindow16;
  1241. DefFontHeight:=8;
  1242. {$else not win32}
  1243. I := Detect; { Detect video card }
  1244. J := 0; { Zero select mode }
  1245. {$endif win32}
  1246. {$endif go32v2}
  1247. InitGraph(I, J, ''); { Initialize graphics }
  1248. I := Graph.GetMaxX; { Fetch max x size }
  1249. J := Graph.GetMaxY; { Fetch max y size }
  1250. If (DefFontHeight = 0) Then { Font height not set }
  1251. J := (Graph.GetMaxY+1) DIV DefLineNum { Approx font height }
  1252. Else J := DefFontHeight; { Use set font height }
  1253. I := J DIV (TextHeight('H')+4); { Approx magnification }
  1254. If (I < 1) Then I := 1; { Must be 1 or above }
  1255. GetTextSettings(Ts); { Get text style }
  1256. SetTextStyle(Ts.Font, Ts.Direction, I); { Set new font settings }
  1257. SysFontWidth := TextWidth('H'); { Transfer font width }
  1258. SysFontHeight := TextHeight('H')+4; { Transfer font height }
  1259. ScreenWidth := (Graph.GetMaxX+1) DIV
  1260. SysFontWidth; { Calc screen width }
  1261. if ScreenWidth > MaxViewWidth then
  1262. ScreenWidth := MaxViewWidth;
  1263. ScreenHeight := (Graph.GetMaxY+1) DIV
  1264. SysFontHeight; { Calc screen height }
  1265. UseFixedFont:=true;
  1266. {$ifdef USE_VIDEO_API}
  1267. if assigned(Video.VideoBuf) then
  1268. FreeMem(Video.VideoBuf);
  1269. GetMem(Video.VideoBuf,sizeof(word)*ScreenWidth*ScreenHeight);
  1270. if assigned(Video.OldVideoBuf) then
  1271. FreeMem(Video.OldVideoBuf);
  1272. GetMem(Video.OldVideoBuf,sizeof(word)*ScreenWidth*ScreenHeight);
  1273. GetMem(GFVGraph.SpVideoBuf,sizeof(pextrainfo)*(ScreenWidth+1)*(ScreenHeight+1));
  1274. FillChar(Video.VideoBuf^,sizeof(word)*ScreenWidth*ScreenHeight,#0);
  1275. FillChar(Video.OldVideoBuf^,sizeof(word)*ScreenWidth*ScreenHeight,#0);
  1276. FillChar(GFVGraph.SpVideoBuf^,sizeof(pextrainfo)*(ScreenWidth+1)*(ScreenHeight+1),#0);
  1277. ScreenMode.color:=true;
  1278. ScreenMode.col:=ScreenWidth;
  1279. ScreenMode.row:=ScreenHeight;
  1280. GfvGraph.SysFontWidth:=SysFontWidth;
  1281. GfvGraph.SysFontHeight:=SysFontHeight;
  1282. GfvGraph.TextScreenWidth:=ScreenWidth;
  1283. GfvGraph.TextScreenHeight:=ScreenHeight;
  1284. SetupExtraInfo;
  1285. {$endif USE_VIDEO_API}
  1286. {$ifdef win32}
  1287. SetGraphHooks;
  1288. {$endif}
  1289. end
  1290. else
  1291. {$endif GRAPH_API}
  1292. begin
  1293. Video.InitVideo;
  1294. {$ifdef USE_VIDEO_API}
  1295. GetVideoMode(ScreenMode);
  1296. If (StoreScreenMode.Col<>0) and
  1297. ((StoreScreenMode.color<>ScreenMode.color) or
  1298. (StoreScreenMode.row<>ScreenMode.row) or
  1299. (StoreScreenMode.col<>ScreenMode.col)) then
  1300. begin
  1301. Video.SetVideoMode(StoreScreenMode);
  1302. GetVideoMode(ScreenMode);
  1303. end;
  1304. {$endif USE_VIDEO_API}
  1305. if ScreenWidth > MaxViewWidth then
  1306. ScreenWidth := MaxViewWidth;
  1307. ScreenWidth:=Video.ScreenWidth;
  1308. ScreenHeight:=Video.ScreenHeight;
  1309. SetViewPort(0,0,ScreenWidth,ScreenHeight,true,true);
  1310. I := ScreenWidth*8 -1; { Mouse width }
  1311. J := ScreenHeight*8 -1; { Mouse height }
  1312. SysScreenWidth := I + 1;
  1313. SysScreenHeight := J + 1;
  1314. SysFontWidth := 8; { Font width }
  1315. SysFontHeight := 8; { Font height }
  1316. end;
  1317. VideoInitialized:=true;
  1318. END;
  1319. {---------------------------------------------------------------------------}
  1320. { DoneVideo -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 19May98 LdB }
  1321. {---------------------------------------------------------------------------}
  1322. PROCEDURE DoneVideo;
  1323. BEGIN
  1324. if not VideoInitialized then
  1325. exit;
  1326. {$ifdef GRAPH_API}
  1327. if Not TextmodeGFV then
  1328. begin
  1329. {$ifdef USE_VIDEO_API}
  1330. FreeMem(Video.VideoBuf,sizeof(word)*ScreenWidth*ScreenHeight);
  1331. Video.VideoBuf:=nil;
  1332. FreeMem(Video.OldVideoBuf,sizeof(word)*ScreenWidth*ScreenHeight);
  1333. Video.OldVideoBuf:=nil;
  1334. FreeExtraInfo;
  1335. {$endif USE_VIDEO_API}
  1336. CloseGraph;
  1337. {$ifdef win32}
  1338. UnsetGraphHooks;
  1339. {$endif}
  1340. end
  1341. else
  1342. {$endif GRAPH_API}
  1343. {$ifdef USE_video_api}
  1344. Video.DoneVideo;
  1345. {$else not USE_video_api}
  1346. ; { nothing to do }
  1347. {$endif not USE_video_api}
  1348. VideoInitialized:=false;
  1349. END;
  1350. {---------------------------------------------------------------------------}
  1351. { ClearScreen -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 04Jan97 LdB }
  1352. {---------------------------------------------------------------------------}
  1353. PROCEDURE ClearScreen;
  1354. BEGIN
  1355. {$ifdef GRAPH_API}
  1356. if Not TextmodeGFV then
  1357. begin
  1358. Graph.ClearDevice;
  1359. end
  1360. else
  1361. {$endif GRAPH_API}
  1362. {$ifdef USE_video_api}
  1363. Video.ClearScreen;
  1364. {$else not USE_video_api}
  1365. ; { nothing to do }
  1366. {$endif not USE_video_api}
  1367. END;
  1368. {---------------------------------------------------------------------------}
  1369. { SetVideoMode -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 10Nov99 LdB }
  1370. {---------------------------------------------------------------------------}
  1371. PROCEDURE SetVideoMode (Mode: Sw_Word);
  1372. BEGIN
  1373. If (Mode > $100) Then DefLineNum := 50 { 50 line mode request }
  1374. Else DefLineNum := 24; { Normal 24 line mode }
  1375. END;
  1376. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  1377. { ERROR CONTROL ROUTINES }
  1378. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  1379. {---------------------------------------------------------------------------}
  1380. { InitSysError -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 20May98 LdB }
  1381. {---------------------------------------------------------------------------}
  1382. PROCEDURE InitSysError;
  1383. BEGIN
  1384. SysErrActive := True; { Set active flag }
  1385. END;
  1386. {---------------------------------------------------------------------------}
  1387. { DoneSysError -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 20May98 LdB }
  1388. {---------------------------------------------------------------------------}
  1389. PROCEDURE DoneSysError;
  1390. BEGIN
  1391. SysErrActive := False; { Clear active flag }
  1392. END;
  1393. {---------------------------------------------------------------------------}
  1394. { SystemError -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 20May98 LdB }
  1395. {---------------------------------------------------------------------------}
  1396. FUNCTION SystemError (ErrorCode: Sw_Integer; Drive: Byte): Sw_Integer;
  1397. BEGIN
  1398. If (FailSysErrors = False) Then Begin { Check error ignore }
  1399. End Else SystemError := 1; { Return 1 for ignored }
  1400. END;
  1401. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  1402. { STRING FORMAT ROUTINES }
  1403. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  1404. {---------------------------------------------------------------------------}
  1405. { PrintStr -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 18Feb99 LdB }
  1406. {---------------------------------------------------------------------------}
  1407. PROCEDURE PrintStr (CONST S: String);
  1408. BEGIN
  1409. Write(S); { Write to screen }
  1410. END;
  1411. {---------------------------------------------------------------------------}
  1412. { FormatStr -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 13Jul99 LdB }
  1413. {---------------------------------------------------------------------------}
  1414. PROCEDURE FormatStr (Var Result: String; CONST Format: String; Var Params);
  1415. TYPE TLongArray = Array[0..0] Of LongInt;
  1416. VAR ResultLength, FormatIndex, Justify, Wth: Byte; Fill: Char; S: String;
  1417. FUNCTION LongToStr (L: Longint; Radix: Byte): String;
  1418. CONST HexChars: Array[0..15] Of Char =
  1419. ('0', '1', '2', '3', '4', '5', '6', '7',
  1420. '8', '9', 'A', 'B', 'C', 'D', 'E', 'F');
  1421. VAR I: LongInt; S: String; Sign: String[1];
  1422. BEGIN
  1423. LongToStr := ''; { Preset empty return }
  1424. If (L < 0) Then Begin { If L is negative }
  1425. Sign := '-'; { Sign is negative }
  1426. L := Abs(L); { Convert to positive }
  1427. End Else Sign := ''; { Sign is empty }
  1428. S := ''; { Preset empty string }
  1429. Repeat
  1430. I := L MOD Radix; { Radix mod of value }
  1431. S := HexChars[I] + S; { Add char to string }
  1432. L := L DIV Radix; { Divid by radix }
  1433. Until (L = 0); { Until no remainder }
  1434. LongToStr := Sign + S; { Return result }
  1435. END;
  1436. PROCEDURE HandleParameter (I : LongInt);
  1437. BEGIN
  1438. While (FormatIndex <= Length(Format)) Do Begin { While length valid }
  1439. While (FormatIndex <= Length(Format)) and
  1440. (Format[FormatIndex] <> '%') { Param char not found }
  1441. Do Begin { Length still valid }
  1442. Result[ResultLength+1] := Format[FormatIndex]; { Transfer character }
  1443. Inc(ResultLength); { One character added }
  1444. Inc(FormatIndex); { Next param char }
  1445. End;
  1446. If (FormatIndex < Length(Format)) AND { Not last char and }
  1447. (Format[FormatIndex] = '%') Then Begin { '%' char found }
  1448. Fill := ' '; { Default fill char }
  1449. Justify := 0; { Default justify }
  1450. Wth := 0; { Default 0=no width }
  1451. Inc(FormatIndex); { Next character }
  1452. If (Format[FormatIndex] = '0') Then
  1453. Fill := '0'; { Fill char to zero }
  1454. If (Format[FormatIndex] = '-') Then Begin { Optional just char }
  1455. Justify := 1; { Right justify }
  1456. Inc(FormatIndex); { Next character }
  1457. End;
  1458. While ((FormatIndex <= Length(Format)) AND { Length still valid }
  1459. (Format[FormatIndex] >= '0') AND
  1460. (Format[FormatIndex] <= '9')) Do Begin { Numeric character }
  1461. Wth := Wth * 10; { Multiply x10 }
  1462. Wth := Wth + Ord(Format[FormatIndex])-$30; { Add numeric value }
  1463. Inc(FormatIndex); { Next character }
  1464. End;
  1465. If ((FormatIndex <= Length(Format)) AND { Length still valid }
  1466. (Format[FormatIndex] = '#')) Then Begin { Parameter marker }
  1467. Inc(FormatIndex); { Next character }
  1468. HandleParameter(Wth); { Width is param idx }
  1469. End;
  1470. If (FormatIndex <= Length(Format)) Then Begin{ Length still valid }
  1471. Case Format[FormatIndex] Of
  1472. 'c': S := Char(TLongArray(Params)[I]); { Character parameter }
  1473. 'd': S := LongToStr(TLongArray(Params)[I],
  1474. 10); { Decimal parameter }
  1475. 's': S := PString(TLongArray(Params)[I])^;{ String parameter }
  1476. 'x': S := LongToStr(TLongArray(Params)[I],
  1477. 16); { Hex parameter }
  1478. '%': Begin { Literal % }
  1479. S := '%'; { Set string }
  1480. Inc(FormatIndex); { Next character }
  1481. Move(S[1], Result[ResultLength+1], 1); { '%' char to result }
  1482. Inc(ResultLength, Length(S)); { Inc result length }
  1483. Continue; { Now continue }
  1484. End;
  1485. End;
  1486. Inc(I); { Next parameter }
  1487. Inc(FormatIndex); { Next character }
  1488. If (Wth > 0) Then Begin { Width control active }
  1489. If (Length(S) > Wth) Then Begin { We must shorten S }
  1490. If (Justify=1) Then { Check right justify }
  1491. S := Copy(S, Length(S)-Wth+1, Wth) { Take right side data }
  1492. Else S := Copy(S, 1, Wth); { Take left side data }
  1493. End Else Begin { We must pad out S }
  1494. If (Justify=1) Then { Right justify }
  1495. While (Length(S) < Wth) Do
  1496. S := S+Fill Else { Right justify fill }
  1497. While (Length(S) < Wth) Do
  1498. S := Fill + S; { Left justify fill }
  1499. End;
  1500. End;
  1501. Move(S[1], Result[ResultLength+1],
  1502. Length(S)); { Move data to result }
  1503. ResultLength := ResultLength + Length(S); { Adj result length }
  1504. End;
  1505. End;
  1506. End;
  1507. END;
  1508. BEGIN
  1509. ResultLength := 0; { Zero result length }
  1510. FormatIndex := 1; { Format index to 1 }
  1511. HandleParameter(0); { Handle parameter }
  1512. SetLength(Result, ResultLength); { Set string length }
  1513. END;
  1514. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  1515. { NEW QUEUED EVENT HANDLER ROUTINES }
  1516. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  1517. {---------------------------------------------------------------------------}
  1518. { PutEventInQueue -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 17Mar98 LdB }
  1519. {---------------------------------------------------------------------------}
  1520. FUNCTION PutEventInQueue (Var Event: TEvent): Boolean;
  1521. BEGIN
  1522. If (QueueCount < QueueMax) Then Begin { Check room in queue }
  1523. Queue[QueueHead] := Event; { Store event }
  1524. Inc(QueueHead); { Inc head position }
  1525. If (QueueHead = QueueMax) Then QueueHead := 0; { Roll to start check }
  1526. Inc(QueueCount); { Inc queue count }
  1527. PutEventInQueue := True; { Return successful }
  1528. End Else PutEventInQueue := False; { Return failure }
  1529. END;
  1530. {---------------------------------------------------------------------------}
  1531. { NextQueuedEvent -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 17Mar98 LdB }
  1532. {---------------------------------------------------------------------------}
  1533. PROCEDURE NextQueuedEvent(Var Event: TEvent);
  1534. BEGIN
  1535. If (QueueCount > 0) Then Begin { Check queued event }
  1536. Event := Queue[QueueTail]; { Fetch next event }
  1537. Inc(QueueTail); { Inc tail position }
  1538. If (QueueTail = QueueMax) Then QueueTail := 0; { Roll to start check }
  1539. Dec(QueueCount); { Dec queue count }
  1540. End Else Event.What := evNothing; { Return empty event }
  1541. END;
  1542. {***************************************************************************}
  1543. { UNIT INITIALIZATION ROUTINE }
  1544. {***************************************************************************}
  1545. BEGIN
  1546. ButtonCount := DetectMouse; { Detect mouse }
  1547. DetectVideo; { Detect video }
  1548. { text mode is the default mode }
  1549. TextModeGFV:=True;
  1550. InitKeyboard;
  1551. {$ifdef Graph_API}
  1552. TextModeGFV:=false;
  1553. {$endif Graph_API}
  1554. {$ifdef HasSysMsgUnit}
  1555. InitSystemMsg;
  1556. {$endif HasSysMsgUnit}
  1557. {$ifdef win32}
  1558. SetFileApisToOEM;
  1559. SetConsoleCP(437);
  1560. SetConsoleOutputCP(437);
  1561. {$endif}
  1562. SaveExit := ExitProc; { Save old exit }
  1563. ExitProc := @ExitDrivers; { Set new exit }
  1564. END.
  1565. {
  1566. $Log$
  1567. Revision 1.39 2004-11-02 23:53:19 peter
  1568. * fixed crashes with ide and 1.9.x
  1569. Revision 1.38 2003/10/01 16:20:27 marco
  1570. * baseunix fixes for 1.1
  1571. Revision 1.37 2002/10/17 11:22:46 pierre
  1572. * fix a problem in InitVideo with StoreVideoMode
  1573. Revision 1.36 2002/10/07 15:44:43 pierre
  1574. * consider endianess for KeyCode/CharCode-ScanCode pairs
  1575. Revision 1.35 2002/09/22 19:42:22 hajny
  1576. + FPC/2 support added
  1577. Revision 1.34 2002/09/13 22:24:30 pierre
  1578. * fix Alt+'9' recognition in GetAltChar function
  1579. Revision 1.33 2002/09/13 09:21:15 pierre
  1580. * don't call InitVideo in DetectVideo procedure
  1581. Revision 1.32 2002/09/09 08:04:05 pierre
  1582. * remove all warnings about far
  1583. Revision 1.31 2002/09/07 15:06:36 peter
  1584. * old logs removed and tabs fixed
  1585. Revision 1.30 2002/06/10 19:40:14 pierre
  1586. * add DoneMouse in DoneEvents
  1587. Revision 1.29 2002/06/10 18:16:55 pierre
  1588. * set Event.What to evNothing if no event in GetSystemEvent
  1589. Revision 1.28 2002/06/07 14:08:28 pierre
  1590. * try to get resizing to work
  1591. Revision 1.27 2002/06/06 20:33:35 pierre
  1592. * remove system event by calling sysmsg.getsystemevent
  1593. Revision 1.26 2002/06/06 13:57:50 pierre
  1594. + activate/desactivate system messages
  1595. Revision 1.25 2002/06/06 06:43:29 pierre
  1596. * avoid more than 132 columns, to avoid TDrawBuffer overrun
  1597. Revision 1.24 2002/06/04 11:12:41 marco
  1598. * Renamefest
  1599. Revision 1.23 2002/05/31 12:38:37 pierre
  1600. * try to enhance graph mode
  1601. Revision 1.22 2002/05/29 21:21:54 pierre
  1602. * Use VGAHi for go32v2 graph version for now
  1603. Revision 1.21 2002/05/29 19:36:12 pierre
  1604. * fix graph related problems
  1605. Revision 1.20 2002/05/28 19:14:35 pierre
  1606. * adapt to new GraphUpdateScreen function
  1607. Revision 1.19 2002/05/24 10:36:52 pierre
  1608. * Try to enhance win32 special chars support
  1609. Revision 1.18 2002/05/24 09:36:33 pierre
  1610. + use win32gr unit to add mouse and keyboard support for win32 graph
  1611. Revision 1.17 2002/05/23 15:07:31 pierre
  1612. * compute graphic size correctly
  1613. Revision 1.16 2002/05/23 06:34:06 pierre
  1614. * fix go32v2 build failure
  1615. Revision 1.15 2002/05/21 12:21:53 pierre
  1616. * fix various graphic problems
  1617. Revision 1.14 2002/05/16 20:21:50 pierre
  1618. + fix for bug report 1953 adapted from S Wiktor
  1619. }
  1620. {******************[ REVISION HISTORY ]********************}
  1621. { Version Date Fix }
  1622. { ------- --------- --------------------------------- }
  1623. { 1.00 26 Jul 96 First DOS/DPMI platform release }
  1624. { 1.10 18 Nov 97 Windows conversion added. }
  1625. { 1.20 29 Aug 97 Platform.inc sort added. }
  1626. { 1.30 10 Jun 98 Virtual pascal 2.0 code added. }
  1627. { 1.40 13 Jul 98 Added FormatStr by Marco Schmidt. }
  1628. { 1.50 14 Jul 98 Fixed width = 0 in FormatStr. }
  1629. { 1.60 13 Aug 98 Complete rewrite of FormatStr. }
  1630. { 1.70 10 Sep 98 Added mouse int hook for FPC. }
  1631. { 1.80 10 Sep 98 Checks run & commenting added. }
  1632. { 1.90 15 Oct 98 Fixed for FPC version 0.998 }
  1633. { 1.91 18 Feb 99 Added PrintStr functions }
  1634. { 1.92 18 Feb 99 FormatStr literal '%' fix added }
  1635. { 1.93 10 Jul 99 Sybil 2.0 code added }
  1636. { 1.94 15 Jul 99 Fixed for FPC 0.9912 release }
  1637. { 1.95 26 Jul 99 Windows..Scales to GFV system font }
  1638. { 1.96 30 Jul 99 Fixed Ctrl+F1..F10 in GetKeyEvent }
  1639. { 1.97 07 Sep 99 InitEvent, DoneEvent fixed for OS2 }
  1640. { 1.98 09 Sep 99 GetMouseEvent fixed for OS2. }
  1641. { 1.99 03 Nov 99 FPC windows support added. }
  1642. { 2.00 26 Nov 99 Graphics stuff moved to GFVGraph }
  1643. { 2.01 21 May 00 DOS fixed to use std GRAPH unit }
  1644. {**********************************************************}