Introduction

Welcome to “The PC Emulation Book.”

This document aims to become a comprehensive guide to emulating the original models of the IBM Personal Computer:

  • The IBM Model 5150 Personal Computer
  • The IBM Model 5160 Personal Computer XT

When we refer to the original “IBM PC”, we are technically referring to the IBM Model 5150. However, the slightly improved IBM Model 5160 (otherwise known as the IBM XT) is similar enough in design and function that they are often lumped together. In this book, we will refer to the 5160 or XT interchangably, when a distinction between the PC and XT is important. Otherwise, consider any reference to the “IBM PC” as referring to either model.

🚧 UNDER CONSTRUCTION! 🚧

You’ll notice that many of the pages in this book are empty stubs. Content is still being fleshed out. Here is a list of some of the more complete pages:

Why Emulate the PC?

The IBM PC is arguably one of the most influential computers in history, establishing standards that enabled the proliferation of “PC-compatible” systems and cemented the very term “PC” as an Intel-based system, probably running a Microsoft operating system. The “PC” lives on even today, only recently challenged for supremacy by the rise of ARM-based CPUs.

The PC was an open and well-documented system. IBM published full schematics and commented BIOS source code listings, allowing anyone to understand in great detail how the system operated, even without owning the physical hardware.

There are thousands of software titles to explore on a PC emulator, although the PC’s limited graphics and sound capabilities make many of the games for the platform less than spectacular. Still, there are some classic titles that are still fun to play today, such as AlleyCat and Digger.

If you’re up for a challenge, recently several demos have been released that push the original PC hardware to its utter limits and require cycle-exact emulation of the 5150 and its components. These demos include 8088 MPH, released in 2015, and Area 5150, released in 2022.

Even without any attempt at cycle-accuracy, the PC can be emulated with a respectable level of compatibility.

What You’ll Learn

This book aims to cover the complete process of building a PC emulator from the ground up, including:

  • Hardware Architecture: Understanding the IBM PC’s system design and component interactions
  • CPU Emulation: Implementing the Intel 8088 processor
  • Support Chips: Emulating the various Intel support chips that made the PC work
  • Peripheral Devices: Implementing keyboards, displays, storage, and other I/O devices
  • System Integration: Bringing all components together into a working emulator

Target Audience

This book is intended for emulator authors, but retro-developers may find it a useful reference as well, or anyone simply curious about how classic computers of the era worked.

Prerequisites

To get the most out of this book, you should have:

  • A basic understanding of computer architecture concepts
  • Familiarity with a high-performance programming language (C, C++, Rust, or similar)
  • Basic understanding of digital logic
  • Some experience with emulation
    • If you have never programmed an emulator before, it is recommended that you start with the CHIP-8, a simple system that teaches basic emulation concepts. You can find a guide here.

License

This book is open-source and all content is licensed under the CC0 1.0 Creative Commons Public Domain license, except where otherwise noted.

Contributing

The main source repository for the PC Emulation Book can be found here.

IBM PC/XT Architecture Overview

The design of the original IBM 5150 reflected IBM’s project requirements to create a low-cost, maintainable system largely comprised of off-the-shelf parts, yet capable of being expanded. They succeeded in that effort far beyond any conceivable expectations - the IBM PC is now recognized as the ancestor of a line of “PC Compatible” systems that continue to be sold to this day.

CPU

IBM chose the Intel 8088 for the 5150, which is also used in the 5160. The 8088 was a lower-cost variant of the 8086 CPU. While still 16-bit internally, the 8088 only had an 8-bit data bus. This simplified the PC’s motherboard design, and made it easy to build a system around Intel’s various 8-bit peripheral chips.

The 8088 has 20 address lines, allowing it to address \(2^{20}\) bytes, or 1MB.

IBM chose to reserve addresses above 0xA0000, leading to the infamous “640KB” memory limit that is often mistakenly blamed on Microsoft.

Expansion Bus

The 8-bit data bus of the 8088 would also dictate the 8-bit data width of the system’s expansion bus. This bus would later be expanded to 16-bits with the IBM 5170 AT, and would later be dubbed the ISA bus by Compaq1 and a growing consortium of PC clone manufacturers.

System Clock

The 5150 has a single main system crystal with a frequency of 14.31818MHz. This frequency is exactly four times the NTSC color subcarrier frequency.

The crystal frequency can be expressed as a fraction:

$$f_{crystal} = \frac{315}{22} \text{ MHz} = 14.318181\overline{81} \text{ MHz}$$

This choice was likely made due to the low cost of NTSC-derived clock crystals, as they were being manufactured by the millions to be used in television sets. It also made the PC more easily compatible with North American television sets, making low-cost display option available to PC owners. It also allowed the IBM Color Graphics Adapter to omit a separate crystal.

The CPU frequency of 4.77 MHz is obtained by dividing the system clock by 3:

$$\frac{14.3181818}{3} = 4.773MHz$$

The 8088 was rated for 5MHz operation2, so this represents about a 5% underclock.


References


  1. wikipedia.org Industry Standard Architecture.

  2. Intel Corporation. 8088 8-Bit Hmos Microprocessor. Intel Corporation, August 1990. Document Number: 231456-006. Available at: Intel 8088 Data Sheet PDF

Intel 8088 CPU

Architecture and Registers

Instruction Set and Execution

Bus Interface and Timing

Intel 8259 Programmable Interrupt Controller

The Intel 8259 Programmable Interrupt Controller (PIC) plays an essential role in the operation of much of the hardware of the IBM PC. The PIC can be thought of as an expansion unit to the 8088’s single INTR pin, allowing 8 separate interrupt sources to be handled in a prioritized manner.

The PIC is a surprisingly challenging chip to emulate correctly, partially due to some ambiguities in its documentation.

Overview

The 8 inputs of the PIC are called Interrupt Request lines, which are often referred to as IRQs (Interrupt reQuest).

The PIC has three main 8-bit registers. Each bit in these registers corresponds to an IRQ with the least significant bit mapping to IRQ 0 and the most significant bit mapping to IRQ 7.

  • Interrupt Request Register (IRR): This register holds bits reflecting the IRQ lines that are requesting service.
  • Interrupt Mask Register (IMR): A 1 bit set in this register prevents the corresponding IRQ line from being serviced.
  • In-Service Register (ISR): A 1 bit set in this register indicates that the corresponding IRQ has been acknowledged by the CPU and is now “in-service”.

The 8 IRQs of the PIC are ordered in terms of priority, with IRQ 0 being the highest priority, and IRQ 7 being the lowest priority. This means that if IRQ 0 and IRQ 1 occur simultaneously, IRQ 0 will be serviced first.

This also means that it is possible for a higher priority interrupt to be serviced while a lower priority interrupt is already in service. Normally, the 8088 clears the I flag when executing an interrupt. If a programmer desires their interrupt service routine to be reentrant, they would need to issue an STI instruction to allow this to occur.

IBM PC PIC Configuration

IRQ Assignments

The IBM PC maps devices to the 8259’s IRQ lines as follows. Some of these connections are direct traces on the motherboard, other IRQs are connected to the ISA bus. In some cases, a peripheral card may have had a jumper to allow selection of a particular IRQ.

IRQConnectionDevice
IRQ 0DirectSystem Timer
IRQ 1DirectKeyboard Controller
IRQ 2ISA/DirectVsync Interrupt (EGA) or Secondary 8259 (AT)
IRQ 3ISASerial Port - COM2
IRQ 4ISASerial Port - COM1
IRQ 5ISAHard Disk Controller or LPT2
IRQ 6ISAFloppy Disk Controller
IRQ 7ISAParallel Port - LPT1

I/O Ports

The 8259 has a single address pin, A0, via which one of two registers can be selected. The two registers are decoded by the PC at the following addresses:

PC Port8259 PortRWDescription
0x200RWCommand/Status Register
0x211RWData/Mask Register

The Unimportant Stuff

The 8259 was designed to be compatible not only with the 8088 and 8086, but with Intel’s earlier CPUs, the 8080 and 8085. There are various mode flag bits that control whether the 8259 should expect to be paired with an 8088 or not - obviously, on the IBM PC, you can expect these bits to be set properly, and emulation of the 8080 modes is certainly not required.

The 8259 supported daisy-chaining of additional 8259 chips to enable more interrupt sources to be handled - something that Intel called cascading. This was not used on the IBM PC, which only had a single 8259. Two 8259s were employed on the IBM 5170 AT in a primary/secondary configuration. Obviously this is something you do not need to emulate either.

The PIC can be operated in edge-triggered or level-triggered mode. The IBM PC exclusively operates in edge-triggered mode, but implementing level-triggered mode is fairly trivial to do.

There are additional features like priority rotation and special mask mode which are not used by the IBM PC.

Interrupt Processing Logic

The important thing to understand about the PIC is that it is implemented as an array of 8 priority cell circuits. The IRR, IMR, and ISR “registers” are simply latches within each priority cell. This means that a good part of the interrupt evaluation logic happens continuously, since it is simply driven by immediate state of the circuit. The PIC has no clock input, so all it can do is respond to changes of its input pins. With one exception - but we’ll talk about that later.

Let’s look at an example of interrupt logic flow:

The Simple Version

  1. A device raises its IRQ line connected to the PIC.
  2. The PIC looks to see if that IRQ is masked off in the IMR, if it is already in service, or if a higher-priority interrupt is in service, in which case the interrupt cannot be serviced at the moment.
  3. If the IRQ can be serviced, the PIC raises the INTR line to the CPU.
  4. The CPU acknowledges the interrupt and the PIC sets the corresponding bit in the ISR to indicate that the interrupt is now in service. The corresponding bit in the IRR is cleared to indicate the IRQ is no longer requesting service.
  5. The CPU executes the interrupt based on the 8-bit vector the PIC provides in response to the CPU’s interrupt acknowledgement.
  6. The interrupt service routine executes. When it is done, it sends an End-of-Interrupt (EOI) command to the PIC.
  7. The PIC clears the corresponding bit in the ISR indicating that the interrupt has completed servicing.

The original IRQ line may remain high at this point, but in the PC’s standard edge-triggered mode it will not be serviced again until it transitions low and then high again.

The Detailed Version

  1. A device raises its IRQ line connected to the PIC.
  2. The low-to-high transition of the IRQ line sets the IRQ’s edge latch and sets the corresponding bit in the IRR.
    1. If the corresponding bit in the IMR is set, the signal from the IRR does not propagate further.
    2. If the corresponding bit in the IMR is clear, the signal from the IRR reaches the Priority Resolver.
  3. The priority resolver checks to see if the corresponding bit in the ISR is set, or if any bits lower than the corresponding bit are set, indicating a higher priority interrupt is already in service.
    1. If any of these bits are set, nothing further happens for the moment.
    2. If none of these bits are set, the priority resolver will instruct the control logic to raise the PIC’s INTR pin, which is connected to the CPU.
  4. The CPU finishes an instruction, at which point it samples the INTR pin.
  5. The CPU notices INTR is high.
    1. If the CPU’s I flag is cleared, it ignores INTR being high and continues execution as normal.
  6. The CPU begins to acknowledge the interrupt.
    1. The CPU issues one bus cycle with the INTA bus status encoded.
    2. The CPU bus controller decodes the INTA bus status and asserts the physical \(\overline{INTA}\) pin.
  7. The PIC detects the \(\overline{INTA}\) pin going high.
    1. The priority resolver sets the highest-priority bit in the ISR to indicate that the interrupt is entering service.
    2. In edge-triggered mode, the priority resolver clears the corresponding bit in the IRR.
    • This is the only difference between edge-triggered mode and level-triggered mode.
    1. The control logic asserts the internal \(\overline{FREEZE}\) signal. This prevents any change to any bit in the IRR while the interrupt acknowledge process is active.
  8. The \(\overline{INTA}\) pin goes low as the CPU completes the INTA bus cycle.
  9. The \(\overline{INTA}\) pin goes high again as the CPU issues a second INTA bus cycle.
  10. The PIC emits the 8-bit interrupt vector which the CPU reads during the second INTA bus cycle.
  11. The \(\overline{INTA}\) pin goes low as the CPU completes the second INTA bus cycle.
    1. The control logic de-asserts the \(\overline{FREEZE}\) signal, allowing the IRR to update again.
    2. In auto-EOI mode, the priority resolver clears the corresponding ISR bit.
  12. The CPU uses the interrupt vector received from the PIC to look up a far pointer to the correct Interrupt Service Routine from the Interrupt Vector Table.
  13. The CPU clears the I and T flags, then jumps to the interrupt service routine.
  14. At the end of the interrupt service routine, the routine sends an EOI command to the PIC.
  15. The PIC clears the appropriate bit in the ISR to indicate that the interrupt has completed servicing.

The Intel 8253 Programmable Interval Timer

The 8253 Programmable Interval Timer (PIT) is responsible for a number of tasks on the IBM PC. It maintains the system time, drives DRAM refresh, and controls the PC speaker to generate sound.

Overview

The PIT contains three independently operating 16-bit counters or ‘channels’, each capable of operating in different modes.

Physically, each timer channel is assigned a clock input, a gate pin, and an output pin (OUT). The gate pin can be used to control or disable counting in specific modes.

Counters are operated by first configuring them by writing a Control Word to the 8253’s Control Word Register. Then, an initial count - often referred to as a ‘reload value’ - is written directly to the timer channel port. A counter has a full 16-bit range, as an initial count of 0 is treated as a count of 65,536 in binary mode or \(10^4\) in BCD mode.

Once configured and running, on each tick of the channel’s clock input, the channel’s internal Counting Element decrements. When the counter reaches 0 (or 1 in some modes), some specific behavior will be triggered (depending on mode), usually changing the state of the channel’s output pin.

The current value of a counter channel can be read at any time by reading from the channel’s specified port.

Pinout

A diagram showing the physical pinout of the Intel 8253 Programmable Interrupt Timer

Figure 1: Intel 8253 Pinout

The 8253 has an 8-bit data bus by which you read and write the chip’s registers, which are selected by the A0 and A1 pins.

IBM PC Timer Configuration

The 8253 has three independent clock input pins, allowing each counter to be driven at a different frequency. The IBM PC ties all three clock inputs to the same clock line, which runs at the system crystal frequency divided by 12.

$$f_{timer} = \frac{\frac{315}{22}}{12} \text{ MHz} = 1.19318\overline{18} \text{ MHz}$$

Note: Other systems that use the 8253 can connect these timer clock inputs in different ways - even connecting one timer channel output to the clock input of another to act as a clock divisor.

TimerPurposeFrequencyConnection
Timer 0System Timer18.2 HzSystem Timer Interrupt
Timer 1DRAM Refresh15 μsDMA Controller for memory refresh
Timer 2SpeakerVariablePC Speaker output

Timer 0

Timer 0’s OUT pin is directly connected to the IR0 pin of the 8259A Programmable Interrupt Controller. When the Timer 0 OUT pin has a low-to-high transition, this will trigger an IRQ0. This causes an interrupt 8, which normally is configured to maintain the system’s time of day clock by the BIOS.

The BIOS initializes Timer 0 to a reload value of 0 (65,536)

$$ T = \frac{65536}{1.19318\overline{18}\times 10^{6}} \approx 0.0549254\ \text{s} $$

$$ T \approx 54.93\ \text{ms} $$

$$ \frac{1\text{s}}{54.93\text{ms}} \approx 18.2Hz $$

This will cause an Interrupt 8 to execute 18.2 times per second.

Many applications, especially games, will use Timer 0 for their own purposes, and so the time of day clock was notoriously inaccurate without being synchronized to a realtime clock module.

