📄 public.cpp
字号:
#include "public.h"
//函数参数传输在不同编译模式中有不同位置。
unsigned long ftonl(unsigned long t)
{
asm{
#if (__LARGE__)
mov dx,word ptr [bp+6]
mov ax,word ptr [bp+8]
#elif (__SMALL__)
mov dx,word ptr [bp+4]
mov ax,word ptr [bp+6]
#else
#error You must choose Large or Small Memory Model at compile time(选择大模式编译)
#endif
XCHG AL,AH
XCHG DL,DH
}
}
unsigned long ftonl(const void *t)
{
asm{
#if (__LARGE__)
les bx,dword ptr [bp+6]
#elif (__SMALL__)
mov bx,word ptr [bp+4]
#else
#error You must choose Large or Small Memory Model at compile
#endif
mov ax,word ptr es:[bx+2]
mov dx,word ptr es:[bx]
XCHG AL,AH
XCHG DL,DH
}
}
/////////////////////////////////////////////////////
unsigned short ftons(unsigned short t)
{
asm{
#if (__LARGE__)
mov ax,word ptr [bp+6]
#elif (__SMALL__)
mov ax,word ptr [bp+4]
#else
#error You must choose Large or Small Memory Model at compile time(选择大模式编译)
#endif
XCHG AL,AH
}
}
unsigned short ftons(const void *t)
{
asm{
#if (__LARGE__)
les bx,dword ptr [bp+6]
#elif (__SMALL__)
mov bx,word ptr [bp+4]
#else
#error You must choose Large or Small Memory Model at compil
#endif
mov ax,word ptr es:[bx]
XCHG AL,AH
}
}
///////////////////////////////////////////////////////////////
//使用bios中断读取系统时间。
//////////////////////////////////////////////////////////////
void ReadBIOSTime(short TimeValue[])
{
#define BCD(s) (((s)>>4)*10+((s)&0xF))
unsigned char cen,year,mon,day,hour,min,sec,Newday;
ReReadTime:
asm{
MOV AH,0x4
INT 0x1A
MOV cen,CH
MOV year,CL
MOV mon,DH
MOV day,DL
MOV AH,0x2
INT 0x1A
MOV hour,CH
MOV min,CL
MOV sec,DH
MOV AH,0x4
INT 0x1A
MOV Newday,DL
}
if(day==Newday)
{
TimeValue[0]=BCD(cen)*100+BCD(year);//年
TimeValue[1]=BCD(mon);//月
TimeValue[2]=BCD(day);//日
TimeValue[3]=BCD(hour);//时
TimeValue[4]=BCD(min);//分
TimeValue[5]=BCD(sec);//秒
}
else goto ReReadTime;
}
///////////////////////////////////////////////////////////////
extern unsigned _stklen ;//=4*1024U;//设置堆栈大小为8K
int gUseStack=0;
void Teststack()
{
int ss=_stklen-stackavail();
if(ss>gUseStack) gUseStack=ss;
//if(stackavail()<MinFreestack) MinFreestack=stackavail();
}
void ShowStackSize()
{
cprintf("\r\n.....Stack:%u Memory:%lu",stackavail(),farcoreleft());
}
///////////////////////////////////////////////////////////////
unsigned short BitCount(unsigned short int x)//计算有多少位
{
unsigned char c=0;
for(;x;x>>=1) c+=(x&0x1);
return c;
}
//////////////////////////////////////////////////////////////////
unsigned long GetCurComputerNo()
{
#define ComputerNoFileName "\\Computer.SN"
FILE *fp;
unsigned long ComputerNo;
fp=fopen(ComputerNoFileName,"r");
if(fp==NULL)
{
ComputerNo=1234567890L;
fp=fopen(ComputerNoFileName,"w");
fprintf(fp,"%lu",ComputerNo);
}
else
{
fscanf(fp,"%lu",&ComputerNo);
}
fclose(fp);
return ComputerNo;
}
//////////////////////////////////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -