Reply 40 of 58, by mkarcher
SoftCat wrote on 2025-12-27, 23:37:Tell me, is the CGA and Hercules always in word mode and bit 0 is always filled with zero?
Text mode and CGA compatible low-res graphics operate in word mode. There is no BIOS-supported Hercules-compatible mode, although the hardware should be capable of Hercules-compatible memory layout, so I will postpone Hercules for now. Text mode is required to be in word mode, because the EGA hardware needs to fetch the character byte (from plane 0) and the attribute byte (from plane 1) at the same time in on go. Planes 0 and 1 are used as 16-bit memory here. Two 8-bit reads would be too slow. As the character bytes for neighbouring characters are two bytes apart in the ISA memory space, and there is no capability of rotating the ISA address before it gets the VRAM address, the CRTC needs to run in word mode to match that. CGA low-res graphics also requires word mode, because this enables the fetching of 8 pixels at once. On the other hand, in CGA high-res graphics mode, the EGA card operates in byte mode and just uses plane 0, as you can see from the register tables in the EGA BIOS:
- In text modes and low-res CGA graphics modes (0..5), the second sequencer init byte (plane mask, goes to 3C4, index 2) is 003H, enabling planes 0 and 1, while in high-res CGA graphics mode (mode 6), the value is 001H, enabling just plane 0.
- In text modes and low-res graphics modes, the graphics controller mode register (sixth byte in the graphics controller block, goes to 3CE, index 5) has bit 4 set (010H in text modes, 030H in low-res CGA graphics modes), while it has bit 4 clear in mode 6 (000H). This bit configures internal operation of the graphics controller, which will at least cause the lowest bit of the read plane select register to be replaced by ISA A0, maybe it also has an effect on what happens to the latches.
- in text modes and low-res graphics modes, the "miscellaneous" register of the graphics controller has bit 1 set (seventh byte in the graphics controller block, goes to 3CE, index 6). The value is 00EH in text modes, 00FH in CGA low-res graphics modes and 000H in CGA high-res graphics mode. While it seems surprising that the graphics controller has two odd/even bits, their purpose is different. All bits of index 5 are handled by both 16-bit graphics controller (often called graphics controller A and graphics controller B) and configure the internal operation. On the other hand, index 6 is just a general-purpose output register, with the low two bits handled by graphics controller A and bits 2 and 3 handled by graphics controller B. You see an indication for this interpretation in the schematics, which names the pin "GP1" on graphics controller A, but calls the signal generated from it "CHAIN". The "CHAIN" signal enables the munging of ISA address bit 0 using dedicated TTL logic.
- The sequencer memory mode register of the sequencer (last sequencer byte, goes to 3C4, index 4) is 03H in text modes, 02H in low-res CGA graphics modes and 06H in CGA high-res graphics. Odd/even is controlled by bit 2 in this register (odd/even enabled if 0, odd/even disabled if 1). The purpose of this bit is to prevent /RAS1 and /RAS3 if the ISA address is even and to prevent /RAS0 and /RAS2 if the ISA address is odd, directing data to the correct planes for ISA writes in odd/even mode. This is the opposite of the purpose of the graphics controller mode register that directs data from the correct planes for ISA reads in odd/even mode.
Furthermore, we can observe that bit 1 of the sequencer memory mode register is always set, and that's the bit that allows access to banks 1 to 3 (256K mode). This means that B800:4000 (aka BC00:0000) will end up in bank 1 (the second bank), and thus you only get 4 pages of text in 80x25 modes on a 64K EGA card. If that bit were clear, B800:4000 will alias to bank 0 (so it will hit memory that is present on any EGA configuration), but only if the memory expansion module is not installed, the access will target address 0001 in bank 0. With the memory expansion module installed, the access would target address 0000 in bank 0 and alias to B800:0000. So for optimal text mode usage, it seems to make sense that this bit would be clear on 64K cards, but set if more memory is installed. Note that clearing this bit likely would not only make bank 0 show up at segment BC00, but also prevent access to the fonts stored in banks 1 to 3. On a 64K card, this wouldn't create any issue, as there is no bank 1 to 3, so there is no need to fetch fonts from them, but this shows yet another reason that this bits needs to be set to fully utilize the BIOS-advertised capabilities of a 256K EGA card.
So, the answer to your question (excluding Hercules for now) is that word mode is used in every CGA-compatible mode except high-res graphics. All CGA-compatible modes generate 8 pixels per video RAM access (one text mode character from a character/attribute pair, 8 4-color pixels from a word or 8 2-color pixels from a single byte). Now for "Hercules": If you actually mean mode 7 (MDA text) by that, it will also use word mode. On the other hand, if you think about a monochrome graphics mode with Hercules-type memory layout, it would most likely be implemented just like CGA mode 6 using byte mode.
On the other hand, you might also wonder whether you could use word mode in CGA mode 6 or a Hercules-compatible graphics mode, and as I understand it, the answer is actually: Yes, and you would need it for a Hercules-compatible graphics mode on a 64K EGA card. Mode 0Fh for 64K cards clearly shows that you can get 32K of linear video memory that way, and it is scanned out producing 16 pixels per video memory read. Note that this only works if the memory extension module is not installed, because only then ISA A14 is mapped to A0 in word mode, showing the "odd half of video meory" at A000:4000 (or B000:4000 for Hercules-type, or B800:4000 for CGA-type memory mapping). With a 256K EGA card and the 128K mapping, you could get that mode kind-of working, but instead of having the 4 Hercules "banks" at B000:0000, B000:2000, B000:4000 and B000:6000, they would appear at A000:0000, A000:2000, B000:0000 and B000:2000, which is not compatible to anything.
Not using word mode for CGA mode 6 on 64K cards seems like a lost opportunity! if you operate the card in 16-pixels-per-memory-read mode, you require only half as much memory reads for video scanout, and thus it seems you could use the 2:3 split between CRTC access to video memory instead of the 4:1 split. Typically, the 2:3 split (2 cycles to the CRTC, 3 cycles available for ISA access) is only used in 320-pixel modes, while the 4:1 split that provides twice the bandwidth to the CRTC is used in 640-pixel modes. This split type is selected using bit 1 of the sequencer clocking mode register (3C4, index 1), and you see that this bit is clear (high CRTC bandwidth) in modes 2,3,6,7, but set (high ISA bandwidth) in modes 0,1,4,5. Looking at the mode 0F/10 tables, IBM did not use the mode with low CRTC bandwidth for the 64K variant of the EGA card. At the moment, i don't know whether this is for technical reasons (i.e. the 2 cycles assigned to the CRTC does not match the timing pattern required to support 4-color graphics modes) or for political reasons, as running the sequencer in high-ISA-bandwidth mode on 64K cards in 4-color mode 10h, but running it in low-ISA-bandwidth mode on 256K cards may cause a notable performance loss in the EGA signature mode if the user upgrades from 64K to 256K, which is not something IBM likely wants their users to experience, even it is perfectly explainable that a 16-color mode leaves less drawing bandwidth to the CPU than a 4-color mode does. If the low-bandwidth mode actually works in 4-color mode 10h, it might have been a good idea to provide both the "fast 4-color mode" and the "slow 16-color mode" on 256K cards. But just as we discussed that the 720x350 (or 720x348) Hercules-type resolution is missing on EGA mono, while the card could perfectly provide it, it seems like IBM tried to limit mode proliferation by purposefully limiting the amount of video modes available.
By the way, that makes me wonder about VGA mode 11 (640x480 monochrome). That mode could be implemented in the 32-pixels-at-a-time mode (VGA only, not present on EGA) using doubleword mode (VGA only again), instead of byte mode only using plane 0, which would provide performance advantage because less bandwith is needed by the CRTC and also because early 16-bit ISA VGA cards only allowed 16-bit cycles in word and doubleword mode, but we likely should keep this tangent out of this thread...