Microprocessor and Assembly Language Lecture-12-Text Display and Keyboard Programming Muhammad Hafeez Department of Computer Science GC University Lahore
Today’s Agenda Controlling the Screen Controlling the Keyboard
The Monitor Electron gun shoot a stream on phosphorus screen Lines and dots are generated with electron gun A raster of lines is created starting from top left corner of screen
Types of Monitors Monochrome Color Single beam, single color typically amber or green Dots of different brightness is created called gray scale Color Screen is coated with RGB phosphorus, and three guns are used to create a single homogenous color
Types of Monitors Monochrome Color Single beam, single color typically amber or green Dots of different brightness is created called gray scale Color Screen is coated with RGB phosphorus, and three guns are used to create a single homogenous color
Video Adapters Video Adapter has two parts Display Memory Video Controller Display Memory address starts at segment A000h and above depending upon the type of video adapter Video Controller reads Display Memory and do appropriate task on the screen
Types of Video Adapters in IBM PC
Display Modes Computer has different techniques and memory requirement for displaying text and images Video Adapter has two modes, each for text and images Text Mode Screen is divided into Rows and Column, 25 rows (0-24) and 80 columns (0-79) Graphics Mode Screen is again divided into Rows and Columns and each screen position is called a pixel
Text Mode Character Generation Every single character on the screen is created using a dotter array called character cell The video adapter uses a character generation circuit to create a dotted pattern Number of dots in a character depends upon the resolution of adapter, monitor has its resolution, its mandatory that both monitor and adapter’s resolution must be compatible
Details of IBM Video Adapters IBM introduced MDA and CGA with its original PC MDA only supported text mode with good character resolution i.e. 9x14 dots, used for business software CGA could display both text and graphics but low resolution in character cell i.e. 8 x 8 dots Then IBM introduced EGA for both text and graphics with character cell 8 x 14 dots Finally IBM introduced VGA and MCGA with more text and graphics resolution, text resolution 8 x 19 dots for each character
Details of IBM Video Adapters IBM introduced MDA and CGA with its original PC MDA only supported text mode with good character resolution i.e. 9x14 dots, used for business software CGA could display both text and graphics but low resolution in character cell i.e. 8 x 8 dots Then IBM introduced EGA for both text and graphics with character cell 8 x 14 dots Finally IBM introduced VGA and MCGA with more text and graphics resolution, text resolution 8 x 19 dots for each character
Text Mode Number A program can select text or graphics mode Following are text mode
Screen Positions 80 x 25 screen positions
Character display and Video Memory In text mode screen consists of rows and columns (80x25), in graphics mode (40x25) is also possible A character displayed at screen is defined by content of word in display memory Low byte contains character ASCII code High byte contains character attribute
Display pages MDA adapter display memory hold screen full of data Graphics adapter can contain many screens of display text, each screen is called display page Number of display varies among adapter starts from 0 Each display page is 4KB for MDA has one page starts at B000:0000h CGA has four pages starting at B800:0000h
Number of pages from various adapter in text mode
Attribute Byte In text mode, high byte of character is called attribute byte It defines foreground color, background color, intensity and whether a character is blinking or not Number of display varies among adapter starts from 0 Each display page is 4KB for MDA has one page starts at B000:0000h CGA has four pages starting at B800:0000h
Attribute Byte Attribute byte for 16 color display has the following format Red color on blue background 0001 0100
Attribute Byte Adjacent colors can be added to produce new colors Intensity bit is used to brighten the color on color display Normal attribute for a character is 07h, white on black background
16 Color on Color Display
Monochrome attributes
Screen Rows and Columns
Manual Screen Printing
Video Interrupt 10h Text Mode functions of INT 10H Select text display mode i.e. character height and width and number of rows and columns INT 10H INPUT: AH=0 AL = Mode Number OUTPUT: None
Video Interrupt 10h Change Cursor Size INT 10H Cursor is displayed as small dotted array MDA, EGA 14 rows (0-13), 11 and 12 lit CGA 8 rows (0-7), 6 and 7 lit INT 10H INPUT: AH=1 CH = start scan line CL = end scan line OUTPUT: None
Video Interrupt 10h Move Cursor INT 10H Let the cursor move anywhere on the screen INT 10H INPUT: AH=2 DH = new cursor row (0-24) DL = new cursor column (0-79) BH= page number OUTPUT: None
Video Interrupt 10h Get cursor position and size INT 10H If we want to know current cursor position INT 10H INPUT: AH=3 BH= page number OUTPUT: DH = CURSOR ROW DL = CURSOR COLUMN CH = CURSOR START SCAN LINE CL = CURSOR END SCAN LINE
Video Interrupt 10h Select active display page INT 10H INPUT: AH=5 AL = ACTIVE DISPLAY PAGE (0-7) OUTPUT: NONE
Video Interrupt 10h INT 10H Scroll the screen Up Also used to clear the screen or clear a particular area on the screen It could be used to draw game boxes INT 10H INPUT: AH=6 AL = Number of lines to scroll up, 0 means whole screen BH = attribute for blank line (07H) CH, CL = ROW, COL FOR UPPER LEFT CORNER OF WINDOW DH, DL = ROW, COL FOR LOWER RIGHT CORNER OF WINDOW OUTPUT: NONE
Video Interrupt 10h INT 10H Scroll the screen Down Also used to clear the screen or clear a particular area on the screen It could also be used to draw game boxes INT 10H INPUT: AH=7 AL = Number of lines to scroll up, 0 means whole screen BH = attribute for blank line (07H) CH, CL = ROW, COL FOR UPPER LEFT CORNER OF WINDOW DH, DL = ROW, COL FOR LOWER RIGHT CORNER OF WINDOW OUTPUT: NONE
Video Interrupt 10h INT 10H Read a character a cursor position INPUT: AH=8 BH = Page Number OUTPUT: AH = ATTRIBUTE OF CHARACTER AL = ASCII OF CHARACTER
Video Interrupt 10h Display character at cursor with any attribute INT 10H INPUT: AH=9 BH = Page Number AL = ASCII OF CHARACTER TO DISPLAY CX = NUMBER OF TIMES TO WRITE CHARACTER BL = ATTRIBUTE OF CHARACTER OUTPUT: NONE
Video Interrupt 10h Display character at cursor with current attribute Cursor does not advance after display of character INT 10H INPUT: AH=0AH BH = Page Number AL = ASCII OF CHARACTER TO DISPLAY CX = NUMBER OF TIMES TO WRITE CHARACTER OUTPUT: NONE
Video Interrupt 10h Display character at cursor with current attribute Cursor is advanced one position This BIOS interrupt is called by INT 21h function 2 INT 10H INPUT: AH=0EH BH = Page Number AL = ASCII OF CHARACTER TO DISPLAY BL = FOREGROUND COLOR (GRAPHICS MODE) OUTPUT: NONE
Video Interrupt 10h INT 10H Get Video Mode INPUT: AH=0FH OUTPUT: AH = NUMBER OF SCREEN COLUMNS AL = DISPLAY MODE BH = ACTIVE DISPLAY PAGE
Video Interrupt 10h
Graphics Three color graphics adapters for IBM PC CGA (Color Graphics Adapter) EGA (Enhanced Graphics Adapter) VGA (Video Graphics Array)
Composition of Video on Monitor Electron beam creates scan lines on screen Number of dots per line can vary by changing the size of dot Number of scan lines may also vary
Pixel Graphics mode screen is also divided into rows and column Each intersection of row and column is called Pixel (Picture Element) Number of pixels define the resolution of screen 320x200 means 300 columns and 200 rows Columns are numbered from left to right starting with 0 Rows numbered from top to bottom start with 0 If in low resolution a pixel may contain more than two dots
Graphics Modes
CGA Graphics CGA in medium resolution 320x200 and high resolution 640x200 16 KB memory starting at address B800:0000 and end at B800:3FFF Each pixel is coded by two bits Four colors can be displayed at a time Medium resolution is 320x200 = 64000 pixels Each pixel require two bits 64000x2 = 128000 bits or 16000 bytes Display memory is 16 KB
16 color combinations
Text in Graphics Mode In graphics mode characters are formed by turning pixels on and off and are not drawn by character generating circuitry as in text mode However cursor position can still be set by using function number 2 INT 10h When we display text in graphics mode we use text coordinates
Text COLUMNS AND ROWS IN GRAPHICS MODE
Set Background Color INT 10H Set Background color after setting mode INPUT: AH=0BH BH = 0 BL = COLOR NUMBER (0-15) OUTPUT: NONE
Writing Pixel INT 10H Write Graphics Pixel INPUT: AH=0CH AL = PIXEL VALUE (COLOR) BH = PAGE NUMBER CX = COLUMN NUMBER DX = ROW NUMBER OUTPUT: NONE
Reading Pixel Read Graphics Pixel INT 10H INPUT: AH=0DH BH = PAGE NUMBER CX = COLUMN NUMBER DX = ROW NUMBER OUTPUT: AL = PIXEL VALUE (COLOR) Pixel read and write can be done any display page
Active Display Page INT 10H Select Active Display Page INT 10H INPUT: AH=5 AL = PAGE NUMBER OUTPUT: AL = PIXEL VALUE (COLOR) Quickly switching the page can be used for animation
Vga Adapter VGA has two important modes to work 640x480 resolution on mode 12H with 16 colors 320x200 resolution on mode 13H with 256 colors. 12H is good for game purpose
Random Number Here is the Program to generate Semi-Random Number
Adding Sound Communicate with Ports using IN and OUT instructions These instructions help assembly program to communicate with peripheral devices
Input/ Output Ports Ports are like registers, in which we send 8-bit or 16-bit data from AL or AX Ports contents can also be read in AL or AX Ports are connected to peripheral devices We change something in Port content, we send a message to particular peripheral devices
Out Instruction Send byte/ word to Input/ Output Port In case of Byte OUT Portno, AL In case of Word OUT Portno, AX
Internals of Port 61
In Instruction Receive byte/ word to Input/ Output Port In case of Byte OUT AL, Portno In case of Word OUT AX, Portno
Example: Sound generation using direct Port access
Timer in IBM PC Three types of timers circuits in IBM PC Timer0 used for DMA (Data Transfer) Timer1 is used as system clock Timer2 is connected to the speaker
Generating Sound using Timer2 Three step process Put a certain number in timer2 to initialize it Load a 16 bit number into timer2 to establish the frequency of tone to be generated Open a switch in output port 61H to generate the sound
Generating Sound using Timer2