Metropoli BBS
VIEWER: progp092.pas MODE: TEXT (ASCII)
{**********************************************************************}
{ Display black and white sprite and move it using arrow keys           }
{**********************************************************************}

procedure demo_cursor;
const
MAX_X = 624;
MAX_Y = 334;
KEY_ESC = $1B;
KEY_UP  = 72;
KEY_DOWN = 80;
KEY_LEFT = 75;
KEY_RIGHT = 77;
KEY_ENTER = $0D;
MONO = 5;
COLOR = 4;
VMONO = 7;

arrow_and_mask : array[0..31] of byte = (
                0,0, 0,0, 0,0, $1F,$F8,
                $1F,$F8, $1F,$F8, $1F,$F8, $1F,$F8,
                $1F,$F8, $1F,$F8, $1F,$F8, $1F,$F8,
                $1F,$F8, 0,0, 0,0, 0,0);

arrow_xor_mask : array[0..31] of byte = (
                $FF,$FF, $80,$01, $BF,$FD, $A0,$05,
                $A0,$05, $A0,$05, $A0,$05, $A0,$05,
                $A0,$05, $A0,$05, $A0,$05, $A0,$05,
                $A0,$05, $BF,$FD, $80,$01, $FF,$FF);

var
i,key,x,y : integer;
begin
        clear_screen;
        i := get_display_type;
        if i = MONO then set_mode($0F)
        else if i = VMONO then set_mode($0F)
        else if i = COLOR then set_mode($0E)
        else set_mode($10);

        { Draw white box to see how cursor looks on white background    }
        for i := 0 to 31 do line(320,100,20*i,0,i);     { Fill background}
        for i := 0 to 31 do line(320,100,20*i,199,i);
        for i := 0 to 19 do line(320,100,0,10*i,i);
        for i := 0 to 19 do line(320,100,639,10*i,i);
        solid_box(220,100,150,150,15);                  { and draw a box}


        { Set cursor shape and color, and display the first cursor      }
        set_cursor(ofs(arrow_and_mask),ofs(arrow_xor_mask), 0, 15);
        x := 220;                       { initial position of cursor    }
        y := 100;
        move_cursor(x,y);               { show cursor at initial pos    }

        { Loop while keys are pressed }

        repeat
                key := integer(readkey);
                case key of     { Move cursor according to key }

                KEY_ESC : remove_cursor;
                KEY_ENTER : remove_cursor;

                KEY_UP: begin
                        if y > 0 then dec(y);
                        move_cursor(x, y);
                        end;

                KEY_DOWN: begin
                        if y < MAX_Y then inc(y);
                        move_cursor(x, y);
                        end;

                KEY_RIGHT: begin
                        if x < MAX_X then inc(x);
                        move_cursor(x, y);
                        end;

                KEY_LEFT: begin
                        if x > 0 then dec(x);
                        move_cursor(x, y);
                        end;
                end;
        until key = KEY_ENTER;

        i := integer(readkey);
        {--- Set default text mode                                      }
        i := get_display_type;
        if i = MONO then set_mode(7)
        else if i = VMONO then set_mode(7)
        else    set_mode(3);
end;

[ RETURN TO DIRECTORY ]