[fpc-pascal] Drawing window out line

Tomas Hajny XHajT03 at hajny.biz
Thu May 22 10:02:57 CEST 2014


On Thu, May 22, 2014 09:00, mokashe.ram wrote:


Hi,

> Could Any One help Me  to  writing Horizontal and vertical line to message
> window in Free Pascal as i MEM and MEMW function not supported in free
> pascal.
>
> note : we can not use Video and CRT Unit both in single unit. i want to
> use
> CRT unit only.
>
> below is the my sample code
>
> PROCEDURE draw_window_outline(top_left_x,
>                               top_left_y,
>                               width,
>                               height,
>                               style,
>                               fore,
>                               back      : BYTE);
>
> VAR
>    x,y    : BYTE;
>    offset : INTEGER;
>
>
> BEGIN
>      IF (style<>255) AND (width>2) AND (height>2) THEN
>      BEGIN
>           offset:=(top_left_x-1)*2
>                  +(top_left_y-1)*160;
>           MEM[$B800:offset]:=top_left_corner[style];
>           MEM[$B800:offset+1]:=back*16+fore;
>           FOR x:=1 TO (width-2) DO
>           BEGIN
>                MEM[$B800:offset+x*2]:=horizontal[style];
>                MEM[$B800:offset+x*2+1]:=back*16+fore;
>           END;
>           MEM[$B800:offset+(width-1)*2]:=top_right_corner[style];
>           MEM[$B800:offset+(width-1)*2+1]:=back*16+fore;
>           FOR y:=1 TO (height-2) DO
>           BEGIN
>                MEM[$B800:offset+y*160]:=vertical[style];
>                MEM[$B800:offset+y*160+1]:=back*16+fore;
>                MEM[$B800:offset+(width-1)*2+y*160]:=vertical[style];
>                MEM[$B800:offset+(width-1)*2+y*160+1]:=back*16+fore;
>           END;
>           offset:=(top_left_x-1)*2
>                  +(top_left_y+height-2)*160;
>           MEM[$B800:offset]:=bottom_left_corner[style];
>           MEM[$B800:offset+1]:=back*16+fore;
>           FOR x:=1 TO (width-2) DO
>           BEGIN
>                MEM[$B800:offset+x*2]:=horizontal[style];
>                MEM[$B800:offset+x*2+1]:=back*16+fore;
>           END;
>           MEMW[$B800:offset+(width-1)*2]:=bottom_right_corner[style];
>           MEM[$B800:offset+(width-1)*2+1]:=back*16+fore;
>      END;
> END;

If using just unit Crt, you need to call procedures TextColor and
TextBackground for proper setting of your foreground and background colour
("fore" and "back" in your example) and then replace references to Mem on
_even_ addresses (the odd ones are handled automatically by the previous
setting of TextColor and TextBackground) with a combination of GotoXY and
Write calls.

Obviously, it's better to do it in lines (i.e. call GotoXY for the first
character in a sequence of modified characters on that line, then combine
the whole sequence to a string (e.g. starting with "char
(top_left_corner[style])" followed by "width-2" instances of "char
(horizontal[style])" and finally "char (top_right_corner[style])") and
then call Write for the whole created string.

Note that using unit Video is both more efficient and also easier for
translation of your original code.

Tomas





More information about the fpc-pascal mailing list