Mô tả cảnh lửa cháy viết bằng ngôn ngữ hệ thống trong C.
Mã:
#include "stdlib.h"
#include "conio.h"
unsigned char flames[330][80];
void Pal(unsigned char Col,unsigned char R,unsigned char G,unsigned char B) {
	asm {
		mov dx,3c8h
		mov al,[Col]
		out dx,al
		inc dx
		mov al,[R]
		out dx,al
		mov al,[G]
		out dx,al
		mov al,[B]
		out dx,al

	}
}
void SetFirePalete() {
	for (int i = 0; i<50; i++) {
		Pal(i,0,0,0);
		Pal(i+50,i,0,0);
		Pal(i+100,49,i,0);
		Pal(i+150,49,49,i);
	}
}
void Fire() {
	int x,y,x1,y1;
	unsigned char Col;
	for(x1=-5; x1<=325; x1++)
	for(y1=120; y1<=200; y1++) {
		y = y1-120;
		x =x1 + 5;
		Col=(flames[x-1][y+1]+flames[x][y+1]+flames[x+1][y+1]+flames[x][y+2])/4;
		if(y1 ==199){ Col= random(80)+120;}
		if (Col>0) Col--;
		flames[x][y]= Col;
		if ( x1>0 && x1<319 && y1<199)
		asm {
			mov ax,0A000h
			mov es,ax
			mov bx,[y1]
			shl bx,1
			shl bx,1
			shl bx,1
			shl bx,1
			shl bx,1
			shl bx,1
			mov di,bx
			shl bx,1
			shl bx,1
			add di,bx
			add di,[x1]
			mov ah,[Col]
			mov es:[di],ah
		}
	}
}
void main () {
	asm { mov ax,13h; int 10h; }
	SetFirePalete();
	while(!kbhit( )) Fire();
	asm { mov ax,3h; int 10h; mov ah,4ch; int 21h;}
}