回 帖 发 新 帖 刷新版面

主题:冰玉的原代码在这里,主要参考《电脑爱好者》及《c游戏编程从入门到精通》,没有时间,你可以参考!哈哈。

















#include<bios.h>
#include<dos.h>
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
#include<iostream.h>
typedef struct
{       char manufacturer;
char version;
char encoding;
char bitsperpixel;
int xmin,ymin;
int xmax,ymax;
int hres,vres;
char palette[48];
char reserved;
char colorplanes;
int width;
int palettetype;
char filler[58];
}PCXHEAD;
long DisplayAdd=0xa0000000;
int CUR_PAGE=0;
void SelectPage(int page)
{    union REGS r;
     r.x.ax=0x4f05;
     r.x.bx=0;
     r.x.dx=page;
     int86(0x10,&r,&r);
}
void PutPixel(long x,long y,unsigned char color)
{    unsigned int page,offset;
     long pixel;
     pixel=x+(y<<9)+(y<<7);
     //pixel+y*640=x+y*(512+128)=x+(y<<9)+(y<<7);
     page=(pixel>>16);
     //page=pixel/0x10000=(pixel>>16);
     offset=pixel-(page<<16);
     //offset=pixel%0x10000=pixel-page*0x10000;
     if(page!=CUR_PAGE)
     { SelectPage(page);
       CUR_PAGE=page;
     }
     *(unsigned char far *)(DisplayAdd+offset)=color;
}
void LoadPicture(char *filename,int Left,int Top)
{    FILE *fpPcxFile;
     PCXHEAD PcxHeader;
     int x,y,count,total,height;
     char ColorTable[256][3],data;
     if((fpPcxFile=fopen(filename,"rb"))==NULL)
     { cerr<<"\a Cannot open"<<filename<<endl;
       getch();
       exit(0);
     }
     fread((char *)&PcxHeader,sizeof(PCXHEAD),1,fpPcxFile);
     height=PcxHeader.ymax-PcxHeader.ymin+1;
     fseek(fpPcxFile,-769L,SEEK_END);
     if(fgetc(fpPcxFile)!=0x0c)
     { cerr<<filename<<"is not a 256-color Pcx file.\a\n";
       getch();
       exit(0);
     }
     fread(ColorTable,1,768,fpPcxFile);
     for(x=0;x<256;x++)
     {  outp(0x3c8,x);
for(y=0;y<3;y++)
   outp(0x3c9,ColorTable[x][y]>>2);
     }
     fseek(fpPcxFile,128L,SEEK_SET);
     for(y=0+Top;y<height+Top;y++)
     {  total=0;
while(total<PcxHeader.width)
{    count=1;
     data=fgetc(fpPcxFile);
     if(0xc0==(0xc0&data))
     { count=0x3f&data;
       data=fgetc(fpPcxFile);
     }
     for(x=0+Left;x<count+Top;x++)
     PutPixel(x+total,y,data);
     total+=count;
}
     }
     fclose(fpPcxFile);
}








#include<dos.h>
#include<string.h>
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
#include<process.h>
#include<dos.h>
#include<conio.h>
#include<math.h>
#define PI 3.1415926
#include"c:\borlandc\dmcl\cpp\Pcx.h"
#include"c:\borlandc\dmcl\cpp\word.h"
unsigned char bit[8]={128,64,32,16,8,4,2,1};

void LoadMouse()
      {
    _AX=0x00;
    geninterrupt(0x33);
      }
int Read(int *MouseX,int *MouseY)
      {
int xx0=*MouseX,yy0=*MouseY;
int XNew,YNew;
        union REGS regs;
do
{
  regs.x.ax=0x03;
  int86(0x33,&regs,&regs);
  XNew=regs.x.cx;
  YNew=regs.x.dx;
}while(XNew==xx0&&YNew==yy0);
*MouseX=XNew;
*MouseY=YNew;
      }

void Delay(int clicks)
{
unsigned int far *clock=(unsigned int far *)0x0000046CL;
unsigned int now;
now=*clock;
while(abs(*clock-now)<clicks){}
}


void GetHzBit(char ch0,char ch1,char *bitdata)
{
FILE *stream;
long fpos;
fpos=32L*(((unsigned char)ch0-161)*94+((unsigned char)ch1-161));
if((stream=fopen("c:\\borlandc\\dmcl\\hzk\\hzk16","rb"))==NULL){
printf("Open hzk16 error!\n");
exit(0);
}
fseek(stream, fpos, SEEK_SET);
fread( bitdata, 32, 1, stream);
fclose(stream);
}

void WriteHz(char ch0,char ch1,int x,int y,int color)
{
register int i,j,k;
unsigned vpos;
char bitdata[32];
GetHzBit(ch0,ch1,bitdata);
for(i=0;i<16;i++)
for(j=0;j<8;j++){
if(bitdata[2*i]&bit[j])
PutPixel(x+j,i+y,color);
if(bitdata[2*i+1]&bit[j])
PutPixel(x+8+j,i+y,color);
}
}
void WriteHzStr(char *str,int x,int y,int color)
{
int num,i,j,xx;
unsigned char s0,s1;
num=strlen(str);
xx=x;
for(i=0;i<num;i+=2){
WriteHz(str[i],str[i+1],xx,y,color);
xx+=16;
}
}

