Direct-Access Color Graphics Chapter 11
Graphics modes C++ provides a different combination of graphics characteristics. These characteristics include the resolution, the number of possible colors, whether text or graphics are to be displayed and other elements Different modes required different hardware ( monitors and adaptors boards), and different Programing approaches
IBM Color Graphics Modes Modes (dec)ColorResolutionAdaptorMonitorMinimum MemoryPages 0 text16 grey40x25*CGACD2K8(16k) 1 text1640x25*CGACD2K8(16k) 2 text16 grey80x25*CGACD4K4(16k) 3 text1680x25*CGACD4K4(16k) 4 text4320x200CGACD16K1(16k) 5 grph4 grey320x200CGACD16K1(16k) 6 grph2 (B&W)640x200CGACD16K1(16k) 7 text2 (B&W)80x25*MAMD4K1(4k) Modes 8,9 abd 10 are for the PC jr Modes 11 and 12 are used internally by EGA board 13 grph16320x200EGAECD32K2(64k) 14 grph16640x200EGAECD64K1(64k) 15 grph2 (B&W)640x350EGAECD64K1(64k) 16 grph16640x350EGAECD128K1(128k) 17 grph2 (B&W)640x480VGAVD256K4(256k) 18 grph16640x481VGAVD256K1(256k) 19 grph256320x200VGAVD256K4(256k) * Characters, other resolution in pixels grphGraphicsMAMonochromo Adaptor MDmonochrome DisplayCGAColor Graphics Adaptor CDColor DisplayEGAEnhanced Graphics Adaptor ECDEnhanced Color DisplayVGAVideo Graphics Array VDVGA Display
Resolution Graphics images on a computer screen are composed of tiny dots called pixels/pels, for “picture element”. Pixels are arranged on the screen in horizontal rows: There are fixed numbers of rows and each row contains a certain number of pixels. Number of pixel used on the screen is called the resolution e.g. mode 4 uses a resolution of 200 rows, each 320 pixels across 320x200 Higher resolution means a sharper, clear picture, with less pronounced “jaggies” (the stairstep effect on diagonal lines) Higher resolution uses more memory for the display and is more expensive.
Text or Graphics Some modes exist only to place text on the color screen Others are made for graphics In the graphic modes, each bit, or each group of bit, corresponds to a particular pixel(dot) on the screen. In the text modes, a group of bits (actually two bytes) corresponds to a character
Color Several modes provide only two colors: black and white Others modes provide 4, 16, or 256 colors A particular mode may allow only four colors on the screen, but it may be possible to switch to a second group of four colors (can’t appear both groups at exactly the same time). These groups of colors are called palettes.
Display Monitors Different monitors are used for the different modes. The simplest and least expensive is text-only monitor. This can be used only with mode 7 The least expensive color monitor display only the CGA modes: 0 through 6 An EGA-capable monitor can display additional modes, from 13 through 16, as well as the CGA modes VGA monitors can display still more modes, from 17 to 19, as well as the CGA and EGA modes Higher the mode number, greater the resolution or number of color displayed
The Display Adaptor PC computers haven't the ability to send signals necessary to generate text or graphics on the monitor. This is the function of printed circuit board called a “display adaptor” which plugs into one of the slot inside the computer. There are display adaptors corresponding to the four graphics standards: monochrome(text only), CGA, EGA, and VGA.
CGA, EGA and VGA graphics modes The CGA allows resolution up to 640x200 At this resolution, two colors are available. At lower resolution, 320x200, four color are available. The CGA also provides several text modes. The EGA adaptor increases resolution to 640 x 350 with 16 colors The VGA increases resolution again to 640x480 with 16 colors and allows 256 colors, but at a lower resolution of 320x200
Display Memory The data place in random access memory causes an immediate change in the picture Different display adaptors come with different amount of memory ResolutionColor x2008K16K32K 640x20016K32K64K 640x35032K64K128K
Pages Enough graphics memory is available in the adaptor, its possible to keep several screens of data in the memory at the same time On the EGA boad, mode 13(320x200), 16 colors) requires only 32K, but 64K is available The extra memory can be used to hold a second screen image By switching from one page to another, very rapid changes can be made to the image on the screen
Using Modes We will use following modes in Programs: mode 4, which is available for all graphics adaptors Mode 13 which work on EGA and VGA adaptors And two VGA-specific modes 18 and 19
Setting Modes The ROM BIOS Set Mode Command use – ROM BIOS routine: Set video mode – Interrupt 10 Hex: Video – Input registers: AH=0, AL = mode number – Output register: None
ROM BIOS graphics routines /* setmode.c */ /* sets graphics mode to value supplied*/ #include /* Declare REGS*/ #define SETMODE 0 /*"set video mode" service*/ #define VIDEO 0x10 /*video BIOS interrupt number*/ void main (int argc, char *argv[]) {union REGS regs; int mode; if(argc !=2) {printf("Example input: setmode 7"); exit();} mode = atoi(argv[1]); /*string to integer*/ regs.h.al = (char)mode; /*mode number in AL register*/ regs.h.ah = SETMODE; /*service# in AH register*/ int86(VIDEO,®s, ®s); /*call video interrupt*/ }
Display Pixels routine C>setmode 4 C>cstripes – ROM BIOS routine: Write dot – Interrupt 10 Hex: Video – Input registers: AH=0C hex, CX = column number DX = row number AL = color BH = page number – Output register: None Palette 1 NumberColor 0black 1cyan 2magenta 3white
Display Pixels with ROM Routines /* cstripes.c */ /* fills CGA screen with 4 color bars. Use mode 4 (320x200)*/ #include /* Declare REGS*/ #define MAXR 200 /*rows*/ #define MAXC 320 /*columns*/ #define VIDEO 0x10 /*video BIOS interrupt number*/ #define WDOT 12 /*'write dot' ROM BIOS */ void main (void) {union REGS regs; int row, col; for(row;row<MAXR;row++) for(col=0;col<MAXC;col++) { regs.h.ah = WDOT; /*'write dot' service*/ regs.x.dx= row;/*row in DX*/ regs.x.cx = col;/* column in CX*/ regs.h.al = col/80;/* color change every 80 rows*/ regs.h.bh = 0;/* page number */ int86(VIDEO,®s, ®s); /*call video interrupt*/ }
Set Palette – ROM BIOS routine: Set color platte – Interrupt 10 Hex: Video – Input registers: AH=0B, – BH = 1 (to change palette), – BL = Plate number – Output register: None – C>setmode 4 – C>corect – C>setpal 0 Palette 0 NumberColor 0black 1green 2red 3broen
Set Color Palette /* setpal.c */ /* sets color palette to one of two values*/ #include /* Declare REGS*/ #define SETPAL 0x0B /*"set color platette" service*/ #define VIDEO 0x10 /*video BIOS interrupt number*/ void main (int argc, char * argv[]) {union REGS regs; int pal; /*palette number*/ if (argc != 2) {printf(Example usage:C>setpal 0");exit();} pal = atoi(argv[1]); /*string to integer*/ regs.h.bh = 1; /*BH =1 to set palette*/ regs.h.bl = pal;/* palette # from user*/ regs.h.ah = SETPAL;/* service # in AH register */ int86(VIDEO,®s, ®s); /*call video interrupt*/ }
Changing the back ground – ROM BIOS routine: Set background – Interrupt 10 Hex: Video – Input registers: AH=0B, – BH = 0 (to change background), – BL = Plate number – Output register: None
Changing the Background /* setback.c */ /* sets color of background to one of 16 values*/ #include /* Declare REGS*/ #define SETPAL 0x0B /*"set color platette" service*/ #define VIDEO 0x10 /*video BIOS interrupt number*/ void main (int argc, char * argv[]) {union REGS regs; int pal; /*palette number*/ if (argc != 2) {printf(Example usage:C>setback 15");exit();} pal = atoi(argv[1]); /*string to integer*/ regs.h.bh = 0; /*BH =0 to set background*/ regs.h.bl = pal;/* palette # from user*/ regs.h.ah = SETPAL;/* service # in AH register */ int86(VIDEO,®s, ®s); /*call video interrupt*/ }
Color Generation Four Signals can be combination in specific ways to produce the 16 colors 2^4 = 16 combination For example mode 4 – two bit combination
Direct access to graphics memory /* fstripes.c */ /* fills CGA screen with 4 color bars. Use mode 4 (320x200)*/ /* uses direct memory access*/ #define MAXR 200 /*rows*/ #define MAXC 320 /*columns*/ #define MAXB (MAXC/4) /*bytes in a row (80)*/ #define BPC (MAXB/4) /*bytes per color (20)*/ char table[4]= {0x00,0x55,0xAA,0xFF}; /*color byte table*/ void main (void) { char color, far *farptr; int addr,index,row,col; for(row;row<MAXR;row++) for(col=0;col<MAXC;col++) { index = (col/BPC) & 0x03; /* clr chng every 20 bytes*/ color = table[index];; /*get color pattern*/ addr = now*(MAXB/2)+col; /*address of bytes*/ if(row & 1) addr += ( ); /* use second bank*/ *(farptr +addr)=color; /*set 4 pixls*/ }
EGA bit-plane graphics /* estripes.c */ /* fills EGA screen with 16 color bars. Use mode 13 (320x200)*/ #include /* Declare REGS*/ #define MAXR 200 /*rows*/ #define MAXC 320 /*columns*/ #define VIDEO 0x10 /*video BIOS interrupt number*/ #define WDOT 12 /*'write dot' ROM BIOS */ void main (void) {union REGS regs; int row, col; for(row;row<MAXR;row++) for(col=0;col<MAXC;col++) { regs.h.ah = WDOT; /*'write dot' service*/ regs.x.dx= row;/*row in DX*/ regs.x.cx = col;/* column in CX*/ regs.h.al = col/20;/* color change every 20 rows*/ regs.h.bh = 0;/* page number */ int86(VIDEO,®s, ®s); /*call video interrupt*/ }
VGA bit-plane graphics /* vgastrip.c */ /* Horizontal stripes. Use mode 18(640x480)*/ /* uses VGA write mode 0*/ #define MAXR 480 /*rows*/ #define MAXC 640 /*columns*/ #define MAXB (MAXC/8) /*bytes in a row*/ void main (void) { char far *farptr; int row,col; unsigned char color; farptr = (char far*) 0xA ; /*set ptr to VGA mem*/ for(row;row<MAXR;row++) { color = (row/30) & 0x0f; /*color chng every 30 rows*/ outportb(0x3C4,2); /*set color to write*/ outportb(3C5,color); /*set color to write*/ for(col=0;col<MAXB;col++) *(farptr + row*MAXB + col) = 0xff; /*set 8 pixels*/ }
VGA 256 Colors /* vga256.c */ /* Draw 256 different colored squares. Use mode 19*/ #define MAXX 320 /*horizontal pixels*/ #define MAXY 192 /*vert pixels (divisible by 16)*/ #define PPBX (MAXX/16) /*pixels per color box, horizontal*/ #define PPBY (MAXY/16) /*pixels per color box, horizontal*/ void main (void) { char far *farptr; /* pointer to video memory*/ int x, y; /*pixel coordinates (0-319,0-191)*/ int row,col;/*color box coordinates (0-15)*/ unsigned char color;/*color of box */ farptr = (char far*) 0xA ; /*set ptr to VGA mem*/ for(y= 0;y<MAXY;y++)/*cycle down*/ for(x=0;x<MAXX;x++)/*cycle across*/ { col = x/PPBX; /*find box coords*/ row = y/PPBY; /*find box coords*/ color = col + row * 16; *(farptr + y*MAXX + x) = color; /*set pixel*/ }