Download presentation
Presentation is loading. Please wait.
Published byScarlett Frederica Small Modified over 9 years ago
1
ECE 103 Engineering Programming Chapter 53 Generic Algorithms Herbert G. Mayer, PSU CS Status 6/4/2014 Initial content copied verbatim from ECE 103 material developed by Professor Phillip Wong @ PSU ECE
2
Syllabus CGA Video Adapter
3
3 From:Advanced C, © Brian Brown, 1986-1999 http://gd.tuwien.ac.at/languages/c/programming-bbrown/advcw2.htm Color Graphics Adapter (CGA) – 1981 This adapter supports the following display modes, using a 16 KB memory buffer starting at B800:0000. Text modes:40 25 BW/Color & 80 25 BW/Color Graphic modes :320 200 BW/4 Color & 640 200 BW In text mode, each screen location requires 2 bytes of storage: 1 byte to hold the character that will be displayed 1 byte to define the character’s attribute (e.g., color) Multiple display pages are supported. The adapter hardware continuously scans the video buffer and displays its contents to the video monitor.
4
4 CGA 40 column text mode – Coordinate grid: 40 columns across 25 rows HELLO,WORLD. 0 39 0 24
5
5 Accessing the CGA Text Screen The original IBM PC offered BIOS (Basic Input Output System) INT 10h interrupt calls to control video output. While convenient to have a built-in way to write characters to the screen, the INT 10h method was relatively slow. To improve performance, many programmers bypassed certain INT 10h calls and wrote directly to the video buffer memory.
6
6 Some INT 10h routines are called to set up the desired text mode. Characters are sent to the video memory by using an offset from the start of the buffer. Suppose row and column are the desired coordinates, and pagenum is the display page. The offset for a 40 column screen is given by: offset = (( row * 0x28 + column ) * 2 ) + ( pagenum * 0x1000 )
7
7 #include /* TITLE 40x25 Color adapter (code will not work on Windows PC) */ #include union REGS regs; void setpage( unsigned int pagenum ) { regs.h.ah = 5; regs.h.al = pagenum; int86( 0x10, ®s, ®s ); } int main (void) { int x, y, offset; /* x=col, y=row, offset=from beginning of buffer */ char ch, attr; /* Character to write and its attribute */ char far *scrn = ( char far * ) 0xB8000000; /* Pointer to start of video buffer */ char *message = "Hello, world.\n"; regs.h.ah = 0; regs.h.al = 1; int86( 0x10, ®s, ®s ); /* Mode 40x25 color */ setpage(1); /* Set display to page 1 while writing to page 0 */ x = 0; y = 1; attr = 0x82; /* column 0, row 1, green blinking */ offset = (( y * 0x28 + x ) * 2 ) + ( 0 * 0x1000 ); while ( *message ) /* Write directly to page 0 */ { scrn[offset++] = *message++; scrn[offset++] = attr; } setpage(0); /* Set display to page 0 */ return 0; }
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.