delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/01/02/10:07:35

Comments: Authenticated sender is <mert0407 AT sable DOT ox DOT ac DOT uk>
From: "George Foot" <george DOT foot AT merton DOT ox DOT ac DOT uk>
To: Alex Lowe <ayin AT 2xtreme DOT net>
Date: Sat, 2 Jan 1999 15:05:24 +0000
MIME-Version: 1.0
Subject: Re: small graphics library
CC: djgpp AT delorie DOT com
X-mailer: Pegasus Mail for Win32 (v2.42a)
Message-Id: <E0zwScm-00050s-00.1999-01-02-15-05-56@mail13.svr.pol.co.uk>
Reply-To: djgpp AT delorie DOT com

On  2 Jan 99 at 1:38, Alex Lowe wrote:

> Hello all,
> 
> I am searching for a SMALL (ironically in big letters) graphics library.
> The smaller the better, just a few graphics modes (at least 640x480x16
> colors) and a putpixel... A Vesa library is nice, if it is SMALL, I
> don't want to make a VESA library.

Not many libraries support 16 colour modes.

> Or... (even better, and preferred)
> 
> a description on how to plot pixels directly to memory in VGA mode 0x12
> (640x480x16color). The memory doesn't seem to be linear at 0xA000. I
> just need the memory scheme so that I can properly plot pixels directly
> to memory, the bios putpixel is wwwaaayyyy too slow, obviously. 

The memory is arranged as four planes.  Each plane is like a 
monochrome bitmap.  One plane holds the red components, one the 
greens, one the blues and one the intensity.  To do any useful 
writes you need to write not only to memory but also to the 
card's registers -- they determine which plane is written to, 
for example.  While the memory layout is pretty simple, 
deciding how to do the write is not.

There are three or four (depends whether you have EGA or VGA)
`write modes'.  The most useful ones for general writing are
modes 0 and 2.  In write mode 0, you set some of the registers
to choose which plane(s) you want to write to, then write the
new value to wherever you want to write.  Most of the time you
need to perform a read before each write, to set the latch
registers.  The value you write is the bitmask; it is entered 
into that memory location in each plane you marked.  There is 
another way to use this write mode; you can set one register to 
say which planes you want to affect, and set another register 
to say whether affected bits in those planes should be set or 
cleared.  Then you write a bitmask as normal.  The effect is to 
set a number of pixels to a certian colour (if the plane mask 
is set to 15).

In write mode 2, the CPU data is the colour to write, and you 
set the bitmask through a register.  Bit 0 of the CPU data goes 
to plane 0 (blue), bit 1 to plane 1 (green), etc.  In many 
cases this mode is more intuitive to use, but it can be slower 
because only 4 bits of CPU data are used (in write mode 0 all 
eight bits are relevant).

Writing efficient code to use 16 colour modes can be a fairly 
tedious process.  You have to consider which write mode to use, 
trying to reduce the number of register writes to a minimum.  
In the summer I wrote a 16 colour EGA/VGA driver for Allegro, 
for the 640 pixel wide modes, but that wouldn't be much use to 
you since you don't want to use Allegro.

If you want to find out more about this you really need some
documentation.  Download the VGADOC package (linked from
http://www.talula.demon.co.uk/freebe/) and look at egaregs.txt
and vgaregs.txt.  That's fairly minimal information but should
be enough to get you started.  I also have complete specs for
the ET4000, which includes more verbose descriptions of the VGA
registers, and an old book on EGA/VGA graphics programming. 
Finding books on this these days is not easy.  If you need any 
further help, or want me to write you a few examples, just let 
me know.

-- 
george DOT foot AT merton DOT oxford DOT ac DOT uk

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019