You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

能否不调用中断使用屏幕页?求无中断操作显存的底层方案

Absolutely! You don’t need to rely on the int 10h interrupt to switch video pages or write to the screen—you can interact directly with the VGA text mode framebuffer and hardware registers instead. Let’s break this down into actionable steps, no BIOS calls required.

Direct VGA Text Mode Basics

First, a quick primer on how text-mode video memory works:

  • For color VGA displays, the framebuffer starts at physical address 0xB8000; monochrome uses 0xB0000.
  • Each screen character occupies 2 bytes:
    1. The first byte is the ASCII value of the character.
    2. The second byte is the attribute (foreground/background color, blink status).
  • A standard 80x25 screen uses 80*25*2 = 4000 bytes per video page. So page 0 starts at 0xB8000, page 1 at 0xB8000 + 4000 = 0xB9000, page 2 at 0xBA000, and so on.

Switching Video Pages Without int 10h

To switch pages, you need to tell the VGA CRT controller to scan from the new page’s framebuffer address. This involves writing directly to the CRT’s index/data register pair:

; Switch to video page 1 (color VGA) without int 10h
mov dx, 0x3D4       ; CRT controller index port
; Set the high byte of the framebuffer start address (register 0x0C)
mov al, 0x0C
out dx, al
inc dx              ; Move to CRT data port
mov al, 0x0F        ; High byte of page 1's offset (0x0FA0 >> 8 = 0x0F)
out dx, al
dec dx              ; Back to index port
; Set the low byte of the framebuffer start address (register 0x0D)
mov al, 0x0D
out dx, al
inc dx              ; Move to data port
mov al, 0xA0        ; Low byte of page 1's offset (0x0FA0 & 0xFF = 0xA0)
out dx, al

What’s happening here?

  • The CRT controller uses registers 0x0C and 0x0D to store the starting offset of the video memory it scans for display.
  • Page 1’s offset from the base 0xB8000 is 4000 (hex 0x0FA0), so we split that into high (0x0F) and low (0xA0) bytes and write them to the respective registers.
  • For monochrome displays, use port 0x3B4 instead of 0x3D4.

Writing Characters Directly to the Framebuffer

Once you’ve switched to page 1, you can write characters directly to its memory without any interrupts. Here’s how to write a white-on-black 'A' to the top-left corner of page 1:

; Write 'A' (white on black) to page 1's top-left corner
mov ax, 0xB900      ; Page 1's segment address (0xB9000 >> 4)
mov es, ax
mov di, 0x0000      ; Offset within the page (top-left = 0)
mov ax, 0x0741      ; 0x07 = white on black attribute, 0x41 = ASCII 'A'
stosw               ; Write ax to es:di, increment di by 2 (for next character)

Or if you prefer direct absolute addressing:

mov word [0xB9000], 0x0741

Key Notes to Remember

  • This method only works in standard VGA text mode (80x25, 16-color). Graphics modes use different framebuffer layouts and registers.
  • If you’re working in a multi-tasking environment or bootloader, consider saving the original CRT register values before modifying them, then restoring them later to avoid breaking other processes.
  • To switch back to page 0, repeat the page-switch code but set the start address bytes to 0x00 (high) and 0x00 (low).

内容的提问来源于stack exchange,提问作者Ahmed Crow

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.11 07:55:39