From ec3f6c3d37f437b8451a7bd3dc4595ab39ba1af2 Mon Sep 17 00:00:00 2001 From: ekeeke31 Date: Mon, 11 Aug 2008 15:18:57 +0000 Subject: [PATCH] added Sega Mouse emulation --- history.txt | 6 ++++-- source/genesis.c | 2 +- source/genesis.h | 2 +- source/input.c | 31 +++++++++++++++++++++++++------ source/io.c | 5 +++++ 5 files changed, 36 insertions(+), 10 deletions(-) diff --git a/history.txt b/history.txt index 583df8d..c93aa5d 100644 --- a/history.txt +++ b/history.txt @@ -14,10 +14,12 @@ current: - added support for some more unlicensed games: Pocket Monster, King of Fighter 98, Soul Blade (credits to Haze) - improved Menacer emulation: fix lightgun support in Body Count & T2: The Arcade Game - implemented Konami Justifier emulation: fix lightgun support in Lethal Enforcers 1 & 2 -- implemented Sega Mouse emulation +- implemented Sega Mouse emulation (Populous 2, Body Count, Shangai 2...) [Wii] -- added Wiimote IR support for lightgun (Menacer/Justifier) controls +- added lightgun support (Menacer/Justifier) through Wiimote IR +- added "Gun cursor" option to enable/disable gun position display +- added "Invert Mouse" option to invert Sega Mouse vertical axe (required by some games) 16/07/2008: ----------- diff --git a/source/genesis.c b/source/genesis.c index 761b8a3..a9ca234 100644 --- a/source/genesis.c +++ b/source/genesis.c @@ -1,6 +1,6 @@ /*************************************************************************************** * Genesis Plus 1.2a - * Genesis internals & Bus arbitration + * Genesis internals & Bus controller * * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Charles Mac Donald (original code) * modified by Eke-Eke (compatibility fixes & additional code), GC/Wii port diff --git a/source/genesis.h b/source/genesis.h index 2212c4a..c632fe8 100644 --- a/source/genesis.h +++ b/source/genesis.h @@ -1,6 +1,6 @@ /*************************************************************************************** * Genesis Plus 1.2a - * Genesis internals & Bus arbitration + * Genesis internals & Bus controller * * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Charles Mac Donald (original code) * modified by Eke-Eke (compatibility fixes & additional code), GC/Wii port diff --git a/source/input.c b/source/input.c index 897262c..4ad143e 100644 --- a/source/input.c +++ b/source/input.c @@ -95,7 +95,8 @@ static inline void lightgun_update(int num) /* Sega Menacer specific */ unsigned int menacer_read() { - int retval = 0x70; + /* pins should return 0 by default (fix Body Count when mouse is enabled) */ + int retval = 0x00; if (input.pad[4] & INPUT_B) retval |= 0x01; if (input.pad[4] & INPUT_A) retval |= 0x02; if (input.pad[4] & INPUT_C) retval |= 0x04; @@ -139,12 +140,16 @@ struct mega_mouse { uint8 State; uint8 Counter; + uint8 Wait; + uint8 Port; } mouse; static inline void mouse_reset() { mouse.State = 0x60; mouse.Counter = 0; + mouse.Wait = 0; + mouse.Port = (input.system[0] == SYSTEM_MOUSE) ? 0 : 4; } void mouse_write(unsigned int data) @@ -164,6 +169,8 @@ void mouse_write(unsigned int data) if ((mouse.State&0x20) != (data&0x20)) { mouse.Counter ++; /* increment phase */ + mouse.Wait = 1; /* mouse latency */ + if (mouse.Counter > 9) mouse.Counter = 9; } } @@ -203,10 +210,10 @@ unsigned int mouse_read() break; case 5: /* Buttons state */ - if (input.pad[0] & INPUT_B) temp |= 0x01; - if (input.pad[0] & INPUT_A) temp |= 0x02; - if (input.pad[0] & INPUT_C) temp |= 0x04; - if (input.pad[0] & INPUT_START) temp |= 0x08; + if (input.pad[mouse.Port] & INPUT_B) temp |= 0x01; + if (input.pad[mouse.Port] & INPUT_A) temp |= 0x02; + if (input.pad[mouse.Port] & INPUT_C) temp |= 0x04; + if (input.pad[mouse.Port] & INPUT_START) temp |= 0x08; break; case 6: /* X Axis MSB */ @@ -227,7 +234,19 @@ unsigned int mouse_read() } /* TR-TL handshaking */ - if (mouse.State & 0x20) temp |= 0x10; + if (mouse.Wait) + { + /* wait before ACK, fix some buggy mouse routine (Shangai 2, Wack World,...) */ + mouse.Wait = 0; + + /* TL = !TR */ + temp |= (~mouse.State & 0x20) >> 1; + } + else + { + /* TL = TR */ + temp |= (mouse.State & 0x20) >> 1; + } return temp; } diff --git a/source/io.c b/source/io.c index 05c58f3..760b264 100644 --- a/source/io.c +++ b/source/io.c @@ -88,6 +88,11 @@ void io_reset(void) port[1].data_r = gamepad_2_read; break; + case SYSTEM_MOUSE: + port[1].data_w = mouse_write; + port[1].data_r = mouse_read; + break; + case SYSTEM_MENACER: port[1].data_w = NULL; port[1].data_r = menacer_read;