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

📄 fire.c

📁 Many C samples. It is a good sample for students to learn C language.
💻 C
字号:
/* Fire */
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>

char x_amt_1 = 0, x_amt_2 = 1, x_amt_3 = -1, x_amt_4 = 1, x_amt_5 = -1;
char y_amt_1 = -1, y_amt_2 = 0, y_amt_3 = 0, y_amt_4 = 1, y_amt_5 = 1;
int opt_decay_at = 2, opt_decay_by = 2;
int pal_darkness = 2;
int current[56][80], working[56][80];

unsigned char pal[768]={   0,  0,  0,  0,  0, 0,  0,  0, 24,  0,  0, 28,
			   0,  0, 32,  0,  0, 32,  0,  0, 36,  0,  0, 40,
			   8,  0, 40, 16,  0, 36, 24,  0, 36, 32,  0, 32,
			  40,  0, 28, 48,  0, 28, 56,  0, 24, 64,  0, 20,
			  72,  0, 20, 80,  0, 16, 88,  0, 16, 96,  0, 12,
			 104,  0,  8,112,  0,  8,120,  0,  4,128,  0,  0,
			 128,  0,  0,132,  0,  0,136,  0,  0,140,  0,  0,
			 144,  0,  0,144,  0,  0,148,  0,  0,152,  0,  0,
			 156,  0,  0,160,  0,  0,160,  0,  0,164,  0,  0,
			 168,  0,  0,172,  0,  0,176,  0,  0,180,  0,  0,
			 184,  4,  0,188,  4,  0,192,  8,  0,196,  8,  0,
			 200, 12,  0,204, 12,  0,208, 16,  0,212, 16,  0,
			 216, 20,  0,220, 20,  0,224, 24,  0,228, 24,  0,
			 232, 28,  0,236, 28,  0,240, 32,  0,244, 32,  0,
			 252, 36,  0,252, 36,  0,252, 40,  0,252, 40,  0,
			 252, 44,  0,252, 44,  0,252, 48,  0,252, 48,  0,
			 252, 52,  0,252, 52,  0,252, 56,  0,252, 56,  0,
			 252, 60,  0,252, 60,  0,252, 64,  0,252, 64,  0,
			 252, 68,  0,252, 68,  0,252, 72,  0,252, 72,  0,
			 252, 76,  0,252, 76,  0,252, 80,  0,252, 80,  0,
			 252, 84,  0,252, 84,  0,252, 88,  0,252, 88,  0,
			 252, 92,  0,252, 96,  0,252, 96,  0,252,100,  0,
			 252,100,  0,252,104,  0,252,104,  0,252,108,  0,
			 252,108,  0,252,112,  0,252,112,  0,252,116,  0,
			 252,116,  0,252,120,  0,252,120,  0,252,124,  0,
			 252,124,  0,252,128,  0,252,128,  0,252,132,  0,
			 252,132,  0,252,136,  0,252, 136,   0,252, 140,   0,
			 252, 140,   0,252, 144,   0,252, 144,   0,252, 148,   0,
			 252, 152,   0,252, 152,   0,252, 156,   0,252, 156,   0,
			 252, 160,   0,252, 160,   0,252, 164,   0,252, 164,   0,
			 252, 168,   0,252, 168,   0,252, 172,   0,252, 172,   0,
			 252, 176,   0,252, 176,   0,252, 180,   0,252, 180,   0,
			 252, 184,   0,252, 184,   0,252, 188,   0,252, 188,   0,
			 252, 192,   0,252, 192,   0,252, 196,   0,252, 196,   0,
			 252, 200,   0,252, 200,   0,252, 204,   0,252, 208,   0,
			 252, 208,   0,252, 208,   0,252, 208,   0,252, 208,   0,
			 252, 212,   0,252, 212,   0,252, 212,   0,252, 212,   0,
			 252, 216,   0,252, 216,   0,252, 216,   0,252, 216,   0,
			 252, 216,   0,252, 220,   0,252, 220,   0,252, 220,   0,
			 252, 220,   0,252, 224,   0,252, 224,   0,252, 224,   0,
			 252, 224,   0,252, 228,   0,252, 228,   0,252, 228,   0,
			 252, 228,   0,252, 228,   0,252, 232,   0,252, 232,   0,
			 252, 232,   0,252, 232,   0,252, 236,   0,252, 236,   0,
			 252, 236,   0,252, 236,   0,252, 240,   0,252, 240,   0,
			 252, 240,   0,252, 240,   0,252, 240,   0,252, 244,   0,
			 252, 244,   0,252, 244,   0,252, 244,   0,252, 248,   0,
			 252, 248,   0,252, 248,   0,252, 248,   0,252, 252,   0,
			 252, 252,   4,252, 252,   8,252, 252,  12,252, 252,  16,
			 252, 252,  20,252, 252,  24,252, 252,  28,252, 252,  32,
			 252, 252,  36,252, 252,  40,252, 252,  40,252, 252,  44,
			 252, 252,  48,252, 252,  52,252, 252,  56,252, 252,  60,
			 252, 252,  64,252, 252,  68,252, 252,  72,252, 252,  76,
			 252, 252,  80,252, 252,  84,252, 252,  84,252, 252,  88,
			 252, 252,  92,252, 252,  96,252, 252, 100,252, 252, 104,
			 252, 252, 108,252, 252, 112,252, 252, 116,252, 252, 120,
			 252, 252, 124,252, 252, 124,252, 252, 128,252, 252, 132,
			 252, 252, 136,252, 252, 140,252, 252, 144,252, 252, 148,
			 252, 252, 152,252, 252, 156,252, 252, 160,252, 252, 164,
			 252, 252, 168,252, 252, 168,252, 252, 172,252, 252, 176,
			 252, 252, 180,252, 252, 184,252, 252, 188,252, 252, 192,
			 252, 252, 196,252, 252, 200,252, 252, 204,252, 252, 208,
			 252, 252, 208,252, 252, 212,252, 252, 216,252, 252, 220,
			 252, 252, 224,252, 252, 228,252, 252, 232,252, 252, 236,
			 252, 252, 240,252, 252, 244,252, 252, 248,252, 252, 252};

void dump2con()
{
  _SI = (unsigned int)&current[0][0];
  asm mov di,0
  asm mov ax,0A000h
  asm mov es,ax
  asm mov cx,40*45
XF1:
  asm mov ax,ds:[si]
  asm add si,2
  asm mov dl,al
  asm mov ax,ds:[si]
  asm add si,2
  asm mov dh,al
  asm mov es:[di],dx
  asm add di,2
  asm dec cx
  asm jnz XF1
}

void flame()
{
  int delta=0,i=0,x=0,y=0;
  int cl1=0,cl2=0,cl3=0,cl4=0,cl5=0,cl6=0;

  for(i=0;i<80;i++)
  {
    if(random(10) < 5)
    {
      delta=random(2)*255;
    }
    working[55][i]=delta;
    working[56][i]=delta;
  }

  for (y = 55; y >= 2; y--)
  {
    for (x = 1; x <= 79; x++)
    {
      cl1 = current[y + y_amt_1][x + x_amt_1];
      cl2 = current[y + y_amt_2][x + x_amt_2];
      cl3 = current[y + y_amt_3][x + x_amt_3];
      cl4 = current[y + y_amt_4][x + x_amt_4];
      cl5 = current[y + y_amt_5][x + x_amt_5];
      cl6 = (cl1+cl2+cl3+cl4+cl5) /5;

      if (cl6 > opt_decay_at)
        cl6 -= opt_decay_by;
      working[y-1][x] = cl6;
    }
  }

  for (y =0; y <= 56; y++)
  {
    for (x = 0; x <= 80; x++)
    {
      current[y][x] = working[y][x];
    }
  }

  dump2con();
}

void set_pal()
{
  int  i;

  for(i=0;i<768;i++)
  {
    pal[i] = pal[i] >> pal_darkness;
  }

  _SI = (unsigned int)&pal[0];
  asm mov cx,768
  asm mov dx,0x03c8
  asm xor al,al
  asm out dx,al
  asm inc dx
l1:
  asm lodsb
  asm out dx, al
  asm dec cx
  asm jnz l1
}


void set_mx(void)
{
  asm CLD
  asm MOV AX,13h
  asm INT 10h
  asm CLI
  asm MOV DX,3c4h
  asm MOV AX,604h
  asm OUT DX,AX
  asm MOV AX,0F02h
  asm OUT DX,AX

  asm MOV DX,3D4h
  asm MOV AX,14h
  asm OUT DX,AX
  asm MOV AX,0E317h
  asm OUT DX,AX
  asm MOV AL,9
  asm OUT DX,AL
  asm INC DX
  asm IN  AL,DX
  asm AND AL,0E0h
  asm ADD AL,7
  asm OUT DX,AL
}


void b4exit()
{
  asm mov ax,03h
  asm int 10h
}

void main()
{
  int x=0,y=0;
  int ch = ' ';

  atexit(b4exit);
  printf("\nFire Demo\nNhan phim bat ky de bat dau - ESC de ket thuc.");
  getch();
  set_mx();
  randomize();
  set_pal();

  for (y = 0; y <= 56; y++)
  {
    for (x = 0; x <= 80; x++)
    {
      current[y][x] = 0;
      working[y][x] = 0;
    }
  }

  do
  {
    flame();
    if(kbhit())
    {
      ch=getch();
    }
  } while (ch != 27);
}

⌨️ 快捷键说明

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