CRTC hardware scrolling on EGA/VGA
17:12 28 Jul 2026

I'm attempting to program hardware scrolling with the CRTC using x86 assembly. I've gotten it working with MDA and CGA adapters, but a scrolling error occurs with EGA and VGA adapters at line 205 (around the 32K boundary in VRAM). Blank lines scroll for an entire screen, then around line 228 the text jumps to the top of the screen and scrolling continues as normal. vram_mask is set to 15-bits on EGA and VGA.

;
; Scroll the screen a specified number of lines
;
scroll:
    ; Multiply number of lines by number of columns
    ; and add to scroll offset.
    mov cx, SCR_COLS
    mul cx
    add [vscroll_offset], ax
    mov cx, [vscroll_offset]
    mov ax, [vram_mask]

    ; CRTC addresses by individual character rather than
    ; character/attribute pairs.
    shr ax, 1
    and cx, ax

    mov dx, [crtc_port]
    mov al, VSCROLL_START_LOW
    out dx, al
    inc dx
    mov al, cl
    out dx, al

    dec dx
    mov al, VSCROLL_START_HIGH
    out dx, al
    inc dx
    mov al, ch
    out dx, al

    ret

I'm linking a video depicting the error.

CRTC scrolling error on EGA/VGA adapters

assembly x86-16 hardware-interface