{ Graphics unit }

unit Grafix;

interface

const
  { Colors constatns }
  ColorTable: array[1..11] of byte =
              (12, { snake 1 }
               14, { snake 2 }
                7, { Walls }
                1, { Background }
               14, { Dialogs - Fore }
                4, {         - Back }
               15, { Number }
                0, { Not selected Item - Fore }
                3, {                   - Back }
               15, { Selected Item - Fore }
                0);{               - Back }

type
  TScreen = array[1..50, 1..80] of record
              Ascii,
              Attr: byte;
            end;

var
  { Global variables }
  Screen: TScreen absolute $B800:0000;

  { Centers text on given row and col }
  procedure Center(X, Y: byte; const text: string);
  { Draws direct to the video mem }
  procedure Print(X, Y, ForeCol, BackCol: byte; What: char);
  { Draw frame on the screen }
  procedure Frame(X1, Y1, X2, Y2, ForeCol, BackCol: byte);
  { Screen cursor handling routines }
  procedure ShowCursor;
  procedure HideCursor;

implementation

uses Crt;

procedure Center;
begin
  GotoXY(X - Length(text) div 2, Y);
  Write(text);
end;

procedure Print;
begin
  { Check bounds }
  If (x >= 1) and (x <= 80) and
     (y >= 1) and (y <= 50) then
  { Draw it }
  with Screen[y, x] do
  begin
    Attr  := BackCol shl 4 or ForeCol;
    Ascii := Ord(What);
  end;
end;

procedure Frame;
var
  x, y: byte;
begin
  For x := X1 + 1 to X2 - 1 do
  begin
    Print(x, Y1, ForeCol, BackCol, 'Á');
    Print(x, Y2, ForeCol, BackCol, 'Â');
  end;
  For y := Y1 + 1 to Y2 - 1do
  begin
    Print(X1, y, ForeCol, BackCol, '´');
    Print(X2, y, ForeCol, BackCol, 'Ã');
  end;

  { Clear that }
  Window(X1 + 1, Y1 + 1, X2 - 1, Y2 - 1);
  TextBackGround(0);
  ClrScr;
  Window(1, 1, 80, 50);
end;

procedure ShowCursor; assembler;
asm
  MOV   AX,$0100        { cursor change request }
  MOV   CX,$0506        { cursor start and stop lines }
  INT   $10             { call that change }
end;

procedure HideCursor; assembler;
asm
  MOV   AX,$0100        { cursor change request }
  MOV   CX,$2607        { cursor start and stop lines }
  INT   $10             { call that change }
end;

end.