crt.pas 23 KB

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