主题:[原创]黑客帝国之数据流
// 主要应用调色板技术,完全原创,版权所有,随便传播。
// Windows XP - Turbo C++ 3.1 - Designed By Wangdawei.Pkuschool
// PS:由于无法截屏,只好发上源代码及可执行文件。
#include <DOS.H>
#include <MATH.H>
#include <STDIO.H>
#include <STRING.H>
#include <STDLIB.H>
#include <BIOS.H>
#define SCREENWIDTH 640
#define SCREENHEIGHT 480
#define CHARWIDTH 8
#define CHARHEIGHT 8
#define PALETTEMASK 0x3C6
#define PALETTEDATA 0x3C9
#define PALETTEREGISTERWR 0x3C8
#define PALETTEREGISTERRD 0x3C7
#define UNLONG unsigned long
#define UNCHAR unsigned char
#define UNINT unsigned int
typedef struct PaletteType
{
UNCHAR red;
UNCHAR blue;
UNCHAR green;
}
Palette,*PalettePtr;
#define ADDRESS(X,Y) ((UNLONG)(Y)<<7)+((UNLONG)(Y)<<9)+(UNLONG)(X)
class cMatrix
{
public:
void SetDisplayMode(int mode);
void PutEng(int x, int y, char character, char color);
void PutPixel(int x,int y,int color);
void SetPaletteRegister(int index, PalettePtr color);
void Delay(UNINT time);
private:
UNCHAR newpage,oldpage;
}Matrix;
union REGS reg;
unsigned char far *romcharset = (unsigned char far *)0xF000FA6EL;
unsigned char far *VideoBuffer = (unsigned char far *)0xA0000000L;
void cMatrix::SetDisplayMode(int mode)
{
reg.x.ax = 0x4F02;
reg.x.bx = mode;
int86(0x10,®,®);
}
void cMatrix::PutPixel(int x,int y,int color)
{
UNLONG address = ADDRESS(x,y);
UNLONG offset;
newpage = (address >> 16);
if (newpage!=oldpage)
{
reg.x.ax = 0x4F05;
reg.x.bx = 0;
reg.x.dx = newpage;
int86(0x10,®,®);
oldpage = newpage;
}
offset = address - (newpage << 16);
VideoBuffer[offset] = color;
}
void cMatrix::PutEng(int x, int y, char character, char color)
{
int i,j;
char far *charpos;
unsigned char bitmask = 0x80;
charpos = romcharset + character * CHARHEIGHT;
for (j=0;j<CHARHEIGHT;j++)
{
bitmask = 0x80;
for (i=0;i<CHARWIDTH;i++)
{
if ((*charpos&bitmask))
PutPixel(x+i,y+j,color);
bitmask = (bitmask>>1);
}
charpos++;
}
}
void cMatrix::SetPaletteRegister(int index, PalettePtr color)
{
outp(PALETTEMASK, 0xFF);
outp(PALETTEREGISTERWR, index);
outp(PALETTEDATA, color->red);
outp(PALETTEDATA, color->green);
outp(PALETTEDATA, color->blue);
}
void cMatrix::Delay(UNINT time)
{
UNINT far *clock = (UNINT far *)0x0000046CL;
UNINT now = *clock;
while (abs(*clock-now)<time){}
}
void main()
{
UNCHAR status[60][80][2];
PalettePtr color;
int x,y,index = 0;
Matrix.SetDisplayMode(0x101);
for (;index<128;index++)
{
color -> red = 0;
color -> blue = 0;
color -> green = index*2;
Matrix.SetPaletteRegister(index,color);
}
color -> red = 0;
color -> blue = 0;
color -> green = 0;
Matrix.SetPaletteRegister(128,color);
for (x=0;x<60;x++)
for (y=0;y<80;y++)
{
status[x][y][0] = rand()%128; // 修改此处可以控制 ASCII 码,如修改为 rand()%2+48 就是满屏的1和0
status[x][y][1] = 128;
Matrix.PutEng(8*y,8*x,status[x][y][0],status[x][y][1]);
}
while (bioskey(1)==0)
{
if ((rand()%10)>5)
status[0][rand()%80][1]=127;
for (x=59;x>=0;x--)
for (y=79;y>=0;y--)
{
if (status[x][y][1]<128&&status[x][y][1]>=0)
{
Matrix.PutEng(8*y,8*x+8,status[x+1][y][0],status[x][y][1]);
status[x+1][y][1] = status[x][y][1];
Matrix.PutEng(8*y,8*x,status[x][y][0],status[x][y][1]--);
}
else status[x][y][1]=128;
}
}
}
// 时间紧急没有写注释,不过相信大家应该能看懂。
// 后面的循环采用了特殊的方式,大家仔细看看就明白了。
// 因此处空间有限,所以源程序下载在
// [url]http://www.vb126.com/bbs/dispbbs.asp?boardID=5&ID=74[/url]
// 我的网络硬盘,可以下载到编译好的文件EXE:(进入后点击“公开的程序及参考资料”)
// [url]http://davidw017.ys168.com[/url]