trunk/src/mame/drivers/namcos22.c
| r20670 | r20671 | |
| 3012 | 3012 | TIMER_CALLBACK_MEMBER(namcos22_state::adillor_trackball_interrupt) |
| 3013 | 3013 | { |
| 3014 | 3014 | generic_pulse_irq_line(m_mcu, param ? M37710_LINE_TIMERA2TICK : M37710_LINE_TIMERA3TICK, 1); |
| 3015 | | m_ar_tb_interrupt[param]->adjust(m_ar_tb_reload[param], param); |
| 3016 | 3015 | } |
| 3017 | 3016 | |
| 3018 | 3017 | TIMER_DEVICE_CALLBACK_MEMBER(namcos22_state::adillor_trackball_update) |
| 3019 | 3018 | { |
| 3020 | | // arbitrary timer for reading trackball |
| 3021 | | for (int axis = 0; axis < 2; axis++) |
| 3019 | // arbitrary timer for reading optical trackball |
| 3020 | UINT8 ix = ioport("TRACKX")->read(); |
| 3021 | UINT8 iy = ioport("TRACKY")->read(); |
| 3022 | |
| 3023 | if (ix != 0x80 || iy < 0x80) |
| 3022 | 3024 | { |
| 3023 | | UINT16 ipt = ioport(axis ? "TRACKY" : "TRACKX")->read(); |
| 3024 | | if (ipt > 0 && ipt < 0x8000) |
| 3025 | if (iy >= 0x80) |
| 3026 | iy = 0x7f; |
| 3027 | double x = (double)(ix - 0x80) / 127.0; |
| 3028 | double y = (double)(0x80 - iy) / 127.0; |
| 3029 | |
| 3030 | // normalize |
| 3031 | double a = atan(x/y); |
| 3032 | double p = sqrt(x*x + y*y); |
| 3033 | double v = (fabs(a) < (M_PI / 4.0)) ? p*cos(a) : p*sin(a); |
| 3034 | v = fabs(v); |
| 3035 | |
| 3036 | // note that it is rotated by 45 degrees, so instead of axes like (+), they are like (x) |
| 3037 | a += (M_PI / 4.0); |
| 3038 | if (a < 0) |
| 3039 | a = 0; |
| 3040 | else if (a > (M_PI / 2.0)) |
| 3041 | a = M_PI / 2.0; |
| 3042 | |
| 3043 | // tied to mcu A2/A3 timer (speed determines frequency) |
| 3044 | // these values(in usec) may need tweaking: |
| 3045 | const int base = 1000; |
| 3046 | const int range = 5000; |
| 3047 | |
| 3048 | double t[2]; |
| 3049 | t[0] = v*sin(a); // y -> A2 |
| 3050 | t[1] = v*cos(a); // x -> A3 |
| 3051 | |
| 3052 | for (int axis = 0; axis < 2; axis++) |
| 3025 | 3053 | { |
| 3026 | | // optical trackball, tied to mcu A2/A3 timer (speed determines frequency) |
| 3027 | | // note that it is rotated by 45 degrees, so instead of axes like (+), they are like (x) |
| 3028 | | // (not yet tested on a real trackball, values below still need to be tweaked) |
| 3029 | | const int cap = 256; |
| 3030 | | const int maxspeed = 500; |
| 3031 | | const int sensitivity = 50; |
| 3032 | | |
| 3033 | | if (ipt > cap) ipt = cap; |
| 3034 | | ipt = cap - ipt; |
| 3035 | | |
| 3036 | | attotime freq = attotime::from_usec(maxspeed + sensitivity * ipt); |
| 3037 | | m_ar_tb_reload[axis] = freq; |
| 3038 | | m_ar_tb_interrupt[axis]->adjust(min(freq, m_ar_tb_interrupt[axis]->remaining()), axis); |
| 3039 | | |
| 3054 | if (t[axis] > (1.0 / (double)(range))) |
| 3055 | { |
| 3056 | attotime freq = attotime::from_usec((base + range) - ((double)(range) * t[axis])); |
| 3057 | m_ar_tb_interrupt[axis]->adjust(min(freq, m_ar_tb_interrupt[axis]->remaining()), axis, freq); |
| 3058 | } |
| 3059 | else |
| 3060 | { |
| 3061 | // not moving |
| 3062 | m_ar_tb_interrupt[axis]->adjust(attotime::never, axis, attotime::never); |
| 3063 | } |
| 3040 | 3064 | } |
| 3041 | | else |
| 3065 | } |
| 3066 | else |
| 3067 | { |
| 3068 | // both axes not moving |
| 3069 | for (int axis = 0; axis < 2; axis++) |
| 3042 | 3070 | { |
| 3043 | | // backwards or not moving |
| 3044 | | m_ar_tb_reload[axis] = attotime::never; |
| 3045 | | m_ar_tb_interrupt[axis]->adjust(attotime::never, axis); |
| 3071 | m_ar_tb_interrupt[axis]->adjust(attotime::never, axis, attotime::never); |
| 3046 | 3072 | } |
| 3047 | 3073 | } |
| 3048 | 3074 | } |
| r20670 | r20671 | |
| 5211 | 5237 | PORT_BIT( 0xfe, IP_ACTIVE_LOW, IPT_UNKNOWN ) |
| 5212 | 5238 | |
| 5213 | 5239 | PORT_START("TRACKX") |
| 5214 | | PORT_BIT( 0xffff, 0x0000, IPT_TRACKBALL_X ) PORT_SENSITIVITY(100) PORT_KEYDELTA(200) PORT_RESET |
| 5240 | PORT_BIT( 0xff, 0x80, IPT_AD_STICK_X ) PORT_MINMAX(0x01, 0xff) PORT_SENSITIVITY(100) PORT_KEYDELTA(20) |
| 5215 | 5241 | |
| 5216 | 5242 | PORT_START("TRACKY") |
| 5217 | | PORT_BIT( 0xffff, 0x0000, IPT_TRACKBALL_Y ) PORT_SENSITIVITY(100) PORT_KEYDELTA(200) PORT_RESET PORT_REVERSE |
| 5243 | PORT_BIT( 0xff, 0x80, IPT_AD_STICK_Y ) PORT_MINMAX(0x01, 0xff) PORT_SENSITIVITY(100) PORT_KEYDELTA(20) |
| 5218 | 5244 | INPUT_PORTS_END /* Armadillo Racing */ |
| 5219 | 5245 | |
| 5220 | 5246 | static INPUT_PORTS_START( propcycl ) |