crt.pp 23 KB

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