[comp.sys.ibm.pc] Video Programming

roper@uw-june.UUCP (02/02/87)

Can anyone recommend a good reference book providing in-depth
programming information for the various video controller types?  I am
looking for something in the style and price range of say, Norton's book
or Advanced MS-DOS (as opposed to the Options and Adapters Manual).

It should do a thorough job of sorting out the current state-of-affairs
in video adapters, especially the various EGA and PGA standards -- which 
are given the short shrift in both of the aforementioned books. 

Any suggestions would be appreciated.

In the meantime, I have a few questions:

1)  Since only 128K of main memory is reserved for display buffers (from
    A0000 to BFFFF), where do EGA's with "a full 256K of RAM", put the 
    other 128K?  Or is it just bank-switched?

2)  By my calculations, 112K is required for a full page of graphics in
    video mode 10h, using a 16-color palette.  Is the rest of the (128K)
    display memory wasted?

3)  Advanced MS-DOS says that mode 10h uses either a 4- or 16-color palette,
    depending upon the amount of display memory provided by the adapter.
    Is this selection made automatically?  What is the cut-off?

4)  Norton makes a vague reference to the difficulty of writing directly
    to the EGA's display buffer.  What's the story?  Are the pros and cons
    of accessing the EGA's buffer directly any different from say, the MA
    or CGA?



Many thanks.

-- 
---Michael Roper---                    *
                                       *   "Calvin, do you believe in God?"
ARPA:  roper@june.cs.washington.edu    *
UUCP:  ihnp4!uw-beaver!uw-june!roper   *  "Well...SOMEBODY is out to get me."

andy@thelink.UUCP (02/04/87)

Regarding EGA memory usage:  Yes, it is divided up into two 128K banks,
so that you get two screen pages.  I'll take your word that the screen
area only adds up to 112K.  Assuming that's true, I don't know if it's
wasted or not.

Andy Dustman ({ihnp4!alpha,iuvax!ndmath}!ack!andy)

zhahai@gaia.UUCP (02/05/87)

In article <1929@uw-june.UUCP> roper@uw-june.UUCP (Michael Roper) writes:
>1)  Since only 128K of main memory is reserved for display buffers (from
>    A0000 to BFFFF), where do EGA's with "a full 256K of RAM", put the 
>    other 128K?  Or is it just bank-switched?

The EGA can be mapped into memory space in several ways, such as B0000-B7FFF
or B8000-BFFFF (for mono & CGA emulation, resp.), or A0000-AFFFF (for
most non-emulation graphic modes), or theoretically A0000-BFFFF (I have
not seen this used; it would conflict with another color/mono adapter).
When in graphic mode 10h, 640x350 color, it's memory is mapped to A0000-AFFFF,
which is only 64K.  It can, however, support up to 4 bit planes in this
address slot (256K Bytes total).  There are various registers which allow
one to read/write single or groups of planes.

>2)  By my calculations, 112K is required for a full page of graphics in
>    video mode 10h, using a 16-color palette.  Is the rest of the (128K)
>    display memory wasted?

You are right, with 16 colors any memory beyond 112K is not displayed;
with 256K this leaves room for a second full page of graphics for ping
ponging if you wish.  Or one could scroll around within a picture larger
than 640x350.  (With only 64K of memory installed in the IBM EGA, only
56K is used, with 4 colors).

>3)  Advanced MS-DOS says that mode 10h uses either a 4- or 16-color palette,
>    depending upon the amount of display memory provided by the adapter.
>    Is this selection made automatically?  What is the cut-off?

Yes, it is automatic; 64K gets 4 colors, 128K or more gets 16.  Handled by
new BIOS (onboard EGA, C0000) during initialization.

>4)  Norton makes a vague reference to the difficulty of writing directly
>    to the EGA's display buffer.  What's the story?  Are the pros and cons
>    of accessing the EGA's buffer directly any different from say, the MA
>    or CGA?

The major pros and cons are the same, speed versus portablility.  All you
get with the BIOS is dot plot/read.  A line drawing primitive can run much
faster if it directly accesses the screen.  The major "con" with the EGA
is that its mapping is more complex regarding multiple bit maps, although
simpler regarding x,y to address translation (no "interleaving" like the
CGA and Herc do in mapping memory to screen).  

