home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Simtel MSDOS - Coast to Coast
/
simteldosarchivecoasttocoast2.iso
/
turbopas
/
pscreen.zip
/
SCREEN.PAS
< prev
Wrap
Pascal/Delphi Source File
|
1989-11-01
|
8KB
|
232 lines
PROGRAM Screen_Writing_Routines;
{$D-,R-,S-,V- }
{ 2LT Michael P. Kelly, U.S. Army Signal Corps
This program shows you 5 possible ways in which to place text on the
screen using QuickPascal. They same can be done in Turbo Pascal as
well. The 5 methods (and there are more than just these) are:
1. Write(ln) using the Crt UNIT global variable set to True
for direct to screen memory writing.
2. Write(ln) using the Crt UNIT global variable set to False
for screen writing using the BIOS.
3. Using a data structure imitating the screen and placing it
over the screen memory using the ABSOLUTE keyword. Then
make all writes to that data structure (VIDEORAM).
4. Using the MEM[] function to access the screen memory
directly and placing the character and attribute there
yourself. Similar in concept to #3, but attacking it from
at different angle.
5. Using a pointer of type byte to write directly to the
video memory in RAM.
The program writes 'limit' number of lines on the screen of all X's
for each method mentioned above. A timer is run on each and the
time for each is then displayed as well as a ratio of performance
versus the fastest one. IF YOU OWN A MONOCHROME MONITOR - change the
CONST VID_SEG from $B800 to $B000 and recompile.
I recently bought QuickPascal v1.0 by MicroSoft for $59.61 at a local
software store. It was a deal! While my native tongue is C, Pascal
is good to come back to now and then. But as always, it is not the
language that matters, it is the programmer! So I will avoid any
discussions as to which language is superior. Anyway, if you can
get your hands on QuickPascal, do it while the price is still low. It
is a nice compiler to have around for the price. I like to take a
vacation from Turbo C once in a while as well.
If you are looking to do any serious programming at all in Pascal, you
will eventually come across choosing a method by which to write text
to the screen. Speed and compatibility are your two major concerns
at this point. They also seem to be inversely proportionate to each
other. These routines and the program to test them will show you
basically what each of the 5 methods has to offer in the way of speed
and ease of implementation. Feel free to chop these routines out and
use them in your code!
If anyone has source code to some good Turbo Pascal routines, please
contact me vie Email at mkelly@galaxy.afit.af.mil or CompuServe
73747,420. I would like to run it through QuickPascal so I can have
some .QPU (Microsoft's version of .TPU) files for program development.
}
USES CRT,
DOS,
CONVERT; { My personal UNIT of data conversion routines. }
CONST
VID_SEG = $B800;
TYPE
CELL = RECORD
CHARACTER : CHAR;
ATTRIBUTE : BYTE;
END;
VIDEORAM = ARRAY[1 .. 2000] OF CELL;
VAR
I : INTEGER;
C : CHAR;
H1,M1,S1,HUN1 : WORD;
H2,M2,S2,HUN2 : WORD;
H3,M3,S3,HUN3 : WORD;
H4,M4,S4,HUN4 : WORD;
H5,M5,S5,HUN5 : WORD;
H6,M6,S6,HUN6 : WORD;
H7,M7,S7,HUN7 : WORD;
H8,M8,S8,HUN8 : WORD;
H9,M9,S9,HUN9 : WORD;
H10,M10,S10,HUN10 : WORD;
B,D,M,A,P : INTEGER;
VIDEO : VIDEORAM ABSOLUTE VID_SEG:0000;
LIMIT : INTEGER;
PROCEDURE WRITE_CHAR(ROW,COL : INTEGER;CH : CHAR;ATTR : BYTE);
VAR
TMP : INTEGER;
BEGIN
TMP := (ROW * 80) + COL;
VIDEO[TMP].CHARACTER := CH;
VIDEO[TMP].ATTRIBUTE := ATTR;
END;
PROCEDURE WRITE_CHAR_2MEM(ROW,COL : INTEGER;CH : CHAR;ATTR : BYTE);
VAR
OFFSET : INTEGER;
BEGIN
OFFSET := (ROW * 160) + (COL * 2);
MEM[VID_SEG:OFFSET] := CHAR2BYTE(CH);
MEM[VID_SEG:OFFSET+1] := ATTR;
END;
PROCEDURE WRITE_STR_2MEM(ROW,COL : INTEGER;STR : STRING;ATTR : BYTE);
VAR
I : INTEGER;
BEGIN
FOR I := 1 TO LENGTH(STR) DO
BEGIN
WRITE_CHAR_2MEM(ROW,COL+I-1,STR[I],ATTR);
END;
END;
PROCEDURE WRITE_STR(ROW,COL : INTEGER;STR : STRING;ATTR : BYTE);
VAR
I : INTEGER;
BEGIN
FOR I := 1 TO LENGTH(STR) DO
BEGIN
WRITE_CHAR(ROW,COL+I-1,STR[I],ATTR);
END;
END;
PROCEDURE WRITE_PTR_CHAR(ROW,COL : INTEGER;CH : CHAR;ATTR : BYTE);
VAR
OFFSET : INTEGER;
BYTE_PTR : ^BYTE;
BEGIN
OFFSET := (ROW * 160) + (COL * 2);
BYTE_PTR := PTR(VID_SEG,OFFSET);
BYTE_PTR^ := CHAR2BYTE(CH);
BYTE_PTR := PTR(VID_SEG,OFFSET+1);
BYTE_PTR^ := ATTR;
END;
PROCEDURE WRITE_PTR_STR(ROW,COL : INTEGER;STR : STRING;ATTR : BYTE);
VAR
I : INTEGER;
BEGIN
FOR I := 1 TO LENGTH(STR) DO
BEGIN
WRITE_PTR_CHAR(ROW,COL+I-1,STR[I],ATTR);
END;
END;
BEGIN
TEXTCOLOR(LIGHTRED);
TEXTBACKGROUND(BLACK);
CLRSCR;
WRITELN('SCREEN WRITING TIME TEST using QuickPascal v1.0');
WRITELN;
WRITELN('Anywhere from 25 to 300 is a good number of repetitions.');
WRITELN;
WRITE('ENTER THE NUMBER OF REPETITIONS: ');
READLN(LIMIT);
IF LIMIT < 25 THEN LIMIT := 25; { Anything less is useless! }
DIRECTVIDEO := FALSE;
CLRSCR;
TEXTCOLOR(RED);
GETTIME(H1,M1,S1,HUN1);
FOR I := 1 TO LIMIT DO
BEGIN
WRITELN('XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX');
END;
GETTIME(H2,M2,S2,HUN2);
CLRSCR;
DIRECTVIDEO := TRUE;
TEXTCOLOR(LIGHTBLUE);
GETTIME(H3,M3,S3,HUN3);
FOR I := 1 TO LIMIT DO
BEGIN
WRITELN('XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX');
END;
GETTIME(H4,M4,S4,HUN4);
CLRSCR;
GETTIME(H5,M5,S5,HUN5);
FOR I := 1 TO LIMIT DO
BEGIN
WRITE_STR((I-1) MOD 25,1,'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',13);
END;
GETTIME(H6,M6,S6,HUN6);
CLRSCR;
GETTIME(H7,M7,S7,HUN7);
FOR I := 1 TO LIMIT DO
BEGIN
WRITE_STR_2MEM((I-1) MOD 25,1,'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',6);
END;
GETTIME(H8,M8,S8,HUN8);
CLRSCR;
GETTIME(H9,M9,S9,HUN9);
FOR I := 1 TO LIMIT DO
BEGIN
WRITE_PTR_STR((I-1) MOD 25,1,'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',11);
END;
GETTIME(H10,M10,S10,HUN10);
CLRSCR;
TEXTCOLOR(YELLOW);
WRITELN('--------------------------- STATISTICS ------------------------------');
TEXTCOLOR(LIGHTRED);
WRITELN;
WRITELN('START BIOS = ',H1:2,':',M1:2,':',S1:2,':',HUN1:2);
WRITELN('STOP BIOS = ',H2:2,':',M2:2,':',S2:2,':',HUN2:2);
WRITELN;
WRITELN('START DIRECT = ',H3:2,':',M3:2,':',S3:2,':',HUN3:2);
WRITELN('STOP DIRECT = ',H4:2,':',M4:2,':',S4:2,':',HUN4:2);
WRITELN;
WRITELN('START MEM[] = ',H7:2,':',M7:2,':',S7:2,':',HUN7:2);
WRITELN('STOP MEM[] = ',H8:2,':',M8:2,':',S8:2,':',HUN8:2);
WRITELN;
WRITELN('START ARRAY = ',H5:2,':',M5:2,':',S5:2,':',HUN5:2);
WRITELN('STOP ARRAY = ',H6:2,':',M6:2,':',S6:2,':',HUN6:2);
WRITELN;
WRITELN('START PTR = ',H9:2,':',M9:2,':',S9:2,':',HUN9:2);
WRITELN('STOP PTR = ',H10:2,':',M10:2,':',S10:2,':',HUN10:2);
B := ((M2*6000)+(S2*100)+HUN2)-((M1*6000)+(S1*100)+HUN1);
D := ((M4*6000)+(S4*100)+HUN4)-((M3*6000)+(S3*100)+HUN3);
M := ((M6*6000)+(S6*100)+HUN6)-((M5*6000)+(S5*100)+HUN5);
A := ((M8*6000)+(S8*100)+HUN8)-((M7*6000)+(S7*100)+HUN7);
P := ((M10*6000)+(S10*100)+HUN10)-((M9*6000)+(S9*100)+HUN9);
TEXTCOLOR(LIGHTCYAN);
WRITELN;
WRITE('BIOS ROUTINE TOOK (',B:4,') 1/100s of a second, ');
WRITELN('Ratio of ',(B/M):4:2);
WRITE('DIRECTVIDEO TOOK (',D:4,') 1/100s of a second, ');
WRITELN('Ratio of ',(D/M):4:2);
WRITE('PTR ROUTINE TOOK (',P:4,') 1/100s of a second, ');
WRITELN('Ratio of ',(P/M):4:2);
WRITE('MEM[] ROUTINE TOOK (',A:4,') 1/100s of a second, ');
WRITELN('Ratio of ',(A/M):4:2);
WRITE('ARRAY ROUTINE TOOK (',M:4,') 1/100s of a second, ');
WRITELN('Ratio of ',(M/M):4:2);
END.