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

📄 prn_buf.c

📁 一款收款机C源代码!因为是几年前的代码了
💻 C
📖 第 1 页 / 共 3 页
字号:
// Descript: debug function
// In Param:	void
// Out Param:	void
// Return:		void
///////////////////////////////////////////////////////////////////////////////
void Prn_DbgCvtStr(void)
{
	byte temp[20];
	
	while (1)
	{
		memcpy(temp, 0, 20);
		temp[0] = DB_WIDTH_PRN;
		strcpy(&temp[1], "Apple");

		Prn_InsImpStr(temp, 1, 20, FLUSH_LEFT);
		Prn_Str(1);

		Prn_InsImpStr(temp, 20, 6, FLUSH_LEFT);
		Prn_Str(1);

		Prn_InsImpStr(temp, 10, 20, FLUSH_LEFT);
		Prn_Str(1);

		memcpy(prn_Buf+1, temp, 20);
		Prn_Str(0);

		memcpy(prn_Buf+10, temp, 20);
		Prn_Str(0);

		memcpy(prn_Buf+20, temp, 6);
		Prn_Str(0);
		
		Prn_InsStr1stSp("Cash", 1, NM_FONT_PRN, DB_WIDTH_PRN);
//		Prn_InsStr("120.00", MAX_PRN_LEN, NM_FONT_PRN, FLUSH_RIGHT);
		Prn_InsStr("120.00", MAX_PRN_LEN, DB_WIDTH_PRN, FLUSH_RIGHT);
		Prn_Str(1);

		if (Key_Poll_Chk())	{break;}

		Prn_InsStr("Subttl", 1, NM_FONT_PRN, FLUSH_LEFT);
		Prn_InsStr("120.00", MAX_PRN_LEN-6, NM_FONT_PRN, FLUSH_RIGHT);
		Prn_Str(1);

		if (Key_Poll_Chk())	{break;}

		Prn_InsMem("Cash", strlen("Cash"), 1, NM_FONT_PRN, FLUSH_LEFT);
		Prn_InsStr("120.00", MAX_PRN_LEN+1-strlen("120.00"), NM_FONT_PRN, FLUSH_LEFT);
		Prn_Str(1);

		if (Key_Poll_Chk())	{break;}

		Prn_InsMem1stSp("Subttl", strlen("Subttl"), 1, NM_FONT_PRN, DB_HTWDT_PRN);
		Prn_InsStr("120.00", MAX_PRN_LEN-6, NM_FONT_PRN, FLUSH_MID);
		Prn_Str(1);

		if (Key_Poll_Chk())	{break;}

		Prn_InsStr1stSp("Cash", 1, NM_FONT_PRN, DB_HEIGT_PRN);
		Prn_InsStr("120.00", MAX_PRN_LEN/2, NM_FONT_PRN, FLUSH_MID);
		Prn_Str(1);

		if (Key_Poll_Chk())	{break;}

		Prn_InsStr1stSp("Subttl", 1, NM_FONT_PRN, DB_HEIGT_PRN);
		Prn_InsStr("120.00", MAX_PRN_LEN/2, NM_FONT_PRN, FLUSH_LEFT);
		Prn_Str(1);
		
		Line_Feed(1);

		if (Key_Poll_Chk())	{break;}
	}
}

