⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.cpp

📁 在DOS利用Watcom c++的保护模式4G内存
💻 CPP
字号:
# include	<stdio.h>
# include	<iostream.h>
# include	<conio.h>
# include	<stdlib.h>
# include	<bios.h>
# include	<i86.h>
# include	<dos.h>

//# include	"tt.cpp"
# include	"mouse.h"
# include	"screen.h"
# include	"vesa.h"

#define VGA_WIDTH 320
#define VGA_HEIGHT 200
#define SVGA_WIDTH 640
#define SVGA_HEIGHT 480

# define	BOOL int
# define	TRUE 1
# define	FALSE 0

BOOL super_vga;
void Attempt_Screen_Open(short & width, short & height)
{
	if ( (width>VGA_WIDTH) || (height>VGA_HEIGHT) ) {
		// must load a super vga screen to get requested dimensions
		VBE_detect();
		if (VESA_InitGraphics(width, height)) {
			// no svga so load vga dimensions
			setgmode(0x13);
			super_vga=FALSE;
			width=VGA_WIDTH;
			height=VGA_HEIGHT;
		} else {
			super_vga=TRUE;
		}
	} else {
		super_vga=FALSE;
		setgmode(0x13);
		width=VGA_WIDTH;
		height=VGA_HEIGHT;
	}
}


/*
class CA
{
public:
	CA(){
		cout<<"CA"<<endl;
	}
	~CA(){}
};
//*/

CMouse g_mouse;

short	scrWidth=640;
short	scrHeight=480;

extern char    far * VESA_LFBPtr;                /* Pointer to linear framebuffer    */
extern unsigned char * screen;

# define	RGB( r, g, b )\
		( b | (g<<8) | (r<<16) )

//# define	COLORREF	(long)

typedef long COLORREF;

 
void	SetPixel( int x, int y, COLORREF color )
{
	if( VESA_LFBPtr != NULL )
	{
		*( (COLORREF __far *)(VESA_LFBPtr+ ((y * scrWidth + x)<<2)) ) = color;
	}
	else
		*( screen+ y * scrWidth + x ) = color;

}

//FILE hzk16;
//# include	<fstream.h>
//fstream	hzk16;
FILE * hzk16 = NULL;

unsigned char * pASCII = NULL;

void	OutText(int x,int y,char *string,COLORREF color, COLORREF bk){
	if(!string)return;
	unsigned char qcode,wcode;
	unsigned long record;
	unsigned char buffer[32];
	int i,j,k;
	int	oldx = x;
	while(*string)
	{
		if((int(*string)>=0x80)&&(int(*(string+1))>=0x80))
		{	//is chinese
			qcode=*string-161;
			wcode=*(string+1)-161;
			record=(unsigned long)(qcode*94+wcode)*32;

			fseek(hzk16,record,SEEK_SET);
			fread(buffer,32,1,hzk16);
			for(i=0;i<16;i++)
				for(j=0;j<2;j++)
					for(k=0;k<8;k++)
						if(buffer[i*2+j]>>(7-k)&1)
							SetPixel(x+k+j*8,y+i,color);
						else if( bk != -1 )
							SetPixel(x+k+j*8,y+i,bk);
			string+=2;
			x+=16;
			continue;
		}
		//else
		{
			//去掉以下注解,将使用16点阵字库里的大写ASCII及数字
/*			if(*string>32&&*string<=123)
			{
				unsigned char str[3];
				str[0]=0xa3;
				str[1]=(*string-32)+0xa0;
				str[2]=NULL;
				DisplayChar(x,y,str,color);
				x+=16;
				string++;
			}
			else
*/
			if(*string=='\n'){
				x	= oldx;
				y	+= 20;
				string++;
				continue;
			}
			else if(*string == '\t'){
				string ++;
				if(*string>='0'&&*string<='9'){
					color = *string - 0x30;
					string ++;
					continue;
				}	else if((*string>='a'&&*string<='f')){
					color = *string - 'a' + 0x0a;
					string ++;
					continue;
				}
				else if((*string>='A'&&*string<='F')){
					color = *string - 'A' + 0x0a;
					string ++;
					continue;
				}
				else string --;
			}


			{
				
				i=*string++;
				if( pASCII == NULL )
					continue;

				unsigned char far *p=(pASCII+i*16);
				for(k=0;k<16;k++,p++)
				{
					for(j=0;j<8;j++)
					{
						if(((*p)>>(7-j))&1)
							SetPixel(x+j,y+k,color);
						else if( bk != -1 )
							SetPixel(x+j,y+k,bk);

					}
				}
				x+=8;
			}
		}
	}
}

