2
$Id: crt.pp,v 1.11 2004/02/08 16:22:20 michael Exp $
3
This file is part of the Free Pascal run time library.
4
Copyright (c) 1999-2000 by the Free Pascal development team.
6
Borland Pascal 7 Compatible CRT Unit - Go32V2 implementation
8
See the file COPYING.FPC, included in this distribution,
9
for details about the copyright.
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
**********************************************************************}
24
ScreenHeight : longint;
38
definition of textrec is in textrec.inc
43
{****************************************************************************
45
****************************************************************************}
47
procedure setscreenmode(mode : byte);
56
function GetScreenHeight : longint;
58
getscreenheight:=mem[$40:$84]+1;
59
If mem[$40:$84]=0 then
60
getscreenheight := 25;
64
function GetScreenWidth : longint;
66
getscreenwidth:=memw[$40:$4a];
70
procedure SetScreenCursor(x,y : longint);
76
regs.realedx:=(y-1) shl 8+(x-1);
81
procedure GetScreenCursor(var x,y : longint);
88
{****************************************************************************
90
****************************************************************************}
92
Function WinMinX: Byte;
94
Current Minimum X coordinate
97
WinMinX:=(WindMin and $ff)+1;
102
Function WinMinY: Byte;
104
Current Minimum Y Coordinate
107
WinMinY:=(WindMin shr 8)+1;
112
Function WinMaxX: Byte;
114
Current Maximum X coordinate
117
WinMaxX:=(WindMax and $ff)+1;
122
Function WinMaxY: Byte;
124
Current Maximum Y coordinate;
127
WinMaxY:=(WindMax shr 8) + 1;
132
Function FullWin:boolean;
134
Full Screen 80x25? Window(1,1,80,25) is used, allows faster routines
137
FullWin:=(WinMinX=1) and (WinMinY=1) and
138
(WinMaxX=ScreenWidth) and (WinMaxY=ScreenHeight);
142
{****************************************************************************
144
****************************************************************************}
147
procedure textmode(mode : integer);
158
if (lastmode and $100)<>0 then
165
screenwidth:=getscreenwidth;
166
screenheight:=getscreenheight;
168
windmax:=(screenwidth-1) or ((screenheight-1) shl 8);
172
Procedure TextColor(Color: Byte);
174
Switch foregroundcolor
177
TextAttr:=(Color and $f) or (TextAttr and $70);
178
If (Color>15) Then TextAttr:=TextAttr Or Blink;
183
Procedure TextBackground(Color: Byte);
185
Switch backgroundcolor
188
TextAttr:=((Color shl 4) and ($f0 and not Blink)) or (TextAttr and ($0f OR Blink) );
195
Set highlighted output.
198
TextColor(TextAttr Or $08);
208
TextColor(TextAttr And $77);
215
Set normal back and foregroundcolors.
223
Procedure GotoXy(X: Byte; Y: Byte);
225
Go to coordinates X,Y in the current window.
228
If (X>0) and (X<=WinMaxX- WinMinX+1) and
229
(Y>0) and (Y<=WinMaxY-WinMinY+1) Then
233
SetScreenCursor(x,y);
238
Procedure Window(X1, Y1, X2, Y2: Byte);
240
Set screen window to the specified coordinates.
243
if (X1>X2) or (X2>ScreenWidth) or
244
(Y1>Y2) or (Y2>ScreenHeight) then
246
WindMin:=((Y1-1) Shl 8)+(X1-1);
247
WindMax:=((Y2-1) Shl 8)+(X2-1);
254
Clear the current window, and set the cursor on 1,1
260
fil:=32 or (textattr shl 8);
262
DosmemFillWord(VidSeg,0,ScreenHeight*ScreenWidth,fil)
265
for y:=WinMinY to WinMaxY do
266
DosmemFillWord(VidSeg,((y-1)*ScreenWidth+(WinMinX-1))*2,WinMaxX-WinMinX+1,fil);
274
Clear from current position to end of line.
280
GetScreenCursor(x,y);
281
fil:=32 or (textattr shl 8);
283
DosmemFillword(VidSeg,((y-1)*ScreenWidth+(x-1))*2,WinMaxX-x+1,fil);
288
Function WhereX: Byte;
290
Return current X-position of cursor.
295
GetScreenCursor(x,y);
301
Function WhereY: Byte;
303
Return current Y-position of cursor.
308
GetScreenCursor(x,y);
313
{*************************************************************************
315
*************************************************************************}
321
function readkey : char;
336
if (regs.al=$e0) and (regs.ah<>0) then
350
function keypressed : boolean;
363
keypressed:=((regs.realflags and zeroflag) = 0);
368
{*************************************************************************
370
*************************************************************************}
372
procedure Delayloop;assembler;
383
procedure initdelay;assembler;
387
{ for some reason, using int $31/ax=$901 doesn't work here }
388
{ and interrupts are always disabled at this point when }
389
{ running a program inside gdb(pas). Web bug 1345 (JM) }
411
procedure Delay(MS: Word);assembler;
430
procedure sound(hz : word);
455
end ['EAX','ECX','EDX'];
470
{****************************************************************************
471
HighLevel Crt Functions
472
****************************************************************************}
474
procedure removeline(y : longint);
478
fil:=32 or (textattr shl 8);
482
dosmemmove(VidSeg,(y*ScreenWidth+(WinMinX-1))*2,
483
VidSeg,((y-1)*ScreenWidth+(WinMinX-1))*2,(WinMaxX-WinMinX+1)*2);
486
dosmemfillword(VidSeg,((WinMaxY-1)*ScreenWidth+(WinMinX-1))*2,(WinMaxX-WinMinX+1),fil);
501
fil:=32 or (textattr shl 8);
506
dosmemmove(VidSeg,(((WinMinY+my-1)-1)*ScreenWidth+(WinMinX-1))*2,
507
VidSeg,(((WinMinY+my)-1)*ScreenWidth+(WinMinX-1))*2,(WinMaxX-WinMinX+1)*2);
510
dosmemfillword(VidSeg,(((WinMinY+y-1)-1)*ScreenWidth+(WinMinX-1))*2,(WinMaxX-WinMinX+1),fil);
516
{****************************************************************************
518
****************************************************************************}
554
{*****************************************************************************
555
Read and Write routines
556
*****************************************************************************}
559
CurrX,CurrY : longint;
561
Procedure WriteChar(c:char);
567
#13 : CurrX:=WinMinX;
569
if CurrX>WinMinX then
579
memw[VidSeg:((CurrY-1)*ScreenWidth+(CurrX-1))*2]:=(textattr shl 8) or byte(c);
583
if CurrX>WinMaxX then
588
while CurrY>WinMaxY do
596
Function CrtWrite(var f : textrec):integer;
600
GetScreenCursor(CurrX,CurrY);
601
for i:=0 to f.bufpos-1 do
602
WriteChar(f.buffer[i]);
603
SetScreenCursor(CurrX,CurrY);
609
Function CrtRead(Var F: TextRec): Integer;
613
if (f.bufpos>0) and (f.bufpos=f.bufend) then
626
GetScreenCursor(CurrX,CurrY);
630
if f.bufpos>f.bufend then
632
SetScreenCursor(CurrX,CurrY);
636
#71 : while f.bufpos>0 do
641
#75 : if f.bufpos>0 then
646
#77 : if f.bufpos<f.bufend then
648
WriteChar(f.bufptr^[f.bufpos]);
651
#79 : while f.bufpos<f.bufend do
653
WriteChar(f.bufptr^[f.bufpos]);
661
while f.bufpos<f.bufend do begin
662
WriteChar(f.bufptr^[f.bufpos]);
671
f.bufptr^[f.bufend]:=#13;
672
f.bufptr^[f.bufend+1]:=#10;
676
#26 : if CheckEOF then
678
f.bufptr^[f.bufend]:=#26;
684
if f.bufpos<f.bufsize-2 then
686
f.buffer[f.bufpos]:=ch;
694
SetScreenCursor(CurrX,CurrY);
699
Function CrtReturn(Var F: TextRec): Integer;
705
Function CrtClose(Var F: TextRec): Integer;
712
Function CrtOpen(Var F: TextRec): Integer;
714
If F.Mode=fmOutput Then
716
TextRec(F).InOutFunc:=@CrtWrite;
717
TextRec(F).FlushFunc:=@CrtWrite;
722
TextRec(F).InOutFunc:=@CrtRead;
723
TextRec(F).FlushFunc:=@CrtReturn;
725
TextRec(F).CloseFunc:=@CrtClose;
730
procedure AssignCrt(var F: Text);
733
TextRec(F).OpenFunc:=@CrtOpen;
736
{ use the C version to avoid using dpmiexcp unit
737
which makes sysutils and exceptions working incorrectly PM }
739
function __djgpp_set_ctrl_c(enable : longint) : boolean;cdecl;external;
744
{ Load startup values }
745
ScreenWidth:=GetScreenWidth;
746
ScreenHeight:=GetScreenHeight;
747
WindMax:=(ScreenWidth-1) or ((ScreenHeight-1) shl 8);
749
GetScreenCursor(x,y);
750
lastmode := mem[$40:$49];
751
if screenheight>25 then
752
lastmode:=lastmode or $100;
753
If not(lastmode=Mono) then
757
TextAttr:=mem[VidSeg:((y-1)*ScreenWidth+(x-1))*2+1];
758
{ Redirect the standard output }
761
TextRec(Output).Handle:=StdOutputHandle;
764
TextRec(Input).Handle:=StdInputHandle;
765
{ Calculates delay calibration }
767
{ Enable ctrl-c input (JM) }
768
__djgpp_set_ctrl_c(0);
773
Revision 1.11 2004/02/08 16:22:20 michael
774
+ Moved CRT interface to common include file
776
Revision 1.10 2003/10/03 21:56:36 peter
779
Revision 1.9 2003/03/17 18:13:13 peter
780
* exported ScreenHeight, ScreenWidth
782
Revision 1.8 2002/12/15 20:22:24 peter
783
* fix making string empty in readln when cursor is not at the end
785
Revision 1.7 2002/09/10 10:38:04 pierre
786
* merged from fixes: fix bug report 1974
788
Revision 1.6 2002/09/07 16:01:18 peter
789
* old logs removed and tabs fixed