VOGONS


EGA Questions

Topic actions

First post, by SoftCat

User metadata
Rank Member
Rank
Member

Is it possible to set 640x200 mode with at least two pages (4 or 2 colors) on an EGA graphics card with 64 KB of VRAM? If so, how exactly do I do this?
Will this mode work on EGA graphics cards with more VRAM? Will this mode work on original VGA graphics cards?

Reply 2 of 29, by vstrakh

User metadata
Rank Member
Rank
Member

Considering EGA uses 14.318MHz from the ISA slot and 16.257MHz from onboard oscillator - there's no reasonable ways to make 9MHz out of it with the tech of the period.
Maybe it's just blatant rounding, a figure of speech to say it's "faster than 8MHz"?
Or it's just someone's though train had derailed while writing that doc, because mode 0dh should have exactly same pixel clock as any other 320x200 mode.

Reply 3 of 29, by digger

User metadata
Rank Oldbie
Rank
Oldbie

Maybe something like it already exists, but would it be useful to create an EGA compatibility test tool that could verify the extent of EGA compatibility of (VGA) cards, including the many more undocumented and obscure features and corner cases that you mentioned?

Reply 4 of 29, by superfury

User metadata
Rank l33t++
Rank
l33t++

The EGA BIOS (which I have a source code copy of, don't remember from where) seems to interpret the switches in an odd way. From what I can see, it reads the dipswitches in reverse order from how the lookup table seems to expect them? So the four bits are read in reverse order, with misc output register set to bit 0's result being stored into bit 3, bit 2 into bit 1, bit 1 into bit 2 and bit 0 into bit 3.
Anyone knows why it's doing that?
Edit: I think it was from here.
I did find some encoding errors which required some "db" manual code injection to make it match the official bios though, at least on newer masm versions.
I think I documented that somewhere on this forum.

Author of the UniPCemu emulator.
UniPCemu Git repository
UniPCemu for Android, Windows, PSP, Vita and Switch on itch.io

Reply 5 of 29, by Jo22

User metadata
Rank l33t++
Rank
l33t++
digger wrote on 2025-12-21, 09:36:

Maybe something like it already exists, but would it be useful to create an EGA compatibility test tool that could verify the extent of EGA compatibility of (VGA) cards, including the many more undocumented and obscure features and corner cases that you mentioned?

That would be wonderful, an EGA version of the CGA Compatibility Tester! ^^

Because so far, I merely know of Commander Keen (such as Keen IV) and STS Orbit Plus which do trigger EGA compatibility issues on poor VGA cards.

The latter is an orbit prediction program that used to be popular in the 90s.
To predict when MIR or ISS are passing by above your home.
It was also useful to see when weather or ham satellites are in your range, so you can listen to them, receive data..

Anyway - In motion tracking mode (M key) it rotates the earth globe below the satellite, using an rarely used EGA mode (two video pages, 640x350 pels).
It calls it EGA "Dual-Page Mode", if memory serves.

Unfortunatelly, this EGA mode does rarely work correctly on emulators or modern VGA cards (DOSBox is fine).
On a cheap thin client I'm using, the screen goes black every time the program switches to the other video page.

That's why I'm using the normal orthographic mode (O key) most of time.
It does move the satellite, but rarely re-draws the globe.
It also doesn't switch modes (remains in 640x480 pels VGA mode).

"Time, it seems, doesn't flow. For some it's fast, for some it's slow.
In what to one race is no time at all, another race can rise and fall..." - The Minstrel

//My video channel//

Reply 6 of 29, by SoftCat

User metadata
Rank Member
Rank
Member
vstrakh wrote on 2025-12-21, 09:35:

Considering EGA uses 14.318MHz from the ISA slot and 16.257MHz from onboard oscillator - there's no reasonable ways to make 9MHz out of it with the tech of the period.
Maybe it's just blatant rounding, a figure of speech to say it's "faster than 8MHz"?
Or it's just someone's though train had derailed while writing that doc, because mode 0dh should have exactly same pixel clock as any other 320x200 mode.

On the EGA graphics card, in all 320x200 modes, the CRTC parameters correspond to a pixel frequency of 7.159 MHz.

Reply 7 of 29, by SoftCat

User metadata
Rank Member
Rank
Member
digger wrote on 2025-12-21, 09:36:

Maybe something like it already exists, but would it be useful to create an EGA compatibility test tool that could verify the extent of EGA compatibility of (VGA) cards, including the many more undocumented and obscure features and corner cases that you mentioned?

Yes, I thought about that too.

Reply 8 of 29, by SoftCat

User metadata
Rank Member
Rank
Member
superfury wrote on 2025-12-21, 11:00:
The EGA BIOS (which I have a source code copy of, don't remember from where) seems to interpret the switches in an odd way. From […]
Show full quote

The EGA BIOS (which I have a source code copy of, don't remember from where) seems to interpret the switches in an odd way. From what I can see, it reads the dipswitches in reverse order from how the lookup table seems to expect them? So the four bits are read in reverse order, with misc output register set to bit 0's result being stored into bit 3, bit 2 into bit 1, bit 1 into bit 2 and bit 0 into bit 3.
Anyone knows why it's doing that?
Edit: I think it was from here.
I did find some encoding errors which required some "db" manual code injection to make it match the official bios though, at least on newer masm versions.
I think I documented that somewhere on this forum.

The EGA BIOS listing is here at the end.
https://drive.google.com/file/d/1WouBG1qGe9Eh … iew?usp=sharing

Reply 9 of 29, by SoftCat

User metadata
Rank Member
Rank
Member
Jo22 wrote on 2025-12-21, 11:34:
That would be wonderful, an EGA version of the CGA Compatibility Tester! ^^ […]
Show full quote

That would be wonderful, an EGA version of the CGA Compatibility Tester! ^^

Because so far, I merely know of Commander Keen (such as Keen IV) and STS Orbit Plus which do trigger EGA compatibility issues on poor VGA cards.

The latter is an orbit prediction program that used to be popular in the 90s.
To predict when MIR or ISS are passing by above your home.
It was also useful to see when weather or ham satellites are in your range, so you can listen to them, receive data..

Anyway - In motion tracking mode (M key) it rotates the earth globe below the satellite, using an rarely used EGA mode (two video pages, 640x350 pels).
It calls it EGA "Dual-Page Mode", if memory serves.

Unfortunatelly, this EGA mode does rarely work correctly on emulators or modern VGA cards (DOSBox is fine).
On a cheap thin client I'm using, the screen goes black every time the program switches to the other video page.

That's why I'm using the normal orthographic mode (O key) most of time.
It does move the satellite, but rarely re-draws the globe.
It also doesn't switch modes (remains in 640x480 pels VGA mode).

Thank you for the link to STS Orbit Plus and the mention of EGA "Dual-Page Mode".

Reply 10 of 29, by GloriousCow

User metadata
Rank Oldbie
Rank
Oldbie
superfury wrote on 2025-12-21, 11:00:

The EGA BIOS (which I have a source code copy of, don't remember from where) seems to interpret the switches in an odd way. From what I can see, it reads the dipswitches in reverse order from how the lookup table seems to expect them? So the four bits are read in reverse order, with misc output register set to bit 0's result being stored into bit 3, bit 2 into bit 1, bit 1 into bit 2 and bit 0 into bit 3.
Anyone knows why it's doing that?

Due to the orientation of the DIP switch and the 74LS153 multiplexer that reads them, it just worked out that was the simplest way to wire them up.

The attachment ega_dip_trace.png is no longer available

MartyPC: A cycle-accurate IBM PC/XT emulator | https://github.com/dbalsom/martypc

Reply 11 of 29, by GloriousCow

User metadata
Rank Oldbie
Rank
Oldbie
SoftCat wrote on 2025-12-21, 00:25:

Here on page 20 (in the PDF it's page 24) for bit 3 it says: "9 MHz for mode D". How can that be the frequency for mode D?
https://drive.google.com/file/d/1WouBG1qGe9Eh … iew?usp=sharing

i have no idea what that was in reference to but IBM technical reference are somewhat notorious for mistakes

the Compaq EGA reference is quite good though
https://archive.org/details/trg-enhanced-colo … s-board-1986-12

MartyPC: A cycle-accurate IBM PC/XT emulator | https://github.com/dbalsom/martypc

Reply 14 of 29, by superfury

User metadata
Rank l33t++
Rank
l33t++

I've read through the Compaq EGA reference and eventually found Figure 5-9 on page BIOS 5-51.
It literally lists BDA 40:88 bits 0-3 as:
0001: MDA/Mono secondary EGA(80)/RGBI
1000: CECG(x200)/RrGgBb secondary MDA/Mono
If the bits were truly read inversed, this wouldn't be true? So the bits shouldn't be read inversed on EGA?

Author of the UniPCemu emulator.
UniPCemu Git repository
UniPCemu for Android, Windows, PSP, Vita and Switch on itch.io

Reply 15 of 29, by SoftCat

User metadata
Rank Member
Rank
Member
superfury wrote on 2025-12-23, 05:24:
I've read through the Compaq EGA reference and eventually found Figure 5-9 on page BIOS 5-51. It literally lists BDA 40:88 bits […]
Show full quote

I've read through the Compaq EGA reference and eventually found Figure 5-9 on page BIOS 5-51.
It literally lists BDA 40:88 bits 0-3 as:
0001: MDA/Mono secondary EGA(80)/RGBI
1000: CECG(x200)/RrGgBb secondary MDA/Mono
If the bits were truly read inversed, this wouldn't be true? So the bits shouldn't be read inversed on EGA?

It's just better to check this code on a real EGA card.


....................................................

INFO_3 DB ?

; INFO_3
; D7-D4 FEATURE BITS
; D3-D0 SWITCHES

....................................................

MISC_OUTPUT EQU 0C2H
IN_STAT_0 EQU 0C2H

....................................................

;----- POST FOR COMBO VIDEO CARD

MOV INFO,00000100B
CALL RD_SWS
MOV INFO_3,BL
CALL F_BTS
OR INFO_3,AL
MOV BL,INFO_3
CALL MK_ENV
JMP POST
SKIP:
RET
VIDEO_SETUP ENDP


POR_1 PROC NEAR
OUT DX,AL
PUSH AX
POP AX
IN AL,DX
AND AL,010H
SHR AL,1
RET
POR_1 ENDP

;----- READ THE SWITCH SETTINGS ON THE CARD

RD_SWS PROC NEAR
ASSUME DS:ABS0
MOV DH,3
MOV DL,MISC_OUTPUT
MOV AL,1
OUT DX,AL

;----- COULD BE 0,4,8,C

MOV AL,0DH
CALL POR_1
SHR AL,1
SHR AL,1
SHR AL,1
MOV BL,AL

MOV AL,9
Show last 45 lines
	CALL	POR_1
SHR AL,1
SHR AL,1
OR BL,AL

MOV AL,5
CALL POR_1
SHR AL,1
OR BL,AL

MOV AL,1
CALL POR_1
OR BL,AL

AND BL,0FH
RET
RD_SWS ENDP

;----- OBTAIN THE FEATURE BITS FROM DAUGHTER CARD

F_BTS PROC NEAR
MOV DH,3
MOV DL,0BAH
MOV AL,1
OUT DX,AL
MOV DL,0DAH
OUT DX,AL
MOV DL,IN_STAT_0
IN AL,DX ; READ FEATURE BITS
AND AL,060H
SHR AL,1
MOV BL,AL
MOV DL,0BAH
MOV AL,2
OUT DX,AL
MOV DL,0DAH
OUT DX,AL
MOV DL,IN_STAT_0
IN AL,DX ; READ FEATURE BITS
AND AL,060H
SHL AL,1
OR AL,BL
RET
F_BTS ENDP

Reply 16 of 29, by GloriousCow

User metadata
Rank Oldbie
Rank
Oldbie
superfury wrote on 2025-12-23, 05:24:

If the bits were truly read inversed, this wouldn't be true? So the bits shouldn't be read inversed on EGA?

There's no reason to jump to that conclusion. The switches can be read in one order and written to the BDA in different order.

MartyPC: A cycle-accurate IBM PC/XT emulator | https://github.com/dbalsom/martypc

Reply 17 of 29, by superfury

User metadata
Rank l33t++
Rank
l33t++
GloriousCow wrote on 2025-12-23, 19:19:
superfury wrote on 2025-12-23, 05:24:

If the bits were truly read inversed, this wouldn't be true? So the bits shouldn't be read inversed on EGA?

There's no reason to jump to that conclusion. The switches can be read in one order and written to the BDA in different order.

Just read the above code. Bits 2,3 are the used dipswitches to read.
Bit 4 from the read is the bit containing the result.
Thus:
switch 11b(3) bit 3 shr 3=>bit 0(=>BL)
switch 10b(2) bit 3 shr 2=>bit 1(=>BL)
switch 01b(1) bit 3 shr 1 =>bit 2(=>BL)
switch 00b(0) bit 3 shr 0=>bit 3(=>BL)
The resulting BL is anded with 0xF(filtering out upper bits) and then stored into address 488h I think I can remember. Which is documented to be having a SW1 order there, thus the conclusion.
It's definition is:
Bit 0=SW1(1=off)
Bit 1=SW2
Bit 2=SW3
Bit 3=SW4

Author of the UniPCemu emulator.
UniPCemu Git repository
UniPCemu for Android, Windows, PSP, Vita and Switch on itch.io

Reply 18 of 29, by SoftCat

User metadata
Rank Member
Rank
Member
mkarcher wrote on 2025-12-16, 22:53:

While I previously claimed that the bit likely exists, I'm actually unsure whether you can have the CRTC address counter wrap around at 16K (the CRTC address counter counts 32-bit units of video RAM, so 16K in that counter is 64KB of RAM). I will check documentation and report back what I find.

The easiest way to do it is like this.

mov ax,40h
mov es,ax
and byte ptr es:[87h],9Fh
mov ax,0Eh
int 10h
.....

Reply 19 of 29, by superfury

User metadata
Rank l33t++
Rank
l33t++

Those bits are literally written to the BDA as-is, combined with the 4 bits (shifted left) of the F_BTS function.
That literally is the source code (decompiled I think, but not sure) of the EGA BIOS itself that SoftCat posted.
The only issue with the source code is a newer MASM versions compiling slightly different on one instruction (requiring manual db bytes for the encoding there to 100% match the binary file gotten from minuszerodegrees, for example).

the MK_ENV literally stores it at said BDA address, nothing more (from BL).

Also interesting to note is, that when I compare the values ending up in the BDA (from said MK_ENV call) when the switches are in inversed order on the graphics card, that the "monochrome" bits (switch 3 open and others closed) actually matches the VGA documented 0010b that's documented to appear there on VGA monochrome monitors (reported by grounding just the ID1 pin). Seeing as the VGA is supposed to be EGA-compatible, it looks like the EGA indeed flips the switch numbers (or wiring them inversed).

One nice thing about the publicly avaiable disassembly of the EGA BIOS is that I can create a mapping file with all the addresses of the instructions, thus allowing me to set breakpoints at specific addresses I'm interested in while debugging the EGA POST.

Author of the UniPCemu emulator.
UniPCemu Git repository
UniPCemu for Android, Windows, PSP, Vita and Switch on itch.io