📄 text.c
字号:
#include "gui.h"
#include "FAT.h"
extern uint16 SectorsPerClust;//每簇扇区数
extern WORD BytesPerSector; // Bytes per sector 每扇区字节数
extern uint8 FAT32_Enable;
void disp_sector_data(uint8 *da)
{
int x,y;
for(x=0;x<220;x+=20)
{
for(y=0;y<301;y+=20)
{
GUI_sprintf_chartohex(x,y,*da,0xffff,0x0000) ; //-----------------------------------------------
da ++ ;
}
}
}
// 显示汉字 使用须先初始化FAT
uint8 Print_text(uint8 x, uint16 y,uint8 size, uint16 bm ,uint16 color,uint16 b_color)
{
uint8 qm ,wm , clust ,i ,type , byte ;
uint8 *buffer ;
uint8 t_x ;
uint16 t_y ;
uint16 count , sector ;
uint32 offset , p ;
struct direntry ZKInfo ;
type = 2 ; //搜索文件格式 bin
count = 1 ;
qm = ((uint8)(bm>>8)) - 0xa1 ; // 0x35
wm = ((uint8)bm) - 0xa1 ; // 0x2f
offset = (uint32) 32 * ( qm * 94 + wm ) ; // 0x274a0
clust = offset / (SectorsPerClust * BytesPerSector) ; //计算数据起始簇数 4096 offset / (SectorsPerClust * BytesPerSector)
sector = offset % (SectorsPerClust * BytesPerSector) / BytesPerSector ; //计算数据超始扇区 offset % 4096 / 512 ;
offset = offset % BytesPerSector ; //计算数据扇区内偏移
do
{
if ( Search(&ZKInfo,&count,&type) ) { return 1 ; }
}
while((ZKInfo.deName[0]=='k') && (ZKInfo.deName[1]=='t') ) ; //查找文件
p = ZKInfo.deStartCluster+(((uint32)ZKInfo.deHighClust)<<16) ; //读取首簇位置
buffer=malloc(512) ;
while(clust>0) // 读取数据所在第一簇
{
free(buffer) ;
p=FAT_NextCluster(p);//读下一簇数据 //read next cluster
buffer=malloc(512) ;
if(p == 0x0fffffff || p == 0x0ffffff8 || (FAT32_Enable == 0 && p == 0xffff))//如果无后续簇则结束, //no more cluster
{
return 0 ;
}
clust -- ;
}
FAT_LoadPartCluster(p,sector,buffer);//读一个扇区 //read a sector
for( t_y=y ; t_y<y+16 ; t_y++ )
{
for( byte=x ; byte < x+9 ; byte+=8 )
{
for( t_x=byte,i=0 ; t_x<byte+8 ;t_x++,i++ )
{
if((buffer[offset]&(0x80>>i))==(0x80>>i))
{
GUI_Point(t_x,t_y,color) ;
}
else
{
GUI_Point(t_x,t_y,b_color) ;
}
}
if(offset<512)
{
offset ++ ;
}
else
{
sector ++ ;
offset = 0 ;
if(sector>=0x08) //---------------------
{
sector = 0 ;
free(buffer) ;
p=FAT_NextCluster(p);//读下一簇数据 //read next cluster
buffer=malloc(512) ;
if(p == 0x0fffffff || p == 0x0ffffff8 || (FAT32_Enable == 0 && p == 0xffff))//如果无后续簇则结束, //no more cluster
{
free(buffer) ;
return 0 ;
}
FAT_LoadPartCluster(p,sector,buffer);//读一个扇区 //read a sector
}
else
{
FAT_LoadPartCluster(p,sector,buffer);//读一个扇区 //read a sector
}
}
}
}
free(buffer) ;
return 0 ;
}
void Print_hz(uint8 x, uint16 y,uint8 size, uint8 *bm ,uint16 color,uint16 b_color)
{
uint8 qm,wm ;
uint16 hz_bm ;
while(*bm!=0x00)
{
qm = *bm++ ;
wm = *bm++ ;
hz_bm = qm ;
hz_bm <<= 8 ;
hz_bm += wm ;
Print_text(x, y,size, hz_bm ,color,b_color) ;
x+= size ;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -