Function 0Fh reads the BIOS data area and returns three things at once: AL is the current mode (the one function 00h last set), AH the number of character columns, and BH the active display page. The column count is 80 in modes 02h, 03h and 07h and in the 640-pixel-wide graphics modes, 40 in modes 00h and 01h and in the 320-pixel modes, where the BIOS draws 8-pixel characters.
It is the first call of any program that changes the mode (so it can restore it at the end) or writes video memory directly (B000h for mode 07h, B800h for the colour text modes, and the right row length for the offsets).
MOV AH, 0Fh ; get the video modeINT 10h ; AL = mode, AH = columns, BH = active pageMOV [COLS1], AHMOV [PAGE1], BHPUSH AX ; keep the modeMOV AH, 09hMOV DX, OFFSET TXT1 ; "mode "INT 21hPOP AXCALL PHEX2 ; the mode in hexMOV AH, 09hMOV DX, OFFSET TXT2 ; "h, "INT 21hMOV AL, [COLS1]CALL PDEC2 ; the columns in decimalMOV AH, 09hMOV DX, OFFSET TXT3 ; " columns, page "INT 21hMOV DL, [PAGE1]ADD DL, "0" ; the page: one digitMOV AH, 02hINT 21hMOV AH, 09hMOV DX, OFFSET CRLF1INT 21hCOLS1 DB 0PAGE1 DB 0TXT1 DB "mode $"TXT2 DB "h, $"TXT3 DB " columns, page $"CRLF1 DB 13, 10, "$"PHEX2: ; print AL as two hex digits; changes AX, CX, DXPUSH AXMOV CL, 4SHR AL, CL ; the high nibble firstCALL PDIG1POP AXAND AL, 0Fh ; then the low one, falling into PDIG1PDIG1:ADD AL, "0"CMP AL, "9"JBE PDIG2ADD AL, 7 ; "A".."F"PDIG2:MOV DL, ALMOV AH, 02h ; DOS: print DLINT 21hRETPDEC2: ; print AL (0..99) as two decimal digitsAAM ; AH = AL / 10, AL = AL mod 10ADD AX, 3030h ; both into "0".."9"PUSH AXMOV DL, AHMOV AH, 02hINT 21hPOP AXMOV DL, ALMOV AH, 02hINT 21hRET
The number of rows is not returned. On an EGA or VGA it is at 40h:84h in the BIOS data area (rows minus one), and INT 10h AH=11h with AL = 30h returns it in DL; on older cards it is always 25.
Pitfalls
If the mode was set with bit 7 of AL on (the "do not clear" request of function 00h), many BIOSes return it with bit 7 set here too; AND AL, 7Fh before comparing. BH is the page being shown, not necessarily the page a program writes to. In VESA modes the answer is not meaningful: VESA has its own function for that, with AX = 4F03h.