[comp.os.msdos.misc] CGA 16-color mode AND rare questions

kistler@iowasp.physics.uiowa.edu (12/17/90)

Once upon a time long ago, I saw a reference to a file which would have the
answer to the question I'm about to ask, but I've lost the reference, so ...

How do you put a CGA (that's right, CGA) into its 16-color, low resolution
mode?  I assume it's just a matter of plugging the right values into the
CRTC and mode select registers, but what's the magic combination?

Also, what and where is the file I mentioned above?  It was a sort of
less-than-frequently-asked-questions-with-really-standard-answers file.

Thanks in advance.
Allen Kistler
Physics and Astronomy
University of Iowa
kistler@iowa.physics.uiowa.edu

bobmon@iuvax.cs.indiana.edu (RAMontante) (12/17/90)

The CGA "16-color low-resolution mode" is the text mode.  You get character
graphics.  The 16 colors are really eight colors, each available in two
intensities; but the bright intensity is only available for the foreground,
i.e. the characters.  If you try to put the background into high intensity
the display makes the foreground blink instead.  (Actually I think you can
reprogram the display adapter to provide high-intensity background, but it
doesn't seem all that valuable a thing to do.)

Low-resolution *graphics* mode gives you your choice of four four-color
palettes (actually, two palettes, each in high and low intensities).
One is red/yellow/green/black, the other is cyan/magenta/light-gray/black,
where black is the background color and can be changed to any one of 16
possibilities (but you will still have only four colors on the screen at
once).  You get 320x200 dots to color this way.

High-resolution graphics gives you 640x200 dots, but you only get black
and your-choice-of-one-of-16.

My Turbo C User's Guide has a helpful discussion of this.

sigma@pawl.rpi.edu (Kevin J Martin) (12/18/90)

bobmon@iuvax.cs.indiana.edu (RAMontante) writes:
>The CGA "16-color low-resolution mode" is the text mode.  You get character
>graphics.  The 16 colors are really eight colors, each available in two
>intensities; but the bright intensity is only available for the foreground,
>i.e. the characters.  If you try to put the background into high intensity
>the display makes the foreground blink instead.  (Actually I think you can
>reprogram the display adapter to provide high-intensity background, but it
>doesn't seem all that valuable a thing to do.)

No, there really is a 160x100x16 graphics mode on the CGA!  I've seen it
used in several old games like Breakout and Moonbase.  I forget the exact
settings for the ports, but you can probably find it in several books on
IBM PC graphics, especially the slightly older ones, which would mention
this mode as if it were the cutting edge of graphics technology.

It flickered on some monitors, and of course you couldn't pick any colors
other than the basic sixteen (basic eight plus high intensities), but hey,
not bad for CGA.

-- 
Kevin Martin
sigma@rpi.edu
"i feel true blue and real"

ss@sprite.Berkeley.EDU (Srinivasan Seshan) (12/18/90)

I always thought that the 160x100x16 was a character
reprogrammed mode.  Where the charater set was replaced
by a programming into all possible values of a 4x2 matrix.
This also prevented use of text in this mode and
also is the reason its not documented.  

Srini Seshan

PS I can't vouch for the above (since it been so long
	since I used one)

sigma@pawl.rpi.edu (Kevin J Martin) (12/18/90)

ss@sprite.Berkeley.EDU (Srinivasan Seshan) writes:

>I always thought that the 160x100x16 was a character
>reprogrammed mode.  Where the charater set was replaced
>by a programming into all possible values of a 4x2 matrix.
>This also prevented use of text in this mode and
>also is the reason its not documented.  

That would be one way to do it, IF CGA had software selectable fonts like
EGA and VGA do.  Unfortunately, standard CGA only offered (as I remember it)
two fonts in text mode (there was a jumper to get a "thin" font on standard
IBM cards), and if you wanted your own characters, you had to define them in
the standard graphics modes - where you could reprogram the text characters
to have 4x2 combinations, but then you wouldn't have more than four colors.

But, does anyone know how to get to the 160x100x16 mode?  Incidentally, it
didn't really have text, since the BIOS didn't support the mode, and the
text would look awful anyway.

-- 
Kevin Martin
sigma@rpi.edu
"i feel true blue and real"

hpa@casbah.acns.nwu.edu (Peter Anvin) (12/18/90)

>Once upon a time long ago, I saw a reference to a file which would have the
>answer to the question I'm about to ask, but I've lost the reference, so ...
>
>How do you put a CGA (that's right, CGA) into its 16-color, low resolution
>mode?  I assume it's just a matter of plugging the right values into the
>CRTC and mode select registers, but what's the magic combination?
>
>Also, what and where is the file I mentioned above?  It was a sort of
>less-than-frequently-asked-questions-with-really-standard-answers file.

The CGA has a mutated text mode which permits 160x100x16 graphics.  The
idea is similar to using the block characters in the range ASCII 219-ASCII
223 to generate very rough text mode graphics in standard text mode.

This is how you (supposedly) do it (UNTESTED BY ME SINCE I DON'T RUN CGA
ANYMORE):

1. Use BIOS to set the screen to 80x25 colour text mode:
   mov ax,0003h
   int 10h
2. Enable background highlight:
   mov dx,03D8h
   mov al,29h
   out dx,al
3. Program the CRTC to show 100 rows of 2-scan-line characters (that is,
   show only the first 2 rows of each character):
   mov dx,03D0h
   mov al,9
   out dx,al                  ; CRTC register #9
   mov dx,03D1h
   mov al,1
   out dx,al                  ; Max line = 01h (00h,01h = 2 lines)
   mov dx,03D0h
   mov al,6
   out dx,al                  ; CRTC register #6
   mov dx,03D1h
   mov al,100
   out dx,al                  ; 100 rows of text
4. Fill each even address in the VDU memory with 0DEh (if you can't see
   why, look it up in the IBM-ASCII table)
   push es
   push di
   mov di,0B800h
   mov es,di                  ; Segment address 0B800h
   xor di,di                  ; Offset 0000h
   mov cx,8000                ; 100 lines x 80 characters = 8000 words
   mov ax,00DEh               ; This code makes the screen black
   rep stosw                  ; Store on the screen
   pop di
   pop es

Now, the VDU RAM will consist of 2-byte cells, similar to in text mode,
each of which will look like:

+-----------------+-----------------+
| 1 1 0 1 1 1 1 0 | B B B B F F F F |
+-----------------+-----------------+
 -- ASCII code --   ---+--- ---+---
                    Left    Right
                    pixel   pixel
                    colour  colour

The offset address (in segment 0B800h) for a certain pixel (x,y) assuming
(0,0) is the upper left corner, is 2*(int(x/2)+80*y)+1, if x is even it is
the upper 4 bits, if x is odd it is the lower 4 bits.

Since this mode is not supprted by BIOS, you cannot use BIOS to read and
write pixels on the screen, nor can you write text on the display in
160x100x16 mode.  You must write your own read/write-display for all
purpouses.

To exit 160x100x16 mode, just use BIOS function 00h to set any standard
mode, such as regular 80x25 text mode:
  mov ax,0003h
  int 10h
-- 
H. Peter Anvin +++ A Strange Stranger +++ N9ITP/SM4TKN +++
INTERNET:  hpa@casbah.acns.nwu.edu   FIDONET:  1:115/989.4
BITNET:    HPA@NUACC                 RBBSNET:  8:970/101.4

rwberry@hubcap.clemson.edu (Robert W Berry) (12/19/90)

If you've ever played Round42, they have an address with a set of Turbo
Pascal routines called the LoRes toolbox (or something like that.)
The TP routines might not be that useful, but if you could get the
source, it might pay off.

The address is:

Elven Software Company
1605 Euclid Avenue
Syracuse, NY  13224

This address is several years old, but you never know.


Good luck and Hope This Helps(tm),
Bob

-- 
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
-=- Bob Berry -=- PC-Guru's Inc.         ! rwberry@hubcap.clemson.edu   -=-
-=- Teach them quick, before they think. ! 803-654-7623 || 803-656-2635 -=-
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-