crt.pas 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976
  1. {****************************************************************************
  2. $Id$
  3. Standard CRT unit.
  4. Free Pascal runtime library for EMX.
  5. Copyright (c) 1997 Daniel Mantione.
  6. This file may be reproduced and modified under the same conditions
  7. as all other Free Pascal source code.
  8. ****************************************************************************}
  9. unit crt;
  10. {$ASMMODE ATT}
  11. interface
  12. {$i crth.inc}
  13. {cemodeset means that the procedure textmode has failed to set up a mode.}
  14. type
  15. cexxxx=(cenoerror,cemodeset);
  16. var
  17. crt_error:cexxxx; {Crt-status. RW}
  18. {***************************************************************************}
  19. implementation
  20. {$i textrec.inc}
  21. const extkeycode:char=#0;
  22. var maxrows,maxcols:word;
  23. calibration:longint;
  24. type Tkbdkeyinfo=record
  25. charcode,scancode:char;
  26. fbstatus,bnlsshift:byte;
  27. fsstate:word;
  28. time:longint;
  29. end;
  30. {if you have information on the folowing datastructure, please
  31. send them to me at [email protected]}
  32. {This datastructure is needed when we ask in what video mode we are,
  33. or we want to set up a new mode.}
  34. viomodeinfo=record
  35. cb:word; { length of the entire data
  36. structure }
  37. fbtype, { bit mask of mode being set}
  38. color: byte; { number of colors (power of 2) }
  39. col, { number of text columns }
  40. row, { number of text rows }
  41. hres, { horizontal resolution }
  42. vres: word; { vertical resolution }
  43. fmt_ID, { attribute format
  44. ! more info wanted !}
  45. attrib: byte; { number of attributes }
  46. buf_addr, { physical address of
  47. videobuffer, e.g. $0b800}
  48. buf_length, { length of a videopage (bytes)}
  49. full_length, { total video-memory on video-
  50. card (bytes)}
  51. partial_length:longint; { ????? info wanted !}
  52. ext_data_addr:pointer; { ????? info wanted !}
  53. end;
  54. Pviomodeinfo=^viomodeinfo;
  55. TVioCursorInfo=record
  56. case boolean of
  57. false:(
  58. yStart:word; {Cursor start (top) scan line (0-based)}
  59. cEnd:word; {Cursor end (bottom) scan line}
  60. cx:word; {Cursor width (0=default width)}
  61. Attr:word); {Cursor colour attribute (-1=hidden)}
  62. true:(
  63. yStartInt: integer; {integer variants can be used to specify negative}
  64. cEndInt:integer; {negative values (interpreted as percentage by OS/2)}
  65. cxInt:integer;
  66. AttrInt:integer);
  67. end;
  68. PVioCursorInfo=^TVioCursorInfo;
  69. {EMXWRAP.DLL has strange calling conventions: All parameters must have
  70. a 4 byte size.}
  71. function kbdcharin(var Akeyrec:Tkbdkeyinfo;wait,kbdhandle:longint):word; cdecl;
  72. external 'EMXWRAP' index 204;
  73. function kbdpeek(var Akeyrec:TkbdkeyInfo;kbdhandle:word):word; cdecl;
  74. external 'EMXWRAP' index 222;
  75. function dossleep(time:cardinal):cardinal; cdecl;
  76. external 'DOSCALLS' index 229;
  77. function vioscrollup(top,left,bottom,right,lines:longint;
  78. var screl:word;viohandle:longint):word; cdecl;
  79. external 'EMXWRAP' index 107;
  80. function vioscrolldn(top,left,bottom,right,lines:longint;
  81. var screl:word;viohandle:longint):word; cdecl;
  82. external 'EMXWRAP' index 147;
  83. function viogetcurpos(var row,column:word;viohandle:longint):word; cdecl;
  84. external 'EMXWRAP' index 109;
  85. function viosetcurpos(row,column,viohandle:longint):word; cdecl;
  86. external 'EMXWRAP' index 115;
  87. function viowrtTTY(s:Pchar;len,viohandle:longint):word; cdecl;
  88. external 'EMXWRAP' index 119;
  89. function viowrtcharstratt(s:Pchar;len,row,col:longint;var attr:byte;
  90. viohandle:longint):word; cdecl;
  91. external 'EMXWRAP' index 148;
  92. function viogetmode(var Amodeinfo:viomodeinfo;viohandle:longint):word; cdecl;
  93. external 'EMXWRAP' index 121;
  94. function viosetmode(var Amodeinfo:viomodeinfo;viohandle:longint):word; cdecl;
  95. external 'EMXWRAP' index 122;
  96. function VioSetCurType(var CurData:TVioCursorInfo;VioHandle:word):word; cdecl;
  97. external 'EMXWRAP' index 132;
  98. {external 'VIOCALLS' index 32;}
  99. function VioGetCurType(var CurData:TVioCursorInfo;VioHandle:word):word; cdecl;
  100. external 'EMXWRAP' index 127;
  101. {external 'VIOCALLS' index 27;}
  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)+1;
  361. right:=lo(windmax)+1;
  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)+1;
  373. right:=lo(windmax)+1;
  374. bot:=hi(windmax);
  375. fil:=$20 or (textattr shl 8);
  376. scroll_dn(row,left,bot-1,right,1,fil);
  377. end;
  378. procedure textmode(mode:integer);
  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. #8:
  461. x:=x-1;
  462. #9:
  463. x:=(x-lo(windmin)) and $fff8+8+lo(windmin);
  464. #10:
  465. ;
  466. #13:
  467. begin
  468. x:=lo(windmin);
  469. inc(y);
  470. end;
  471. else
  472. begin
  473. ca:=@s[i];
  474. n:=1;
  475. while not(s[i+1] in [#8,#9,#10,#13]) and
  476. { (x+n<=lo(windmax)+1) and (i<len-1) do}
  477. (x+n<=lo(windmax)) and (i<len-1) do
  478. begin
  479. inc(n);
  480. inc(i);
  481. end;
  482. if os_mode=osOS2 then
  483. viowrtcharstratt(ca,n,y,x,textattr,0)
  484. else
  485. asm
  486. mov ax, 1300h
  487. mov bh, 0
  488. mov bl, TEXTATTR
  489. mov dh, byte ptr y
  490. mov dl, byte ptr x
  491. mov cx, n
  492. push ebp
  493. mov ebp, ca
  494. int 10h
  495. pop ebp
  496. end;
  497. x:=x+n;
  498. end;
  499. end;
  500. if x>lo(windmax) then
  501. begin
  502. x:=lo(windmin);
  503. inc(y);
  504. end;
  505. if y>hi(windmax) then
  506. begin
  507. screl:=$20+textattr shl 8;
  508. scroll_up(hi(windmin),lo(windmin),
  509. hi(windmax),lo(windmax),
  510. 1,screl);
  511. y:=hi(windmax);
  512. end;
  513. { writeln(stderr,x,' ',y);}
  514. inc(i);
  515. end;
  516. setcursor(y,x);
  517. end;
  518. {$ASMMODE ATT}
  519. function crtread(var f:textrec):word;
  520. {Read a series of characters from the console.}
  521. var max,curpos:integer;
  522. c:char;
  523. clist:array[0..2] of char;
  524. begin
  525. max:=f.bufsize-2;
  526. curpos:=0;
  527. repeat
  528. c:=readkey;
  529. case c of
  530. #0:
  531. readkey;
  532. #8:
  533. if curpos>0 then
  534. begin
  535. clist:=#8' '#8;
  536. writePchar(@clist,3);
  537. dec(curpos);
  538. end;
  539. #13:
  540. begin
  541. f.bufptr^[curpos]:=#13;
  542. inc(curpos);
  543. f.bufptr^[curpos]:=#10;
  544. inc(curpos);
  545. f.bufpos:=0;
  546. f.bufend:=curpos;
  547. clist[0]:=#13;
  548. writePchar(@clist,1);
  549. break;
  550. end;
  551. #32..#255:
  552. if curpos<max then
  553. begin
  554. f.bufptr^[curpos]:=c;
  555. inc(curpos);
  556. writePchar(@c,1);
  557. end;
  558. end;
  559. until false;
  560. crtread:=0;
  561. end;
  562. function crtwrite(var f:textrec):word;
  563. {Write a series of characters to the console.}
  564. begin
  565. writePchar(Pchar(f.bufptr),f.bufpos);
  566. f.bufpos:=0;
  567. crtwrite:=0;
  568. end;
  569. function crtopen(var f:textrec):integer;
  570. begin
  571. if f.mode=fmoutput then
  572. crtopen:=0
  573. else
  574. crtopen:=5;
  575. end;
  576. function crtinout(var f:textrec):integer;
  577. begin
  578. case f.mode of
  579. fminput:
  580. crtinout:=crtread(f);
  581. fmoutput:
  582. crtinout:=crtwrite(f);
  583. end;
  584. end;
  585. function crtclose(var f:textrec):integer;
  586. begin
  587. f.mode:=fmclosed;
  588. crtclose:=0;
  589. end;
  590. procedure assigncrt(var f:text);
  591. {Assigns a file to the crt console.}
  592. begin
  593. textrec(f).mode:=fmclosed;
  594. textrec(f).bufsize:=128;
  595. textrec(f).bufptr:=@textrec(f).buffer;
  596. textrec(f).bufpos:=0;
  597. textrec(f).openfunc:=@crtopen;
  598. textrec(f).inoutfunc:=@crtinout;
  599. textrec(f).flushfunc:=@crtinout;
  600. textrec(f).closefunc:=@crtclose;
  601. textrec(f).name[0]:='.';
  602. textrec(f).name[0]:=#0;
  603. end;
  604. procedure sound(hz:word);
  605. {sound and nosound are not implemented because the OS/2 API supports a freq/
  606. duration procedure instead of start/stop procedures.}
  607. begin
  608. end;
  609. procedure nosound;
  610. begin
  611. end;
  612. function get_ticks:word;
  613. type Pword=^word;
  614. begin
  615. get_ticks:=Pword(longint(first_meg)+$46c)^;
  616. end;
  617. procedure initdelay;
  618. {Calibrate the delay procedure. Copied from DOS rtl.}
  619. var first:word;
  620. begin
  621. calibration:=0;
  622. { wait for new tick }
  623. first:=get_ticks;
  624. while get_ticks=first do
  625. begin
  626. end;
  627. first:=get_ticks;
  628. { this estimates calibration }
  629. while get_ticks=first do
  630. inc(calibration);
  631. { calculate this to ms }
  632. calibration:=calibration div 70;
  633. while true do
  634. begin
  635. first:=get_ticks;
  636. while get_ticks=first do
  637. begin
  638. end;
  639. first:=get_ticks;
  640. delay(55);
  641. if first=get_ticks then
  642. exit
  643. else
  644. begin
  645. { decrement calibration two percent }
  646. calibration:=calibration-calibration div 50;
  647. dec(calibration);
  648. end;
  649. end;
  650. end;
  651. {****************************************************************************
  652. Extra Crt Functions
  653. ****************************************************************************}
  654. {$ASMMODE INTEL}
  655. procedure CursorOn;
  656. var
  657. I: TVioCursorInfo;
  658. begin
  659. if Os_Mode = osOS2 then
  660. begin
  661. VioGetCurType (I, 0);
  662. with I do
  663. begin
  664. yStartInt := -90;
  665. cEndInt := -100;
  666. Attr := 15;
  667. end;
  668. VioSetCurType (I, 0);
  669. end
  670. else
  671. asm
  672. push es
  673. push bp
  674. mov ax, 1130h
  675. mov bh, 0
  676. mov ecx, 0
  677. int 10h
  678. pop bp
  679. pop es
  680. or ecx, ecx
  681. jnz @COnOld
  682. mov cx, 0707h
  683. jmp @COnAll
  684. @COnOld:
  685. dec cx
  686. mov ch, cl
  687. dec ch
  688. @COnAll:
  689. mov ah, 1
  690. int 10h
  691. end;
  692. end;
  693. procedure CursorOff;
  694. var
  695. I: TVioCursorInfo;
  696. begin
  697. if Os_Mode = osOS2 then
  698. begin
  699. VioGetCurType (I, 0);
  700. I.AttrInt := -1;
  701. VioSetCurType (I, 0);
  702. end
  703. else
  704. asm
  705. mov ah, 1
  706. mov cx, 0FFFFh
  707. int 10h
  708. end;
  709. end;
  710. procedure CursorBig;
  711. var
  712. I: TVioCursorInfo;
  713. begin
  714. if Os_Mode = osOS2 then
  715. begin
  716. VioGetCurType (I, 0);
  717. with I do
  718. begin
  719. yStart := 0;
  720. cEndInt := -100;
  721. Attr := 15;
  722. end;
  723. VioSetCurType (I, 0);
  724. end
  725. else
  726. asm
  727. mov ah, 1
  728. mov cx, 1Fh
  729. int 10h
  730. end;
  731. end;
  732. {$ASMMODE DEFAULT}
  733. {Initialization.}
  734. type Pbyte=^byte;
  735. var curmode:viomodeinfo;
  736. mode:byte;
  737. begin
  738. textattr:=lightgray;
  739. if os_mode=osOS2 then
  740. begin
  741. curmode.cb:=sizeof(curmode);
  742. viogetmode(curmode,0);
  743. maxcols:=curmode.col;
  744. maxrows:=curmode.row;
  745. lastmode:=0;
  746. case maxcols of
  747. 40:
  748. lastmode:=0;
  749. 80:
  750. lastmode:=1;
  751. 132:
  752. lastmode:=2;
  753. end;
  754. case maxrows of
  755. 25:;
  756. 28:
  757. lastmode:=lastmode+16;
  758. 43:
  759. lastmode:=lastmode+32;
  760. 50:
  761. lastmode:=lastmode+48;
  762. end
  763. end
  764. else
  765. begin
  766. {Request video mode to determine columns.}
  767. asm
  768. mov $0x0f,%ah
  769. int $0x10
  770. { mov %al,_MODE }
  771. mov %al,MODE
  772. end;
  773. case mode of
  774. 0,1:
  775. begin
  776. lastmode:=0;
  777. maxcols:=40;
  778. end;
  779. else
  780. begin
  781. lastmode:=1;
  782. maxcols:=80;
  783. end;
  784. end;
  785. {Get number of rows from realmode $0040:$0084.}
  786. maxrows:=Pbyte(longint(first_meg)+$484)^;
  787. case maxrows of
  788. 25:;
  789. 28:
  790. lastmode:=lastmode+16;
  791. 43:
  792. lastmode:=lastmode+32;
  793. 50:
  794. lastmode:=lastmode+48;
  795. end
  796. end;
  797. windmin:=0;
  798. windmax:=((maxrows-1) shl 8) or (maxcols-1);
  799. if os_mode <> osOS2 then
  800. initdelay;
  801. crt_error:=cenoerror;
  802. assigncrt(input);
  803. textrec(input).mode:=fminput;
  804. assigncrt(output);
  805. textrec(output).mode:=fmoutput;
  806. end.
  807. {
  808. $Log$
  809. Revision 1.4 2004-03-21 20:28:43 hajny
  810. + Cursor* implemented
  811. Revision 1.3 2004/02/08 16:22:20 michael
  812. + Moved CRT interface to common include file
  813. Revision 1.2 2003/10/19 09:35:28 hajny
  814. * fixes from OS/2 merged to EMX
  815. Revision 1.1 2003/03/23 23:11:17 hajny
  816. + emx target added
  817. }