fpusrscr.pas 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604
  1. {
  2. This file is part of the Free Pascal Integrated Development Environment
  3. Copyright (c) 1998 by Berczi Gabor
  4. User screen support routines
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. {$i globdir.inc}
  12. unit FPUsrScr;
  13. interface
  14. uses
  15. {$ifdef Windows}
  16. windows,
  17. {$endif Windows}
  18. {$ifdef Unix}
  19. baseunix,
  20. termio,
  21. {$ifdef linux}
  22. linuxvcs,
  23. {$endif}
  24. {$endif}
  25. video,Objects;
  26. type
  27. PScreen = ^TScreen;
  28. TScreen = object(TObject)
  29. function GetWidth: integer; virtual;
  30. function GetHeight: integer; virtual;
  31. procedure GetLine(Line: integer; var Text, Attr: string); virtual;
  32. procedure GetCursorPos(var P: TPoint); virtual;
  33. { remember the initial video screen }
  34. procedure Capture; virtual;
  35. { restore the initial video mode }
  36. procedure Restore; virtual;
  37. { move up or down if supported by OS }
  38. function Scroll(i : integer) : integer; virtual;
  39. { is moving supported by OS }
  40. function CanScroll : boolean; virtual;
  41. { saves the current IDE screen }
  42. procedure SaveIDEScreen; virtual;
  43. { saves the current console screen }
  44. procedure SaveConsoleScreen; virtual;
  45. { restores the saved console screen }
  46. procedure SwitchToConsoleScreen; virtual;
  47. { restores the saved IDE screen }
  48. procedure SwitchBackToIDEScreen; virtual;
  49. end;
  50. {$IFDEF netwlibc}
  51. PNWLScreen = ^TNWLScreen;
  52. TNWLScreen = object(TScreen)
  53. function GetWidth: integer; virtual;
  54. function GetHeight: integer; virtual;
  55. procedure GetLine(Line: integer; var Text, Attr: string); virtual;
  56. procedure GetCursorPos(var P: TPoint); virtual;
  57. { remember the initial video screen }
  58. procedure Capture; virtual;
  59. { restore the initial video mode }
  60. procedure Restore; virtual;
  61. { saves the current IDE screen }
  62. procedure SaveIDEScreen; virtual;
  63. { saves the current console screen }
  64. procedure SaveConsoleScreen; virtual;
  65. { restores the saved console screen }
  66. procedure SwitchToConsoleScreen; virtual;
  67. { restores the saved IDE screen }
  68. procedure SwitchBackToIDEScreen; virtual;
  69. end;
  70. {$ENDIF}
  71. {$IFDEF AMIGA}
  72. {$DEFINE AMIGASCREEN}
  73. {$ENDIF}
  74. {$IFDEF MORPHOS}
  75. {$DEFINE AMIGASCREEN}
  76. {$ENDIF}
  77. {$IFDEF AMIGASCREEN}
  78. PAmigaScreen = ^TAmigaScreen;
  79. TAmigaScreen = object(TScreen)
  80. function GetWidth: integer; virtual;
  81. function GetHeight: integer; virtual;
  82. procedure GetLine(Line: integer; var Text, Attr: string); virtual;
  83. procedure GetCursorPos(var P: TPoint); virtual;
  84. { remember the initial video screen }
  85. procedure Capture; virtual;
  86. { restore the initial video mode }
  87. procedure Restore; virtual;
  88. { saves the current IDE screen }
  89. procedure SaveIDEScreen; virtual;
  90. { saves the current console screen }
  91. procedure SaveConsoleScreen; virtual;
  92. { restores the saved console screen }
  93. procedure SwitchToConsoleScreen; virtual;
  94. { restores the saved IDE screen }
  95. procedure SwitchBackToIDEScreen; virtual;
  96. end;
  97. {$ENDIF}
  98. {$IFDEF OS2}
  99. POS2Screen = ^TOS2Screen;
  100. TOS2Screen = object(TScreen)
  101. constructor Init;
  102. destructor Done; virtual;
  103. public
  104. function GetWidth: integer; virtual;
  105. function GetHeight: integer; virtual;
  106. procedure GetLine(Line: integer; var Text, Attr: string); virtual;
  107. procedure GetCursorPos(var P: TPoint); virtual;
  108. { remember the initial video screen }
  109. procedure Capture; virtual;
  110. { restore the initial video mode }
  111. procedure Restore; virtual;
  112. { move up or down if supported by OS }
  113. function Scroll(i : integer) : integer; virtual;
  114. { saves the current IDE screen }
  115. procedure SaveIDEScreen; virtual;
  116. { saves the current console screen }
  117. procedure SaveConsoleScreen; virtual;
  118. { restores the saved console screen }
  119. procedure SwitchToConsoleScreen; virtual;
  120. { restores the saved IDE screen }
  121. procedure SwitchBackToIDEScreen; virtual;
  122. end;
  123. {$ENDIF}
  124. {$ifdef DOS}
  125. TDOSVideoInfo = record
  126. Mode : word;
  127. ScreenSize: word;
  128. Page : byte;
  129. Rows,Cols : integer;
  130. CurPos : TPoint;
  131. CurShapeT : integer;
  132. CurShapeB : integer;
  133. StateSize : word;
  134. StateBuf : pointer;
  135. end;
  136. PDOSScreen = ^TDOSScreen;
  137. TDOSScreen = object(TScreen)
  138. constructor Init;
  139. destructor Done; virtual;
  140. public
  141. function GetWidth: integer; virtual;
  142. function GetHeight: integer; virtual;
  143. procedure GetLine(Line: integer; var Text, Attr: string); virtual;
  144. procedure GetCursorPos(var P: TPoint); virtual;
  145. procedure Capture; virtual;
  146. procedure Restore; virtual;
  147. procedure SaveIDEScreen; virtual;
  148. procedure SaveConsoleScreen; virtual;
  149. procedure SwitchToConsoleScreen; virtual;
  150. procedure SwitchBackToIDEScreen; virtual;
  151. procedure FreeGraphBuffer;
  152. private
  153. LastTextConsoleVideoInfo,
  154. ConsoleVideoInfo : TDOSVideoInfo;
  155. VBufferSize : longint;
  156. VIDEBufferSize : longint;
  157. VBuffer : PByteArray;
  158. VIDEBuffer : PByteArray;
  159. IDEVideoInfo : TDOSVideoInfo;
  160. ctrl_c_state : boolean;
  161. {$ifdef USE_GRAPH_SWITCH}
  162. GraphImageSize : longint;
  163. GraphDriverName,
  164. GraphModeName : string;
  165. GraphXres,GraphYres : longint;
  166. GraphBuffer : pointer;
  167. ConsoleGraphDriver, ConsoleGraphMode : word;
  168. {$endif USE_GRAPH_SWITCH}
  169. function GetLineStartOfs(Line: integer): word;
  170. procedure GetBuffer(Size: word);
  171. procedure FreeBuffer;
  172. procedure GetVideoMode(var MI: TDOSVideoInfo);
  173. procedure SetVideoMode(MI: TDOSVideoInfo);
  174. end;
  175. {$endif}
  176. {$ifdef Unix}
  177. TConsoleType = (ttyNetwork,ttyLinux,ttyFreeBSD,ttyNetBSD);
  178. PLinuxScreen = ^TLinuxScreen;
  179. TLinuxScreen = object(TScreen)
  180. constructor Init;
  181. destructor Done; virtual;
  182. public
  183. function GetWidth: integer; virtual;
  184. function GetHeight: integer; virtual;
  185. procedure GetLine(Line: integer; var Text, Attr: string); virtual;
  186. procedure GetCursorPos(var P: TPoint); virtual;
  187. procedure Capture; virtual;
  188. procedure Restore; virtual;
  189. procedure SaveIDEScreen; virtual;
  190. procedure SaveConsoleScreen; virtual;
  191. procedure SwitchToConsoleScreen; virtual;
  192. procedure SwitchBackToIDEScreen; virtual;
  193. private
  194. IdeScreen: PByteArray;
  195. IdeSize : longint;
  196. IsXterm : boolean;
  197. Console : TConsoleType;
  198. TTyfd : longint;
  199. ConsVideoBuf : PByteArray;
  200. ConsHeight, ConsWidth,
  201. ConsCursorX, ConsCursorY : byte;
  202. ConsVideoBufSize : longint;
  203. ConsTio : termios;
  204. ConsTioValid : boolean;
  205. end;
  206. {$endif}
  207. {$ifdef Windows}
  208. PWindowsScreen = ^TWindowsScreen;
  209. TWindowsScreen = object(TScreen)
  210. constructor Init;
  211. destructor Done; virtual;
  212. public
  213. function GetWidth: integer; virtual;
  214. function GetHeight: integer; virtual;
  215. procedure GetLine(Line: integer; var Text, Attr: string); virtual;
  216. procedure GetCursorPos(var P: TPoint); virtual;
  217. function CanScroll : boolean; virtual;
  218. function Scroll(i : integer) : integer; virtual;
  219. procedure Capture; virtual;
  220. procedure Restore; virtual;
  221. procedure SaveIDEScreen; virtual;
  222. procedure SaveConsoleScreen; virtual;
  223. procedure SwitchToConsoleScreen; virtual;
  224. procedure SwitchBackToIDEScreen; virtual;
  225. private
  226. DosScreenBufferHandle,
  227. IDEScreenBufferHandle,
  228. StartScreenBufferHandle,
  229. DummyScreenBufferHandle,
  230. NewScreenBufferHandle : THandle;
  231. IDEActive : boolean;
  232. ConsoleMode,IdeMode : Dword;
  233. IdeScreenMode : TVideoMode;
  234. procedure BufferCopy(src,dest : THandle);
  235. {$ifdef debug}
  236. procedure Complain(St : string);
  237. Procedure SetConsoleMode(FH : Handle;Mode : DWord);
  238. {$endif debug}
  239. end;
  240. {$endif}
  241. procedure InitUserScreen;
  242. procedure DoneUserScreen;
  243. const UserScreen : PScreen = nil;
  244. implementation
  245. uses
  246. Dos,WUtils
  247. {$ifdef GO32V2}
  248. ,Dpmiexcp, Go32
  249. {$endif}
  250. ,Drivers,App
  251. {$ifdef USE_GRAPH_SWITCH}
  252. ,Graph,VESA
  253. {$else not USE_GRAPH_SWITCH}
  254. {$ifdef VESA}
  255. ,VESA
  256. {$endif VESA}
  257. {$endif not USE_GRAPH_SWITCH}
  258. ;
  259. function TScreen.GetWidth: integer;
  260. begin
  261. Getwidth:=0;
  262. Abstract;
  263. end;
  264. function TScreen.GetHeight: integer;
  265. begin
  266. Getheight:=0;
  267. Abstract;
  268. end;
  269. procedure TScreen.GetLine(Line: integer; var Text, Attr: string);
  270. begin
  271. Abstract;
  272. end;
  273. procedure TScreen.GetCursorPos(var P: TPoint);
  274. begin
  275. Abstract;
  276. end;
  277. procedure TScreen.Capture;
  278. begin
  279. Abstract;
  280. end;
  281. procedure TScreen.Restore;
  282. begin
  283. Abstract;
  284. end;
  285. procedure TScreen.SwitchToConsoleScreen;
  286. begin
  287. Abstract;
  288. end;
  289. procedure TScreen.SwitchBackToIDEScreen;
  290. begin
  291. Abstract;
  292. end;
  293. procedure TScreen.SaveIDEScreen;
  294. begin
  295. Abstract;
  296. end;
  297. function TScreen.Scroll(i : integer) : integer;
  298. begin
  299. Scroll:=0;
  300. end;
  301. function TScreen.CanScroll : boolean;
  302. begin
  303. CanScroll:=false;
  304. end;
  305. procedure TScreen.SaveConsoleScreen;
  306. begin
  307. Abstract;
  308. end;
  309. {****************************************************************************
  310. TDOSScreen
  311. ****************************************************************************}
  312. {$ifdef DOS}
  313. constructor TDOSScreen.Init;
  314. begin
  315. inherited Init;
  316. FillChar(LastTextConsoleVideoInfo,Sizeof(TDOSVideoInfo),#0);
  317. Capture;
  318. { get the current ctrl-C state }
  319. Ctrl_c_state:=djgpp_set_ctrl_c(false);
  320. djgpp_set_ctrl_c(Ctrl_c_state);
  321. end;
  322. destructor TDOSScreen.Done;
  323. begin
  324. FreeBuffer;
  325. if assigned(VIDEBuffer) then
  326. FreeMem(VIDEBuffer,VIDEBufferSize);
  327. inherited Done;
  328. end;
  329. function TDOSScreen.GetWidth: integer;
  330. begin
  331. GetWidth:=ConsoleVideoInfo.Cols;
  332. end;
  333. function TDOSScreen.GetHeight: integer;
  334. begin
  335. GetHeight:=ConsoleVideoInfo.Rows;
  336. end;
  337. procedure TDOSScreen.GetLine(Line: integer; var Text, Attr: string);
  338. var
  339. X: integer;
  340. W: word;
  341. begin
  342. Text:=''; Attr:='';
  343. if (Line<GetHeight) and
  344. {$ifdef USE_GRAPH_SWITCH}
  345. not assigned(GraphBuffer) and
  346. {$endif USE_GRAPH_SWITCH}
  347. assigned(VBuffer) then
  348. begin
  349. W:=GetLineStartOfs(Line);
  350. for X:=0 to GetWidth-1 do
  351. begin
  352. {Text:=Text+chr(VBuffer^[W+X*2]);
  353. Attr:=Attr+chr(VBuffer^[W+X*2+1]);}
  354. System.Insert(chr(VBuffer^[W+X*2]),Text,Length(Text)+1);
  355. System.Insert(chr(VBuffer^[W+X*2+1]),Attr,Length(Attr)+1);
  356. end;
  357. {$ifdef USE_GRAPH_SWITCH}
  358. end
  359. else if assigned(GraphBuffer) then
  360. begin
  361. if (Line=0) then
  362. Text:='Console in graph mode, use Alt+F5'
  363. else if (Line=1) then
  364. Text:='Graph driver: '+GraphDriverName
  365. else if (Line=2) then
  366. Text:='Graph mode: '+GraphModeName+' ('+
  367. IntToStr(GraphXres+1)+'x'+IntToStr(GraphYres+1)+')';
  368. Attr:=CharStr(chr($0F),Length(Text));
  369. end;
  370. {$else not USE_GRAPH_SWITCH}
  371. end;
  372. {$endif USE_GRAPH_SWITCH}
  373. end;
  374. procedure TDOSScreen.GetCursorPos(var P: TPoint);
  375. begin
  376. P:=ConsoleVideoInfo.CurPos;
  377. end;
  378. procedure TDOSScreen.Capture;
  379. begin
  380. SaveConsoleScreen;
  381. end;
  382. procedure TDOSScreen.FreeGraphBuffer;
  383. begin
  384. { We don't want to restore the last user screen if
  385. it was a grpahic screen, for example if we
  386. leave in the middle of the debugging of a
  387. graphic program, so we first
  388. dispose the graphic buffer, thus
  389. SwitchToConsoleScreen will restore the
  390. last used text mode }
  391. if LastTextConsoleVideoInfo.Mode<>0 then
  392. begin
  393. ConsoleVideoInfo:=LastTextConsoleVideoInfo;
  394. {$ifdef USE_GRAPH_SWITCH}
  395. if assigned(GraphBuffer) then
  396. begin
  397. FreeMem(GraphBuffer,GraphImageSize);
  398. GraphBuffer:=nil;
  399. GraphImageSize:=0;
  400. end;
  401. {$endif USE_GRAPH_SWITCH}
  402. end;
  403. end;
  404. procedure TDosScreen.Restore;
  405. begin
  406. FreeGraphBuffer;
  407. SwitchToConsoleScreen;
  408. end;
  409. procedure TDosScreen.SaveIDEScreen;
  410. var
  411. VSeg,SOfs: word;
  412. begin
  413. GetVideoMode(IDEVideoInfo);
  414. { First keep a copy of IDE screen }
  415. if ConsoleVideoInfo.Mode=7 then
  416. VSeg:=SegB000
  417. else
  418. VSeg:=SegB800;
  419. SOfs:=MemW[Seg0040:$4e];
  420. if not assigned(VIDEBuffer) or (VIDEBufferSize<>IDEVideoInfo.ScreenSize) then
  421. begin
  422. if assigned(VIDEBuffer) then
  423. FreeMem(VIDEBuffer,VIDEBufferSize);
  424. GetMem(VIDEBuffer,IDEVideoInfo.ScreenSize);
  425. VIDEBufferSize:=IDEVideoInfo.ScreenSize;
  426. end;
  427. DosmemGet(VSeg,SOfs,VIDEBuffer^,IDEVideoInfo.ScreenSize);
  428. end;
  429. procedure TDosScreen.SaveConsoleScreen;
  430. var
  431. VSeg,SOfs: word;
  432. {$ifdef USE_GRAPH_SWITCH}
  433. saved : boolean;
  434. GraphDriver,GraphMode : integer;
  435. {$endif USE_GRAPH_SWITCH}
  436. begin
  437. GetVideoMode(ConsoleVideoInfo);
  438. {$ifdef USE_GRAPH_SWITCH}
  439. saved:=false;
  440. if assigned(GraphBuffer) then
  441. begin
  442. FreeMem(GraphBuffer,GraphImageSize);
  443. GraphBuffer:=nil;
  444. GraphImageSize:=0;
  445. end;
  446. if (ConsoleVideoInfo.Mode>= $100) or
  447. (ConsoleVideoInfo.Mode=$13) or
  448. (ConsoleVideoInfo.Mode=$12) or
  449. (ConsoleVideoInfo.Mode=$10) or
  450. (ConsoleVideoInfo.Mode=$E) then
  451. begin
  452. if VesaSetMode(ConsoleVideoInfo.Mode or $8000) then
  453. begin
  454. Graph.DontClearGraphMemory:=true;
  455. if ConsoleVideoInfo.Mode>=$100 then
  456. begin
  457. GraphDriver:=Graph.Vesa;
  458. GraphMode:=ConsoleVideoInfo.Mode and $fff;
  459. end
  460. else
  461. begin
  462. GraphDriver:=Graph.VGA;
  463. case ConsoleVideoInfo.Mode of
  464. $E : GraphMode:=VGALo;
  465. $10 : GraphMode:=VGAMed;
  466. $12 : GraphMode:=VGAHi;
  467. $13 : begin
  468. GraphDriver:=Graph.LowRes;
  469. GraphMode:=0;
  470. end;
  471. end;
  472. end;
  473. Graph.InitGraph(GraphDriver,GraphMode,'');
  474. if graphresult=grOk then
  475. begin
  476. ConsoleGraphDriver:=GraphDriver;
  477. GraphDriverName:=GetDriverName;
  478. GraphModeName:=GetModeName(GraphMode);
  479. ConsoleGraphMode:=GraphMode;
  480. Graph.DontClearGraphMemory:=false;
  481. GraphXres:=Graph.GetmaxX;
  482. GraphYres:=Graph.GetmaxY;
  483. GraphImageSize:=ImageSize(0,0,GraphXres,GraphYres);
  484. GetMem(GraphBuffer,GraphImageSize);
  485. FillChar(GraphBuffer^,GraphImageSize,#0);
  486. GetImage(0,0,GraphXres,GraphYres,GraphBuffer^);
  487. ConsoleVideoInfo.Rows:=GraphYres div 8;
  488. ConsoleVideoInfo.Cols:=GraphXres div 8;
  489. {FreeBuffer;}
  490. saved:=true;
  491. end
  492. {$ifdef DEBUG}
  493. else
  494. Writeln(stderr,'Error in InitGraph ',Graphdriver, ' ',Graphmode)
  495. {$endif DEBUG}
  496. ;
  497. end;
  498. end;
  499. { mode < $100 so use standard Save code }
  500. if not saved then
  501. {$endif USE_GRAPH_SWITCH}
  502. begin
  503. LastTextConsoleVideoInfo:=ConsoleVideoInfo;
  504. GetBuffer(ConsoleVideoInfo.ScreenSize);
  505. if ConsoleVideoInfo.Mode=7 then
  506. VSeg:=SegB000
  507. else
  508. VSeg:=SegB800;
  509. SOfs:=MemW[Seg0040:$4e];
  510. DosmemGet(VSeg,SOfs,VBuffer^,ConsoleVideoInfo.ScreenSize);
  511. end;
  512. end;
  513. procedure TDOSScreen.SwitchToConsoleScreen;
  514. var
  515. VSeg,SOfs: word;
  516. {$ifdef USE_GRAPH_SWITCH}
  517. restored : boolean;
  518. GraphDriver,GraphMode : integer;
  519. {$endif USE_GRAPH_SWITCH}
  520. begin
  521. SetVideoMode(ConsoleVideoInfo);
  522. {$ifdef USE_GRAPH_SWITCH}
  523. restored:=false;
  524. if assigned(GraphBuffer) then
  525. begin
  526. if VesaSetMode(ConsoleVideoInfo.Mode) then
  527. begin
  528. if ConsoleVideoInfo.Mode>=$100 then
  529. begin
  530. GraphDriver:=Graph.Vesa;
  531. GraphMode:=ConsoleVideoInfo.Mode and $fff;
  532. end
  533. else
  534. begin
  535. GraphDriver:=Graph.VGA;
  536. case ConsoleVideoInfo.Mode of
  537. $E : GraphMode:=VGALo;
  538. $10 : GraphMode:=VGAMed;
  539. $12 : GraphMode:=VGAHi;
  540. $13 : begin
  541. GraphDriver:=Graph.LowRes;
  542. GraphMode:=0;
  543. end;
  544. end;
  545. end;
  546. if (ConsoleGraphDriver<>GraphDriver) or
  547. (ConsoleGraphMode<>GraphMode) then
  548. Graph.InitGraph(GraphDriver,GraphMode,'');
  549. if graphresult=grOk then
  550. begin
  551. PutImage(0,0,GraphBuffer^,CopyPut);
  552. FreeMem(GraphBuffer,GraphImageSize);
  553. GraphBuffer:=nil;
  554. GraphImageSize:=0;
  555. restored:=true;
  556. end;
  557. end;
  558. end;
  559. { mode < $100 so use standard Save code }
  560. if not restored then
  561. {$endif USE_GRAPH_SWITCH}
  562. begin
  563. if ConsoleVideoInfo.Mode=7 then
  564. VSeg:=SegB000
  565. else
  566. VSeg:=SegB800;
  567. SOfs:=MemW[Seg0040:$4e];
  568. DosmemPut(VSeg,SOfs,VBuffer^,ConsoleVideoInfo.ScreenSize);
  569. djgpp_set_ctrl_c(Ctrl_c_state);
  570. end;
  571. end;
  572. procedure TDOSScreen.SwitchBackToIDEScreen;
  573. var
  574. VSeg,SOfs: word;
  575. begin
  576. SetVideoMode(IDEVideoInfo);
  577. if ConsoleVideoInfo.Mode=7 then
  578. VSeg:=SegB000
  579. else
  580. VSeg:=SegB800;
  581. SOfs:=MemW[Seg0040:$4e];
  582. if assigned(VIDEBuffer) then
  583. DosmemPut(VSeg,SOfs,VIDEBuffer^,IDEVideoInfo.ScreenSize);
  584. Ctrl_c_state := djgpp_set_ctrl_c(false);
  585. { Its difficult to know
  586. the state of the mouse
  587. so simply show it always
  588. fixes bug 2253 PM }
  589. ShowMouse;
  590. end;
  591. function TDOSScreen.GetLineStartOfs(Line: integer): word;
  592. begin
  593. GetLineStartOfs:=(ConsoleVideoInfo.Cols*Line)*2;
  594. end;
  595. procedure TDOSScreen.GetBuffer(Size: word);
  596. begin
  597. if (VBuffer<>nil) and (VBufferSize=Size) then Exit;
  598. if VBuffer<>nil then FreeBuffer;
  599. VBufferSize:=Size;
  600. GetMem(VBuffer,VBufferSize);
  601. end;
  602. procedure TDOSScreen.FreeBuffer;
  603. begin
  604. if (VBuffer<>nil) and (VBufferSize>0) then FreeMem(VBuffer,VBufferSize);
  605. VBuffer:=nil;
  606. end;
  607. procedure TDOSScreen.GetVideoMode(var MI: TDOSVideoInfo);
  608. var
  609. r: registers;
  610. begin
  611. if (MI.StateSize>0) and (MI.StateBuf<>nil) then
  612. begin FreeMem(MI.StateBuf,MI.StateSize); MI.StateBuf:=nil; end;
  613. MI.ScreenSize:=MemW[Seg0040:$4c];
  614. r.ah:=$0f;
  615. intr($10,r);
  616. MI.Mode:=r.al;
  617. MI.Page:=r.bh;
  618. MI.Cols:=r.ah;
  619. {$ifdef VESA}
  620. VESAGetMode(MI.Mode);
  621. MI.Mode:=MI.Mode and $fff;
  622. {$endif}
  623. MI.Rows:=MI.ScreenSize div (MI.Cols*2);
  624. if MI.Rows=51 then MI.Rows:=50;
  625. r.ah:=$03;
  626. r.bh:=MI.Page;
  627. intr($10,r);
  628. with MI do
  629. begin
  630. CurPos.X:=r.dl; CurPos.Y:=r.dh;
  631. CurShapeT:=r.ch; CurShapeB:=r.cl;
  632. end;
  633. end;
  634. procedure TDOSScreen.SetVideoMode(MI: TDOSVideoInfo);
  635. var r: registers;
  636. CM: TDOSVideoInfo;
  637. begin
  638. FillChar(CM,sizeof(CM),0);
  639. GetVideoMode(CM);
  640. if (CM.Mode<>MI.Mode) or (CM.Cols<>MI.Cols) or (CM.Rows<>MI.Rows) then
  641. begin
  642. {$ifdef VESA}
  643. if MI.Mode>=$100 then
  644. VESASetMode(MI.Mode)
  645. else
  646. {$endif}
  647. begin
  648. r.ah:=$00; r.al:=MI.Mode; intr($10,r);
  649. end;
  650. if (MI.Mode=3) and (MI.Cols=80) and (MI.Rows=50) then
  651. begin
  652. r.ax:=$1112; r.bx:=$0;
  653. intr($10,r);
  654. end;
  655. end;
  656. r.ah:=$05; r.al:=MI.Page; intr($10,r);
  657. r.ah:=$02; r.bh:=MI.Page; r.dl:=MI.CurPos.X; r.dh:=MI.CurPos.Y; intr($10,r);
  658. r.ah:=$01; r.ch:=MI.CurShapeT; r.cl:=MI.CurShapeB; intr($10,r);
  659. end;
  660. {$endif}
  661. {****************************************************************************
  662. TLinuxScreen
  663. ****************************************************************************}
  664. {$ifdef Unix}
  665. constructor TLinuxScreen.Init;
  666. var
  667. ThisTTY: string[30];
  668. FName: string;
  669. WS: packed record
  670. ws_row, ws_col, ws_xpixel, ws_ypixel: Word;
  671. end;
  672. begin
  673. inherited Init;
  674. IdeScreen := nil;
  675. TTYFd:=-1;
  676. IsXterm:=getenv('TERM')='xterm';
  677. ThisTTY:=TTYName(stdinputhandle);
  678. if Not IsXterm and (IsATTY(stdinputhandle)<>-1) then
  679. begin
  680. Console:=TTyNetwork; {Default: Network or other vtxxx tty}
  681. if ((Copy(ThisTTY, 1, 8) = '/dev/tty') and (ThisTTY[9]<>'p')) or (Copy(ThisTTY,1,8)='/dev/vc/') Then
  682. begin
  683. Case ThisTTY[9] of
  684. '0'..'9' :
  685. begin { running Linux on native console or native-emulation }
  686. {$ifdef linux}
  687. FName:='/dev/vcsa' + ThisTTY[9];
  688. TTYFd:=fpOpen(FName, &666, O_RdWr); { open console }
  689. if TTYFd = -1 then
  690. begin
  691. if try_grab_vcsa then
  692. TTYFd:=fpOpen(FName, &666, O_RdWr); { try again }
  693. end;
  694. If TTYFd <>-1 Then
  695. Console:=ttyLinux;
  696. {$endif}
  697. end;
  698. 'v' : { check for (Free?)BSD native}
  699. If (ThisTTY[10]>='0') and (ThisTTY[10]<='9') Then
  700. Console:=ttyFreeBSD; {TTYFd ?}
  701. end;
  702. end;
  703. If Copy(GetEnv('TERM'),1,6)='cons25' Then
  704. Console:=ttyFreeBSD;
  705. FillChar(WS, SizeOf(WS), 0);
  706. fpioctl(stdinputhandle, TIOCGWINSZ, @WS);
  707. if WS.ws_Col=0 then
  708. WS.ws_Col:=80;
  709. if WS.ws_Row=0 then
  710. {$ifdef symobi}
  711. { normally Symobi's terminal has 24 rows, but a new line is added at the
  712. end, so applications like the IDE get visually garbaged }
  713. WS.ws_Row:=23;
  714. {$else}
  715. WS.ws_Row:=25;
  716. {$endif}
  717. ConsWidth:=WS.ws_Col;
  718. ConsHeight:=WS.ws_row;
  719. end;
  720. Capture;
  721. end;
  722. destructor TLinuxScreen.Done;
  723. begin
  724. if assigned(IdeScreen) then
  725. freemem(IdeScreen,IdeSize);
  726. if assigned(ConsVideoBuf) then
  727. freemem(ConsVideoBuf,ConsVideoBufSize);
  728. inherited Done;
  729. end;
  730. function TLinuxScreen.GetWidth: integer;
  731. begin
  732. GetWidth:=ConsWidth;
  733. end;
  734. function TLinuxScreen.GetHeight: integer;
  735. begin
  736. GetHeight:=ConsHeight;
  737. end;
  738. procedure TLinuxScreen.GetLine(Line: integer; var Text, Attr: string);
  739. var
  740. X, W : longint;
  741. begin
  742. Text:='';
  743. Attr:='';
  744. if (TtyFd<>-1) and assigned(ConsVideoBuf) then
  745. begin
  746. if Line<GetHeight then
  747. begin
  748. W:=(ConsWidth*Line)*Sizeof(word);
  749. for X:=0 to GetWidth-1 do
  750. begin
  751. {Text:=Text+chr(VBuffer^[W+X*2]);
  752. Attr:=Attr+chr(VBuffer^[W+X*2+1]);}
  753. System.Insert(chr(ConsVideoBuf^[W+X*2]),Text,Length(Text)+1);
  754. System.Insert(chr(ConsVideoBuf^[W+X*2+1]),Attr,Length(Attr)+1);
  755. end;
  756. end;
  757. end;
  758. end;
  759. procedure TLinuxScreen.GetCursorPos(var P: TPoint);
  760. begin
  761. P.X:=ConsCursorX+1;
  762. P.Y:=ConsCursorY+1;
  763. end;
  764. procedure TLinuxScreen.Capture;
  765. begin
  766. SaveConsoleScreen;
  767. end;
  768. procedure TLinuxScreen.Restore;
  769. begin
  770. SwitchToConsoleScreen;
  771. end;
  772. procedure TLinuxScreen.SaveIDEScreen;
  773. begin
  774. if assigned(IdeScreen) then
  775. freemem(IdeScreen,IdeSize);
  776. getmem(IdeScreen,videobufsize);
  777. IdeSize:=videobufsize;
  778. move(videobuf^,IdeScreen^,videobufsize);
  779. end;
  780. procedure TLinuxScreen.SaveConsoleScreen;
  781. var
  782. NewSize : longint;
  783. begin
  784. if IsXTerm then
  785. write(#27'7'#27'[?47h')
  786. else if (TTYfd<>-1) then
  787. begin
  788. fpLSeek(TTYFd, 0, Seek_Set);
  789. fpread(TTYFd,ConsHeight,sizeof(byte));
  790. fpread(TTYFd,ConsWidth,sizeof(byte));
  791. fpread(TTYFd,ConsCursorX,sizeof(byte));
  792. fpread(TTYFd,ConsCursorY,sizeof(byte));
  793. NewSize:=ConsWidth*ConsHeight*sizeof(word);
  794. if (NewSize<>ConsVideoBufSize) and
  795. assigned(ConsVideoBuf) then
  796. Begin
  797. FreeMem(ConsVideoBuf,ConsVideoBufSize);
  798. ConsVideoBuf:=nil;
  799. End;
  800. If not assigned(ConsVideoBuf) then
  801. GetMem(ConsVideoBuf,NewSize);
  802. ConsVideoBufSize:=NewSize;
  803. fpread(TTYFd,ConsVideoBuf^,ConsVideoBufSize);
  804. end
  805. else
  806. begin
  807. ConsWidth:=80;
  808. ConsHeight:=25;
  809. ConsCursorX:=0;
  810. ConsCursorY:=0;
  811. ConsVideoBuf:=nil;
  812. end;
  813. ConsTioValid:=(TCGetAttr(1,ConsTio)<>-1);
  814. end;
  815. procedure TLinuxScreen.SwitchToConsoleScreen;
  816. begin
  817. if IsXterm then
  818. begin
  819. write(#27'[0m');
  820. write(#27'[?47l'#27'8'#27'[m');
  821. end
  822. else if (TTyfd<>-1) then
  823. begin
  824. fplSeek(TTYFd, 2, Seek_Set);
  825. fpwrite(TTYFd, ConsCursorX, sizeof(byte));
  826. fpwrite(TTYFd, ConsCursorY, sizeof(byte));
  827. fpwrite(TTYFd, ConsVideoBuf^,ConsVideoBufSize);
  828. { FreeMem(ConsVideoBuf,ConsVideoBufSize);
  829. ConsVideoBuf:=nil; }
  830. end;
  831. If ConsTioValid then
  832. TCSetAttr(1,TCSANOW,ConsTio);
  833. end;
  834. procedure TLinuxScreen.SwitchBackToIDEScreen;
  835. begin
  836. if IdeScreen = nil then
  837. exit;
  838. move(IdeScreen^,videobuf^,videobufsize);
  839. freemem(IdeScreen,IdeSize);
  840. IdeScreen := nil;
  841. end;
  842. {$endif}
  843. {****************************************************************************
  844. TWindowsScreen
  845. ****************************************************************************}
  846. {$ifdef Windows}
  847. { Seems to be missing in windows unit PM }
  848. const
  849. ENABLE_INSERT_MODE = $20;
  850. ENABLE_QUICK_EDIT_MODE = $40;
  851. ENABLE_EXTENDED_FLAGS = $80;
  852. ENABLE_AUTO_POSITION = $100;
  853. procedure UpdateFileHandles;
  854. begin
  855. {StdInputHandle:=longint(GetStdHandle(STD_INPUT_HANDLE));}
  856. StdOutputHandle:=longint(GetStdHandle(cardinal(STD_OUTPUT_HANDLE)));
  857. {StdErrorHandle:=longint(GetStdHandle(STD_ERROR_HANDLE));}
  858. TextRec(Output).Handle:=StdOutputHandle;
  859. TextRec(StdOut).Handle:=StdOutputHandle;
  860. {TextRec(StdErr).Handle:=StdErrorHandle;}
  861. end;
  862. constructor TWindowsScreen.Init;
  863. var
  864. SecurityAttr : Security_attributes;
  865. BigWin : Coord;
  866. res : longbool;
  867. Error : dword;
  868. ConsoleScreenBufferInfo : Console_screen_buffer_info;
  869. begin
  870. inherited Init;
  871. {if GetConsoleOutputCP<>437 then
  872. res:=SetConsoleOutputCP(437);}
  873. SecurityAttr.nLength:=SizeOf(Security_attributes);
  874. SecurityAttr.lpSecurityDescriptor:=nil;
  875. SecurityAttr.bInheritHandle:=true;
  876. NewScreenBufferHandle:=CreateConsoleScreenBuffer(
  877. GENERIC_READ or GENERIC_WRITE,
  878. FILE_SHARE_READ or FILE_SHARE_WRITE,SecurityAttr,
  879. CONSOLE_TEXTMODE_BUFFER,nil);
  880. DummyScreenBufferHandle:=CreateConsoleScreenBuffer(
  881. GENERIC_READ or GENERIC_WRITE,
  882. FILE_SHARE_READ or FILE_SHARE_WRITE,SecurityAttr,
  883. CONSOLE_TEXTMODE_BUFFER,nil);
  884. StartScreenBufferHandle:=GetStdHandle(cardinal(STD_OUTPUT_HANDLE));
  885. GetConsoleMode(GetStdHandle(cardinal(Std_Input_Handle)), @ConsoleMode);
  886. IdeMode:=ConsoleMode;
  887. {$ifdef debug}
  888. Complain('Starting ConsoleMode is $'+hexstr(ConsoleMode,8));
  889. {define Windowsbigwin}
  890. {$endif debug}
  891. {$ifdef Windowsbigwin}
  892. GetConsoleScreenBufferInfo(StartScreenBufferHandle,
  893. @ConsoleScreenBufferInfo);
  894. BigWin.X:=ConsoleScreenBufferInfo.dwSize.X;
  895. BigWin.Y:=ConsoleScreenBufferInfo.srwindow.bottom-ConsoleScreenBufferInfo.srwindow.top; // mants 15779 was 200
  896. { Try to allow to store more info }
  897. res:=SetConsoleScreenBufferSize(NewScreenBufferHandle,BigWin);
  898. if not res then
  899. error:=GetLastError;
  900. res:=SetConsoleScreenBufferSize(StartScreenBufferHandle,BigWin);
  901. if not res then
  902. error:=GetLastError;
  903. {$endif Windowsbigwin}
  904. GetConsoleScreenBufferInfo(StartScreenBufferHandle,
  905. @ConsoleScreenBufferInfo);
  906. { make sure that the IDE Screen Handle has the maximum display size
  907. this removes the scroll bars if it is maximized }
  908. BigWin.X:=ConsoleScreenBufferInfo.dwSize.X;
  909. BigWin.Y:=ConsoleScreenBufferInfo.srwindow.bottom-ConsoleScreenBufferInfo.srwindow.top;
  910. res:=SetConsoleScreenBufferSize(NewScreenBufferHandle,
  911. BigWin);
  912. // mants 15779 : was
  913. // res:=SetConsoleScreenBufferSize(NewScreenBufferHandle,
  914. // ConsoleScreenBufferInfo.dwMaximumWindowSize);
  915. if not res then
  916. error:=GetLastError;
  917. IDEScreenBufferHandle:=NewScreenBufferHandle;
  918. DosScreenBufferHandle:=StartScreenBufferHandle;
  919. Capture;
  920. IdeScreenMode.row:=0;
  921. SwitchBackToIDEScreen;
  922. end;
  923. destructor TWindowsScreen.Done;
  924. begin
  925. { copy the Dos buffer content into the original ScreenBuffer
  926. which remains the startup std_output_handle PM }
  927. {if StartScreenBufferHandle=IDEScreenBufferHandle then}
  928. BufferCopy(DosScreenBufferHandle,IDEScreenBufferHandle);
  929. SetConsoleActiveScreenBuffer(StartScreenBufferHandle);
  930. SetStdHandle(cardinal(Std_Output_Handle),StartScreenBufferHandle);
  931. UpdateFileHandles;
  932. CloseHandle(NewScreenBufferHandle);
  933. CloseHandle(DummyScreenBufferHandle);
  934. inherited Done;
  935. end;
  936. function TWindowsScreen.GetWidth: integer;
  937. var
  938. ConsoleScreenBufferInfo : Console_screen_buffer_info;
  939. begin
  940. GetConsoleScreenBufferInfo(DosScreenBufferHandle,
  941. @ConsoleScreenBufferInfo);
  942. GetWidth:=ConsoleScreenBufferInfo.dwSize.X;
  943. end;
  944. function TWindowsScreen.GetHeight: integer;
  945. var
  946. ConsoleScreenBufferInfo : Console_screen_buffer_info;
  947. begin
  948. GetConsoleScreenBufferInfo(DosScreenBufferHandle,
  949. @ConsoleScreenBufferInfo);
  950. GetHeight:=ConsoleScreenBufferInfo.dwSize.Y;
  951. end;
  952. function TWindowsScreen.CanScroll : boolean;
  953. var
  954. ConsoleScreenBufferInfo : Console_screen_buffer_info;
  955. BufferLines : longint;
  956. WindowLines : longint;
  957. begin
  958. GetConsoleScreenBufferInfo(DosScreenBufferHandle,
  959. @ConsoleScreenBufferInfo);
  960. WindowLines:=ConsoleScreenBufferInfo.srWindow.Bottom-
  961. ConsoleScreenBufferInfo.srWindow.Top;
  962. BufferLines:= ConsoleScreenBufferInfo.dwSize.Y-1;
  963. CanScroll:=(BufferLines>WindowLines);
  964. end;
  965. function TWindowsScreen.Scroll(i : integer) : integer;
  966. var
  967. ConsoleScreenBufferInfo : Console_screen_buffer_info;
  968. ConsoleWindow : Small_rect;
  969. begin
  970. GetConsoleScreenBufferInfo(DosScreenBufferHandle,
  971. @ConsoleScreenBufferInfo);
  972. if (ConsoleScreenBufferInfo.srWindow.Top + i < 0) then
  973. i:= -ConsoleScreenBufferInfo.srWindow.Top;
  974. if (ConsoleScreenBufferInfo.srWindow.Bottom + i > ConsoleScreenBufferInfo.dwSize.Y) then
  975. i:= ConsoleScreenBufferInfo.dwSize.Y - ConsoleScreenBufferInfo.srWindow.Bottom;
  976. if i<>0 then
  977. begin
  978. ConsoleWindow.Left:=ConsoleScreenBufferInfo.srWindow.Left;
  979. ConsoleWindow.Right:=ConsoleScreenBufferInfo.srWindow.Right;
  980. ConsoleWindow.Top:=ConsoleScreenBufferInfo.srWindow.Top+i;
  981. ConsoleWindow.Bottom:=ConsoleScreenBufferInfo.srWindow.Bottom+i;
  982. SetConsoleWindowInfo(DosScreenBufferHandle,true,ConsoleWindow);
  983. Scroll:=i;
  984. end
  985. else
  986. Scroll:=0;
  987. end;
  988. procedure TWindowsScreen.GetLine(Line: integer; var Text, Attr: string);
  989. type
  990. CharInfoArray = Array [0..255] of Char_Info;
  991. var
  992. LineBuf : ^CharInfoArray;
  993. BufSize,BufCoord : Coord;
  994. i,LineSize : longint;
  995. WriteRegion : SMALL_RECT;
  996. begin
  997. GetMem(LineBuf,SizeOf(CharInfoArray));
  998. LineSize:=ScreenWidth;
  999. If LineSize>256 then
  1000. LineSize:=256;
  1001. BufSize.X:=LineSize;
  1002. BufSize.Y:=1;
  1003. BufCoord.X:=0;
  1004. BufCoord.Y:=0;
  1005. with WriteRegion do
  1006. begin
  1007. Top :=Line;
  1008. Left :=0;
  1009. Bottom := Line+1;
  1010. Right := LineSize-1;
  1011. end;
  1012. ReadConsoleOutput(DosScreenBufferHandle, PChar_info(LineBuf),
  1013. BufSize, BufCoord, @WriteRegion);
  1014. for i:=1 to LineSize do
  1015. begin
  1016. Text[i]:=LineBuf^[i-1].AsciiChar;
  1017. Attr[i]:=char(byte(LineBuf^[i-1].Attributes));
  1018. end;
  1019. FreeMem(LineBuf,SizeOf(CharInfoArray));
  1020. Text[0]:=char(byte(LineSize));
  1021. Attr[0]:=char(byte(LineSize));
  1022. end;
  1023. procedure TWindowsScreen.GetCursorPos(var P: TPoint);
  1024. var
  1025. ConsoleScreenBufferInfo : Console_screen_buffer_info;
  1026. begin
  1027. GetConsoleScreenBufferInfo(DosScreenBufferHandle,
  1028. @ConsoleScreenBufferInfo);
  1029. P.X:=ConsoleScreenBufferInfo.dwCursorPosition.X;
  1030. P.Y:=ConsoleScreenBufferInfo.dwCursorPosition.Y;
  1031. end;
  1032. procedure TWindowsScreen.BufferCopy(Src, Dest : THandle);
  1033. type
  1034. CharInfoArray = Array [0..256*255-1] of Char_Info;
  1035. var
  1036. LineBuf : ^CharInfoArray;
  1037. BufSize,BufCoord : Coord;
  1038. Error, LineSize,
  1039. Part, OnePartY: longint;
  1040. res : boolean;
  1041. WriteRegion : SMALL_RECT;
  1042. ConsoleScreenBufferInfo : Console_screen_buffer_info;
  1043. DestConsoleScreenBufferInfo : Console_screen_buffer_info;
  1044. begin
  1045. GetConsoleScreenBufferInfo(Src,
  1046. @ConsoleScreenBufferInfo);
  1047. GetConsoleScreenBufferInfo(Dest,
  1048. @DestConsoleScreenBufferInfo);
  1049. GetMem(LineBuf,SizeOf(CharInfoArray));
  1050. FillChar(LineBuf^,SizeOf(CharInfoArray),#0);
  1051. LineSize:=ConsoleScreenBufferInfo.dwSize.X;
  1052. If LineSize>256 then
  1053. LineSize:=256;
  1054. BufSize.X:=LineSize;
  1055. BufSize.Y:=ConsoleScreenBufferInfo.dwSize.Y;
  1056. BufCoord.X:=0;
  1057. BufCoord.Y:=0;
  1058. with WriteRegion do
  1059. begin
  1060. Top :=0;
  1061. Left :=0;
  1062. Bottom := ConsoleScreenBufferInfo.dwSize.Y-1;
  1063. Right := LineSize-1;
  1064. end;
  1065. if BufSize.X*BufSize.Y*Sizeof(CHAR_INFO) >= $8000 then
  1066. begin
  1067. OnePartY := ($8000 -1) div (BufSize.X * SizeOf(Char_Info) );
  1068. BufSize.Y:=OnePartY;
  1069. Part:=0;
  1070. while ((Part+1)*OnePartY < ConsoleScreenBufferInfo.dwSize.Y) do
  1071. begin
  1072. WriteRegion.Top := Part*OnePartY;
  1073. WriteRegion.Bottom := (Part+1)*OnePartY-1;
  1074. res:=ReadConsoleOutput(Src, PChar_info(LineBuf),
  1075. BufSize, BufCoord, @WriteRegion);
  1076. if not res then
  1077. Error:=GetLastError;
  1078. res:=WriteConsoleOutput(Dest, PChar_info(LineBuf),
  1079. BufSize, BufCoord, @WriteRegion);
  1080. if not res then
  1081. Error:=GetLastError;
  1082. Inc(Part);
  1083. end;
  1084. BufSize.Y:=ConsoleScreenBufferInfo.dwSize.Y - Part*OnePartY;
  1085. WriteRegion.Top := Part*OnePartY;
  1086. WriteRegion.Bottom := ConsoleScreenBufferInfo.dwSize.Y-1;
  1087. res:=ReadConsoleOutput(Src, PChar_info(LineBuf),
  1088. BufSize, BufCoord, @WriteRegion);
  1089. if not res then
  1090. Error:=GetLastError;
  1091. res:=WriteConsoleOutput(Dest, PChar_info(LineBuf),
  1092. BufSize, BufCoord, @WriteRegion);
  1093. if not res then
  1094. Error:=GetLastError;
  1095. end
  1096. else
  1097. begin
  1098. res:=ReadConsoleOutput(Src, PChar_info(LineBuf),
  1099. BufSize, BufCoord, @WriteRegion);
  1100. if not res then
  1101. Error:=GetLastError;
  1102. res:=WriteConsoleOutput(Dest, PChar_info(LineBuf),
  1103. BufSize, BufCoord, @WriteRegion);
  1104. if not res then
  1105. Error:=GetLastError;
  1106. end;
  1107. FreeMem(LineBuf,SizeOf(CharInfoArray));
  1108. SetConsoleCursorPosition(Dest, ConsoleScreenBufferInfo.dwCursorPosition);
  1109. end;
  1110. procedure TWindowsScreen.Capture;
  1111. begin
  1112. {if StartScreenBufferHandle=IdeScreenBufferHandle then
  1113. BufferCopy(IDEScreenBufferHandle,DosScreenBufferHandle)
  1114. else
  1115. BufferCopy(DosScreenBufferHandle,IDEScreenBufferHandle);}
  1116. SaveConsoleScreen;
  1117. end;
  1118. procedure TWindowsScreen.Restore;
  1119. begin
  1120. SwitchToConsoleScreen;
  1121. end;
  1122. { dummy for Windows as the Buffer screen
  1123. do hold all the info }
  1124. procedure TWindowsScreen.SaveIDEScreen;
  1125. var
  1126. NowIdeMode : Dword;
  1127. begin
  1128. IdeScreenMode:=ScreenMode;
  1129. GetConsoleMode(GetStdHandle(cardinal(Std_Input_Handle)), @NowIdeMode);
  1130. {$ifdef debug}
  1131. Complain('IDE ConsoleMode is $'+hexstr(NowIdeMode,8));
  1132. if NowIdeMode<>IdeMode then
  1133. Complain('is not equal to IDEMode $'+hexstr(IdeMode,8));
  1134. {$endif debug}
  1135. IdeMode:=NowIdeMode;
  1136. { set the dummy buffer as active already now PM }
  1137. SetStdHandle(cardinal(Std_Output_Handle),DummyScreenBufferHandle);
  1138. UpdateFileHandles;
  1139. end;
  1140. { dummy for Windows as the Buffer screen
  1141. do hold all the info }
  1142. procedure TWindowsScreen.SaveConsoleScreen;
  1143. begin
  1144. GetConsoleMode(GetStdHandle(cardinal(Std_Input_Handle)), @ConsoleMode);
  1145. {$ifdef debug}
  1146. Complain('ConsoleMode now is $'+hexstr(ConsoleMode,8));
  1147. {$endif debug}
  1148. { set the dummy buffer as active already now PM }
  1149. SetStdHandle(cardinal(Std_Output_Handle),DummyScreenBufferHandle);
  1150. UpdateFileHandles;
  1151. end;
  1152. procedure TWindowsScreen.SwitchToConsoleScreen;
  1153. begin
  1154. SetConsoleActiveScreenBuffer(DosScreenBufferHandle);
  1155. SetStdHandle(cardinal(Std_Output_Handle),DosScreenBufferHandle);
  1156. SetConsoleMode(GetStdHandle(cardinal(Std_Input_Handle)), ConsoleMode);
  1157. UpdateFileHandles;
  1158. IDEActive:=false;
  1159. end;
  1160. procedure TWindowsScreen.SwitchBackToIDEScreen;
  1161. var
  1162. ConsoleScreenBufferInfo : Console_screen_buffer_info;
  1163. WindowPos : Small_rect;
  1164. res : boolean;
  1165. error : longint;
  1166. begin
  1167. SetStdHandle(cardinal(Std_Output_Handle),IDEScreenBufferHandle);
  1168. UpdateFileHandles;
  1169. GetConsoleScreenBufferInfo(IDEScreenBufferHandle,
  1170. @ConsoleScreenBufferInfo);
  1171. SetConsoleActiveScreenBuffer(IDEScreenBufferHandle);
  1172. { Needed to force InitSystemMsg to use the right console handle }
  1173. DoneEvents;
  1174. InitEvents;
  1175. IdeMode:=({IdeMode or }ENABLE_MOUSE_INPUT or
  1176. ENABLE_WINDOW_INPUT or
  1177. ENABLE_EXTENDED_FLAGS)
  1178. and not (ENABLE_PROCESSED_INPUT or
  1179. ENABLE_LINE_INPUT or
  1180. ENABLE_ECHO_INPUT or
  1181. ENABLE_INSERT_MODE or
  1182. ENABLE_QUICK_EDIT_MODE);
  1183. SetConsoleMode(GetStdHandle(cardinal(Std_Input_Handle)), IdeMode);
  1184. WindowPos.left:=0;
  1185. WindowPos.right:=ConsoleScreenBufferInfo.srWindow.right
  1186. -ConsoleScreenBufferInfo.srWindow.left;
  1187. WindowPos.top:=0;
  1188. WindowPos.bottom:=ConsoleScreenBufferInfo.srWindow.bottom
  1189. -ConsoleScreenBufferInfo.srWindow.top;
  1190. with ConsoleScreenBufferInfo.dwMaximumWindowSize do
  1191. begin
  1192. if WindowPos.Right<X-1 then
  1193. WindowPos.right:=X-1;
  1194. if WindowPos.Bottom<Y-1 then
  1195. WindowPos.Bottom:=Y-1;
  1196. end;
  1197. res:=SetConsoleWindowInfo(IDEScreenBufferHandle,true,WindowPos);
  1198. if not res then
  1199. error:=GetLastError;
  1200. {$ifdef DEBUG}
  1201. IdeScreenMode.row:=WindowPos.bottom+1;
  1202. IdeScreenMode.col:=WindowPos.right+1;
  1203. {$endif DEBUG}
  1204. { needed to force the correct size for videobuf }
  1205. if Assigned(Application) and (IdeScreenMode.row<>0)then
  1206. Application^.SetScreenVideoMode(IdeScreenMode);
  1207. IDEActive:=true;
  1208. end;
  1209. {$ifdef debug}
  1210. procedure TWindowsScreen.Complain(St : string);
  1211. begin
  1212. if IDEActive then
  1213. DebugMessage('',St,0,0)
  1214. else
  1215. Writeln(stderr,St);
  1216. end;
  1217. procedure TWindowsScreen.SetConsoleMode(FH : Handle;Mode: DWord);
  1218. var
  1219. Test: DWord;
  1220. begin
  1221. If not Windows.SetConsoleMode(FH,Mode) then
  1222. begin
  1223. Complain('SetConsoleMode call failed GetLastError='+IntToStr(GetLastError));
  1224. end
  1225. else
  1226. begin
  1227. if not GetConsoleMode(FH,Test) then
  1228. begin
  1229. Complain('GetConsoleMode call failed GetLastError='+IntToStr(GetLastError));
  1230. end
  1231. else if (Test<>Mode) then
  1232. begin
  1233. Complain('GetConsoleMode result '+IntToStr(Test)+' <> '+
  1234. IntToStr(Mode));
  1235. end;
  1236. end;
  1237. end;
  1238. {$endif DEBUG}
  1239. {$endif}
  1240. {****************************************************************************
  1241. TOS2Screen
  1242. ****************************************************************************}
  1243. {$ifdef OS2}
  1244. function TOS2Screen.GetWidth: integer;
  1245. begin
  1246. GetWidth:=80;
  1247. end;
  1248. function TOS2Screen.GetHeight: integer;
  1249. begin
  1250. GetHeight:=25;
  1251. end;
  1252. procedure TOS2Screen.GetLine(Line: integer; var Text, Attr: string);
  1253. begin
  1254. Text:=' ';
  1255. Attr:=' ';
  1256. end;
  1257. procedure TOS2Screen.GetCursorPos(var P: TPoint);
  1258. begin
  1259. P.X:=1;
  1260. P.Y:=1;
  1261. end;
  1262. { remember the initial video screen }
  1263. procedure TOS2Screen.Capture;
  1264. begin
  1265. end;
  1266. { restore the initial video mode }
  1267. procedure TOS2Screen.Restore;
  1268. begin
  1269. end;
  1270. { move up or down if supported by OS }
  1271. function TOS2Screen.Scroll(i : integer) : integer;
  1272. begin
  1273. end;
  1274. { saves the current IDE screen }
  1275. procedure TOS2Screen.SaveIDEScreen;
  1276. begin
  1277. end;
  1278. { saves the current console screen }
  1279. procedure TOS2Screen.SaveConsoleScreen;
  1280. begin
  1281. end;
  1282. { restores the saved console screen }
  1283. procedure TOS2Screen.SwitchToConsoleScreen;
  1284. begin
  1285. end;
  1286. { restores the saved IDE screen }
  1287. procedure TOS2Screen.SwitchBackToIDEScreen;
  1288. begin
  1289. end;
  1290. constructor TOS2Screen.Init;
  1291. begin
  1292. end;
  1293. destructor TOS2Screen.Done;
  1294. begin
  1295. end;
  1296. {$ENDIF}
  1297. {****************************************************************************
  1298. TNWLScreen
  1299. ****************************************************************************}
  1300. {$ifdef netwlibc}
  1301. function TNWLScreen.GetWidth: integer;
  1302. begin
  1303. GetWidth:=80;
  1304. end;
  1305. function TNWLScreen.GetHeight: integer;
  1306. begin
  1307. GetHeight:=25;
  1308. end;
  1309. procedure TNWLScreen.GetLine(Line: integer; var Text, Attr: string);
  1310. begin
  1311. Text:=' ';
  1312. Attr:=' ';
  1313. end;
  1314. procedure TNWLScreen.GetCursorPos(var P: TPoint);
  1315. begin
  1316. P.X:=1;
  1317. P.Y:=1;
  1318. end;
  1319. { remember the initial video screen }
  1320. procedure TNWLScreen.Capture;
  1321. begin
  1322. end;
  1323. { restore the initial video mode }
  1324. procedure TNWLScreen.Restore;
  1325. begin
  1326. end;
  1327. { saves the current IDE screen }
  1328. procedure TNWLScreen.SaveIDEScreen;
  1329. begin
  1330. end;
  1331. { saves the current console screen }
  1332. procedure TNWLScreen.SaveConsoleScreen;
  1333. begin
  1334. end;
  1335. { restores the saved console screen }
  1336. procedure TNWLScreen.SwitchToConsoleScreen;
  1337. begin
  1338. end;
  1339. { restores the saved IDE screen }
  1340. procedure TNWLScreen.SwitchBackToIDEScreen;
  1341. begin
  1342. end;
  1343. {$ENDIF}
  1344. {****************************************************************************
  1345. TAmigaScreen
  1346. ****************************************************************************}
  1347. {$IFDEF AMIGASCREEN}
  1348. function TAmigaScreen.GetWidth: integer;
  1349. begin
  1350. GetWidth:=80;
  1351. end;
  1352. function TAmigaScreen.GetHeight: integer;
  1353. begin
  1354. GetHeight:=25;
  1355. end;
  1356. procedure TAmigaScreen.GetLine(Line: integer; var Text, Attr: string);
  1357. begin
  1358. Text:=' ';
  1359. Attr:=' ';
  1360. end;
  1361. procedure TAmigaScreen.GetCursorPos(var P: TPoint);
  1362. begin
  1363. P.X:=1;
  1364. P.Y:=1;
  1365. end;
  1366. { remember the initial video screen }
  1367. procedure TAmigaScreen.Capture;
  1368. begin
  1369. end;
  1370. { restore the initial video mode }
  1371. procedure TAmigaScreen.Restore;
  1372. begin
  1373. end;
  1374. { saves the current IDE screen }
  1375. procedure TAmigaScreen.SaveIDEScreen;
  1376. begin
  1377. end;
  1378. { saves the current console screen }
  1379. procedure TAmigaScreen.SaveConsoleScreen;
  1380. begin
  1381. end;
  1382. { restores the saved console screen }
  1383. procedure TAmigaScreen.SwitchToConsoleScreen;
  1384. begin
  1385. end;
  1386. { restores the saved IDE screen }
  1387. procedure TAmigaScreen.SwitchBackToIDEScreen;
  1388. begin
  1389. end;
  1390. {$ENDIF}
  1391. {****************************************************************************
  1392. Initialize
  1393. ****************************************************************************}
  1394. procedure InitUserScreen;
  1395. begin
  1396. {$ifdef DOS}
  1397. UserScreen:=New(PDOSScreen, Init);
  1398. {$else}
  1399. {$ifdef Unix}
  1400. UserScreen:=New(PLinuxScreen, Init);
  1401. {$else}
  1402. {$ifdef Windows}
  1403. UserScreen:=New(PWindowsScreen, Init);
  1404. {$else}
  1405. {$ifdef OS2}
  1406. UserScreen:=New(POS2Screen, Init);
  1407. {$else}
  1408. {$ifdef netwlibc}
  1409. UserScreen:=New(PNWLScreen, Init);
  1410. {$else}
  1411. {$ifdef AMIGASCREEN}
  1412. UserScreen:=nil; //New(PAmigaScreen, Init);
  1413. {$else}
  1414. UserScreen:=New(PScreen, Init);
  1415. {$endif AMIGASCREEN}
  1416. {$endif netwlibc}
  1417. {$endif OS2}
  1418. {$endif Windows}
  1419. {$endif Unix}
  1420. {$endif Dos}
  1421. end;
  1422. procedure DoneUserScreen;
  1423. begin
  1424. if UserScreen<>nil then
  1425. begin
  1426. UserScreen^.Restore;
  1427. Dispose(UserScreen, Done);
  1428. UserScreen:=nil;
  1429. end;
  1430. end;
  1431. end.