PS2 mouse bios emulation (c2woody)
Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@1720
This commit is contained in:
		
							parent
							
								
									5de58e54bc
								
							
						
					
					
						commit
						7deaa068a5
					
				
					 3 changed files with 138 additions and 15 deletions
				
			
		| 
						 | 
				
			
			@ -16,9 +16,16 @@
 | 
			
		|||
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
/* $Id: mouse.h,v 1.6 2004-03-14 13:39:45 qbix79 Exp $ */
 | 
			
		||||
 | 
			
		||||
#ifndef _MOUSE_H_
 | 
			
		||||
#define _MOUSE_H_
 | 
			
		||||
 | 
			
		||||
void Mouse_ShowCursor(void);
 | 
			
		||||
void Mouse_HideCursor(void);
 | 
			
		||||
 | 
			
		||||
void Mouse_SetPS2State(bool use);
 | 
			
		||||
void Mouse_ChangePS2Callback(Bit16u pseg, Bit16u pofs);
 | 
			
		||||
 | 
			
		||||
void Mouse_CursorMoved(float x,float y);
 | 
			
		||||
void Mouse_CursorSet(float x,float y);
 | 
			
		||||
| 
						 | 
				
			
			@ -28,3 +35,5 @@ void Mouse_ButtonReleased(Bit8u button);
 | 
			
		|||
void Mouse_AutoLock(bool enable);
 | 
			
		||||
void Mouse_NewVideoMode(void);
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -16,7 +16,7 @@
 | 
			
		|||
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
/* $Id: bios.cpp,v 1.29 2004-02-29 21:55:49 harekiet Exp $ */
 | 
			
		||||
/* $Id: bios.cpp,v 1.30 2004-03-14 13:39:45 qbix79 Exp $ */
 | 
			
		||||
 | 
			
		||||
#include <time.h>
 | 
			
		||||
#include "dosbox.h"
 | 
			
		||||
| 
						 | 
				
			
			@ -29,6 +29,7 @@
 | 
			
		|||
#include "pic.h"
 | 
			
		||||
#include "joystick.h"
 | 
			
		||||
#include "dos_inc.h"
 | 
			
		||||
#include "mouse.h"
 | 
			
		||||
 | 
			
		||||
static Bitu call_int1a,call_int11,call_int8,call_int17,call_int12,call_int15,call_int1c;
 | 
			
		||||
static Bitu call_int1,call_int70;
 | 
			
		||||
