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

📄 source.cpp

📁 英创386的LCD控制协议和函数,还有例程
💻 CPP
📖 第 1 页 / 共 2 页
字号:
#include<math.h>
#include<SYS\STAT.H>
#include<string.h>
#include<conio.h>
#include<graphics.h>
#include<stdio.h>
#include<fcntl.h>
#include<io.h>
#include<stdlib.h>
#include<process.h>
#include<iostream.h>
#include<dos.h>
#include<dir.h>

REGS r;

static int number = 0;
int yy;
int promptcolor = 11;
int promptline = 200;

void pressbutton(int left, int top, int right, int bottom, char *str)
{
   unsigned long Len;

   rectangle(left,top,right,bottom);
   setfillstyle(SOLID_FILL,LIGHTGRAY);
//	  bar(left+1,top+1,right-1,bottom-1);
   bar(left+1,top+1,right+1,bottom+1);
   setcolor(BLACK);
   line(left+1,top+1,right-1,top+1);
   line(left+1,top+1,left+1,bottom-1);
   setcolor(LIGHTGRAY);
   line(left+1,bottom-1,right-1,bottom-1);
   line(right-1,top+1,right-1,bottom-1);
   Len = strlen(str);
   Len =(int)(right - left - Len + 1)/2;
   outtextxy(left+Len+1,top+Len+20-1,str);
}

void releasebutton(int left, int top, int right, int bottom, char *str)
{
   unsigned long Len, Ren;

   rectangle(left,top,right,bottom);
   setfillstyle(SOLID_FILL,LIGHTGRAY);
//	  bar(left+1,top+1,right-1,bottom-1);
   bar(left+1,top+1,right,bottom);
   setcolor(WHITE);
   line(left+1,top+1,right-1,top+1);
   line(left+1,top+1,left+1,bottom-1);
   setcolor(BLACK);
   line(left+1,bottom-1,right-1,bottom-1);
   line(right-1,top+1,right-1,bottom-1);

   Len = strlen(str);
   Len =(int)(right - left - Len + 1)/2;
 //  Ren =(int)(top - bottom - 10 + 1)/2;
   outtextxy(left+Len,top+Len+20,str);
}

unsigned long getbit(unsigned char c, long n)
{

   return ((c>>n)&1);
//   setcolor(color);
//   sprintf(b, "%c", ch);
//   outtextxy(x, y, b);
}

void outcc16(long x, long y, long nm, int color, int handle)
{
  unsigned long wei;
  unsigned long qu;
  long i1, i2, i3, rec;
  long addr;
  char font[32];

  qu = (nm&0xff) - 0xa1; //rem (-160)
  wei = ((nm&0xff00)>>8)-0xa1;
  rec = (qu - 0)*94 + wei ;          //This the cdisplay.drv's structure
  addr = rec * 32L;
  lseek(handle, addr, SEEK_SET);
  read(handle, font, 32);
  for(i1 = 0; i1<16; i1++)
     for(i2 = 0; i2<2; i2++)
	for(i3 = 0; i3<8; i3++)
	   if(getbit(font[i1*2+i2], 7-i3))
	      putpixel(x+i2*8+i3, y+i1, color);
//  close(handle);
}


void outchxy(int x, int y, char ch, int color)
{
   char b[2];

   setcolor(color);
   sprintf(b, "%c", ch);
   outtextxy(x,y,b);
}
void display(long x , long y, long wd, char *s, int color)
{

   int handle = open("cclib16.fnt", O_BINARY | O_RDONLY);

   while(*s)
      if((*s&0x80)&&(*(s+1)&0x80))
	 {
	 outcc16(x, y, *(long *)s,color,handle);
	 s += 2;
	 x = x + wd + 16;
	 }
      else
	 {
	 outchxy(x, y+5, *s, color);
	 s++;
	 x = x + wd + 8;
	 }

    close(handle);

}


void ccouttext16(long x , long y, long wd, char *s, int color, int status, char *p, long p1, float p2)
{
   int handle, Lenn;
   //status == 1  --> p is the character
   //status == 2  --> p is the int
   //status == 3  --> p is the float
   char  P[100];

   handle = open("cclib16.fnt", O_BINARY | O_RDONLY);

   while(*s)
      if((*s&0x80)&&(*(s+1)&0x80))
	 {
	 outcc16(x, y, *(long *)s,color,handle);
	 s += 2;
	 x = x + wd + 16;
	 }
      else
	 {
	 outchxy(x, y+5, *s, color);
	 s++;
	 x = x + wd + 8;
	 }

    close(handle);

    Lenn = strlen(s);

    if( status == 1)
       {
       display(x+Lenn,y+Lenn,wd,p,color);
       }
    else if( status == 2 )
       {
       sprintf( P, "%d", p1);
       display(x+Lenn,y+Lenn,wd,P,color);

       }
    else if( status == 3 )
       {
       sprintf( P, "%f", p2);
       display(x+Lenn,y+Lenn,wd,p,color);
       }

}

int ccinit(void)
{
   int handle;
   handle = open("cclib16.fnt", O_BINARY | O_RDONLY);
   if(handle == -1)
      {
      cout<<"cclib16.fnt not found!!";
      getch();
      closegraph();
      exit(1);
      }
  close(handle);

  r.x.ax=0;
  int86(0x33,&r,&r);
  r.x.ax=1;
  int86(0x33,&r,&r);
  return 0;
}

