[comp.lang.pascal] Help with [direct CGA write] algorithm

dslg0849@uxa.cso.uiuc.edu (Daniel S. Lewart) (01/01/91)

kamal@wpi.WPI.EDU (Kamal Z Zamli) writes:

> Hi everyone,
>             I had some trouble on my program, it goes something
> like this:
>
>   const
>     DisplayPtr:pointer=ptr($B800,0000) (* assume CGA *)
>   type
>     DataArray = array [1..5000] of string;
>   var
>     Data:DataArray;
>
> Here's my problem, I can't seem to find an algorithm ( I'm using TP
> 5.5) to assign the formatted ( key problem!!!! ) output of
> DataArray to the offset of DisplayPtr.

The following code demonstrates how to write the variable 'Data' directly to
the CGA video screen buffer in text mode.
-------------------------------------------------------------------------------
Uses Crt;

const
  ScreenHeight = 25;  ScreenWidth = 80;
  Size = ScreenHeight*ScreenWidth;
type
  DataArray = array[1..ScreenHeight,1..ScreenWidth] of record
    Ch: Char;
    Attr: Byte;
  end;
var
  x,y: Byte;
  s: String;
  Data: DataArray;
  ScreenBuffer: DataArray absolute $B800:$0000;
Begin
  for y := 1 to ScreenHeight do
    for x := 1 to ScreenWidth do
    begin
      Data[y,x].Attr := TextAttr;
      Data[y,x].Ch := ' ';
    end;
  s := 'Hello World';
  for x := 1 to Length(s) do
    Data[13,34+x].Ch := s[x];
  ScreenBuffer := Data;
End.
-------------------------------------------------------------------------------
Daniel Lewart
d-lewart@uiuc.edu