Important Notice
The pages on this site contain documentation for very old MS-DOS software,
purely for historical purposes.
If you're looking for up-to-date documentation, particularly for programming,
you should not rely on the information found here, as it will be woefully
out of date.
CRT1.PAS
◄Example► ◄Contents► ◄Index► ◄Back►
PROGRAM crt1;
{ CRT1.PAS : Demonstrates use of Crt procedures for keyboard input. }
USES
Crt, Dos;
CONST
wait = 100;
achar = 'o';
up_arrow = #72;
down_arrow = #80;
left_arrow = #75;
right_arrow = #77;
F1_key = #59;
F2_key = #60;
music = True; { play music at the end of the program }
VAR
posx, posy, lasty : Byte;
c1, c2, akey : Char;
wait_sec : LongInt;
{============================= cursor_off ==============================
Procedure cursor_off turns off the text cursor.
}
PROCEDURE cursor_off;
VAR
regs : Registers;
BEGIN
WITH regs DO BEGIN
AX := $0100;
CX := $2000;
Intr( $10, regs )
END;
END; { procedure cursor_off }
{============================ main program ============================}
BEGIN
ClrScr;
Writeln( 'Press the arrow keys to move the letter "o"' );
Writeln( 'Press the [F1] function key to stop' );
Writeln( 'Press the [F2] function key to see the char bounce' );
cursor_off;
c1 := ' ';
c2 := ' ';
GotoXY( 5,5 );
posx := WhereX;
posy := WhereY;
Write( achar );
WHILE NOT ((c1 = #0) AND (c2 = F1_key)) DO BEGIN
WHILE NOT KeyPressed DO; { nothing }
c1 := ReadKey;
IF (c1 = #0) THEN BEGIN
c2 := ReadKey;
CASE c2 OF
up_arrow : BEGIN
GotoXY( WhereX-1, WhereY );
Write( ' ' );
IF (posy > 1) THEN Dec( posy )
ELSE posy := 25;
GotoXY( posx, posy );
Write( achar );
END;
down_arrow : BEGIN
GotoXY( WhereX-1, WhereY );
Write( ' ' );
IF (posy < 25) THEN Inc( posy )
ELSE posy := 1;
GotoXY( posx, posy );
Write( achar );
END;
left_arrow : BEGIN
GotoXY( WhereX-1, WhereY );
Write( ' ' );
IF (posx > 1) THEN Dec( posx )
ELSE posx := 79;
GotoXY( posx, posy );
Write( achar );
END;
right_arrow : BEGIN
GotoXY( WhereX-1, WhereY );
Write( ' ' );
IF (posx < 79) THEN Inc( posx )
ELSE posx := 1;
GotoXY( posx, posy );
Write( achar );
END;
F2_key : BEGIN
wait_sec := wait;
lasty := posy;
WHILE (lasty <= 25) AND (NOT KeyPressed) DO
BEGIN
WHILE (posy < 25) AND (NOT KeyPressed) DO
BEGIN
GotoXY( WhereX-1, WhereY );
Write( ' ' );
Inc( posy );
GotoXY( posx, posy );
Write( achar );
Delay( wait_sec )
END; { while posy < 25... }
WHILE (posy > lasty) AND (NOT KeyPressed) DO
BEGIN
GotoXY( WhereX-1, WhereY );
Write( ' ' );
Dec( posy );
GotoXY( posx, posy );
Write( achar );
Delay( wait_sec )
END; { while posy > lasty ... }
Inc( lasty );
wait_sec := wait_sec - 10;
IF wait_sec < 1 THEN wait_sec := 10;
END; { while lasty <= 25... }
END; { F2_key }
ELSE Write( ^G );
END; { CASE }
END; { IF }
END; { WHILE }
GotoXY( 1, 24 );
ClrEol;
Write( 'Press any key to continue ...' );
akey:= ReadKey;
IF music THEN
BEGIN
Sound( 500 ); Delay( 300 ); NoSound;
Sound( 600 ); Delay( 400 ); NoSound;
Sound( 400 ); Delay( 250 ); NoSound;
Sound( 1000 ); Delay( 400 ); NoSound;
Sound( 800 ); Delay( 500 ); NoSound;
Sound( 900 ); Delay( 400 ); NoSound;
Sound( 500 ); Delay( 1000 ); NoSound;
END;
END.