/*-----------------------------------------------------------------*
*  Function:   Format the print number(long) in the new print buffer
*  Parameter:  num:  the long number.
*              dots: the radix point position.
*					Location: the start position in the print buffer
*					Direction: The put direction in the print buffer.
*					fmt: The print format, Normal, DB_WIDTH_PRN, ...
*  Return:     void.
*	Create by Jiang WangMing at 2004-8-30 14:11
*-----------------------------------------------------------------*/
byte LongPrnFmt_Ex(long num, char dots, byte Location, byte Direction, byte fmt)
{
	byte tmp[MAX_LENGTH_15];
	byte len;
	byte sto_dot = 0;
	byte sto_aster = 0;
	byte adj = 0;

	if((Location > MAX_PRN_LEN) || (Location < 1))		/* When the locate position is illegal, return */
		return (0);

	Get_Sto_Flag(&sto_dot, &adj, &sto_aster);

	#if	SW_VER == SW_NE2
	len = LongAndDot2Str(num, dots, tmp, sto_dot, adj, sto_aster, 1);
	#else
	len = LongAndDot2Str(num, dots, tmp, sto_dot, adj, sto_aster, 0);
	#endif

	/* Store the data in the print buffer */
	if(Direction == LEFTFLUSH)					/* LEFTFLUSH */
		Prn_InsMem(tmp+MAX_LENGTH_15-len, len, Location, fmt, FLUSH_LEFT);
	else
		Prn_InsMem(tmp+MAX_LENGTH_15-len, len, Location, fmt, FLUSH_RIGHT);

	return (len);
}

/*
	The the printing string dot height.
		NM_FONT_PRN:
		DB_WIDTH_PRN:
			The return is 1.
		DB_HEIGT_PRN:
		DB_HTWDT_PRN:
			The return is 2.
	Create by Jiang WangMing at 2004-8-28 15:07
	Note: The parameter len is the string length of src.
*/
byte	Get_Str_Prn_Height(byte *src, byte len)
{
	byte	i;

	if(len == 0)
		return (0);
	for(i = 0; i < len;)
	{
		switch(src[i])
		{
			case	DB_HEIGT_PRN:
			case	DB_HTWDT_PRN:
				return (2);

			case	NM_FONT_PRN:
				i += 2;
				break;

			case	DB_WIDTH_PRN:
				i += 4;
				break;
		}
	}
	return (1);
}


/*=======================================================================================================
*  Push or pop the printing data.
*  In:   flag for indicates push or pop   
*    : 0 -- push
*    : 1 -- pop
*	Modified at 2004-8-31 9:19
*======================================================================================================*/
void  prn_Data_Store(CHR flag )
{
   static CHR prn_data_back[PRN_BUF_LEN];
   static CHR prn_data_back2[PRN_FMTED_BUF_LEN];
   CHR   *ptr1 = prn_Buf; 				/* The old print buffer */
   CHR	*ptr2 = prn_data_back;
   CHR	*ptr3 = prnBufFmt;			/* The new print buffer */
   CHR	*ptr4 = prn_data_back2;
   CHR   cntr;

   if ( flag == 0 )              //Store the data to buffer.
   {
      for (cntr = 0; cntr < PRN_BUF_LEN; cntr ++ )
         *ptr2 ++ = *ptr1 ++;
      for (cntr = 0; cntr < PRN_FMTED_BUF_LEN; cntr ++ )
         *ptr4 ++ = *ptr3 ++;
      clr_Prn_Buf();
   }
   else
   {
      for (cntr = 0; cntr < PRN_BUF_LEN; cntr ++ )
         *ptr1 ++ = *ptr2 ++;
      for (cntr = 0; cntr < PRN_FMTED_BUF_LEN; cntr ++ )
         *ptr3 ++ = *ptr4 ++;
   }
}


/*
	票据打印机的打印函数, 需要对双宽双高进行一个解析
	假如说是一个LOGO的话, 就不进行打印.
*/
void	prn_RP(void)
{
	byte	i;
	byte	len;
	byte	ctrl_byte;			/* The control byte */

	if(Judge_Send_RP() == OK)			/* The judge is OK */
	{
		Send_Inte_Char();		/* Send the international character set */
		len = Get_Desc_Len_Ex(prnBufFmt+2, MAX_PRN_LEN, YES);
		if (Rp_Auto_Space) 
        {
			for (i = 0; i < Rp_Auto_Space; i++) 
            {
				set_kp_rp_font_fmt(NM_FONT_PRN);
				Uart_WriteByte(port_use_print, ' ');
			}
		}
		for(i = 0; i < len; i ++)
		{
			if(prnBufFmt[2+i*2] == PRN_DBWD_FREE_BYTE)		/* The double size free byte, continue */
				continue;
			set_kp_rp_font_fmt(prnBufFmt[2+i*2]);
			Uart_WriteByte(port_use_print, prnBufFmt[2+i*2+1]);
		}
		send_end_info();
	}
}

