DOS下的屏幕保护

#include "dos.h"
#include "conio.h"
#include "stdlib.h"
#include "math.h"
#include "time.h"

#define MAX 30
#define FIRSTPAGE 5
#define LASTPAGE 6
#define Z 3
#define DELAY_TIME 3000

int ACTIVEPAGE=0;
struct {
      int x,y;
      int dx,dy;
      int color;
      int active;
      }dot[MAX];
struct {
      int x,y;
      int color;
      }bigchar;

void tSetVisualPage(char page);
void tClrScr(unsigned char color);
void tPutCh(int x,int y,int color,unsigned char ch);
void tBigChar(int x,int y,int z,int color);
void tSetActivePage(int page);
void tInit(int fx,int fy);
void tMove(int fx,int fy,int fr);
void tProtectScr();

main()
{
 tProtectScr();
}

void tProtectScr()
{
  int i,page,fx,fy,fr,cycle=1,fire,permit=1;
  bigchar.x=10; bigchar.y=6; bigchar.color=random(14)+1;
  page=FIRSTPAGE;
  tSetVisualPage(FIRSTPAGE);
  randomize();
  while(cycle){
    if(bigchar.x>80){
       bigchar.y=(bigchar.y>12)?0:bigchar.y+1;
       bigchar.color=random(15)+1;
       }
    bigchar.x=(bigchar.x>80)?-(32+Z*3):bigchar.x+1;
    fx=random(79); fy=random(24); fr=random(20);
    tInit(fx,fy);
    fire=(random(10)>4)?1:0;
    permit=(random(10)>5)?1:0;
    for(i=0;i<10;i++){
      tSetActivePage(page=(page==LASTPAGE)?FIRSTPAGE:LASTPAGE);
      tClrScr(BLACK);
      if(permit){
 tBigChar(bigchar.x,bigchar.y,Z,bigchar.color);
 if(fire) tMove(fx,fy,fr);
 }
      else{
 if(fire) tMove(fx,fy,fr);
 tBigChar(bigchar.x,bigchar.y,Z,bigchar.color);
 }
      tSetVisualPage(page);
      if(kbhit()){ cycle=0; break;}
      delay(DELAY_TIME);
      } /* for end */
    }   /* while end */
  tSetVisualPage(0);
  printf("/nProtect Screen normal shut off.");
}

void tMove(int fx,int fy,int fr)
{
  int i,piece;
  for(i=0;i<MAX;i++){
    if( hypot(abs(dot[i].x-fx),abs(dot[i].y-fy))>fr )  dot[i].active=0;
    if(dot[i].active!=0){
      tPutCh(dot[i].x,dot[i].y,dot[i].color,220);
      dot[i].x+=dot[i].dx;
      dot[i].y+=dot[i].dy;
      }
    }
}

void tInit(int fx,int fy)
{
  int i;
  for(i=0;i<MAX;i++){
    dot[i].x=fx; dot[i].y=fy;
    dot[i].dx=3-random(6); dot[i].dy=3-random(6);
    dot[i].color=random(14)+1;
    dot[i].active=1;
    }
}

void tSetActivePage(int page)
{
  if(page<0 || page>7) return;
  ACTIVEPAGE=page;
}

void tBigChar(int x,int y,int z,int color)
{
  int i,n,j,oldy;
  static unsigned char chardot[4][12]={
 {0,0,0x7c,0xc6,0xc6,0x60,0x38,0xc,6,0xc6,0xc6,0x7c},
 {0,0,0xfe,0x66,0x62,0x68,0x78,0x68,0x60,0x62,0x66,0xfe},
 {0,0,0xfc,0x66,0x66,0x66,0x7c,0x60,0x60,0x60,0x60,0xf0},
 {0,0,0x3c,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x3c} };
  oldy=y;
  for(n=0;n<4;n++,x+=(z+8))
    for(i=0,y=oldy;i<12;i++,y++)
      for(j=0;j<8;j++)
 if( (chardot[n][i]>>(7-j)) &1) tPutCh(x+j,y,color,219);
}

void tPutCh(int x,int y,int color,unsigned char ch)
{
  unsigned char far *buf;
  if(x>79 || x<0 || y<0 || y>24) return;
  buf=(unsigned char far *)0xb8000000+0x1000*ACTIVEPAGE;
  *(buf+y*160+x*2)=(unsigned char)ch;
  *(buf+y*160+x*2+1)=(unsigned char)color;
}

void tClrScr(unsigned char color)
{
  unsigned char far *buf;
  int i;
  buf=(unsigned char far *)0xb8000000+0x1000*ACTIVEPAGE;
  for(i=0;i<4000;i+=2){
    *(buf+i)=32;
    *(buf+i+1)=(unsigned char)color<<4;
    }
}

void tSetVisualPage(char page)
{
  union REGS r;
  r.h.ah=5; r.h.al=page;
  int86(0x10,&r,&r);
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值