crt.pas 22 KB

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