home *** CD-ROM | disk | FTP | other *** search
/ Big Blue Disk 10 / bbd10new.zip / VIDEO6.TXT < prev    next >
Text File  |  1987-05-22  |  17KB  |  282 lines

  1. |D╔══════════════════╗════════════════════════════════════════════════════════════
  2. |D║ |5The Happy Hacker |D║════════════════════════════════════════════════════════════
  3. |D╚══════════════════╝════════════════════════════════════════════════════════════
  4.  
  5. ^C^1A VIDEO TUTORTIAL  --  Part 6
  6. ^Cby Joel Ellis Rea
  7.  
  8.    Last issue I discussed the "heart" of both the MDA and the CGA (as well as
  9. boards which are enhancements to these, such as the Hercules and Plantronics),
  10. the Motorola 6845 Cathode Ray Tube Controller (CRTC) chip.  I mentioned then
  11. that there are other registers implemented in the hardware of the MDA and CGA
  12. besides the 18 CRTC registers.  I specifically described 2 of these, which are
  13. used to access the 18 CRTC registers themselves.  In this issue, I will more
  14. fully describe the non-CRTC registers of both the MDA and the CGA, as well as
  15. give some examples of their use.  Also on this issue is a demonstration program
  16. which shows some of the effects possible by directly "tweaking" these registers
  17. as well as the CRTC registers.
  18.  
  19.    Any board that is installed into the IBM-PC bus usually presents some form
  20. of memory or pseudo-memory to the PC address space.  This is usually one or
  21. more of the following three types:
  22.  
  23. 1.  RAM (Random Access Memory), which can be read from or written to.
  24.  
  25. 2.  ROM (Read-Only Memory), which can only be read from, not written to.
  26.     This is generally used to add new commands to the System BIOS (Basic Input/
  27.     Output System) ROM located on the motherboard.  The EGA does this, the CGA
  28.     and MDA do not.
  29.  
  30. 3.  I/O (Input/Output) ports.  These use a different form of addressing than
  31.     RAM or ROM, and thus do not take up "space" in the CPU's 1Meg address
  32.     space.  Rather, they form their own 64K address space.
  33.  
  34.    The MDA and CGA have types 1 and 3, RAM and I/O ports.  The RAM is for the
  35. display buffer, and the I/O ports are for control.  They also have ROM (for the
  36. character generator) but it is not made available to the PC bus.  It is used by
  37. the card's circuitry alone.
  38.  
  39.    It is a fundamental law of hardware interfacing that no two devices can
  40. claim the same memory addresses in the system at the same time.  Should this
  41. occur, the system will lock up (or crash) due to "bus contention", meaning two
  42. devices fighting over the same area of memory.  This goes for the 64K I/O space
  43. as well, which is really just another area of memory with its own address
  44. space.  IBM planned a way to avoid contention by allocating both the memory and
  45. I/O spaces for particular purposes.  The memory space ranges from 00000h to
  46. FFFFFh (1M), while the I/O space ranges from 0000h to FFFFh (64K).  System RAM
  47. can reside in space from 00000h to 0AFFFFh (640K).  The rest of the space, from
  48. 0B0000h to 0FFFFFh (384K), is reserved for plug-in boards and the System BIOS,
  49. bootstrap, BASIC and diagnostic ROMs.
  50.  
  51.    The memory space from 0B0000h through 0B7FFFh (32K) has been allocated to
  52. the MDA board and its clones and extensions, though the MDA itself only uses 4K
  53. of that (0B0000h through 0B0FFFh).  Likewise, the space from 0B8000h through
  54. 0BFFFFh (also 32K) has been allocated to the CGA and its clones and extensions,
  55. though the CGA itself only uses 16K of that (from 0B8000h through 0BBFFFh).
  56. The total memory space allocated to video, then, is 64K, from 0B0000h to
  57. 0BFFFFh.  Any video board that needs more than that must use some form of
  58. "bank-switching" or indirect memory access.
  59.  
  60.    The I/O space is another matter.  The MDA is allocated the I/O space from
  61. 03B0h through 03BFh (16 bytes) for its functions.  The CGA is allocated the I/O
  62. space from 03D0h through 03DFh (also 16 bytes) for its functions.  The EGA can
  63. somewhat simulate the CGA and MDA by using those spaces in a way somewhat
  64. similar (but not identical) to the way the CGA and MDA do.  It also uses the
  65. I/O space from 03C0h through 03CFh, giving it the total video I/O space from
  66. 03B0h through 03DFh (48 bytes).
  67.  
  68.    Both the MDA and the CGA contain ports for accessing the CRTC registers,
  69. plus a general control port and a general status port.  The CGA also contains a
  70. color port and two light pen ports, while the MDA contains three ports for
  71. controlling the on-board parallel printer interface (LPT1:).  I will not
  72. discuss the parallel printer interface ports in this series of articles.
  73.  
  74.    The last hexadecimal digit in the port address determines which port is
  75. being accessed.  The same hex digit denotes the same port on both the MDA and
  76. CGA, where they both have similar ports.  In such cases, I will use the
  77. notation "03?#h", where "#" is the port-identifying hex digit and "?" is "D"
  78. in the case of a CGA and "B" in the case of an MGA.  Where a port, or feature
  79. of a port, is unique to the CGA, I will use "03D#h".  In the case of uniqueness
  80. to the MDA, I will use "03B#h".
  81.  
  82.    The 16 ports for the MDA and CGA are as follows:
  83.  
  84. ^1   PORT         MDA NAME                CGA NAME
  85.  
  86. ^1   03?0h        Unused (03B4h phantom)  Unused (03D4h phantom)
  87. ^1   03?1h        Unused (03B5h phantom)  Unused (03D5h phantom)
  88. ^1   03?2h        Unused (03B4h phantom)  Unused (03D4h phantom)
  89. ^1   03?3h        Unused (03B5h phantom)  Unused (03D5h phantom)
  90. ^1   03?4h        6845 CRTC Index         6845 CRTC Index
  91. ^1   03?5h        6845 CRTC Data          6845 CRTC Data
  92. ^1   03?6h        Unused (03B4h phantom)  Unused (03D4h phantom)
  93. ^1   03?7h        Unused (03B5h phantom)  Unused (03D5h phantom)
  94. ^1   03?8h        MDA Control Port        CGA Control Port
  95. ^1   03?9h        Unused (Reserved)       CGA Color/Palette Port
  96. ^1   03?Ah        MDA Status Port         CGA Status Port
  97. ^1   03?Bh        Unused (Reserved)       CGA Light Pen Latch Clear
  98. ^1   03?Ch        Parallel Data Port      CGA Light Pen Latch Preset
  99. ^1   03?Dh        Parallel Status Port    Unused (Reserved?)
  100. ^1   03?Eh        Parallel Control Port   Unused (03D4 phantom?)
  101. ^1   03?Fh        Unused                  Unused (03D5 phantom?)
  102.  
  103.    As discussed last issue, port 03?4h is used to select which of the 18 CRTC
  104. registers (R0-R17) will appear at port 03?5h for reading and/or writing.  The
  105. ports labeled "phantom" act the same as 03?4h or 03?5h.  Thus, you could use
  106. 03D0h and 03D1h instead of 03D4h and 03D5h, but this is not recommended.  Many
  107. of the MDA/CGA enhancements co-opt these ports for their own uses.  The
  108. Plantronics ColorPLUS, for example, uses 03DDh, while the Genoa Spectrum and
  109. the ATI Graphics Solution uses both 03DDh (for Plantronics ColorPLUS emulation)
  110. and 03DEh (for their own functions, such as 132-column text).  See the
  111. instruction book with any enhanced board for details on its registers.
  112.  
  113.    For now, we will concentrate on the control (03?8h), color/palette (03D9h)
  114. and status (03?Ah) ports.  The control port allocates its 8 bits as follows:
  115.  
  116. ^1   BIT  VALUE   MDA USAGE (when set)    CGA USAGE (when set)
  117.  
  118. ^1    0       1   High Resolution (?)     80x25 Alphanumeric
  119. ^1    1       2   Unused                  320x200 Graphics
  120. ^1    2       4   Unused                  Color Burst Disable
  121. ^1    3       8   Video Enable            Video Enable
  122. ^1    4      16   Unused                  640x200 Graphics
  123. ^1    5      32   Blink Enable            Blink Enable
  124. ^1    6      64   Unused                  Unused
  125. ^1    7     128   Unused                  Unused
  126.  
  127.    The single most important bit in the control port is bit #3, the video
  128. enable signal.  If that bit is not set, then the screen will be BLANK, no
  129. matter what other bits or registers are set.  The primary use of this is to
  130. disable the video while radically changing the video display, so that a partial
  131. change will not damage the monitor.
  132.  
  133.    A useful one is bit #5, blink enable.  This, like bit #3, is normally set.
  134. When it is set, bit #7 (the most significant bit, or MSB) of the attribute
  135. bytes for each character will cause that character to blink.  When cleared, the
  136. MSB of the attribute byte will instead set the background intensity of the
  137. character cell.  On the MDA, this will allow you to have bold as well as dim
  138. inverse characters.  That is, the background will be bright instead of normal
  139. when inverted.  On the CGA, this will allow you to have 16 colors for text
  140. backgrounds as well as for the text characters themselves, all visible on the
  141. screen at once, instead of the usual 8 background colors.  Note that the BIOS
  142. clears this bit whenever it is called upon to scroll or clear the screen.  For
  143. screen displays that don't scroll, this capability is very useful.  It is an
  144. important part of the "formula" for making the CGA's "hidden" 160x100 16-color
  145. "low-res" graphics mode.  It also allows black text on a yellow background,
  146. which is scientifically proven to be the most readable color combination to the
  147. human eye.  Yellow cannot normally be a background color, since it is high-
  148. intensity.  Brown is its low-intensity analog.
  149.  
  150.    Bit #0 on the MDA is labeled "High Resolution Mode" in the IBM Personal
  151. Computer Technical Reference Manual for the IBM PC/XT, page 1-118.  However, I
  152. have not been able to get it to produce any discernable effect whatsoever.
  153. Thus the "(?)" in its description in my table above.  Of course it has a
  154. DEFINITE effect on the CGA.  It doubles the video output rate, thus allowing
  155. the 80x25 text display to be possible.  However, switching between 40 and 80
  156. column modes involves more than just this bit.  Several of the CRTC registers
  157. must also be changed.  This is one of those cases where it is wise to disable
  158. video first, make the changes, then re-enable video.
  159.  
  160.    Bit #2 on the CGA disables the color burst when set, or enables it when
  161. reset, allowing a sharper but black and white display on composite (VCR-
  162. compatible) monitors.  In particular, it removes the vertical striping effect
  163. caused by the presence of NTSC color information.  On RGB monitors, it has no
  164. effect in text or 640x200 hi-res modes, but it has a very useful effect on the
  165. 320x200 4-color medium-res mode:  it provides access to a third palette,
  166. providing red, cyan and white as foreground colors in addition to the two
  167. palettes mentioned in the IBM BASIC manuals!
  168.  
  169.    On the CGA, the graphics modes differ from the 40x25 text mode only in that
  170. the video information comes straight from memory rather than by way of the
  171. character generator ROM and by the vertical settings of the CRTC.  In
  172. particular, the CRTC is set up to provide 100 "character rows", each 2 scan
  173. lines high, instead of 25 character rows each 8 scan lines high.  Then bit #1
  174. is set to enable graphics, and bit #4 is set if hi-res (640x200) graphics is
  175. desired.  By setting bit #4 without also setting bit #1, a very strange effect
  176. is produced.  It seems to be similar to the "low-res" (160x100) mode, but not
  177. as controllable.
  178.  
  179.    That about covers the command register.  The color/palette register does not
  180. exist on the MDA.  Its bits on the CGA are as follows:
  181.  
  182. ^1   BIT  VALUE   CGA usage
  183.  
  184. ^1    0      1    BLUE bit of Special color.
  185. ^1    1      2    GREEN bit of Special color.
  186. ^1    2      4    RED bit of Special color.
  187. ^1    3      8    INTENSITY bit of Special color.
  188. ^1    4     16    Intensity of med-res graphics foreground or text background.
  189. ^1    5     32    Palette for 320x200 (med-res) graphics foreground.
  190. ^1    6     64    Unused.
  191. ^1    7    128    Unused.
  192.  
  193.    Bits 0-3 select one of 16 colors as the CGA "Special" color.  In text modes
  194. (and low-res 160x100 "graphics" mode which is actually a form of the 80-column
  195. text mode), this refers to the border color.  This is how you set the border
  196. color in text mode.  In medium-res 320x200 graphics mode, this refers instead
  197. to the common background color.  While the three foreground colors can only be
  198. selected from a few hard-wired palettes, the background can be any of 16
  199. colors, and this is what selects which color it is.  In high-res 640x200
  200. graphics mode, the background is always black.  The "Special" color bits
  201. instead set the foreground (drawing) color.  "But I thought 640x200 graphics
  202. mode was black & white only!" you say?  That is indeed what the IBM BASIC
  203. manual says.  But actually, you can have any of the 16 colors (but only one on
  204. the screen at a time) on a black background by using this register!
  205.  
  206.    Bit 4 selects the palette used by the 320x200 color graphics mode (with
  207. color burst on).  As you may know, in that mode you can have three foreground
  208. colors on one background color.  The background color can be any of the 16 CGA
  209. colors (selected by the Special Color bits 0-3 of this very register!), but the
  210. foreground colors are more limited.  In "color-burst on" mode, you can choose
  211. from red/green/brown, or magenta/cyan/light gray.  When bit 4 is reset you get
  212. the red/green/brown palette.  When set, you get the magenta/cyan/light gray
  213. palette.  Note that in the 320x200 "B&W" ("color-burst off") mode, this bit has
  214. no effect and the only palette consists of red/cyan/light Gray.  Bit 4 has
  215. another meaning in alphanumeric modes.  It is supposed to set the intensity of
  216. the background when you have "blink" enabled in the Control Port (03D8h, bit
  217. 5), but I have not been able to demonstrate this effect on any machine we have
  218. here.  We have no true CGAs, but we have several work-alikes on which all these
  219. other "tricks" work.  Also, one of my fellow employees has a true CGA at home,
  220. and he says it doesn't work there either.  The demo program included will
  221. attempt to demonstrate this.
  222.  
  223.    Bit 5 allows you to set the intensity of the three foreground colors in
  224. either version of the 320x200 medium-res graphics modes.  When reset, the
  225. colors are low-intensity.  When set, they are high-intensity.  Thus, instead of
  226. red/ green/brown, magenta/cyan/light gray and red/cyan/light gray, you get
  227. light red/ light green/yellow, light magenta/light cyan/white and light
  228. red/light cyan/ white.  Between bits 4 and 5, and the color-burst bit in the
  229. control port, you have 6 total palettes you can use in 320x200 medium-res
  230. graphics mode.
  231.  
  232.    So much for the color/palette register.  Now we come to the last register
  233. that is on both the MDA as well as the CGA -- the status register, at 03?Ah
  234. (03BAh for MDA, 03DAh for CGA).  Its bits are as follows:
  235.  
  236. ^1   Bit  Value   MDA Meaning             CGA Meaning
  237.  
  238. ^1    0      1    Horizontal Retrace      Horizontal Retrace
  239. ^1    1      2    Unused                  Light Pen Trigger Set
  240. ^1    2      4    Unused                  Light Pen Triggered
  241. ^1    3      8    Vertical Retrace        Vertical Retrace
  242.  
  243.  (Bits 4-7 are not used on either the MDA or CGA.)
  244.  
  245.    We will not discuss the CGA light pen in this article.  For now, we will
  246. concentrate on the retrace signals common to both boards.   When these are
  247. zero, the beam is in the process of scanning the visible portion of a line.
  248. This means that the display circuitry is accessing display RAM.  If the CPU
  249. also tries to access the display RAM at the same time, there is no problem
  250. EXCEPT ON THE CGA, IN 80x25 ALPHANUMERIC ("TEXT") MODE (and modes derived from
  251. it, such as the 160x100 16-color + border low-res pseudo-graphics mode)!
  252. Should such simultaneous access occur in the CGA 80x25 text mode, the 6845 will
  253. be trying to read memory during the same cycles that the CPU is.  The CPU, of
  254. course, has priority (to prevent system crashes), so the 6845 reads false data,
  255. usually all ones.  This causes a momentary "glitch" on the screen.  If this
  256. happens often enough to be really noticeable, the effect is called "digital
  257. snow" and is very distracting -- so much so that the BIOS scroll routines will
  258. prefer to turn the video off while scrolling, causing the "blink" so familiar
  259. to true CGA owners.  Believe me, the blink is preferrable to the blizzard!
  260.  
  261.    Scrolling is, of course, a mass-memory move.  But when doing more minor
  262. access to the display memory, it is not necessary to blank the screen each
  263. time.  Just wait until vertical blanking (Bit 3 set) and do your access.  If
  264. you are programming in assembly language ONLY and wish to have more access
  265. time, you can also use horizontal blanking (Bit 0 set).  Each horizontal
  266. blanking pulse lasts barely long enough to access ONE byte with a 4.77MHz 8088,
  267. however.  "Turbo" machines and "AT-class" machines have less of a problem here.
  268.  
  269.    The REAL solution, of course, is to have a faster video board that doesn't
  270. make like the Colorado ski season all over your screen.  Most CGA work-alikes
  271. have made this change, and the effect is VERY nice.  You appreciate it only
  272. after you have worked with a true IBM CGA or other "slow/snow" clone card.
  273.  
  274.    This concludes our discussion of the more important ports and registers of
  275. the CGA and MDA boards.  I have provided a demonstration program which will
  276. show off many of the effects I have discussed.  You can run it from here by
  277. simply pressing the [RETURN] ([─┘]) key.  ^1NOTE^N:  This demo works only on CGA
  278. and compatible adapters, and does ^1NOT^N work on an EGA or a PCjr.
  279.  
  280.    Next time I will discuss the BIOS, and how it makes living with the CGA and
  281. MDA a little easier.  Until then, happy viewing!
  282.