⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dotlib.cpp

📁 英创386的LCD控制协议和函数,还有例程
💻 CPP
字号:
/*//////////////////////////////////////////////////////////////////////////
Orgnaztion:	Realtime Technology Co. Ltd.
Filename:	DOTLIB.CPP
Compiler:	BC3.1
Authors:	Wang Ping
Date:		Sept. 1998
Revised:	...
///////////////////////////////////////////////////////////////////////////*/
#include <stdio.h>
#include <process.h>
#include <string.h>
#include "sed1335.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];

   HzScale=1;

   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 );

   MLib( CHname );
   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;
   unsigned char hfont[16], MaskBit;

   (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;

   if( color == 0 ) color = 0xffff;
   else             color = 0;
   for( i=0; i<16; i++ )
      {
      hfont[i] ^= color;
      }

   WriteByteBlock( x, y, hfont, 16 );
}

void DOTLIB::WriteHz( int x,int y, char cc[2], int color, int Scale )
{
   int i, i1;
   unsigned char hfont[33], ffont[32];

   (void)Scale;
   memcpy( hfont, &dotM[ matrix[ (unsigned)(cc[0]&0x7f)-32 ]
	   [ (unsigned)(cc[1]&0x7f)-32]*32 ],          32   );

   if( color == 0 ) color = 0xffff;
   else             color = 0;
   for( i=0; i<16; i++ )
      {
      for( i1=0; i1<2; i1++ )
	 {
	 ffont[i1*16+i] = hfont[2*i+i1] ^color;
	 }
      }

   WriteByteBlock( x, y, ffont, 16 );
   WriteByteBlock( x+8, y, &ffont[16], 16 );
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -