Previous 199869 Revisions Next

r24047 Tuesday 2nd July, 2013 at 18:05:45 UTC by Tafoid
Modernize the Konami 037122 device.  [Osso]
[src/mame/drivers]hornet.c
[src/mame/video]konicdev.c konicdev.h

trunk/src/mame/drivers/hornet.c
r24046r24047
405405READ32_MEMBER(hornet_state::hornet_k037122_sram_r)
406406{
407407   k037122_device *k037122 = get_cgboard_id() ? m_k037122_2 : m_k037122_1;
408   return k037122_sram_r(k037122, space, offset, mem_mask);
408   return k037122->sram_r(space, offset, mem_mask);
409409}
410410
411411WRITE32_MEMBER(hornet_state::hornet_k037122_sram_w)
412412{
413413   k037122_device *k037122 = get_cgboard_id() ? m_k037122_2 : m_k037122_1;
414   k037122_sram_w(k037122, space, offset, data, mem_mask);
414   k037122->sram_w(space, offset, data, mem_mask);
415415}
416416
417417
418418READ32_MEMBER(hornet_state::hornet_k037122_char_r)
419419{
420420   k037122_device *k037122 = get_cgboard_id() ? m_k037122_2 : m_k037122_1;
421   return k037122_char_r(k037122, space, offset, mem_mask);
421   return k037122->char_r(space, offset, mem_mask);
422422}
423423
424424WRITE32_MEMBER(hornet_state::hornet_k037122_char_w)
425425{
426426   k037122_device *k037122 = get_cgboard_id() ? m_k037122_2 : m_k037122_1;
427   k037122_char_w(k037122, space, offset, data, mem_mask);
427   k037122->char_w(space, offset, data, mem_mask);
428428}
429429
430430READ32_MEMBER(hornet_state::hornet_k037122_reg_r)
431431{
432432   k037122_device *k037122 = get_cgboard_id() ? m_k037122_2 : m_k037122_1;
433   return k037122_reg_r(k037122, space, offset, mem_mask);
433   return k037122->reg_r(space, offset, mem_mask);
434434}
435435
436436WRITE32_MEMBER(hornet_state::hornet_k037122_reg_w)
437437{
438438   k037122_device *k037122 = get_cgboard_id() ? m_k037122_2 : m_k037122_1;
439   k037122_reg_w(k037122, space, offset, data, mem_mask);
439   k037122->reg_w(space, offset, data, mem_mask);
440440}
441441
442442WRITE_LINE_MEMBER(hornet_state::voodoo_vblank_0)
r24046r24047
454454
455455   voodoo_update(voodoo, bitmap, cliprect);
456456
457   k037122_tile_draw(m_k037122_1, bitmap, cliprect);
457   m_k037122_1->tile_draw(bitmap, cliprect);
458458
459459   draw_7segment_led(bitmap, 3, 3, m_led_reg0);
460460   draw_7segment_led(bitmap, 9, 3, m_led_reg1);
r24046r24047
469469      voodoo_update(voodoo, bitmap, cliprect);
470470
471471      /* TODO: tilemaps per screen */
472      k037122_tile_draw(m_k037122_1, bitmap, cliprect);
472      m_k037122_1->tile_draw(bitmap, cliprect);
473473   }
474474   else if (strcmp(screen.tag(), ":rscreen") == 0)
475475   {
r24046r24047
477477      voodoo_update(voodoo, bitmap, cliprect);
478478
479479      /* TODO: tilemaps per screen */
480      k037122_tile_draw(m_k037122_2, bitmap, cliprect);
480      m_k037122_2->tile_draw(bitmap, cliprect);
481481   }
482482
483483   draw_7segment_led(bitmap, 3, 3, m_led_reg0);
trunk/src/mame/video/konicdev.c
r24046r24047
1060910609/*                                                                         */
1061010610/***************************************************************************/
1061110611
10612struct k037122_state
10613{
10614   screen_device *screen;
10615   tilemap_t        *layer[2];
10616   int            gfx_index;
10617
10618   UINT32 *       tile_ram;
10619   UINT32 *       char_ram;
10620   UINT32 *       reg;
10621};
10622
10623
1062410612#define K037122_NUM_TILES       16384
1062510613
10626/*****************************************************************************
10627    INLINE FUNCTIONS
10628*****************************************************************************/
10614const device_type K037122 = &device_creator<k037122_device>;
1062910615
10630INLINE k037122_state *k037122_get_safe_token( device_t *device )
10616k037122_device::k037122_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
10617   : device_t(mconfig, K037122, "Konami 0371222", tag, owner, clock, "k037122", __FILE__),
10618   m_screen(NULL),
10619   m_tile_ram(NULL),
10620   m_char_ram(NULL),
10621   m_reg(NULL)
1063110622{
10632   assert(device != NULL);
10633   assert(device->type() == K037122);
10634
10635   return (k037122_state *)downcast<k037122_device *>(device)->token();
1063610623}
1063710624
10638INLINE const k037122_interface *k037122_get_interface( device_t *device )
10625//-------------------------------------------------
10626//  device_config_complete - perform any
10627//  operations now that the configuration is
10628//  complete
10629//-------------------------------------------------
10630
10631void k037122_device::device_config_complete()
1063910632{
10640   assert(device != NULL);
10641   assert((device->type() == K037122));
10642   return (const k037122_interface *) device->static_config();
10633   // inherit a copy of the static data
10634   const k037122_interface *intf = reinterpret_cast<const k037122_interface *>(static_config());
10635   if (intf != NULL)
10636      *static_cast<k037122_interface *>(this) = *intf;
10637
10638   // or initialize to defaults if none provided
10639   else
10640   {
10641      m_screen_tag = "";
10642      m_gfx_index = 0;
10643   }
1064310644}
1064410645
10645/*****************************************************************************
10646    DEVICE HANDLERS
10647*****************************************************************************/
10646//-------------------------------------------------
10647//  device_start - device-specific startup
10648//-------------------------------------------------
1064810649
10649static const gfx_layout k037122_char_layout =
10650void k037122_device::device_start()
1065010651{
10652   static const gfx_layout k037122_char_layout =
10653   {
1065110654   8, 8,
1065210655   K037122_NUM_TILES,
1065310656   8,
r24046r24047
1065510658   { 1*16, 0*16, 3*16, 2*16, 5*16, 4*16, 7*16, 6*16 },
1065610659   { 0*128, 1*128, 2*128, 3*128, 4*128, 5*128, 6*128, 7*128 },
1065710660   8*128
10658};
10661   };   
10662   
10663   m_screen = machine().device<screen_device>(m_screen_tag);
10664   
10665   m_char_ram = auto_alloc_array_clear(machine(), UINT32, 0x200000 / 4);
10666   m_tile_ram = auto_alloc_array_clear(machine(), UINT32, 0x20000 / 4);
10667   m_reg = auto_alloc_array_clear(machine(), UINT32, 0x400 / 4);
1065910668
10660TILE_GET_INFO_MEMBER(k037122_device::k037122_tile_info_layer0)
10669   m_layer[0] = &machine().tilemap().create(tilemap_get_info_delegate(FUNC(k037122_device::tile_info_layer0),this), TILEMAP_SCAN_ROWS, 8, 8, 256, 64);
10670   m_layer[1] = &machine().tilemap().create(tilemap_get_info_delegate(FUNC(k037122_device::tile_info_layer1),this), TILEMAP_SCAN_ROWS, 8, 8, 128, 64);
10671
10672   m_layer[0]->set_transparent_pen(0);
10673   m_layer[1]->set_transparent_pen(0);
10674
10675   machine().gfx[m_gfx_index] = auto_alloc_clear(machine(), gfx_element(machine(), k037122_char_layout, (UINT8*)m_char_ram, machine().total_colors() / 16, 0));
10676
10677   save_pointer(NAME(m_reg), 0x400 / 4);
10678   save_pointer(NAME(m_char_ram), 0x200000 / 4);
10679   save_pointer(NAME(m_tile_ram), 0x20000 / 4);
10680
10681}
10682
10683//-------------------------------------------------
10684//  device_reset - device-specific reset
10685//-------------------------------------------------
10686
10687void k037122_device::device_reset()
1066110688{
10662   k037122_state *k037122 = k037122_get_safe_token(this);
10663   UINT32 val = k037122->tile_ram[tile_index + (0x8000/4)];
10689   memset(m_char_ram, 0, 0x200000);
10690   memset(m_tile_ram, 0, 0x20000);
10691   memset(m_reg, 0, 0x400);
10692}
10693
10694/*****************************************************************************
10695    DEVICE HANDLERS
10696*****************************************************************************/
10697
10698TILE_GET_INFO_MEMBER(k037122_device::tile_info_layer0)
10699{
10700   UINT32 val = m_tile_ram[tile_index + (0x8000/4)];
1066410701   int color = (val >> 17) & 0x1f;
1066510702   int tile = val & 0x3fff;
1066610703   int flags = 0;
r24046r24047
1067010707   if (val & 0x800000)
1067110708      flags |= TILE_FLIPY;
1067210709
10673   SET_TILE_INFO_MEMBER(k037122->gfx_index, tile, color, flags);
10710   SET_TILE_INFO_MEMBER(m_gfx_index, tile, color, flags);
1067410711}
1067510712
10676TILE_GET_INFO_MEMBER(k037122_device::k037122_tile_info_layer1)
10713TILE_GET_INFO_MEMBER(k037122_device::tile_info_layer1)
1067710714{
10678   k037122_state *k037122 = k037122_get_safe_token(this);
10679   UINT32 val = k037122->tile_ram[tile_index];
10715   UINT32 val = m_tile_ram[tile_index];
1068010716   int color = (val >> 17) & 0x1f;
1068110717   int tile = val & 0x3fff;
1068210718   int flags = 0;
r24046r24047
1068610722   if (val & 0x800000)
1068710723      flags |= TILE_FLIPY;
1068810724
10689   SET_TILE_INFO_MEMBER(k037122->gfx_index, tile, color, flags);
10725   SET_TILE_INFO_MEMBER(m_gfx_index, tile, color, flags);
1069010726}
1069110727
1069210728
10693void k037122_tile_draw( device_t *device, bitmap_rgb32 &bitmap, const rectangle &cliprect )
10729void k037122_device::tile_draw( bitmap_rgb32 &bitmap, const rectangle &cliprect )
1069410730{
10695   k037122_state *k037122 = k037122_get_safe_token(device);
10696   const rectangle &visarea = k037122->screen->visible_area();
10731   const rectangle &visarea = m_screen->visible_area();
1069710732
10698   if (k037122->reg[0xc] & 0x10000)
10733   if (m_reg[0xc] & 0x10000)
1069910734   {
10700      k037122->layer[1]->set_scrolldx(visarea.min_x, visarea.min_x);
10701      k037122->layer[1]->set_scrolldy(visarea.min_y, visarea.min_y);
10702      k037122->layer[1]->draw(bitmap, cliprect, 0, 0);
10735      m_layer[1]->set_scrolldx(visarea.min_x, visarea.min_x);
10736      m_layer[1]->set_scrolldy(visarea.min_y, visarea.min_y);
10737      m_layer[1]->draw(bitmap, cliprect, 0, 0);
1070310738   }
1070410739   else
1070510740   {
10706      k037122->layer[0]->set_scrolldx(visarea.min_x, visarea.min_x);
10707      k037122->layer[0]->set_scrolldy(visarea.min_y, visarea.min_y);
10708      k037122->layer[0]->draw(bitmap, cliprect, 0, 0);
10741      m_layer[0]->set_scrolldx(visarea.min_x, visarea.min_x);
10742      m_layer[0]->set_scrolldy(visarea.min_y, visarea.min_y);
10743      m_layer[0]->draw(bitmap, cliprect, 0, 0);
1070910744   }
1071010745}
1071110746
10712static void update_palette_color( device_t *device, UINT32 palette_base, int color )
10747void k037122_device::update_palette_color( UINT32 palette_base, int color )
1071310748{
10714   k037122_state *k037122 = k037122_get_safe_token(device);
10715   UINT32 data = k037122->tile_ram[(palette_base / 4) + color];
10749   UINT32 data = m_tile_ram[(palette_base / 4) + color];
1071610750
10717   palette_set_color_rgb(device->machine(), color, pal5bit(data >> 6), pal6bit(data >> 0), pal5bit(data >> 11));
10751   palette_set_color_rgb(machine(), color, pal5bit(data >> 6), pal6bit(data >> 0), pal5bit(data >> 11));
1071810752}
1071910753
10720READ32_DEVICE_HANDLER( k037122_sram_r )
10754READ32_MEMBER( k037122_device::sram_r )
1072110755{
10722   k037122_state *k037122 = k037122_get_safe_token(device);
10723
10724   return k037122->tile_ram[offset];
10756   return m_tile_ram[offset];
1072510757}
1072610758
10727WRITE32_DEVICE_HANDLER( k037122_sram_w )
10759WRITE32_MEMBER( k037122_device::sram_w )
1072810760{
10729   k037122_state *k037122 = k037122_get_safe_token(device);
10761   COMBINE_DATA(m_tile_ram + offset);
1073010762
10731   COMBINE_DATA(k037122->tile_ram + offset);
10732
10733   if (k037122->reg[0xc] & 0x10000)
10763   if (m_reg[0xc] & 0x10000)
1073410764   {
1073510765      if (offset < 0x8000 / 4)
1073610766      {
10737         k037122->layer[1]->mark_tile_dirty(offset);
10767         m_layer[1]->mark_tile_dirty(offset);
1073810768      }
1073910769      else if (offset >= 0x8000 / 4 && offset < 0x18000 / 4)
1074010770      {
10741         k037122->layer[0]->mark_tile_dirty(offset - (0x8000 / 4));
10771         m_layer[0]->mark_tile_dirty(offset - (0x8000 / 4));
1074210772      }
1074310773      else if (offset >= 0x18000 / 4)
1074410774      {
10745         update_palette_color(device, 0x18000, offset - (0x18000 / 4));
10775         update_palette_color(0x18000, offset - (0x18000 / 4));
1074610776      }
1074710777   }
1074810778   else
1074910779   {
1075010780      if (offset < 0x8000 / 4)
1075110781      {
10752         update_palette_color(device, 0, offset);
10782         update_palette_color(0, offset);
1075310783      }
1075410784      else if (offset >= 0x8000 / 4 && offset < 0x18000 / 4)
1075510785      {
10756         k037122->layer[0]->mark_tile_dirty(offset - (0x8000 / 4));
10786         m_layer[0]->mark_tile_dirty(offset - (0x8000 / 4));
1075710787      }
1075810788      else if (offset >= 0x18000 / 4)
1075910789      {
10760         k037122->layer[1]->mark_tile_dirty(offset - (0x18000 / 4));
10790         m_layer[1]->mark_tile_dirty(offset - (0x18000 / 4));
1076110791      }
1076210792   }
1076310793}
1076410794
1076510795
10766READ32_DEVICE_HANDLER( k037122_char_r )
10796READ32_MEMBER( k037122_device::char_r )
1076710797{
10768   k037122_state *k037122 = k037122_get_safe_token(device);
10769   int bank = k037122->reg[0x30 / 4] & 0x7;
10798   int bank = m_reg[0x30 / 4] & 0x7;
1077010799
10771   return k037122->char_ram[offset + (bank * (0x40000 / 4))];
10800   return m_char_ram[offset + (bank * (0x40000 / 4))];
1077210801}
1077310802
10774WRITE32_DEVICE_HANDLER( k037122_char_w )
10803WRITE32_MEMBER( k037122_device::char_w )
1077510804{
10776   k037122_state *k037122 = k037122_get_safe_token(device);
10777   int bank = k037122->reg[0x30 / 4] & 0x7;
10805   int bank = m_reg[0x30 / 4] & 0x7;
1077810806   UINT32 addr = offset + (bank * (0x40000/4));
1077910807
10780   COMBINE_DATA(k037122->char_ram + addr);
10781   space.machine().gfx[k037122->gfx_index]->mark_dirty(addr / 32);
10808   COMBINE_DATA(m_char_ram + addr);
10809   space.machine().gfx[m_gfx_index]->mark_dirty(addr / 32);
1078210810}
1078310811
10784READ32_DEVICE_HANDLER( k037122_reg_r )
10812READ32_MEMBER( k037122_device::reg_r )
1078510813{
10786   k037122_state *k037122 = k037122_get_safe_token(device);
10787
1078810814   switch (offset)
1078910815   {
1079010816      case 0x14/4:
r24046r24047
1079210818         return 0x000003fa;
1079310819      }
1079410820   }
10795   return k037122->reg[offset];
10821   return m_reg[offset];
1079610822}
1079710823
10798WRITE32_DEVICE_HANDLER( k037122_reg_w )
10824WRITE32_MEMBER( k037122_device::reg_w )
1079910825{
10800   k037122_state *k037122 = k037122_get_safe_token(device);
10801
10802   COMBINE_DATA(k037122->reg + offset);
10826   COMBINE_DATA(m_reg + offset);
1080310827}
1080410828
10805/*****************************************************************************
10806    DEVICE INTERFACE
10807*****************************************************************************/
1080810829
10809const device_type K037122 = &device_creator<k037122_device>;
10810
10811k037122_device::k037122_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
10812   : device_t(mconfig, K037122, "Konami 0371222", tag, owner, clock, "k037122", __FILE__)
10813{
10814   m_token = global_alloc_clear(k037122_state);
10815}
10816
10817//-------------------------------------------------
10818//  device_config_complete - perform any
10819//  operations now that the configuration is
10820//  complete
10821//-------------------------------------------------
10822
10823void k037122_device::device_config_complete()
10824{
10825}
10826
10827//-------------------------------------------------
10828//  device_start - device-specific startup
10829//-------------------------------------------------
10830
10831void k037122_device::device_start()
10832{
10833   k037122_state *k037122 = k037122_get_safe_token(this);
10834   const k037122_interface *intf = k037122_get_interface(this);
10835
10836   k037122->screen = machine().device<screen_device>(intf->screen);
10837   k037122->gfx_index = intf->gfx_index;
10838
10839   k037122->char_ram = auto_alloc_array(machine(), UINT32, 0x200000 / 4);
10840   k037122->tile_ram = auto_alloc_array(machine(), UINT32, 0x20000 / 4);
10841   k037122->reg = auto_alloc_array(machine(), UINT32, 0x400 / 4);
10842
10843   k037122->layer[0] = &machine().tilemap().create(tilemap_get_info_delegate(FUNC(k037122_device::k037122_tile_info_layer0),this), TILEMAP_SCAN_ROWS, 8, 8, 256, 64);
10844   k037122->layer[1] = &machine().tilemap().create(tilemap_get_info_delegate(FUNC(k037122_device::k037122_tile_info_layer1),this), TILEMAP_SCAN_ROWS, 8, 8, 128, 64);
10845
10846   k037122->layer[0]->set_transparent_pen(0);
10847   k037122->layer[1]->set_transparent_pen(0);
10848
10849   machine().gfx[k037122->gfx_index] = auto_alloc(machine(), gfx_element(machine(), k037122_char_layout, (UINT8*)k037122->char_ram, machine().total_colors() / 16, 0));
10850
10851   save_pointer(NAME(k037122->reg), 0x400 / 4);
10852   save_pointer(NAME(k037122->char_ram), 0x200000 / 4);
10853   save_pointer(NAME(k037122->tile_ram), 0x20000 / 4);
10854
10855}
10856
10857//-------------------------------------------------
10858//  device_reset - device-specific reset
10859//-------------------------------------------------
10860
10861void k037122_device::device_reset()
10862{
10863   k037122_state *k037122 = k037122_get_safe_token(this);
10864
10865   memset(k037122->char_ram, 0, 0x200000);
10866   memset(k037122->tile_ram, 0, 0x20000);
10867   memset(k037122->reg, 0, 0x400);
10868}
10869
10870
1087110830/***************************************************************************/
1087210831/*                                                                         */
1087310832/*                         misc debug handlers                             */
trunk/src/mame/video/konicdev.h
r24046r24047
140140
141141struct k037122_interface
142142{
143   const char     *screen;
144   int            gfx_index;
143   const char     *m_screen_tag;
144   int            m_gfx_index;
145145};
146146
147147class k007121_device : public device_t
r24046r24047
562562
563563extern const device_type K001604;
564564
565class k037122_device : public device_t
565class k037122_device : public device_t,
566                              public k037122_interface
566567{
567568public:
568569   k037122_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
569   ~k037122_device() { global_free(m_token); }
570   ~k037122_device() {}
570571
571   // access to legacy token
572   void *token() const { assert(m_token != NULL); return m_token; }
572   void tile_draw( bitmap_rgb32 &bitmap, const rectangle &cliprect );
573   DECLARE_READ32_MEMBER( sram_r );
574   DECLARE_WRITE32_MEMBER( sram_w );
575   DECLARE_READ32_MEMBER( char_r );
576   DECLARE_WRITE32_MEMBER( char_w );
577   DECLARE_READ32_MEMBER( reg_r );
578   DECLARE_WRITE32_MEMBER( reg_w );
579
573580protected:
574581   // device-level overrides
575582   virtual void device_config_complete();
576583   virtual void device_start();
577584   virtual void device_reset();
585
578586private:
579587   // internal state
580   void *m_token;
588   screen_device *m_screen;
589   tilemap_t     *m_layer[2];
590   
591   UINT32 *       m_tile_ram;
592   UINT32 *       m_char_ram;
593   UINT32 *       m_reg;
581594
582   TILE_GET_INFO_MEMBER(k037122_tile_info_layer0);
583   TILE_GET_INFO_MEMBER(k037122_tile_info_layer1);
595   TILE_GET_INFO_MEMBER(tile_info_layer0);
596   TILE_GET_INFO_MEMBER(tile_info_layer1);
597   void update_palette_color( UINT32 palette_base, int color );
584598};
585599
586600extern const device_type K037122;
r24046r24047
11451159DECLARE_WRITE32_DEVICE_HANDLER( k001604_reg_w );
11461160DECLARE_READ32_DEVICE_HANDLER( k001604_reg_r );
11471161
1148
1149/**  Konami 037122  **/
1150void k037122_tile_draw( device_t *device, bitmap_rgb32 &bitmap, const rectangle &cliprect );
1151DECLARE_READ32_DEVICE_HANDLER( k037122_sram_r );
1152DECLARE_WRITE32_DEVICE_HANDLER( k037122_sram_w );
1153DECLARE_READ32_DEVICE_HANDLER( k037122_char_r );
1154DECLARE_WRITE32_DEVICE_HANDLER( k037122_char_w );
1155DECLARE_READ32_DEVICE_HANDLER( k037122_reg_r );
1156DECLARE_WRITE32_DEVICE_HANDLER( k037122_reg_w );
1157
11581162#define K056832_DRAW_FLAG_MIRROR      0x00800000
11591163
11601164// debug handlers

Previous 199869 Revisions Next


© 1997-2024 The MAME Team