#ifdef	PC_COMM
#ifdef	ELEC_JRNL
/* 
	把打印缓冲区的内容发送到串口, 这个是电子日志上传的一部分. 
*/
void	Prn_Send_EJ(void)
{
	byte	i;
	byte	status;

	if(Chk_EJ_Up())
	{
		status = Get_EJ_Sta();
		if((status == EJ_QUIT_UP) || (status == EJ_EXIT_COMM))
			return;
	}
	for(i = 0; i < MAX_PRN_LEN; i ++)
	{
		if(prnBufFmt[2+i*2] == PRN_DBWD_FREE_BYTE)			/* The double size free byte, continue */
		{
			elec_tmp_buf[i] = ' ';
		}
		else
		{
			elec_tmp_buf[i] = prnBufFmt[2+i*2+1];
		}
	}
	Send_EJ_Up(elec_tmp_buf, 0);
}
#endif
#endif

/*
1.	Prn_InitDesc(Var_Str_Cash, MAX_20_LENGTH, Str_Cash, NM_FONT_PRN, DB_WIDTH_PRN);
	
2.	prn_Cash_Info()
	{
		LongPrnFmt(payment, dots, RPOSI, RIGHTFLUSH);
		Prn_InsMem(&prn_Buf[RPOSI-9], 10, RPOSI, NM_FONT_PRN, FLUSH_RIGHT);
		Prn_InsFmtStr(str, 1, MAX_20_LENGTH, NULL);
		Prn_Str(1);
	}

3. pProgAble_Desc()
	{
			case KD_SUBTTL:
				if(modi_flag)
				{
					len = max_len;
					memcpy(ptr_var_table[Idx_Step], tmp, len*2);
					((char *)(ptr_var_table[Idx_Step]))[len*2] = 0;
					prn_ProgAble_Desc(Idx_Step);
				}
	}

4. prn_ProgAble_Desc()
	{
		// ...
		max_len = Get_Max_Len(Idx);
		Prn_InsFmtStr(ptr_var_table[Idx], 1, max_len, NULL);
		Prn_Str(1);
	}
	
5. data.c
	#define	DESC_LEN_DOUBLE		2
	char Var_Str_Cash[MAX_20_LENGTH * DESC_LEN_DOUBLE + 1];

6. 

*/



void prn_Bmp();
void CvtDbHeigt(void);
void CvtBmpCompress(const byte *src);
void CvtDbHtWd(void);
void CvtNormal(void);
void CvtBmp(void);
void CvtBmpCompress(const byte *src);
void CvtBmpNormal(const byte *src);
void CalcuDotNum(void);
void CvtDbWidth(void);



void prn_Bmp()
{
	if((sysflag->CurrLogoNo == 0) || (sysflag->CurrLogoNo > MAX_LOGO_NUM))
		return;
	DEBUG_SET(
		if (sysflag->CurrLogoNo < MAX_LOGO_NUM) {		/* Not the RAM logo */
			Pos_Prn_Logo(sysflag->CurrLogoNo);		/* Print the pos printer logo */
			return;
		}
	)
	prn_Buf[0] = NM_BMP_PRN;
	prn_Buf[1] = sysflag->CurrLogoNo;
	prn_Str();
}


