VGA: How to use VGAlib3 functions

Below is a short example of how to use VGAlib3 functions in order to (quickly) build a user interface and get some data on screen in respons to some simple action. The simple action in this case is moving the mouse. The resulting output is the continuous reporting of the mouse coordinates on screen.

VGA: the source

Here's the source of a simple VGAlib3 screen that uses three frames: Top, Bottom and PlotWin. While it runs, don't forget to keep the mouse rolling!

      
MODULE VGA;


FROM    VgaLib      IMPORT  WinData, SetVGA, SetText, DrawH, DrawV, SetColour, MakeBox, EraseBox, FillBox,
                            PlotChar, ChrWid, Center, WriteNumber, PlotText;
FROM    Mouse       IMPORT  ShowMouse, HideMouse, ConfineMouse,
                            GetMouseStatus, InitMouse, MouseRecord, SetMouseCursor;
FROM    SYSTEM      IMPORT  ADDRESS, ASSEMBLER;
FROM    System      IMPORT  Terminate;
FROM    Keyboard    IMPORT  KeyPressed, GetKey;
FROM    InOut       IMPORT  WriteString, WriteCard;


VAR MainScreen,                         (* Main screen definition *)
    TopWin, PlotWin : WinData;          (* Parameter and Plotting windows *)
    k, Result       : CARDINAL;
    ch              : CHAR;
    String          : ARRAY [0..80] OF CHAR;
    Rodent          : MouseRecord;
    StopCond        : CARDINAL;


PROCEDURE W8;

VAR k   : CHAR;

BEGIN
    REPEAT
    UNTIL KeyPressed ();
    GetKey (k);
END W8;


PROCEDURE SetCursor (x, y : CARDINAL);

BEGIN
    ASM
        PUSH BP
        MOV  DL, x
        MOV  DH, y
        MOV  BH, 0
        MOV  AH, 2
        INT  10H
        POP  BP
    END;
END SetCursor;


PROCEDURE InitWins;

BEGIN
    MainScreen.TopX   :=   0;   MainScreen.TopY   :=   0;
    MainScreen.Width  := 640;   MainScreen.Height := 480;
    MainScreen.CurX   :=   0;   MainScreen.CurY   :=   0;
    MainScreen.DeltaX :=   0;   MainScreen.DeltaY :=   0;
    MainScreen.Indent :=   5;
    MainScreen.TexCol := 0AX;   MainScreen.BoxCol := 0EX;
    MainScreen.BckCol :=  2X;   MainScreen.MnuCol :=  4X;

    TopWin.TopX     :=  10;     TopWin.TopY     :=  10;
    TopWin.Width    := 620;     TopWin.Height   := 180;
    TopWin.CurX     :=   0;     TopWin.CurY     :=   0;
    TopWin.DeltaX   :=   0;     TopWin.DeltaY   :=   0;
    TopWin.Indent   :=   4;
    TopWin.TexCol   := 0EX;     TopWin.BoxCol   := 0CX;
    TopWin.BckCol   :=  5X;     TopWin.MnuCol   := 14X;

    PlotWin.TopX    :=  10;     PlotWin.TopY    := 200;
    PlotWin.Width   := 620;     PlotWin.Height  := 270;
    PlotWin.CurX    :=   0;     PlotWin.CurY    :=   0;
    PlotWin.DeltaX  := 618;     PlotWin.DeltaY  := 265;
    PlotWin.Indent  :=   4;
    PlotWin.TexCol  := 0DX;     PlotWin.BoxCol  := 0FX;
    PlotWin.BckCol  := 02X;     PlotWin.MnuCol  :=  7X;
END InitWins;


PROCEDURE SetUpScreen;

BEGIN
    InitWins;
    SetVGA;
        MakeBox (MainScreen);
        MakeBox (TopWin);
        MakeBox (PlotWin);
    PlotWin.CurX := 10;
    PlotWin.CurY := 20;
    String := "Hello, one_text for You!";
        Center (PlotWin, String);
    PlotWin.CurX := 10;
    PlotWin.CurY := 40;
    Center (PlotWin, "Hullo, one_text for U!");
    TopWin.CurX := 4;
    TopWin.CurY := 4;
    W8;
    SetColour (TopWin.TexCol);
        FOR  ch := 0X TO 0FFX  DO
            PlotChar (TopWin, ch);
        END;
END SetUpScreen;


PROCEDURE StartMouse;

BEGIN
    InitMouse (Rodent);
    IF Rodent.Status = 0 THEN
        WriteString ("No mouse installed. Exiting....");
        Terminate (2);
    END;
    IF Rodent.Buttons = 2 THEN
        StopCond := 3;
    ELSE
        StopCond := 7;
    END;
    SetMouseCursor (400, 200);
    ShowMouse;
END StartMouse;


BEGIN
    SetUpScreen;
    StartMouse;
    PlotWin.CurY := 200;
    PlotWin.CurX := 40;
    PlotText (PlotWin, 'Hello lets just see what the results will be!');

    LOOP
        REPEAT
            GetMouseStatus (Rodent);
            TopWin.CurX := 300;
            TopWin.CurY := 150;
            WriteNumber (TopWin, Rodent.MouseX, 5);
            WriteNumber (TopWin, Rodent.MouseY, 5);
            WriteNumber (TopWin, Rodent.Status, 3);
        UNTIL Rodent.Status = StopCond;
        EXIT;
    END;
    SetText;
END VGA.
   

Page created October 28, 2006 and