Video memory holds several screens at once. Function 05h tells the card to show page AL: it sets the CRT controller's start address to that page's offset, stores the page number at 40h:62h and its offset at 40h:4Eh, and moves the hardware cursor to that page's own cursor position. Nothing is copied, so the switch is instant; programs use it to build a screen out of sight and flip to it, or to keep a help screen ready.
| Mode | Pages | Page n starts at |
|---|---|---|
| 00h, 01h (40×25) | 8 | B800h:n × 800h |
| 02h, 03h (80×25) | 8 (4 on a CGA) | B800h:n × 1000h |
| 07h | 1 on an MDA, 8 on an EGA or VGA | B000h:n × 1000h |
| 0Dh, 0Eh, 10h | 8, 4, 2 (with 256K) | A000h + page size |
| 04h–06h, 12h, 13h | 1 | — |
The services that write characters at a position (02h, 03h, 08h, 09h, 0Ah, 13h) take a page in BH and work on any page, shown or not. Teletype (0Eh) and DOS output go to the active page; many BIOSes, DOSBox-X's included, ignore BH for teletype. Writing directly needs the page's address: page 1 of mode 03h starts at B800h:1000h, which is the same place as B900h:0000h. Here page 1 is filled, shown for two seconds, and page 0 comes back unharmed:
MOV AX, 0B900h ; page 1 of mode 03h: B800h:1000h = B900h:0MOV ES, AXXOR DI, DIMOV AX, 1F20h ; blanks, white on blueMOV CX, 80 * 25CLDREP STOSW ; fill page 1MOV DI, (12 * 80 + 33) * 2 ; row 12, column 33MOV SI, OFFSET TXT1MOV CX, 14 ; its lengthMOV AH, 1Fh ; white on blueNEXT1:LODSBSTOSW ; character and attributeLOOP NEXT1MOV AX, 0501h ; show page 1INT 10hMOV CX, 001Eh ; wait 2 s: CX:DX = 1E8480h microsecondsMOV DX, 8480hMOV AH, 86h ; BIOS: waitINT 15hMOV AX, 0500h ; and page 0 againINT 10hMOV AH, 09hMOV DX, OFFSET MSG1INT 21hTXT1 DB "This is page 1"MSG1 DB "Back on page 0", 13, 10, "$"
Pitfalls
Return to page 0 before exiting: DOS and most programs assume it, and DOS output would otherwise go on to the page that happens to be showing. A page nobody wrote to may hold leftovers from an earlier program, so clear it before showing it, as the example does with REP STOSW. A mode set selects page 0 again. In graphics modes the number of pages depends on the card's memory, and the VGA modes 12h and 13h have only one.