Timer 0’s GATE pin is tied to +5v.

Timer 1

Timer 1’s OUT pin connects to a 74LS74 flip-flop which latches its output. The output of this flip flop is connected to the DRQ0 pin of the 8237 DMA Controller, and is reset by the \(\overline{\text{DACK0}}\) signal. This causes one DMA transfer to occur in read mode, which refreshes the system’s DRAM.

The BIOS initializes Timer 1 to a reload value of 18:

$$ T = \frac{18}{1.19318\overline{18}\times 10^{6}} \approx 0.0000151\ \text{s} $$

$$ T \approx 15.1\ \text{μs} $$

$$ \frac{1\text{s}}{15.1\times 10^{-6}\text{s}} \approx 66.2\text{KHz} $$

This will cause a DMA refresh request approximately every 15 microseconds, or every 72 clock cycles. If this sounds like a lot, it is. The DRAM refresh process robs the 8088 of about 5-6% of its performance, depending on bus activity.

Note: You can ignore this channel if you are not interested in cycle-accuracy. However, the IBM PC BIOS does check that Timer 1 is running by checking that the DMA channel 0 is counting. You can hack your way around this test by just making the DMA channel 0 count on read.

Timer 1’s GATE pin is tied to +5v.

Timer 2

Timer 2’s OUT pin connects to the PC’s speaker and cassette interface circuitry. Timer 2 is typically configured to produce square waves to drive the speaker to play notes of specific frequencies, and Timer 2’s GATE input can be used to silence the speaker when desired.

For more details, see the PC Speaker chapter.

