📄 video.cpp
字号:
#include "video.h"
typedef unsigned long DWORD;
static DWORD _inpd(int portnum);
static DWORD _outpd(int portnum, DWORD val);
unsigned long VIDDID(int iBus, int iDevice);
FILE *fpE;
FILE *fpC;
unsigned char *pFontE;
unsigned char *pFontC;
unsigned far int * pVideoMem; //Base Address for Memory Buffer
int iOldPage = 0; //Store Video Page number
//double asp_ratio = 1.0; //Aspection ration of circle
/****************************************************
Function:
Initial to specified graphics mode
Input parameter:
iMode: Graph Mode.
0x114 for 800*600*16bit,
0x3 for 80*25 text mode
Output parameter:
0: Error
1: OK
****************************************************/
int Graph_Mode(int iMode)
{
if(VIDDID(0, 0)!=0x71008086)
return 0;
pVideoMem = (unsigned int *)MK_FP(0xA000, 0);
union REGS in, out;
if(iMode>=0x100)
{
in.x.bx=iMode;
in.x.ax=0x4F02;
int86(0x10,&in,&out);
return 1;
}
else
{
in.x.ax=iMode;
int86(0x10,&in,&out);
return 1;
}
}
/****************************************************
Function:
Initial to graphics mode
Input parameter:
None
Output parameter:
0: Error
1: OK
****************************************************/
int InitGraph()
{
if(VIDDID(0, 0)!=0x71008086)
return 0;
return Graph_Mode(0x114); //or, 0x114 for SVGA
}
/****************************************************
Function:
close graphics mode
Input parameter:
None
Output parameter:
None
****************************************************/
void CloseGraph()
{
Graph_Mode(0x3);
}
/****************************************************
Function:
Switch to specified video page
Input parameter:
iPageNumber
Output parameter:
None
****************************************************/
void VideoPage(int iPageNumber)
{
union REGS in, out;
in.x.bx=0;
in.x.dx=iPageNumber;
//i.x.dx=iPageNumber*16;
in.x.ax=0x4F05;
int86(0x10,&in,&out);
iOldPage = iPageNumber;
return;
}
/****************************************************
Function:
Paint the whole screen with chaned color
Input parameter:
None
Output parameter:
None
****************************************************/
void PaintScreen()
{
unsigned int i;
unsigned long iCount;
int iPage, iBlue;
iCount=0;
for(iPage=0; iPage<15; iPage++)
{
VideoPage(iPage);
for(i=0; i<32768; i++)
{
iCount++;
iBlue = iCount*256/(15*32768);
*(pVideoMem+i) = RGB(0, 0, iBlue);
}
}
}
/****************************************************
Function Name:
ClearDevice
Function:
Clear the screen with specified color
Input parameter:
iBackColor: Specified back ground color
Output parameter:
None
****************************************************/
void ClearDevice(int iBackColor)
{
unsigned int i;
int iPage;
for(iPage=0; iPage<15; iPage++)
{
VideoPage(iPage);
for(i=0; i<32768; i++)
{
*(pVideoMem+i) = iBackColor;
}
}
}
/****************************************************
Function:
Fill whole screen with black. like cleardevice
Input parameter:
None
Output parameter:
None
****************************************************/
void ClearToBlack()
{
unsigned int i;
int iPage;
for(iPage=0; iPage<15; iPage++)
{
VideoPage(iPage);
for(i=0; i<32768; i++)
*(pVideoMem+i) = 0;
}
}
/****************************************************
Function:
Draw a point with specified color
Input parameter:
x, y: coordinate
iColor: specified color
Output parameter:
None
****************************************************/
void SetPoint(int x, int y, unsigned int iColor)
{
unsigned long iDist, iTemp;
unsigned int iPos;
int iPN;
iDist = 800l*y+x;
iTemp = iDist;
iPN = 0;
while(iTemp>32768)
{
iTemp = iTemp - 32768;
iPN++;
}
iPos = iTemp;
if(iPN != iOldPage)
VideoPage(iPN);
*(pVideoMem+iPos) = iColor;
}
/****************************************************
Function:
Draw a line with specified color
Input parameter:
startx, starty: coordinate of start point
endx, endy: coordinate of end point
iColor: specified color
Output parameter:
0: Error
1: OK
****************************************************/
int MemLine(int startx, int starty, int endx, int endy, unsigned int color)
{
register int t, distance;
int xerr=0, yerr=0, delta_x, delta_y;
int incx, incy;
delta_x = endx-startx;
delta_y = endy-starty;
if(delta_x>0) incx = 1;
else if (delta_x == 0 ) incx = 0;
else incx = -1;
//Compute the direcxtion of the increment,
//an increment of 0 means either a vertical of horizontral line.
if(delta_y>0) incy = 1;
else if (delta_y == 0 ) incy = 0;
else incy = -1;
//Determine which distance is greater
delta_x = abs(delta_x);
delta_y = abs(delta_y);
if(delta_x>delta_y) distance = delta_x;
else distance = delta_y;
//Draw the line
for(t=0; t<=distance+1; t++)
{
SetPoint(startx, starty, color);
xerr+=delta_x;
yerr+=delta_y;
if(xerr>distance)
{
xerr-=distance;
startx+=incx;
}
if(yerr>distance)
{
yerr-=distance;
starty+=incy;
}
}
return 1;
}
/****************************************************
Function:
Draw a box
Input parameter:
startx, starty: coordinate of left - top
endx, endy: coordinate of right - bottom
iColor: specified color
Output parameter:
None
****************************************************/
void MemBox(int startx, int starty, int endx, int endy, unsigned int color)
{
MemLine(startx, starty, endx, starty, color);
MemLine(endx, starty, endx, endy, color);
MemLine(endx, endy, startx, endy, color);
MemLine(startx, endy, startx, starty, color);
}
/****************************************************
Function:
Draw a box with specified color filled
Input parameter:
startx, starty: coordinate of left - top
endx, endy: coordinate of right - bottom
iColor: specified color
Output parameter:
None
****************************************************/
void MemFillBox(int startx, int starty, int endx, int endy, unsigned color)
{
register int i, begin, end;
begin = startx<endx? startx:endx;
end = startx>endx? startx:endx;
for(i=begin; i<end; i++)
MemLine(i, starty, i, endy, color);
}
/****************************************************
Function:
Draw a circle with specified color
Input parameter:
x_center, y_center: coordinate of circle center
radius: radius of circle
iColor: specified color
Output parameter:
None
****************************************************/
void MemCircle(int x_center, int y_center, int radius, unsigned int color)
{
register int x, y, delta;
y=radius;
delta = 3-2*radius;
for(x=0; x<y; )
{
plot_circle(x, y, x_center, y_center, color);
if(delta < 0)
{
delta+=4*x+6;
}
else
{
delta+=4*(x-y)+10;
y--;
}
x++;
}
x=y;
if(y)
plot_circle(x, y, x_center, y_center, color);
}
//Internal used by MemCircle
void plot_circle(int x, int y, int x_center, int y_center, unsigned int color)
{
int startx, endx, x1, starty, endy, y1;
starty=y; //*asp_ratio;
endy=(y+1); //*asp_ratio;
startx=x; //*asp_ratio;
endx=(x+1); //*asp_ratio;
for(x1=startx; x1<endx; ++x1)
{
SetPoint(x1+x_center, y+y_center, color);
SetPoint(x1+x_center, y_center-y, color);
SetPoint(x_center-x1, y_center-y, color);
SetPoint(x_center-x1, y+y_center, color);
}
for(y1=starty; y1<endy; ++y1)
{
SetPoint(y1+x_center, x+y_center, color);
SetPoint(y1+x_center, y_center-x, color);
SetPoint(x_center-y1, y_center-x, color);
SetPoint(x_center-y1, x+y_center, color);
}
}
/****************************************************
Function:
Draw a circle with specified color filled
Input parameter:
x_center, y_center: coordinate of circle center
radius: radius of circle
iColor: specified color
Output parameter:
None
****************************************************/
void MemFillCircle(int x, int y, int r, unsigned int color)
{
while(r)
{
MemCircle(x, y, r, color);
r--;
}
}
/****************************************************
Function:
Open Font to get information for DrawEnglish,
must call this function before draw any text.
Input parameter:
None
Output parameter:
0: Error
1: Succesfully
****************************************************/
int OpenEFont()
{
if(VIDDID(0, 7)!=0x71108086)
return 0;
fpE=fopen("asc16", "rb");
if(fpE == NULL)
{
printf("Error opening asc16\n");
printf("Press any key to exit...\n");
getch();
return 0;
}
pFontE = (unsigned char *)malloc(sizeof(char)*16);
return 1;
}
/****************************************************
Function:
Close Font, must call it before exit.
Input parameter:
None
Output parameter:
None
****************************************************/
void CloseEFont()
{
fclose(fpE);
free(pFontE);
}
/****************************************************
Function:
Draw an English character
Input parameter:
x, y: coordinate of character
c: character
iColor: specified color
Output parameter:
None
****************************************************/
void DrawEnglish(int x, int y, int c, int iColor)
{
int ix, iy;
fseek(fpE, 16l*c, SEEK_SET);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -