On Tue, May 20, 2014 14:25, mokashe....@gmail.com wrote:

Hi,

> I am trying use VideoBuf Variable available in 'Video' unit but getting
> error *"Program Received Signal SIGSEGV Segmentation fault". *
 .
 .
>               {* MEM[$B800:(x_offset-1)*2
>                         +(y_offset-1)*160]:=32;
>                MEM[$B800:(x_offset-1)*2
>                         +(y_offset-1)*160+1]:=colour*16; *}
>
>               * VideoBuf^[(x_offset-1)*2
>                         +(y_offset-1)*ScreenWidth]:=Ord(32);
>                VideoBuf^[(x_offset-1)*2
>                         +(y_offset-1)*160+1]:=Ord(colour*16);*

As suggested in my post in the other thread about the Mem and MemW topic,
the two consecutive accesses to Mem[] should be preferably converted to
just one with VideoBuf, because the elements accessed by VideoBuf^ are
words (which in turn consist from one byte for the character code and
another byte for the colour attributes consisting of the background colour
in the upper nibble and foreground colour in the lower nibble). Moreover,
since the elements are words, you should not multiply the offset by two
any longer. This in turn gives you:

         VideoBuf^[(x_offset-1)
                  +(y_offset-1)*ScreenWidth]:=$20 or (colour * 16) shl 8;

This works as intended (now disregarding stuff like missing checking of
the provided parameters against ScreenWidth and ScreenHeight - calling the
routine above with too big parameters would indeed still give you a
SIGSEGV, but that's another story).

Tomas


_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to