const byte DotNumArray[256] = {
	0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4,
	0+1, 1+1, 1+1, 2+1, 1+1, 2+1, 2+1, 3+1, 1+1, 2+1, 2+1, 3+1, 2+1, 3+1, 3+1, 4+1,
	0+1, 1+1, 1+1, 2+1, 1+1, 2+1, 2+1, 3+1, 1+1, 2+1, 2+1, 3+1, 2+1, 3+1, 3+1, 4+1,
	0+2, 1+2, 1+2, 2+2, 1+2, 2+2, 2+2, 3+2, 1+2, 2+2, 2+2, 3+2, 2+2, 3+2, 3+2, 4+2,
	0+1, 1+1, 1+1, 2+1, 1+1, 2+1, 2+1, 3+1, 1+1, 2+1, 2+1, 3+1, 2+1, 3+1, 3+1, 4+1,
	0+2, 1+2, 1+2, 2+2, 1+2, 2+2, 2+2, 3+2, 1+2, 2+2, 2+2, 3+2, 2+2, 3+2, 3+2, 4+2,
	0+2, 1+2, 1+2, 2+2, 1+2, 2+2, 2+2, 3+2, 1+2, 2+2, 2+2, 3+2, 2+2, 3+2, 3+2, 4+2,
	0+3, 1+3, 1+3, 2+3, 1+3, 2+3, 2+3, 3+3, 1+3, 2+3, 2+3, 3+3, 2+3, 3+3, 3+3, 4+3,
	0+1, 1+1, 1+1, 2+1, 1+1, 2+1, 2+1, 3+1, 1+1, 2+1, 2+1, 3+1, 2+1, 3+1, 3+1, 4+1,
	0+2, 1+2, 1+2, 2+2, 1+2, 2+2, 2+2, 3+2, 1+2, 2+2, 2+2, 3+2, 2+2, 3+2, 3+2, 4+2,
	0+2, 1+2, 1+2, 2+2, 1+2, 2+2, 2+2, 3+2, 1+2, 2+2, 2+2, 3+2, 2+2, 3+2, 3+2, 4+2,
	0+3, 1+3, 1+3, 2+3, 1+3, 2+3, 2+3, 3+3, 1+3, 2+3, 2+3, 3+3, 2+3, 3+3, 3+3, 4+3,
	0+2, 1+2, 1+2, 2+2, 1+2, 2+2, 2+2, 3+2, 1+2, 2+2, 2+2, 3+2, 2+2, 3+2, 3+2, 4+2,
	0+3, 1+3, 1+3, 2+3, 1+3, 2+3, 2+3, 3+3, 1+3, 2+3, 2+3, 3+3, 2+3, 3+3, 3+3, 4+3,
	0+3, 1+3, 1+3, 2+3, 1+3, 2+3, 2+3, 3+3, 1+3, 2+3, 2+3, 3+3, 2+3, 3+3, 3+3, 4+3,
	0+4, 1+4, 1+4, 2+4, 1+4, 2+4, 2+4, 3+4, 1+4, 2+4, 2+4, 3+4, 2+4, 3+4, 3+4, 4+4
	};

/******************************************************************************
* Describe:	convert Normal BMP to dot-matrix buffer
*			240 * 240
* Input :	void
* Output:	void
* return:	void
******************************************************************************/
//extern const char *LOGO_START;
void CvtBmp(void)
{
	const	char *src;

//	src = (char *)(dword)( (CurrLogoNo-1) * (word)(240 * 8) + (dword)0xfe2000);
	switch (sysflag->CurrLogoNo)
	{
		case 1:		src = Logo1;			break;
		case 2:		src = Logo2;			break;
		case 3:		src = Logo3;			break;
		case 4:		src = Logo4;			break;
		case 5:		src = Logo5;			break;
		case 6:		src = Logo6;			break;
		case 7:		src = Logo7;			break;
		case 8:		src = Logo8;			break;
		case 9:		src = Logo9;			break;
		case 10:		src = Logo10;			break;
		#ifdef PC_COMM										// Support the PC communication function
		case 11:		src = RAM_Logo;		break;
		#endif 												// End PC_COMM
		default:		src = NULL;				break;	// This case will no occur
	}
	if (sysflag->CurrLogoNo <= 10)
		CvtBmpCompress(src);
	else
		CvtBmpNormal(src);								// RAM LOGO不采用压缩算法.
}

