qp.hlp (Table of Contents; Topic list)
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.
CRT3.PAS
  Example Contents Index                                    Back
 
PROGRAM crt3;
 
{ CRT3.PAS : Demonstrates cursor control. }
 
USES
    Crt, Dos;
 
CONST
    initial_wait = 100;
    speed_up     = 10;
    minimum_wait = 10;
    blank        = ' ';
 
VAR
    c              : Char;
    pos_x, pos_y   : Byte;
    left_x, down_y : Boolean;
    wait           : LongInt;
 
{================================ beep =================================
  Procedure beep makes noise.
}
 
PROCEDURE beep;
 
BEGIN
    Sound( 100 );
    Delay( 100 );
    NoSound;
    wait := wait - speed_up;    { speed up letter }
    IF wait < minimum_wait THEN
        wait := initial_wait;
END; { procedure beep }
 
{============================= 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
 
    { Initialization. }
    wait := initial_wait;
    left_x := True;
    down_y := True;
 
    { Clear screen and cursor, get started. }
    ClrScr;
    cursor_off;
    DirectVideo := True;
    GotoXY( 10, 5 );
    Write( 'Press any letter ...' );
    Writeln;
    Writeln( 'Type any other character to quit. ');
    c := ReadKey;
    Write( c );
    pos_x := WhereX-1;
    pos_y := WhereY;
 
    { Bounce the character around the screen, changing
      direction when it reaches the edge of the screen.
    }
    REPEAT
        GotoXY( pos_x, pos_y );
        Write( blank );
        { Alter X coordinate depending on direction. }
        IF left_x THEN
            Inc( pos_x )
        ELSE
            Dec( pos_x );
        { Alter Y coordinate depending on direction. }
        IF down_y THEN
            Inc( pos_y )
        ELSE
            Dec( pos_y );
 
        GotoXY( pos_x, pos_y );
        Write( c );
        Delay( wait );
 
        { Reached right edge of the screen? }
        IF pos_x = 80 THEN
            BEGIN
            left_x := False;
            beep;
            END;
 
        { Reached left edge of the screen? }
        IF pos_x = 1  THEN
            BEGIN
            left_x := True;
            beep;
            END;
 
        { Reached the bottom of the screen? }
        IF pos_y = 25 THEN
            BEGIN
            down_y := False;
            beep;
            END;
 
        { Reached the top of the screen? }
        IF pos_y = 1 THEN
            BEGIN
            down_y := True;
            beep;
            END;
 
    UNTIL KeyPressed;
 
    { The next character typed stops the program. }
    c := ReadKey;
    GotoXY( 1, 25 );
    Write( 'Press any key to end the program ...' );
    c := ReadKey;
 
END.