ece 103 engineering programming chapter 53 generic algorithms herbert g. mayer, psu cs status...
TRANSCRIPT
ECE 103 Engineering ProgrammingChapter 53
Generic Algorithms
Herbert G. Mayer, PSU CSStatus 6/4/2014
Initial content copied verbatim fromECE 103 material developed by
Professor Phillip Wong @ PSU ECE
Syllabus CGA Video Adapter
3
CGA Video Adapter
From: Advanced C, © Brian Brown, 1986-1999http://gd.tuwien.ac.at/languages/c/programming-bbrown/advcw2.htm
Color Graphics Adapter (CGA) – 1981This adapter supports the following display modes, using a 16 KB memory buffer
starting at B800:0000.Text modes: 4025 BW/Color & 8025 BW/ColorGraphic modes : 320200 BW/4 Color & 640200 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
CGA 40 column text mode – Coordinate grid:40 columns across
25 r
ows
H E L L O , W O R L D .
0 39
0
24
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
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
#include <dos.h> /* TITLE 40x25 Color adapter (code will not work on Windows PC) */
#include <stdio.h>
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;
}