Timer 2’s GATE pin is tied to the 8255 PPI’s Port B, Bit 0 (Pin #18).

I/O Ports

The 8253 has two address lines, A0 and A1, which allow selection of four ports. These four ports are decoded by the PC at the following addresses:

PC Port8253 PortRWDescription
0x400RWTimer 0 Count Register
0x411RWTimer 1 Count Register
0x422RWTimer 2 Count Register
0x433WControl Word Register

Control Word Format

The 8253’s control word can be written to at port 0x43 and is used to configure one of the three counters, each of which can be configured with different modes.

An breakdown of the format of the Intel 8253 Control Word

Figure 2: Intel 8253 Control Word Format

The specified channel’s counting mode, IO mode, and whether or not it should count in BCD, is configured with a single 8-bit write. Note that using 0b11 as the timer selection is invalid on the 8253. On the 8254, it selects the read-back command, which will not be covered here.

Counter Channel Configuration

Binary vs BCD Mode

A timer channel can be configured to count in either binary or Binary Coded Decimal (BCD) mode. I have not seen any software that actually uses BCD mode. When writing your initial 8253 implementation, you can probably ignore BCD mode.

RW Mode

A timer channel can be configured for 16-bit read/writes in LSBMSB mode using 0b11 in the RW field, or in one of two 8-bit read/write modes:

  • LSB (0b01):
    • On write, an 8-bit value is used to initialize the \(\text{CR}_l\) register, which holds the least significant 8 bits of the initial 16-bit count.
    • On read, the contents of the \(\text{O}_l\) register are returned. See Counter Channel Operation.
  • MSB (0b10):
    • On write, an 8-bit value is used to initialize the \(\text{CR}_m\) register, which holds the most significant 8 bits of the initial 16-bit count.
    • On read, the contents of the \(\text{O}_m\) register are returned. See Counter Channel Operation.

The 8-bit RW modes allow programming a timer channel with fewer writes. In MSB mode, the full range of a timer channel is available, with reduced granularity.

Note: The RW mode of a channel does not affect its basic counting operation. It remains a full 16-bit counter internally regardless of input mode.

In LSBMSB mode, it takes two 8-bit writes to read or write to the timer channel. An internal latch keeps track of whether the initial LSB has been written. On a write, the first byte written is used to initialize the \(\text{CR}_l\) register. The second byte initializes the \(\text{CR}_m\) register. On a read, the first read returns the \(\text{O}_l\) register, the second read returns the \(\text{O}_m\) register.

Warning: The 8253 cannot handle interleaved 16-bit read and write operations. In LSBMSB mode if you write one byte and then read one byte without completing the write operation, you will receive random data. Some software has been observed improperly operating the 8253 in this way, especially software designed for the 8254 which did not have this limitation. Ensure that your 8253 can recover in this scenario - what value you decide to return is up to you - the actual value is nondeterministic “open bus” behavior internal to the chip.

Counter Latch Command

There is a small matter of concern when a channel is configured for LSBMSB mode. Since it takes two bytes to read the full 16-bit counter value, it is possible that the counter can decrement between the time the first byte is read and the second. Therefore, a Counter Latch command is provided. The Counter Latch command is sent by setting the RW field of the control word to 0b00. This does not change the counter channel’s configuration otherwise - the Mode and BCD bits are ignored when sending the counter latch command. See the Counter Latch Operation section below for how the latching is implemented.

Counter Channel Operation

Intel 8253 counter block diagram showing the organization of various registers that comprise a counter unit and their connections to each other and the 8253's internal bus.

Figure 3: Intel 8253 Counter Block Diagram

There are a few important things to note in the channel block diagram above. The heart of the counter is the Counting Element (CE). This is a 16-bit synchronous down-counter that contains the current count value. Above the CE are \(\text{CR}_m\) and \(\text{CR}_l\), two halves of the Count Register (CR). The CR holds the initially configured count, and is used to reload the CE on terminal count in modes that do so.

The count value is transferred from the CR to the CE when a full write of the CR is complete. This may require one or two bytes, depending on the configured RW Mode.

Both Count Registers are initialized to 0 whenever a channel’s mode is set. This avoids leaving either of the CR registers in an indeterminate state when using either byte RW mode.

Counter Loading

Counter loading is not instantaneous on write. A CR is not loaded until the 8253 sees a full clock cycle with a rising and falling edge after the write occurs. If the specific mode requires that the CE be loaded immediately from the CR, all 16-bits are transferred at once.

A count can be loaded with any 16-bit value from 0-65,535. To allow a full 16-bit range, a count value of 0 is interpreted by the 8253 as a count value of 65536.

Counter Latch Operation

Below the CE are \(\text{O}_m\) and \(\text{O}_l\), two halves of the Output Latch. When reading the count value from a channel, we are actually reading from the output latch. Typically, the output latch is updated each time the CE changes. When the Counter Latch Command is issued, the CE simply stops updating the Output Latch, essentially “freezing” the value inside at the point in which the latch command was issued.

When the Output Latch is fully read, which may take one or two bytes depending on the configured RW Mode, the Output Latch is “unfrozen” and will resume being updated by the CE on every tick.

The Output Latch operation can only be reset by fully reading the Output Latch. Issuing a new Counter Latch command will be ignored until the Output Latch is fully read.

Clocking Logic

An 8253 timer channel generally takes an action, such as transferring the CR to CE or decrementing the CE on the next falling edge of its input clock.

Counter Operating Modes

Timer channels can be set to any of 6 different modes.

Mode 0 — Interrupt on Terminal Count

Upon setting this mode, OUT is initially LOW. This is the only mode where the initial OUT state is LOW after a mode is set.

In Mode 0, the counter counts down once per tick from the initial count until it reaches 0. When it reaches 0, OUT goes high and stays high until reprogrammed. The counter will continue to count, rolling over from 0 to 0xFFFF, but no longer affects the state of the OUT pin.

Note: The word “Interrupt” in this mode name can be a little misleading. Nothing about this mode is specific to generating interrupts. Interrupts are generated whenever timer channel 0’s output has a rising edge. Therefore, any operating mode can generate interrupts with timer channel 0. Additionally, using the Interrupt on Terminal Count mode on any other timer channel will not generate an interrupt.

Count Loading

  • After setting the mode and initial count, the CR will be loaded into the CE on the next clock edge after the final write of the initial count.

Output Behavior

  • After mode set: OUT → LOW
  • When countdown reaches 0: OUT → HIGH (and remains HIGH)
  • Upon writing new count: OUT → LOW

GATE Behavior

  • Level-triggered
  • GATE HIGH: enables counting
  • GATE LOW: inhibits counting (freezes the countdown)

Reload Behavior

  • In 8-bit RW modes:
    • Writing either the LSB or MSB while the counter is running forces OUT low immediately.
    • The CR will be loaded into the CE on the next clock edge.
  • In LSBMSB RW mode:
    • Writing the LSB while the counter is running disables counting and forces OUT low immediately.
    • Writing the MSB will load the CR into the CE on the next clock edge.

Timing

  • For initial count = N, OUT will go high up to N+1 timer clock cycles after the write.
Mode 0 Timing

Figure 4: Timer Mode 0 - Interrupt on Terminal Count Timing


Mode 1 — Hardware Retriggerable One-Shot

Summary

This mode allows a low pulse of the OUT pin of a configurable length, triggerable via the GATE pin. This mode is inoperable on the IBM PC except on timer channel 2.

Upon setting this mode, OUT is initially HIGH. A rising edge of the GATE input will trigger OUT → LOW on the next clock edge. When the count reaches 0, OUT → HIGH. The counter will continue to count, rolling over from 0 to 0xFFFF, but will not affect the state of the OUT pin until the counter is re-triggered.

We refer to a “trigger” as a LOW → HIGH transition of the GATE pin.

Note: The count starts running as soon as Mode 1 is selected - but you’ll note that the CE is not loaded until a GATE trigger. Presumably, the counting element still contains whatever it had in it when the mode was set, but this has not been verified.

Count Loading

  • After setting the mode and initial count, the CR will hold the initial count but will NOT write it into the CE until a trigger occurs.

Output Behavior

  • After mode set: OUT → HIGH
  • After GATE LOW → HIGH: OUT → LOW
  • At terminal count: OUT → HIGH

GATE Behavior

  • Edge-triggered
  • GATE LOW -> HIGH: Trigger. The CR is loaded into the CE on the next clock edge.
    • Since the trigger reloads the CE, another trigger will restart any count in progress.

Reload Behavior

  • Writing a new count during an active count will not affect the current count until the next trigger, as the trigger controls loading of the CE from CR.

Timing

Mode 1 Timing

Figure 5: Timer Mode 1 - Hardware Retriggerable One-Shot Timing

---

Mode 2 — Rate Generator

Summary

In this mode, OUT normally remains HIGH, but produces regular one-clock-wide low pulses. This mode is useful when a periodic LOW → HIGH transition is required.

On the IBM PC, timer channel 1 is typically configured for Mode 2 to repeatedly generate the \(DREQ0\) signal.

Output Behavior

  • After mode set: OUT → HIGH
  • When count reaches 1: OUT → LOW
  • When count reaches 0: OUT → HIGH

GATE Behavior

  • Edge-triggered
  • GATE LOW -> HIGH: Trigger. The CR is loaded into the CE on the next clock edge. Counting enabled.
  • GATE LOW: OUT is forced HIGH, counting disabled.

Reload Behavior

  • Writing a new count during an active count will not affect the current count until either a terminal count or a GATE trigger.
  • CR is automatically loaded into the CE after terminal count is reached, restarting the count.

Constraints

  • A count of 1 is invalid and will cause the timer channel not to function.

Timing

Mode 2 Timing

Figure 5: Timer Mode 2 - Rate Generator Timing

---

Mode 3 — Square Wave Generator

Summary

Similar to Mode 2, but produces a square wave: OUT alternates high and low with a 50% duty cycle (if the initial count is even). This is a general-purpose mode with many applications. The IBM BIOS sets timer channel 0 to Mode 3 to run the BIOS time-of-day clock. This mode can also be used to drive a tone of a specific frequency to the PC speaker on timer channel 2.

This mode is a bit more complex than the other modes. The 8253 creates a square wave of a period determined by the initial count by decrementing the counting element by 2 instead of 1. This presents a problem if the initial count is odd, as we need to reach 0 to trigger the terminal count condition.

Odd Count Logic

Within the counter is a flip-flop I will call the 1/3 flip-flop. This flip-flop is initially 0.

  • If the CE is odd, the 8253 will decrement it as follows:
    • If the 1/3 flip-flop is 0, the CE will be decremented by 1. This sets the CE to an even value.
    • If the 1/3 flip-flop is 1, the CE will be decremented by 3. This sets the CE to an even value.
  • If the CE is even, the 8253 will decrement it by 2.
  • When the counter reaches terminal count (0), CE is reloaded by CR, and the 1/3 flip-flop is toggled.

This is a somewhat awkward way of accounting for the one missed clock period per cycle we would otherwise accumulate over time with an odd count. The result of this logic is that the resulting square wave is HIGH for \(\frac{N+1}{2}\) clocks and LOW for \(\frac{N-1}{2}\) clocks.

Note: The 8254 implements the logic for Mode 3 differently than the 8253. Refer to the 8254 datasheet for an accurate description if you are emulating an 8254.

The counter also has an output flip-flop that it uses in this mode to toggle the state of the OUT pin when terminal count is reached.

Output Behavior

  • After mode set: OUT → HIGH
  • At terminal count: OUT toggles state

GATE Behavior

  • Edge-triggered
  • GATE HIGH: Trigger. The CR is loaded into the CE on the next clock edge. Counting enabled.
  • GATE LOW: OUT → HIGH. Counting disabled.

Reload Behavior

  • Writing a new count during an active count will not affect the current count until either a terminal count or a GATE trigger.
  • CR is automatically loaded into the CE after terminal count is reached, restarting the count.

Timing

Mode 3 Timing

Figure 6: Timer Mode 3 - Square Wave Generator Timing


Mode 4 — Software Triggered Strobe

Summary

When the initial count reaches 0, OUT produces a one-clock-wide low pulse. This is similar to Mode 2, but with a distinct difference - in Mode 2, OUT goes low on a count of 1, and HIGH again on a count of 0. In Mode 4, OUT goes low on a count of 0, then HIGH again on the next clock edge. The counter will continue to count, rolling over from 0 to 0xFFFF, but will not affect the state of the OUT pin until the next count value is written.

Counting begins when the initial count is written (the “software trigger”).

Output Behavior

  • After mode set: OUT → HIGH
  • At terminal count: OUT → LOW for one clock period

Count Loading

  • After writing the count, the CR is loaded into the CE on the next clock edge. Counting begins automatically on the following clock edge.
  • Writing a new count during an active count will trigger a CR to be loaded into the CE at the next clock edge.
    • In LSBMSB mode, writing the first byte only has no effect.

GATE Behavior

  • Level-triggered
  • GATE HIGH: Counting enabled.
  • GATE LOW: Counting disabled.
  • GATE does not affect OUT.
  • GATE does not trigger a reload of the counter.

Timing

Mode 4 Timing

Figure 7: Timer Mode 4 - Software Triggered Strobe Timing


Mode 5 — Hardware Triggered Strobe

Summary

Similar to Mode 4, but triggered by a LOW → HIGH transition of GATE. In Mode 5, OUT goes low on a count of 0, then HIGH again on the next clock edge. The counter will continue to count, rolling over from 0 to 0xFFFF, but will not affect the state of the OUT pin until the counter is retriggered by the GATE pin.

Note: The count starts running as soon as Mode 5 is selected - but you’ll note that the CE is not loaded until a GATE trigger. Presumably, the counting element still contains whatever it had in it when the mode was set, but this has not been verified.

Output Behavior

  • After mode set: OUT → HIGH
  • At terminal count: OUT → LOW for one clock period

GATE Behavior

  • Edge-triggered
  • GATE LOW -> HIGH: Trigger. The CR is loaded into the CE on the next clock edge. Counting enabled.
  • GATE does not affect OUT,

Reload Behavior

  • Writing a new count value during an active count will not affect the current count until either a terminal count or a GATE trigger.

Timing

Mode 5 Timing

Figure 7: Timer Mode 5 - Hardware Triggered Strobe Timing


Mode Summary Table

NModeOUT after Mode setGATE modeWriting count reloads next clkAutomatic ReloadGATE initiates countingGATE controls counting
0Interrupt on Terminal CountLOWLevel-triggeredYESNONOYES
1Hardware Retriggerable One ShotHIGHEdge-triggeredNONOYESNO
2Rate GeneratorHIGHBothNOYESYESYES
3Square Wave GeneratorHIGHBothNOYESYESYES
4Software Triggered StrobeHIGHLevel-triggeredYESNONOYES
5Hardware Triggered StrobeHIGHEdge-triggeredNONOYESNO

Edge Cases

Some interesting edge cases have been observed. Consider the following scenario:

  • A timer channel is set to Mode 2 - Rate Generator, RW mode LSBMSB, and an initial count written, starting the count.
  • Only the LSB of a new count is written.
  • The timer reaches terminal count. What value is loaded into the Counting Element?
  • Once the Counting Element has been reloaded, what happens when the MSB of the new count is then written?

If you have studied the counter channel block diagram, you may be able to figure out what should happen. The \(\text{CR}_m\) and \(\text{CR}_l\) registers are used to hold the programmed initial count, and the CE is reloaded from these registers. In addition, the counter keeps a flip-flop to keep track of the progress of writing a new count, and will write the contents of the CR registers to the CE when the write is complete (depending on mode).


The Intel 8254

The 8254 is an improved model of the 8253 and was used in the IBM AT. It would become the standard timer chip in PC compatible systems for many years.

Changes in the 8254

  • Faster clock inputs
  • A channel state read-back command
  • Resolves the issue with the 8253 where reads and writes to the same channel could not be interleaved without leaving the chip in an undefined state.
  • Modified the logic of Mode 3 - Square Wave Generator.

If you wish to emulate the 8254 instead of the 8253, there’s no real problem with doing so.

Emulation Tips

Implementation Priority

  • Implement these modes first:
    • Mode 3, Square Wave Generator
    • Mode 2, Rate Generator
    • Mode 0, Interrupt on Terminal Count
  • Connect the output of Timer Channel 0 to IRQ0
  • Connect the 8255 PPI Port B bit 0 to the GATE of Timer Channel 2

Primary Emulation Resources

Further Reading

References


    Programmable Peripheral Interface (8255 PPI)

    The Intel 8255 PPI is a general-purpose IO chip that provides 24 configurable, bidirectional I/O pins.

    The 8255 was used in a number of systems, and even a few mouse controller cards.

    The IBM 5150 and 5160 utilize the PPI to receive scancodes from the keyboard interface, read the system’s DIP switches, read motherboard status lines and write control signals.

    The PPI is a moderately complex chip with several modes of operation. Perhaps unique to all the support chips you need to emulate, the vast majority of the PPI’s extended capabilities and modes can be completely ignored by a basic PC emulator.

    Intel 8237 DMA Controller

    The Intel 8237 DMA (Direct Memory Access) Controller enables efficient data transfers between memory and I/O devices without CPU intervention. In the IBM PC, it coordinates data transfer to and from floppy and hard drives, as well as performing DRAM refresh cycles.

    Overview

    The 8237 provides four independent DMA channels, each capable of transferring data between memory and peripherals. In theory, the 8237 is capable of performing memory-to-memory transfers as well, but its implementation in the IBM PC prevents it from doing so.

    IBM PC DMA Configuration

    ChannelPurposeDevice
    0Memory RefreshDRAM
    1Unused-
    2Floppy DiskFDC
    3Hard Disk*HDC

    Note: Not all hard disk controllers use DMA. Notably, most models of the XTIDE do not.

    Hardware Interface

    I/O Ports (8237A-5)

    PortRegisterAccess
    0x00Channel 0 AddressR/W
    0x01Channel 0 CountR/W
    0x02Channel 1 AddressR/W
    0x03Channel 1 CountR/W
    0x04Channel 2 AddressR/W
    0x05Channel 2 CountR/W
    0x06Channel 3 AddressR/W
    0x07Channel 3 CountR/W
    0x08Status RegisterR
    0x08Command RegisterW
    0x09Request RegisterW
    0x0AMask RegisterW
    0x0BMode RegisterW
    0x0CClear Flip-FlopW
    0x0DMaster ClearW
    0x0EClear Mask RegisterW
    0x0FWrite All Mask BitsW

    Page Registers

    The DMA page registers are not part of the 8237 itself, but are implemented on the motherboard. They are provided here for convenience.

    Note: The page register addresses are mapped out of order from their respective channels. Take note of the assignments.

    • 0x81: Channel 2 Page Register (Address bits 16-19)
    • 0x82: Channel 3 Page Register (Address bits 16-19)
    • 0x83: Channel 1 Page Register (Address bits 16-19)

    The IBM AT added a page register for Channel 0, but this is not implemented on the PC/XT:

    • 0x87: Channel 0 Page (bits 16-19)

    8288 Bus Controller

    8284 Clock/Ready Generator

    DIP switches

    The Keyboard Interface

    The DMA Page Registers

    DRAM Refresh

    DMA and Ready Generation

    Floppy Drive Controller

    IBM PC/XT systems outfitted with a floppy drive had an “IBM 5.25” Diskette Drive Adapter“ card installed in one of the available expansion slots.

    For a good look at the Diskette Drive Adapter, see minuszerodegrees.net.

    The IBM floppy drive controller, as we’ll refer to it here, was a collection of 74-series logic chips and a 16.0Mhz clock crystal supporting the “brain” of the card, a NEC µPD765A (NEC 765) floppy drive controller chip. It could support up to four floppy disk drives, although configurations of more than two were uncommon. Drives 0-3 would be assigned the drive letters A-D. It would feel a bit wrong to have a floppy disk as drive C, but if you did indeed have three drives connected, that’s what you’d end up with.

    The NEC 765 takes an 8MHz clock, divided once from the card’s 16Mhz crystal.

    The IBM controller card adds a main control register external to the 765, called the Digital Output Register or DOR. The DOR has several functions - it selects a specific drive as the target of operations, it can reset the 765, it can enable or disable interrupts and DMA, and it can turn on and off the attached floppy drive motors.

    The Digital Output Register (DOR)

    Figure 1: The Digital Output Register (DOR)

    Drive Selection Bits

    The two least significant bits (Bits 0-1) of the DOR control which floppy drive is selected:

    Bit 1Bit 0Selected Drive
    00Drive A
    01Drive B
    10Drive C
    11Drive D

    If a drive’s motor is not on, selecting it in the DOR will do nothing until the motor is turned on.

    The DOR is implemented with an 74LS273 8-bit register chip. The DOR is write-only.

    The FDC RESET bit 2 directly toggles the 765’s RST pin, resetting the controller chip.

    Note: To avoid confusion, be aware that the DOR is the only drive selection method used by the IBM floppy drive controller. The NEC 765 command set includes fields that would, in theory, select which drive the operation is intended to target. Under IBM’s controller design, these bits do nothing - the 765 is not in control of which drive is selected. You can verify this yourself by noting the 765’s “unit select” pins, 28 and 29, are not connected.

    On the IBM PC/XT, the floppy drive controller is operated by the BIOS in DMA mode exclusively. It is possible to operate the controller in polled-io mode in a manual fashion, but there are severe disadvantages to doing so - as was seen on the IBM PCjr which lacked a DMA controller. The lack of DMA prevented such operations as transferring data via the serial ports and floppy disk drive at the same time.

    I/O Ports

    The IBM Diskette Drive Adapter decodes the following IO port addresses:

    PC Port765 PortRWDescription
    0x3F2n/aWDigital Output Register
    0x3F40RµPD765A Status Register
    0x3F51RWµPD765A Data Register

    DMA Channel

    The IBM Diskette Drive Adapter uses DMA Channel 2.

    IRQs

    The IBM Diskette Drive Adapter uses IRQ 6.

    Technical References

    References

    1


    1. (minuszerodegrees.net) IBM 5-1/4“ Diskette Drive Adapter. IBM Corporation. Document Number: 6361505.

    Hard Disk Controllers

    IBM/Xebec Hard Disk Controler

    XTIDE

    Display Concepts

    The main displays for the IBM PC were cathode-ray tube (CRT) monitors and television sets.

    A CRT works by directing a beam of electrons at a screen coated with phosphor within a vacuum-sealed glass tube. The phosphor glows when struck by the electron beam, emitting light visible from the front side of the glass. The beam can be moved around (or deflected) by magnets, since electrons have a charge. Some CRTs could move the beam around in arbitrary ways to draw lines - these were called vector displays. You may be familiar with them used in early arcade games like Asteroids or the Vectrex video game console.

    Most, if not all home computer displays were raster displays. In a raster display, the electron beam is moved across the screen in a succession of lines called scanlines, usually starting in the upper-left corner. When the electron beam reached the right side of the screen, it was shut off briefly and the magnets set to deflect the beam back to the left side, slightly lower down on the screen, ready to draw the next scanline. In this manner the entire screen can be drawn, until the bottom-right corner of the screen is reached. After that, the beam must be turned off again and the deflection set to return the beam back to the upper left corner. This process repeats at frequency anywhere from 50Hz to 70Hz or more, depending on the adapter and monitor.

    The phosphors on the screen only stay fully lit during the period at which the electron beam is directly illuminating them, after which they start to fade. Different phosphors faded more slowly than others - the phosphors used in older monochrome monitors faded slowly enough that scrolling text could leave “smears” on the screen. Fast responding phosphors were more preferable for this reason. To a high speed camera, a CRT will look like a bright line trailed by a fading image, however quirks of human perception means that we perceive a raster-scanned display as having a fixed, steady image. That said, many people experience eye strain using monitors with lower refresh rates.

    Terminology

    • pixel: - (Picture Element) This is usually the smallest addressable element of a raster display, determined by the capabilities of the display and display adapter.
    • hdot: - (Horizontal dot) This is essentially the time-based unit equivalent to a pixel, but a pixel need not be drawn during every hdot.
    • dot clock: - The frequency at which the video card produces pixels. By slowing down the dot clock, the effective horizontal resolution of a card can be decreased, making each pixel wider. The display timings of the card must be reconfigured to account for this.
    • horizontal blanking period: - The period in which the electron beam is turned off at the left and right edges of the screen or beyond.
    • vertical blanking period: - The period in which the display is turned off at the top and bottom edges of the screen or beyond.
    • horizontal retrace: - The period in which the electron beam is being moved from the right side of the screen to the left side. Occurs during the horizontal blanking period. Also called a horizontal refresh.
    • vertical retrace: - The period in which the electron beam is being moved from the bottom-right of the screen to the top-left side. Occurs duing the vertical blanking period. Also called a vertical refresh.
    • horizontal front porch: - The period of the horizontal blanking period immediately before the horizontal retrace period.
    • horizontal back porch: - The period of the horizontal blanking period immediately after the horizontal retrace period.
    • vertical front porch: - The period of the vertical blanking period immediately before the vertical retrace period.
    • vertical back porch: - The period of the verttical blanking period immediately after the vertical retrace period.
    • hsync: - A signal the display adapter may send to the monitor to initiate the horizontal retrace period.
    • vsync: - A signal the display adapter may send to the monitor to initiate the vertical retrace period.
    • horizontal refresh rate: - The frequency at which the monitor displays an entire scanline, ending in an hsync. Expressed in KHz.
    • vertical refresh rate: - The frequency at which the monitor displays an entire frame, ending in a vsync. Expressed in Hz.
    • overscan:
      • On analog television sets, the overscan is part of the video signal that may be hidden by the display’s bezels.
      • On digital computer monitors, ‘overscan’ typically refers to the part of the video signal which lies outside of the region where addressable pixels are displayed, which may lie partially within the borders of the monitor’s bezels, and partially outside it. The overscan can often be set to a particular color, depending on the adapter.

    Primary Emulation Resources:

    The Motorola 6845 CRTC

    6845 Registers

    The 6845’s register numbers are frequently given in either decimal or hexadecimal. Motorola’s own references use decimal, so that is what we will use here.

    IndexHexName
    000hHorizontal Total
    101hHorizontal Displayed
    202hHorizontal Sync Position
    303hSync Width
    404hVertical Total
    505hVertical Total Adjust
    606hVertical Displayed
    707hVertical Sync Position
    808hInterlace Mode and Skew
    909hMax Scan Line Address
    100AhCursor Start
    110BhCursor End
    120ChStart Address (High)
    130DhStart Address (Low)
    140EhCursor Address (High)
    150FhCursor Address (Low)
    1610hLight Pen Latch Address (High)
    1711hLight Pen Latch Address (Low)

    Monochrome Display Adapter (MDA)

    The IBM Color Graphics Adapter (CGA)

    The IBM CGA card was one of the first video adapters available for the IBM PC/XT, along with the IBM Monochrome Display Adapter and the Hercules video adapter.

    The CGA could be connected to a regular North American television set via its composite output connector. A digital DE-9 connection eventually allowed it to be connected to the IBM 5153 Color Display, once that was finally released. IBM left owners of the CGA waiting a bit for a proper monitor - it was only released in 1983, two years after the CGA’s debut.

    The CGA has 16KB of DRAM dedicated to video memory, and a 4KB font ROM that holds bit patterns for drawing text glyphs.

    In text mode, the CGA card was capable of outputting 16 colors. In graphics mode, it was limited to 3 palettes of 3 fixed colors each, with a selectable background color. The CGA also had a high-resolution mode, with a single, selectable foreground color on black.

    Like the MDA, the CGA is built around the Motorola MC6845 CRTC. See that section first for a basic understanding of how that chip is used to define display geometry.

    Display Timings

    Unlike the MDA, the CGA does not have its own crystal. IBM designed the main system crystal of the PC itself around the NTSC display standard, with the apparent intent of simplifying the production of the CGA and other television-compatible peripherals.

    The 5150 has a single main system crystal with a frequency of 14.31818MHz. This frequency is exactly four times the NTSC color subcarrier frequency.

    The crystal frequency can be expressed as a fraction:

    $$f_{crystal} = \frac{315}{22} \text{ MHz} = 14.318181\overline{81} \text{ MHz}$$

    The CGA’s output is almost but not quite entirely NTSC-conforming. A real NTSC signal provides two interlaced fields of 262.5 scanlines, whereas the CGA outputs 262 progressive scanlines at approximately 60fps. This 565 vs 564 scanline difference is minor enough for television sets to ignore.

    The CGA produces a display field of \(912 \times 262\) or \(238,944\) hdots.

    The exact vertical refresh rate of the CGA can be calculated as:

    $$f_{refresh} = \frac{14{,}318{,}181}{238{,}944} = 59.92 \text{ Hz}$$

    The horizontal retrace rate can be calculated as:

    $$f_{hsync} = \frac{14{,}318{,}181}{912} = 15.70 \text{ kHz}$$

    This is a significant number in that you will often hear monitors capable of displaying 200-line resolution modes produced by the CGA and EGA video cards described as 15KHz displays.

    Dot Clock

    The 14.31818Mhz clock of the CGA can be used directly as the dot clock, which is the case in the card’s high resolution text mode. Alternatively, it can be divided by two to produce a 7.159Mhz dot clock, which is done in the card’s lower resolution modes. When using the native clock or hclock the card typically outputs 640 pixels per scanline. When using the halved clock or lclock, the card typically outputs 320 pixels per scanline, as the effective width of each pixel is doubled since the raster beam continues to scan out the screen at the same rate.

    With either clock, the number of vertical scanlines remains the same, but the horizontal timings programmed into the CRTC must be adjusted to account for the lower clock when the clock divisor is in use.

    Video Memory

    The 16KB of DRAM on the CGA is not expandable. It also single-ported, meaning that only either the CPU or the CGA can access the video memory at any given time. This is a bit of a problem as the CGA needs to be reading video memory constantly as it rasterizes the screen.

    The CGA has some circuitry for attempting to marshall the CPU’s access to video memory, but perhaps due to limitations in board space, this circuitry was only implemented for the card’s low-resolution modes where the lclock is used. In high-resolution text mode, attempts to access video memory by the CPU while the CGA is rasterizing the active display area will result in what is called snow - random glitches where the CGA reads the wrong data while attempting to read character glyphs or attribute bytes. IBM worked around this in BIOS routines that scrolled the screen - such as when you execute the DIR command in DOS by rapidly disabling and re-enabling the display, causing noticable flicker.

    Operational Modes

    The CGA has two main modes of operation, text mode and graphics mode.

    Text Mode

    In text mode, video memory is organized conceptually as a grid of character cells, the dimensions of which are directly configured on the CRTC. Typically, this will be a rectangular grid of 80x25 characters. Each logical cell is comprised of a pair of bytes in video memory, the first byte being a character code and the second byte being a character attribute. The character code indicates what character glyph to display. For a list of all character codes and their corresponding glyphs, see the ASCII table appendix.

    The character code, combined with the vertical line counter of the CRTC, is used to resolve a byte contained in the CGA’s font ROM representing 8 pixels (or span) of a character glyph. The character attribute byte then describes the colors to use for the foreground and background as the glyph span is drawn.

    Since each character cell requires two bytes, it takes 4KB of memory to display an 80x25 text mode screen. This means up to four text-mode screens can fit in the CGA’s 16KB of memory, and a program can switch between each screen by adjusting the CRTC’s start address registers. Multiple screens present in video memory are often called video pages, and switching between them may be referred to as page-switching or page-flipping when used for fast animation. Alternatively, a single large screen of up to 80x100 could be stored in memory and the visible 80x25 region panned down through it by adjusting the start address registers one row at a time.

    Primary Emulation Resources

    Video Memory and Timing

    Keyboard

    The IBM 5150 and 5160 originally used an 83-key IBM “Model F” keyboard1, IBM Part #1501100 (Part #1501105 in the UK2).

    Later revisions of the BIOS ROM for the IBM 5160 contained support for the 101-key Enhanced Keyboard3. This keyboard introduced multi-byte scancodes, which required large changes in the keyboard handling code of the BIOS to accommodate.

    IBM changed the keyboard protocol with the IBM 5170 AT, making everyone buy new keyboards. Therefore, keyboards of this era are often described as speaking either the “XT” or “AT” protocol. Some keyboards were made that could switch between both, and adapters were (and are) available.

    The 83-key keyboard layout is missing many of the keys that we take for granted on modern keyboard layouts. Unlike modern keyboards, the function keys are arranged in a block on the left side.

    The IBM 83-key XT keyboard, with scancodes overlaid

    Figure 1.1: IBM PC 83-key Model F Keyboard Layout with scancodes (Click to zoom)

    Keyboard Operation

    The keyboard communicates with the PC by sending scancodes when a key is pressed or released. On the original 83-key keyboard, each key produces a pair of single-byte scancodes, one when pressed, called the make scancode, and one when released called the break scancode. The make scancodes are typically the values provided in scancode tables, and can be seen in the figure above. Break scancodes are calculated by taking the make scancode and setting the MSB to 1.

    Since keyboard operation is event-driven, if the host computer were ever to miss processing a ‘key-up’ scancode, this would cause the phenomenon of a “stuck key,” something most PC users have experienced at one point.

    Inside the Model F keyboard is an Intel 8048 microcontroller that is responsible for scanning the internal key matrix and converting keypresses (and releases) into scancodes to send to the host PC. On early versions of the Model F, the 8048 could be reset directly through the RESET pin on the keyboard DIN connector. Later versions of the Model F disconnected this RESET line and the 8048 is no longer externally resettable, except perhaps by unplugging the keyboard.

    The 8048 has burned-in program ROM and a small amount of onboard RAM, in which it keeps a 16-byte scancode FIFO buffer. Scancodes are placed into this buffer as they are detected from the keyboard matrix, and read out as they are sent to the host.

    Note: It is important that you buffer scancodes in your emulator - a fast typist can generate scancodes very rapidly - consider how quickly scancodes may be produced in the event that multiple keys are pressed and released at once. It is generally insufficient to deliver one scancode per frame.

    The keyboard is a serial device, and the keyboard port is a specialized serial port. The exact electrical details of the keyboard port are not crucially important to emulating the keyboard, except for the operation of the clock pin.

    Bit 6 of the 8255 PPI’s Port B register, when set to 0, will pull the keyboard clock line low. When held in this state for approximately 20ms, the 8048 will perform a keyboard self-test. When the clock line is released by writing 1 to PPI Port B bit 6, the keyboard will send the special scancode 0xAA. If the keyboard internally detects a physically stuck key, it will send the scancode of that key 10ms after sending 0xAA.4.

    If you fail to emulate sending the reset scancode 0xAA at the appropriate time, the BIOS will emit a POST error code 301.

    Note that the ‘clock’ line does not actually clock the 8048. The keyboard data and clock lines are simply connected to specialized I/O pins on the 8048 that it can monitor. The 8048 is clocked via an internal oscillator configured for approximately 5MHz.

    Typematic Repeat

    Most computer users are familiar with what happens when a key on the keyboard is held down - typically after a short delay, the keyboard will begin repeating the keypress automatically.

    IBM called this feature “typematic” on the Model F. When a key is held down, it will start to repeat after approximately 500ms at a rate of approximately 11 characters per second. Both the make and break scancodes are sent for each repeat.

    It is possible to simply pass through the host’s typematic repeat to your emulator, but I recommend handling it yourself, as it gives you better control over the rate (which might otherwise be too fast).

    There are some subtleties to typematic repeat operation:

    • If more than one key is held down, only the last key will repeat.
    • Repeat will stop when a key is released, even if other keys remain held down.

    The IBM BIOS keyboard routines will filter typematic events for Ctrl, Shift, Alt, Num Lock, Scroll Lock, Caps Lock, and Insert. If the default BIOS keyboard routines are used by an application that does not process keyboard events fast enough, it is likely that holding down a key will fill the BIOS keyboard buffer and result in several angry beeps from the PC speaker.

    The Keyboard Interface

    Serial data from the keyboard is first read into a shift register on the motherboard, then ultimately read out in a parallel fashion via the 8255 PPI’s Port A. See the chapter on the IBM PC’s Keyboard Interface for more details.

    SDL Scancode Table

    If you happen to be using SDL for your emulator, here’s a table of SDL keycode definitions to IBM scancodes:

    SDL KeyScancode (hex)
    SDLK_A1E
    SDLK_B30
    SDLK_C2E
    SDLK_D20
    SDLK_E12
    SDLK_F21
    SDLK_G22
    SDLK_H23
    SDLK_I17
    SDLK_J24
    SDLK_K25
    SDLK_L26
    SDLK_M32
    SDLK_N31
    SDLK_O18
    SDLK_P19
    SDLK_Q10
    SDLK_R13
    SDLK_S1F
    SDLK_T14
    SDLK_U16
    SDLK_V2F
    SDLK_W11
    SDLK_X2D
    SDLK_Y15
    SDLK_Z2C
    SDLK_102
    SDLK_203
    SDLK_304
    SDLK_405
    SDLK_506
    SDLK_607
    SDLK_708
    SDLK_809
    SDLK_90A
    SDLK_00B
    SDLK_RETURN1C
    SDLK_ESCAPE01
    SDLK_BACKSPACE0E
    SDLK_TAB0F
    SDLK_SPACE39
    SDLK_MINUS0C
    SDLK_EQUALS0D
    SDLK_LEFTBRACKET1A
    SDLK_RIGHTBRACKET1B
    SDLK_BACKSLASH2B
    SDLK_SEMICOLON27
    SDLK_APOSTROPHE28
    SDLK_COMMA33
    SDLK_PERIOD34
    SDLK_SLASH35
    SDLK_GRAVE29
    SDLK_LSHIFT2A
    SDLK_RSHIFT36
    SDLK_LCTRL1D
    SDLK_RCTRL1D
    SDLK_LALT38
    SDLK_RALT38
    SDLK_CAPSLOCK3A
    SDLK_F13B
    SDLK_F23C
    SDLK_F33D
    SDLK_F43E
    SDLK_F53F
    SDLK_F640
    SDLK_F741
    SDLK_F842
    SDLK_F943
    SDLK_F1044
    SDLK_F1157
    SDLK_F1258
    SDLK_UP48
    SDLK_DOWN50
    SDLK_LEFT4B
    SDLK_RIGHT4D
    SDLK_INSERT52
    SDLK_DELETE53
    SDLK_HOME47
    SDLK_END4F
    SDLK_PAGEUP49
    SDLK_PAGEDOWN51
    SDLK_KP_14F
    SDLK_KP_250
    SDLK_KP_351
    SDLK_KP_44B
    SDLK_KP_54C
    SDLK_KP_64D
    SDLK_KP_747
    SDLK_KP_848
    SDLK_KP_949
    SDLK_KP_052
    SDLK_KP_PLUS4E
    SDLK_KP_MINUS4A
    SDLK_KP_PERIOD53
    SDLK_KP_ENTER1C
    SDLK_KP_DIVIDE35
    SDLK_KP_MULTIPLY37
    SDLK_KP_EQUALS0D

    References


    1. wikipedia.org Model F keyboard.

    2. seasip.info The IBM 1501105 Keyboard

    3. minuszerodegrees.net IBM 5160 - Keyboards

    4. minuszerodegrees.net 5160 Keyboard Startup

    Speaker and Sound

    The Cassette Interface

    Serial Ports

    Parallel Ports

    The Game Port

    Joystikcs

    Mice

    Microsoft Serial Mouse

    Mouse Systems Serial Mouse

    Light Pen

    The IBM 5150 BIOS

    The IBM 5160 BIOS

    GLaBIOS

    Emulation Architecture

    CPU Emulation Techniques

    Device Synchronization

    Performance Optimization

    Testing Strategies

    Debugging Tools

    Compatibility Issues

    Extended ASCII Table

    This table shows all 256 characters of the IBM PC’s Code Page 437 character set as rendered by the CGA’s 8x8 font.

    Dec Hex Oct Char Glyph Dec Hex Oct Char Glyph Dec Hex Oct Char Glyph Dec Hex Oct Char Glyph
    0 00 000 NUL 64 40 100 @ 128 80 200 Ç 192 C0 300
    1 01 001 SOH 65 41 101 A 129 81 201 ü 193 C1 301
    2 02 002 STX 66 42 102 B 130 82 202 é 194 C2 302
    3 03 003 ETX 67 43 103 C 131 83 203 â 195 C3 303
    4 04 004 EOT 68 44 104 D 132 84 204 ä 196 C4 304
    5 05 005 ENQ 69 45 105 E 133 85 205 à 197 C5 305
    6 06 006 ACK 70 46 106 F 134 86 206 å 198 C6 306
    7 07 007 BEL 71 47 107 G 135 87 207 ç 199 C7 307
    8 08 010 BS 72 48 110 H 136 88 210 ê 200 C8 310
    9 09 011 TAB 73 49 111 I 137 89 211 ë 201 C9 311
    10 0A 012 LF 74 4A 112 J 138 8A 212 è 202 CA 312
    11 0B 013 VT 75 4B 113 K 139 8B 213 ï 203 CB 313
    12 0C 014 FF 76 4C 114 L 140 8C 214 î 204 CC 314
    13 0D 015 CR 77 4D 115 M 141 8D 215 ì 205 CD 315
    14 0E 016 SO 78 4E 116 N 142 8E 216 Ä 206 CE 316
    15 0F 017 SI 79 4F 117 O 143 8F 217 Å 207 CF 317
    16 10 020 DLE 80 50 120 P 144 90 220 É 208 D0 320
    17 11 021 DC1 81 51 121 Q 145 91 221 æ 209 D1 321
    18 12 022 DC2 82 52 122 R 146 92 222 Æ 210 D2 322
    19 13 023 DC3 83 53 123 S 147 93 223 ô 211 D3 323
    20 14 024 DC4 84 54 124 T 148 94 224 ö 212 D4 324
    21 15 025 NAK 85 55 125 U 149 95 225 ò 213 D5 325
    22 16 026 SYN 86 56 126 V 150 96 226 û 214 D6 326
    23 17 027 ETB 87 57 127 W 151 97 227 ù 215 D7 327
    24 18 030 CAN 88 58 130 X 152 98 230 ÿ 216 D8 330
    25 19 031 EM 89 59 131 Y 153 99 231 Ö 217 D9 331
    26 1A 032 SUB 90 5A 132 Z 154 9A 232 Ü 218 DA 332
    27 1B 033 ESC 91 5B 133 [ 155 9B 233 ¢ 219 DB 333
    28 1C 034 FS 92 5C 134 \ 156 9C 234 £ 220 DC 334
    29 1D 035 GS 93 5D 135 ] 157 9D 235 ¥ 221 DD 335
    30 1E 036 RS 94 5E 136 ^ 158 9E 236 222 DE 336
    31 1F 037 US 95 5F 137 _ 159 9F 237 ƒ 223 DF 337
    32 20 040 Space 96 60 140 ` 160 A0 240 á 224 E0 340 α
    33 21 041 ! 97 61 141 a 161 A1 241 í 225 E1 341 ß
    34 22 042 " 98 62 142 b 162 A2 242 ó 226 E2 342 Γ
    35 23 043 # 99 63 143 c 163 A3 243 ú 227 E3 343 π
    36 24 044 $ 100 64 144 d 164 A4 244 ñ 228 E4 344 Σ
    37 25 045 % 101 65 145 e 165 A5 245 Ñ 229 E5 345 σ
    38 26 046 & 102 66 146 f 166 A6 246 ª 230 E6 346 µ
    39 27 047 ' 103 67 147 g 167 A7 247 º 231 E7 347 τ
    40 28 050 ( 104 68 150 h 168 A8 250 ¿ 232 E8 350 Φ
    41 29 051 ) 105 69 151 i 169 A9 251 233 E9 351 Θ
    42 2A 052 * 106 6A 152 j 170 AA 252 ¬ 234 EA 352 Ω
    43 2B 053 + 107 6B 153 k 171 AB 253 ½ 235 EB 353 δ
    44 2C 054 , 108 6C 154 l 172 AC 254 ¼ 236 EC 354
    45 2D 055 - 109 6D 155 m 173 AD 255 ¡ 237 ED 355 φ
    46 2E 056 . 110 6E 156 n 174 AE 256 « 238 EE 356 ε
    47 2F 057 / 111 6F 157 o 175 AF 257 » 239 EF 357
    48 30 060 0 112 70 160 p 176 B0 260 240 F0 360
    49 31 061 1 113 71 161 q 177 B1 261 241 F1 361 ±
    50 32 062 2 114 72 162 r 178 B2 262 242 F2 362
    51 33 063 3 115 73 163 s 179 B3 263 243 F3 363
    52 34 064 4 116 74 164 t 180 B4 264 244 F4 364
    53 35 065 5 117 75 165 u 181 B5 265 245 F5 365
    54 36 066 6 118 76 166 v 182 B6 266 246 F6 366 ÷
    55 37 067 7 119 77 167 w 183 B7 267 247 F7 367
    56 38 070 8 120 78 170 x 184 B8 270 248 F8 370 °
    57 39 071 9 121 79 171 y 185 B9 271 249 F9 371
    58 3A 072 : 122 7A 172 z 186 BA 272 250 FA 372 ·
    59 3B 073 ; 123 7B 173 { 187 BB 273 251 FB 373
    60 3C 074 < 124 7C 174 | 188 BC 274 252 FC 374
    61 3D 075 = 125 7D 175 } 189 BD 275 253 FD 375 ²
    62 3E 076 > 126 7E 176 ~ 190 BE 276 254 FE 376
    63 3F 077 ? 127 7F 177 191 BF 277 255 FF 377

    Notable Characters

    Control Characters (0x00-0x1F)

    In the IBM PC character set, the control characters have glyphs mapped to them. These characters were often used in games. The two smiley faces are perhaps the most famous - they played the role of the player character in innumerable video games, such as Rogue.

    DecHexDescription
    000Null (displays as blank)
    101Smiley face
    202Inverse smiley face
    303Heart
    404Diamond
    505Club
    606Spade
    707Bullet (BEL character)
    130DMusical note (CR character)

    Box Drawing Characters (0xB0-0xDF)

    The IBM PC character set includes an extensive set of box-drawing characters used for creating text-mode user interfaces. These include single-line, double-line, and mixed box corners and intersections.

    Mathematical and Greek Symbols (0xE0-0xFF)

    The upper range includes mathematical symbols and Greek letters commonly used in technical documentation:

    DecHexDescription
    224E0Alpha
    225E1Beta
    227E3Pi
    228E4Sigma (uppercase)
    229E5Sigma (lowercase)
    230E6Mu
    241F1Plus-minus
    246F6Division
    248F8Degree
    253FDSuperscript 2

    Memory Map Reference

    The BIOS Data Area (BDA)

    The BIOS Data Area (BDA) is a 257-byte1 region of memory located at segment 0x0040 (physical address 0x00400).

    It is used by the BIOS to store system variables and state.

    OffsetBytesDescriptionIntComments
    002COM 1 base address14
    022COM 2 base address14
    042COM 3 base address14
    062COM 4 base address14
    082LPT 1 base address17
    0A2LPT 2 base address17
    0C2LPT 3 base address17
    0E2LPT 4 base address17EBDA on PS/2 and later
    102Equipment List Flags11See Equipment List Flags
    121Reserved
    121PCjr: infrared keyboard error count
    132Base memory size12Number of kilobytes of RAM
    152Reserved
    171Keyboard Flag Byte 016See Keyboard Flag Byte 0
    181Keyboard Flag Byte 116See Keyboard Flag Byte 1
    191Work area for ALT key16Handles ALT + numpad key entry
    1A2Keyboard-buffer Head Offset16Head offset into keyboard ring buffer
    1C2Keyboard-buffer Tail Offset16Tail offset into keyboard ring buffer
    1E32Keyboard Buffer16
    3E1Floppy recalibrate status13See Floppy Recalibrate Status
    3F1Floppy motor status13See Floppy Motor Status
    401Floppy motor timeout13
    411Floppy operation status13
    427Floppy controller status13See Floppy Controller Status
    4930Video info10
    491Current Video Mode10
    4A2Number of Columns
    4C2Size of video buffer (bytes)
    4E2Offset of current video page
    5016Cursor position of pages 1-8
    601Cursor ending scanline
    611Cursor starting scanline
    621Active display page number
    632Base port for active CRTC3B4 for MDA, 3D4 for CGA+
    651CGA mode control registerEmulated on EGA+
    661CGA current paletteEmulated on EGA+
    675PC: Cassette tape control
    674AT: POST re-entry pointer
    6B1Last Unexpected interrupt
    6C4Timer Counter1A
    701Timer Overflow1A
    711Break key state16
    722Reset Flag
    741HDD operation status13
    751Number of HDDs attached13
    762Reserved13
    781LPT 1 time-out14
    791LPT 2 time-out14
    7A1LPT 3 time-out14
    7B1Reserved
    7C1COM 1 time-out
    7D1COM 2 time-out
    7E1COM 3 time-out
    7F1COM 4 time-out
    802Keyboard buffer start ptr16
    822Keyboard buffer end ptr16
    847Video info10
    852EGA: Character line height
    851PCjr: Typematic repeat key
    861PCjr: Typematic repeat delay
    871EGA: Video mode optionsSee Video Mode Options
    871PCjr: Current Fn key number
    881EGA: Feature / DIP switchesSee EGA Dip Switches
    881PCjr: Keyboard status byte 3
    891VGA/MCGA: Video Display DataSee VGA Display Data
    8A1EGA: Display Combination Code (DCC) index
    8B1Floppy media control13See Floppy Media Control
    8C1HDD Controller status13
    8D1HDD Controller error status13
    8E1HDD Interrupt control13
    8F1Reserved
    901Floppy 0 media status13See Floppy Media Status
    911Floppy 1 media status13
    921Floppy 2 media status13
    931Floppy 3 media status13
    941Drive 0 current cylinder13
    951Drive 1 current cylinder13
    961Keyboard Mode State and Flags16See Keyboard Mode Byte
    971Keyboard LED State16See Keyboard LED State
    982User wait flag offset15
    9A2User wait flag segment15
    9C4User wait count (milliseconds)
    A01RTC Wait active flag15See RTC Wait Flags
    A17Reserved
    A84BIOS Video info Pointer10
    AC84Reserved
    1001Print Screen Status5
    Equipment List FlagsBit flags describing the hardware configuration detected by the BIOSEquipment List FlagsBit flags describing the hardware configuration detected by the BIOS40:101514131211109876543210nPRN--GPnCOMDMAnFLOPVMRAMFPUIPL
    BitsNameDescription
    0IPLFloppy drive installed
    1FPUFPU installed
    2:3RAMOnboard RAM installed (first 256K)
    4:5VMInitial video mode at boot time
    6:7nFLOPNumber of floppy drives installed, -1
    8DMADMA controller installed (if 0)
    9:11nCOMNumber of serial ports installed
    12GPGame port installed
    13Reserved
    14:15nPRNNumber of printer ports installed

    Initial Video Mode

    Bits 5,4Description
    00Unused
    0140x25 color
    1080x25 color
    1180x25 monochrome
    Keyboard Flag Byte 0Primary keyboard status flagsKeyboard Flag Byte 0Primary keyboard status flags40:1776543210INSCAPSNUMSCRLALTCTRLLSHFTRSHFT
    BitsNameDescription
    0RSHFTRight Shift key depressed
    1LSHFTLeft Shift key depressed
    2CTRLCTRL key depressed
    3ALTALT key depressed
    4SCRLScroll-Lock active
    5NUMNum-Lock active
    6CAPSCaps-Lock active
    7INSInsert active
    Keyboard Flag Byte 1Secondary keyboard status flagsKeyboard Flag Byte 1Secondary keyboard status flags40:1876543210INSCAPSNUMSCRLSUSPSYSLALTLCTRL
    BitsNameDescription
    0LCTRLLeft CTRL key depressed
    1LALTLeft ALT key depressed
    2SYSSystem key depressed and held
    3SUSPSuspend key has been toggled
    4SCRLScroll-Lock key depressed
    5NUMNum-Lock key depressed
    6CAPSCaps-Lock key depressed
    7INSInsert key depressed
    Floppy Recalibration StatusInterrupt and calibration status for floppy drivesFloppy Recalibration StatusInterrupt and calibration status for floppy drives40:3E76543210INT--DRV3DRV2DRV1DRV0
    BitsNameDescription
    0DRV01 = Recalibrate drive 0
    1DRV11 = Recalibrate drive 1
    2DRV21 = Recalibrate drive 2
    3DRV31 = Recalibrate drive 3
    4:6Unused
    7INTWorking interrupt flag (1=working)
    Floppy Motor StatusCurrent state of floppy drive motorsFloppy Motor StatusCurrent state of floppy drive motors40:3F76543210WR--DRV3DRV2DRV1DRV0
    BitsNameDescription
    0DRV01 = Drive 0 motor on
    1DRV11 = Drive 1 motor on
    2DRV21 = Drive 2 motor on
    3DRV31 = Drive 3 motor on
    4:6Unused
    7WRWrite operation in progress
    Floppy Controller StatusStatus bytes returned from the floppy controller from the last disk operation (INT 13,1)Floppy Controller StatusStatus bytes returned from the floppy controller from the last disk operation (INT 13,1)40:4176543210TMOSEEKFAILCRCDMASECADDRCMD
    BitsNameDescription
    0CMDInvalid floppy controller command
    1ADDRAddress mark not found
    2SECSector not found
    3DMAFloppy controller DMA error
    4CRCCRC check / data error
    5FAILFloppy controller failure
    6SEEKSeek to track failed
    7TMOFloppy time-out
    Video Mode Options (EGA+)EGA/VGA video mode flagsVideo Mode Options (EGA+)EGA/VGA video mode flags40:8776543210MODERAM--INACT--MONOCURS
    BitsNameDescription
    0CURS1 = Alphanumeric cursor emulation enabled
    1MONO1 = Video subsystem attached to monochrome
    2Reserved
    3INACT1 = Video subsystem is inactive
    4Reserved
    5:6RAMVideo RAM: 00=64K, 01=128K, 10=192K, 11=256K
    7MODEVideo mode number passed to INT 10, function 0 (Bit 7)
    EGA DIP and Feature SwitchesEGA feature bit switches (emulated on VGA)EGA DIP and Feature SwitchesEGA feature bit switches (emulated on VGA)40:8876543210FEAT1FEAT1FEAT0FEAT0SW4SW3SW2SW1
    BitsNameDescription
    0SW1EGA SW1 config (1=off)
    1SW2EGA SW2 config (1=off)
    2SW3EGA SW3 config (1=off)
    3SW4EGA SW4 config (1=off)
    4FEAT0Input FEAT0 (ISR0 bit 5) after output on FCR0
    5FEAT0Input FEAT0 (ISR0 bit 6) after output on FCR0
    6FEAT1Input FEAT1 (ISR0 bit 5) after output on FCR1
    7FEAT1Input FEAT1 (ISR0 bit 6) after output on FCR1
    Video Display Data (MCGA/VGA)MCGA and VGA specific status. Bits 7 and 4 control scan lines.Video Display Data (MCGA/VGA)MCGA and VGA specific status. Bits 7 and 4 control scan lines.40:8976543210SL_HI--SL_LOPALMONOGRAYVGA
    BitsNameDescription
    0VGA1 = VGA is active
    1GRAY1 = Gray scale is enabled
    2MONO1 = Using monochrome monitor
    3PAL1 = Default palette loading is disabled
    4SL_LOScan Line Select Bit 0
    5:6Reserved
    7SL_HIScan Line Select Bit 1 (00=350, 01=400, 10=200)
    Floppy Media ControlLast selected floppy drive data and step ratesFloppy Media ControlLast selected floppy drive data and step rates40:8B76543210RATESTEP--
    BitsNameDescription
    0:3Reserved
    4:5STEPStep Rate: 00=0C, 01=0D, 10=0A
    6:7RATEData Rate: 00=500K, 01=300K, 10=250K
    Floppy Media StatusMedia status for Drives 0-3 (4 copies at 40:90..93)Floppy Media StatusMedia status for Drives 0-3 (4 copies at 40:90..93)40:9076543210RATEDBLEST--STATE
    BitsNameDescription
    0:2STATEDrive/Media State
    3Reserved
    4EST1 = Media/drive established
    5DBLDouble stepping required
    6:7RATEData Rate: 00=500K, 01=300K, 10=250K
    Keyboard Mode/TypeExtended keyboard status flagsKeyboard Mode/TypeExtended keyboard status flags40:9676543210RD_IDID_CHNUM101R_ALTR_CTLE0E1
    BitsNameDescription
    0E1Last code was the E1 hidden code
    1E0Last code was the E0 hidden code
    2R_CTLRight CTRL key depressed
    3R_ALTRight ALT key depressed
    4101101/102 enhanced keyboard installed
    5NUMForce Num-Lock if Rd ID & KBX
    6ID_CHLast char was first ID char
    7RD_IDRead ID in process
    Keyboard LED FlagsStatus of keyboard indicators and transmissionKeyboard LED FlagsStatus of keyboard indicators and transmission40:9776543210ERRMODERSNDACKCIRCCAPSNUMSCRL
    BitsNameDescription
    0SCRLScroll-Lock indicator
    1NUMNum-Lock indicator
    2CAPSCaps-Lock indicator
    3CIRCCircus system indicator
    4ACKACK received
    5RSNDRe-send received flag
    6MODEMode indicator update
    7ERRKeyboard transmit error flag
    RTC Wait Function FlagsINT 15,86 RTC wait function statusRTC Wait Function FlagsINT 15,86 RTC wait function status40:A076543210ELAP--PEND
    BitsNameDescription
    0PEND1 = Wait pending
    1:6Unused
    7ELAP1 = INT 15,86 wait time elapsed

    Primary Emulation Resources

    References


    1. Intel® Platform Innovation Framework for EFI Compatibility Support Module Specification, Revision 0.97, September 4, 2007.

    I/O Port Reference

    Port(s)SystemDeviceAccessDescription
    0000-001FPC/XT/ATDMADMA Controller 1 - Intel 8237
    0000PC/XT/ATDMAr/wDMA channel 0 address
    0001PC/XT/ATDMAr/wDMA channel 0 word count
    0002PC/XT/ATDMAr/wDMA channel 1 address
    0003PC/XT/ATDMAr/wDMA channel 1 word count
    0004PC/XT/ATDMAr/wDMA channel 2 address
    0005PC/XT/ATDMAr/wDMA channel 2 word count
    0006PC/XT/ATDMAr/wDMA channel 3 address
    0007PC/XT/ATDMAr/wDMA channel 3 word count
    0008PC/XT/ATDMArDMA channel 0-3 status
    0008PC/XT/ATDMAwDMA channel 0-3 command register
    0009PC/XT/ATDMAwDMA write request register
    000APC/XT/ATDMAr/wDMA channel 0-3 mask register
    000BPC/XT/ATDMAwDMA channel 0-3 mode register
    000CPC/XT/ATDMAwDMA clear byte pointer flip-flop
    000DPC/XT/ATDMArDMA read temporary register
    000DPC/XT/ATDMAwDMA master clear
    000EPC/XT/ATDMAwDMA clear mask register
    000FPC/XT/ATDMAwDMA write mask register
    0020-003FPC/XT/ATPICPIC 1 - Programmable Interrupt Controller - Intel 8259
    0020PC/XT/ATPICwPIC Initialization command word ICW1
    0021PC/XT/ATPICwPIC ICW2,ICW3,ICW4 after ICW1 to 0020
    0021PC/XT/ATPICr/wPIC master interrupt mask register
    0020PC/XT/ATPICrPIC interrupt request/in-service registers by OCW3
    0040-005FPC/XT/ATPITPIT - Programmable Interrupt Timer - Intel 8253 or 8254
    0040PC/XT/ATPITr/wPIT counter 0, counter divisor
    0041PC/XT/ATPITr/wPIT counter 1, RAM refresh counter (XT, AT)
    0042PC/XT/ATPITr/wPIT counter 2, cassette & speaker (XT, AT, PS/2)
    0043PC/XT/ATPITr/wPIT mode register for counters 0-2
    0060-006FPC/XTPPIr/wPPI - Programmable Peripheral Interface - Intel 8255
    0060-006FATKBDKeyboard microcontroller - 804x (8041, 8042)
    0060PC/XTPPIrPPI Port A
    0061ATKBDwKeyboard microcontroller
    0061PC/XTPPIrPPI Port B
    0062PC/XTPPIr/wPPI Port C
    0063PC/XTPPIr/wPPI Command Port
    0070-007FPC/XT/ATRTCCMOS RAM/RTC (Real Time Clock MC146818)
    0080-008FPC/XT/ATDMADMA page registers (74612)
    0080PC/XT/ATDMAr/wextra page register (temporary storage)
    0081PC/XT/ATDMAr/wDMA channel 2 address byte 2
    0082PC/XT/ATDMAr/wDMA channel 3 address byte 2
    0083PC/XT/ATDMAr/wDMA channel 1 address byte 2
    0084DMAr/wextra page register
    0085DMAr/wextra page register
    0086DMAr/wextra page register
    0087DMAr/wDMA channel 0 address byte 2
    0088DMAr/wextra page register
    0089DMAr/wDMA channel 6 address byte 2
    0089DMAr/wDMA channel 7 address byte 2
    0089DMAr/wDMA channel 5 address byte 2
    008CDMAr/wextra page register
    008DDMAr/wextra page register
    008EDMAr/wextra page register
    008FDMAr/wDMA refresh page register
    00A0-00AFATPICPIC 2 - Programmable Interrupt Controller - Intel 8259
    00A0XTNMIr/wNMI mask register (XT)
    00C0PCjr/TandySN746496 programmable tone/noise generator
    00C0-00DFATDMADMA 2 - Direct Memory Access controller - Intel 8237
    00F0-00F5PCjrFDCPCjr Disk Controller
    00F0PCjrFDCdisk controller
    00F2PCjrFDCdisk controller control port
    00F4PCjrFDCdisk controller status register
    00F5PCjrFDCdisk controller data port
    00F0-00FFATFPUFPU - Math Coprocessor (80287..80387)
    00F0ATFPUwMath coprocessor clear busy latch
    00F1ATFPUwMath coprocessor reset
    00F8ATFPUr/wMath coprocessor opcode transfer
    00FAATFPUr/wMath coprocessor opcode transfer
    0140-0157PC/XT/ATRTCRTC (alternate Real Time Clock for XT) (1st at 0340-0357)
    0200-020FPC/XT/ATGame PortGame port
    0201PC/XT/ATGame PortrRead joystick position and status
    0210-0217XTExpansionExpansion unit (XT)
    0210XTExpansionwlatch expansion bus data
    0211XTExpansionwclear wait, test latch
    0212XTExpansionrLow byte data address
    0213XTExpansionw0=enable, 1=disable expansion unit
    0214XTExpansionwlatch data (receiver card port)
    0215XTExpansionrHigh byte of address, then Low byte (receiver card port)
    0220-0223PC/XT/ATSoundSound Blaster / Adlib port
    0220PC/XT/ATSoundr/wLeft speaker – Status / Address port
    0221PC/XT/ATSoundwLeft speaker – Data port
    0222PC/XT/ATSoundr/wRight speaker – Status / Address port
    0223PC/XT/ATSoundwRight speaker – Data port
    0220-0227PC/XT/ATSoundSoundblaster PRO and SSB 16 ASP
    0220-022FPC/XT/ATSoundSoundblaster PRO 2.0
    0220-022FPC/XT/ATSoundSoundblaster PRO 4.0
    0220PC/XT/ATSoundrleft FM status port
    0220PC/XT/ATSoundwleft FM music register address port (index)
    0221PC/XT/ATSoundr/wleft FM music data port
    0222PC/XT/ATSoundrright FM status port
    0222PC/XT/ATSoundwright FM music register address port (index)
    0223PC/XT/ATSoundr/wright FM music data port
    0224PC/XT/ATSoundwmixer register address port (index)
    0225PC/XT/ATSoundr/wmixer data port
    0226PC/XT/ATSoundwDSP reset
    0228PC/XT/ATSoundrFM music status port
    0228PC/XT/ATSoundwFM music register address port (index)
    0229PC/XT/ATSoundwFM music data port
    022APC/XT/ATSoundrDSP read data (voice I/O and Midi)
    022CPC/XT/ATSoundwDSP write data / write command
    022CPC/XT/ATSoundrDSP write buffer status (bit 7)
    022EPC/XT/ATSoundrDSP data available status (bit 7)
    0240-024FPC/XT/ATSoundGravis UltraSound
    0240-0257AT/XTRTCRTC (alternate Real Time Clock for XT) (1st at 0340-0357)
    0258-025FPC/XT/ATMemoryIntel Above Board
    0278-027EPC/XT/ATParallelParallel printer port, same as 0378 and 03BC
    0278PC/XT/ATParallelwdata port
    0279PC/XT/ATParallelr/wstatus port
    027APC/XT/ATParallelr/wcontrol port
    02A2-02A3PC/XT/ATRTCMSM58321RS clock
    02B0-02DFATVideoAlternate EGA IO addresss (Primary at 3BX) - Basically unused
    02E0-02EFPC/XT/ATGPIBGPIB (General Purpose Interface Bus, IEEE 488 interface)
    02E1PC/XT/ATGPIBGPIB (adapter 0)
    02E0-02EFATGPIBdata aquisition (AT)
    02E2PC/XT/ATGPIBdata aquisition (adapter 0)
    02E3PC/XT/ATGPIBdata aquisition (adapter 0)
    02E8-02EFPC/XT/ATVideo8514/A and compatible video cards
    02F8-02FFPC/XT/ATSerialSerial port, same as 02E8, 03E8 and 03F8
    02F8PC/XT/ATSerialwtransmitter holding register
    02F8PC/XT/ATSerialrreceiver buffer register
    02F9PC/XT/ATSerialr/wdivisor latch, high byte when DLAB=1
    02FAPC/XT/ATSerialrinterrupt identification register
    02FBPC/XT/ATSerialr/wline control register
    02FCPC/XT/ATSerialr/wmodem control register
    02FDPC/XT/ATSerialrline status register
    02FFPC/XT/ATSerialr/wscratch register
    0300ATDiagAward BIOS - POST Diagnostic
    0300-0301PC/XT/ATSoundSoundblaster 16 ASP MPU-Midi
    0320-0323XTHDCXT Hard Disk Controller 1
    0320PC/XT/ATHDCr/wdata register
    0321PC/XT/ATHDCwreset controller
    0322XTHDCrread DIPswitch setting on XT controller card
    0323PC/XT/ATHDCwwrite pattern to DMA and INT mask register
    0324-0327XTHDCXT Hard Disk Controller 2
    0328-032BXTHDCXT Hard Disk Controller 3
    032C-032FXTHDCXT Hard Disk Controller 4
    0330-0331PC/XT/ATSoundMIDI interface
    0338PC/XT/ATSoundAdLib FM Synthesis Card
    0340-034FPC/XT/ATSoundGravis UltraSound (DIP option)
    0340-0357PC/XTRTCRTC (1st Real Time Clock for XT), (alternate at 0240-0257)
    0348-0357PC/XT/ATDCA 3278
    034C-034FPC/XT/ATSoundGravis UltraMax (DIP Option)
    0360-036FAT/XTPC network (AT)
    0360-0367XTPC network (XT only)
    0370-0377ATFDCFDC 2 (2nd Floppy Disk Controller) first FDC at 03F0
    0370FDCrdiskette Extra High Density controller board jumpers (AT)
    0372FDCwdiskette controller DOR (Digital Output Register)
    0374FDCrdiskette controller main status register
    0374FDCwdiskette controller datarate select register
    0375FDCr/wdiskette controller command/data register
    0376FDCr/w(2nd FIXED disk controller data register)
    0377FDCrdiskette controller DIR (Digital Input Register)
    0377FDCwselect register for diskette data transfer rate
    0378-037APC/XT/ATParallelParallel printer port (LPT1) - See also 0278 and 03BC
    0378Parallelwdata port
    0379Parallelr/wstatus port
    037AParallelr/wcontrol port
    0388-0389PC/XT/ATSoundSound Blaster / Adlib port
    0388PC/XT/ATSoundr/wBoth Speakers – Status / Address port
    0389PC/XT/ATSoundwData port
    03B0-03BFPC/XT/ATVideoMDA (Monochrome Display Adapter based on 6845)
    03B0PC/XT/ATVideosame as 03B4
    03B1PC/XT/ATVideosame as 03B5
    03B2PC/XT/ATVideosame as 03B4
    03B3PC/XT/ATVideosame as 03B5
    03B4PC/XT/ATVideowMDA CRTC index register
    03B5PC/XT/ATVideor/wMDA CRTC data register
    03B6PC/XT/ATVideosame as 03B4
    03B7PC/XT/ATVideosame as 03B5
    03B8PC/XT/ATVideor/wMDA mode control register
    03B9PC/XT/ATVideoreserved for color select register on color adapter
    03BAPC/XT/ATVideorCRT status register EGA/VGA: input status 1 register
    03BAPC/XT/ATVideowEGA/VGA feature control register
    03BBPC/XT/ATVideoreserved for light pen strobe reset
    03BC-03BFPC/XT/ATVideoParallel printer port, same as 0278 and 0378
    03BCPC/XT/ATVideowdata port
    03BDPC/XT/ATVideor/wstatus port
    03BEPC/XT/ATVideor/wcontrol port
    03BFVideor/wHercules configuration switch register
    03C0-03CFVideoEGA (1st Enhanced Graphics Adapter) alternate at 02C0
    03C0Video(r)/w EGA VGA ATC index/data register
    03C1VideorVGA other attribute register
    03C2VideorEGA VGA input status 0 register
    03C3Videor/wVGA video subsystem enable (see also port 46E8h)
    03C4VideowEGA TS index register
    03C5VideowEGA TS data register
    03C6Videor/wVGA PEL mask register
    03C7Videor/wVGA PEL address read mode
    03C8Videor/wVGA PEL address write mode
    03C9Videor/wVGA PEL data register
    03CAVideowEGA graphics 2 position register
    03CCVideowEGA graphics 1 position register
    03CEVideowEGA GDC index register
    03CFVideowEGA GDC data register
    03D0-03DFVideoCGA (Color Graphics Adapter)
    03D0Videosame as 03D4
    03D1Videosame as 03D5
    03D2Videosame as 03D4
    03D3Videosame as 03D5
    03D4VideowCRTC (6845) index register (EGA/VGA)
    03D5VideowCRTC (6845) data register (EGA/VGA)
    03D6Videosame as 03D4
    03D7Videosame as 03D5
    03D8Videor/wCGA mode control register (except PCjr)
    03D9Videor/wCGA palette register
    03DAVideorCGA status register
    03DAVideorEGA/VGA input status 1 register
    03DAVideowEGA/VGA feature control register
    03DBVideowclear light pen latch
    03DCVideor/wpreset light pen latch
    03DFPCjrSystemCRT/CPU page register (PCjr only)
    03E8-03EFPC/XT/ATSerialserial port, same as 02E8, 02F8 and 03F8
    03F0-03F7ATFDCFDC 1 (1st Floppy Disk Controller) - second FDC at 0370
    03F0PC/XT/ATFDCrdiskette EHD controller board jumper settings (82072AA)
    03F2PC/XT/ATFDCwdiskette controller DOR (Digital Output Register)
    03F3PC/XT/ATFDCtape drive register (on the 82077AA)
    03F4PC/XT/ATFDCrdiskette controller main status register
    03F4PC/XT/ATFDCwdiskette controller data rate select register
    03F5PC/XT/ATFDCrdiskette command/data register 0 (ST0)
    03F5PC/XT/ATFDCwdiskette command register
    03F6PC/XT/ATFDCr/wFIXED disk controller data register
    03F7PC/XT/ATFDCr/wharddisk controller
    03F7AT/XTFDCrdiskette controller DIR (Digital Input Register, PC/AT mode)
    03F7AT/XTFDCwconfiguration control register (PC/AT, PS/2)
    03F8-03FFPC/XT/ATSerialSerial port (8250,8251,16450,16550,16550A,etc.)
    03F8PC/XT/ATSerialwSerial port, transmitter holding register
    03F9PC/XT/ATSerialr/wSerial port, divisor latch high byte when DLAB==1
    03F9PC/XT/ATSerialr/wSerial port, interrupt enable register when DLAB==0
    03FAPC/XT/ATSerialrSerial port, interrupt identification register
    03FAPC/XT/ATSerialw16650 FCR (FIFO Control Register)
    03FBPC/XT/ATSerialr/wline control register
    03FCPC/XT/ATSerialr/wmodem control register
    03FDPC/XT/ATSerialrline status register
    03FEPC/XT/ATSerialrmodem status register
    03FFPC/XT/ATSerialr/wscratch register
    0530-0533PC/XT/ATSoundGravis UltraSound Daughter Card
    0620-0627XTNetworkPC network (adapter 1)
    0628-062FXTNetworkPC network (adapter 2)
    0680PC/XT/ATSystemwMicrochannel POST Diagnostic
    06E8-06EFPC/XT/ATVideo8514/A and compatible video cards
    0746PC/XT/ATSoundGravis UltraSound
    0800-08FFPC/XT/ATSystemI/O port access registers for extended CMOS RAM or SRAM
    0A20-0A23PC/XT/ATNetworkToken Ring (adapter 1)
    0A24-0A27PC/XT/ATNetworkToken Ring (adapter 2)
    0AE8-0AEFPC/XT/ATVideo8514/A and compatible video cards
    0EE8-0EEFPC/XT/ATVideo8514/A and compatible video cards
    12E8-12EFPC/XT/ATVideo8514/A and compatible video cards
    16E8-16EFPC/XT/ATVideo8514/A and compatible video cards
    1AE8-1AEFPC/XT/ATVideo8514/A and compatible video cards
    1EE8-1EEFPC/XT/ATVideo8514/A and compatible video cards
    2100-210FPC/XT/ATVideoIBM XGA (eXtended Graphics Adapter 8514/A) (first installed)
    2110-217FPC/XT/ATVideosecondary XGA adapters
    22E8-22EFPC/XT/ATVideo8514/A and compatible video cards
    3220-3227PC/XT/ATSerialserial port 3, description same as 03F8
    3228-322FPC/XT/ATSerialserial port 4, description same as 03F8
    3540-354FPC/XT/ATSCSIIBM SCSI (Small Computer System Interface) adapter
    3550-355FPC/XT/ATSCSIIBM SCSI (Small Computer System Interface) adapter
    3560-356FPC/XT/ATSCSIIBM SCSI (Small Computer System Interface) adapter
    3570-357FPC/XT/ATSCSIIBM SCSI (Small Computer System Interface) adapter
    4220-4227PC/XT/ATSerialserial port, description same as 03F8
    4228-422FPC/XT/ATSerialserial port, description same as 03F8
    42E0-42EFPC/XT/ATGPIBGPIB (General Purpose Interface Bus, IEEE 488 interface)
    46E8PC/XT/ATVideoVGA video adapter enable
    4AE8-4AEFPC/XT/ATVideo8514/A and compatible video cards
    5220-5227PC/XT/ATSerialserial port, description same as 03F8
    5228-522FPC/XT/ATSerialserial port, description same as 03F8
    62E0-62EFPC/XT/ATGPIBGPIB (General Purpose Interface Bus, IEEE 488 interface)
    82E0-82EFPC/XT/ATGPIBGPIB (General Purpose Interface Bus, IEEE 488 interface)
    82E8-82EFPC/XT/ATVideo8514/A and compatible video cards
    8AE8-8AEFPC/XT/ATVideo8514/A and compatible video cards
    8EE8-8EEFPC/XT/ATVideo8514/A and compatible video cards
    92E8-92EFPC/XT/ATVideo8514/A and compatible video cards
    96E8-96EFPC/XT/ATVideo8514/A and compatible video cards
    A2E0-A2EFPC/XT/ATGPIBGPIB (General Purpose Interface Bus, IEEE 488 interface)
    A2E8-A2EFPC/XT/ATVideo8514/A and compatible video cards
    A6E8-A6EFPC/XT/ATVideo8514/A and compatible video cards
    AAE8-AAEFPC/XT/ATVideo8514/A and compatible video cards
    AEE8-AEEFPC/XT/ATVideo8514/A and compatible video cards
    B220-B227PC/XT/ATSerialserial port, description same as 03F8
    B228-B22FPC/XT/ATSerialserial port, description same as 03F8
    B2E8-B2EFPC/XT/ATVideo8514/A and compatible video cards
    B6E8-B6EFPC/XT/ATVideo8514/A and compatible video cards
    BAE8-BAEFPC/XT/ATVideo8514/A and compatible video cards
    BEE8-BEEFPC/XT/ATVideo8514/A and compatible video cards
    C220-C227PC/XT/ATSerialserial port, description same as 03F8
    C228-C22FPC/XT/ATSerialserial port, description same as 03F8
    C2E0-C2EFPC/XT/ATGPIBGPIB (General Purpose Interface Bus, IEEE 488 interface)
    D220-D227PC/XT/ATSerialserial port, description same as 03F8
    D228-D22FPC/XT/ATSerialserial port, description same as 03F8
    E2E0-E2EFPC/XT/ATGPIBGPIB (General Purpose Interface Bus, IEEE 488 interface)
    E2E8-E2EFPC/XT/ATVideo8514/A and compatible video cards

    Primary Emulation Resources

    BIOS Interrupt Reference

    Video References

    This section contains reference material for video adapters.

    BIOS Video Modes

    This table is courtesy of minuszerodegrees.net.

        = HSYNC: positive at 18.43 kHz, VSYNC: negative at 50 Hz
        = HSYNC: positive at 15.7 kHz, VSYNC: positive at 60 Hz       (a.k.a. EGA Mode 1)
        = HSYNC: positive at 21.85 kHz, VSYNC: negative at 60 Hz    (a.k.a. EGA Mode 2 or EGA High Resolution)
        = HSYNC: 31.5 kHz, VSYNC: 70 Hz
        = HSYNC: 31.5 kHz, VSYNC: 60 Hz

      Text /
    Graphics
    Size Mono / Color /
    Grayscale
    IBM MDA card IBM EGA
    with
    MDA monitor
    (see note 1)
    IBM CGA card IBM PCjr /
    Tandy 1000
    IBM EGA card
    with
    CGA monitor
    (see note 1)
    IBM EGA card
    with
    EGA monitor
    MCGA Standard
    VGA
    00h Text 40x25 chars Grayscale - - Yes
    shades:16
    320x200
    char:8x8
    Yes
    shades:16
    320x200
    char:8x8
    Yes
    shades:16
    320x200
    char:8x8
    Yes
    shades:16
    320x350
    char:8x14
    Yes
    shades:16
    320x400
    char:8x16
    Yes
    shades:16
    360x400
    char:9x16
    01h Text 40x25 chars Color - - Yes
    Colors:16
    320x200
    char:8x8
    Yes
    Colors:16
    320x200
    char:8x8
    Yes
    Colors:16
    320x200
    char:8x8
    Yes
    Colors:16
    320x350
    char:8x14
    Yes
    Colors:16
    320x400
    char:8x16
    Yes
    Colors:16
    360x400
    char:9x16
    02h Text 80x25 chars Grayscale - - Yes
    shades:16
    640x200
    char:8x8
    Yes
    shades:16
    640x200
    char:8x8
    Yes
    shades:16
    640x200
    char:8x8
    Yes
    shades:16
    640x350
    char:8x14
    Yes
    shades:16
    640x400
    char:8x16
    Yes
    shades:16
    720x400
    char:9x16
    03h Text 80x25 chars Color - - Yes
    Colors:16
    640x200
    char:8x8
    Yes
    Colors:16
    640x200
    char:8x8
    Yes
    Colors:16
    640x200
    char:8x8
    Yes
    Colors:16
    640x350
    char:8x14
    Yes
    Colors:16
    640x400
    char:8x16
    Yes
    Colors:16
    720x400
    char:9x16
    04h Graphics 320x200 Color - - Yes
    Colors:4
    Yes
    Colors:4
    Yes
    Colors:4
    Yes
    Colors:4
    Yes
    Colors:4
    Yes
    Colors:4
    05h Graphics 320x200 Grayscale - - Yes
    shades:4
    Yes
    shades:4
    Yes
    shades:4
    Yes
    shades:4
    Yes
    shades:4
    Yes
    shades:4
    06h Graphics 640x200 Mono - - Yes Yes Yes Yes Yes Yes
    07h Text 80x25 chars Mono Yes
    720x350
    char:9x14
    Yes
    720x350
    char:9x14
    (see note 2)
    - - - - - -
    08h Graphics 160x200 Color - - - Yes
    Colors:16
    - - - -
    09h Graphics 320x200 Color - - - Yes
    Colors:16
    - - - -
    0Ah Graphics 640x200 Color - - - Yes
    Colors:4
    - - - -
    0Bh       - [EGA internal use] - - [EGA internal use] [EGA internal use] - -
    0Ch       - [EGA internal use] - - [EGA internal use] [EGA internal use] - -
    0Dh Graphics 320x200 Color - - - - Yes
    Colors:16
    Yes
    Colors:16
    - Yes
    Colors:16
    0Eh Graphics 640x200 Color - - - - Yes
    Colors:16
    Yes
    Colors:16
    - Yes
    Colors:16
    0Fh Graphics 640x350 Mono - Yes - - - - - Yes
    10h Graphics 640x350 Color - - - - - Yes
    Colors:
    4 for 64KB
    16 for 128KB
    (see note 3)
    - Yes
    Colors:16
    11h Graphics 640x480 Mono - - - - - - Yes Yes
    12h Graphics 640x480 Color - - - - - - - Yes
    Colors:16
    13h Graphics 320x200 Color - - - - - - Yes
    Colors:256
    Yes
    Colors:256



    Note 1:

    Changing the monitor type on an IBM EGA card requires that switches on the IBM EGA card be changed.

    Note 2:

    Register and attribute behaviour is not quite the same as an MDA card. For more info, read the first page of the document here.

    Note 3:

    4 Colors if 64KB of RAM fitted to EGA video card; 16 Colors if 128KB (or more) of RAM fitted.

    Primary Emulation Resources

    EGA DIP Switch Settings

    SW1SW2SW3SW4Primary CardEGA Monitor TypeDIP Hex
    0 (ON)0 (ON)0 (ON)0 (ON)MDA Primary + EGAColor (40x25)0
    1 (OFF)0 (ON)0 (ON)0 (ON)MDA PrimaryColor (80x25)1
    0 (ON)1 (OFF)0 (ON)0 (ON)MDA Primary + EGAEnhanced Color (in Normal Color Mode)2
    1 (OFF)1 (OFF)0 (ON)0 (ON)MDA Primary + EGAEnhanced Color (in Enhanced Color Mode)3
    0 (ON)0 (ON)1 (OFF)0 (ON)CGA Primary + EGAMonochrome (CGA Color (40x25))4
    1 (OFF)0 (ON)1 (OFF)0 (ON)CGA Primary + EGAMonochrome (CGA Color (80x25))5
    0 (ON)1 (OFF)1 (OFF)0 (ON)EGA Primary + MDAColor (40x25)6
    1 (OFF)1 (OFF)1 (OFF)0 (ON)EGA Primary + MDAColor (80x25)7
    0 (ON)0 (ON)0 (ON)1 (OFF)EGA Primary + MDAEnhanced Color (in Normal Color Mode)8
    1 (OFF)0 (ON)0 (ON)1 (OFF)EGA Primary + MDAEnhanced Color (in Enhanced Color Mode)9
    0 (ON)1 (OFF)0 (ON)1 (OFF)EGA Primary + CGAMonochrome (CGA Color (40x25))A
    1 (OFF)1 (OFF)0 (ON)1 (OFF)EGA Primary + CGAMonochrome (CGA Color (80x25))B
    0 (ON)0 (ON)1 (OFF)1 (OFF)reservedreservedreserved
    1 (OFF)0 (ON)1 (OFF)1 (OFF)reservedreservedreserved
    0 (ON)1 (OFF)1 (OFF)1 (OFF)reservedreservedreserved
    1 (OFF)1 (OFF)1 (OFF)1 (OFF)reservedreservedreserved

    Most EGA clone cards used the same settings - perhaps defining special interpretations of the last four unused settings on the original IBM EGA.

    VGA cards or other cards without such DIP switches emulated the closest appropriate DIP HEX value to store in the BDA.

    Note that DIP switches are read by the PC logically reversed. A switch that is ON reads logical low (0) while a switch that is OFF reads logically high (1).

    Primary Emulation Resources

    EGA Registers

    Most register references you will find online are for the VGA exclusively, or else intermingle EGA and VGA to the point where it can be confusing if you are looking for a EGA specific reference.

    Every bit listed in this section is specific to the original IBM EGA, unless where noted.

    NOTE: The original IBM EGA and several clones have jumpers that can invert address line A09 during port decoding. This causes all the 3XX range registers to be decoded at 2XX. This is a fairly obscure feature and I am not aware of anything that uses it - even video BIOS routines will typically fail to control the card with this jumper set.

    The EGA can switch between a port base of 3DX and 3BX for the CRTC and Input Status Register 1 registers - this is primarily for MDA compatibility. The EGA may configure itself this way on boot depending on the status of the EGA DIP Switches.

    Indexed Registers

    Register indexing is a common way to reduce the complexity of address decoding and conserve the IO address space. In its most common form, it consists of a pair of registers - an address port and a data port. First, a byte address or register index is written to the address port. This selects the desired register, assuming it represents a valid index. Then, with the desired register selected, the new value for the register is written to the data port. The address port and data port are typically consecutive IO addresses, with the address port at an even address. There is a good reason for this.

    A consequence of the 8088’s transparent 8-bit bus is that an indexed register can be selected and written to via a single word-sized OUT. The data byte is typically packed into AH, with the address in AL. The 8088’s BIU will convert the word write into two 8-bit writes at the base IO address and then the base address + 1. On the AT and subsequent 16-bit architectures, this conversion had to be specifically emulated by hardware on the motherboard.

    Indexed registers can also be implemented via an internal flip-flop, where only a single IO port is required. The first write will set the register index, the second write will set the corresponding register data. Under this scheme there must be a way to reset the flip-flop to a known state. This technique is used for the EGA’s single Attribute Controller IO port, which can be reset by reading Input Status Register 1 at either 3DAh or 3BAh, depending on the EGA’s current base address.

    Register File Overview

    I/O AddressRead FunctionWrite Function
    3B4 / 3D4Not ReadableCRTC Address Register
    3B5 / 3D5Not ReadableCRTC Data Register
    3BA / 3DAInput Status Register 1Feature Control Register
    3C0Not ReadableAttribute Controller
    3C2Input Status Register 0Miscellaneous Output Register
    3C4Not ReadableSequencer Address Register
    3C5Not ReadableSequencer Data Register
    3CENot ReadableGraphics Controller Address Register
    3CFNot ReadableGraphics Controller Data Register

    Register Set Details Index

    CRTC Registers

    The EGA uses a custom LSI CRTC chip. It is very similar in operation to the Motorola 6845, but defines most vertical counters in units of scanlines. Using scanlines as the vertical unit is more convenient for a graphics-mode oriented video adapter. It also has the big advantage of not requiring any memory-addressing tricks that lead to inconvenient video memory layouts on the CGA and Hercules cards.

    Most of the EGA CRTC registers are write-only, with the exception of the three register pairs that hold memory addresses - the Start Address, Cursor Location, and Light Pen address registers can be read out. The inability to read the EGA CRTC registers was an annoyance for graphics and games programmers everywhere. This was rectified on the VGA which made most of the register file readable, but much software written for 4bpp modes did not rely on this to maintain backwards compatibility.

    IndexRegister NameAccessDescription
    00hHorizontal TotalWTotal character clocks in a scanline, minus 2
    01hHorizontal Display EndWNumber of characters visible per line
    02hStart Horizontal BlankWCharacter position where horizontal blanking begins
    03hEnd Horizontal BlankWCharacter position where horizontal blanking ends
    04hStart Horizontal RetraceWCharacter position where horizontal retrace begins
    05hEnd Horizontal RetraceWCharacter position where horizontal retrace ends
    06hVertical TotalWTotal number of scanlines per frame
    07hOverflowWHigh bits for V-Total, V-Display, V-Sync
    08hPreset Row ScanWStarting scanline within a character cell
    09hMax Scan LineWHeight of character cell minus 1
    0AhCursor StartWTop scanline of cursor
    0BhCursor EndWBottom scanline of cursor
    0ChStart Address HighRWHigh byte of display memory start pointer
    0DhStart Address LowRWLow byte of display memory start pointer
    0EhCursor Location HighRWHigh byte of cursor memory address
    0FhCursor Location LowRWLow byte of cursor memory address
    10hVertical Retrace StartWScanline where Vertical Retrace begins
    10hLight Pen Address HighRHigh byte of Light Pen latched memory address
    11hVertical Retrace EndWScanline where Vertical Retrace ends (Bits 0-3)
    11hLight Pen Address LowRLow byte of Light Pen latched memory address
    12hVertical Display EndWLast visible scanline (low 8 bits)
    13hOffsetWSpan width of logical scanline
    14hUnderline LocationWScanline within cell for underline
    15hStart Vertical BlankWScanline where blanking starts
    16hEnd Vertical BlankWScanline where blanking ends
    17hMode ControlWHardware compatibility/timing toggles
    18hLine CompareWScanline on which CRTC start address is reset

    Graphics Controller Registers

    PortRegister NameAccess
    3CCGraphics 1 PositionW
    3CAGraphics 2 PositionW
    3CEGraphics AddressW
    3CFGraphics DataW

    On the original IBM EGA, there are two separate Graphics Controller chips. They can generally be treated as a single entity except for the two Graphics Position registers. These two registers are used to tell each of the graphics controllers which pair of graphics planes they will be managing.

    The Graphics Controller chips lack an IOW pin, thus all their registers are write-only.

    Graphics Controller Indexed Registers

    IndexRegister Name
    00hSet/Reset
    01hEnable Set/Reset
    02hColor Compare
    03hData Rotate
    04hRead Map Select
    05hMode Register
    06hMiscellaneous
    07hColor Don’t Care
    08hBit Mask

    Sequencer Registers

    PortRegister NameAccess
    3C4Sequencer AddressW
    3C5Sequencer DataW

    Sequencer Indexed Registers

    IndexRegister Name
    00hReset
    01hClocking Mode
    02hMap Mask
    03hCharacter Map Select
    04hMemory Mode

    Attribute Controller Registers

    PortRegister NameAccess
    3BA / 3CAReset Attribute Flip-FlopR
    3C0Address / Data (Flip-flops on each write)W

    Attribute Controller Indexed Registers

    IndexRegister NameAccess
    00h-0FhAttribute Palette Entries [0-F]W*
    10hMode ControlW
    11hOverscan ColorW
    12hColor Plane EnableW
    13hHorizontal Pel PanningW

    The first sixteen registers in the Attribute Controller define a 4bpp palette.

    External Register Details

    Miscellaneous Output RegisterControls basic hardware configuration such as IO address and clock selectionMiscellaneous Output RegisterControls basic hardware configuration such as IO address and clock selection3C2 (Write-Only)76543210VSPHSPPAGEDISABLECLKERAMIO
    BitsNameDescription
    0IOI/O Address (0=3Bx mono, 1=3Dx color)
    1ERAMEnable RAM (1=Enabled)
    2:3CLKClock Select (00=14MHz, 01=16MHz, 10=External, 11=Unused)
    4DISABLEDisable Video Drivers (1=Disable)
    5PAGEPage bit for Odd/Even mode
    6HSPHorizontal Sync Polarity (0=Pos, 1=Neg)
    7VSPVertical Sync Polarity (0=Pos, 1=Neg)
    Feature Control RegisterSet control signals sent to the EGA Feature ConnectorFeature Control RegisterSet control signals sent to the EGA Feature Connector3BA / 3DA (Write-Only)76543210--ReservedFC1FC0
    BitsNameDescription
    0FC0Feature Control Bit 0
    1FC1Feature Control Bit 1
    2:3ReservedReserved
    4:7Unused
    Input Status Register 0Read DIP switches and interrupt statusInput Status Register 0Read DIP switches and interrupt status3C2 (Read-Only)76543210INTFEAT1FEAT0SENSE--
    BitsNameDescription
    0:3Unused
    4SENSESwitch Sense - State of selected configuration switch
    5FEAT0State of FEAT0 pin on Feature Connector
    6FEAT1State of FEAT1 pin on Feature Connector
    7INTCRT Interrupt Pending (1=Yes)

    Attribute Controller Register Details

    Attribute Palette EntryUsed by the Attribute Controller to look up an output color from a 4bpp pixel indexAttribute Palette EntryUsed by the Attribute Controller to look up an output color from a 4bpp pixel index3C0 Index 0-Fh (Write-Only)76543210UnusedSRSG/ISB/IRGB
    BitsNameDescription
    0BBlue
    1GGreen
    2RRed
    3SB/ISecondary Blue / Mono Intensity
    4SG/ISecondary Green / Intensity
    5SRSecondary Red
    6:7UnusedUnused
    Attribute Mode ControlSpecifies general mode options for Attribute Controller operationAttribute Mode ControlSpecifies general mode options for Attribute Controller operation3C0 Index 10h (Write-Only)76543210UnusedB/ILGDTG/A
    BitsNameDescription
    0G/AVideo Mode:
    1: Graphics Mode
    0: Alphanumeric Mode
    1DTText Attribute Type:
    0: Color
    1: MDA
    2LGEnable Line Graphics Characters
    3B/IAttribute Bit 7 interpreted as:
    1: Blink Enabled
    0: Background Intensity
    4:7UnusedUnused
    Overscan Color RegisterSelects the color to use when drawing the overscan areaOverscan Color RegisterSelects the color to use when drawing the overscan area3C0 Index 11h (Write-Only)76543210UnusedSRSG/ISB/IRGB
    BitsNameDescription
    0BBlue
    1GGreen
    2RRed
    3SB/ISecondary Blue
    4SG/ISecondary Green / Intensity
    5SRSecondary Red
    6:7UnusedUnused
    Color Plane Enable RegisterControls which bits are enabled when addressing the palette registersColor Plane Enable RegisterControls which bits are enabled when addressing the palette registers3C0 Index 12h (Write-Only)76543210UnusedMUXECP
    BitsNameDescription
    0:3ECPEnable Color Planes
    Each bit set in this field enables the corresponding plane 0-3.
    4:5MUXVideo Status MUX
    6:7UnusedUnused
    Horizontal Pel Panning RegisterShifts the display horizontally to the leftHorizontal Pel Panning RegisterShifts the display horizontally to the left3C0 Index 13h (Write-Only)76543210UnusedPAN
    BitsNameDescription
    0:3PANHorizontal Pel Panning Value
    EGA Mode: 0-7
    Monochrome Mode: 8,0-7
    4:7UnusedUnused

    SuperEGA Registers

    There were several video chipset manufacturers who produced EGA chipsets with extended capabilities, most typically an increased resolution of 640x480. These adapters were typically called SuperEGAs.

    SuperEGA chipsets often extended the standard EGA register file, with new register indices defined for the CRTC, graphics controllers, sequencer and attribute controller.

    ET2000

    The Tseng Labs ET2000 was an advanced chipset designed to be adaptable to a variety of different graphics adapters, although it only ever appeared on three EGA cards: the Tseng Labs EVA and EVA/480, and the NEC GB-1 (a rebadged EVA/480). The plain EVA model lacks the 25MHz clock that allows 640x480 resolution.

    It is comprised of three VLSI chips in PLCC68 packages:

    ChipFunction
    ET2000CRTC / Sequencer
    ET2001Attribute Controller
    ET2002Graphics Controller

    A fourth chip, the ET2003 bit-slice processor, was announced but never saw production.

    Clocking Select Bits

    As with most SuperEGAs, the ET2000 in its full incarnation is typically paired with a 25MHz pixel clock - it also has a third crystal, a 19.96608MHz clock that is used as a pixel clock in 132 column modes, as well as clocking the memory address multiplexers.

    bitsclock select
    0014.381818MHz (OSC pin from ISA bus)
    0116.257MHz
    1025MHz or external OSC (J3)
    1119.96608MHz

    Extended General Registers

    PortAccessDescription
    7CXhWCMII Activation Port
    3C8hWCMII Command Port

    These are essentially the same decoded port - the CMII compatibility module will respond to A10 set as a special ‘wake’ address. It must be written to twice, with a data byte that has bits 7 and 6 set, to activate the card and begin hooking IO writes for translation.

    Extended CRTC Registers

    IndexNameAccessDescription
    19hOverflow #2WHigh bits for V-Total, V-Display, V-Sync
    1Ah?WET2000 BIOS sets bit 1 then reads 12h (?)
    1BhX Zoom Start Column?Character clock of zoom viewport start
    1ChX Zoom End Column?Character clock of zoom viewport end
    1DhY Zoom Start Scanline?Scanline on which zoom viewport starts
    1EhY Zoom End Scanline?Scanline on which zoom viewport ends
    1FhY Zoom Start and End Scanline High?
    20hZoom Start Address Low?
    21hZoom Start Address Middle?
    22h??
    23h??
    24h??
    25h??

    Extended Sequencer Registers

    IndexNameAccessDescription
    06hZoom TimingWControls timings for zoom/viewport feature
    07hCharacter TimingWSet to 03, 02 or 01 in large column modes

    Extended Graphics Controller Registers

    IndexNameAccessDescription
    0Dh?WInitialized to 0

    Extended Attribute Controller Registers

    IndexNameAccessDescription
    14h?WInitialized to 0
    15h?WInitialized to 0
    16h?WBit 1 set in 132 column modes

    Video Palettes

    CGA Text Mode

    In color text modes, the CGA card can emit a total of 16 different colors - a combination of the four video signals: red, green, blue, and intensity - a signal that boosts the brightness of the previous three color signals. Note that the intensity bit also boosts the apparent brightness of pure black, creating a dim gray.

    NOTE: The standard CGA brown color is not actually a color emitted by the CGA card; the conversion of ‘dark yellow’ to brown occurs via special circuitry within the IBM 5153 Color Display and most CGA-compatible monitors.

    Full RGBI Palette

    R G B I Color Hex
    0000 000000
    0010 0000AA
    0100 00AA00
    0110 00AAAA
    1000 AA0000
    1010 AA00AA
    1100 AA5500
    1110 AAAAAA
    0001 555555
    0011 5555FF
    0101 55FF55
    0111 55FFFF
    1001 FF5555
    1011 FF55FF
    1101 FFFF55
    1111 FFFFFF

    The “IBM 5153” Palette

    The aforementioned palette represents “ideal” colors - theoretically perfect color outputs. Modern displays have no problem rendering such colors, but original CGA monitors such as the IBM 5153 Color Display had their own eccentricities.

    Taking into account the electrical characteristics of the 5153, a more visually authentic CGA palette can be derived:

    R G B I Color Hex
    0000 000000
    0010 0000C4
    0100 00C400
    0110 00C4C4
    1000 C40000
    1010 C400C4
    1100 C47E00
    1110 C4C4C4
    0001 4E4E4E
    0011 4E4EDC
    0101 4EDC4E
    0111 4EF3F3
    1001 DC4E4E
    1011 F34EF3
    1101 F3F34E
    1111 FFFFFF

    CGA Graphics Modes

    Although much is said - derisively - about the CGA’s ugly ‘palettes’, the IBM CGA card does not actually have what we would typically consider palettes at all.

    In graphics mode, pairs of bits from video memory drive the red and green video output lines directly, with no color look-ups performed. The effect of having multiple palettes is produced by miscellaneous logic that determines if and when the blue video output is additionally enabled or not.

    When both bits from video memory are 0, the background/overscan color configured in the CGA Color Control register is substituted. Black is not a requirement for any of the CGA’s palettes.

    The intensity bit, specified in the CGA Color Control register, provides two variations of brightness per palette.

    Default Palette (Blue Disabled)

    R G B I Color Hex
    0000 Overscan
    0100 00AA00
    1000 AA0000
    1100 AA5500
    R G B I Color Hex
    0001 Overscan
    0101 55FF55
    1001 FF5555
    1101 FFFF55

    Secondary Palette (Blue Enabled)

    R G B I Color Hex
    0000 Overscan
    0110 00AAAA
    1010 AA00AA
    1110 AAAAAA
    R G B I Color Hex
    0001 Overscan
    0111 55FFFF
    1011 FF55FF
    1111 FFFFFF

    Alternate Palette (Blue Enabled Except When Red)

    Sometimes described as a “hidden” palette, and often considered the most aesthetically pleasing, the cyan-red-white palette was only implemented to provide better contrast when displaying CGA graphics modes on a monochrome composite display, such as a black-and-white television set. It was not implemented for its aesthetics, and thus IBM probably didn’t see fit to document it as a color option - after all, later revisions of the CGA could have always disabled the need for it by adjustments to the composite output circuitry.

    This palette is created by miscellaneous logic that enables the blue video output unless the color red is decoded.

    R G B I Color Hex
    0000 Overscan
    0110 00AAAA
    1000 AA0000
    1110 AAAAAA
    R G B I Color Hex
    0001 Overscan
    0111 55FFFF
    1001 FF5555
    1111 FFFFFF

    EGA 6-bit Palette (64 Colors)

    The EGA can display any 16 of these 64 colors simultaneously when connected to an EGA monitor and operating in 350 line mode, although there are exceptions that enable use of 6bpp color in 200 line modes with the right hardware.

    IndexRIGIBIRGBColorHex IndexRIGIBIRGBColorHex
    00000000 00000020100000 550000
    01000001 0000AA21100001 5500AA
    02000010 00AA0022100010 55AA00
    03000011 00AAAA23100011 55AAAA
    04000100 AA000024100100 FF0000
    05000101 AA00AA25100101 FF00AA
    06000110 AAAA0026100110 FFAA00
    07000111 AAAAAA27100111 FFAAAA
    08001000 00005528101000 550055
    09001001 0000FF29101001 5500FF
    0A001010 00AA552A101010 55AA55
    0B001011 00AAFF2B101011 55AAFF
    0C001100 AA00552C101100 FF0055
    0D001101 AA00FF2D101101 FF00FF
    0E001110 AAAA552E101110 FFAA55
    0F001111 AAAAFF2F101111 FFAAFF
    10010000 00550030110000 555500
    11010001 0055AA31110001 5555AA
    12010010 00FF0032110010 55FF00
    13010011 00FFAA33110011 55FFAA
    14010100 AA550034110100 FF5500
    15010101 AA55AA35110101 FF55AA
    16010110 AAFF0036110110 FFFF00
    17010111 AAFFAA37110111 FFFFAA
    18011000 00555538111000 555555
    19011001 0055FF39111001 5555FF
    1A011010 00FF553A111010 55FF55
    1B011011 00FFFF3B111011 55FFFF
    1C011100 AA55553C111100 FF5555
    1D011101 AA55FF3D111101 FF55FF
    1E011110 AAFF553E111110 FFFF55
    1F011111 AAFFFF3F111111 FFFFFF

    The Default VGA Palette

    The VGA has a total palette of 256 out of 262,144 colors, making a full table a bit impractical. The default VGA palette is shown below.

    The VGA still has the 16 Attribute Controller Palette registers, which are used in text mode and 4bpp modes, however they no longer store color information. Instead, they contain indexes into the 256 color registers of the DAC. This DAC lookup is always active.

    The first 16 colors of the default VGA palette correspond to the traditional 16 color RGBI palette, and so the Attribute Palette registers reference the same colors by virtue of being initialized with the values 0-F. The Attribute Palette registers remain 6 bits, and so they can only reference a total of 64 DAC Color registers. Due to this, the VGA divides the 256 total Color registers into four separate banks, which can be selected independently.

    0000000000AA00AA0000AAAAAA0000AA00AAAA5500AAAAAA5555555555FF55FF5555FFFFFF5555FF55FFFFFF55FFFFFF
    0000001414142020202C2C2C383838454545515151616161717171828282929292A2A2A2B6B6B6CBCBCBE3E3E3FFFFFF
    0000FF4100FF7D00FFBE00FFFF00FFFF00BEFF007DFF0041FF0000FF4100FF7D00FFBE00FFFF00BEFF007DFF0041FF00
    00FF0000FF4100FF7D00FFBE00FFFF00BEFF007DFF0041FF7D7DFF9E7DFFBE7DFFDF7DFFFF7DFFFF7DDFFF7DBEFF7D9E
    FF7D7DFF9E7DFFBE7DFFDF7DFFFF7DDFFF7DBEFF7D9EFF7D7DFF7D7DFF9E7DFFBE7DFFDF7DFFFF7DDFFF7DBEFF7D9EFF
    B6B6FFC7B6FFDBB6FFEBB6FFFFB6FFFFB6EBFFB6DBFFB6C7FFB6B6FFC7B6FFDBB6FFEBB6FFFFB6EBFFB6DBFFB6C7FFB6
    B6FFB6B6FFC7B6FFDBB6FFEBB6FFFFB6EBFFB6DBFFB6C7FF0000711C007138007155007171007171005571003871001C
    710000711C007138007155007171005571003871001C710000710000711C007138007155007171005571003871001C71
    383871453871553871613871713871713861713855713845713838714538715538716138717138617138557138457138
    387138387145387155387161387171386171385571384571515171595171615171695171715171715169715161715159
    715151715951716151716951717151697151617151597151517151517159517161517169517171516971516171515971
    000041100041200041300041410041410030410020410010410000411000412000413000414100304100204100104100
    004100004110004120004130004141003041002041001041202041282041302041382041412041412038412030412028
    412020412820413020413820414120384120304120284120204120204128204130204138204141203841203041202841
    2C2C41302C41342C413C2C41412C41412C3C412C34412C30412C2C41302C41342C413C2C41412C3C412C34412C30412C
    2C412C2C41302C41342C413C2C41412C3C412C34412C3041000000000000000000000000000000000000000000000000

    Primary Emulation Resources