Standalone Display Adapter Driver
In Listing Five, we can examine the code from a trivial "glass tty" terminal emulator for the display, which in this case happens to be a CGA board. We can be content at the moment with newline, carriage return, and tab functions, since we do not intend to do anything other than line-oriented text output in the standalone system. Scrolling, by far, is the most complicated feature.
Listing 5: Standalone Display Driver
/* cga.c: Copyright (c) 1989, 1990 William Jolitz. All rights reserved.
* Written by William Jolitz 9/89
* Redistribution and use in source and binary forms are freely permitted
* provided that the above copyright notice and attribution and date of work
* and this paragraph are duplicated in all such forms.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
* Standalone driver for IBM PC Displays like CGA.
*/
typedef unsigned short u_short;
typedef unsigned char u_char;
#define CRT_TXTADDR Crtat
#define COL 80
#define ROW 25
#define CHR 2
u_short *Crtat = ((u_short *)0xb8000); /* 0xb0000 for monochrome */
u_short *crtat;
u_char color = 0xe ;
int row;
sput(c) u_char c; {
if (crtat == 0) {
crtat = CRT_TXTADDR; bzero (crtat,COL*ROW*CHR);
}
if (crtat >= (CRT_TXTADDR+COL*ROW*CHR)) {
crtat = CRT_TXTADDR+COL*(ROW-1); row = 0;
}
switch(c) {
case '\t':
do {
*crtat++ = (color<<8)| ' '; row++ ;
} while (row %8);
break;
case '\010':
crtat--; row--;
break;
case '\r':
bzero (crtat,(COL-row)*CHR) ; crtat -= row ; row = 0;
break;
case '\n':
if (crtat >= CRT_TXTADDR+COL*(ROW-1)) { /* scroll */
bcopy(CRT_TXTADDR+COL, CRT_TXTADDR,COL*(ROW-1)*CHR);
bzero (CRT_TXTADDR+COL*(ROW-1),COL*CHR) ;
crtat -= COL ;
}
crtat += COL ;
break;
default:
*crtat++ = (color<<8)| c; row++ ;
break ;
}
}
Our decision to avoid the BIOS at this point does make things more difficult, because the BIOS automatically configures in device-dependent code from ROMs onboard the display card to support the given device. Fortunately, market forces have kept the proliferation of variations down to a reasonable number, with either MDA or CGA interface standards supported by practically all boards. Up to the point where we must support X Windows, we can live with probing to determine the display type and "hard coding" for each.
|
|