crt.pp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1993-98 by the Free Pascal development team.
  5. Borland Pascal 7 Compatible CRT Unit for Go32V1 and Go32V2
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. unit crt;
  13. interface
  14. {$I os.inc}
  15. const
  16. { CRT modes }
  17. BW40 = 0; { 40x25 B/W on Color Adapter }
  18. CO40 = 1; { 40x25 Color on Color Adapter }
  19. BW80 = 2; { 80x25 B/W on Color Adapter }
  20. CO80 = 3; { 80x25 Color on Color Adapter }
  21. Mono = 7; { 80x25 on Monochrome Adapter }
  22. Font8x8 = 256; { Add-in for ROM font }
  23. { Mode constants for 3.0 compatibility }
  24. C40 = CO40;
  25. C80 = CO80;
  26. { Foreground and background color constants }
  27. Black = 0;
  28. Blue = 1;
  29. Green = 2;
  30. Cyan = 3;
  31. Red = 4;
  32. Magenta = 5;
  33. Brown = 6;
  34. LightGray = 7;
  35. { Foreground color constants }
  36. DarkGray = 8;
  37. LightBlue = 9;
  38. LightGreen = 10;
  39. LightCyan = 11;
  40. LightRed = 12;
  41. LightMagenta = 13;
  42. Yellow = 14;
  43. White = 15;
  44. { Add-in for blinking }
  45. Blink = 128;
  46. var
  47. { Interface variables }
  48. CheckBreak: Boolean; { Enable Ctrl-Break }
  49. CheckEOF: Boolean; { Enable Ctrl-Z }
  50. DirectVideo: Boolean; { Enable direct video addressing }
  51. CheckSnow: Boolean; { Enable snow filtering }
  52. LastMode: Word; { Current text mode }
  53. TextAttr: Byte; { Current text attribute }
  54. WindMin: Word; { Window upper left coordinates }
  55. WindMax: Word; { Window lower right coordinates }
  56. { Interface procedures }
  57. procedure AssignCrt(var F: Text);
  58. function KeyPressed: Boolean;
  59. function ReadKey: Char;
  60. procedure TextMode(Mode: Integer);
  61. procedure Window(X1,Y1,X2,Y2: Byte);
  62. procedure GotoXY(X,Y: Byte);
  63. function WhereX: Byte;
  64. function WhereY: Byte;
  65. procedure ClrScr;
  66. procedure ClrEol;
  67. procedure InsLine;
  68. procedure DelLine;
  69. procedure TextColor(Color: Byte);
  70. procedure TextBackground(Color: Byte);
  71. procedure LowVideo;
  72. procedure HighVideo;
  73. procedure NormVideo;
  74. procedure Delay(MS: Word);
  75. procedure Sound(Hz: Word);
  76. procedure NoSound;
  77. {Extra Functions}
  78. procedure cursoron;
  79. procedure cursoroff;
  80. procedure cursorbig;
  81. implementation
  82. uses
  83. go32;
  84. {$ifdef VER0_99_5}
  85. {$I386_ATT} {can be removed in the future}
  86. {$endif}
  87. {$ASMMODE ATT}
  88. var
  89. DelayCnt,
  90. ScreenWidth,
  91. ScreenHeight : longint;
  92. {
  93. definition of textrec is in textrec.inc
  94. }
  95. {$i textrec.inc}
  96. {****************************************************************************
  97. Low level Routines
  98. ****************************************************************************}
  99. procedure setscreenmode(mode : byte);
  100. {$ifdef GO32V2}
  101. var
  102. regs : trealregs;
  103. {$endif GO32V2}
  104. begin
  105. {$ifdef GO32V2}
  106. regs.realeax:=mode;
  107. realintr($10,regs);
  108. {$else GO32V2}
  109. asm
  110. movb 8(%ebp),%al
  111. xorb %ah,%ah
  112. pushl %ebp
  113. int $0x10
  114. popl %ebp
  115. end;
  116. {$endif GO32V2}
  117. end;
  118. function GetScreenHeight : longint;
  119. begin
  120. {$ifdef GO32V2}
  121. getscreenheight:=mem[$40:$84]+1;
  122. {$else}
  123. dosmemget($40,$84,getscreenheight,1);
  124. inc(getscreenheight);
  125. {$endif}
  126. end;
  127. function GetScreenWidth : longint;
  128. begin
  129. {$ifdef GO32V2}
  130. getscreenwidth:=mem[$40:$4a];
  131. {$else}
  132. dosmemget($40,$4a,getscreenwidth,1);
  133. {$endif}
  134. end;
  135. procedure SetScreenCursor(x,y : longint);
  136. {$ifdef GO32V2}
  137. var
  138. regs : trealregs;
  139. {$endif GO32V2}
  140. begin
  141. {$ifdef GO32V2}
  142. regs.realeax:=$0200;
  143. regs.realebx:=0;
  144. regs.realedx:=(y-1) shl 8+(x-1);
  145. realintr($10,regs);
  146. {$else GO32V2}
  147. asm
  148. movb $0x02,%ah
  149. movb $0,%bh
  150. movb y,%dh
  151. movb x,%dl
  152. subw $0x0101,%dx
  153. pushl %ebp
  154. int $0x10
  155. popl %ebp
  156. end;
  157. {$endif GO32V2}
  158. end;
  159. procedure GetScreenCursor(var x,y : longint);
  160. begin
  161. {$ifdef Go32V2}
  162. x:=mem[$40:$50]+1;
  163. y:=mem[$40:$51]+1;
  164. {$else Go32V2}
  165. x:=0;
  166. y:=0;
  167. dosmemget($40,$50,x,1);
  168. dosmemget($40,$51,y,1);
  169. inc(x);
  170. inc(y);
  171. {$endif GO32V2}
  172. end;
  173. {****************************************************************************
  174. Helper Routines
  175. ****************************************************************************}
  176. Function WinMinX: Byte;
  177. {
  178. Current Minimum X coordinate
  179. }
  180. Begin
  181. WinMinX:=(WindMin and $ff)+1;
  182. End;
  183. Function WinMinY: Byte;
  184. {
  185. Current Minimum Y Coordinate
  186. }
  187. Begin
  188. WinMinY:=(WindMin shr 8)+1;
  189. End;
  190. Function WinMaxX: Byte;
  191. {
  192. Current Maximum X coordinate
  193. }
  194. Begin
  195. WinMaxX:=(WindMax and $ff)+1;
  196. End;
  197. Function WinMaxY: Byte;
  198. {
  199. Current Maximum Y coordinate;
  200. }
  201. Begin
  202. WinMaxY:=(WindMax shr 8) + 1;
  203. End;
  204. Function FullWin:boolean;
  205. {
  206. Full Screen 80x25? Window(1,1,80,25) is used, allows faster routines
  207. }
  208. begin
  209. FullWin:=(WindMax-WindMin=$184f);
  210. end;
  211. {****************************************************************************
  212. Public Crt Functions
  213. ****************************************************************************}
  214. procedure textmode(mode : integer);
  215. begin
  216. lastmode:=mode;
  217. mode:=mode and $ff;
  218. setscreenmode(mode);
  219. screenwidth:=getscreenwidth;
  220. screenheight:=getscreenheight;
  221. windmin:=0;
  222. windmax:=(screenwidth-1) or ((screenheight-1) shl 8);
  223. end;
  224. Procedure TextColor(Color: Byte);
  225. {
  226. Switch foregroundcolor
  227. }
  228. Begin
  229. TextAttr:=(Color and $8f) or (TextAttr and $70);
  230. End;
  231. Procedure TextBackground(Color: Byte);
  232. {
  233. Switch backgroundcolor
  234. }
  235. Begin
  236. TextAttr:=(Color shl 4) or (TextAttr and $0f);
  237. End;
  238. Procedure HighVideo;
  239. {
  240. Set highlighted output.
  241. }
  242. Begin
  243. TextColor(TextAttr Or $08);
  244. End;
  245. Procedure LowVideo;
  246. {
  247. Set normal output
  248. }
  249. Begin
  250. TextColor(TextAttr And $77);
  251. End;
  252. Procedure NormVideo;
  253. {
  254. Set normal back and foregroundcolors.
  255. }
  256. Begin
  257. TextColor(7);
  258. TextBackGround(0);
  259. End;
  260. Procedure GotoXy(X: Byte; Y: Byte);
  261. {
  262. Go to coordinates X,Y in the current window.
  263. }
  264. Begin
  265. If (X>0) and (X<=WinMaxX- WinMinX+1) and
  266. (Y>0) and (Y<=WinMaxY-WinMinY+1) Then
  267. Begin
  268. Inc(X,WinMinX-1);
  269. Inc(Y,WinMinY-1);
  270. SetScreenCursor(x,y);
  271. End;
  272. End;
  273. Procedure Window(X1, Y1, X2, Y2: Byte);
  274. {
  275. Set screen window to the specified coordinates.
  276. }
  277. Begin
  278. if (X1>X2) or (X2>ScreenWidth) or
  279. (Y1>Y2) or (Y2>ScreenHeight) then
  280. exit;
  281. WindMin:=((Y1-1) Shl 8)+(X1-1);
  282. WindMax:=((Y2-1) Shl 8)+(X2-1);
  283. GoToXY(1,1);
  284. End;
  285. Procedure ClrScr;
  286. {
  287. Clear the current window, and set the cursor on 1,1
  288. }
  289. var
  290. fil : word;
  291. y : longint;
  292. begin
  293. fil:=32 or (textattr shl 8);
  294. if FullWin then
  295. DosmemFillWord($b800,0,ScreenHeight*ScreenWidth,fil)
  296. else
  297. begin
  298. for y:=WinMinY to WinMaxY do
  299. DosmemFillWord($b800,((y-1)*ScreenWidth+(WinMinX-1))*2,WinMaxX-WinMinX+1,fil);
  300. end;
  301. Gotoxy(1,1);
  302. end;
  303. Procedure ClrEol;
  304. {
  305. Clear from current position to end of line.
  306. }
  307. var
  308. x,y : longint;
  309. fil : word;
  310. Begin
  311. GetScreenCursor(x,y);
  312. fil:=32 or (textattr shl 8);
  313. if x<WinMaxX then
  314. DosmemFillword($b800,((y-1)*ScreenWidth+(x-1))*2,WinMaxX-x+1,fil);
  315. End;
  316. Function WhereX: Byte;
  317. {
  318. Return current X-position of cursor.
  319. }
  320. var
  321. x,y : longint;
  322. Begin
  323. GetScreenCursor(x,y);
  324. WhereX:=x-WinMinX+1;
  325. End;
  326. Function WhereY: Byte;
  327. {
  328. Return current Y-position of cursor.
  329. }
  330. var
  331. x,y : longint;
  332. Begin
  333. GetScreenCursor(x,y);
  334. WhereY:=y-WinMinY+1;
  335. End;
  336. {*************************************************************************
  337. KeyBoard
  338. *************************************************************************}
  339. var
  340. is_last : boolean;
  341. last : char;
  342. function readkey : char;
  343. var
  344. char2 : char;
  345. char1 : char;
  346. {$ifdef GO32V2}
  347. regs : trealregs;
  348. {$endif GO32V2}
  349. begin
  350. if is_last then
  351. begin
  352. is_last:=false;
  353. readkey:=last;
  354. end
  355. else
  356. begin
  357. {$ifdef GO32V2}
  358. regs.realeax:=$0000;
  359. realintr($16,regs);
  360. char1:=chr(regs.realeax and $ff);
  361. char2:=chr((regs.realeax and $ff00) shr 8);
  362. {$else GO32V2}
  363. asm
  364. movb $0,%ah
  365. pushl %ebp
  366. int $0x16
  367. popl %ebp
  368. movb %al,char1
  369. movb %ah,char2
  370. end;
  371. {$endif GO32V2}
  372. if char1=#0 then
  373. begin
  374. is_last:=true;
  375. last:=char2;
  376. end;
  377. readkey:=char1;
  378. end;
  379. end;
  380. function keypressed : boolean;
  381. {$ifdef GO32V2}
  382. var
  383. regs : trealregs;
  384. {$endif GO32V2}
  385. begin
  386. if is_last then
  387. begin
  388. keypressed:=true;
  389. exit;
  390. end
  391. else
  392. begin
  393. {$ifdef GO32V2}
  394. regs.realeax:=$0100;
  395. realintr($16,regs);
  396. keypressed:=((regs.realflags and zeroflag) = 0);
  397. {$else GO32V2}
  398. asm
  399. movb $1,%ah
  400. pushl %ebp
  401. int $0x16
  402. popl %ebp
  403. setnz %al
  404. movb %al,__RESULT
  405. end;
  406. {$endif GO32V2}
  407. end;
  408. end;
  409. {*************************************************************************
  410. Delay
  411. *************************************************************************}
  412. procedure Delayloop;
  413. begin
  414. asm
  415. .LDelayLoop1:
  416. subl $1,%eax
  417. jc .LDelayLoop2
  418. cmpl %fs:(%edi),%ebx
  419. je .LDelayLoop1
  420. .LDelayLoop2:
  421. end;
  422. end;
  423. procedure initdelay;
  424. begin
  425. asm
  426. movl $0x46c,%edi
  427. movl $-28,%edx
  428. movl %fs:(%edi),%ebx
  429. .LInitDel1:
  430. cmpl %fs:(%edi),%ebx
  431. je .LInitDel1
  432. movl %fs:(%edi),%ebx
  433. movl %edx,%eax
  434. call DelayLoop
  435. notl %eax
  436. xorl %edx,%edx
  437. movl $55,%ecx
  438. divl %ecx
  439. movl %eax,DelayCnt
  440. end;
  441. end;
  442. procedure Delay(MS: Word);
  443. begin
  444. asm
  445. movzwl MS,%ecx
  446. jecxz .LDelay2
  447. movl $0x400,%edi
  448. movl DelayCnt,%edx
  449. movl %fs:(%edi),%ebx
  450. .LDelay1:
  451. movl %edx,%eax
  452. call DelayLoop
  453. loop .LDelay1
  454. .LDelay2:
  455. end;
  456. end;
  457. procedure sound(hz : word);
  458. begin
  459. if hz=0 then
  460. begin
  461. nosound;
  462. exit;
  463. end;
  464. asm
  465. movzwl hz,%ecx
  466. movl $1193046,%eax
  467. cdq
  468. divl %ecx
  469. movl %eax,%ecx
  470. movb $0xb6,%al
  471. outb %al,$0x43
  472. movb %cl,%al
  473. outb %al,$0x42
  474. movb %ch,%al
  475. outb %al,$0x42
  476. inb $0x61,%al
  477. orb $0x3,%al
  478. outb %al,$0x61
  479. end ['EAX','ECX','EDX'];
  480. end;
  481. procedure nosound;
  482. begin
  483. asm
  484. inb $0x61,%al
  485. andb $0xfc,%al
  486. outb %al,$0x61
  487. end ['EAX'];
  488. end;
  489. {****************************************************************************
  490. HighLevel Crt Functions
  491. ****************************************************************************}
  492. procedure removeline(y : longint);
  493. var
  494. fil : word;
  495. begin
  496. fil:=32 or (textattr shl 8);
  497. While (y<WinMaxY) do
  498. begin
  499. dosmemmove($b800,(((WinMinY+y)-1)*ScreenWidth+(WinMinX-1))*2,
  500. $b800,(((WinMinY+y-1)-1)*ScreenWidth+(WinMinX-1))*2,(WinMaxX-WinMinX+1)*2);
  501. inc(y);
  502. end;
  503. dosmemfillword($b800,((WinMaxY-1)*ScreenWidth+(WinMinX-1))*2,(WinMaxX-WinMinX+1),fil);
  504. end;
  505. procedure delline;
  506. begin
  507. removeline(wherey);
  508. end;
  509. procedure insline;
  510. var
  511. my,y : longint;
  512. fil : word;
  513. begin
  514. fil:=32 or (textattr shl 8);
  515. y:=WhereY;
  516. my:=WinMaxY-1;
  517. while (my>=y) do
  518. begin
  519. dosmemmove($b800,(((WinMinY+my-1)-1)*ScreenWidth+(WinMinX-1))*2,
  520. $b800,(((WinMinY+my)-1)*ScreenWidth+(WinMinX-1))*2,(WinMaxX-WinMinX+1)*2);
  521. dec(my);
  522. end;
  523. dosmemfillword($b800,(((WinMinY+y-1)-1)*ScreenWidth+(WinMinX-1))*2,(WinMaxX-WinMinX+1),fil);
  524. end;
  525. {****************************************************************************
  526. Extra Crt Functions
  527. ****************************************************************************}
  528. procedure cursoron;
  529. {$ifdef GO32V2}
  530. var
  531. regs : trealregs;
  532. {$endif GO32V2}
  533. begin
  534. {$ifndef GO32V2}
  535. asm
  536. movb $1,%ah
  537. movb $10,%cl
  538. movb $9,%ch
  539. pushl %ebp
  540. int $0x10
  541. popl %ebp
  542. end;
  543. {$else GO32V2}
  544. regs.realeax:=$0100;
  545. regs.realecx:=$90A;
  546. realintr($10,regs);
  547. {$endif GO32V2}
  548. end;
  549. procedure cursoroff;
  550. {$ifdef GO32V2}
  551. var
  552. regs : trealregs;
  553. {$endif GO32V2}
  554. begin
  555. {$ifdef GO32V2}
  556. regs.realeax:=$0100;
  557. regs.realecx:=$ffff;
  558. realintr($10,regs);
  559. {$else GO32V2}
  560. asm
  561. movb $1,%ah
  562. movb $-1,%cl
  563. movb $-1,%ch
  564. pushl %ebp
  565. int $0x10
  566. popl %ebp
  567. end;
  568. {$endif GO32V2}
  569. end;
  570. procedure cursorbig;
  571. {$ifdef GO32V2}
  572. var
  573. regs : trealregs;
  574. {$endif GO32V2}
  575. begin
  576. {$ifdef GO32V2}
  577. regs.realeax:=$0100;
  578. regs.realecx:=$10A;
  579. realintr($10,regs);
  580. {$else GO32V2}
  581. asm
  582. movb $1,%ah
  583. movw $110,%cx
  584. pushl %ebp
  585. int $0x10
  586. popl %ebp
  587. end;
  588. {$endif GO32V2}
  589. end;
  590. {*****************************************************************************
  591. Read and Write routines
  592. *****************************************************************************}
  593. var
  594. CurrX,CurrY : longint;
  595. Procedure WriteChar(c:char);
  596. var
  597. {$ifdef GO32V2}
  598. regs : trealregs;
  599. {$else}
  600. chattr : word;
  601. {$endif}
  602. begin
  603. case c of
  604. #10 : inc(CurrY);
  605. #13 : CurrX:=WinMinX;
  606. #8 : begin
  607. if CurrX>WinMinX then
  608. dec(CurrX);
  609. end;
  610. #7 : begin { beep }
  611. {$ifdef GO32V2}
  612. regs.dl:=7;
  613. regs.ah:=2;
  614. realintr($21,regs);
  615. {$endif}
  616. end;
  617. else
  618. begin
  619. {$ifdef GO32V2}
  620. memw[$b800:((CurrY-1)*ScreenWidth+(CurrX-1))*2]:=(textattr shl 8) or byte(c);
  621. {$else}
  622. chattr:=(textattr shl 8) or byte(c);
  623. dosmemput($b800,((CurrY-1)*ScreenWidth+(CurrX-1))*2,chattr,2);
  624. {$endif}
  625. inc(CurrX);
  626. end;
  627. end;
  628. if CurrX>WinMaxX then
  629. begin
  630. CurrX:=WinMinX;
  631. inc(CurrY);
  632. end;
  633. while CurrY>WinMaxY do
  634. begin
  635. removeline(1);
  636. dec(CurrY);
  637. end;
  638. end;
  639. Function CrtWrite(var f : textrec):integer;
  640. var
  641. i : longint;
  642. begin
  643. GetScreenCursor(CurrX,CurrY);
  644. for i:=0 to f.bufpos-1 do
  645. WriteChar(f.buffer[i]);
  646. SetScreenCursor(CurrX,CurrY);
  647. f.bufpos:=0;
  648. CrtWrite:=0;
  649. end;
  650. Function CrtRead(Var F: TextRec): Integer;
  651. procedure BackSpace;
  652. begin
  653. if (f.bufpos>0) and (f.bufpos=f.bufend) then
  654. begin
  655. WriteChar(#8);
  656. WriteChar(' ');
  657. WriteChar(#8);
  658. dec(f.bufpos);
  659. dec(f.bufend);
  660. end;
  661. end;
  662. var
  663. ch : Char;
  664. Begin
  665. f.bufpos:=0;
  666. f.bufend:=0;
  667. repeat
  668. if f.bufpos>f.bufend then
  669. f.bufend:=f.bufpos;
  670. SetScreenCursor(CurrY,CurrX);
  671. ch:=readkey;
  672. case ch of
  673. #0 : case readkey of
  674. #71 : while f.bufpos>0 do
  675. begin
  676. dec(f.bufpos);
  677. WriteChar(#8);
  678. end;
  679. #75 : if f.bufpos>0 then
  680. begin
  681. dec(f.bufpos);
  682. WriteChar(#8);
  683. end;
  684. #77 : if f.bufpos<f.bufend then
  685. begin
  686. WriteChar(f.bufptr^[f.bufpos]);
  687. inc(f.bufpos);
  688. end;
  689. #79 : while f.bufpos<f.bufend do
  690. begin
  691. WriteChar(f.bufptr^[f.bufpos]);
  692. inc(f.bufpos);
  693. end;
  694. end;
  695. ^S,
  696. #8 : BackSpace;
  697. ^Y,
  698. #27 : begin
  699. f.bufpos:=f.bufend;
  700. while f.bufend>0 do
  701. BackSpace;
  702. end;
  703. #13 : begin
  704. WriteChar(#13);
  705. WriteChar(#10);
  706. f.bufptr^[f.bufend]:=#13;
  707. f.bufptr^[f.bufend+1]:=#10;
  708. inc(f.bufend,2);
  709. break;
  710. end;
  711. #26 : if CheckEOF then
  712. begin
  713. f.bufptr^[f.bufend]:=#26;
  714. inc(f.bufend);
  715. break;
  716. end;
  717. else
  718. begin
  719. if f.bufpos<f.bufsize-2 then
  720. begin
  721. f.buffer[f.bufpos]:=ch;
  722. inc(f.bufpos);
  723. WriteChar(ch);
  724. end;
  725. end;
  726. end;
  727. until false;
  728. f.bufpos:=0;
  729. SetScreenCursor(CurrY,CurrX);
  730. CrtRead:=0;
  731. End;
  732. Function CrtReturn:Integer;
  733. Begin
  734. CrtReturn:=0;
  735. end;
  736. Function CrtClose(Var F: TextRec): Integer;
  737. Begin
  738. F.Mode:=fmClosed;
  739. CrtClose:=0;
  740. End;
  741. Function CrtOpen(Var F: TextRec): Integer;
  742. Begin
  743. If F.Mode=fmOutput Then
  744. begin
  745. TextRec(F).InOutFunc:=@CrtWrite;
  746. TextRec(F).FlushFunc:=@CrtWrite;
  747. end
  748. Else
  749. begin
  750. F.Mode:=fmInput;
  751. TextRec(F).InOutFunc:=@CrtRead;
  752. TextRec(F).FlushFunc:=@CrtReturn;
  753. end;
  754. TextRec(F).CloseFunc:=@CrtClose;
  755. CrtOpen:=0;
  756. End;
  757. procedure AssignCrt(var F: Text);
  758. begin
  759. Assign(F,'');
  760. TextRec(F).OpenFunc:=@CrtOpen;
  761. end;
  762. var
  763. x,y : longint;
  764. begin
  765. { Load startup values }
  766. ScreenWidth:=GetScreenWidth;
  767. ScreenHeight:=GetScreenHeight;
  768. WindMax:=(ScreenWidth-1) or ((ScreenHeight-1) shl 8);
  769. { Load TextAttr }
  770. GetScreenCursor(x,y);
  771. {$ifdef GO32V2}
  772. TextAttr:=mem[$b800:((y-1)*ScreenWidth+(x-1))*2+1];
  773. lastmode:=mem[$40:$49];
  774. {$else Go32V2}
  775. dosmemget($b800,((y-1)*ScreenWidth+(x-1))*2+1,TextAttr,1);
  776. dosmemget($40,$49,lastmode,1);
  777. {$endif Go32V2}
  778. { Redirect the standard output }
  779. assigncrt(Output);
  780. Rewrite(Output);
  781. TextRec(Output).Handle:=StdOutputHandle;
  782. assigncrt(Input);
  783. Reset(Input);
  784. TextRec(Input).Handle:=StdInputHandle;
  785. { Calculates delay calibration }
  786. initdelay;
  787. end.
  788. {
  789. $Log$
  790. Revision 1.9 1998-08-15 17:00:10 peter
  791. * moved delaycnt from interface to implementation
  792. Revision 1.8 1998/08/08 21:56:45 peter
  793. * updated crt with new delay, almost like bp7 routine
  794. Revision 1.5 1998/05/31 14:18:12 peter
  795. * force att or direct assembling
  796. * cleanup of some files
  797. Revision 1.4 1998/05/28 10:21:38 pierre
  798. * Handles of input and output restored
  799. Revision 1.3 1998/05/27 00:19:16 peter
  800. * fixed crt input
  801. Revision 1.2 1998/05/21 19:30:46 peter
  802. * objects compiles for linux
  803. + assign(pchar), assign(char), rename(pchar), rename(char)
  804. * fixed read_text_as_array
  805. + read_text_as_pchar which was not yet in the rtl
  806. }