Topic : The VGA Training Program
Author : Grant Smith
Page : 1 Next >>
Go to page :


--==[ PART 1 : The Basics]==--


Introduction

Hi there! This is Denthor of ASPHYXIA, AKA Grant Smith. This training
program is aimed at all those budding young demo coders out there. I am
assuming that the reader is fairly young, has a bit of basic Std. 6 math
under his belt, has done a bit of programming before, probably in BASIC,
and wants to learn how to write a demo all of his/her own.

This I what I am going to do. I am going to describe how certain routines
work, and even give you working source code on how you do it. The source
code will assume that you have a VGA card that can handle the
320x200x256 mode. I will also assume that you have Turbo Pascal 6.0 or
above (this is because some of the code will be in Assembly language,
and Turbo Pascal 6.0 makes this incredibly easy to use).  [In addition,
C++ source has been included, so you now have a choice].  By the end of
the first "run" of sections, you will be able to code some cool demo stuff
all by yourself. The info you need, I will provide to you, but it will be
you who decides on the most spectacular way to use it.

Why not download some of our demos and see what I'm trying to head you
towards.

[Note: things in brackets have been added by Snowman.  The original text
has remained mostly unaltered except for the inclusion of C++ material]

I will be posting one part a week on the Mailbox BBS. I have the first
"run" of sections worked out, but if you want me to also do sections on
other areas of coding, leave a message to Grant Smith in private E-Mail,
or start a conversation here in this conference. I will do a bit of
moderating of a sort, and point out things that have been done wrong.

In this, the first part, I will show you how you are supposed to set up
your Pascal or C++ program, how to get into 320x200x256 graphics mode
without a BGI file, and various methods of putpixels and a clearscreen
utility.

NOTE : I drop source code all through my explanations. You needn't try
       to grab all of it from all over the place, at the end of each part I
       add a little program that uses all the new routines that we have
       learned. If you do not fully understand a section, leave me
       private mail telling me what you don't understand or asking how I
       got something etc, and I will try to make myself clearer. One
       last thing : When you spot a mistake I have made in one of my
       parts, leave me mail and I will correct it post-haste.  However, I
       do not know C++ currently, so if you have trouble with that source,
       contact Christopher Mann instead.



Disclaimer

Hi again, sorry that I have to add this, but here goes.  All source code
obtained from this series of instruction programs is used at your own
risk.  Denthor and the ASPHYXIA demo team hold no responsibility for any
loss or damage suffered by anyone through the use of this code.  Look
guys, the code I'm going to give you has been used by us before in
Demos, Applications etc, and we have never had any compliants of machine
damage, but if something does go wrong with your computer, don't blame
us.  Sorry, but that's the way it is.



The MCGA mode and how you get into it in Pascal or C++ without a BGI

Lets face it. BGI's are next to worthless for demo coding. It is
difficult to find something that is slower then the BGI units for doing
graphics. Another thing is, they wern't really meant for 256 color
screens anyhow. You have to obtain a specific external 256VGA BGI to get
into it in Pascal, and it just doesn't make the grade.

So the question remains, how do we get into MCGA 320x200x256 mode in
Pascal or C++ without a BGI?  The answer is simple : Assembly language.
Obviously assembly language has loads of functions to handle the VGA
card, and this is just one of them. If you look in Norton Gides to
Assembly Language, it says this ...



INT 10h,  00h (0)        Set Video Mode

    Sets the video mode.

       On entry:      AH         00h
                      AL         Video mode

       Returns:       None

       Registers destroyed:      AX, SP, BP, SI, DI



This is all well and good, but what does it mean? It means that if you
plug in the video mode into AL and call interrupt 10h, SHAZAM! you are
in the mode of your choice. Now, the MCGA video mode is mode 13h, and
here is how we do it:

[PASCAL]

  Procedure SetMCGA;
  BEGIN
    asm
          mov     ax,0013h
          int     10h
    end;
  END;

[C++]

  void SetMCGA() {
    _AX = 0x0013;
    geninterrupt (0x10);
  }


There you have it! One call to that procedure/function, and BANG you are in
320x200x256 mode. We can't actually do anything in it yet, so to go back
to text mode, you make the video mode equal to 03h, as seen below :

[PASCAL]

  Procedure SetText;
  BEGIN
    asm
          mov     ax,0003h
          int     10h
    end;
  END;

[C++]

  void SetText() {
    _AX = 0x0003;
    geninterrupt (0x10);
  }


BANG! We are back in text mode! Now, cry all your enquiring minds, what
use is this? We can get into the mode, but how do we actually SHOW
something on the screen? For that, you must move onto the next section
....



  Clearing the screen to a specific color

Now that we are in MCGA mode, how do we clear the screen. The answer is
simple : you must just remember that the base adress of the screen is
a000h. From a000h, the next 64000 bytes are what is actually displayed on
the screen (Note : 320 * 200 = 64000). So to clear the screen, you just use
the fillchar command like so :

[PASCAL]

      FillChar (Mem [$a000:0],64000,Col);

[C++]
    
      memset(vga, Col, 0xffff);  // "vga" is a pointer to address 0xa000


What the mem command passes the Segment base and the Offset of a part of
memory : in this case the screen base is the Segment, and we are starting
at the top of the screen; Offset 0. The 64000 [0xffff] is the size of the
screen (see above), and Col is a value between 0 and 255, which represents
the color you want to clear the screen to.



  Putting a pixel on the screen (two different methoods)

If you look in Norton Guides about putting a pixel onto the screen, you
will see this  :



    Writes a pixel dot of a specified color at a specified screen
    coordinate.

    On entry:      AH         0Ch
                   AL         Pixel color
                   CX         Horizontal position of pixel
                   DX         Vertical position of pixel
                   BH         Display page number (graphics modes with more
                              than 1 page)

  

Page : 1 Next >>