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).

Prints "mode 03h, 80 columns, page 0" at the usual DOS prompt.
MOV AH, 0Fh ; get the video mode
INT 10h ; AL = mode, AH = columns, BH = active page
MOV [COLS1], AH
MOV [PAGE1], BH
PUSH AX ; keep the mode
MOV AH, 09h
MOV DX, OFFSET TXT1 ; "mode "
INT 21h
POP AX
CALL PHEX2 ; the mode in hex
MOV AH, 09h
MOV DX, OFFSET TXT2 ; "h, "
INT 21h
MOV AL, [COLS1]
CALL PDEC2 ; the columns in decimal
MOV AH, 09h
MOV DX, OFFSET TXT3 ; " columns, page "
INT 21h
MOV DL, [PAGE1]
ADD DL, "0" ; the page: one digit
MOV AH, 02h
INT 21h
MOV AH, 09h
MOV DX, OFFSET CRLF1
INT 21h
COLS1 DB 0
PAGE1 DB 0
TXT1 DB "mode $"
TXT2 DB "h, $"
TXT3 DB " columns, page $"
CRLF1 DB 13, 10, "$"
PHEX2: ; print AL as two hex digits; changes AX, CX, DX
PUSH AX
MOV CL, 4
SHR AL, CL ; the high nibble first
CALL PDIG1
POP AX
AND AL, 0Fh ; then the low one, falling into PDIG1
PDIG1:
ADD AL, "0"
CMP AL, "9"
JBE PDIG2
ADD AL, 7 ; "A".."F"
PDIG2:
MOV DL, AL
MOV AH, 02h ; DOS: print DL
INT 21h
RET
PDEC2: ; print AL (0..99) as two decimal digits
AAM ; AH = AL / 10, AL = AL mod 10
ADD AX, 3030h ; both into "0".."9"
PUSH AX
MOV DL, AH
MOV AH, 02h
INT 21h
POP AX
MOV DL, AL
MOV AH, 02h
INT 21h
RET

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.