crt.pas 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958
  1. {****************************************************************************
  2. Standard CRT unit.
  3. Free Pascal runtime library for EMX.
  4. Copyright (c) 1997 Daniel Mantione.
  5. This file may be reproduced and modified under the same conditions
  6. as all other Free Pascal source code.
  7. ****************************************************************************}
  8. unit crt;
  9. {$ASMMODE ATT}
  10. interface
  11. {$i crth.inc}
  12. {cemodeset means that the procedure textmode has failed to set up a mode.}
  13. type
  14. cexxxx=(cenoerror,cemodeset);
  15. var
  16. crt_error:cexxxx; {Crt-status. RW}
  17. {***************************************************************************}
  18. implementation
  19. {$i textrec.inc}
  20. const extkeycode:char=#0;
  21. var maxrows,maxcols:word;
  22. calibration:longint;
  23. type Tkbdkeyinfo=record
  24. charcode,scancode:char;
  25. fbstatus,bnlsshift:byte;
  26. fsstate:word;
  27. time:longint;
  28. end;
  29. {if you have information on the folowing datastructure, please
  30. send them to me at [email protected]}
  31. {This datastructure is needed when we ask in what video mode we are,
  32. or we want to set up a new mode.}
  33. viomodeinfo=record
  34. cb:word; { length of the entire data
  35. structure }
  36. fbtype, { bit mask of mode being set}
  37. color: byte; { number of colors (power of 2) }
  38. col, { number of text columns }
  39. row, { number of text rows }
  40. hres, { horizontal resolution }
  41. vres: word; { vertical resolution }
  42. fmt_ID, { attribute format
  43. ! more info wanted !}
  44. attrib: byte; { number of attributes }
  45. buf_addr, { physical address of
  46. videobuffer, e.g. $0b800}
  47. buf_length, { length of a videopage (bytes)}
  48. full_length, { total video-memory on video-
  49. card (bytes)}
  50. partial_length:longint; { ????? info wanted !}
  51. ext_data_addr:pointer; { ????? info wanted !}
  52. end;
  53. Pviomodeinfo=^viomodeinfo;
  54. TVioCursorInfo=record
  55. case boolean of
  56. false:(
  57. yStart:word; {Cursor start (top) scan line (0-based)}
  58. cEnd:word; {Cursor end (bottom) scan line}
  59. cx:word; {Cursor width (0=default width)}
  60. Attr:word); {Cursor colour attribute (-1=hidden)}
  61. true:(
  62. yStartInt: integer; {integer variants can be used to specify negative}
  63. cEndInt:integer; {negative values (interpreted as percentage by OS/2)}
  64. cxInt:integer;
  65. AttrInt:integer);
  66. end;
  67. PVioCursorInfo=^TVioCursorInfo;
  68. {EMXWRAP.DLL has strange calling conventions: All parameters must have
  69. a 4 byte size.}
  70. function kbdcharin(var Akeyrec:Tkbdkeyinfo;wait,kbdhandle:longint):word; cdecl;
  71. external 'EMXWRAP' index 204;
  72. function kbdpeek(var Akeyrec:TkbdkeyInfo;kbdhandle:word):word; cdecl;
  73. external 'EMXWRAP' index 222;
  74. function dossleep(time:cardinal):cardinal; cdecl;
  75. external 'DOSCALLS' index 229;
  76. function vioscrollup(top,left,bottom,right,lines:longint;
  77. var screl:word;viohandle:longint):word; cdecl;
  78. external 'EMXWRAP' index 107;
  79. function vioscrolldn(top,left,bottom,right,lines:longint;
  80. var screl:word;viohandle:longint):word; cdecl;
  81. external 'EMXWRAP' index 147;
  82. function viogetcurpos(var row,column:word;viohandle:longint):word; cdecl;
  83. external 'EMXWRAP' index 109;
  84. function viosetcurpos(row,column,viohandle:longint):word; cdecl;
  85. external 'EMXWRAP' index 115;
  86. function viowrtTTY(s:Pchar;len,viohandle:longint):word; cdecl;
  87. external 'EMXWRAP' index 119;
  88. function viowrtcharstratt(s:Pchar;len,row,col:longint;var attr:byte;
  89. viohandle:longint):word; cdecl;
  90. external 'EMXWRAP' index 148;
  91. function viogetmode(var Amodeinfo:viomodeinfo;viohandle:longint):word; cdecl;
  92. external 'EMXWRAP' index 121;
  93. function viosetmode(var Amodeinfo:viomodeinfo;viohandle:longint):word; cdecl;
  94. external 'EMXWRAP' index 122;
  95. function VioSetCurType(var CurData:TVioCursorInfo;VioHandle:word):word; cdecl;
  96. external 'EMXWRAP' index 132;
  97. {external 'VIOCALLS' index 32;}
  98. function VioGetCurType(var CurData:TVioCursorInfo;VioHandle:word):word; cdecl;
  99. external 'EMXWRAP' index 127;
  100. {external 'VIOCALLS' index 27;}
  101. procedure syscall;external name '___SYSCALL';
  102. procedure setscreenmode(mode:word);
  103. { This procedure sets a new videomode. Note that the constants passes to
  104. this procedure are different than in the dos mode.}
  105. const modecols:array[0..2] of word=(40,80,132);
  106. moderows:array[0..3] of word=(25,28,43,50);
  107. var newmode:viomodeinfo;
  108. begin
  109. if os_mode=osOS2 then
  110. begin
  111. newmode.cb:=8;
  112. newmode.fbtype:=1; {Non graphics colour mode.}
  113. newmode.color:=4; {We want 16 colours, 2^4=16.}
  114. newmode.col:=modecols[mode and 15];
  115. newmode.row:=moderows[mode shr 4];
  116. if viosetmode(newmode,0)=0 then
  117. crt_error:=cenoerror
  118. else
  119. crt_error:=cemodeset;
  120. maxcols:=newmode.col;
  121. maxrows:=newmode.row;
  122. end
  123. else
  124. begin
  125. maxcols:=modecols[mode and 15];
  126. maxrows:=moderows[mode shr 4];
  127. crt_error:=cenoerror;
  128. {Set correct vertical resolution.}
  129. asm
  130. movw $0x1202,%ax
  131. movw 8(%ebp),%bx
  132. shrw $4,%bx
  133. cmpb $2,%bl
  134. jne .L_crtsetmode_a1
  135. decw %ax
  136. .L_crtsetmode_a1:
  137. mov $0x30,%bl
  138. int $0x10
  139. end;
  140. {132 column mode in DOS is videocard dependend.}
  141. if mode and 15=2 then
  142. begin
  143. crt_error:=cemodeset;
  144. exit;
  145. end;
  146. {Switch to correct mode.}
  147. asm
  148. mov 8(%ebp),%bx
  149. and $15,%bl
  150. mov $1,%ax
  151. cmp $1,%bl
  152. jne .L_crtsetmode_b1
  153. mov $3,%al
  154. .L_crtsetmode_b1:
  155. int $0x10
  156. {Use alternate print-screen function.}
  157. mov $0x12,%ah
  158. mov $0x20,%bl
  159. int $0x10
  160. end;
  161. {Set correct font.}
  162. case mode shr 4 of
  163. 1:
  164. {Set 8x14 font.}
  165. asm
  166. mov $0x1111,%ax
  167. mov $0,%bl
  168. int $0x10
  169. end;
  170. 2,3:
  171. {Set 8x8 font.}
  172. asm
  173. mov $0x1112,%ax
  174. mov $0,%bl
  175. int $0x10
  176. end;
  177. end;
  178. end;
  179. end;
  180. procedure getcursor(var y,x:word);
  181. {Get the cursor position.}
  182. begin
  183. if os_mode=osOS2 then
  184. viogetcurpos(y,x,0)
  185. else
  186. asm
  187. movb $3,%ah
  188. movb $0,%bh
  189. int $0x10
  190. movl y,%eax
  191. movl x,%ebx
  192. movzbl %dh,%edi
  193. andw $255,%dx
  194. movw %di,(%eax)
  195. movw %dx,(%ebx)
  196. end;
  197. end;
  198. {$ASMMODE INTEL}
  199. procedure setcursor(y,x:word);
  200. {Set the cursor position.}
  201. begin
  202. if os_mode=osOS2 then
  203. viosetcurpos(y,x,0)
  204. else
  205. asm
  206. mov ah, 2
  207. mov bh, 0
  208. mov dh, byte ptr y
  209. mov dl, byte ptr x
  210. int 10h
  211. end;
  212. end;
  213. procedure scroll_up(top,left,bottom,right,lines:word;var screl:word);
  214. begin
  215. if os_mode=osOS2 then
  216. vioscrollup(top,left,bottom,right,lines,screl,0)
  217. else
  218. asm
  219. mov ah, 6
  220. mov al, byte ptr lines
  221. mov edi, screl
  222. mov bh, [edi + 1]
  223. mov ch, byte ptr top
  224. mov cl, byte ptr left
  225. mov dh, byte ptr bottom
  226. mov dl, byte ptr right
  227. int 10h
  228. end;
  229. end;
  230. procedure scroll_dn(top,left,bottom,right,lines:word;var screl:word);
  231. begin
  232. if os_mode=osOS2 then
  233. vioscrolldn(top,left,bottom,right,lines,screl,0)
  234. else
  235. asm
  236. mov ah, 7
  237. mov al, byte ptr lines
  238. mov edi, screl
  239. mov bh, [edi + 1]
  240. mov ch, byte ptr top
  241. mov cl, byte ptr left
  242. mov dh, byte ptr bottom
  243. mov dl, byte ptr right
  244. int 10h
  245. end;
  246. end;
  247. {$ASMMODE ATT}
  248. function keypressed:boolean;
  249. {Checks if a key is pressed.}
  250. var Akeyrec:Tkbdkeyinfo;
  251. begin
  252. if os_mode=osOS2 then
  253. begin
  254. kbdpeek(Akeyrec,0);
  255. keypressed:=(extkeycode<>#0) or ((Akeyrec.fbstatus and $40)<>0);
  256. end
  257. else
  258. begin
  259. if extkeycode<>#0 then
  260. begin
  261. keypressed:=true;
  262. exit
  263. end
  264. else
  265. asm
  266. movb $1,%ah
  267. int $0x16
  268. setnz %al
  269. movb %al,__RESULT
  270. end;
  271. end;
  272. end;
  273. function readkey:char;
  274. {Reads the next character from the keyboard.}
  275. var Akeyrec:Tkbdkeyinfo;
  276. c,s:char;
  277. begin
  278. if extkeycode<>#0 then
  279. begin
  280. readkey:=extkeycode;
  281. extkeycode:=#0
  282. end
  283. else
  284. begin
  285. if os_mode=osOS2 then
  286. begin
  287. kbdcharin(Akeyrec,0,0);
  288. c:=Akeyrec.charcode;
  289. s:=Akeyrec.scancode;
  290. if (c=#224) and (s<>#0) then
  291. c:=#0;
  292. end
  293. else
  294. begin
  295. asm
  296. movb $0,%ah
  297. int $0x16
  298. movb %al,c
  299. movb %ah,s
  300. end;
  301. end;
  302. if c=#0 then
  303. extkeycode:=s;
  304. readkey:=c;
  305. end;
  306. end;
  307. procedure clrscr;
  308. {Clears the current window.}
  309. var screl:word;
  310. begin
  311. screl:=$20+textattr shl 8;
  312. scroll_up(hi(windmin),lo(windmin),
  313. hi(windmax),lo(windmax),
  314. hi(windmax)-hi(windmin)+1,
  315. screl);
  316. gotoXY(1,1);
  317. end;
  318. procedure gotoXY(x,y:byte);
  319. {Positions the cursor on (x,y) relative to the window origin.}
  320. begin
  321. if x<1 then
  322. x:=1;
  323. if y<1 then
  324. y:=1;
  325. if y+hi(windmin)-2>=hi(windmax) then
  326. y:=hi(windmax)-hi(windmin)+1;
  327. if x+lo(windmin)-2>=lo(windmax) then
  328. x:=lo(windmax)-lo(windmin)+1;
  329. setcursor(y+hi(windmin)-1,x+lo(windmin)-1);
  330. end;
  331. function whereX:byte;
  332. {Returns the x position of the cursor.}
  333. var x,y:word;
  334. begin
  335. getcursor(y,x);
  336. whereX:=x-lo(windmin)+1;
  337. end;
  338. function whereY:byte;
  339. {Returns the y position of the cursor.}
  340. var x,y:word;
  341. begin
  342. getcursor(y,x);
  343. whereY:=y-hi(windmin)+1;
  344. end;
  345. procedure clreol;
  346. {Clear from current position to end of line.
  347. Contributed by Michail A. Baikov}
  348. var i:byte;
  349. begin
  350. {not fastest, but compatible}
  351. for i:=wherex to lo(windmax) do write(' ');
  352. gotoxy(1,wherey); {may be not}
  353. end;
  354. procedure delline;
  355. {Deletes the line at the cursor.}
  356. var row,left,right,bot:longint;
  357. fil:word;
  358. begin
  359. row:=whereY;
  360. left:=lo(windmin);
  361. right:=lo(windmax);
  362. bot:=hi(windmax)+1;
  363. fil:=$20 or (textattr shl 8);
  364. scroll_up(row+1,left,bot,right,1,fil);
  365. end;
  366. procedure insline;
  367. {Inserts a line at the cursor position.}
  368. var row,left,right,bot:longint;
  369. fil:word;
  370. begin
  371. row:=whereY;
  372. left:=lo(windmin);
  373. right:=lo(windmax);
  374. bot:=hi(windmax);
  375. fil:=$20 or (textattr shl 8);
  376. scroll_dn(row,left,bot,right,1,fil);
  377. end;
  378. procedure TextMode (Mode: word);
  379. { Use this procedure to set-up a specific text-mode.}
  380. begin
  381. textattr:=$07;
  382. lastmode:=mode;
  383. mode:=mode and $ff;
  384. setscreenmode(mode);
  385. windmin:=0;
  386. windmax:=(maxcols-1) or ((maxrows-1) shl 8);
  387. clrscr;
  388. end;
  389. procedure textcolor(color:byte);
  390. {All text written after calling this will have color as foreground colour.}
  391. begin
  392. textattr:=(textattr and $70) or (color and $f)+color and 128;
  393. end;
  394. procedure textbackground(color:byte);
  395. {All text written after calling this will have colour as background colour.}
  396. begin
  397. textattr:=(textattr and $8f) or ((color and $7) shl 4);
  398. end;
  399. procedure normvideo;
  400. {Changes the text-background to black and the foreground to white.}
  401. begin
  402. textattr:=$7;
  403. end;
  404. procedure lowvideo;
  405. {All text written after this will have low intensity.}
  406. begin
  407. textattr:=textattr and $f7;
  408. end;
  409. procedure highvideo;
  410. {All text written after this will have high intensity.}
  411. begin
  412. textattr:=textattr or $8;
  413. end;
  414. procedure delay(ms:word);
  415. var i,j:longint;
  416. {Waits ms microseconds. The DOS code is copied from the DOS rtl.}
  417. begin
  418. {Under OS/2 we could also calibrate like under DOS. But this is
  419. unreliable, because OS/2 can hold our programs while calibrating,
  420. if it needs the processor for other things.}
  421. if os_mode=osOS2 then
  422. dossleep(ms)
  423. else
  424. begin
  425. for i:=1 to ms do
  426. for j:=1 to calibration do
  427. begin
  428. end;
  429. end;
  430. end;
  431. procedure window(X1,Y1,X2,Y2:byte);
  432. {Change the write window to the given coordinates.}
  433. begin
  434. if (X1<1) or
  435. (Y1<1) or
  436. (X2>maxcols) or
  437. (Y2>maxrows) or
  438. (X1>X2) or
  439. (Y1>Y2) then
  440. exit;
  441. windmin:=(X1-1) or ((Y1-1) shl 8);
  442. windmax:=(X2-1) or ((Y2-1) shl 8);
  443. gotoXY(1,1);
  444. end;
  445. {$ASMMODE INTEL}
  446. procedure writePchar(s:Pchar;len:word);
  447. {Write a series of characters to the screen.
  448. Not very fast, but is just text-mode isn't it?}
  449. var x,y:word;
  450. c:char;
  451. i,n:integer;
  452. screl:word;
  453. ca:Pchar;
  454. begin
  455. i:=0;
  456. getcursor(y,x);
  457. while i<=len-1 do
  458. begin
  459. case s[i] of
  460. #7: asm
  461. mov dl, 7
  462. mov ah, 2
  463. call syscall
  464. end;
  465. #8: if X > Succ (Lo (WindMin)) then Dec (X);
  466. { #9: x:=(x-lo(windmin)) and $fff8+8+lo(windmin);}
  467. #10: inc(y);
  468. #13: x:=lo(windmin);
  469. else
  470. begin
  471. ca:=@s[i];
  472. n:=1;
  473. while not(s[i+1] in [#7,#8,#10,#13]) and
  474. { (x+n<=lo(windmax)+1) and (i<len-1) do}
  475. (x+n<=lo(windmax)) and (i<len-1) do
  476. begin
  477. inc(n);
  478. inc(i);
  479. end;
  480. if os_mode=osOS2 then
  481. viowrtcharstratt(ca,n,y,x,textattr,0)
  482. else
  483. asm
  484. mov ax, 1300h
  485. mov bh, 0
  486. mov bl, TEXTATTR
  487. mov dh, byte ptr y
  488. mov dl, byte ptr x
  489. mov cx, n
  490. push ebp
  491. mov ebp, ca
  492. int 10h
  493. pop ebp
  494. end;
  495. x:=x+n;
  496. end;
  497. end;
  498. if x>lo(windmax) then
  499. begin
  500. x:=lo(windmin);
  501. inc(y);
  502. end;
  503. if y>hi(windmax) then
  504. begin
  505. screl:=$20+textattr shl 8;
  506. scroll_up(hi(windmin),lo(windmin),
  507. hi(windmax),lo(windmax),
  508. 1,screl);
  509. y:=hi(windmax);
  510. end;
  511. { writeln(stderr,x,' ',y);}
  512. inc(i);
  513. end;
  514. setcursor(y,x);
  515. end;
  516. {$ASMMODE ATT}
  517. function crtread(var f:textrec):word;
  518. {Read a series of characters from the console.}
  519. var max,curpos:integer;
  520. c:char;
  521. clist:array[0..2] of char;
  522. begin
  523. max:=f.bufsize-2;
  524. curpos:=0;
  525. repeat
  526. c:=readkey;
  527. case c of
  528. #0:
  529. readkey;
  530. #8:
  531. if curpos>0 then
  532. begin
  533. clist:=#8' '#8;
  534. writePchar(@clist,3);
  535. dec(curpos);
  536. end;
  537. #13:
  538. begin
  539. f.bufptr^[curpos]:=#13;
  540. inc(curpos);
  541. f.bufptr^[curpos]:=#10;
  542. inc(curpos);
  543. f.bufpos:=0;
  544. f.bufend:=curpos;
  545. clist[0]:=#13;
  546. writePchar(@clist,1);
  547. break;
  548. end;
  549. #32..#255:
  550. if curpos<max then
  551. begin
  552. f.bufptr^[curpos]:=c;
  553. inc(curpos);
  554. writePchar(@c,1);
  555. end;
  556. end;
  557. until false;
  558. crtread:=0;
  559. end;
  560. function crtwrite(var f:textrec):word;
  561. {Write a series of characters to the console.}
  562. begin
  563. writePchar(Pchar(f.bufptr),f.bufpos);
  564. f.bufpos:=0;
  565. crtwrite:=0;
  566. end;
  567. function crtopen(var f:textrec):integer;
  568. begin
  569. if f.mode=fmoutput then
  570. crtopen:=0
  571. else
  572. crtopen:=5;
  573. end;
  574. function crtinout(var f:textrec):integer;
  575. begin
  576. case f.mode of
  577. fminput:
  578. crtinout:=crtread(f);
  579. fmoutput:
  580. crtinout:=crtwrite(f);
  581. end;
  582. end;
  583. function crtclose(var f:textrec):integer;
  584. begin
  585. f.mode:=fmclosed;
  586. crtclose:=0;
  587. end;
  588. procedure assigncrt(var f:text);
  589. {Assigns a file to the crt console.}
  590. begin
  591. textrec(f).mode:=fmclosed;
  592. textrec(f).bufsize:=128;
  593. textrec(f).bufptr:=@textrec(f).buffer;
  594. textrec(f).bufpos:=0;
  595. textrec(f).openfunc:=@crtopen;
  596. textrec(f).inoutfunc:=@crtinout;
  597. textrec(f).flushfunc:=@crtinout;
  598. textrec(f).closefunc:=@crtclose;
  599. textrec(f).name[0]:='.';
  600. textrec(f).name[0]:=#0;
  601. end;
  602. procedure sound(hz:word);
  603. {sound and nosound are not implemented because the OS/2 API supports a freq/
  604. duration procedure instead of start/stop procedures.}
  605. begin
  606. end;
  607. procedure nosound;
  608. begin
  609. end;
  610. function get_ticks:word;
  611. type Pword=^word;
  612. begin
  613. get_ticks:=Pword(longint(first_meg)+$46c)^;
  614. end;
  615. procedure initdelay;
  616. {Calibrate the delay procedure. Copied from DOS rtl.}
  617. var first:word;
  618. begin
  619. calibration:=0;
  620. { wait for new tick }
  621. first:=get_ticks;
  622. while get_ticks=first do
  623. begin
  624. end;
  625. first:=get_ticks;
  626. { this estimates calibration }
  627. while get_ticks=first do
  628. inc(calibration);
  629. { calculate this to ms }
  630. calibration:=calibration div 70;
  631. while true do
  632. begin
  633. first:=get_ticks;
  634. while get_ticks=first do
  635. begin
  636. end;
  637. first:=get_ticks;
  638. delay(55);
  639. if first=get_ticks then
  640. exit
  641. else
  642. begin
  643. { decrement calibration two percent }
  644. calibration:=calibration-calibration div 50;
  645. dec(calibration);
  646. end;
  647. end;
  648. end;
  649. {****************************************************************************
  650. Extra Crt Functions
  651. ****************************************************************************}
  652. {$ASMMODE INTEL}
  653. procedure CursorOn;
  654. var
  655. I: TVioCursorInfo;
  656. begin
  657. if Os_Mode = osOS2 then
  658. begin
  659. VioGetCurType (I, 0);
  660. with I do
  661. begin
  662. yStartInt := -90;
  663. cEndInt := -100;
  664. Attr := 15;
  665. end;
  666. VioSetCurType (I, 0);
  667. end
  668. else
  669. asm
  670. push es
  671. push bp
  672. mov ax, 1130h
  673. mov bh, 0
  674. mov ecx, 0
  675. int 10h
  676. pop bp
  677. pop es
  678. or ecx, ecx
  679. jnz @COnOld
  680. mov cx, 0707h
  681. jmp @COnAll
  682. @COnOld:
  683. dec cx
  684. mov ch, cl
  685. dec ch
  686. @COnAll:
  687. mov ah, 1
  688. int 10h
  689. end;
  690. end;
  691. procedure CursorOff;
  692. var
  693. I: TVioCursorInfo;
  694. begin
  695. if Os_Mode = osOS2 then
  696. begin
  697. VioGetCurType (I, 0);
  698. I.AttrInt := -1;
  699. VioSetCurType (I, 0);
  700. end
  701. else
  702. asm
  703. mov ah, 1
  704. mov cx, 0FFFFh
  705. int 10h
  706. end;
  707. end;
  708. procedure CursorBig;
  709. var
  710. I: TVioCursorInfo;
  711. begin
  712. if Os_Mode = osOS2 then
  713. begin
  714. VioGetCurType (I, 0);
  715. with I do
  716. begin
  717. yStart := 0;
  718. cEndInt := -100;
  719. Attr := 15;
  720. end;
  721. VioSetCurType (I, 0);
  722. end
  723. else
  724. asm
  725. mov ah, 1
  726. mov cx, 1Fh
  727. int 10h
  728. end;
  729. end;
  730. {$ASMMODE DEFAULT}
  731. {Initialization.}
  732. type Pbyte=^byte;
  733. var curmode:viomodeinfo;
  734. mode:byte;
  735. begin
  736. textattr:=lightgray;
  737. if os_mode=osOS2 then
  738. begin
  739. curmode.cb:=sizeof(curmode);
  740. viogetmode(curmode,0);
  741. maxcols:=curmode.col;
  742. maxrows:=curmode.row;
  743. lastmode:=0;
  744. case maxcols of
  745. 40:
  746. lastmode:=0;
  747. 80:
  748. lastmode:=1;
  749. 132:
  750. lastmode:=2;
  751. end;
  752. case maxrows of
  753. 25:;
  754. 28:
  755. lastmode:=lastmode+16;
  756. 43:
  757. lastmode:=lastmode+32;
  758. 50:
  759. lastmode:=lastmode+48;
  760. end
  761. end
  762. else
  763. begin
  764. {Request video mode to determine columns.}
  765. asm
  766. mov $0x0f,%ah
  767. int $0x10
  768. { mov %al,_MODE }
  769. mov %al,MODE
  770. end;
  771. case mode of
  772. 0,1:
  773. begin
  774. lastmode:=0;
  775. maxcols:=40;
  776. end;
  777. else
  778. begin
  779. lastmode:=1;
  780. maxcols:=80;
  781. end;
  782. end;
  783. {Get number of rows from realmode $0040:$0084.}
  784. maxrows:=Pbyte(longint(first_meg)+$484)^;
  785. case maxrows of
  786. 25:;
  787. 28:
  788. lastmode:=lastmode+16;
  789. 43:
  790. lastmode:=lastmode+32;
  791. 50:
  792. lastmode:=lastmode+48;
  793. end
  794. end;
  795. windmin:=0;
  796. windmax:=((maxrows-1) shl 8) or (maxcols-1);
  797. if os_mode <> osOS2 then
  798. initdelay;
  799. crt_error:=cenoerror;
  800. assigncrt(input);
  801. textrec(input).mode:=fminput;
  802. assigncrt(output);
  803. textrec(output).mode:=fmoutput;
  804. end.