📄 video.cpp
字号:
fread(pFontE, sizeof(char), 16, fpE);
for(iy=0; iy<16; iy++)
{
for(ix=0; ix<8; ix++)
{
if(*(pFontE+iy)&(1<<ix))
SetPoint(x+8-ix, iy+y, iColor);
}
}
}
/****************************************************
Function:
Draw an English string
Input parameter:
x, y: start coordinate of character
text: string that contains text
iColor: specified color
Output parameter:
None
****************************************************/
void DrawEnglishString(int x, int y, char *text, int iColor)
{
int ix, iy;
int i=0;
ix=x;
iy=y;
while(*(text+i))
{
DrawEnglish(ix, iy, *(text+i), iColor);
ix=ix+9;
i++;
}
}
/****************************************************
Function:
Open Font to get information for DrawEnglish,
must call this function before draw any text.
Input parameter:
None
Output parameter:
0: Error
1: OK
****************************************************/
int OpenCFont()
{
if(VIDDID(0, 11)!=0xc0102c)
return 0;
fpC=fopen("hzk16", "rb");
if(fpC == NULL)
{
printf("Error opening asc16\n");
printf("Press any key to exit...\n");
getch();
return 0;
}
pFontC = (unsigned char *)malloc(sizeof(char)*32);
return 1;
}
/****************************************************
Function:
Close Font, must call it before exit.
Input parameter:
None
Output parameter:
None
****************************************************/
void CloseCFont()
{
fclose(fpC);
free(pFontC);
}
/****************************************************
Function:
Draw an English character
Input parameter:
x, y: coordinate of character
c1, c2: code of Chinese word
iColor: specified color
Output parameter:
None
****************************************************/
void DrawChinese(int x, int y, int c1, int c2, int iColor)
{
int ix, iy;
unsigned long int qu, wei;
qu=c1-161;
wei=c2-161;
fseek(fpC, 32l*(94*qu+wei), SEEK_SET);
//fseek(fpC, 0x1100l*32, SEEK_SET);
fread(pFontC, 32, 1, fpC);
for(iy=0; iy<16; iy++)
{
for(ix=0; ix<8; ix++)
{
if(*(pFontC+iy*2)&(1<<ix))
SetPoint(x+8-ix, iy+y, iColor);
if(*(pFontC+iy*2+1)&(1<<ix))
SetPoint(x+16-ix, iy+y, iColor);
}
}
}
/****************************************************
Function:
Draw an Chinese string
Input parameter:
x, y: start coordinate of character
text: string that contains text
iColor: specified color
Output parameter:
None
****************************************************/
void DrawChineseString(int x, int y, unsigned char *text, int iColor)
{
int ix, iy;
int i=0;
int c1, c2;
ix=x;
iy=y;
while(*(text+i))
{
if(((*(text+i))&0x80)!=0) // Chinese Word.
{
c1=*(text+i);
i++;
c2=*(text+i);
i++;
DrawChinese(ix, iy, c1, c2, iColor);
ix=ix+16;
}
else // English word
{
c1=*(text+i);
i++;
DrawEnglish(ix, iy, c1, iColor);
ix=ix+8;
}
}
}
/////////////////////////////////////////////////////
//All following function added by the request of client
/////////////////////////////////////////////////////
/****************************************************
Function Name:
GetPoint
Function:
Get the color of specified point
Input parameter:
x, y: coordinate
Output parameter:
iColor: color of specified color
****************************************************/
unsigned int GetPoint(int x, int y)
{
unsigned long iDist, iTemp;
unsigned int iPos;
unsigned int iColor;
int iPN;
iDist = 800l*y+x;
iTemp = iDist;
iPN = 0;
while(iTemp>32768)
{
iTemp = iTemp - 32768;
iPN++;
}
iPos = iTemp;
if(iPN != iOldPage)
VideoPage(iPN);
iColor = *(pVideoMem+iPos);
return iColor;
}
/****************************************************
Function Name: GetImageSize
Function:
Get Size of Image needed, used to allocate memory
Input parameter:
iStartX, iStartY: left-up coordinate of box
iEndX, iEndY: right-bottom coordinate of box
Output parameter:
iImageSize: image size in bytes
****************************************************/
int GetImageSize(int iStartX, int iStartY, int iEndX, int iEndY)
{
return ((iEndX-iStartX)*(iEndY-iStartY)+2)*sizeof(int);
}
/****************************************************
Function Name: GetImage
Function:
Get Image from video buffer, save for other using
Be sure that iEndX>iStartX, and iEndY>iStartY!!!!!
Input parameter:
iStartX, iStartY: left-up coordinate of box
iEndX, iEndY: right-bottom coordinate of box
int *Buffer: buffer to store image
Output parameter:
None
****************************************************/
void GetImage(int iStartX, int iStartY, int iEndX, int iEndY, int far *Buffer)
{
unsigned long iCurX, iCurY;
int i=0;
*(Buffer+i)=iEndX-iStartX; //Store image width
i++;
*(Buffer+i)=iEndY-iStartY; //Store image height
i++;
for(iCurY=iStartY; iCurY<iEndY; iCurY++)
{
for(iCurX=iStartX; iCurX<iEndX; iCurX++)
{
*(Buffer+i)=GetPoint(iCurX, iCurY);
i++;
}
}
}
/****************************************************
Function Name: PutImage
Function:
Put saved image to specified position
Input parameter:
iStartX, iStartY: left-up coordinate of image
int *Buffer: buffer to store image
Output parameter:
None
****************************************************/
void PutImage(int iStartX, int iStartY, int far *Buffer)
{
unsigned long iCurX, iCurY;
int iEndX, iEndY;
int iWidth, iHeight;
int i=0;
iWidth=*(Buffer+i);
i++;
iHeight=*(Buffer+i);
i++;
iEndX=iStartX+iWidth;
iEndY=iStartY+iHeight;
for(iCurY=iStartY; iCurY<iEndY; iCurY++)
{
for(iCurX=iStartX; iCurX<iEndX; iCurX++)
{
SetPoint(iCurX, iCurY, *(Buffer+i));
i++;
}
}
}
/****************************************************
Function:
Draw a point with specified color, XOR_OUTPUT
Input parameter:
x, y: coordinate
iColor: specified color
Output parameter:
None
****************************************************/
void SetPointXOR(int x, int y, unsigned int iColor)
{
unsigned long iDist, iTemp;
unsigned int iPos;
int iPN;
unsigned int iOldColor;
iDist = 800l*y+x;
iTemp = iDist;
iPN = 0;
while(iTemp>32768)
{
iTemp = iTemp - 32768;
iPN++;
}
iPos = iTemp;
if(iPN != iOldPage)
VideoPage(iPN);
iOldColor=*(pVideoMem+iPos);
iColor=iColor^iOldColor;
*(pVideoMem+iPos) = iColor;
}
/****************************************************
Function:
Draw a line with specified color, XOR
Input parameter:
startx, starty: coordinate of start point
endx, endy: coordinate of end point
iColor: specified color
Output parameter:
None
****************************************************/
void MemLineXOR(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++)
{
SetPointXOR(startx, starty, color);
xerr+=delta_x;
yerr+=delta_y;
if(xerr>distance)
{
xerr-=distance;
startx+=incx;
}
if(yerr>distance)
{
yerr-=distance;
starty+=incy;
}
}
}
/****************************************************
Function:
32 bit inport
Input parameter:
portnum: port number
Output parameter:
32bit value
****************************************************/
static DWORD _inpd(int portnum)
{
static DWORD value;
asm mov dx, portnum;
asm lea bx, value;
#if defined(__BORLANDC__)
__emit__(0x66, 0x50, //push EAX
0x66, 0xED, //in EAX, DX
0x66, 0x89, 0x07, //mov [BX], EAX
0x66, 0x58); //pop EAX
#else
asm push eax;
asm in eax, dx;
asm mov [bx], eax;
asm pop eax;
#endif
return value;
}
/****************************************************
Function:
32 bit outport
Input parameter:
portnum: port number
val: 32bit data to output
Output parameter:
32bit value
****************************************************/
static DWORD _outpd(int portnum, DWORD val)
{
static DWORD value=0;
value = val;
asm mov dx, portnum;
asm lea bx, value;
#if defined(__BORLANDC__)
__emit__(0x66, 0x50, //push EAX
0x66, 0x8B, 0X07, //in EAX, [BX]
0x66, 0xEF, //out DX, EAX
0x66, 0x58); //pop EAX
#else
asm push eax;
asm mov eax, [bx];
asm out dx, eax;
asm pop eax;
#endif
return value;
}
/****************************************************
Function:
Read Vendor ID & Device ID from specified space
Input parameter:
iBus: Bus Number
iDevice: Device Number
Output parameter:
DeviceID & Vendor ID
****************************************************/
unsigned long VIDDID(int iBus, int iDevice)
{
unsigned long iod;
unsigned long iobase;
iobase = 0x80000000+iBus*0x10000+(iDevice*8)*0x100;
_outpd(0xcf8, iobase);
iod=_inpd(0xcfc);
return iod;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -