📄 coch.c
字号:
#include "config.h"
#include"COCH.h"
#define FONT(offset) ( *((unsigned long *) (0x00030000+(offset))) )//转换表所存的首地址
#define UNIC2GB(offset) ( *((unsigned long *) (0x00040000+(offset))) )//转换表所存的首地址
//求字符串长度
uint8 strlen(uint8 *str)
{
uint8 len=0;
for(;*(str+len);len++);
return len;
}
//求uint16型数据的十进制长度
uint8 intlen(uint16 souce)
{
uint8 resul=0;
for(;souce;souce=souce/10)
resul++;
return resul;
}
//单个字符转二进制,支持大小写
uint8 h_string2hex(uint8 st)
{
uint8 result;
if(st>'9')
{
if(st>'Z')
result=st-'a'+10;
else
result=st-'A'+10;
}
else
{
result=st-'0';
}
return result;
}
//多个字符转二进制(16进制字符)
uint16 string2hex(uint8 *str)
{
uint16 resul=0;
uint8 len,i;
len=strlen(str);
for(i=0;i<len;i++)
resul=resul+(h_string2hex(*(str+i))<<((len-i-1)<<2));
return resul;
}
//uint16数据转字符串
void hex2string(uint16 souce,uint8 *str)
{
uint8 len;
len=intlen(souce);
*(str+len)=0;
for(;souce;souce=souce/10)
{
len--;
*(str+len)=souce%10+0x30;
}
}
//查内码转unicode码,高位在前
void FindTab(uint8 *ch,uint8 *result)
{
uint32 FontOffset=0;
uint8 i;
FontOffset=(ch[0]-0xb0)*94+ch[1]-0xa1;
if(ch[0]>0xd7)FontOffset=FontOffset-5;
FontOffset=FontOffset<<1;
for(i=0;i<2;i++)
*(result+i)=FONT( FontOffset+i);
}
//unicode码转内码
//由于unicode码并不连续,其间隔为20000多而实际只有6763个所以可先用偏移量除3得出大体位置,然后再上下查表得出
void FindTabU2(uint8 *unicode,uint8 *result)
{
uint32 FontOffset=0;
uint32 buf1,buf2;
uint8 rebuf[2];
FontOffset=(unicode[0]<<8)+unicode[1];
buf1=FontOffset;
FontOffset-=19968;
FontOffset=FontOffset/3;
if(FontOffset>6760)FontOffset=6760;
FontOffset=FontOffset<<2;
*(rebuf)=UNIC2GB(FontOffset);
*(rebuf+1)=UNIC2GB(FontOffset+1);
buf2=(rebuf[0]<<8)+rebuf[1];
while(1)
{
if(buf2==buf1)
{
result[0]=UNIC2GB(FontOffset+2);
result[1]=UNIC2GB(FontOffset+3);
return;
}
else
{
if(buf2>buf1)
FontOffset-=4;
if(buf2<buf1)
FontOffset+=4;
rebuf[0]=UNIC2GB(FontOffset);
rebuf[1]=UNIC2GB(FontOffset+1);
buf2=(rebuf[0]<<8)+rebuf[1];
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -