Viewing File: <root>/src/mame/video/ironhors.c

    1  /***************************************************************************
    2  
    3    video.c
    4  
    5    Functions to emulate the video hardware of the machine.
    6  
    7  ***************************************************************************/
    8  
    9  #include "emu.h"
   10  #include "video/resnet.h"
   11  #include "includes/ironhors.h"
   12  
   13  /***************************************************************************
   14  
   15    Convert the color PROMs into a more useable format.
   16  
   17  ***************************************************************************/
   18  
   19  void ironhors_state::palette_init()
   20  {
   21      const UINT8 *color_prom = machine().root_device().memregion("proms")->base();
   22      static const int resistances[4] = { 2000, 1000, 470, 220 };
   23      double rweights[4], gweights[4], bweights[4];
   24      int i;
   25  
   26      /* compute the color output resistor weights */
   27      compute_resistor_weights(0, 255, -1.0,
   28              4, resistances, rweights, 1000, 0,
   29              4, resistances, gweights, 1000, 0,
   30              4, resistances, bweights, 1000, 0);
   31  
   32      /* allocate the colortable */
   33      machine().colortable = colortable_alloc(machine(), 0x100);
   34  
   35      /* create a lookup table for the palette */
   36      for (i = 0; i < 0x100; i++)
   37      {
   38          int bit0, bit1, bit2, bit3;
   39          int r, g, b;
   40  
   41          /* red component */
   42          bit0 = (color_prom[i + 0x000] >> 0) & 0x01;
   43          bit1 = (color_prom[i + 0x000] >> 1) & 0x01;
   44          bit2 = (color_prom[i + 0x000] >> 2) & 0x01;
   45          bit3 = (color_prom[i + 0x000] >> 3) & 0x01;
   46          r = combine_4_weights(rweights, bit0, bit1, bit2, bit3);
   47  
   48          /* green component */
   49          bit0 = (color_prom[i + 0x100] >> 0) & 0x01;
   50          bit1 = (color_prom[i + 0x100] >> 1) & 0x01;
   51          bit2 = (color_prom[i + 0x100] >> 2) & 0x01;
   52          bit3 = (color_prom[i + 0x100] >> 3) & 0x01;
   53          g = combine_4_weights(gweights, bit0, bit1, bit2, bit3);
   54  
   55          /* blue component */
   56          bit0 = (color_prom[i + 0x200] >> 0) & 0x01;
   57          bit1 = (color_prom[i + 0x200] >> 1) & 0x01;
   58          bit2 = (color_prom[i + 0x200] >> 2) & 0x01;
   59          bit3 = (color_prom[i + 0x200] >> 3) & 0x01;
   60          b = combine_4_weights(bweights, bit0, bit1, bit2, bit3);
   61  
   62          colortable_palette_set_color(machine().colortable, i, MAKE_RGB(r, g, b));
   63      }
   64  
   65      /* color_prom now points to the beginning of the lookup table,*/
   66      color_prom += 0x300;
   67  
   68      /* characters use colors 0x10-0x1f of each 0x20 color bank,
   69         while sprites use colors 0-0x0f */
   70      for (i = 0; i < 0x200; i++)
   71      {
   72          int j;
   73  
   74          for (j = 0; j < 8; j++)
   75          {
   76              UINT8 ctabentry = (j << 5) | ((~i & 0x100) >> 4) | (color_prom[i] & 0x0f);
   77              colortable_entry_set_value(machine().colortable, ((i & 0x100) << 3) | (j << 8) | (i & 0xff), ctabentry);
   78          }
   79      }
   80  }
   81  
   82  WRITE8_MEMBER(ironhors_state::ironhors_videoram_w)
   83  {
   84      m_videoram[offset] = data;
   85      m_bg_tilemap->mark_tile_dirty(offset);
   86  }
   87  
   88  WRITE8_MEMBER(ironhors_state::ironhors_colorram_w)
   89  {
   90      m_colorram[offset] = data;
   91      m_bg_tilemap->mark_tile_dirty(offset);
   92  }
   93  
   94  WRITE8_MEMBER(ironhors_state::ironhors_charbank_w)
   95  {
   96      if (m_charbank != (data & 0x03))
   97      {
   98          m_charbank = data & 0x03;
   99          machine().tilemap().mark_all_dirty();
  100      }
  101  
  102      m_spriterambank = data & 0x08;
  103  
  104      /* other bits unknown */
  105  }
  106  
  107  WRITE8_MEMBER(ironhors_state::ironhors_palettebank_w)
  108  {
  109      if (m_palettebank != (data & 0x07))
  110      {
  111          m_palettebank = data & 0x07;
  112          machine().tilemap().mark_all_dirty();
  113      }
  114  
  115      coin_counter_w(machine(), 0, data & 0x10);
  116      coin_counter_w(machine(), 1, data & 0x20);
  117  
  118      /* bit 6 unknown - set after game over */
  119  
  120      if (data & 0x88)
  121          popmessage("ironhors_palettebank_w %02x",data);
  122  }
  123  
  124  WRITE8_MEMBER(ironhors_state::ironhors_flipscreen_w)
  125  {
  126      if (flip_screen() != (~data & 0x08))
  127      {
  128          flip_screen_set(~data & 0x08);
  129          machine().tilemap().mark_all_dirty();
  130      }
  131  
  132      /* other bits are used too, but unknown */
  133  }
  134  
  135  TILE_GET_INFO_MEMBER(ironhors_state::get_bg_tile_info)
  136  {
  137      int code = m_videoram[tile_index] + ((m_colorram[tile_index] & 0x40) << 2) +
  138          ((m_colorram[tile_index] & 0x20) << 4) + (m_charbank << 10);
  139      int color = (m_colorram[tile_index] & 0x0f) + 16 * m_palettebank;
  140      int flags = ((m_colorram[tile_index] & 0x10) ? TILE_FLIPX : 0) |
  141          ((m_colorram[tile_index] & 0x20) ? TILE_FLIPY : 0);
  142  
  143      SET_TILE_INFO_MEMBER(0, code, color, flags);
  144  }
  145  
  146  void ironhors_state::video_start()
  147  {
  148      m_bg_tilemap = &machine().tilemap().create(tilemap_get_info_delegate(FUNC(ironhors_state::get_bg_tile_info),this), TILEMAP_SCAN_ROWS, 8, 8, 32, 32);
  149  
  150      m_bg_tilemap->set_scroll_rows(32);
  151  }
  152  
  153  void ironhors_state::draw_sprites( bitmap_ind16 &bitmap, const rectangle &cliprect )
  154  {
  155      int offs;
  156      UINT8 *sr;
  157  
  158      if (m_spriterambank != 0)
  159          sr = m_spriteram;
  160      else
  161          sr = m_spriteram2;
  162  
  163      for (offs = 0; offs < m_spriteram.bytes(); offs += 5)
  164      {
  165          int sx = sr[offs + 3];
  166          int sy = sr[offs + 2];
  167          int flipx = sr[offs + 4] & 0x20;
  168          int flipy = sr[offs + 4] & 0x40;
  169          int code = (sr[offs] << 2) + ((sr[offs + 1] & 0x03) << 10) + ((sr[offs + 1] & 0x0c) >> 2);
  170          int color = ((sr[offs + 1] & 0xf0) >> 4) + 16 * m_palettebank;
  171      //  int mod = flip_screen() ? -8 : 8;
  172  
  173          if (flip_screen())
  174          {
  175              sx = 240 - sx;
  176              sy = 240 - sy;
  177              flipx = !flipx;
  178              flipy = !flipy;
  179          }
  180  
  181          switch (sr[offs + 4] & 0x0c)
  182          {
  183              case 0x00:  /* 16x16 */
  184                  drawgfx_transpen(bitmap,cliprect,machine().gfx[1],
  185                          code/4,
  186                          color,
  187                          flipx,flipy,
  188                          sx,sy,0);
  189                  break;
  190  
  191              case 0x04:  /* 16x8 */
  192                  {
  193                      if (flip_screen()) sy += 8; // this fixes the train wheels' position
  194  
  195                      drawgfx_transpen(bitmap,cliprect,machine().gfx[2],
  196                              code & ~1,
  197                              color,
  198                              flipx,flipy,
  199                              flipx?sx+8:sx,sy,0);
  200                      drawgfx_transpen(bitmap,cliprect,machine().gfx[2],
  201                              code | 1,
  202                              color,
  203                              flipx,flipy,
  204                              flipx?sx:sx+8,sy,0);
  205                  }
  206                  break;
  207  
  208              case 0x08:  /* 8x16 */
  209                  {
  210                      drawgfx_transpen(bitmap,cliprect,machine().gfx[2],
  211                              code & ~2,
  212                              color,
  213                              flipx,flipy,
  214                              sx,flipy?sy+8:sy,0);
  215                      drawgfx_transpen(bitmap,cliprect,machine().gfx[2],
  216                              code | 2,
  217                              color,
  218                              flipx,flipy,
  219                              sx,flipy?sy:sy+8,0);
  220                  }
  221                  break;
  222  
  223              case 0x0c:  /* 8x8 */
  224                  {
  225                      drawgfx_transpen(bitmap,cliprect,machine().gfx[2],
  226                              code,
  227                              color,
  228                              flipx,flipy,
  229                              sx,sy,0);
  230                  }
  231                  break;
  232          }
  233      }
  234  }
  235  
  236  UINT32 ironhors_state::screen_update_ironhors(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
  237  {
  238      int row;
  239  
  240      for (row = 0; row < 32; row++)
  241          m_bg_tilemap->set_scrollx(row, m_scroll[row]);
  242  
  243      m_bg_tilemap->draw(bitmap, cliprect, 0, 0);
  244      draw_sprites(bitmap, cliprect);
  245      return 0;
  246  }
  247  
  248  TILE_GET_INFO_MEMBER(ironhors_state::farwest_get_bg_tile_info)
  249  {
  250      int code = m_videoram[tile_index] + ((m_colorram[tile_index] & 0x40) << 2) +
  251          ((m_colorram[tile_index] & 0x20) << 4) + (m_charbank << 10);
  252      int color = (m_colorram[tile_index] & 0x0f) + 16 * m_palettebank;
  253      int flags = 0;//((m_colorram[tile_index] & 0x10) ? TILE_FLIPX : 0) |  ((m_colorram[tile_index] & 0x20) ? TILE_FLIPY : 0);
  254  
  255      SET_TILE_INFO_MEMBER(0, code, color, flags);
  256  }
  257  
  258  VIDEO_START_MEMBER(ironhors_state,farwest)
  259  {
  260      m_bg_tilemap = &machine().tilemap().create(tilemap_get_info_delegate(FUNC(ironhors_state::farwest_get_bg_tile_info),this), TILEMAP_SCAN_ROWS, 8, 8, 32, 32);
  261  
  262      m_bg_tilemap->set_scroll_rows(32);
  263  }
  264  
  265  void ironhors_state::farwest_draw_sprites( bitmap_ind16 &bitmap, const rectangle &cliprect )
  266  {
  267      int offs;
  268      UINT8 *sr = m_spriteram2;
  269      UINT8 *sr2 = m_spriteram;
  270  
  271      for (offs = 0; offs < m_spriteram.bytes(); offs += 4)
  272      {
  273          int sx = sr[offs + 2];
  274          int sy = sr[offs + 1];
  275          int flipx = sr[offs + 3] & 0x20;
  276          int flipy = sr[offs + 3] & 0x40;
  277          int code = (sr[offs] << 2) + ((sr2[offs] & 0x03) << 10) + ((sr2[offs] & 0x0c) >> 2);
  278          int color = ((sr2[offs] & 0xf0) >> 4) + 16 * m_palettebank;
  279  
  280      //  int mod = flip_screen() ? -8 : 8;
  281  
  282  //      if (flip_screen())
  283          {
  284          //  sx = 240 - sx;
  285              sy = 240 - sy;
  286          //  flipx = !flipx;
  287          //  flipy = !flipy;
  288          }
  289  
  290          switch (sr[offs + 3] & 0x0c)
  291          {
  292              case 0x00:  /* 16x16 */
  293                  drawgfx_transpen(bitmap,cliprect,machine().gfx[1],
  294                          code/4,
  295                          color,
  296                          flipx,flipy,
  297                          sx,sy,0);
  298                  break;
  299  
  300              case 0x04:  /* 16x8 */
  301                  {
  302                      if (flip_screen()) sy += 8; // this fixes the train wheels' position
  303  
  304                      drawgfx_transpen(bitmap,cliprect,machine().gfx[2],
  305                              code & ~1,
  306                              color,
  307                              flipx,flipy,
  308                              flipx?sx+8:sx,sy,0);
  309                      drawgfx_transpen(bitmap,cliprect,machine().gfx[2],
  310                              code | 1,
  311                              color,
  312                              flipx,flipy,
  313                              flipx?sx:sx+8,sy,0);
  314                  }
  315                  break;
  316  
  317              case 0x08:  /* 8x16 */
  318                  {
  319                      drawgfx_transpen(bitmap,cliprect,machine().gfx[2],
  320                              code & ~2,
  321                              color,
  322                              flipx,flipy,
  323                              sx,flipy?sy+8:sy,0);
  324                      drawgfx_transpen(bitmap,cliprect,machine().gfx[2],
  325                              code | 2,
  326                              color,
  327                              flipx,flipy,
  328                              sx,flipy?sy:sy+8,0);
  329                  }
  330                  break;
  331  
  332              case 0x0c:  /* 8x8 */
  333                  {
  334                      drawgfx_transpen(bitmap,cliprect,machine().gfx[2],
  335                              code,
  336                              color,
  337                              flipx,flipy,
  338                              sx,sy,0);
  339                  }
  340                  break;
  341          }
  342      }
  343  }
  344  
  345  UINT32 ironhors_state::screen_update_farwest(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
  346  {
  347      int row;
  348  
  349      for (row = 0; row < 32; row++)
  350          m_bg_tilemap->set_scrollx(row, m_scroll[row]);
  351  
  352      m_bg_tilemap->draw(bitmap, cliprect, 0, 0);
  353      farwest_draw_sprites(bitmap, cliprect);
  354      return 0;
  355  }