void Words_Step(char *str,int x,int y,int color,int speed)
{
int num,i,j,xx;
unsigned char s0,s1;
num=strlen(str);
xx=x;
for(i=0;i<num;i+=2){
WriteHz(str[i],str[i+1],xx,y,color);
Delay(speed);
xx+=16;
}
}

void Set_Video_Mode(int mode)
{
union REGS inregs,outregs;
inregs.h.ah=0;
inregs.h.al=(unsigned char)mode;
int86(0x10,&inregs,&outregs);
}
void DRAWCIRCLE(int X,int Y,int R,int COLOR)
{
int XX,YY,ANGLE;
for(ANGLE=0;ANGLE<360;ANGLE++)
{
XX=X+R*cos(2*PI*ANGLE/360);
YY=Y+R*sin(2*PI*ANGLE/360);
PutPixel(XX,YY,COLOR);
}

}

void CHANGE_COLOR(int COLORNUM,int Red,int Green,int Blue)
{
outportb(0x3c8,COLORNUM);
outportb(0x3c9,Red);
outportb(0x3c9,Green);
outportb(0x3c9,Blue);
}

void DRAWLINE(int X,int Y,int LENGTH,int COLOR)
{
int NUM;
for(NUM=0;NUM<LENGTH;NUM++)
PutPixel(X+NUM,Y,COLOR);
}
void DRAWBAR(int X,int Y)
{
int NUM;
int Red=0,Green=0,Blue=0;
for(NUM=0;NUM<15;NUM++)
{
CHANGE_COLOR(NUM,Red,Green,Blue);
Blue+=4;
Red+=3;
Green+=2;
}
int TEMP_Y=Y;
for(NUM=14;NUM>=0;NUM--)
DRAWLINE(X,TEMP_Y--,200,NUM);
TEMP_Y=Y;
for(NUM=14;NUM>=0;NUM--)
DRAWLINE(X,TEMP_Y++,200,NUM);
}
void DRAW(int X,int Y)
{
int NUM;
int Red=0,Green=0,Blue=0,R=0;
for(NUM=0;NUM<=15;NUM++)
{
CHANGE_COLOR(NUM,Red,Green,Blue);
Blue+=2;
Red+=4;
Green+=2;
}
for(NUM=15;NUM>0;NUM--)
{
DRAWCIRCLE(X,Y,R++,NUM);
DRAWCIRCLE(X,Y,R++,NUM);
}
}
void initgraph()
{    union REGS r;
     r.x.ax=0x4f02;
     r.x.bx=0x101;
     int86(0x10,&r,&r);
     if(r.x.ax!=0x004f)
     { cerr<<"Error:\a\nYour video can doesn't support 640*480*256 mode";
       getch();
       exit(0);
     }
}
void closegraph()
{    union REGS r;
     r.h.ah=0;
     r.h.al=0x03;
     int86(0x10,&r,&r);
}
void main()
{
     int mousex,mousey;
     long i;
     initgraph();
     LoadPicture("c:\\borlandc\\dmcl\\pcx\\desktop.pcx",0,0);
     getch();
     /*LoadPicture("e:\\Menu2.pcx",0,0);
     getch();
     LoadPicture("e:\\Menu3.pcx",0,0);
     getch();
     LoadPicture("e:\\Menu4.pcx",0,0);
     getch();
     LoadPicture("e:\\Menu5.pcx",0,0);
     getch();
     LoadPicture("e:\\hua640.pcx",0,0);
     getch();*/
     for(i=0;i<256;i++)
PutPixel(i,330,i);
     for(i=0;i<256;i++)
PutPixel(330,i,i);
     getch();
     DRAWBAR(100,300);
     getch();
     DRAW(100,100);
     getch();
     PutS(200,300,YELLOW,BLACK,"My name is WangBingZheng!");
     DRAWCIRCLE(10,10,5,100);
     getch();
     Words_Step("现在文字处于渐显状态。",100,230,WHITE,4);
     getch();
     /*LoadPicture("e:\\c.pcx",0,0);
     getch();
     LoadPicture("e:\\program\\8\\wbz2.pcx",0,0);
     getch();
     LoadPicture("e:\\program\\8\\wbz3.pcx",0,0);
     getch();
     LoadPicture("e:\\program\\8\\025.pcx",40,40);
     getch();
     LoadPicture("e:\\l2640.pcx",0,0);
     getch();
     LoadPicture("e:\\l640.pcx",0,0);
     getch();
     LoadPicture("e:\\yj640.pcx",0,0);
     getch();*/
     closegraph();
}

回复列表 (共8个回复)

沙发

上面的为pcx.h文件

板凳

大虾:
   能否占用一下你宝贵的时间,发一份“宝码”到www_xyx@163.com,谢谢!

3 楼

发一份给我,xmzhy@21cn.com

4 楼

还有我:hexiyu@21cn.com

5 楼

我也要啊 areyouking@163.com

6 楼

jejbv,mdg dbf

7 楼

请给我也发一份,谢谢!

midjazzy@hotmail.com

8 楼

midjazzy@hotmail.com
请给我也发一份,谢谢!

我来回复

您尚未登录,请登录后再回复。点此登录或注册