crt.pp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999-2000 by Nils Sjoholm and Carl Eric Codere
  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. unit Crt;
  12. {--------------------------------------------------------------------}
  13. { LEFT TO DO: }
  14. {--------------------------------------------------------------------}
  15. { o Write special characters are not recognized }
  16. { o Write does not take care of window coordinates yet. }
  17. { o Read does not recognize the special editing characters }
  18. { o Read does not take care of window coordinates yet. }
  19. { o Readkey extended scancode is not correct yet }
  20. { o Color mapping only works for 4 colours }
  21. { o ClrScr, DeleteLine, InsLine do not work with window coordinates }
  22. {--------------------------------------------------------------------}
  23. Interface
  24. Const
  25. { Controlling consts }
  26. Flushing=false; {if true then don't buffer output}
  27. ScreenWidth = 80;
  28. ScreenHeight = 25;
  29. {$i crth.inc}
  30. Implementation
  31. {
  32. The definitions of TextRec and FileRec are in separate files.
  33. }
  34. {$i textrec.inc}
  35. {$i filerec.inc}
  36. var
  37. maxcols,maxrows : longint;
  38. CONST
  39. { This is used to make sure that readkey returns immediately }
  40. { if keypressed was used beforehand. }
  41. KeyPress : char = #0;
  42. _LVODisplayBeep = -96;
  43. Type
  44. pInfoData = ^tInfoData;
  45. tInfoData = packed record
  46. id_NumSoftErrors : Longint; { number of soft errors on disk }
  47. id_UnitNumber : Longint; { Which unit disk is (was) mounted on }
  48. id_DiskState : Longint; { See defines below }
  49. id_NumBlocks : Longint; { Number of blocks on disk }
  50. id_NumBlocksUsed : Longint; { Number of block in use }
  51. id_BytesPerBlock : Longint;
  52. id_DiskType : Longint; { Disk Type code }
  53. id_VolumeNode : Longint; { BCPL pointer to volume node }
  54. id_InUse : Longint; { Flag, zero if not in use }
  55. end;
  56. { * List Node Structure. Each member in a list starts with a Node * }
  57. pNode = ^tNode;
  58. tNode = packed Record
  59. ln_Succ, { * Pointer to next (successor) * }
  60. ln_Pred : pNode; { * Pointer to previous (predecessor) * }
  61. ln_Type : Byte;
  62. ln_Pri : Shortint; { * Priority, for sorting * }
  63. ln_Name : PChar; { * ID string, null terminated * }
  64. End; { * Note: Integer aligned * }
  65. { normal, full featured list }
  66. pList = ^tList;
  67. tList = packed record
  68. lh_Head : pNode;
  69. lh_Tail : pNode;
  70. lh_TailPred : pNode;
  71. lh_Type : Byte;
  72. l_pad : Byte;
  73. end;
  74. pMsgPort = ^tMsgPort;
  75. tMsgPort = packed record
  76. mp_Node : tNode;
  77. mp_Flags : Byte;
  78. mp_SigBit : Byte; { signal bit number }
  79. mp_SigTask : Pointer; { task to be signalled (TaskPtr) }
  80. mp_MsgList : tList; { message linked list }
  81. end;
  82. pMessage = ^tMessage;
  83. tMessage = packed record
  84. mn_Node : tNode;
  85. mn_ReplyPort : pMsgPort; { message reply port }
  86. mn_Length : Word; { message len in bytes }
  87. end;
  88. pIOStdReq = ^tIOStdReq;
  89. tIOStdReq = packed record
  90. io_Message : tMessage;
  91. io_Device : Pointer; { device node pointer }
  92. io_Unit : Pointer; { unit (driver private)}
  93. io_Command : Word; { device command }
  94. io_Flags : Byte;
  95. io_Error : Shortint; { error or warning num }
  96. io_Actual : Longint; { actual number of bytes transferred }
  97. io_Length : Longint; { requested number bytes transferred}
  98. io_Data : Pointer; { points to data area }
  99. io_Offset : Longint; { offset for block structured devices }
  100. end;
  101. pIntuiMessage = ^tIntuiMessage;
  102. tIntuiMessage = packed record
  103. ExecMessage : tMessage;
  104. IClass : Longint;
  105. Code : Word;
  106. Qualifier : Word;
  107. IAddress : Pointer;
  108. MouseX,
  109. MouseY : Word;
  110. Seconds,
  111. Micros : Longint;
  112. IDCMPWindow : Pointer;
  113. SpecialLink : pIntuiMessage;
  114. end;
  115. pWindow = ^tWindow;
  116. tWindow = packed record
  117. NextWindow : pWindow; { for the linked list in a screen }
  118. LeftEdge,
  119. TopEdge : Integer; { screen dimensions of window }
  120. Width,
  121. Height : Integer; { screen dimensions of window }
  122. MouseY,
  123. MouseX : Integer; { relative to upper-left of window }
  124. MinWidth,
  125. MinHeight : Integer; { minimum sizes }
  126. MaxWidth,
  127. MaxHeight : Word; { maximum sizes }
  128. Flags : Longint; { see below for defines }
  129. MenuStrip : Pointer; { the strip of Menu headers }
  130. Title : PChar; { the title text for this window }
  131. FirstRequest : Pointer; { all active Requesters }
  132. DMRequest : Pointer; { double-click Requester }
  133. ReqCount : Integer; { count of reqs blocking Window }
  134. WScreen : Pointer; { this Window's Screen }
  135. RPort : Pointer; { this Window's very own RastPort }
  136. BorderLeft,
  137. BorderTop,
  138. BorderRight,
  139. BorderBottom : Shortint;
  140. BorderRPort : Pointer;
  141. FirstGadget : Pointer;
  142. Parent,
  143. Descendant : pWindow;
  144. Pointer_ : Pointer; { sprite data }
  145. PtrHeight : Shortint; { sprite height (not including sprite padding) }
  146. PtrWidth : Shortint; { sprite width (must be less than or equal to 16) }
  147. XOffset,
  148. YOffset : Shortint; { sprite offsets }
  149. IDCMPFlags : Longint; { User-selected flags }
  150. UserPort,
  151. WindowPort : pMsgPort;
  152. MessageKey : pIntuiMessage;
  153. DetailPen,
  154. BlockPen : Byte; { for bar/border/gadget rendering }
  155. CheckMark : Pointer;
  156. ScreenTitle : PChar; { if non-null, Screen title when Window is active }
  157. GZZMouseX : Integer;
  158. GZZMouseY : Integer;
  159. GZZWidth : Integer;
  160. GZZHeight : Word;
  161. ExtData : Pointer;
  162. UserData : Pointer; { general-purpose pointer to User data extension }
  163. WLayer : Pointer;
  164. IFont : Pointer;
  165. MoreFlags : Longint;
  166. end;
  167. const
  168. M_LNM = 20; { linefeed newline mode }
  169. PMB_ASM = M_LNM + 1; { internal storage bit for AS flag }
  170. PMB_AWM = PMB_ASM + 1; { internal storage bit for AW flag }
  171. MAXTABS = 80;
  172. IECLASS_MAX = $15;
  173. type
  174. pKeyMap = ^tKeyMap;
  175. tKeyMap = packed record
  176. km_LoKeyMapTypes : Pointer;
  177. km_LoKeyMap : Pointer;
  178. km_LoCapsable : Pointer;
  179. km_LoRepeatable : Pointer;
  180. km_HiKeyMapTypes : Pointer;
  181. km_HiKeyMap : Pointer;
  182. km_HiCapsable : Pointer;
  183. km_HiRepeatable : Pointer;
  184. end;
  185. pConUnit = ^tConUnit;
  186. tConUnit = packed record
  187. cu_MP : tMsgPort;
  188. { ---- read only variables }
  189. cu_Window : Pointer; { (WindowPtr) intuition window bound to this unit }
  190. cu_XCP : Integer; { character position }
  191. cu_YCP : Integer;
  192. cu_XMax : Integer; { max character position }
  193. cu_YMax : Integer;
  194. cu_XRSize : Integer; { character raster size }
  195. cu_YRSize : Integer;
  196. cu_XROrigin : Integer; { raster origin }
  197. cu_YROrigin : Integer;
  198. cu_XRExtant : Integer; { raster maxima }
  199. cu_YRExtant : Integer;
  200. cu_XMinShrink : Integer; { smallest area intact from resize process }
  201. cu_YMinShrink : Integer;
  202. cu_XCCP : Integer; { cursor position }
  203. cu_YCCP : Integer;
  204. { ---- read/write variables (writes must must be protected) }
  205. { ---- storage for AskKeyMap and SetKeyMap }
  206. cu_KeyMapStruct : tKeyMap;
  207. { ---- tab stops }
  208. cu_TabStops : Array [0..MAXTABS-1] of Word;
  209. { 0 at start, -1 at end of list }
  210. { ---- console rastport attributes }
  211. cu_Mask : Shortint;
  212. cu_FgPen : Shortint;
  213. cu_BgPen : Shortint;
  214. cu_AOLPen : Shortint;
  215. cu_DrawMode : Shortint;
  216. cu_AreaPtSz : Shortint;
  217. cu_AreaPtrn : Pointer; { cursor area pattern }
  218. cu_Minterms : Array [0..7] of Byte; { console minterms }
  219. cu_Font : Pointer; { (TextFontPtr) }
  220. cu_AlgoStyle : Byte;
  221. cu_TxFlags : Byte;
  222. cu_TxHeight : Word;
  223. cu_TxWidth : Word;
  224. cu_TxBaseline : Word;
  225. cu_TxSpacing : Word;
  226. { ---- console MODES and RAW EVENTS switches }
  227. cu_Modes : Array [0..(PMB_AWM+7) div 8 - 1] of Byte;
  228. { one bit per mode }
  229. cu_RawEvents : Array [0..(IECLASS_MAX+7) div 8 - 1] of Byte;
  230. end;
  231. const
  232. CD_CURRX = 1;
  233. CD_CURRY = 2;
  234. CD_MAXX = 3;
  235. CD_MAXY = 4;
  236. CSI = chr($9b);
  237. SIGBREAKF_CTRL_C = 4096;
  238. function AllocVec( size, reqm : Longint ): Pointer;
  239. begin
  240. asm
  241. MOVE.L A6,-(A7)
  242. MOVE.L size,d0
  243. MOVE.L reqm,d1
  244. MOVE.L _ExecBase, A6
  245. JSR -684(A6)
  246. MOVE.L (A7)+,A6
  247. MOVE.L d0,@RESULT
  248. end;
  249. end;
  250. function DoPkt(ID : pMsgPort;
  251. Action, Param1, Param2,
  252. Param3, Param4, Param5 : Longint) : Longint;
  253. begin
  254. asm
  255. MOVEM.L d2/d3/d4/d5/d6/d7/a6,-(A7)
  256. MOVE.L ID,d1
  257. MOVE.L Action,d2
  258. MOVE.L Param1,d3
  259. MOVE.L Param2,d4
  260. MOVE.L Param3,d5
  261. MOVE.L Param4,d6
  262. MOVE.L Param5,d7
  263. MOVE.L _DOSBase,A6
  264. JSR -240(A6)
  265. MOVEM.L (A7)+,d2/d3/d4/d5/d6/d7/a6
  266. MOVE.L d0,@RESULT
  267. end;
  268. end;
  269. procedure FreeVec( memory : Pointer );
  270. begin
  271. asm
  272. MOVE.L A6,-(A7)
  273. MOVE.L memory,a1
  274. MOVE.L _ExecBase,A6
  275. JSR -690(A6)
  276. MOVE.L (A7)+,A6
  277. end;
  278. end;
  279. function GetConsoleTask : pMsgPort;
  280. begin
  281. asm
  282. MOVE.L A6,-(A7)
  283. MOVE.L _DOSBase,A6
  284. JSR -510(A6)
  285. MOVE.L (A7)+,A6
  286. MOVE.L d0,@RESULT
  287. end;
  288. end;
  289. function GetMsg(port : pMsgPort): pMessage;
  290. begin
  291. asm
  292. MOVE.L A6,-(A7)
  293. MOVE.L port,a0
  294. MOVE.L _ExecBase,A6
  295. JSR -372(A6)
  296. MOVE.L (A7)+,A6
  297. MOVE.L d0,@RESULT
  298. end;
  299. end;
  300. function ModifyIDCMP(window : pWindow;
  301. IDCMPFlags : Longint) : Boolean;
  302. begin
  303. asm
  304. MOVE.L A6,-(A7)
  305. MOVE.L window,a0
  306. MOVE.L IDCMPFlags,d0
  307. MOVE.L _IntuitionBase,A6
  308. JSR -150(A6)
  309. MOVE.L (A7)+,A6
  310. TST.L d0
  311. bne @success
  312. bra @end
  313. @success:
  314. move.b #1,d0
  315. @end:
  316. move.b d0,@RESULT
  317. end;
  318. end;
  319. procedure ReplyMsg(mess : pMessage);
  320. begin
  321. asm
  322. MOVE.L A6,-(A7)
  323. MOVE.L mess,a1
  324. MOVE.L _ExecBase,A6
  325. JSR -378(A6)
  326. MOVE.L (A7)+,A6
  327. end;
  328. end;
  329. function WaitPort(port : pMsgPort): pMessage;
  330. begin
  331. asm
  332. MOVE.L A6,-(A7)
  333. MOVE.L port,a0
  334. MOVE.L _ExecBase,A6
  335. JSR -384(A6)
  336. MOVE.L (A7)+,A6
  337. MOVE.L d0,@RESULT
  338. end;
  339. end;
  340. procedure Delay_(ticks : Longint);
  341. begin
  342. asm
  343. MOVE.L A6,-(A7)
  344. MOVE.L ticks,d1
  345. MOVE.L _DOSBase,A6
  346. JSR -198(A6)
  347. MOVE.L (A7)+,A6
  348. end;
  349. end;
  350. function SetSignal(newSignals, signalMask : Longint) : Longint;
  351. begin
  352. asm
  353. MOVE.L A6,-(A7)
  354. MOVE.L newSignals,d0
  355. MOVE.L signalMask,d1
  356. MOVE.L _ExecBase,A6
  357. JSR -306(A6)
  358. MOVE.L (A7)+,A6
  359. MOVE.L d0,@RESULT
  360. end;
  361. end;
  362. function OpenInfo : pInfoData;
  363. var
  364. port : pMsgPort;
  365. info : pInfoData;
  366. bptr, d4, d5, d6, d7 : Longint;
  367. begin
  368. info := pInfoData(AllocVec(SizeOf(tInfoData), 1));
  369. if info <> nil then begin
  370. port := GetConsoleTask;
  371. bptr := Longint(info) shr 2;
  372. if port <> nil then begin
  373. if DoPkt(port, $19, bptr, d4, d5, d6, d7) <> 0 then info := pInfoData(bptr shl 2)
  374. else port := nil;
  375. end;
  376. if port = nil then begin
  377. FreeVec(info);
  378. info := nil;
  379. end;
  380. end;
  381. OpenInfo := info;
  382. end;
  383. procedure CloseInfo(var info : pInfoData);
  384. begin
  385. if info <> nil then begin
  386. FreeVec(info);
  387. info := nil;
  388. end;
  389. end;
  390. function ConData(modus : byte) : integer;
  391. var
  392. info : pInfoData;
  393. theunit : pConUnit;
  394. pos : Longint;
  395. begin
  396. pos := 1;
  397. info := OpenInfo;
  398. if info <> nil then begin
  399. theunit := pConUnit((pIoStdReq(info^.id_InUse))^.io_Unit);
  400. case modus of
  401. CD_CURRX : pos := theunit^.cu_XCP;
  402. CD_CURRY : pos := theunit^.cu_YCP;
  403. CD_MAXX : pos := theunit^.cu_XMax;
  404. CD_MAXY : pos := theunit^.cu_YMax;
  405. end;
  406. CloseInfo(info);
  407. end;
  408. ConData := pos + 1;
  409. end;
  410. function WhereX : Byte;
  411. begin
  412. WhereX := Byte(ConData(CD_CURRX))-lo(windmin);
  413. end;
  414. function realx: byte;
  415. begin
  416. RealX := Byte(ConData(CD_CURRX));
  417. end;
  418. function realy: byte;
  419. begin
  420. RealY := Byte(ConData(CD_CURRY));
  421. end;
  422. function WhereY : Byte;
  423. begin
  424. WhereY := Byte(ConData(CD_CURRY))-hi(windmin);
  425. end;
  426. function screencols : integer;
  427. begin
  428. screencols := ConData(CD_MAXX);
  429. end;
  430. function screenrows : integer;
  431. begin
  432. screenrows := ConData(CD_MAXY);
  433. end;
  434. procedure Realgotoxy(x,y : integer);
  435. begin
  436. Write(CSI, y, ';', x, 'H');
  437. end;
  438. procedure gotoxy(x,y : byte);
  439. begin
  440. if (x<1) then
  441. x:=1;
  442. if (y<1) then
  443. y:=1;
  444. if y+hi(windmin)-2>=hi(windmax) then
  445. y:=hi(windmax)-hi(windmin)+1;
  446. if x+lo(windmin)-2>=lo(windmax) then
  447. x:=lo(windmax)-lo(windmin)+1;
  448. Write(CSI, y+hi(windmin), ';', x+lo(windmin), 'H');
  449. end;
  450. procedure CursorOff;
  451. begin
  452. Write(CSI,'0 p');
  453. end;
  454. procedure CursorOn;
  455. begin
  456. Write(CSI,'1 p');
  457. end;
  458. procedure ClrScr;
  459. begin
  460. Write(Chr($0c));
  461. end;
  462. function ReadKey : char;
  463. const
  464. IDCMP_VANILLAKEY = $00200000;
  465. IDCMP_RAWKEY = $00000400;
  466. var
  467. info : pInfoData;
  468. win : pWindow;
  469. imsg : pIntuiMessage;
  470. msg : pMessage;
  471. key : char;
  472. idcmp, vanil : Longint;
  473. begin
  474. key := #0;
  475. if KeyPress <> #0 then
  476. Begin
  477. ReadKey:=KeyPress;
  478. KeyPress:=#0;
  479. exit;
  480. end;
  481. info := OpenInfo;
  482. if info <> nil then begin
  483. win := pWindow(pConUnit((pIoStdReq(info^.id_InUse))^.io_Unit)^.cu_Window);
  484. idcmp := win^.IDCMPFlags;
  485. vanil := IDCMP_VANILLAKEY or IDCMP_RAWKEY;
  486. ModifyIDCMP(win, (idcmp or vanil));
  487. repeat
  488. msg := WaitPort(win^.UserPort);
  489. imsg := pIntuiMessage(GetMsg(win^.UserPort));
  490. if (imsg^.IClass = IDCMP_VANILLAKEY) then
  491. key := char(imsg^.Code)
  492. else
  493. if (imsg^.IClass = IDCMP_RAWKEY) then
  494. key := char(imsg^.Code);
  495. ReplyMsg(pMessage(imsg));
  496. until key <> #0;
  497. repeat
  498. msg := GetMsg(win^.UserPort);
  499. if msg <> nil then ReplyMsg(msg);
  500. until msg = nil;
  501. ModifyIDCMP(win, idcmp);
  502. CloseInfo(info);
  503. end;
  504. ReadKey := key;
  505. end;
  506. function KeyPressed : Boolean;
  507. const
  508. IDCMP_VANILLAKEY = $00200000;
  509. IDCMP_RAWKEY = $00000400;
  510. var
  511. info : pInfoData;
  512. win : pWindow;
  513. imsg : pIntuiMessage;
  514. msg : pMessage;
  515. idcmp, vanil : Longint;
  516. ispressed : Boolean;
  517. begin
  518. KeyPress := #0;
  519. ispressed := False;
  520. info := OpenInfo;
  521. if info <> nil then begin
  522. win := pWindow(pConUnit((pIoStdReq(info^.id_InUse))^.io_Unit)^.cu_Window);
  523. idcmp := win^.IDCMPFlags;
  524. vanil := IDCMP_VANILLAKEY or IDCMP_RAWKEY;
  525. ModifyIDCMP(win, (idcmp or vanil));
  526. msg := WaitPort(win^.UserPort);
  527. imsg := pIntuiMessage(GetMsg(win^.UserPort));
  528. if (imsg^.IClass = IDCMP_VANILLAKEY) or (imsg^.IClass = IDCMP_RAWKEY) then
  529. Begin
  530. ispressed := true;
  531. KeyPress := char(imsg^.Code)
  532. end;
  533. ReplyMsg(pMessage(imsg));
  534. repeat
  535. msg := GetMsg(win^.UserPort);
  536. if msg <> nil then ReplyMsg(msg);
  537. until msg = nil;
  538. ModifyIDCMP(win, idcmp);
  539. CloseInfo(info);
  540. end;
  541. KeyPressed := ispressed;
  542. end;
  543. procedure TextColor(color : byte);
  544. begin
  545. TextAttr := (TextAttr and $70) or color;
  546. Write(CSI, '3', color, 'm');
  547. end;
  548. procedure TextBackground(color : byte);
  549. begin
  550. Textattr:=(textattr and $8f) or ((color and $7) shl 4);
  551. Write(CSI, '4', color, 'm');
  552. end;
  553. procedure Window(X1,Y1,X2,Y2: Byte);
  554. begin
  555. if (x1<1) or (x2>screencols) or (y2>screenrows) or
  556. (x1>x2) or (y1>y2) then
  557. exit;
  558. windmin:=(x1-1) or ((y1-1) shl 8);
  559. windmax:=(x2-1) or ((y2-1) shl 8);
  560. gotoxy(1,1);
  561. end;
  562. procedure DelLine;
  563. begin
  564. Write(CSI,'X');
  565. end;
  566. procedure ClrEol;
  567. begin
  568. Write(CSI,'K');
  569. end;
  570. procedure InsLine;
  571. begin
  572. Write(CSI,'1 L');
  573. end;
  574. procedure cursorbig;
  575. begin
  576. end;
  577. procedure lowvideo;
  578. begin
  579. end;
  580. procedure highvideo;
  581. begin
  582. end;
  583. procedure nosound;
  584. begin
  585. end;
  586. procedure sound(hz : word);
  587. begin
  588. end;
  589. procedure delay(DTime : Word);
  590. var
  591. dummy : Longint;
  592. begin
  593. dummy := trunc((real(DTime) / 1000.0) * 50.0);
  594. Delay_(dummy);
  595. end;
  596. function CheckBreak : boolean;
  597. begin
  598. if (SetSignal(0, 0) and SIGBREAKF_CTRL_C) = SIGBREAKF_CTRL_C then
  599. CheckBreak := true
  600. else
  601. CheckBreak := false;
  602. end;
  603. procedure textmode(mode : integer);
  604. begin
  605. lastmode:=mode;
  606. mode:=mode and $ff;
  607. windmin:=0;
  608. windmax:=(screencols-1) or ((screenrows-1) shl 8);
  609. maxcols:=screencols;
  610. maxrows:=screenrows;
  611. end;
  612. procedure normvideo;
  613. begin
  614. end;
  615. function GetTextBackground : byte;
  616. var
  617. info : pInfoData;
  618. pen : byte;
  619. begin
  620. pen := 1;
  621. info := OpenInfo;
  622. if info <> nil then begin
  623. pen := pConUnit((pIoStdReq(info^.id_InUse))^.io_Unit)^.cu_BgPen;
  624. CloseInfo(info);
  625. end;
  626. GetTextBackground := pen;
  627. end;
  628. function GetTextColor : byte;
  629. var
  630. info : pInfoData;
  631. pen : byte;
  632. begin
  633. pen := 1;
  634. info := OpenInfo;
  635. if info <> nil then begin
  636. pen := pConUnit((pIoStdReq(info^.id_InUse))^.io_Unit)^.cu_FgPen;
  637. CloseInfo(info);
  638. end;
  639. GetTextColor := pen;
  640. end;
  641. {*****************************************************************************
  642. Read and Write routines
  643. *****************************************************************************}
  644. { Problem here: Currently all these routines are not implemented because of how }
  645. { the console device works. Because w low level write is required to change the }
  646. { position of the cursor, and since the CrtWrite is assigned as the standard }
  647. { write routine, a recursive call will occur }
  648. { How to fix this: }
  649. { At startup make a copy of the Output handle, and then use this copy to make }
  650. { low level positioning calls. This does not seem to work yet. }
  651. Function CrtWrite(var f : textrec):integer;
  652. var
  653. i,col,row : longint;
  654. c : char;
  655. buf: array[0..1] of char;
  656. begin
  657. col:=realx;
  658. row:=realy;
  659. inc(row);
  660. inc(col);
  661. for i:=0 to f.bufpos-1 do
  662. begin
  663. c:=f.buffer[i];
  664. case ord(c) of
  665. 10 : begin
  666. inc(row);
  667. end;
  668. 13 : begin
  669. col:=lo(windmin)+1;
  670. end;
  671. 8 : if col>lo(windmin)+1 then
  672. begin
  673. dec(col);
  674. end;
  675. 7 : begin
  676. { beep }
  677. asm
  678. move.l a6,d6 { save base pointer }
  679. move.l _IntuitionBase,a6 { set library base }
  680. sub.l a0,a0
  681. jsr _LVODisplayBeep(a6)
  682. move.l d6,a6 { restore base pointer }
  683. end;
  684. end;
  685. else
  686. begin
  687. buf[0]:=c;
  688. realgotoxy(row,col);
  689. do_write(f.handle,longint(@buf[0]),1);
  690. inc(col);
  691. end;
  692. end;
  693. if col>lo(windmax)+1 then
  694. begin
  695. col:=lo(windmin)+1;
  696. inc(row);
  697. end;
  698. while row>hi(windmax)+1 do
  699. begin
  700. delline;
  701. dec(row);
  702. end;
  703. end;
  704. f.bufpos:=0;
  705. realgotoxy(row-1,col-1);
  706. CrtWrite:=0;
  707. end;
  708. Function CrtClose(Var F: TextRec): Integer;
  709. Begin
  710. F.Mode:=fmClosed;
  711. CrtClose:=0;
  712. End;
  713. Function CrtOpen(Var F: TextRec): Integer;
  714. Begin
  715. If F.Mode = fmOutput Then
  716. CrtOpen:=0
  717. Else
  718. CrtOpen:=5;
  719. End;
  720. Function CrtRead(Var F: TextRec): Integer;
  721. Begin
  722. f.bufend:=do_read(f.handle,longint(f.bufptr),f.bufsize);
  723. f.bufpos:=0;
  724. CrtRead:=0;
  725. End;
  726. Function CrtInOut(Var F: TextRec): Integer;
  727. Begin
  728. Case F.Mode of
  729. fmInput: CrtInOut:=CrtRead(F);
  730. fmOutput: CrtInOut:=CrtWrite(F);
  731. End;
  732. End;
  733. procedure assigncrt(var f : text);
  734. begin
  735. { TextRec(F).Mode:=fmClosed;
  736. TextRec(F).BufSize:=SizeOf(TextBuf);
  737. TextRec(F).BufPtr:=@TextRec(F).Buffer;
  738. TextRec(F).BufPos:=0;
  739. TextRec(F).OpenFunc:=@CrtOpen;
  740. TextRec(F).InOutFunc:=@CrtInOut;
  741. TextRec(F).FlushFunc:=@CrtInOut;
  742. TextRec(F).CloseFunc:=@CrtClose;
  743. TextRec(F).Name[0]:='.';
  744. TextRec(F).Name[1]:=#0;}
  745. end;
  746. var
  747. old_exit : pointer;
  748. procedure crt_exit;
  749. begin
  750. { Restore default colors }
  751. write(CSI,'0m');
  752. exitproc:=old_exit;
  753. end;
  754. Begin
  755. old_exit:=exitproc;
  756. exitproc:=@crt_exit;
  757. { load system variables to temporary variables to save time }
  758. maxcols:=screencols;
  759. maxrows:=screenrows;
  760. { Set the initial text attributes }
  761. { Text background }
  762. Textattr:=(textattr and $8f) or ((GetTextBackGround and $7) shl 4);
  763. { Text foreground }
  764. TextAttr := (TextAttr and $70) or GetTextColor;
  765. { set output window }
  766. windmax:=(maxcols-1) or (( maxrows-1) shl 8);
  767. { Get a copy of the standard }
  768. { output handle, and when using }
  769. { direct console calls, use this }
  770. { handle instead. }
  771. { assigncrt(Output);
  772. TextRec(Output).mode:=fmOutput;}
  773. end.
  774. $Log$
  775. Revision 1.4 2004-02-08 16:22:20 michael
  776. + Moved CRT interface to common include file
  777. Revision 1.3 2002/09/07 16:01:16 peter
  778. * old logs removed and tabs fixed
  779. }