ICS312 Set 17 Introduction to Video Programming BIOS Level Video Control (INT 10H) – Display Modes • Monitors can display both text and graphics and have different techniques and memory requirements for each. Consequently, video adapters have two display modes: text and graphics. • In text mode, the screen is divided into columns and rows, typically 80 columns by 25 rows, and a character is displayed at each screen position (character cell). • In graphics mode, the screen is again divided into columns and rows, and each screen position is called a pixel (short for picture element). A picture can be displayed by specifying the color of each pixel on the screen. If one uses e.g. 64k bit color and Unidec coding, it takes 4 bytes to represent a single screen character. For the sake of simplicity, we will consider text examples using 16 bit color with ascii coding and of the many graphics mode we will consider (an easy to use) one that employs 200 rows and 320 columns BIOS Level Video Control (INT 10H) – Text Modes mode 3 Description 80 x 25 16 bit color text BIOS Level Video Control (INT 10H) – Graphics Modes Mode(hex) Description 13 320 x 200 256 color Video Display Addresses B800:0000h Standard display address for text mode Text Mode Programming • Positions on the screen are referenced using (column, row) coordinates • The upper left corner has coordinates (0,0) • For an 80 x 25 display, the rows are 0-24 and the columns are 0-79 Text Mode Programming (Cont.1) Table of some 80 x 25 screen positions Position Decimal Hexadecimal Upper left corner Lower left corner Upper right corner Lower right corner Center screen (0,0) (0,24) (79,0) (79,24) (39,12) (0,0) (0,18) (4F,0) (4F,18) (27,C) Text Mode Programming (Cont.2) • The character displayed at a screen position is specified by the contents of a WORD in the display memory. So it requires 80*25 words to specify a page, ie 4K bytes. • The low byte of the word contains the character's ASCII code; the high byte contains its attribute • Attribute tells how the character will be displayed (its color, whether it's blinking, underlined, and so on) Display Pages • Graphics adapters can store several screens of text data • To fully use the display memory, it is divided into display pages • One display page can hold the data for one screen • The pages are numbered starting with 0; the number of pages available depends on the adapter and the display mode selected. We will only use page 0 The Attribute Byte 16 bit Color Display Attribute Byte: Bit# 7 6 Attr BL R 5 G 4 B 3 IN 2 R 1 G 0 B Attributes: Bit # Attribute 0-2 3 4-6 7 character color (foreground color) intensity background color blinking The Attribute Byte (Cont.) • To display a red character on a blue background, the attribute byte would be: 0001 0100 = 14h • If the attribute byte is: 0011 0101 = 35h Uses blue + green (cyan) in the background and red+blue (magenta) in the foreground, so the character displayed would be magenta on a cyan background • If the intensity bit (bit 3) is 1, the foreground color is lightened (brightened) • If the blinking bit (bit 7) is 1, the character turns on and off Sixteen Color Text Display Basic I R G 0 0 0 0 0 0 0 0 1 0 0 1 0 1 0 0 1 0 0 1 1 0 1 1 Colors B Color 0 black 1 blue 0 green 1 cyan 0 red 1 magenta 0 brown 1 lt. grey I 1 1 1 1 1 1 1 1 R 0 0 0 0 1 1 1 1 G 0 0 1 1 0 0 1 1 Bright Colors B Color 0 dark gray 1 light blue 0 light green 1 light cyan 0 light red 1 lt magenta 0 yellow 1 white foreground colors can be either basic or bright background colors can only be basic colors The first 16 colors in graphics modes that employ large numbers of colors are the same as those on the preceeding slide A Demonstration To display a character with a given attribute at any screen position, store the character and attribute at the corresponding word in the active display page. The following program fills the color screen with red "A"s on a blue background. TITLE SCREEN DISPLAY_1 .MODEL SMALL .STACK 100H .CODE A Demonstration (Cont.1) MAIN PROC ; set ES to active display page MOV AX, 0B800H ; color active display page MOV ES, AX MOV DI, 0 ; initialize DI MOV CX, 2000 ; 80x25 = 2000 words CLD ; forward dir. for string fns ; fill active display page MOV AH, 14H ; red color on blue background MOV AL, 'A' REP STOSW ; STOSW is one of the string-handling functions. ; It writes the word in AX repetitively CX times at the ; location specified by ES:DI A Demonstration (Cont.2) MAIN MOV AH, 4CH INT 21H ENDP END MAIN After the program is run, the screen positions retain these attributes (in DOS mode) unless another program changes it, or the computer is reset (or the window is closed). INT 10h Video Functions – 00h 00h: Set Video Mode. Selects the video mode and clears the screen automatically. Two examples of video mode: Input: AH = 0 AL = 3; mode 3, giving 80 cols x 25 rows color text INT 10h Video Functions – 02h 02h: Set Cursor Position. to specified position. Input: AH DH DL BH = = = = Move cursor 2 row (0-24) col (0-79 for 80x25 display) video page number (usually 0) INT 10h Video Functions – 06h Scroll the Screen or a Window Up Input: AH = 6 AL = number of lines to scroll (0 => whole screen) BH = attribute for blank lines CL, CH = column,row for upper left corner DL, DH = column,row for lower right window INT 10h Video Functions – 06h(Cont.1) •Scrolling the screen up one line means moving each display line UP one row and inserting a blank line at the bottom of the screen •The previous top row disappears from the screen •The whole screen or any rectangular area (window) may be scrolled •AL contains the number of lines to scroll •If AL = 0, all the lines are scrolled and this clears the screen or window INT 10h Video Functions – 06h (Cont.2) Example: Clear the screen to blank for the 80x25 display. MOV AH, 6 ; scroll up function MOV AL, 0 ; clear entire screen MOV CX, 0 ; upper left corner is (0,0) MOV DL, 4FH ; lower rt. corner is (4Fh, 18H) ie (79,24) MOV DH, 18H MOV BH, 7 ; normal video attribute, a white ; foreground on a black background INT 10H INT 10h Video Functions – 09h •Write character and attribute. Display any ASCII character at current position and set desired attribute. Can be used in graphics or video mode. Input: AH = 09 AL = ASCII character code BH = video page number (usually 0) BL = attribute to be used. CX = repetition count INT 10h Video Functions – 09h (Cont.1) • Cursor does not move • If AL contains the ASCII code of a control character, a control function is not performed --- a display symbol is shown instead INT 10h Video Functions – 0Ah 0Ah:Write character. Display any ASCII character at current position without changing the current attribute. Can be used in text or video mode. Input: AH = 0Ah AL = ASCII character code BH = video page number (usually 0) CX = repetition count SUMMARY fn set cursor 02 dl,dh=col,row bh=0 scroll up 06 cl,ch bh=attrib al= amount dl,dh write char 09 al = char & attrib. bh=0 cx=count bl=attrib write char 0A al = char bh=0 cx=count A Comprehensive Example A demonstration of several of the INT 10h functions. This program: 1. Sets the display mode to 3 (80x25 16 bit color text) 2. Clears a window with upper left corner at column 26,row 8 (1Ah, 08h), and lower right corner at column 52, row 16 (34h, 10h) to cyan on red. 3. Moves the cursor to column 39, row 12 (0Ch, 27h). 4. Prints a blinking, cyan "A" at that cursor position. A Comprehensive Example (Cont.1) TITLE SCREEN DISPLAY_2 ; red screen with blinking cyan 'A' in middle of screen .MODEL SMALL .STACK 100H .CODE MAIN PROC ; set video mode MOV AH, 0 ; select mode function MOV AL, 3 ; 80x25 color text INT 10H A Comprehensive Example (Cont.2) ; clear window to red MOV AH, 6 ; scroll up function MOV CX, 081AH ; upper left corner (1Ah, 08h) MOV DX, 1034H ; lower right corner (34h, 10h) MOV BH, 43H ; cyan chars on red background MOV AL, 0 ; scroll all lines INT 10H ; move cursor MOV AH, 2 ; move cursor function MOV DX, 0C27H ; center of screen (27H, 0Ch) MOV BH, 0 ; page 0 INT 10H A Comprehensive Example (Cont.3) ; display character with attribute MOV AH, 09 ; display character function MOV BH, 0 ; page 0 MOV BL, 0C3H ; blinking cyan char (code 03H), ; on a red background (code 0cH) MOV CX, 1 ; display one character MOV AL, 'A' ; character is 'A' INT 10H ; dos exit MOV AH, 4CH INT 21H MAIN ENDP END MAIN