| 
						 | 
				
			
			@ -303,12 +304,50 @@ static Bitu INT15_Handler(void) {
 | 
			
		|||
        CALLBACK_SCF(true);
 | 
			
		||||
        break;
 | 
			
		||||
	case 0xc2:	/* BIOS PS2 Pointing Device Support */
 | 
			
		||||
	case 0xc4:	/* BIOS POS Programma option Select */
 | 
			
		||||
		/* 
 | 
			
		||||
			Damn programs should use the mouse drivers 
 | 
			
		||||
			So let's fail these calls 
 | 
			
		||||
		*/
 | 
			
		||||
		LOG(LOG_BIOS,LOG_NORMAL)("INT15:Function %X called,bios mouse not supported",reg_ah);
 | 
			
		||||
		switch (reg_al) {
 | 
			
		||||
		case 0x00:		// enable/disable
 | 
			
		||||
			if (reg_bh==0) {	// disable
 | 
			
		||||
				Mouse_SetPS2State(false);
 | 
			
		||||
				reg_ah=0;
 | 
			
		||||
				CALLBACK_SCF(false);
 | 
			
		||||
			} else if (reg_bh==0x01) {	//enable
 | 
			
		||||
				Mouse_SetPS2State(true);
 | 
			
		||||
				reg_ah=0;
 | 
			
		||||
				CALLBACK_SCF(false);
 | 
			
		||||
			} else CALLBACK_SCF(true);
 | 
			
		||||
			break;
 | 
			
		||||
		case 0x01:		// reset
 | 
			
		||||
			reg_bx=0x00aa;	// mouse
 | 
			
		||||
			CALLBACK_SCF(false);
 | 
			
		||||
			break;
 | 
			
		||||
		case 0x02:		// set sampling rate
 | 
			
		||||
			CALLBACK_SCF(false);
 | 
			
		||||
			break;
 | 
			
		||||
		case 0x03:		// set resolution
 | 
			
		||||
			CALLBACK_SCF(false);
 | 
			
		||||
			break;
 | 
			
		||||
		case 0x04:		// get type
 | 
			
		||||
			reg_bh=0;	// ID
 | 
			
		||||
			CALLBACK_SCF(false);
 | 
			
		||||
			break;
 | 
			
		||||
		case 0x05:		// initialize
 | 
			
		||||
			CALLBACK_SCF(false);
 | 
			
		||||
			break;
 | 
			
		||||
		case 0x06:		// extended commands
 | 
			
		||||
			if ((reg_bh==0x01) || (reg_bh==0x02)) CALLBACK_SCF(false);
 | 
			
		||||
			else CALLBACK_SCF(true);
 | 
			
		||||
			break;
 | 
			
		||||
		case 0x07:		// set callback
 | 
			
		||||
			Mouse_ChangePS2Callback(SegValue(es),reg_bx);
 | 
			
		||||
			CALLBACK_SCF(false);
 | 
			
		||||
			break;
 | 
			
		||||
		default:
 | 
			
		||||
			CALLBACK_SCF(true);
 | 
			
		||||
			break;
 | 
			
		||||
		}
 | 
			
		||||
		break;
 | 
			
		||||
	case 0xc4:	/* BIOS POS Programm option Select */
 | 
			
		||||
		LOG(LOG_BIOS,LOG_NORMAL)("INT15:Function %X called, bios mouse not supported",reg_ah);
 | 
			
		||||
		CALLBACK_SCF(true);
 | 
			
		||||
		break;
 | 
			
		||||
	default:
 | 
			
		||||
| 
						 | 
				
			
			@ -398,19 +437,20 @@ void BIOS_Init(Section* sec) {
 | 
			
		|||
	/* Setup equipment list */
 | 
			
		||||
	Bitu config=0x4400;						//1 Floppy, 2 serial and 1 parrallel
 | 
			
		||||
#if (C_FPU)
 | 
			
		||||
	config|=0x2;
 | 
			
		||||
	config|=0x2;					//FPU
 | 
			
		||||
#endif
 | 
			
		||||
	switch (machine) {
 | 
			
		||||
	case MCH_HERC:
 | 
			
		||||
		config|=0x30;						//Startup monochrome
 | 
			
		||||
		break;
 | 
			
		||||
	case MCH_CGA:	case MCH_TANDY:
 | 
			
		||||
		config|=0x20;						//STartup 80x25 color
 | 
			
		||||
		config|=0x20;				//Startup 80x25 color
 | 
			
		||||
		break;
 | 
			
		||||
	default:
 | 
			
		||||
		config|=0;							//EGA VGA
 | 
			
		||||
		break;
 | 
			
		||||
	}
 | 
			
		||||
	config |= 0x04;					// PS2 mouse
 | 
			
		||||
	mem_writew(BIOS_CONFIGURATION,config);
 | 
			
		||||
	/* Setup extended memory size */
 | 
			
		||||
	IO_Write(0x70,0x30);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -16,7 +16,7 @@
 | 
			
		|||
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
/* $Id: mouse.cpp,v 1.32 2004-02-29 22:22:56 harekiet Exp $ */
 | 
			
		||||
/* $Id: mouse.cpp,v 1.33 2004-03-14 13:39:45 qbix79 Exp $ */
 | 
			
		||||
 | 
			
		||||
#include <string.h>
 | 
			
		||||
#include "dosbox.h"
 | 
			
		||||
| 
						 | 
				
			
			@ -28,9 +28,71 @@
 | 
			
		|||
#include "inout.h"
 | 
			
		||||
#include "int10.h"
 | 
			
		||||
#include "bios.h"
 | 
			
		||||
#include "cpu.h"
 | 
			
		||||
 | 
			
		||||
static Bitu call_int33,call_int74;
 | 
			
		||||
 | 
			
		||||
static Bit16u ps2cbseg, ps2cbofs;
 | 
			
		||||
static bool useps2callback;
 | 
			
		||||
static Bit16u call_ps2;
 | 
			
		||||
static RealPt ps2_callback;
 | 
			
		||||
static Bit16s oldmouseX, oldmouseY;
 | 
			
		||||
 | 
			
		||||
void Mouse_SetPS2State(bool use) {
 | 
			
		||||
	if ((SegValue(es)!=0) && (reg_bx!=0)) useps2callback = use;
 | 
			
		||||
	else useps2callback = false;
 | 
			
		||||
	Mouse_AutoLock(useps2callback);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Mouse_ChangePS2Callback(Bit16u pseg, Bit16u pofs) {
 | 
			
		||||
	if ((pseg==0) && (pofs==0)) useps2callback = false;
 | 
			
		||||
	else useps2callback = true;
 | 
			
		||||
	ps2cbseg = pseg;
 | 
			
		||||
	ps2cbofs = pofs;
 | 
			
		||||
	Mouse_AutoLock(useps2callback);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void DoPS2Callback(Bit16u data, Bit16s mouseX, Bit16s mouseY) {
 | 
			
		||||
	if (useps2callback) {
 | 
			
		||||
		Bit16u mdat = (data & 0x03) | 0x08;
 | 
			
		||||
		Bit16s xdiff = mouseX-oldmouseX;
 | 
			
		||||
		Bit16s ydiff = oldmouseY-mouseY;
 | 
			
		||||
		oldmouseX = mouseX;
 | 
			
		||||
		oldmouseY = mouseY;
 | 
			
		||||
 | 
			
		||||
		if ((xdiff>0xff) || (xdiff<-0xff)) mdat |= 0x40;		// x overflow
 | 
			
		||||
		if ((ydiff>0xff) || (ydiff<-0xff)) mdat |= 0x80;		// y overflow
 | 
			
		||||
 | 
			
		||||
		xdiff %= 256;
 | 
			
		||||
		ydiff %= 256;
 | 
			
		||||
 | 
			
		||||
		if (xdiff<0) {
 | 
			
		||||
			xdiff = (0x100+xdiff);
 | 
			
		||||
			mdat |= 0x10;
 | 
			
		||||
		}
 | 
			
		||||
		if (ydiff<0) {
 | 
			
		||||
			ydiff = (0x100+ydiff);
 | 
			
		||||
			mdat |= 0x20;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		CPU_Push16((Bit16u)mdat); 
 | 
			
		||||
		CPU_Push16((Bit16u)(xdiff % 256)); 
 | 
			
		||||
		CPU_Push16((Bit16u)(ydiff % 256)); 
 | 
			
		||||
		CPU_Push16((Bit16u)0); 
 | 
			
		||||
 | 
			
		||||
		CPU_Push16(RealSeg(ps2_callback));
 | 
			
		||||
		CPU_Push16(RealOff(ps2_callback));
 | 
			
		||||
		SegSet16(cs, ps2cbseg);
 | 
			
		||||
		reg_ip = ps2cbofs;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Bitu PS2_Handler(void) {
 | 
			
		||||
	reg_sp += 8;	// remove the 4 words
 | 
			
		||||
	return CBRET_NONE;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
// forward
 | 
			
		||||
void WriteMouseIntVector(void);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -352,11 +414,16 @@ void Mouse_CursorMoved(float x,float y) {
 | 
			
		|||
	mouse.mickey_y += dy;
 | 
			
		||||
 | 
			
		||||
	mouse.x += dx;
 | 
			
		||||
	if (mouse.x>mouse.max_x) mouse.x=mouse.max_x;
 | 
			
		||||
	if (mouse.x<mouse.min_x) mouse.x=mouse.min_x;
 | 
			
		||||
	mouse.y += dy;
 | 
			
		||||
	if (mouse.y>mouse.max_y) mouse.y=mouse.max_y;
 | 
			
		||||
	if (mouse.y<mouse.min_y) mouse.y=mouse.min_y;
 | 
			
		||||
	
 | 
			
		||||
	/* ignore constraints if using PS2 mouse callback in the bios */
 | 
			
		||||
	if (!useps2callback) {		
 | 
			
		||||
		if (mouse.x > mouse.max_x) mouse.x = mouse.max_x;
 | 
			
		||||
		if (mouse.x < mouse.min_x) mouse.x = mouse.min_x;
 | 
			
		||||
		if (mouse.y > mouse.max_y) mouse.y = mouse.max_y;
 | 
			
		||||
		if (mouse.y < mouse.min_y) mouse.y = mouse.min_y;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	Mouse_AddEvent(MOUSE_MOVED);
 | 
			
		||||
	DrawCursor();
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -762,6 +829,7 @@ static Bitu INT74_Handler(void) {
 | 
			
		|||
			SegSet16(ds,oldds); SegSet16(es,oldes); SegSet16(ss,oldss); // Save segments
 | 
			
		||||
 | 
			
		||||
		}
 | 
			
		||||
		DoPS2Callback(mouse.event_queue[mouse.events].buttons, POS_X, POS_Y);
 | 
			
		||||
	}
 | 
			
		||||
	IO_Write(0xa0,0x20);
 | 
			
		||||
	IO_Write(0x20,0x20);
 | 
			
		||||
| 
						 | 
				
			
			@ -783,7 +851,7 @@ void CreateMouseCallback(void)
 | 
			
		|||
{
 | 
			
		||||
	// Create callback
 | 
			
		||||
	call_int33=CALLBACK_Allocate();
 | 
			
		||||
	CALLBACK_Setup(call_int33,&INT33_Handler,CB_IRET);
 | 
			
		||||
	CALLBACK_Setup(call_int33,&INT33_Handler,CB_IRET,"Mouse");
 | 
			
		||||
	// Create a mouse vector with weird address 
 | 
			
		||||
	// for strange mouse detection routines in Sim City & Wasteland
 | 
			
		||||
	Bit16u ofs = call_int33<<4;
 | 
			
		||||
| 
						 | 
				
			
			@ -809,6 +877,12 @@ void MOUSE_Init(Section* sec) {
 | 
			
		|||
		real_writed(0,((0x8+MOUSE_IRQ)<<2),CALLBACK_RealPointer(call_int74));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	useps2callback = false;
 | 
			
		||||
 | 
			
		||||
 	call_ps2=CALLBACK_Allocate();
 | 
			
		||||
	CALLBACK_Setup(call_ps2,&PS2_Handler,CB_IRET,"ps2 bios callback");
 | 
			
		||||
	ps2_callback=CALLBACK_RealPointer(call_ps2);
 | 
			
		||||
 | 
			
		||||
	memset(&mouse,0,sizeof(mouse));
 | 
			
		||||
	mouse_reset_hardware();
 | 
			
		||||
	mouse_reset();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue