src/mess/machine/ti99_4x.c
| r1589 | r1590 | |
| 1994 | 1994 | #pragma mark MECHATRONICS MOUSE |
| 1995 | 1995 | #endif |
| 1996 | 1996 | |
| 1997 | | static void mecmouse_select(int sel) |
| 1997 | static void mecmouse_select(int selnow, int stick1, int stick2) |
| 1998 | 1998 | { |
| 1999 | | if (mecmouse_sel != (sel != 0)) |
| 2000 | | { |
| 2001 | | mecmouse_sel = (sel != 0); |
| 2002 | | if (mecmouse_sel) |
| 2003 | | { |
| 1999 | /* The Mechatronic mouse is connected to the joystick port and occupies |
| 2000 | both joystick select lines and the switch lines. From these five |
| 2001 | lines, left/right/down are used for the motion (i.e. 3 motion steps |
| 2002 | for positive and four for negative motion and one for rest), |
| 2003 | the fire line is used for the secondary mouse button, and the up |
| 2004 | line is used for the primary button. |
| 2005 | The mouse motion is delivered by the same lines for both directions; |
| 2006 | this requires swapping the axes. According to the source code of |
| 2007 | the accompanying mouse driver, the readout of the current axis is |
| 2008 | done by selecting joystick 1, then joystick 2. The axis swapping is |
| 2009 | achieved by selecting stick 1 again. When selecting stick 2, the |
| 2010 | second axis is seen on the input lines. |
| 2011 | Interrupting this sequence will lead to swapped axes. This is |
| 2012 | prevented by resetting the toggle when the mouse is deselected |
| 2013 | (neither 1 nor 2 are selected). |
| 2014 | |
| 2015 | The joystick lines are selected as follows: |
| 2016 | TI-99/4: Stick 1: P4=1, P3=0, P2=1 (5) |
| 2017 | Stick 2: P4=1, P3=1, P2=0 (6) |
| 2018 | |
| 2019 | TI-99/4A: Stick 1: P4=1, P3=1, P2=0 (6) |
| 2020 | Stick 2: P4=1, P3=1, P2=1 (7) |
| 2021 | |
| 2022 | TI-99/8: Stick 1: P3=1, P2=1, P1=1, P0=0 (14) |
| 2023 | Stick 2: P3=1, P2=1, P1=1, P0=1 (15) |
| 2024 | |
| 2025 | Geneve: n/a, has own mouse handling via v9938 |
| 2026 | |
| 2027 | As we can only deliver at max 3 steps positive and 4 steps negative, |
| 2028 | we split the delta so that subsequent queries add up to the actual |
| 2029 | delta. That is, one delta of +10 yields a 3+3+3+1. |
| 2030 | |
| 2031 | mecmouse_x holds the current delta to be counted down for x |
| 2032 | (y accordingly) |
| 2033 | |
| 2034 | mecmouse_x_buf is the current step count reported to CRU |
| 2035 | |
| 2036 | Michael Zapf, 2008-01-22 |
| 2037 | */ |
| 2038 | |
| 2039 | if (selnow==stick2) { |
| 2040 | if (mecmouse_sel==stick1) { |
| 2004 | 2041 | if (! mecmouse_read_y) |
| 2005 | 2042 | { |
| 2006 | | /* sample mouse data for both axes */ |
| 2043 | /* Sample x motion. */ |
| 2007 | 2044 | if (mecmouse_x < -4) |
| 2008 | 2045 | mecmouse_x_buf = -4; |
| 2009 | 2046 | else if (mecmouse_x > 3) |
| r1589 | r1590 | |
| 2012 | 2049 | mecmouse_x_buf = mecmouse_x; |
| 2013 | 2050 | mecmouse_x -= mecmouse_x_buf; |
| 2014 | 2051 | mecmouse_x_buf = (mecmouse_x_buf-1) & 7; |
| 2015 | | |
| 2052 | } |
| 2053 | else |
| 2054 | { |
| 2055 | /* Sample y motion. */ |
| 2016 | 2056 | if (mecmouse_y < -4) |
| 2017 | 2057 | mecmouse_y_buf = -4; |
| 2018 | 2058 | else if (mecmouse_y > 3) |
| r1589 | r1590 | |
| 2023 | 2063 | mecmouse_y_buf = (mecmouse_y_buf-1) & 7; |
| 2024 | 2064 | } |
| 2025 | 2065 | } |
| 2026 | | else |
| 2066 | mecmouse_sel = selnow; |
| 2067 | } |
| 2068 | else if (selnow==stick1) |
| 2069 | { |
| 2070 | if (mecmouse_sel==stick2) |
| 2071 | { |
| 2072 | /* Swap the axes. */ |
| 2027 | 2073 | mecmouse_read_y = ! mecmouse_read_y; |
| 2074 | } |
| 2075 | mecmouse_sel = selnow; |
| 2028 | 2076 | } |
| 2077 | else |
| 2078 | { |
| 2079 | /* Reset the axis toggle when the mouse is deselected */ |
| 2080 | mecmouse_read_y = 0; |
| 2081 | } |
| 2029 | 2082 | } |
| 2030 | 2083 | |
| 2031 | 2084 | static void mecmouse_poll(void) |
| r1589 | r1590 | |
| 2039 | 2092 | |
| 2040 | 2093 | /* compute x delta */ |
| 2041 | 2094 | delta_x = new_mx - last_mx; |
| 2042 | | |
| 2095 | |
| 2043 | 2096 | /* check for wrap */ |
| 2044 | 2097 | if (delta_x > 0x80) |
| 2045 | | delta_x = 0x100-delta_x; |
| 2098 | delta_x = -0x100+delta_x; |
| 2046 | 2099 | if (delta_x < -0x80) |
| 2047 | | delta_x = -0x100-delta_x; |
| 2100 | delta_x = 0x100+delta_x; |
| 2048 | 2101 | |
| 2102 | /* Prevent unplausible values at startup. */ |
| 2103 | if (delta_x > 100 || delta_x<-100) delta_x = 0; |
| 2104 | |
| 2049 | 2105 | last_mx = new_mx; |
| 2050 | 2106 | |
| 2051 | 2107 | /* compute y delta */ |
| r1589 | r1590 | |
| 2053 | 2109 | |
| 2054 | 2110 | /* check for wrap */ |
| 2055 | 2111 | if (delta_y > 0x80) |
| 2056 | | delta_y = 0x100-delta_y; |
| 2112 | delta_y = -0x100+delta_y; |
| 2057 | 2113 | if (delta_y < -0x80) |
| 2058 | | delta_y = -0x100-delta_y; |
| 2114 | delta_y = 0x100+delta_y; |
| 2059 | 2115 | |
| 2116 | if (delta_y > 100 || delta_y<-100) delta_y = 0; |
| 2117 | |
| 2060 | 2118 | last_my = new_my; |
| 2061 | 2119 | |
| 2062 | 2120 | /* update state */ |
| r1589 | r1590 | |
| 2064 | 2122 | mecmouse_y += delta_y; |
| 2065 | 2123 | } |
| 2066 | 2124 | |
| 2067 | | |
| 2068 | 2125 | /*===========================================================================*/ |
| 2069 | 2126 | #if 0 |
| 2070 | 2127 | #pragma mark - |
| r1589 | r1590 | |
| 2258 | 2315 | KeyCol |= 1 << (offset-2); |
| 2259 | 2316 | else |
| 2260 | 2317 | KeyCol &= ~ (1 << (offset-2)); |
| 2261 | | |
| 2262 | | if (has_mecmouse) |
| 2263 | | mecmouse_select(KeyCol == ((ti99_model == model_99_4) ? 6 : 7)); |
| 2318 | |
| 2319 | if (has_mecmouse) |
| 2320 | mecmouse_select(KeyCol, (ti99_model == model_99_4) ? 5 : 6, |
| 2321 | (ti99_model == model_99_4) ? 6 : 7); |
| 2264 | 2322 | } |
| 2265 | 2323 | |
| 2266 | 2324 | /* |
| r1589 | r1590 | |
| 2348 | 2406 | KeyCol &= ~ (1 << offset); |
| 2349 | 2407 | |
| 2350 | 2408 | if (has_mecmouse) |
| 2351 | | mecmouse_select(KeyCol == 15); |
| 2409 | mecmouse_select(KeyCol, 14, 15); |
| 2352 | 2410 | } |
| 2353 | 2411 | |
| 2354 | 2412 | static void ti99_8_WCRUS(int offset, int data) |