unsigned long Test(char *cs, int x , int  y, int n, int status)
{
    struct stat statbuf;
    stat(cs, &statbuf);
    long Filelengh = statbuf.st_size;
    if (status == 0)
       ccouttext16(x, y, n, "被转换的文件长度 :", 6,2,"",Filelengh,0);
    else if (status == 1)
       ccouttext16(x, y, n, "新生成文件的长度 :", 6,2,"",Filelengh,0);
    long Filelengh0 = (Filelengh-2)/2;
    if (status == 0)
       ccouttext16(x, y+50, n, "被转换的文件的汉字个数: ", 6,2,"",Filelengh0,0);
    else if (status == 1)
       ccouttext16(x, y+50, n, "新生成文件的汉字个数: ", 6,2,"",Filelengh0,0);
    return  Filelengh ;

}

unsigned long Test(char *cs, int x , int  y, int n, int status, int color)
{
    struct stat statbuf;
    stat

    (cs, &statbuf);
    long Filelengh = statbuf.st_size;
    if (status == 0)
       ccouttext16(x, y, n, "被转换的文件长度 :", color,2,"",Filelengh,0);
    else if (status == 1)
       ccouttext16(x, y, n, "新生成文件的长度 :", color,2,"",Filelengh,0);
    else if (status == 2)
       ccouttext16(x, y, n, "最后生成文件的长度 :", color,2,"",Filelengh,0);
    long Filelengh0 = (Filelengh-2)/2;
    if (status == 0)
       ccouttext16(x, y+50, n, "被转换的文件的汉字个数: ", color,2,"",Filelengh0,0);
    else if (status == 1)
       ccouttext16(x, y+50, n, "新生成文件的汉字个数: ", color,2,"",Filelengh0,0);
    else if (status == 2)
       ccouttext16(x, y+50, n, "最后生成文件的汉字个数 :", color,2,"",Filelengh0,0);
    return  Filelengh ;

}

int Search(int x, int y, int color, int wd, char *filename, FILE *newfile, char* name)
{

   FILE *file;
   char hz[900] ;
   char lhz[4];//, num[10];
   unsigned long Len, oldLen, newLen, mod, jj = 0;
   int i1,i,i2=1;
   int handle = open("cclib16.fnt", O_BINARY | O_RDONLY);
   int ii, fhz= 0, num ;

   oldLen = Test(filename, 10,60,1,0,color+1);

  if ((file = fopen(filename, "rt")) == NULL)
   {
       ccouttext16(10, 30, 1, "打开文件失败或文件不存在!!", color,0,"",1,1);
       return -1;
   }

   mod = (unsigned long)fmod(oldLen,800);
//   newLen = mod;
   num = int(oldLen/800);

   if (num>=1)
      Len = 800;
   else
      {
      Len = oldLen;
      num = 0;
      }


  for (i1 = 0 ; i1<num+1; i1++)
     {
      if (( i1 == num) && (num<1))
	 Len = oldLen;
      if ((i1 == num) && (num>1))
	 Len = mod;
       for(int k=0; k<900; k++)
	  {
	  hz[k] = 0x00;
	  if (k<4)
	     lhz[k] = 0x00;
	  }
      fread(hz,Len,1,file);
      for(int j=0; j<Len ; j=j+2)
	 if(!(hz[j]&0x80))
	     j--;
	 else
	    {
	    if (j==799)
	       {
	       fread(lhz,1,1,file);
	       strcat(hz,lhz);
	       }
	    if(hz[j+1]&0x80)
	       {
	       fhz ++;
	       sprintf(lhz,"%c%c",hz[j],hz[j+1]);
	       fwrite(lhz,  sizeof(char),strlen(lhz),  newfile);
	       outcc16(x, y,*(long *)lhz,color,handle);
	       x = x + wd + 16;
	       jj++;
	       if (fhz == 20*i2)
		  {
		  x = 10;
		  y = y+20;
		  if (y >440)
		     {
		     getch();
		     cleardevice();
		     y =1;
		     }
		  i2++;
		  }
	       }
	 }
      }

  if (y+30 >440)
     {
     getch();
     cleardevice();
     y =1;
     }

  ccouttext16(10,y+30, 1, "共收集汉字有 : ", color+2,2,"",jj,1);

   close(handle);
   fclose(file);

  if ((y+60 >440) || (y +110 >440))
     {
     getch();
     cleardevice();
     y =1;
     }


   fclose(newfile);

   Test(name, 10, y+60,1,1,color+1);

  if (y+150 >440)
     {
     getch();
     cleardevice();
     y =1;
     }

   ccouttext16(10,y+160, 1, "生成汉字收集文件  : ", color+2,1," NEWHZ:DAT",1,1);


   return y+160;
}

int Find(int x, int y, int color, int wd, char *filename, FILE *newfile, char* name)
{

   FILE *file;
   char oldhz[900], newhz[900] ;
   char lhz[4];//, num[10];
   long Len, oldLen, mod, fhz=0,i2=1,savej[900], jj = 0,jj1 = 0;

⌨️ 快捷键说明

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