/*********************************************************/
/* VGA13H模式函数 */
/*********************************************************/
/*********************************************************/
# if !defined(__DOS_DEF_)
# include <dos.h>
# endif
/* 此处定义了一些通用的宏 */
# define BYTE unsigned char
# define WORD unsigned int
# define DWORD unsigned long
# define BOOL BYTE
# define TRUE 1
# define FALSE !TRUE
/* BIOS 8*8 西文字库的段地址和偏移量 */
WORD FONT_SEG;
WORD FONT_OFF;
void setmode();
void waitkey();
void closemode();
void GetFontAdd();
void locate(int Line,int Col);
void pset(int x,int y,BYTE color);
void setpal(int Color,BYTE r,BYTE g,BYTE b);
BYTE ScanKey(void);
BYTE point(int x,int y);
/* 获取BIOS 8*8 西文字库的段地址和偏移量 */
void GetFontAdd()
{
struct REGPACK regs;
regs.r_bx=0x0300;
regs.r_ax=0x1130;
intr(0x10,®s);
FONT_SEG=regs.r_es;
FONT_OFF=regs.r_bp;
}
/* 等待键盘输入 */
void waitkey()
{
_AX=0;
geninterrupt(0x16);
}
/* 设置VGA 13H模式 */
void setmode()
{
_AX=0x13;
geninterrupt(0x10);
GetFontAdd();
}
/* 设置文本模式 */
void closemode()
{
_AX=0x3;
geninterrupt(0x10);
}
/* 设置调色板 */
void setpal(int Color,BYTE r,BYTE g,BYTE b)
{
outportb(0x3c8,Color);
outportb(0x3c9,r);
outportb(0x3c9,g);
outportb(0x3c9,b);
}
/* 屏幕定位(用于输出字符)*/
void locate(int Line,int Col)
{
_DH=Line;
_DL=Col;
_AH=2;
_BX=0;
geninterrupt(0x10);
}
/* 从键盘缓冲区内直接读出扫描码 */
BYTE ScanKey(void)
{
int start,end;
WORD key=0;
start=peek(0,0x41a);
end=peek(0,0x41c);
if (start==end) return(0);
else
{
key=peek(0x40,start);
start+=2;
if (start==0x3e) start=0x1e;
poke(0x40,0x1a,start);
return(key/256);
}
}
/* 在(X,Y)处绘点 */
void pset(int x,int y,BYTE color)
{
pokeb(0xa000,y*320+x,color);
}
/* 取(X,Y)处颜色 */
BYTE point(int x,int y)
{
return peekb(0xa000,y*320+x);
}
/*---------------------------flame-------------------------*/
# include <stdlib.h>
# include "vga13h.h"
# include <dos.h>
void main()
{
int i,j;
unsigned int x,y,c;
setmode();
for (x=1;x<=32;x++)
{
setpal(x, x*2-1, 0, 0 );
setpal(x+32, 63, x*2-1, 0 );
setpal(x+64, 63, 63, x*2-1);
setpal(x+96, 63, 63, 63 );
}
while(ScanKey()!=1)
{
/*
for (i=0;i<16;i++)
for (j=0;j<16;j++)
pset(random(300)+j,random(150)+i,random(256));
*/
for (x=0;x<320;x+=2)
{
for (y=1;y<=202;y+=2)
{
c=(point(x,y)+point(x+2,y)+point(x,y+2)+point(x+2,y+2))>>2;
if (c--)
{
poke(0xa000,(y-2)*320+x,(c<<8)+c);
poke(0xa000,(y-1)*320+x,(c<<8)+c);
}
}
y-=2;
pset(x,y,random(320));
}
}
closemode();
}