Graphics by Lord Azathoth

Drawing characters
When the video is in VESA graphics mode, is impossible to write characters and strings with the function `printf()`. But there are a method to write text using the standard or a modified font...
Read the standard font
The VGA have a standard font table stored in his memory. We can read the address of this table by using the interrupt 13h, function 1130h (charachters generator). There are different tables, but we wanna use the table 06h (VGA font, 16 bytes/character). I know there are some trouble getting the right address under DOS (without Windows 95), so is better to save the table to a file (I'll call it 'STANDARD.FNT'). Well, how to read this table? There are a demo code:

       __dpmi_regs regs;

       regs.x.ax=0x1130;
       regs.h.bh=0x06;   // 8x16 font (MCGA, VGA)
       __dpmi_int(0x10, ®s);
       dosmemget((regs.x.es<<4)+regs.x.bp, sizeof(fonttable), fonttable);
       return(regs.x.cx);

The function returns the address of the font table in the registers es:bp, and we can read it in the virtual address space of the DJGPP using `dosmemget()`.
Drawing characters and strings
The standard font is monocromatic, and is stored in memory in the 8x16 format. This means that each character use 8 bit for scan line, and have 16 scan lines. Each bit of the scan line is 1 if the pixel of the character is on, or 0 if the pixel of the character is off. So we must controll all the bits of all the scan lines to draw a character:

    void font_putchar(int x, int y, char ch)
    {
       int countx, county, cmp;

       for(county=0;county<16;county++)
          for(countx=0,cmp=0x80;countx<8;countx++,cmp>>=1)
             if(fonttable[ch][county]&cmp)
                put_pixel(x+countx, y+county, font_color);
    }

For the strings all call the function `font_putchar()` for each character:

    void font_putstring(int x, int y, char *str)
    {
       int i;

       for(i=0;str[i];i++)
       {
          font_putchar(x, y, str[i]);
          x+=8;
       }
    }

I wrote a demo program, but it will not work without W95. Is better to see the demo program of the VESA library, that contains optimized functions for use fonts.

[main] [prec] [next] [email]
Site Made and Maintained by The Dark Angel <DarkAngel@tin.it>
My ICQ Number is 2063026
You Visited This Page
times
This page hosted by Get your own Free Home Page