crt.pp 19 KB

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