Wednesday, October 30, 2013

The PCjr. and CGA Compatibility

When IBM designed the PCjr., it based it on its pre-existing IBM PC Color/Graphics Display Adapter (CGA).  However, IBM did not design it in a way that it would be guaranteed to be backwards compatible with all CGA software, especially games.  This article will demonstrate the limitations of the PCjr. with CGA games.

There are four types of games of CGA games, first those that are not aware of the PCjr (Adventure in Serenia), second those that are aware of the PCjr. but do not use the enhanced graphics features of the PCjr. (M.U.L.E.), third those that are aware of the PCjr. and enhance the graphics in some way (Alley Cat), and fourth those that do not really work on the PCjr. (Microsoft Decathlon).  (Interestingly, all these games were released by IBM).  This article is only concerned with the first two types of games.

CGA and the PCjr. are fully compatible at the BIOS level, but only partially compatible at the register level.  The PCjr. can do everything that CGA can do at the hardware level, it just has to do some things very differently.  The CGA is a relatively simple device with eight registers :

Hex Address       Register Function
3D4                    6845 Index Register (to access 18 internal registers)
3D5                    6845 Data Register
3D8                    Mode Control Register
3D9                    Color Select Register
3DA                   Status Register
3DB                   Clear Light Pen Latch
3DC                   Preset Light Pen Latch

IBM implemented all these registers except for the 6-bit Mode Control and Color Select Registers.  There is nothing present at 3D8 and 3D9 in the PCjr.  The CGA and PCjr. have true Motorola MC6845 CRTCs.  The PCjr. also has a video gate array that acts as the graphics controller.

In addition, the graphics memory window with CGA, B8000-BBFFF will also be found with the PCjr., regardless of the amount of memory the PCjr. has (since it shares its video memory with the CPU).

1.  What works

Anything that access the BIOS will work correctly in either the IBM PC with CGA or PCjr.  The PC BIOS through Int 10H, offers several video functions.  All the video functions in the PC are present on the PCjr. Among the chief functions of BIOS Int 10H include setting the graphics modes.  IBM defined seven modes in the BIOS for CGA, 0-6, as shown below

Mode 0 - 40 column x 25 line Text Color/Black and White
Mode 1 - 40 column x 25 line Text Color/Color
Mode 2 - 80 column x 25 line Text Color/Black and White
Mode 3 - 80 column x 25 line Text Color/Color
Mode 4 - 320x200 Graphics 4-Color
Mode 5 - 320x200 Graphics 4-Color/Black and White
Mode 6 - 640x200 Graphics Black and White

On an RGB monitor, all modes except 6 are color capable through the BIOS.  On a color composite monitor or TV, only Modes 1, 3 and 4 are capable of color.  IBM preferred the black and white modes so that text would appear legible on a color composite monitor or TV.

Two other important functions that Int 10H provides include setting the palette to either green/red/brown or cyan/magenta/white and setting the background + border color in the 320x200 graphics modes and the border color in the text modes.  Even though the register write is the same, it will not set the foreground color in the 640x200 mode.

Additionally, those tweaked text modes, found in games like Round 42 (160x100) or ICON : Quest for the Ring (320x200), may also work because the program tweaks the registers of the Motorola MC6845 CRTC.  ICON has a PCjr. executable, and some games like Styx had a PCjr. specific version.

2.  What doesn't work

Since the Mode Control Register does not exist in the PCjr., a program must select the modes using the BIOS.  Any program writing to the Mode Control Register to change its mode will not work.  In addition, for text modes CGA uses bit 5 to turn blinking off and allow a text cell to select the 8 intense colors.  Finally, when bit 2 is 0 it turns on color for the color composite mode.  This is the way that color composite graphics are shown on CGA using the 640x200 mode and the bit is 0 by default in Modes 1, 3 and 4.

The Color Select Register also does not exist in the PCjr., so any program that uses the register to select colors will not work.  Color selection in CGA is limited as follows :

For text modes, bits 0-3 selects the border color.
For 320x200 graphics modes, bits 0-3 select the background and border color.
For 640x200 graphics mode, bits 0-3 select the foreground color (background and border color is always black, works with color composite graphics when bit 2 of the Mode Control register is 0)

None of those functions will work at all on the PCjr.

Bit 5 selects the 3-color palette in 320x200 Mode 4.  If the bit is 0, then the palette is green, red and brown.  If the bit is 1, the palette is cyan, magenta and white.  This is the default.  In Mode 5, this bit has no effect, the palette is always cyan, red and white.  The background color is the only color that is freely selectable in the 320x200 modes.  Since bit 5 is not implemented, any game that uses the Color Select Register to change the palette will show the cyan, magenta and white palette, even though that is not what was intended.  Also, the cyan, red and white palette will not appear, the default palette will be used.

Bit 4 determines whether the palette colors are in low or high intensity.  It works for all three palettes described above.  Thus green, red and brown becomes light green, light red, yellow; cyan, magenta and white become light cyan, light magenta and high intensity white; and cyan, red and white becomes light cyan, light red and high intensity white.  Since bit 4 is not implemented on the PCjr. games will only use the low intensity palettes.

Thus on CGA there are really six palettes available :

IBM PC CGA Mode 4 Palette 1 Low Intensity :

Ultima II - Revenge of the Enchantress
IBM PC CGA Mode 4 Palette 0 Low Intensity :

Digger
IBM PC CGA Mode 5 Palette 0/1 Low Intensity :

Donkey Kong
IBM PC CGA Mode 4 Palette 1 High Intensity :

Battlezone
IBM PC CGA Mode 4 Palette 0 High Intensity :

Shamus
IBM PC CGA Mode 5 Palette 0/1 High Intensity :

Tapper
On the PCjr., however, there are really only two palettes available for games that aren't PCjr. aware, if they work at all :

IBM PCjr. "CGA" Mode 4/5 Palette 1 :

Ultima II - Revenge of the Enchantress
IBM PCjr. "CGA" Mode 4/5 Palette 0 :

Shamus
Note that for PCjr. CGA Palette 1, cyan and magenta are the same as real CGA, but white has become high intensity white.  This is intentional and has been verified on real hardware.  Apparently IBM decided the original palette was not bright enough and so decided to brighten things up a bit.  For PCjr. CGA Palette 0, the intense palette is not available, even for games that intended to use it.  However, several games that used Palette 0 will use Palette 1 on the PCjr. because they used a register write instead of the BIOS function to set the palette.

However, in a 4-color mode, the PCjr. is not limited to the 78 possible combinations of the three preset colors and the background color.  Through its palette registers, the PCjr. can set each of the four colors to any color in the 16-color palette.  1,820 combinations become available.  Likewise, in a two color mode, the PCjr. can set the foreground and background colors independently, and the background color need not be black.  In addition, the PCjr. can set the border color independently in any mode, whereas the CGA can only set a unique border color in text modes.  Instead of only fifteen choices, 120 choices become available.

Even though Tandy copied the PCjr.'s video gate array and graphics capabilities, it restored the Mode Control and Color Select Registers giving it near perfect compatibility with any non-Tandy aware CGA program using the those registers.

No comments:

Post a Comment