// 压缩图像数据转换.
void CvtBmpCompress(const byte *src)
{
	byte 	i;
	byte 	idx;
	byte str[50];
	word sameDotCnt = 0;
	byte cnt;
	byte dotsBytesLen;									// 压缩字节占用字节数.

	src += 2;												// 字模3软件提供的压缩数据,前两个字节为宽度和高度信息.
	idx = phead;
	dotsBytesLen = 0;
	sameDotCnt = 0;
	for (i=0; i<BMP_LINE; i++)
	{
		cnt = 0;
		while (cnt < 30)
		{
			if (sameDotCnt == 0)
			{
				if ((*src == 0x00) || (*src == 0xff))
				{
					if (*(src+1) != 0)					// 此字节表示长度,若为0则表示连续的0x00/0xff超过255字节.
					{
						sameDotCnt = *(src+1);
						dotsBytesLen = 2;
					}
					else										// 连续的0x00/0xff超过255字节,用两个字节表示长度(高位在后).
					{
						sameDotCnt = *(src+3) + *(src+2) * 0x100;
						dotsBytesLen = 4;
					}
				}
				else
				{
					str[cnt] = *src;
					cnt++;
					src++;
					dotsBytesLen = 1;
				}
			}
			else if ((sameDotCnt + cnt) > 30)
			{
				memset(&str[cnt], *src, 30-cnt);
				sameDotCnt -= (30 - cnt);
				cnt = 30;
			}
			else
			{
				memset(&str[cnt], *src, sameDotCnt);
				cnt += sameDotCnt;
				sameDotCnt = 0;
				src += dotsBytesLen;
			}
		}
		
		Prn_Dot_Ring[idx][0] = NM_DOT_FD_CNTR;
		Prn_Dot_Ring[idx][1] = 2;

		#if	0		// 由于以前华海改的程序,有一些没有看懂,所以暂时先沿用以前的内容
		memset(&Prn_Dot_Ring[idx][7+8], 0, 1+8);
		memcpy(&Prn_Dot_Ring[idx][7+1+8], str, 30);
		memset(&Prn_Dot_Ring[idx][7+1+30+8], 0, 1+8+1+8);
		memcpy(&Prn_Dot_Ring[idx][7+1+30+1+8+1+8], str, 30);
		memset(&Prn_Dot_Ring[idx][7+1+30+1+8+1+30+8], 0, 1+8);
		#else
		apply_one_line();		// 目前先沿用以前的使用,仅仅先申请一个点行。
		memset(&Prn_Dot_Ring[idx][7], 0, 9);
		memcpy(&Prn_Dot_Ring[idx][7+9], str, 30);
		memset(&Prn_Dot_Ring[idx][7+9+30], 0, PRN_DOT_BUF_MAX-(7+9+30));
		#endif
		idx++;
		phead++;
	}
}

// 非压缩图像数据转换.
void CvtBmpNormal(const byte *src)
{
	byte 	i;
	byte 	idx;

	idx = phead;

	for (i=0; i<BMP_LINE; i++)
	{
		Prn_Dot_Ring[idx][0] = NM_DOT_FD_CNTR;
		Prn_Dot_Ring[idx][1] = 2;
		
		#if 0
		memset(&Prn_Dot_Ring[idx][7], 0, 1);
		memcpy(&Prn_Dot_Ring[idx][7+1], src, 30);
		memset(&Prn_Dot_Ring[idx][7+1+30], 0, 1+8+1);
		memcpy(&Prn_Dot_Ring[idx][7+1+30+1+8+1], src, 30);
		memset(&Prn_Dot_Ring[idx][7+1+30+1+8+1+30], 0, 1);
		#else
		apply_one_line();
		memset(&Prn_Dot_Ring[idx][7], 0, 9);
		memcpy(&Prn_Dot_Ring[idx][7+9], src, 30);
		memset(&Prn_Dot_Ring[idx][7+9+30], 0, PRN_DOT_BUF_MAX-(7+9+30));
		#endif
		idx++;
		src += 30;
		phead++;
	}
}

⌨️ 快捷键说明

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