www.pudn.com > netbox-ii_ks0108_192x64.rar > DOTLIB.CPP


#include  
#include  
#include  
#include "hd61202.h" 
#include "dotlib.h" 
#include "source.h" 
 
//char* source; 
 
DOTLIB::DOTLIB() 
{ 
   dotM = NULL; 
   dotM = new char[ 512*32 ]; 
   if( dotM == NULL ) { printf( "font buffer fail" ); exit(1); } 
   char_addr.ptr = NULL; 
   char_addr.ptr = new char[256*14]; 
   if( char_addr.ptr == NULL ) { printf( "font buffer fail" ); exit(2); } 
} 
 
DOTLIB::~DOTLIB() 
{ 
   if( dotM != NULL ) 	     	delete dotM; 
   if( char_addr.ptr != NULL ) 	delete char_addr.ptr; 
} 
 
void  DOTLIB::initiChinese( char* CHname, char* ENname ) 
{ 
   char PathName[40]; 
 
   sprintf( PathName, "%s", ENname );    // load the 8*14 set of character 
   FILE *fp = fopen( PathName, "rb" ); 
   if( fp==NULL ) return; 
   fread( char_addr.ptr, 14, 256, fp ); 
   fclose( fp ); 
 
   getM( CHname ); 
} 
 
void DOTLIB::MLib( char *CHname ) 
{ 
  char*     cc=source; 
  char      string[33]; 
 
  FILE *lib, *mlib; 
 
  lib = fopen( "cclib16.fnt", "rb" ); 
  if( lib == NULL ) return; 
  remove( "mlib.chr" ); 
 
  mlib = fopen(CHname, "ab+" ); 
  if( mlib == NULL )  { fclose( lib ); return; } 
 
  for ( int i=0; i < 512;  ) 
     { 
     if (cc[0]=='\0')  break; 
     if ((cc[0]&0x80)/128!=1)  continue; 
     if (cc[1]=='\0')  break; 
     if ((cc[0]&0x80)/128!=1)  continue; 
 
     fseek( lib, (((long)((cc[0] & 0x7f)-32)-1L)*94 
		+ (long)((cc[1] & 0x7f)-32)-1L)*32, SEEK_SET ); 
 
     fread( string, 32, 1, lib ); 
     string[32]=0; 
     fwrite( string, 32, 1, mlib ); 
 
     i++; 
     cc++; 
     cc++; 
     } 
 
  fclose(lib); 
  fclose(mlib); 
} 
 
void DOTLIB::getM( char *CHname ) 
{ 
    char*   cc=source; 
    FILE *mlib; 
 
    for (int i=0; i<96; i++) 
      for (int j=0; j<96; j++) 
	matrix[i][j] = 0; 
 
    for ( i=0; i<512; ) 
	{ 
	if (cc[0]=='\0')          break; 
	if ((cc[0]&0x80)/128!=1)  continue; 
	if (cc[1]=='\0')          break; 
	if ((cc[0]&0x80)/128!=1)  continue; 
 
	matrix[ (unsigned)(cc[0]&0x7f)-32 ][ (unsigned)(cc[1]&0x7f)-32 ] 
	= (unsigned int)i; 
	i++; 
	cc++; 
	cc++; 
	} 
 
    if( (mlib=fopen(CHname, "rb" ))==NULL )   return; 
    fread( dotM,  512*32, 1, mlib ); 
    fclose( mlib ); 
} 
 
int DOTLIB::GetBit( unsigned char c, int n ) 
{ 
   return ( (c>>n)&1 ); 
} 
 
void  DOTLIB::Writechar(int x, int y, char ch_in, int color, int Scale ) 
{ 
   address  addr=char_addr; 
   int      i, j, PgIdx; 
   unsigned char hfont[16], MaskBit; 
   unsigned int  vfont[8]; 
 
   (void)Scale; 
   addr.sptr.oset+=14*(unsigned char)ch_in; 
 
   // get horizontal font 
   hfont[0] = 0; 
   for( i=0, j=1; i<14; i++, j++ )  hfont[j] = addr.ptr[i]; 
   hfont[15] = 0; 
 
   // convert to vertical font 
   for( i=0; i<8; i++ ) 
      { 
      vfont[i] = 0; 
      MaskBit = (0x80>>i); 
      for( j=0; j<16; j++ ) 
	 { 
	 vfont[i] = vfont[i]<<1; 
	 if( (hfont[15-j]&MaskBit) == MaskBit ) vfont[i] |= 0x01; 
	 } 
      } 
 
   if( color == 0 ) color = 0xffff; 
   else             color = 0; 
   PgIdx = y / 8; 
   for( i=0; i<8; i++ ) 
      { 
      vfont[i] ^= color; 
      WriteByte( x+i, PgIdx, (unsigned char)(vfont[i]&0x00ff) ); 
      WriteByte( x+i, PgIdx+1, (unsigned char)((vfont[i]>>8)&0x00ff) ); 
      } 
} 
 
void DOTLIB::WriteHz( int x,int y, char cc[2], int color, int Scale ) 
{ 
   int i, j, PgIdx, i1, i2; 
   unsigned char hfont[33], MaskBit; 
   unsigned int  vfont[16]; 
 
   (void)Scale; 
   memcpy( hfont, &dotM[ matrix[ (unsigned)(cc[0]&0x7f)-32 ] 
	   [ (unsigned)(cc[1]&0x7f)-32]*32 ],          32   ); 
 
   // convert to vertical font 
   for( i=0; i<8; i++ ) 
      { 
      vfont[i] = 0; 
      vfont[i+8] = 0; 
      MaskBit = (0x80>>i); 
      for( j=0; j<16; j++ ) 
	 { 
	 vfont[i] = vfont[i]<<1; 
	 vfont[i+8] = vfont[i+8]<<1; 
	 if( (hfont[2*(15-j)]&MaskBit) == MaskBit ) vfont[i] |= 0x01; 
	 if( (hfont[2*(15-j)+1]&MaskBit) == MaskBit ) vfont[i+8] |= 0x01; 
	 } 
      } 
 
   if( color == 0 ) color = 0xffff; 
   else             color = 0; 
   PgIdx = y / 8; 
   for( i=0; i<16; i++ ) 
      { 
      vfont[i] ^= color; 
      WriteByte( x+i, PgIdx, (unsigned char)(vfont[i]&0x00ff) ); 
      WriteByte( x+i, PgIdx+1, (unsigned char)((vfont[i]>>8)&0x00ff) ); 
      } 
 
}