Topic : The VGA Training Program
Author : Grant Smith
Page : << Previous 8  Next >>
Go to page :


  }
      Vaddr  : word;                        { Segment of our virtual screen  }

[C++] [Note: For simplicity's sake, I have decided to handle the memory
      allocation differently in the translation to C++ code]

  unsigned char *vaddr = NULL;             // Pointer to the virtual screen //

If you put this in a program as it stands, and try to acess VirScr [or vaddr],
your machine will probably crash. Why? Because you have to get the memory for
your pointers before you can acess them! You do that as follows :

[Pascal]

  Procedure SetUpVirtual;
  BEGIN
    GetMem (VirScr,64000);
    vaddr := seg (virscr^);
  END;

[C++]

  void SetUpVirtual() {
    vaddr = (unsigned char *) calloc(64000,1);
  }

This procedure has got the memory for the screen, then set vaddr to the
screens segment. DON'T EVER LEAVE THIS PROCEDURE OUT OF YOUR PROGRAM!
If you leave it out, when you write to your virtual screen you will probably
be writing over DOS or some such thing. Not a good plan ;-).

When you have finished your program, you will want to free the memory
taken up by the virtual screen by doing the following :

[Pascal]

  Procedure ShutDown;
  BEGIN
    FreeMem (VirScr,64000);
  END;

[C++]

  void ShutDown() {
    free(vaddr);
  }

If you don't do this your other programs will have less memory to use for
themselves.



  Putting a pixel to your virtual screen

This is very similar to putting a pixel to your normal MCGA screen, as
discussed in part one... here is our origonal putpixel :

[Pascal]

  Procedure PutPixel (X,Y : Integer; Col : Byte);
  BEGIN
    Mem [VGA:X+(Y*320)]:=col;
  END;

[C++]

  void Putpixel (int x, int y, unsigned char Col) {
    memset(vga+(x+(y*320)),Col,1);
  }


For our virtual screen, we do the following :

[Pascal]

  Procedure VirtPutPixel (X,Y : Integer; Col : Byte);
  BEGIN
    Mem [Vaddr:X+(Y*320)]:=col;
  END;

[C++]

  void Putpixel (int x, int y, unsigned char Col) {
    memset(vaddr+(x+(y*320)),Col,1);
  }


It seems quite wasteful to have two procedures doing exactly the same thing,
just to different screens, doesn't it? So why don't we combine the two like
this :

[Pascal]

  Procedure PutPixel (X,Y : Integer; Col : Byte; Where : Word);
  BEGIN
    Mem [Where:X+(Y*320)]:=col;
  END;

[C++]

  void Putpixel (int x, int y, unsigned char Col, unsigned char *Where) {
    memset(Where+(x+(y*320)),Col,1);
  }


To use this, you will say something like :

Putpixel (20,20,32,VGA);
PutPixel (30,30,64,Vaddr);


These two statements draw two pixels ... one to the VGA screen and one to
the virtual screen! Doesn't that make you jump  with joy! ;-) You will
have noticed that we still can't actually SEE the virtual screen, so on to
the next part ...



  How to "Flip" your virtual screen on to the true screen

You in fact already have to tools to do this yourselves from information
in the previous parts of this trainer series. We will of course use the
Move [_fmemcpy] command, like so :

[Pascal]

  Move (Virscr^,mem [VGA:0],64000);

[C++]

  _fmemcpy(vga,vaddr,64000);


simple, eh? You may want to wait for a verticle retrace (Part 2) before you
do that, as it may make the flip much smoother (and, alas, slower).

Note that most of our other procedures may be altered to support the
virtual screen, such as Cls etc. (see Part 1 of this series), using the
methoods described above (I have altered the CLS procedure in the sample
program given at the end of this Part.)

We of ASPHYXIA have used virtual screens in almost all of our demos.
Can you imagine how awful the SoftelDemo would have looked if you had to
watch us redrawing the moving background, text and vectorballs for EACH
FRAME? The flicker, doubling effects etc would have made it awful! So
we used a virtual screen, and are very pleased with the result.
Note, though, that to get the speed we needed to get the demo fast enough,
we wrote our sprites routines, flip routines, pallette routines etc. all
in assembly. The move command is very fast, but not as fast as ASM ;-)



  In closing

I am writing this on the varsity computers in between lectures. I prefer
writing & coding between 6pm and 4am, but it isn't a good plan when
varsity is on ;-), so this is the first part of the trainer series ever
written before 9pm.

I have been asked to do a part on scrolling the screen, so that is
probably what I will do for next week. Also, ASPHYXIA will soon be putting
up a small demo with source on the local boards. It will use routines
that we have discussed in this series, and demonstrate how powerful these
routines can be if used in the correct manner.

Some projects for you to do :
  1) Rewrite the flip statement so that you can say :
        flip (Vaddr,VGA);
        flip (VGA,Vaddr);
      ( This is how ASPHYXIAS one works )

  2) Put most of the routines (putpixel, cls, pal etc.) into a unit,
     so that you do not need to duplicate the procedures in each program
     you write. If you need help, leave me mail.


See you next week
   - Denthor


--==[ PART 5 ]==--


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

Introduction

Hello! This is Denthor here with the 5 part of the ASPHYXIA VGA Trainer
Series : The Scrolling Saga. I have had many requests for information on
scrolling, so I decided to make it this weeks topic. Note that I do make
reference to my recently released program TEXTER5, which should be available
from wherever you get this message. (Note to Sysops : If you put the trainer
series up on your boards, please add WORMIE.ZIP and TEXTER5.ZIP as they
both suppliment this series)

By the way, sorry for the delay in the appearance of this part. Tests,
projects and a few wild days of sin at the Wild Coast all conspired
against the prompt appearance of this part. Also note I need more input as
to what I should do future parts on, so leave me mail.

If you would like to contact me, or the team, there are many ways you
can do it : 1) Write a message to Grant Smith in private mail here on
                  the Mailbox BBS.
            2) Write a message here in the Programming conference here
                  on the Mailbox (Preferred if you have a general
                  programming query or problem others would benefit from)
            3) Write to ASPHYXIA on the ASPHYXIA BBS.
            4) Write to Denthor, Eze or Livewire on Connectix.
            5) Write to :  Grant Smith
                           P.O.Box 270 Kloof
                           3640
                           Natal
            6) Call me (Grant Smith) at 73 2129 (leave a message if you
                  call during varsity)

NB : If you are a representative of a company or BBS, and want ASPHYXIA
       to do you a demo, leave mail to me; we can discuss it.
NNB : If you have done/attempted a demo, SEND IT TO ME! We are feeling
        quite lonely and want to meet/help out/exchange code with other demo
        groups. What do you have to lose? Leave a message here and we can work
        out how to transfer it. We really want to hear from you!




  What is scrolling?

If you

Page : << Previous 8  Next >>