Presentation is loading. Please wait.

Presentation is loading. Please wait.

Graphics Bitmaps Drawing characters glyphs and multicolor patterns.

Similar presentations


Presentation on theme: "Graphics Bitmaps Drawing characters glyphs and multicolor patterns."— Presentation transcript:

1 Graphics Bitmaps Drawing characters glyphs and multicolor patterns

2 Limitations of BIOS routines Last time we used a ROM-BIOS routine to draw a text message on a graphics screen (i.e., the so-called ‘write_string’ service) But some limitations were apparent: –String-location had to conform to a cell-grid –Background color pattern was obliterated We can overcome both these limitations if we draw the character-glyphs ourselves

3 Built-in character bitmaps The ROM-BIOS has full sets of bitmaps for the images of all the ASCII characters in several sizes (e.g., 8x8, 8x14 and 8x16) Example: An 8-by-8 glyph for the letter ‘H’

4 Layout of 8x16 glyph-table The Glyph-Table is an array of bit-images Each bit-image is 16-bytes in length Each ascii-code serves as array-index ‘@’‘A’‘B’‘C’‘D’‘E’‘F’ 0x40 0x41 0x42 0x43 0x44 0x45 0x46 etc

5 The 8086 physical memory Boot ROM Video ROM VRAM RAM Reserved for add-ins 0x00000 0xA0000 0xC0000 0xF0000 VECTORS BIOS DATA EBDA 1-MB The VGA firmware Character-Glyph tables are located in this region A built-in BIOS function will report each of the glyph-table start-locations

6 Finding the ROM fonts Standard BIOS service locates ROM fonts Designed to execute in 8086 real-mode Normal service-call protocol is followed: –Parameters are placed in CPU registers –Software interrupt instruction is executed –ROM-BIOS code performs desired service –Parameters may be returned in registers

7 Example # AT&T assembly language syntax mov$0x11, %ah # char. gen. services mov$0x30, %al # get font information mov$6, %bh # 8x16 font address int$0x10 # request BIOS service # the font address is returned in ES:BP # (and count of scanlines should be in CX)

8 Invoking BIOS from Linux Include our “int86.h” header-file Define ‘struct vm86plus_struct’ object: vm Initialize necessary register-fields of ‘vm’ – vm.regs.eax = 0x1130; – vm.regs.ebx = 0x0600; Call our function: int86( 0x10, vm ); Retrieve the returned parameters from vm – e.g., from ‘vm.regs.es’ and ‘vm.regs.ebp’

9 Drawing a character (in mode 18) Must enable I/O and 1-MB memory-map Virtual address of VRAM is 0x000A0000 Use any ascii-code as a glyph-table index Use x,y coordinates for character location Specify the character’s ‘foreground color’ Thus your function-call could look like: draw_char( x, y, color, ascii );

10 Using VGA Write Mode 3 To preserve the background pattern when a character-glyph is drawn, you can use a ‘Masked Write’ operation (‘Write Mode 3’) To position the character at an arbitrary horizontal pixel position, use Data-Rotate The foreground color goes in ‘Set/Reset’ The Bit Mask register prevents unwanted pixels from being drawn when rotation

11 Illustration Adjacent bytes on the screen Left-hand Right-hand Bit Mask Bit Mask Character-glyph is right-rotated Afterward this rotated glyph gets ‘masked’

12 Implementation details void draw_char( int x, int y, int fg, int ascii ) { int which = y * hres + x; int where = which / 8; int shift = which % 8; int left_mask = 0xFF >> shift; int right_mask = ~(left_mask); char *glyph = (char*)fontbase + 16*ascii;

13 Draw_char() (continued) outw( 0x0305, GCPORT );// use Mode 3 outw( color<<8, GCPORT );// Set/Reset // first-pass draws glyph’s left portion outw( (left_mask<<8) | 8, GCPORT ); for (int row = 0; row < 16; row++) { char temp = vram[ where + row*80 ]; vram[ where + row*80 ] = glyph[ row ]; }

14 Draw_char() (concluded) if ( shift == 0 ) return;// we can do an early exit // else second-pass draws glyph’s right portion ++where;// location of the adjacent byte outw( (right_mask<<8) | 8, GCPORT ); // Bit Mask for (int row = 0; row < 16; row++) { char temp = vram[ where + row*80 ]; vram[ where + row*80 ] = glyph[ row ]; }

15 Our ‘drawtext.cpp’ demo We used an 8-by-8 bitmap to generate the patterned background for drawing text on 0x00 0x33 0x00 0x33 Background color 0001 (binary) Foreground color 1001 (binary)

16 How ‘Write Mode 0’ works 00110011 00110011 Latch plane 3 00000000 Latch plane 2 00000000 Latch plane 1 11111111 Latch plane 0 Data from CPU x 0 0 1 0 1 1 1 ENABLE SET/RESET SET/RESET Byte from pattern-glyph Screen Pixel (planar) VRAM byte

17 Algorithm to ‘tile’ screen-area // Use Write Mode 0 (“Direct Write”) // Data-Rotate = 0, Function-Select is ‘copy’ // Bit Mask is 0xFF (e.g., all pixels writable) // Enable Set/Reset is 0x7, Set/Reset is 0x1 // pattern-glyph described by array of 8-bytes for (y = ymin; y < ymax; y++) for (x = xmin; x < xmax; x++) vram[ y * 80 + x ] = glyph[ y % 8 ];

18 Designing bitmap ‘patterns’ You can create interesting backgrounds Fill screen regions with a copied pattern 0xFF 0x80 0xFF 0x08 foreground color background color

19 Algorithm for ‘tiling’ (mode 19) unsigned charpat[ 8 ];# 8x8 2-color bitmap unsigned char*vram = 0x000A0000, color; for (int y = 0; y < vres; v++) for (int x = 0; x < hres; x++) { intr = y % 8, k = x % 8; color = ( pat[ r ] & (0x80>>k) ) ? fg : bg; vram[ y*hres + x ] = color; }

20 In-class exercise Take a look at our ‘brickpat.cpp’ demo It tiles the screen with a brick-wall pattern But it executes in mode 19 (256-colors) Can you revise this demo so that it will work in a ‘planar’ mode (i.e., 16-colors)? Hint: Apply the principles of Write Mode 0 in a manner similar to ‘drawtext.cpp’ demo Can you write text against your brick-wall?


Download ppt "Graphics Bitmaps Drawing characters glyphs and multicolor patterns."

Similar presentations


Ads by Google