Understanding the EGA/VGA Scrolling Artifact at Line 205

When programming retro graphics hardware in x86 assembly, implementation details between legacy display adapters (MDA and CGA) and newer cards (EGA and VGA) can introduce subtle bugs. A common problem occurs when implementing hardware scrolling via the CRT Controller (CRTC): everything works seamlessly on MDA and CGA, but on EGA and VGA adapters, the screen glitches or jumps once scrolling reaches around line 205.

The Math Behind the Glitch

To understand why line 205 is the failure point, let's look at the math involved in standard 80-column text mode:

  • Columns per line: 80
  • Target line: 205
  • Total character offset: 205 × 80 = 16,400 characters

Notice the number 16,400. In binary/hexadecimal terms, 16,384 is 0x4000 (or 214). Line 205 is the exact moment the character offset exceeds 16,384 characters.

The Root Cause: Incorrect Bit Mask Shifting

Examining the assembly code reveals where the calculation breaks down: