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

📄 ldrawtxt.cpp

📁 ldraw_DOS游戏开发包
💻 CPP
字号:
#include <ldraw.h>
#include <string.h>
#include <dos.h>
#include <stdio.h>
////////////////////////////////////////////////////////////////////////////
static uchar *word_data_RomAsc=(uchar *)0xffa6eL,
             *word_data_Asc=word_data_RomAsc,
             *word_FontBuf=NULL,word_Chinese=1;
static short word_data_delay=0, word_data_ch=16, 
             word_data_eh=8, word_d_cl=32, word_d_el;
static char  word_proc_BlitAsc(short x,short y,char c);
static char  word_proc_BlitChn(short x,short y,char *s);
static void  word_proc_ReadDot(unsigned char *ChineseCode);
static uchar *word_DotBuf,word_DotR=0,word_AddX=1;
static char  *word_cfont="HZK16.";
////////////////////////////////////////////////////////////////////////////
void lChineseLoad(char *font);
void lChineseUnLoad();
void lAscLoad(char *font);
void lAscUnLoad();
void lAscLoad(char *fname)
{ FILE *f; 
  if (word_data_Asc!=word_data_RomAsc) return;
  if ((f=fopen(fname,"rb"))==NULL) return; 
  word_data_Asc=new uchar[256*8];
  fread(word_data_Asc,256*3,1,f); fclose(f);
}
void lAscUnLoad()
{ if (word_data_Asc==word_data_RomAsc) return;
  delete word_data_Asc; word_data_Asc=word_data_RomAsc; 
}
void lChineseUnLoad()
{ if (word_FontBuf==NULL) return;
  delete word_FontBuf;
  word_FontBuf=NULL; word_Chinese=0;
}
void lChineseLoad(char *font)
{ FILE *f; int len;
  if (word_FontBuf!=NULL) return;
  word_Chinese=0;
  if ((f=fopen(font,"rb"))==NULL) return;
  fseek(f,0,SEEK_END); len=ftell(f)+1;
  word_FontBuf=new uchar[len];
  if (!word_FontBuf) { fclose(f); return; }
  fseek(f,0,SEEK_SET);
  fread(word_FontBuf,len,1,f);
  fclose(f);
  word_Chinese=1;
}
static void  word_proc_ReadDot(unsigned char *ChineseCode)
{ int lptr=((ChineseCode[0]-0xa1)*94L+ChineseCode[1]-0xa1)*word_d_cl;
  if (word_FontBuf==NULL&&word_DotR==0) lChineseLoad(word_cfont);
  word_DotR=1; if (word_FontBuf==NULL) { word_DotBuf=word_data_RomAsc; return; }
  word_DotBuf=word_FontBuf+lptr; 
}
////////////////////////////////////////////////////////////////////////////
void louttext(short *win,char *b)
{ int l=strlen(b),
      x=win[0],y=win[1]+(word_data_ch>>1),c=0;
  unsigned char s[3]="  ";
  x+=word_AddX;
  while (c<l) {
      s[0]=b[c]; s[1]=b[c+1];
      if (s[0]=='\r') x=win[0], ++c;
	 else
      if (s[0]=='\n') y+=16, x=win[0], ++c;
	 else
      if (s[0]<='z'||word_Chinese==0) { if (x+8>win[2]) x=win[0], y+=16;
         x+=word_proc_BlitAsc(x,y-(word_data_eh>>1),s[0]); c++; 
      } else { if (x+16>win[2]) x=win[0], y+=16;
        x+=word_proc_BlitChn(x,y-(word_data_ch>>1),(char*)s); c+=2; 
      }
         
      if (word_data_delay!=0) delay(word_data_delay);
  }
}
void louttext(char *b)
{
  int l=strlen(b),
      x=ld_x,y=ld_y,c=0;
  unsigned char s[3]="  ";
  x+=word_AddX;
  while (c<l) {
      s[0]=*(b+c); s[1]=*(b+c+1);
      if (s[0]=='\r') x=0, ++c;
	 else
      if (s[0]=='\n') y+=16, x=0, ++c;
	 else
      if (s[0]<='z'||word_Chinese==0) { x+=word_proc_BlitAsc(x,y-(word_data_eh>>1),s[0]); c++; }
         else { x+=word_proc_BlitChn(x,y-(word_data_ch>>1),(char*)s); c+=2; }
         
      if (word_data_delay!=0) delay(word_data_delay);
  }
  ld_x=x; ld_y=y;
}
void louttextxy(short x,short y,char *s)
{ ld_x=x; ld_y=y; louttext(s);
}

static char word_proc_BlitChn(short x,short y,char *ChineseCode)
{
   unsigned char        c;
   short                i,j;
   
   if (x<-16||y<-16||x>DrawLen||y>DrawWid) return 16;
   word_proc_ReadDot((uchar*)ChineseCode);
   if (word_DotBuf==NULL) return 0;
   if (ChineseCode[0]==0||ChineseCode[0]==0x20||ChineseCode[1]==0||ChineseCode[1]==0x20) return 0;
   for (i=0;i<16;i++){
      c=word_DotBuf[i<<1];
      for (j=0;j<8;j++){
	 if (c & 0x80) lpixel(x+j,y+i,ld_workColor);
	    else if (ld_workBColor) lpixel(x+j,y+i,ld_workBColor);
	 c=c<<1; 
      } c=word_DotBuf[(i<<1)+1];
      for (j=0;j<8;j++){
	 if (c & 0x80) lpixel(x+j+8,y+i,ld_workColor);
	    else if (ld_workBColor) lpixel(x+j+8,y+i,ld_workBColor);
	 c=c<<1;
      }
   }
  return 16;
}
static char word_proc_BlitAsc(short xc,short yc,char c)
{int x,y;
 uchar *work_char = word_data_Asc + c * 8, mask;

 if (xc<-8||yc<-8||xc>DrawLen||yc>DrawWid) return 8;
 for (y=0; y<8; y++) {
    mask = 0x80;
    for (x=0; x<8; x++)	{
	if ((*work_char & mask)) lpixel(xc+x,yc+y,ld_workColor);
	   else if (ld_workBColor) lpixel(x+xc,y+yc,ld_workBColor);
	mask >>=1;
	}
    work_char++;
    }
return 8;
}

⌨️ 快捷键说明

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