Previous 199869 Revisions Next

r20671 Saturday 2nd February, 2013 at 15:42:59 UTC by hap
improve armadillo control
[src/mame/drivers]namcos22.c
[src/mame/includes]namcos22.h

trunk/src/mame/includes/namcos22.h
r20670r20671
7878   optional_shared_ptr<UINT32> m_czram;
7979
8080   int m_bEnableDspIrqs;
81   attotime m_ar_tb_reload[2];
8281   emu_timer *m_ar_tb_interrupt[2];
8382   UINT16 m_MasterBIOZ;
8483   UINT32 *m_pPointRAM;
trunk/src/mame/drivers/namcos22.c
r20670r20671
30123012TIMER_CALLBACK_MEMBER(namcos22_state::adillor_trackball_interrupt)
30133013{
30143014   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);
30163015}
30173016
30183017TIMER_DEVICE_CALLBACK_MEMBER(namcos22_state::adillor_trackball_update)
30193018{
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)
30223024   {
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++)
30253053      {
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         }
30403064      }
3041      else
3065   }
3066   else
3067   {
3068      // both axes not moving
3069      for (int axis = 0; axis < 2; axis++)
30423070      {
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);
30463072      }
30473073   }
30483074}
r20670r20671
52115237   PORT_BIT( 0xfe, IP_ACTIVE_LOW, IPT_UNKNOWN )
52125238
52135239   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)
52155241
52165242   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)
52185244INPUT_PORTS_END /* Armadillo Racing */
52195245
52205246static INPUT_PORTS_START( propcycl )

Previous 199869 Revisions Next


© 1997-2024 The MAME Team