delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/01/16/18:09:10

From: hackeroc3 AT aol DOT com (HackerOC3)
Newsgroups: comp.os.msdos.djgpp
Subject: Char blitting
Date: 16 Jan 1998 19:46:37 GMT
Lines: 65
Message-ID: <19980116194601.OAA28275@ladder02.news.aol.com>
NNTP-Posting-Host: ladder02.news.aol.com
Organization: AOL http://www.aol.com
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

I am using a function to blit chars and strings to the screen.  Below is the
version that blits chars.  It crashes my computer.  I think it may have
something to do with the base
address for the ASCII chars, 0xF000FA6EL.

void Blit_Char(int xc, int yc, char c, int color, int trans_flag)
{
//This function uses the ROM 8x8 character set to blit a character on the
//video screen.  Notice the trick used to extract bits out of each character
//byte that comprises a line.

int offset, x, y;
unsigned char * work_char;
unsigned char bit_mask = 0x80;

//Compute the starting offset in the ROM character look - up table.

*work_char = (unsigned char)0xF000FA6EL + c * CHAR_HEIGHT);

//Compute the offset of the character in the video buffer.

offset = (yc<<8) + (yc<<6) + xc;

for(y = 0; y<CHAR_HEIGHT; x++)
   //Reset the bit mask.
   {
   bit_mask = 0x80;

   for (x = 0; x<CHAR_WIDTH; x++)
       {
       //Test for a transparent pixel; that is, 0.  If the pixel is not
       //transparent, draw it.
       if ((*work_char & bit_mask)){
           _farpokeb(_dos_ds, 0xa0000 + offset + x, c);}
       else if (!trans_flag){  //Takes care of transparency
            _farpokeb(_dos_ds, 0xa0000 + offset + x, 0);}

       //Shift the bitmask.

       bit_mask = (bit_mask>>1);

       } //end for x

   //Move to the next line in the video buffer and in the ROM data area.
   offset += SCREEN_WIDTH;
   work_char++;
   } //end for y;
} //end Blit_Char

//CHAR_WIDTH and CHAR_HEIGHT are both 8, SCREEN_WIDTH is 320
//This function is called by Blit_String:
void Blit_String(int x, int y, int color, char *string, int trans_flag)
{
int index;
for (index=0; string[index]!=0; index++)
     {

     Blit_Char(x+(index<<3),y,string[index],color,trans_flag);
     }
}


DO NOT RUN THIS AS IS:  IT WILL CRASH YOUR COMPUTER

HackerOC3 AT aol DOT com

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019