//# include	<fstream.h>
/*
void (__interrupt __far *OldISR)();
 
    void interrupt ISR_0( void )
    {
        // Your code here... 
    }
 
    void main(void)
    {
            :               :
        OldISR=_dos_getvect(TheVectorHere);
        _dos_setvect(TheVectorHere,ISR_0);
            :               :
        _dos_setvect(TheVectorHere,OldISR);
 
    }
 
	
#pragma aux SAVE_BP =\
	"push ds"		\
	"push bp"	
*/
# define	__CPPARGS	

// 安装中断
void	__interrupt (*OldKeyInterrupt)(__CPPARGS)=NULL;
static volatile int KeyScan=0;
unsigned char KeyBuffer[0x80];
void	__interrupt NewKeyInterrupt(__CPPARGS)
{
	register char x;
	KeyScan=inp(0x60);       // read key code from keyboard
	x=inp(0x61);             // tell keyboard that key was processed
	outp(0x61,(x|0x80));
	outp(0x61,x);
	outp(0x20,0x20);                  // send End-Of-Interrupt

	KeyBuffer[KeyScan&0x7f] = (!(KeyScan>0x80));

	(*OldKeyInterrupt)();
}
//////////////////////////////////////
//用于中断部分函数
# define	INTERRUPT_ON

# define	KEYINTERRUPT	0x09

void	InstallKey()
{
# ifdef	INTERRUPT_ON
	if( OldKeyInterrupt == NULL ){
		OldKeyInterrupt	= _dos_getvect( KEYINTERRUPT );
		_dos_setvect( KEYINTERRUPT , NewKeyInterrupt );
	}
# endif
}
void	UninstallKey()
{
# ifdef	INTERRUPT_ON
	if( OldKeyInterrupt )_dos_setvect( KEYINTERRUPT , OldKeyInterrupt );
	OldKeyInterrupt = NULL;
# endif
}

extern void AvailableModes(void);

void	main()
{


	//VBE_detect();
	//AvailableModes();

	//return ;


# pragma aux LOAD_BP =\
	"pop bp"		\
	"pop ds"		

	int key(0),x,y;
//	FILE * fp = fopen("test.t","wb");
//	fseek( fp, 0, SEEK_SET );
	//fwrite( "abc", 3, 1, fp );
	//fclose( fp );
	//return ;

//	fstream	infile;

	hzk16 = fopen("hzk16","rb");
	if( hzk16 == NULL){
	//	cout<<"hzk file open fail!"<<endl;
	}
	//hzk16.open("hzk16");//,ios_base::in);
	char buff[0x40];
	memset( KeyBuffer, 0, 0x80 );

/*
	SAVE_BP;

	union REGPACK rp;
	rp.w.ax = 0x1130;
	rp.w.bx = 0x0600;
	intr(0x10,&rp);
	unsigned e	= rp.w.es;
	unsigned s	= rp.w.bp;
	pASCII = (unsigned char *)(e*0x10+s);//MK_FP( e, s );

	LOAD_BP;
	
//*/
	VESA_LFBPtr = NULL;
	Attempt_Screen_Open( scrWidth, scrHeight);

	g_mouse.Init();
	g_mouse.SetRang( 0, 0, scrWidth-1, scrHeight-1 );
	g_mouse.Show(1);
	g_mouse.MoveTo( scrWidth/2, scrHeight/2 );
	OutText( 100, 100, "汉字", RGB(255,255,255), RGB(0,0,255) );
	InstallKey();

	while( key != 0x1b )
	{
		key = g_mouse.GetStatePosi(x,y);
		//if( key >= 0x100 )
		//{
			SetPixel( x, y, RGB(0,255,255) );
		//	cout<<(key&0xff)<<" X="<<x<<" Y="<<y<<endl;
		//}
		if( kbhit() )
			key = getch();
		switch( key ){
		case 0x20:
			{
				for( int j(0); j<scrHeight; j++)
					SetPixel( scrWidth/2, j, RGB(j,255-j, 128) );
				OutText( x, y, "鼠标", RGB(0,255,0), -1 );

			} break;
		default: 
			break;
		}
		if( KeyBuffer[0x44] != 0 )
		{
			OutText( x, y, "中断", RGB(255,0,255), 0 );
		}

	}
	UninstallKey();
	g_mouse.Show(0);
	setgmode(0x03);

	if( hzk16 != NULL ){
		fclose( hzk16 );
//		cout<<"yes , close it !"<<endl;
	}
//	hzk16.close();


}



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -