Previous 199869 Revisions Next

r17384 Tuesday 21st August, 2012 at 21:05:31 UTC by Ville Linde
cobra.c: Added JVS emulation.
[src/mame/drivers]cobra.c

trunk/src/mame/drivers/cobra.c
r17383r17384
278278#include "machine/pci.h"
279279#include "machine/idectrl.h"
280280#include "machine/timekpr.h"
281#include "machine/jvshost.h"
282#include "machine/jvsdev.h"
281283#include "video/polynew.h"
282284#include "sound/rf5c400.h"
283285
r17383r17384
286288#define M2SFIFO_VERBOSE         0
287289#define S2MFIFO_VERBOSE         0
288290
291
292/* Cobra Renderer class */
293
289294struct cobra_polydata
290295{
291296};
r17383r17384
354359   };
355360};
356361
362
363/* FIFO class */
357364class cobra_fifo
358365{
359366public:
r17383r17384
402409   event_delegate m_event_callback;
403410};
404411
412
413/* Cobra JVS Device class */
414
415class cobra_jvs : public jvs_device
416{
417public:
418   cobra_jvs(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
419
420protected:
421   virtual bool switches(UINT8 *&buf, UINT8 count_players, UINT8 bytes_per_switch);
422   virtual bool coin_counters(UINT8 *&buf, UINT8 count);
423};
424
425const device_type COBRA_JVS = &device_creator<cobra_jvs>;
426
427cobra_jvs::cobra_jvs(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
428   : jvs_device(mconfig, COBRA_JVS, "COBRA_JVS", tag, owner, clock)
429{
430
431}
432
433bool cobra_jvs::switches(UINT8 *&buf, UINT8 count_players, UINT8 bytes_per_switch)
434{
435   printf("jvs switch read: num players %d, bytes %d\n", count_players, bytes_per_switch);
436
437   if (count_players > 2 || bytes_per_switch > 2)
438      return false;
439
440   static const char* player_ports[2] = { ":P1", ":P2" };
441
442   *buf++ = ioport(":TEST")->read_safe(0);
443
444   for (int i=0; i < count_players; i++)
445   {
446      UINT32 pval = ioport(player_ports[i])->read_safe(0);
447      for (int j=0; j < bytes_per_switch; j++)
448      {
449         *buf++ = (UINT8)(pval >> ((1-j) * 8));
450      }
451   }
452   return true;
453}
454
455bool cobra_jvs::coin_counters(UINT8 *&buf, UINT8 count)
456{
457   printf("jvs coin counter read: count %d\n", count);
458
459   if (count > 2)
460      return false;
461
462   *buf++ = 0x00;
463   *buf++ = 0x01;
464
465   return true;
466}
467
468
469class cobra_jvs_host : public jvs_host
470{
471public:
472   cobra_jvs_host(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
473   void write(UINT8, const UINT8 *&rec_data, UINT32 &rec_size);
474
475private:
476   UINT8 m_send[512];
477   int m_send_ptr;
478};
479
480const device_type COBRA_JVS_HOST = &device_creator<cobra_jvs_host>;
481
482cobra_jvs_host::cobra_jvs_host(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
483   : jvs_host(mconfig, COBRA_JVS_HOST, "COBRA_JVS_HOST", tag, owner, clock)
484{
485   m_send_ptr = 0;
486}
487
488void cobra_jvs_host::write(UINT8 data, const UINT8 *&rec_data, UINT32 &rec_size)
489{
490   m_send[m_send_ptr++] = data;
491   push(data);
492
493   if (m_send[0] == 0xe0)
494   {
495      if (m_send_ptr > 2)
496      {
497         UINT8 length = m_send[2];
498         if (length == 0xff)
499            length = 4;
500         else
501            length = length + 3;
502
503         if (m_send_ptr >= length)
504         {
505            commit_encoded();
506
507            get_encoded_reply(rec_data, rec_size);
508   
509            m_send_ptr = 0;
510            return;
511         }
512      }
513   }
514   else
515   {
516      m_send_ptr = 0;
517   }
518
519   rec_data = NULL;
520   rec_size = 0;
521}
522
523
524/* Cobra driver class */
525
405526class cobra_state : public driver_device
406527{
407528public:
r17383r17384
465586   void m2sfifo_event_callback(cobra_fifo::EventType event);
466587   void s2mfifo_event_callback(cobra_fifo::EventType event);
467588
589   enum
590   {
591      MAIN_INT_M2S = 0x01,
592      MAIN_INT_S2M = 0x02,
593   };
594
468595   UINT8 m_m2s_int_enable;
469596   UINT8 m_s2m_int_enable;
470597   UINT8 m_vblank_enable;
r17383r17384
503630   int m_gfx_fifo_loopback;
504631   int m_gfx_unknown_v1;
505632   int m_gfx_status_byte;
633
506634   DECLARE_DRIVER_INIT(racjamdx);
507635   DECLARE_DRIVER_INIT(bujutsu);
508636   DECLARE_DRIVER_INIT(cobra);
r17383r17384
510638
511639void cobra_renderer::render_color_scan(INT32 scanline, const extent_t &extent, const cobra_polydata &extradata, int threadid)
512640{
513   /*
514641    UINT32 *fb = &m_framebuffer->pix32(scanline);
515642
516    UINT32 color = 0xffff0000; // TODO
643    UINT32 color = 0xff000000; // TODO
517644
518645    for (int x = extent.startx; x < extent.stopx; x++)
519646    {
520647        fb[x] = color;
521648    }
522    */
523649}
524650
525651void cobra_renderer::render_texture_scan(INT32 scanline, const extent_t &extent, const cobra_polydata &extradata, int threadid)
r17383r17384
873999
8741000         if (m_m2s_int_enable & 0x80)
8751001         {
1002            if (!m_m2s_int_mode)
1003               m_main_int_active |= MAIN_INT_M2S;
1004
8761005            cputag_set_input_line(machine(), "maincpu", INPUT_LINE_IRQ0, ASSERT_LINE);
8771006         }
8781007
r17383r17384
8951024   switch (event)
8961025   {
8971026      case cobra_fifo::EVENT_EMPTY:
1027         m_main_int_active &= ~MAIN_INT_S2M;
8981028         break;
8991029
9001030      case cobra_fifo::EVENT_HALF_FULL:
r17383r17384
10361166
10371167      int value = 0x01;
10381168
1039      if (m_s2mfifo->is_empty())      // TODO: this is an interrupt
1040      {
1041         value |= 0x2;
1042      }
1043
1044      //value |= (m_main_int_active & 2) ? 0x00 : 0x02;
1045      value |= (m_main_int_active & 1) ? 0x00 : 0x08;
1169      value |= (m_main_int_active & MAIN_INT_S2M) ? 0x00 : 0x02;
1170      value |= (m_main_int_active & MAIN_INT_M2S) ? 0x00 : 0x08;
10461171      value |= (m_gfx_unk_flag & 0x80) ? 0x00 : 0x04;
10471172
10481173      r |= (UINT64)(value) << 32;
r17383r17384
10601185
10611186      m_m2sfifo->push(&space.device(), (UINT8)(data >> 40));
10621187
1188      if (!m_m2s_int_mode)
1189         m_main_int_active &= ~MAIN_INT_M2S;
1190
10631191      cputag_set_input_line(space.machine(), "subcpu", INPUT_LINE_IRQ0, ASSERT_LINE);
10641192
10651193      // EXISR needs to update for the *next* instruction during FIFO tests
r17383r17384
10821210      {
10831211         if (!m_m2sfifo->is_half_full())
10841212         {
1085            m_main_int_active |= 1;
1213            m_main_int_active |= MAIN_INT_M2S;
10861214         }
10871215         else
10881216         {
1089            m_main_int_active &= ~1;
1217            m_main_int_active &= ~MAIN_INT_M2S;
10901218         }
10911219      }
10921220      else
10931221      {
10941222         if (m_m2sfifo->is_empty())
10951223         {
1096            m_main_int_active |= 1;
1224            m_main_int_active |= MAIN_INT_M2S;
10971225         }
10981226         else
10991227         {
1100            m_main_int_active &= ~1;
1228            m_main_int_active &= ~MAIN_INT_M2S;
11011229         }
11021230      }
11031231
r17383r17384
11331261
11341262      if ((m_s2m_int_enable & 0x80) == 0)
11351263      {
1136         m_main_int_active &= ~2;
1264         m_main_int_active &= ~MAIN_INT_S2M;
11371265
11381266         // clear the interrupt
11391267         cputag_set_input_line(space.machine(), "maincpu", INPUT_LINE_IRQ0, CLEAR_LINE);
r17383r17384
13461474
13471475      m_s2mfifo->push(&space.device(), (UINT8)(data >> 24));
13481476
1477      m_main_int_active |= MAIN_INT_S2M;
1478
13491479      // fire off an interrupt if enabled
13501480      if (m_s2m_int_enable & 0x80)
13511481      {
1352         m_main_int_active |= 2;
1353
13541482         cputag_set_input_line(space.machine(), "maincpu", INPUT_LINE_IRQ0, ASSERT_LINE);
13551483      }
13561484   }
r17383r17384
15531681
15541682static void sub_jvs_w(device_t *device, UINT8 data)
15551683{
1684   cobra_jvs_host *jvs = downcast<cobra_jvs_host *>(device->machine().device("cobra_jvs_host"));
15561685   printf("sub_jvs_w: %02X\n", data);
1686
1687   const UINT8 *rec_data;
1688   UINT32 rec_size;
1689
1690   jvs->write(data, rec_data, rec_size);
1691
1692   if (rec_size > 0)
1693   {
1694      printf("jvs reply ");
1695      for (int i=0; i < rec_size; i++)
1696      {
1697         printf("%02X ", rec_data[i]);
1698      }
1699      printf("\n");
1700   }
15571701}
15581702
15591703static ADDRESS_MAP_START( cobra_sub_map, AS_PROGRAM, 32, cobra_state )
r17383r17384
19382082                  }
19392083                  else
19402084                  {
1941                     //render_delegate rd = render_delegate(FUNC(cobra_renderer::render_color_scan), this);
2085                     render_delegate rd = render_delegate(FUNC(cobra_renderer::render_color_scan), this);
19422086                     for (int i=2; i < units; i++)
19432087                     {
1944                        //render_triangle(visarea, rd, 6, vert[i-2], vert[i-1], vert[i]);
1945                        draw_point(visarea, vert[i-2], 0xffff0000);
1946                        draw_point(visarea, vert[i-1], 0xffff0000);
1947                        draw_point(visarea, vert[i], 0xffff0000);
2088                        render_triangle(visarea, rd, 6, vert[i-2], vert[i-1], vert[i]);
2089                        //draw_point(visarea, vert[i-2], 0xffff0000);
2090                        //draw_point(visarea, vert[i-1], 0xffff0000);
2091                        //draw_point(visarea, vert[i], 0xffff0000);
19482092                     }
19492093                  }
19502094                  break;
r17383r17384
25392683/*****************************************************************************/
25402684
25412685INPUT_PORTS_START( cobra )
2542   PORT_START("IN0")
2543   PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_START1 )
2544   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_8WAY PORT_PLAYER(1)
2545   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_8WAY PORT_PLAYER(1)
2546   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_8WAY PORT_PLAYER(1)
2547   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_8WAY PORT_PLAYER(1)
2548   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(1)
2549   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(1)
2550   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_PLAYER(1)
2686   PORT_START("TEST")
2687   PORT_SERVICE_NO_TOGGLE( 0x80, IP_ACTIVE_LOW)         /* Test Button */
2688   PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_SERVICE ) PORT_NAME("Service") PORT_CODE(KEYCODE_7)
2689   PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_SERVICE2 )
2690   PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_UNKNOWN )
2691   PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_UNUSED )
2692   PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_UNUSED )
2693   PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_UNUSED )
2694   PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_UNUSED )
25512695
2696   PORT_START("P1")
2697   PORT_BIT( 0x8000, IP_ACTIVE_LOW, IPT_START ) PORT_PLAYER(1)
2698   PORT_BIT( 0x4000, IP_ACTIVE_LOW, IPT_UNKNOWN ) PORT_PLAYER(1)
2699   PORT_BIT( 0x2000, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_8WAY PORT_PLAYER(1)
2700   PORT_BIT( 0x1000, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_8WAY PORT_PLAYER(1)
2701   PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_8WAY PORT_PLAYER(1)
2702   PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_8WAY PORT_PLAYER(1)
2703   PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(1)
2704   PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(1)
2705   PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_PLAYER(1)
2706   PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_PLAYER(1)
2707   PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_BUTTON5 ) PORT_PLAYER(1)
2708   PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_BUTTON6 ) PORT_PLAYER(1)
2709   PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_UNUSED ) PORT_PLAYER(1)
2710   PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_UNUSED ) PORT_PLAYER(1)
2711   PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_UNUSED ) PORT_PLAYER(1)
2712   PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_UNUSED ) PORT_PLAYER(1)
2713
2714   PORT_START("P2")
2715   PORT_BIT( 0x8000, IP_ACTIVE_LOW, IPT_START ) PORT_PLAYER(2)
2716   PORT_BIT( 0x4000, IP_ACTIVE_LOW, IPT_UNKNOWN ) PORT_PLAYER(2)
2717   PORT_BIT( 0x2000, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_8WAY PORT_PLAYER(2)
2718   PORT_BIT( 0x1000, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_8WAY PORT_PLAYER(2)
2719   PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_8WAY PORT_PLAYER(2)
2720   PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_8WAY PORT_PLAYER(2)
2721   PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(2)
2722   PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(2)
2723   PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_PLAYER(2)
2724   PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_PLAYER(2)
2725   PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_BUTTON5 ) PORT_PLAYER(2)
2726   PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_BUTTON6 ) PORT_PLAYER(2)
2727   PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_UNUSED ) PORT_PLAYER(2)
2728   PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_UNUSED ) PORT_PLAYER(2)
2729   PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_UNUSED ) PORT_PLAYER(2)
2730   PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_UNUSED ) PORT_PLAYER(2)
25522731INPUT_PORTS_END
25532732
25542733static powerpc_config main_ppc_cfg =
r17383r17384
26272806
26282807   MCFG_QUANTUM_TIME(attotime::from_hz(15005))
26292808
2630   MCFG_MACHINE_RESET( cobra )
2809   MCFG_MACHINE_RESET(cobra)
26312810
26322811   MCFG_PCI_BUS_LEGACY_ADD("pcibus", 0)
26332812   MCFG_PCI_BUS_LEGACY_DEVICE(0, NULL, mpc106_pci_r, mpc106_pci_w)
r17383r17384
26502829   MCFG_SOUND_ROUTE(0, "lspeaker", 1.0)
26512830   MCFG_SOUND_ROUTE(1, "rspeaker", 1.0)
26522831
2653   MCFG_M48T58_ADD( "m48t58" )
2832   MCFG_M48T58_ADD("m48t58")
26542833
2834   MCFG_DEVICE_ADD("cobra_jvs_host", COBRA_JVS_HOST, 4000000)
2835   MCFG_JVS_DEVICE_ADD("cobra_jvs", COBRA_JVS, "cobra_jvs_host")
2836
26552837MACHINE_CONFIG_END
26562838
26572839/*****************************************************************************/

Previous 199869 Revisions Next


© 1997-2024 The MAME Team