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

📄 mouse.c

📁 自己用c语言变写了一个魔方程序
💻 C
字号:
/*************************
 *	MOUSE.C          *
 *************************/

#include <dos.h>
#include "mouse.h"

/*  Function 0.    Mouse Reset     */
int reset_mouse(void)
{
	union REGS ireg, oreg;

	ireg.x.ax = 0;
	int86(0x33, &ireg, &oreg);

	return( (oreg.x.ax == 0)? 0: 1 );
}

/*  Use the mouse if there is one */
void init_mouse(void)
{
	extern int mu_install;

    if ( reset_mouse() ) {
        show_mouse();
		mu_install = 1;
	}
}

/*  Function 0.     Get mouse button number    */
int get_button_num(void)
{
	union REGS ireg, oreg;

	ireg.x.ax = 0;
	int86(0x33, &ireg, &oreg);

	return( ( (oreg.x.bx==3)||(oreg.x.bx==2) )? oreg.x.bx: 0 );
}


/*  Function 1.    Show mouse cursor   */
void show_mouse(void)
{
	union REGS ireg;

	ireg.x.ax = 1;
	int86(0x33, &ireg, &ireg);
}


/* Function 2.     Hide mouse cursor   */
void hide_mouse(void)
{
	union REGS ireg;

	ireg.x.ax = 2;
	int86(0x33, &ireg, &ireg);
}


/* Function 3. Check which button(s) is(are) pressed  */
int which_pressed(MOUSE *mouse)
{
	union REGS ireg, oreg;

	ireg.x.ax = 3;
	int86(0x33, &ireg, &oreg);

	mouse->x = oreg.x.cx;
	mouse->y = oreg.x.dx;
	return(oreg.x.bx);
}


/* Function 3.   Get position of cursor in graphics  */
void get_xy(MOUSE *grmouse)
{
	union REGS ireg, oreg;

	ireg.x.ax = 3;
	int86(0x33, &ireg, &oreg);

	grmouse->x = oreg.x.cx;
	grmouse->y = oreg.x.dx;
}


/* Function 3.   Get position of cursor in text  */
void get_t_xy(MOUSE *txtmouse)
{
	union REGS ireg, oreg;

	ireg.x.ax = 3;
	int86(0x33, &ireg, &oreg);

	txtmouse->x = oreg.x.cx/8 + 1;
	txtmouse->y = oreg.x.dx/8 + 1;
}


/* Function 4.   Set position of mouse cursor in graphics  */
void set_xy(int x, int y)
{
	union REGS ireg;

	ireg.x.ax = 4;
	ireg.x.cx = x;
	ireg.x.dx = y;
	int86(0x33, &ireg, &ireg);
}


/* Function 4.   Set position of mouse cursor in text  */
void set_t_xy(int Tx, int Ty)
{
	int x, y;

	x = (Tx-1) * 8;
	y = (Ty-1) * 8;
    set_xy(x, y);
}


/* Function 5.   Get button press information  */
int pressed_status(MOUSE *mouse, int button)
{
	union REGS ireg, oreg;

	ireg.x.ax = 5;
	ireg.x.bx = button;
	int86(0x33, &ireg, &oreg);

	mouse->x = oreg.x.cx;
	mouse->y = oreg.x.dx;
	mouse->but = oreg.x.ax;
	return(oreg.x.bx);
}

int click_button(MOUSE *mouse, int button)
{
	/* 0: left_b, 1: right_b, 2: middle_b */
	int mask[] = {-1, 0, 1, -1, 2};

    return( ((which_pressed(mouse)==button)&&
        (pressed_status(mouse, mask[button])==1))? 1: 0);
}


/* Function 6.   Get button release information  */
int released_status(MOUSE *mouse, int button)
{
	union REGS ireg, oreg;

	ireg.x.ax = 6;
	ireg.x.bx = button;
	int86(0x33, &ireg, &oreg);

	mouse->x = oreg.x.cx;
	mouse->y = oreg.x.dx;
	mouse->but = oreg.x.ax;
	return(oreg.x.bx);
}


/* Function 7.  Set the range of horizontal cursor position */
void set_x_range(int min, int max)
{
	union REGS ireg;

	ireg.x.ax = 7;
	ireg.x.cx = min;
	ireg.x.dx = max;
	int86(0x33, &ireg, &ireg);
}


/* Function 8.  Set the range of vertical cursor position */
void set_y_range(int min, int max)
{
	union REGS ireg;

	ireg.x.ax = 8;
	ireg.x.cx = min;
	ireg.x.dx = max;
	int86(0x33, &ireg, &ireg);
}


/* Function 9.  Set mouse graphic cursor block  */
void set_graphic_cursor(int x, int y, unsigned int far *pattern)
{
	union REGS ireg;
	struct SREGS isreg;

	ireg.x.ax = 9;
	ireg.x.bx = x;
	ireg.x.cx = y;
	ireg.x.dx = FP_OFF(pattern);
	isreg.es  = FP_SEG(pattern);
	int86x(0x33, &ireg, &ireg, &isreg);
}


/* Function 10.  Set mouse text cursor   */
void set_text_cursor(int type, int screen_mask, int cursor_mask)
{
	union REGS ireg;

	ireg.x.ax = 10;
	ireg.x.bx = type;
	ireg.x.cx = screen_mask;   /* 匡拒村夹陪ボ

⌨️ 快捷键说明

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