In brief: The mode 10h screen is mapped as 4 bit maps, all at location
A0000-A6FFF (28 KBytes).  A0000 is the upper left byte (most significant
bit leftmost, as with CGA/Herc; IBM displays are mixed-endian #%$@).
A0001 is just to the right of that. A0050 (80 decimal after start of buffer)
is just below the first byte, A00A0 just below that.
You can write to any set of planes (all 4, just one, or anything between)
without modifying the others - Provided you do a read of the location 
before writing (if writing all 4 it doesn't matter).  You can read from any
one plane, or from a comparison of any set of planes with a color compare
register.  You can mask which bits of the byte are changed and which are
not (again, must read first unless writing to all bits).  You can do an
AND, OR, XOR or replace when writing (... must read first unless doing
a replace).  There is also a rotation function built in, which I have
not found any way to use (the cpu rotate is more useful).  Perhaps you
can see why this aspect is more difficult to set up (especially with poor
documentation) than CGA stuff.  The good part is that sometime you can
get a real speed gain (you can read from one location, (8 bits x 4 planes)
and write the contents to another, thus transferring 32 bits in one byte
copy).  Good luck.  I have not seen good documentation; IBM now sell the
EGA tech ref material without the Options and Adapters Tech Ref Manuals
set, I hear.  PC tech journal has had some articles which cover everything
in the IBM manuals; have to look in a library to find which issues.
Be prepared to use a debugger and try things out to verify your guesses
at to what the documentation means.

A challenge: find out how to get a 1024x1024 virtual screen (4 colors).
It can be done. (you only get a 640x350 window to display, of course, but
you can move it around).       ~z~

>---Michael Roper---                    *
-- 
Zhahai Stewart
{hao | nbires}!gaia!zhahai

perry@omepd.UUCP (02/07/87)

In article <1929@uw-june.UUCP> roper@uw-june.UUCP (Michael Roper) writes:
>Can anyone recommend a good reference book providing in-depth
>programming information for the various video controller types?  I am
>looking for something in the style and price range of say, Norton's book
>or Advanced MS-DOS (as opposed to the Options and Adapters Manual).
>It should do a thorough job of sorting out the current state-of-affairs
>in video adapters, especially the various EGA and PGA standards -- which 
>are given the short shrift in both of the aforementioned books. 

Well, I'm afraid I can't quote you a definitive, readable, understandable
etc. source. For myself, I took the sparse information in Norton&Co. and two
articles quoted there (?) and started trying. I think that these two
articles are a fair beginning point for dealing with the EGA, but they are,
of course, just an introduction and bare-bones hardware/BIOS listing. No
PGA there, either.
If you want to try them, here are the article quotations (your favorite
library ought to have them):

	*Graphic Enhancement*
	PC Tech Journal, April 1985
	pages 58-77
	- gives a good summary of hardware and BIOS calls for the EGA -

	*Programming The Enhanced Graphics Adapter*
	BYTE magazine, fall 1985 issue ("Inside The IBM PCs")
	Pages 209-220
	- gives an introduction into the hardware of the EGA -

For both articles, it helps a lot if you have already done some video
programming before.

In the meantime, here are the answers to your questions:

>1)  Since only 128K of main memory is reserved for display buffers (from
>    A0000 to BFFFF), where do EGA's with "a full 256K of RAM", put the 
>    other 128K?  Or is it just bank-switched?

In the old CGA-compatible modes, the memory layout is identical to that
of the CGA. Of course, you are using only a small part of the EGA memory
in this case.
In high-resolution (640x350) mode, memory is divided into four parallel
"planes". Each plane covers the entire screen and contributes one bit to
the color information; the four bits at identical positions in the four
planes give the (four-bit) number of the color in that pixel, and this
number (0 through 15) indexes the real color stored in the EGA's palette
vector (hence 16-out-of-64 colors).
In the PC's address space, the four planes occupy the same addresses
(so they fit into <64K). You CAN'T write directly into video memory as you
would with a CGA or Hercules adapter (or the EGA in CGA mode); instead you
have to set various and sundry hardware registers to select one of several
read/write modes, and what you finally read from/write to the memory
locations is latched, masked, shifted, and otherwise twisted around depending
on these modes. It sometimes gets rather complicated; obviously, they designed
it for efficiency rather than for ease of use.

>2)  By my calculations, 112K is required for a full page of graphics in
>    video mode 10h, using a 16-color palette.  Is the rest of the (128K)
>    display memory wasted?
The EGA maintains status information on its own RAM, most notably the color
palette and programmable character fonts. Consider that you can load four
complete bit-mapped character sets (with up to 128 characters each) into
the EGA (although you can only use two at a time). Of course, some bytes
(probably a few K) are wasted, but who counts memory chips nowadays :-).
By the way, with a 256K EGA, you can really have two high-res display pages.

>3)  Advanced MS-DOS says that mode 10h uses either a 4- or 16-color palette,
>    depending upon the amount of display memory provided by the adapter.
>    Is this selection made automatically?  What is the cut-off?
The 4-color palette in high-res (10h) mode is used only on the minimal (64K)
version. As you noted, you need 112K (and some more) to represent a full
16-color high-res page. On a 64K-diet, the EGA switches to 2 planes (instead
of 4) and has therefore only a 4-out-of-64 color selection. With 128K, you
get one page of 16 colors. This selection is made automatically (by the BIOS).

>4)  Norton makes a vague reference to the difficulty of writing directly
>    to the EGA's display buffer.  What's the story?  Are the pros and cons
>    of accessing the EGA's buffer directly any different from say, the MA
>    or CGA?
See answer to (1). It's a completely different world. On the one hand, you
don't 'see' the pixels any more in your address space, so the simplicity of
reading or changing individual pixels just via a 'mov' is lost. On the other
hand, the various read/write modes of the EGA give you (I think) adequate
support to do things *efficiently* (though not very *simply*). You certainly
have to go to considerable lengths to program the EGA directly.
The BIOS makes a valiant effort to hide this complex hardware from you. You
can still happily call the *read pixel* or *set pixel* etc. functions of
INT 10h. However, as these calls are *elementary*, using them to build
complex graphics makes your program **awfully slow**. Remember that there's
also 75% more pixels to handle...

I hope this helps you (and other Net-People).

P.S.: Would some kind souls out there please try to send me mail? I suspect that
 ***  there's something fishy about my incoming mail address, but I'd love
 ***  to learn otherwise... thanks in advance.
------------------------------------------------------------------------
  <<  Perry The Cynic >>	      ...!tektronix!ogcvax!omepd!inteloa!perry
						...!verdix!omepd!inteloa!perry
    (Peter Kiehtreiber)			      -or try- perry@inteloa.intel.com

sbanner1@uvicctr.UUCP (02/14/87)

In article <368@omepd> perry@inteloa.intel.com (Perry The Cynic) writes:
>In article <1929@uw-june.UUCP> roper@uw-june.UUCP (Michael Roper) writes:
>>Can anyone recommend a good reference book providing in-depth
>>programming information for the various video controller types?  I am
>>looking for something in the style and price range of say, Norton's book
>>or Advanced MS-DOS (as opposed to the Options and Adapters Manual).
>>It should do a thorough job of sorting out the current state-of-affairs
>>in video adapters, especially the various EGA and PGA standards -- which 
>>are given the short shrift in both of the aforementioned books. 

  In not quite the same line as the above (but close), does anyone
out there know how to use the Tecmar Graphics Master's 640x400 16 color
mode.  I can get things that are sort of similar to what ACAD produces,
but only on a portion (about a quarter), of the screen.  What I can get,
I get by playing directly with the 6845 registers, and screen memory,
but I am not sure if I have just not stumbled accross the right
combination yet, or am looking in totaly the wrong direction.  I would
send Tecmar a letter (and I still might), but I have heard that they
are not very helpfull in this area, so I am asking here first (and
working on a disassembly of the ACAD driver for the board, but I am
not too familiar with taking apart disassembled code).

                  Thanks,

                      S. John Banner

...!{uw-beaver,ubc-vision}!uvicctr!sbanner1
ccsjb@uvvm
sbanner1@uvunix.UVIC.CDN

#1 1121 Fort St.
Victoria BC.
Canada
V8V 3K9