Previous 199869 Revisions Next

r26063 Saturday 9th November, 2013 at 06:43:52 UTC by Osso
Converted mame/machine/seicop to a device. Eventually it should be merged with emu/machine/seibu_cop. (nw)
[src/mame/drivers]legionna.c
[src/mame/machine]seicop.c seicop.h

trunk/src/mame/machine/seicop.c
r26062r26063
15991599#define seibu_cop_log logerror
16001600#define LOG_CMDS 1
16011601
1602static UINT16 *cop_mcu_ram;
1602const device_type SEIBU_COP_LEGACY = &device_creator<seibu_cop_legacy_device>;
16031603
1604static UINT16 copd2_table[0x100];
1605static UINT16 copd2_table_2[0x100/8];
1606static UINT16 copd2_table_3[0x100/8];
1607static UINT16 copd2_table_4[0x100/8];
1604seibu_cop_legacy_device::seibu_cop_legacy_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
1605   : device_t(mconfig, SEIBU_COP_LEGACY, "Seibu COP Legacy", tag, owner, clock, "seibu_cop_legacy", __FILE__),
1606   m_cop_mcu_ram(NULL),
1607   m_cop_438(0),
1608   m_cop_43a(0),
1609   m_cop_43c(0),
1610   m_cop_dma_fade_table(0),
1611   m_cop_dma_trigger(0),
1612   m_cop_scale(0),
1613   m_cop_rng_max_value(0),
1614   m_copd2_offs(0),
1615   m_cop_status(0),
1616   m_cop_dist(0),
1617   m_cop_angle(0),
1618   m_cop_hit_status(0),
1619   m_cop_hit_val_x(0),
1620   m_cop_hit_val_y(0),
1621   m_cop_hit_val_z(0),
1622   m_cop_hit_val_unk(0),
1623   m_cop_sort_lookup(0),
1624   m_cop_sort_ram_addr(0),
1625   m_cop_sort_param(0),
1626   m_cop_angle_compare(0),
1627   m_cop_angle_mod_val(0),
1628   m_r0(0),
1629   m_r1(0),
1630   m_cop_rom_addr_lo(0),
1631   m_cop_rom_addr_hi(0),
1632   m_cop_rom_addr_unk(0),
1633   m_u1(0),
1634   m_u2(0),
1635   m_fill_val(0),
1636   m_pal_brightness_val(0),
1637   m_pal_brightness_mode(0),
1638   m_cop_sprite_dma_src(0),
1639   m_cop_sprite_dma_abs_x(0),
1640   m_cop_sprite_dma_abs_y(0),
1641   m_cop_sprite_dma_size(0),
1642   m_cop_sprite_dma_param(0)
1643{
1644   memset(m_copd2_table, 0, sizeof(UINT16)*0x100);
1645   memset(m_copd2_table_2, 0, sizeof(UINT16)*0x100/8);
1646   memset(m_copd2_table_3, 0, sizeof(UINT16)*0x100/8);
1647   memset(m_copd2_table_4, 0, sizeof(UINT16)*0x100/8);
1648   memset(m_cop_dma_src, 0, sizeof(UINT16)*0x200);
1649   memset(m_cop_dma_size, 0, sizeof(UINT16)*0x200);
1650   memset(m_cop_dma_dst, 0, sizeof(UINT16)*0x200);
1651   memset(m_seibu_vregs, 0, sizeof(UINT16)*0x50/2);
1652   
1653   for (int i = 0; i < 8; i++)
1654   {
1655      m_cop_register[i] = 0;
1656   }
1657}
16081658
1609static UINT16 cop_438;
1610static UINT16 cop_43a;
1611static UINT16 cop_43c;
1659//-------------------------------------------------
1660//  device_config_complete - perform any
1661//  operations now that the configuration is
1662//  complete
1663//-------------------------------------------------
16121664
1613static UINT16 cop_dma_src[0x200];
1614static UINT16 cop_dma_size[0x200];
1615static UINT16 cop_dma_dst[0x200];
1616static UINT16 cop_dma_fade_table;
1617static UINT16 cop_dma_trigger = 0;
1618static UINT16 cop_scale;
1665void seibu_cop_legacy_device::device_config_complete()
1666{
1667}
16191668
1620static UINT8 cop_rng_max_value;
1669//-------------------------------------------------
1670//  device_start - device-specific startup
1671//-------------------------------------------------
16211672
1622static UINT16 copd2_offs = 0;
1673void seibu_cop_legacy_device::device_start()
1674{
1675   m_cop_mcu_ram = reinterpret_cast<UINT16 *>(machine().root_device().memshare("cop_mcu_ram")->ptr());
1676   
1677   save_item(NAME(m_cop_438));
1678   save_item(NAME(m_cop_43a));
1679   save_item(NAME(m_cop_43c));
1680   save_item(NAME(m_cop_dma_fade_table));
1681   save_item(NAME(m_cop_dma_trigger));
1682   save_item(NAME(m_cop_scale));
1683   save_item(NAME(m_cop_rng_max_value));
1684   save_item(NAME(m_copd2_offs));
1685   save_item(NAME(m_cop_status));
1686   save_item(NAME(m_cop_dist));
1687   save_item(NAME(m_cop_angle));
1688   save_item(NAME(m_cop_hit_status));
1689   save_item(NAME(m_cop_hit_val_x));
1690   save_item(NAME(m_cop_hit_val_y));
1691   save_item(NAME(m_cop_hit_val_z));
1692   save_item(NAME(m_cop_hit_val_unk));
1693   save_item(NAME(m_cop_sort_lookup));
1694   save_item(NAME(m_cop_sort_ram_addr));
1695   save_item(NAME(m_cop_sort_param));
1696   save_item(NAME(m_cop_angle_compare));
1697   save_item(NAME(m_cop_angle_mod_val));
1698   save_item(NAME(m_r0));
1699   save_item(NAME(m_r1));
1700   save_item(NAME(m_cop_rom_addr_lo));
1701   save_item(NAME(m_cop_rom_addr_hi));
1702   save_item(NAME(m_cop_rom_addr_unk));
1703   save_item(NAME(m_u1));
1704   save_item(NAME(m_u2));
1705   save_item(NAME(m_fill_val));
1706   save_item(NAME(m_pal_brightness_val));
1707   save_item(NAME(m_pal_brightness_mode));
1708   save_item(NAME(m_cop_sprite_dma_src));
1709   save_item(NAME(m_cop_sprite_dma_abs_x));
1710   save_item(NAME(m_cop_sprite_dma_abs_y));
1711   save_item(NAME(m_cop_sprite_dma_size));
1712   save_item(NAME(m_cop_sprite_dma_param));
1713   save_item(NAME(m_copd2_table));
1714   save_item(NAME(m_copd2_table_2));
1715   save_item(NAME(m_copd2_table_3));
1716   save_item(NAME(m_copd2_table_4));
1717   save_item(NAME(m_cop_dma_src));
1718   save_item(NAME(m_cop_dma_size));
1719   save_item(NAME(m_cop_dma_dst));
1720   save_item(NAME(m_seibu_vregs));
1721}
16231722
1624static void copd2_set_tableoffset(running_machine &machine, UINT16 data)
1723//-------------------------------------------------
1724//  device_reset - device-specific startup
1725//-------------------------------------------------
1726
1727void seibu_cop_legacy_device::device_reset()
16251728{
1729}
1730
1731void seibu_cop_legacy_device::copd2_set_tableoffset(UINT16 data)
1732{
16261733   //logerror("mcu_offs %04x\n", data);
1627   copd2_offs = data;
1628   if (copd2_offs>0xff)
1734   m_copd2_offs = data;
1735   if (m_copd2_offs>0xff)
16291736   {
16301737      logerror("copd2 offs > 0x100\n");
16311738   }
16321739
1633   copd2_table_2[copd2_offs/8] = cop_438;
1634   copd2_table_3[copd2_offs/8] = cop_43a;
1635   copd2_table_4[copd2_offs/8] = cop_43c;
1740   m_copd2_table_2[m_copd2_offs/8] = m_cop_438;
1741   m_copd2_table_3[m_copd2_offs/8] = m_cop_43a;
1742   m_copd2_table_4[m_copd2_offs/8] = m_cop_43c;
16361743#if 0
16371744
16381745   {
r26062r26063
16421749      fp=fopen(filename, "w+b");
16431750      if (fp)
16441751      {
1645         fwrite(copd2_table_2, 0x200/8, 1, fp);
1752         fwrite(m_copd2_table_2, 0x200/8, 1, fp);
16461753         fclose(fp);
16471754      }
16481755   }
r26062r26063
16531760      fp=fopen(filename, "w+b");
16541761      if (fp)
16551762      {
1656         fwrite(copd2_table_3, 0x200/8, 1, fp);
1763         fwrite(m_copd2_table_3, 0x200/8, 1, fp);
16571764         fclose(fp);
16581765      }
16591766   }
r26062r26063
16641771      fp=fopen(filename, "w+b");
16651772      if (fp)
16661773      {
1667         fwrite(copd2_table_4, 0x200/8, 1, fp);
1774         fwrite(m_copd2_table_4, 0x200/8, 1, fp);
16681775         fclose(fp);
16691776      }
16701777   }
r26062r26063
16771784      for (i=0;i<0x20;i++)
16781785      {
16791786         int ii;
1680         printf("%02x | %01x | %04x | %04x | ", i, copd2_table_2[i], copd2_table_3[i], copd2_table_4[i]);
1787         printf("%02x | %01x | %04x | %04x | ", i, m_copd2_table_2[i], m_copd2_table_3[i], m_copd2_table_4[i]);
16811788
16821789
16831790         for (ii=0;ii<0x8;ii++)
16841791         {
1685            printf("%03x ", copd2_table[i*8 + ii]);
1792            printf("%03x ", m_copd2_table[i*8 + ii]);
16861793
16871794         }
16881795         printf("\n");
r26062r26063
16931800
16941801}
16951802
1696static void copd2_set_tabledata(running_machine &machine, UINT16 data)
1803void seibu_cop_legacy_device::copd2_set_tabledata(UINT16 data)
16971804{
1698   copd2_table[copd2_offs] = data;
1805   m_copd2_table[m_copd2_offs] = data;
16991806
17001807   if(data) {
17011808      int off = data & 31;
17021809      int reg = (data >> 5) & 3;
17031810      int op = (data >> 7) & 31;
17041811
1705      logerror("COPDIS: %04x s=%02x f1=%x l=%x f2=%02x %x %04x %02x %03x %02x.%x.%02x ", cop_43c,  (cop_43c >> 11) << 3, (cop_43c >> 10) & 1, ((cop_43c >> 7) & 7)+1, cop_43c & 0x7f, cop_438, cop_43a, copd2_offs, data, op, reg, off);
1812      logerror("COPDIS: %04x s=%02x f1=%x l=%x f2=%02x %x %04x %02x %03x %02x.%x.%02x ", m_cop_43c,  (m_cop_43c >> 11) << 3, (m_cop_43c >> 10) & 1, ((m_cop_43c >> 7) & 7)+1, m_cop_43c & 0x7f, m_cop_438, m_cop_43a, m_copd2_offs, data, op, reg, off);
17061813
17071814      off *= 2;
17081815
1709      // COPDIS: 0205 s=00 f1=0 l=5 f2=05 6 ffeb 00 188 03.0.08 read32 10(r0)
1710      // COPDIS: 0205 s=00 f1=0 l=5 f2=05 6 ffeb 01 282 05.0.02 add32 4(r0)
1711      // COPDIS: 0205 s=00 f1=0 l=5 f2=05 6 ffeb 02 082 01.0.02 write32 4(r0)
1712      // COPDIS: 0205 s=00 f1=0 l=5 f2=05 6 ffeb 03 b8e 17.0.0e add16h 1c(r0)
1713      // COPDIS: 0205 s=00 f1=0 l=5 f2=05 6 ffeb 04 98e 13.0.0e write16h 1c(r0)
1816      // COPDIS: 0205 s=00 f1=0 l=5 f2=05 6 ffeb 00 188 03.0.08 read32 10(m_r0)
1817      // COPDIS: 0205 s=00 f1=0 l=5 f2=05 6 ffeb 01 282 05.0.02 add32 4(m_r0)
1818      // COPDIS: 0205 s=00 f1=0 l=5 f2=05 6 ffeb 02 082 01.0.02 write32 4(m_r0)
1819      // COPDIS: 0205 s=00 f1=0 l=5 f2=05 6 ffeb 03 b8e 17.0.0e add16h 1c(m_r0)
1820      // COPDIS: 0205 s=00 f1=0 l=5 f2=05 6 ffeb 04 98e 13.0.0e write16h 1c(m_r0)
17141821
17151822      // 188 182 082 b8e 98e -> 04  = 04+04    1ch = 1c+04
17161823      // 188 188 082 b8e 98e -> 04  = 04+10    1ch = 1c+10
r26062r26063
17731880      fp=fopen(filename, "w+b");
17741881      if (fp)
17751882      {
1776         fwrite(copd2_table, 0x200, 1, fp);
1883         fwrite(m_copd2_table, 0x200, 1, fp);
17771884         fclose(fp);
17781885      }
17791886   }
17801887#endif
17811888}
17821889
1783static UINT32 cop_register[8];
1784static UINT16 seibu_vregs[0x50/2];
1785
1786static WRITE16_HANDLER( seibu_common_video_regs_w )
1890WRITE16_MEMBER( seibu_cop_legacy_device::seibu_common_video_regs_w )
17871891{
17881892   legionna_state *state = space.machine().driver_data<legionna_state>();
1789   COMBINE_DATA(&seibu_vregs[offset]);
1893   COMBINE_DATA(&m_seibu_vregs[offset]);
17901894
17911895   switch(offset)
17921896   {
1793      case (0x01a/2): { state->flip_screen_set(seibu_vregs[offset] & 0x01); break; }
1794      case (0x01c/2): { state->m_layer_disable =  seibu_vregs[offset]; break; }
1795      case (0x020/2): { state->m_scrollram16[0] = seibu_vregs[offset]; break; }
1796      case (0x022/2): { state->m_scrollram16[1] = seibu_vregs[offset]; break; }
1797      case (0x024/2): { state->m_scrollram16[2] = seibu_vregs[offset]; break; }
1798      case (0x026/2): { state->m_scrollram16[3] = seibu_vregs[offset]; break; }
1799      case (0x028/2): { state->m_scrollram16[4] = seibu_vregs[offset]; break; }
1800      case (0x02a/2): { state->m_scrollram16[5] = seibu_vregs[offset]; break; }
1897      case (0x01a/2): { state->flip_screen_set(m_seibu_vregs[offset] & 0x01); break; }
1898      case (0x01c/2): { state->m_layer_disable =  m_seibu_vregs[offset]; break; }
1899      case (0x020/2): { state->m_scrollram16[0] = m_seibu_vregs[offset]; break; }
1900      case (0x022/2): { state->m_scrollram16[1] = m_seibu_vregs[offset]; break; }
1901      case (0x024/2): { state->m_scrollram16[2] = m_seibu_vregs[offset]; break; }
1902      case (0x026/2): { state->m_scrollram16[3] = m_seibu_vregs[offset]; break; }
1903      case (0x028/2): { state->m_scrollram16[4] = m_seibu_vregs[offset]; break; }
1904      case (0x02a/2): { state->m_scrollram16[5] = m_seibu_vregs[offset]; break; }
18011905      default: { logerror("seibu_common_video_regs_w unhandled offset %02x %04x\n",offset*2,data); break; }
18021906   }
18031907}
r26062r26063
19192023
19202024 *******************************************************************************************/
19212025
1922// temporary hack until this is a proper device
1923inline void get_ram(running_machine &machine)
1924{
1925   if (cop_mcu_ram == NULL) cop_mcu_ram = reinterpret_cast<UINT16 *>(machine.root_device().memshare("cop_mcu_ram")->ptr());
1926}
19272026
1928READ16_HANDLER( copdxbl_0_r )
2027READ16_MEMBER( seibu_cop_legacy_device::copdxbl_0_r )
19292028{
1930   get_ram(space.machine());
1931   UINT16 retvalue = cop_mcu_ram[offset];
2029   UINT16 retvalue = m_cop_mcu_ram[offset];
19322030
19332031   switch(offset)
19342032   {
r26062r26063
19412039      //case (0x47e/2):
19422040      //case (0x5b0/2):
19432041      //case (0x5b4/2):
1944      //  return cop_mcu_ram[offset];
2042      //  return m_cop_mcu_ram[offset];
19452043
19462044      case (0x700/2): return space.machine().root_device().ioport("DSW1")->read();
19472045      case (0x704/2): return space.machine().root_device().ioport("PLAYERS12")->read();
r26062r26063
19512049   }
19522050}
19532051
1954WRITE16_HANDLER( copdxbl_0_w )
2052WRITE16_MEMBER( seibu_cop_legacy_device::copdxbl_0_w )
19552053{
19562054   legionna_state *state = space.machine().driver_data<legionna_state>();
1957   get_ram(space.machine());
1958   COMBINE_DATA(&cop_mcu_ram[offset]);
2055   COMBINE_DATA(&m_cop_mcu_ram[offset]);
19592056
19602057   switch(offset)
19612058   {
r26062r26063
19662063      }
19672064
19682065      /*TODO: kludge on x-axis.*/
1969      case (0x660/2): { state->m_scrollram16[0] = cop_mcu_ram[offset] - 0x1f0; break; }
1970      case (0x662/2): { state->m_scrollram16[1] = cop_mcu_ram[offset]; break; }
1971      case (0x664/2): { state->m_scrollram16[2] = cop_mcu_ram[offset] - 0x1f0; break; }
1972      case (0x666/2): { state->m_scrollram16[3] = cop_mcu_ram[offset]; break; }
1973      case (0x668/2): { state->m_scrollram16[4] = cop_mcu_ram[offset] - 0x1f0; break; }
1974      case (0x66a/2): { state->m_scrollram16[5] = cop_mcu_ram[offset]; break; }
1975      case (0x66c/2): { state->m_scrollram16[6] = cop_mcu_ram[offset] - 0x1f0; break; }
1976      case (0x66e/2): { state->m_scrollram16[7] = cop_mcu_ram[offset]; break; }
2066      case (0x660/2): { state->m_scrollram16[0] = m_cop_mcu_ram[offset] - 0x1f0; break; }
2067      case (0x662/2): { state->m_scrollram16[1] = m_cop_mcu_ram[offset]; break; }
2068      case (0x664/2): { state->m_scrollram16[2] = m_cop_mcu_ram[offset] - 0x1f0; break; }
2069      case (0x666/2): { state->m_scrollram16[3] = m_cop_mcu_ram[offset]; break; }
2070      case (0x668/2): { state->m_scrollram16[4] = m_cop_mcu_ram[offset] - 0x1f0; break; }
2071      case (0x66a/2): { state->m_scrollram16[5] = m_cop_mcu_ram[offset]; break; }
2072      case (0x66c/2): { state->m_scrollram16[6] = m_cop_mcu_ram[offset] - 0x1f0; break; }
2073      case (0x66e/2): { state->m_scrollram16[7] = m_cop_mcu_ram[offset]; break; }
19772074
19782075      case (0x740/2):
19792076      {
r26062r26063
19902087     which seems common to all the games
19912088*/
19922089
1993static UINT16 cop_status,cop_dist,cop_angle;
1994static UINT16 cop_hit_status;
1995static INT16 cop_hit_val_x,cop_hit_val_y,cop_hit_val_z,cop_hit_val_unk;
1996static UINT32 cop_sort_lookup,cop_sort_ram_addr,cop_sort_param;
1997static INT8 cop_angle_compare;
1998static INT8 cop_angle_mod_val;
1999static struct
2000{
2001   int x,y;
2002   INT16 min_x,min_y,max_x,max_y;
2003   UINT16 hitbox;
2004   UINT16 hitbox_x,hitbox_y;
2005}cop_collision_info[2];
2006static int r0, r1;
2007
2008static UINT16 cop_rom_addr_lo,cop_rom_addr_hi,cop_rom_addr_unk;
2009
20102090/* RE from Seibu Cup Soccer bootleg */
20112091static const UINT8 fade_table(int v)
20122092{
r26062r26063
20162096   return (low * (high | (high >> 5)) + 0x210) >> 10;
20172097}
20182098
2019static UINT16 u1,u2;
20202099
2021#define COP_CMD(_1_,_2_,_3_,_4_,_5_,_6_,_7_,_8_,_u1_,_u2_) \
2022   (copd2_table[command+0] == _1_ && copd2_table[command+1] == _2_ && copd2_table[command+2] == _3_ && copd2_table[command+3] == _4_ && \
2023   copd2_table[command+4] == _5_ && copd2_table[command+5] == _6_ && copd2_table[command+6] == _7_ && copd2_table[command+7] == _8_ && \
2024   u1 == _u1_ && u2 == _u2_)
2100#define COP_CMD(_1_,_2_,_3_,_4_,_5_,_6_,_7_,_8_,_m_u1_,_m_u2_) \
2101   (m_copd2_table[command+0] == _1_ && m_copd2_table[command+1] == _2_ && m_copd2_table[command+2] == _3_ && m_copd2_table[command+3] == _4_ && \
2102   m_copd2_table[command+4] == _5_ && m_copd2_table[command+5] == _6_ && m_copd2_table[command+6] == _7_ && m_copd2_table[command+7] == _8_ && \
2103   m_u1 == _m_u1_ && m_u2 == _m_u2_)
20252104
20262105/*
20272106Godzilla 0x12c0 X = 0x21ed Y = 0x57da
r26062r26063
20402119Y = collides between 0xd0 and 0x30 (not inclusive)
204121200x588 bits 2 & 3 = 0x580 bits 0 & 1
20422121*/
2043static void cop_take_hit_box_params(UINT8 offs)
2122void seibu_cop_legacy_device::cop_take_hit_box_params(UINT8 offs)
20442123{
20452124   INT16 start_x,start_y,height,width;
20462125
20472126   {
2048      height = UINT8(cop_collision_info[offs].hitbox_y >> 8);
2049      start_y = INT8(cop_collision_info[offs].hitbox_y);
2050      width = UINT8(cop_collision_info[offs].hitbox_x >> 8);
2051      start_x = INT8(cop_collision_info[offs].hitbox_x);
2127      height = UINT8(m_cop_collision_info[offs].hitbox_y >> 8);
2128      start_y = INT8(m_cop_collision_info[offs].hitbox_y);
2129      width = UINT8(m_cop_collision_info[offs].hitbox_x >> 8);
2130      start_x = INT8(m_cop_collision_info[offs].hitbox_x);
20522131   }
20532132
2054   cop_collision_info[offs].min_x = (cop_collision_info[offs].x >> 16) + start_x;
2055   cop_collision_info[offs].max_x = cop_collision_info[offs].min_x + width;
2056   cop_collision_info[offs].min_y = (cop_collision_info[offs].y >> 16) + start_y;
2057   cop_collision_info[offs].max_y = cop_collision_info[offs].min_y + height;
2133   m_cop_collision_info[offs].min_x = (m_cop_collision_info[offs].x >> 16) + start_x;
2134   m_cop_collision_info[offs].max_x = m_cop_collision_info[offs].min_x + width;
2135   m_cop_collision_info[offs].min_y = (m_cop_collision_info[offs].y >> 16) + start_y;
2136   m_cop_collision_info[offs].max_y = m_cop_collision_info[offs].min_y + height;
20582137}
20592138
20602139
2061static UINT8 cop_calculate_collsion_detection(running_machine &machine)
2140UINT8 seibu_cop_legacy_device::cop_calculate_collsion_detection()
20622141{
20632142   static UINT8 res;
20642143
20652144   res = 3;
20662145
20672146   /* outbound X check */
2068   if(cop_collision_info[0].max_x >= cop_collision_info[1].min_x && cop_collision_info[0].min_x <= cop_collision_info[1].max_x)
2147   if(m_cop_collision_info[0].max_x >= m_cop_collision_info[1].min_x && m_cop_collision_info[0].min_x <= m_cop_collision_info[1].max_x)
20692148      res &= ~2;
20702149
2071   if(cop_collision_info[1].max_x >= cop_collision_info[0].min_x && cop_collision_info[1].min_x <= cop_collision_info[0].max_x)
2150   if(m_cop_collision_info[1].max_x >= m_cop_collision_info[0].min_x && m_cop_collision_info[1].min_x <= m_cop_collision_info[0].max_x)
20722151      res &= ~2;
20732152
20742153   /* outbound Y check */
2075   if(cop_collision_info[0].max_y >= cop_collision_info[1].min_y && cop_collision_info[0].min_y <= cop_collision_info[1].max_y)
2154   if(m_cop_collision_info[0].max_y >= m_cop_collision_info[1].min_y && m_cop_collision_info[0].min_y <= m_cop_collision_info[1].max_y)
20762155      res &= ~1;
20772156
2078   if(cop_collision_info[1].max_y >= cop_collision_info[0].min_y && cop_collision_info[1].min_y <= cop_collision_info[0].max_y)
2157   if(m_cop_collision_info[1].max_y >= m_cop_collision_info[0].min_y && m_cop_collision_info[1].min_y <= m_cop_collision_info[0].max_y)
20792158      res &= ~1;
20802159
2081   cop_hit_val_x = (cop_collision_info[0].x - cop_collision_info[1].x) >> 16;
2082   cop_hit_val_y = (cop_collision_info[0].y - cop_collision_info[1].y) >> 16;
2083   cop_hit_val_z = 1;
2084   cop_hit_val_unk = res; // TODO: there's also bit 2 and 3 triggered in the tests, no known meaning
2160   m_cop_hit_val_x = (m_cop_collision_info[0].x - m_cop_collision_info[1].x) >> 16;
2161   m_cop_hit_val_y = (m_cop_collision_info[0].y - m_cop_collision_info[1].y) >> 16;
2162   m_cop_hit_val_z = 1;
2163   m_cop_hit_val_unk = res; // TODO: there's also bit 2 and 3 triggered in the tests, no known meaning
20852164
2086   //popmessage("%d %d %04x %04x %04x %04x",cop_hit_val_x,cop_hit_val_y,cop_collision_info[0].hitbox_x,cop_collision_info[0].hitbox_y,cop_collision_info[1].hitbox_x,cop_collision_info[1].hitbox_y);
2165   //popmessage("%d %d %04x %04x %04x %04x",m_cop_hit_val_x,m_cop_hit_val_y,m_cop_collision_info[0].hitbox_x,m_cop_collision_info[0].hitbox_y,m_cop_collision_info[1].hitbox_x,m_cop_collision_info[1].hitbox_y);
20872166
20882167   //if(res == 0)
2089   //popmessage("0:%08x %08x %08x 1:%08x %08x %08x\n",cop_collision_info[0].x,cop_collision_info[0].y,cop_collision_info[0].hitbox,cop_collision_info[1].x,cop_collision_info[1].y,cop_collision_info[1].hitbox);
2090//  popmessage("0:%08x %08x %08x %08x 1:%08x %08x %08x %08x\n",cop_collision_info[0].min_x,cop_collision_info[0].max_x,cop_collision_info[0].min_y, cop_collision_info[0].max_y,
2091//                                                   cop_collision_info[1].min_x,cop_collision_info[1].max_x,cop_collision_info[1].min_y, cop_collision_info[1].max_y);
2168   //popmessage("0:%08x %08x %08x 1:%08x %08x %08x\n",m_cop_collision_info[0].x,m_cop_collision_info[0].y,m_cop_collision_info[0].hitbox,m_cop_collision_info[1].x,m_cop_collision_info[1].y,m_cop_collision_info[1].hitbox);
2169//  popmessage("0:%08x %08x %08x %08x 1:%08x %08x %08x %08x\n",m_cop_collision_info[0].min_x,m_cop_collision_info[0].max_x,m_cop_collision_info[0].min_y, m_cop_collision_info[0].max_y,
2170//                                                   m_cop_collision_info[1].min_x,m_cop_collision_info[1].max_x,m_cop_collision_info[1].min_y, m_cop_collision_info[1].max_y);
20922171
20932172   return res;
20942173}
20952174
2096static READ16_HANDLER( generic_cop_r )
2175READ16_MEMBER( seibu_cop_legacy_device::generic_cop_r )
20972176{
20982177   UINT16 retvalue;
2099   get_ram(space.machine());
2100   retvalue = cop_mcu_ram[offset];
2178   retvalue = m_cop_mcu_ram[offset];
21012179
21022180
21032181   switch (offset)
r26062r26063
21112189         return retvalue;
21122190
21132191      case 0x180/2:
2114         return cop_hit_status;
2192         return m_cop_hit_status;
21152193
21162194      /* these two controls facing direction in Godzilla opponents (only vs.) - x value compare? */
21172195      case 0x182/2:
2118         return (cop_hit_val_y);
2196         return (m_cop_hit_val_y);
21192197
21202198      case 0x184/2:
2121         return (cop_hit_val_x);
2199         return (m_cop_hit_val_x);
21222200
21232201      /* Legionnaire only - z value compare? */
21242202      case 0x186/2:
2125         return (cop_hit_val_z);
2203         return (m_cop_hit_val_z);
21262204
21272205      case 0x188/2:
2128         return cop_hit_val_unk;
2206         return m_cop_hit_val_unk;
21292207
21302208      /* BCD */
21312209      case 0x190/2:
r26062r26063
21402218      case 0x1a2/2:
21412219      case 0x1a4/2:
21422220      case 0x1a6/2:
2143         return space.machine().firstcpu->total_cycles() % (cop_rng_max_value+1);
2221         return space.machine().firstcpu->total_cycles() % (m_cop_rng_max_value+1);
21442222
21452223      case 0x1b0/2:
2146         return cop_status;
2224         return m_cop_status;
21472225
21482226      case 0x1b2/2:
2149         return cop_dist;
2227         return m_cop_dist;
21502228
21512229      case 0x1b4/2:
2152         return cop_angle;
2230         return m_cop_angle;
21532231
21542232      default:
21552233         seibu_cop_log("%06x: COPX unhandled read returning %04x from offset %04x\n", space.device().safe_pc(), retvalue, offset*2);
r26062r26063
21572235   }
21582236}
21592237
2160static UINT32 fill_val;
2161static UINT8 pal_brightness_val,pal_brightness_mode;
2162static UINT32 cop_sprite_dma_src;
2163static int cop_sprite_dma_abs_x,cop_sprite_dma_abs_y,cop_sprite_dma_size;
2164static UINT32 cop_sprite_dma_param;
2165
2166static WRITE16_HANDLER( generic_cop_w )
2238WRITE16_MEMBER( seibu_cop_legacy_device::generic_cop_w )
21672239{
21682240   UINT32 temp32;
2169   get_ram(space.machine());
2170
2241   
21712242   switch (offset)
21722243   {
21732244      default:
r26062r26063
21772248      /* Sprite DMA */
21782249      case (0x000/2):
21792250      case (0x002/2):
2180         cop_sprite_dma_param = (cop_mcu_ram[0x000/2]) | (cop_mcu_ram[0x002/2] << 16);
2181         //popmessage("%08x",cop_sprite_dma_param & 0xffffffc0);
2251         m_cop_sprite_dma_param = (m_cop_mcu_ram[0x000/2]) | (m_cop_mcu_ram[0x002/2] << 16);
2252         //popmessage("%08x",m_cop_sprite_dma_param & 0xffffffc0);
21822253         break;
21832254
2184      case (0x00c/2): { cop_sprite_dma_size = cop_mcu_ram[offset]; break; }
2255      case (0x00c/2): { m_cop_sprite_dma_size = m_cop_mcu_ram[offset]; break; }
21852256      case (0x010/2):
21862257      {
21872258         if(data)
r26062r26063
21892260         else
21902261         {
21912262            /* guess */
2192            cop_register[4]+=8;
2193            cop_sprite_dma_src+=6;
2263            m_cop_register[4]+=8;
2264            m_cop_sprite_dma_src+=6;
21942265
2195            cop_sprite_dma_size--;
2266            m_cop_sprite_dma_size--;
21962267
2197            if(cop_sprite_dma_size > 0)
2198               cop_status &= ~2;
2268            if(m_cop_sprite_dma_size > 0)
2269               m_cop_status &= ~2;
21992270            else
2200               cop_status |= 2;
2271               m_cop_status |= 2;
22012272         }
22022273         break;
22032274      }
22042275
22052276      case (0x012/2):
22062277      case (0x014/2):
2207         cop_sprite_dma_src = (cop_mcu_ram[0x014/2]) | (cop_mcu_ram[0x012/2] << 16);
2278         m_cop_sprite_dma_src = (m_cop_mcu_ram[0x014/2]) | (m_cop_mcu_ram[0x012/2] << 16);
22082279         break;
22092280
22102281      /* triggered before 0x6200 in Seibu Cup, looks like an angle value ... */
2211      case (0x01c/2): cop_angle_compare = INT8(cop_mcu_ram[0x1c/2]);  break;
2212      case (0x01e/2): cop_angle_mod_val = INT8(cop_mcu_ram[0x1e/2]); break;
2282      case (0x01c/2): m_cop_angle_compare = INT8(m_cop_mcu_ram[0x1c/2]);  break;
2283      case (0x01e/2): m_cop_angle_mod_val = INT8(m_cop_mcu_ram[0x1e/2]); break;
22132284
22142285      /* BCD Protection */
22152286      case (0x020/2):
22162287      case (0x022/2):
2217         temp32 = (cop_mcu_ram[0x020/2]) | (cop_mcu_ram[0x022/2] << 16);
2218         cop_mcu_ram[0x190/2] = (((temp32 / 1) % 10) + (((temp32 / 10) % 10) << 8) + 0x3030);
2219         cop_mcu_ram[0x192/2] = (((temp32 / 100) % 10) + (((temp32 / 1000) % 10) << 8) + 0x3030);
2220         cop_mcu_ram[0x194/2] = (((temp32 / 10000) % 10) + (((temp32 / 100000) % 10) << 8) + 0x3030);
2221         cop_mcu_ram[0x196/2] = (((temp32 / 1000000) % 10) + (((temp32 / 10000000) % 10) << 8) + 0x3030);
2222         cop_mcu_ram[0x198/2] = (((temp32 / 100000000) % 10) + (((temp32 / 1000000000) % 10) << 8) + 0x3030);
2288         temp32 = (m_cop_mcu_ram[0x020/2]) | (m_cop_mcu_ram[0x022/2] << 16);
2289         m_cop_mcu_ram[0x190/2] = (((temp32 / 1) % 10) + (((temp32 / 10) % 10) << 8) + 0x3030);
2290         m_cop_mcu_ram[0x192/2] = (((temp32 / 100) % 10) + (((temp32 / 1000) % 10) << 8) + 0x3030);
2291         m_cop_mcu_ram[0x194/2] = (((temp32 / 10000) % 10) + (((temp32 / 100000) % 10) << 8) + 0x3030);
2292         m_cop_mcu_ram[0x196/2] = (((temp32 / 1000000) % 10) + (((temp32 / 10000000) % 10) << 8) + 0x3030);
2293         m_cop_mcu_ram[0x198/2] = (((temp32 / 100000000) % 10) + (((temp32 / 1000000000) % 10) << 8) + 0x3030);
22232294         break;
22242295      case (0x024/2):
22252296         /*
r26062r26063
22322303
22332304      case (0x028/2):
22342305      case (0x02a/2):
2235         fill_val = (cop_mcu_ram[0x028/2]) | (cop_mcu_ram[0x02a/2] << 16);
2306         m_fill_val = (m_cop_mcu_ram[0x028/2]) | (m_cop_mcu_ram[0x02a/2] << 16);
22362307         break;
22372308
22382309      /* max possible value returned by the RNG at 0x5a*, trusted */
2239      case (0x02c/2): cop_rng_max_value = cop_mcu_ram[0x2c/2] & 0xff; break;
2310      case (0x02c/2): m_cop_rng_max_value = m_cop_mcu_ram[0x2c/2] & 0xff; break;
22402311
22412312      /* Command tables for 0x500 / 0x502 commands */
2242      case (0x032/2): { copd2_set_tabledata(space.machine(), data); break; }
2243      case (0x034/2): { copd2_set_tableoffset(space.machine(), data); break; }
2244      case (0x038/2): { cop_438 = data; break; }
2245      case (0x03a/2): { cop_43a = data; break; }
2246      case (0x03c/2): { cop_43c = data; break; }
2313      case (0x032/2): { copd2_set_tabledata(data); break; }
2314      case (0x034/2): { copd2_set_tableoffset(data); break; }
2315      case (0x038/2): { m_cop_438 = data; break; }
2316      case (0x03a/2): { m_cop_43a = data; break; }
2317      case (0x03c/2): { m_cop_43c = data; break; }
22472318      case (0x03e/2):
22482319         /*
22492320         0 in all 68k based games
r26062r26063
22532324         */
22542325         break;
22552326
2256      case (0x044/2): { cop_scale = data & 3; break; }
2257      case (0x046/2): { cop_rom_addr_unk = data & 0xffff; break; }
2258      case (0x048/2): { cop_rom_addr_lo = data & 0xffff; break; }
2259      case (0x04a/2): { cop_rom_addr_hi = data & 0xffff; break; }
2327      case (0x044/2): { m_cop_scale = data & 3; break; }
2328      case (0x046/2): { m_cop_rom_addr_unk = data & 0xffff; break; }
2329      case (0x048/2): { m_cop_rom_addr_lo = data & 0xffff; break; }
2330      case (0x04a/2): { m_cop_rom_addr_hi = data & 0xffff; break; }
22602331
22612332      /* brightness control */
2262      case (0x05a/2): pal_brightness_val = data & 0xff; break;
2263      case (0x05c/2): pal_brightness_mode = data & 0xff; break;
2333      case (0x05a/2): m_pal_brightness_val = data & 0xff; break;
2334      case (0x05c/2): m_pal_brightness_mode = data & 0xff; break;
22642335
22652336      /* DMA / layer clearing section */
22662337      case (0x074/2):
r26062r26063
22772348
22782349      /* used in palette DMAs, for fading effects */
22792350      case (0x076/2):
2280         cop_dma_fade_table = data;
2351         m_cop_dma_fade_table = data;
22812352         break;
22822353
22832354      case (0x078/2): /* DMA source address */
22842355      {
2285         cop_dma_src[cop_dma_trigger] = data; // << 6 to get actual address
2356         m_cop_dma_src[m_cop_dma_trigger] = data; // << 6 to get actual address
22862357         //seibu_cop_log("%06x: COPX set layer clear address to %04x (actual %08x)\n", space.device().safe_pc(), data, data<<6);
22872358         break;
22882359      }
22892360
22902361      case (0x07a/2): /* DMA length */
22912362      {
2292         cop_dma_size[cop_dma_trigger] = data;
2363         m_cop_dma_size[m_cop_dma_trigger] = data;
22932364         //seibu_cop_log("%06x: COPX set layer clear length to %04x (actual %08x)\n", space.device().safe_pc(), data, data<<5);
22942365         break;
22952366      }
22962367
22972368      case (0x07c/2): /* DMA destination */
22982369      {
2299         cop_dma_dst[cop_dma_trigger] = data;
2370         m_cop_dma_dst[m_cop_dma_trigger] = data;
23002371         //seibu_cop_log("%06x: COPX set layer clear value to %04x (actual %08x)\n", space.device().safe_pc(), data, data<<6);
23012372         break;
23022373      }
23032374
23042375      case (0x07e/2): /* DMA parameter */
23052376      {
2306         cop_dma_trigger = data;
2377         m_cop_dma_trigger = data;
23072378         //seibu_cop_log("%06x: COPX set layer clear trigger? to %04x\n", space.device().safe_pc(), data);
23082379         if (data>=0x1ff)
23092380         {
23102381            seibu_cop_log("invalid DMA trigger!, >0x1ff\n");
2311            cop_dma_trigger = 0;
2382            m_cop_dma_trigger = 0;
23122383         }
23132384
23142385         break;
23152386      }
23162387
2317      case (0x08c/2): cop_sprite_dma_abs_y = (cop_mcu_ram[0x08c/2]); break;
2318      case (0x08e/2): cop_sprite_dma_abs_x = (cop_mcu_ram[0x08e/2]); break;
2388      case (0x08c/2): m_cop_sprite_dma_abs_y = (m_cop_mcu_ram[0x08c/2]); break;
2389      case (0x08e/2): m_cop_sprite_dma_abs_x = (m_cop_mcu_ram[0x08e/2]); break;
23192390
23202391      /* Registers */
2321      case (0x0a0/2): { cop_register[0] = (cop_register[0]&0x0000ffff)|(cop_mcu_ram[offset]<<16); break; }
2322      case (0x0c0/2): { cop_register[0] = (cop_register[0]&0xffff0000)|(cop_mcu_ram[offset]<<0);  break; }
2392      case (0x0a0/2): { m_cop_register[0] = (m_cop_register[0]&0x0000ffff)|(m_cop_mcu_ram[offset]<<16); break; }
2393      case (0x0c0/2): { m_cop_register[0] = (m_cop_register[0]&0xffff0000)|(m_cop_mcu_ram[offset]<<0);  break; }
23232394
2324      case (0x0a2/2): { cop_register[1] = (cop_register[1]&0x0000ffff)|(cop_mcu_ram[offset]<<16); break; }
2325      case (0x0c2/2): { cop_register[1] = (cop_register[1]&0xffff0000)|(cop_mcu_ram[offset]<<0);  break; }
2395      case (0x0a2/2): { m_cop_register[1] = (m_cop_register[1]&0x0000ffff)|(m_cop_mcu_ram[offset]<<16); break; }
2396      case (0x0c2/2): { m_cop_register[1] = (m_cop_register[1]&0xffff0000)|(m_cop_mcu_ram[offset]<<0);  break; }
23262397
2327      case (0x0a4/2): { cop_register[2] = (cop_register[2]&0x0000ffff)|(cop_mcu_ram[offset]<<16); break; }
2328      case (0x0c4/2): { cop_register[2] = (cop_register[2]&0xffff0000)|(cop_mcu_ram[offset]<<0);  break; }
2398      case (0x0a4/2): { m_cop_register[2] = (m_cop_register[2]&0x0000ffff)|(m_cop_mcu_ram[offset]<<16); break; }
2399      case (0x0c4/2): { m_cop_register[2] = (m_cop_register[2]&0xffff0000)|(m_cop_mcu_ram[offset]<<0);  break; }
23292400
2330      case (0x0a6/2): { cop_register[3] = (cop_register[3]&0x0000ffff)|(cop_mcu_ram[offset]<<16); break; }
2331      case (0x0c6/2): { cop_register[3] = (cop_register[3]&0xffff0000)|(cop_mcu_ram[offset]<<0);  break; }
2401      case (0x0a6/2): { m_cop_register[3] = (m_cop_register[3]&0x0000ffff)|(m_cop_mcu_ram[offset]<<16); break; }
2402      case (0x0c6/2): { m_cop_register[3] = (m_cop_register[3]&0xffff0000)|(m_cop_mcu_ram[offset]<<0);  break; }
23322403
2333      case (0x0a8/2): { cop_register[4] = (cop_register[4]&0x0000ffff)|(cop_mcu_ram[offset]<<16); break; }
2334      case (0x0c8/2): { cop_register[4] = (cop_register[4]&0xffff0000)|(cop_mcu_ram[offset]<<0);  break; }
2404      case (0x0a8/2): { m_cop_register[4] = (m_cop_register[4]&0x0000ffff)|(m_cop_mcu_ram[offset]<<16); break; }
2405      case (0x0c8/2): { m_cop_register[4] = (m_cop_register[4]&0xffff0000)|(m_cop_mcu_ram[offset]<<0);  break; }
23352406
2336      case (0x0aa/2): { cop_register[5] = (cop_register[5]&0x0000ffff)|(cop_mcu_ram[offset]<<16); break; }
2337      case (0x0ca/2): { cop_register[5] = (cop_register[5]&0xffff0000)|(cop_mcu_ram[offset]<<0);  break; }
2407      case (0x0aa/2): { m_cop_register[5] = (m_cop_register[5]&0x0000ffff)|(m_cop_mcu_ram[offset]<<16); break; }
2408      case (0x0ca/2): { m_cop_register[5] = (m_cop_register[5]&0xffff0000)|(m_cop_mcu_ram[offset]<<0);  break; }
23382409
2339      case (0x0ac/2): { cop_register[6] = (cop_register[6]&0x0000ffff)|(cop_mcu_ram[offset]<<16); break; }
2340      case (0x0cc/2): { cop_register[6] = (cop_register[6]&0xffff0000)|(cop_mcu_ram[offset]<<0);  break; }
2410      case (0x0ac/2): { m_cop_register[6] = (m_cop_register[6]&0x0000ffff)|(m_cop_mcu_ram[offset]<<16); break; }
2411      case (0x0cc/2): { m_cop_register[6] = (m_cop_register[6]&0xffff0000)|(m_cop_mcu_ram[offset]<<0);  break; }
23412412
23422413
23432414      case (0x100/2):
r26062r26063
23482419         int command;
23492420
23502421         #if LOG_CMDS
2351         seibu_cop_log("%06x: COPX execute table macro command %04x %04x | regs %08x %08x %08x %08x %08x\n", space.device().safe_pc(), data, cop_mcu_ram[offset], cop_register[0], cop_register[1], cop_register[2], cop_register[3], cop_register[4]);
2422         seibu_cop_log("%06x: COPX execute table macro command %04x %04x | regs %08x %08x %08x %08x %08x\n", space.device().safe_pc(), data, m_cop_mcu_ram[offset], m_cop_register[0], m_cop_register[1], m_cop_register[2], m_cop_register[3], m_cop_register[4]);
23522423         #endif
23532424
23542425         command = -1;
r26062r26063
23582429            it isn't supposed to do anything, especially in the former case (it definitely NEEDS that sprites have an arc movement when they are knocked down). */
23592430         for (i=0;i<32;i++)
23602431         {
2361            if ((cop_mcu_ram[offset] & 0xff00) == (copd2_table_4[i] & 0xff00))
2432            if ((m_cop_mcu_ram[offset] & 0xff00) == (m_copd2_table_4[i] & 0xff00))
23622433            {
23632434               #if LOG_CMDS
2364               seibu_cop_log("    Cop Command %04x found in slot %02x with other params %04x %04x\n", cop_mcu_ram[offset], i, copd2_table_2[i], copd2_table_3[i]);
2435               seibu_cop_log("    Cop Command %04x found in slot %02x with other params %04x %04x\n", m_cop_mcu_ram[offset], i, m_copd2_table_2[i], m_copd2_table_3[i]);
23652436               #endif
23662437
2367               u1 = copd2_table_2[i] & 0x000f;
2368               u2 = copd2_table_3[i] & 0xffff;
2438               m_u1 = m_copd2_table_2[i] & 0x000f;
2439               m_u2 = m_copd2_table_3[i] & 0xffff;
23692440               command = i;
23702441            }
23712442         }
23722443
23732444         if (command==-1)
23742445         {
2375            seibu_cop_log("    Cop Command %04x NOT IN TABLE!\n", cop_mcu_ram[offset]);
2446            seibu_cop_log("    Cop Command %04x NOT IN TABLE!\n", m_cop_mcu_ram[offset]);
23762447            break;
23772448         }
23782449         else
r26062r26063
23842455               seibu_cop_log("     Sequence: ");
23852456               for (j=0;j<0x8;j++)
23862457               {
2387                  seibu_cop_log("%04x ", copd2_table[command+j]);
2458                  seibu_cop_log("%04x ", m_copd2_table[command+j]);
23882459               }
23892460               seibu_cop_log("\n");
23902461            }
23912462            #endif
23922463         }
23932464
2394         //printf("%04x %04x %04x\n",cop_mcu_ram[offset],u1,u2);
2465         //printf("%04x %04x %04x\n",m_cop_mcu_ram[offset],m_u1,m_u2);
23952466
23962467         /*
23972468         Macro notes:
r26062r26063
24152486
24162487            offs = (offset & 3) * 4;
24172488
2418            space.write_dword(cop_register[0] + 0x04 + offs, space.read_dword(cop_register[0] + 0x04 + offs) + space.read_dword(cop_register[0] + 0x10 + offs));
2419            space.write_dword(cop_register[0] + 0x1c + offs, space.read_dword(cop_register[0] + 0x10 + offs) + space.read_dword(cop_register[0] + 0x1c + offs));
2489            space.write_dword(m_cop_register[0] + 0x04 + offs, space.read_dword(m_cop_register[0] + 0x04 + offs) + space.read_dword(m_cop_register[0] + 0x10 + offs));
2490            space.write_dword(m_cop_register[0] + 0x1c + offs, space.read_dword(m_cop_register[0] + 0x10 + offs) + space.read_dword(m_cop_register[0] + 0x1c + offs));
24202491            return;
24212492         }
24222493
r26062r26063
24312502            /* add 0x10 + offs */
24322503            /* write 0x10 + offs */
24332504
2434            space.write_dword(cop_register[0] + 0x10 + offs, space.read_dword(cop_register[0] + 0x10 + offs) + space.read_dword(cop_register[0] + 0x28 + offs));
2505            space.write_dword(m_cop_register[0] + 0x10 + offs, space.read_dword(m_cop_register[0] + 0x10 + offs) + space.read_dword(m_cop_register[0] + 0x28 + offs));
24352506            return;
24362507         }
24372508
r26062r26063
24492520         */
24502521         if(COP_CMD(0xb9a,0xb88,0x888,0x000,0x000,0x000,0x000,0x000,7,0xfdfb))
24512522         {
2452            int raw_angle = (space.read_word(cop_register[0]+(0x34^2)) & 0xff);
2523            int raw_angle = (space.read_word(m_cop_register[0]+(0x34^2)) & 0xff);
24532524            double angle = raw_angle * M_PI / 128;
2454            double amp = (65536 >> 5)*(space.read_word(cop_register[0]+(0x36^2)) & 0xff);
2525            double amp = (65536 >> 5)*(space.read_word(m_cop_register[0]+(0x36^2)) & 0xff);
24552526            int res;
24562527
24572528            /* TODO: up direction, why? */
24582529            if(raw_angle == 0xc0)
24592530               amp*=2;
24602531
2461            res = int(amp*sin(angle)) << cop_scale;
2532            res = int(amp*sin(angle)) << m_cop_scale;
24622533
2463            space.write_dword(cop_register[0] + 0x10, res);
2534            space.write_dword(m_cop_register[0] + 0x10, res);
24642535            return;
24652536         }
24662537
r26062r26063
24782549         */
24792550         if(COP_CMD(0xb9a,0xb8a,0x88a,0x000,0x000,0x000,0x000,0x000,7,0xfdfb))
24802551         {
2481            int raw_angle = (space.read_word(cop_register[0]+(0x34^2)) & 0xff);
2552            int raw_angle = (space.read_word(m_cop_register[0]+(0x34^2)) & 0xff);
24822553            double angle = raw_angle * M_PI / 128;
2483            double amp = (65536 >> 5)*(space.read_word(cop_register[0]+(0x36^2)) & 0xff);
2554            double amp = (65536 >> 5)*(space.read_word(m_cop_register[0]+(0x36^2)) & 0xff);
24842555            int res;
24852556
24862557            /* TODO: left direction, why? */
24872558            if(raw_angle == 0x80)
24882559               amp*=2;
24892560
2490            res = int(amp*cos(angle)) << cop_scale;
2561            res = int(amp*cos(angle)) << m_cop_scale;
24912562
2492            space.write_dword(cop_register[0] + 20, res);
2563            space.write_dword(m_cop_register[0] + 20, res);
24932564            return;
24942565         }
24952566
24962567         /* 0x130e / 0x138e */
24972568         if(COP_CMD(0x984,0xaa4,0xd82,0xaa2,0x39b,0xb9a,0xb9a,0xa9a,5,0xbf7f))
24982569         {
2499            int dy = space.read_dword(cop_register[1]+4) - space.read_dword(cop_register[0]+4);
2500            int dx = space.read_dword(cop_register[1]+8) - space.read_dword(cop_register[0]+8);
2570            int dy = space.read_dword(m_cop_register[1]+4) - space.read_dword(m_cop_register[0]+4);
2571            int dx = space.read_dword(m_cop_register[1]+8) - space.read_dword(m_cop_register[0]+8);
25012572
2502            cop_status = 7;
2573            m_cop_status = 7;
25032574            if(!dx) {
2504               cop_status |= 0x8000;
2505               cop_angle = 0;
2575               m_cop_status |= 0x8000;
2576               m_cop_angle = 0;
25062577            } else {
2507               cop_angle = atan(double(dy)/double(dx)) * 128.0 / M_PI;
2578               m_cop_angle = atan(double(dy)/double(dx)) * 128.0 / M_PI;
25082579               if(dx<0)
2509                  cop_angle += 0x80;
2580                  m_cop_angle += 0x80;
25102581            }
25112582
2512            r0 = dy;
2513            r1 = dx;
2583            m_r0 = dy;
2584            m_r1 = dx;
25142585
2515            //printf("%d %d %f %04x\n",dx,dy,atan(double(dy)/double(dx)) * 128 / M_PI,cop_angle);
2586            //printf("%d %d %f %04x\n",dx,dy,atan(double(dy)/double(dx)) * 128 / M_PI,m_cop_angle);
25162587
2517            if(cop_mcu_ram[offset] & 0x80)
2518               space.write_word(cop_register[0]+(0x34^2), cop_angle);
2588            if(m_cop_mcu_ram[offset] & 0x80)
2589               space.write_word(m_cop_register[0]+(0x34^2), m_cop_angle);
25192590            return;
25202591         }
25212592
r26062r26063
25232594         //(heatbrl)  | 5 | bf7f | 138e | 984 aa4 d82 aa2 39b b9a b9a b9a
25242595         if(COP_CMD(0x984,0xaa4,0xd82,0xaa2,0x39b,0xb9a,0xb9a,0xb9a,5,0xbf7f))
25252596         {
2526            int dy = space.read_dword(cop_register[1]+4) - space.read_dword(cop_register[0]+4);
2527            int dx = space.read_dword(cop_register[1]+8) - space.read_dword(cop_register[0]+8);
2597            int dy = space.read_dword(m_cop_register[1]+4) - space.read_dword(m_cop_register[0]+4);
2598            int dx = space.read_dword(m_cop_register[1]+8) - space.read_dword(m_cop_register[0]+8);
25282599
2529            cop_status = 7;
2600            m_cop_status = 7;
25302601            if(!dx) {
2531               cop_status |= 0x8000;
2532               cop_angle = 0;
2602               m_cop_status |= 0x8000;
2603               m_cop_angle = 0;
25332604            } else {
2534               cop_angle = atan(double(dy)/double(dx)) * 128.0 / M_PI;
2605               m_cop_angle = atan(double(dy)/double(dx)) * 128.0 / M_PI;
25352606               if(dx<0)
2536                  cop_angle += 0x80;
2607                  m_cop_angle += 0x80;
25372608            }
25382609
2539            r0 = dy;
2540            r1 = dx;
2610            m_r0 = dy;
2611            m_r1 = dx;
25412612
2542            if(cop_mcu_ram[offset] & 0x80)
2543               space.write_word(cop_register[0]+(0x34^2), cop_angle);
2613            if(m_cop_mcu_ram[offset] & 0x80)
2614               space.write_word(m_cop_register[0]+(0x34^2), m_cop_angle);
25442615            return;
25452616         }
25462617
r26062r26063
25542625         */
25552626         if(COP_CMD(0xf9c,0xb9c,0xb9c,0xb9c,0xb9c,0xb9c,0xb9c,0x99c,4,0x007f))
25562627         {
2557            int dy = r0;
2558            int dx = r1;
2628            int dy = m_r0;
2629            int dx = m_r1;
25592630
25602631            dx >>= 16;
25612632            dy >>= 16;
2562            cop_dist = sqrt((double)(dx*dx+dy*dy));
2633            m_cop_dist = sqrt((double)(dx*dx+dy*dy));
25632634
2564            if(cop_mcu_ram[offset] & 0x80)
2565               space.write_word(cop_register[0]+(0x38), cop_dist);
2635            if(m_cop_mcu_ram[offset] & 0x80)
2636               space.write_word(m_cop_register[0]+(0x38), m_cop_dist);
25662637            return;
25672638         }
25682639
r26062r26063
25792650         */
25802651         if(COP_CMD(0xf9a,0xb9a,0xb9c,0xb9c,0xb9c,0x29c,0x000,0x000,5,0xfcdd))
25812652         {
2582            int dy = r0;
2583            int dx = r1;
2584            int div = space.read_word(cop_register[0]+(0x36^2));
2653            int dy = m_r0;
2654            int dx = m_r1;
2655            int div = space.read_word(m_cop_register[0]+(0x36^2));
25852656            int res;
2586            int cop_dist_raw;
2657            int m_cop_dist_raw;
25872658
25882659            if(!div)
25892660            {
r26062r26063
25922663            }
25932664
25942665            /* TODO: calculation of this one should occur at 0x3b30/0x3bb0 I *think* */
2595            /* TODO: recheck if cop_scale still masks at 3 with this command */
2596            dx >>= 11 + cop_scale;
2597            dy >>= 11 + cop_scale;
2598            cop_dist_raw = sqrt((double)(dx*dx+dy*dy));
2666            /* TODO: recheck if m_cop_scale still masks at 3 with this command */
2667            dx >>= 11 + m_cop_scale;
2668            dy >>= 11 + m_cop_scale;
2669            m_cop_dist_raw = sqrt((double)(dx*dx+dy*dy));
25992670
2600            res = cop_dist_raw;
2671            res = m_cop_dist_raw;
26012672            res /= div;
26022673
2603            cop_dist = (1 << (5 - cop_scale)) / div;
2674            m_cop_dist = (1 << (5 - m_cop_scale)) / div;
26042675
26052676            /* TODO: bits 5-6-15 */
2606            cop_status = 7;
2677            m_cop_status = 7;
26072678
2608            space.write_word(cop_register[0]+(0x38^2), res);
2679            space.write_word(m_cop_register[0]+(0x38^2), res);
26092680            return;
26102681         }
26112682
26122683         /*
26132684             collision detection:
26142685
2615             int dy_0 = space.read_dword(cop_register[0]+4);
2616             int dx_0 = space.read_dword(cop_register[0]+8);
2617             int dy_1 = space.read_dword(cop_register[1]+4);
2618             int dx_1 = space.read_dword(cop_register[1]+8);
2619             int hitbox_param1 = space.read_dword(cop_register[2]);
2620             int hitbox_param2 = space.read_dword(cop_register[3]);
2686             int dy_0 = space.read_dword(m_cop_register[0]+4);
2687             int dx_0 = space.read_dword(m_cop_register[0]+8);
2688             int dy_1 = space.read_dword(m_cop_register[1]+4);
2689             int dx_1 = space.read_dword(m_cop_register[1]+8);
2690             int hitbox_param1 = space.read_dword(m_cop_register[2]);
2691             int hitbox_param2 = space.read_dword(m_cop_register[3]);
26212692
2622             TODO: we are ignoring the u1 / u2 params for now
2693             TODO: we are ignoring the m_u1 / m_u2 params for now
26232694         */
26242695
2625         if(COP_CMD(0xb80,0xb82,0xb84,0xb86,0x000,0x000,0x000,0x000,u1,u2))
2696         if(COP_CMD(0xb80,0xb82,0xb84,0xb86,0x000,0x000,0x000,0x000,m_u1,m_u2))
26262697         {
2627            cop_collision_info[0].y = (space.read_dword(cop_register[0]+4));
2628            cop_collision_info[0].x = (space.read_dword(cop_register[0]+8));
2698            m_cop_collision_info[0].y = (space.read_dword(m_cop_register[0]+4));
2699            m_cop_collision_info[0].x = (space.read_dword(m_cop_register[0]+8));
26292700            return;
26302701         }
26312702
26322703         //(heatbrl)  | 9 | ffff | b080 | b40 bc0 bc2
2633         if(COP_CMD(0xb40,0xbc0,0xbc2,0x000,0x000,0x000,0x000,0x000,u1,u2))
2704         if(COP_CMD(0xb40,0xbc0,0xbc2,0x000,0x000,0x000,0x000,0x000,m_u1,m_u2))
26342705         {
2635            cop_collision_info[0].hitbox = space.read_word(cop_register[2]);
2636            cop_collision_info[0].hitbox_y = space.read_word((cop_register[2]&0xffff0000)|(cop_collision_info[0].hitbox));
2637            cop_collision_info[0].hitbox_x = space.read_word(((cop_register[2]&0xffff0000)|(cop_collision_info[0].hitbox))+2);
2706            m_cop_collision_info[0].hitbox = space.read_word(m_cop_register[2]);
2707            m_cop_collision_info[0].hitbox_y = space.read_word((m_cop_register[2]&0xffff0000)|(m_cop_collision_info[0].hitbox));
2708            m_cop_collision_info[0].hitbox_x = space.read_word(((m_cop_register[2]&0xffff0000)|(m_cop_collision_info[0].hitbox))+2);
26382709
26392710            /* do the math */
26402711            cop_take_hit_box_params(0);
2641            cop_hit_status = cop_calculate_collsion_detection(space.machine());
2712            m_cop_hit_status = cop_calculate_collsion_detection();
26422713
26432714            return;
26442715         }
26452716
2646         if(COP_CMD(0xba0,0xba2,0xba4,0xba6,0x000,0x000,0x000,0x000,u1,u2))
2717         if(COP_CMD(0xba0,0xba2,0xba4,0xba6,0x000,0x000,0x000,0x000,m_u1,m_u2))
26472718         {
2648            cop_collision_info[1].y = (space.read_dword(cop_register[1]+4));
2649            cop_collision_info[1].x = (space.read_dword(cop_register[1]+8));
2719            m_cop_collision_info[1].y = (space.read_dword(m_cop_register[1]+4));
2720            m_cop_collision_info[1].x = (space.read_dword(m_cop_register[1]+8));
26502721            return;
26512722         }
26522723
26532724         //(heatbrl)  | 6 | ffff | b880 | b60 be0 be2
2654         if(COP_CMD(0xb60,0xbe0,0xbe2,0x000,0x000,0x000,0x000,0x000,u1,u2))
2725         if(COP_CMD(0xb60,0xbe0,0xbe2,0x000,0x000,0x000,0x000,0x000,m_u1,m_u2))
26552726         {
2656            cop_collision_info[1].hitbox = space.read_word(cop_register[3]);
2657            cop_collision_info[1].hitbox_y = space.read_word((cop_register[3]&0xffff0000)|(cop_collision_info[1].hitbox));
2658            cop_collision_info[1].hitbox_x = space.read_word(((cop_register[3]&0xffff0000)|(cop_collision_info[1].hitbox))+2);
2727            m_cop_collision_info[1].hitbox = space.read_word(m_cop_register[3]);
2728            m_cop_collision_info[1].hitbox_y = space.read_word((m_cop_register[3]&0xffff0000)|(m_cop_collision_info[1].hitbox));
2729            m_cop_collision_info[1].hitbox_x = space.read_word(((m_cop_register[3]&0xffff0000)|(m_cop_collision_info[1].hitbox))+2);
26592730
26602731            /* do the math */
26612732            cop_take_hit_box_params(1);
2662            cop_hit_status = cop_calculate_collsion_detection(space.machine());
2733            m_cop_hit_status = cop_calculate_collsion_detection();
26632734            return;
26642735         }
26652736
r26062r26063
26722743            offs = (offset & 3) * 4;
26732744
26742745            /* TODO: I really suspect that following two are actually taken from the 0xa180 macro command then internally loaded */
2675            abs_x = space.read_word(cop_register[0] + 8) - cop_sprite_dma_abs_x;
2676            abs_y = space.read_word(cop_register[0] + 4) - cop_sprite_dma_abs_y;
2677            rel_xy = space.read_word(cop_sprite_dma_src + 4 + offs);
2746            abs_x = space.read_word(m_cop_register[0] + 8) - m_cop_sprite_dma_abs_x;
2747            abs_y = space.read_word(m_cop_register[0] + 4) - m_cop_sprite_dma_abs_y;
2748            rel_xy = space.read_word(m_cop_sprite_dma_src + 4 + offs);
26782749
26792750            //if(rel_xy & 0x0706)
26802751            //  printf("sprite rel_xy = %04x\n",rel_xy);
26812752
26822753            if(rel_xy & 1)
2683               space.write_word(cop_register[4] + offs + 4,0xc0 + abs_x - (rel_xy & 0xf8));
2754               space.write_word(m_cop_register[4] + offs + 4,0xc0 + abs_x - (rel_xy & 0xf8));
26842755            else
2685               space.write_word(cop_register[4] + offs + 4,(((rel_xy & 0x78) + (abs_x) - ((rel_xy & 0x80) ? 0x80 : 0))));
2756               space.write_word(m_cop_register[4] + offs + 4,(((rel_xy & 0x78) + (abs_x) - ((rel_xy & 0x80) ? 0x80 : 0))));
26862757
2687            space.write_word(cop_register[4] + offs + 6,(((rel_xy & 0x7800) >> 8) + (abs_y) - ((rel_xy & 0x8000) ? 0x80 : 0)));
2758            space.write_word(m_cop_register[4] + offs + 6,(((rel_xy & 0x7800) >> 8) + (abs_y) - ((rel_xy & 0x8000) ? 0x80 : 0)));
26882759            return;
26892760         }
26902761
r26062r26063
26952766
26962767            offs = (offset & 3) * 4;
26972768
2698            space.write_word(cop_register[4] + offs + 0,space.read_word(cop_sprite_dma_src + offs) + (cop_sprite_dma_param & 0x3f));
2699            //space.write_word(cop_register[4] + offs + 2,space.read_word(cop_sprite_dma_src+2 + offs));
2769            space.write_word(m_cop_register[4] + offs + 0,space.read_word(m_cop_sprite_dma_src + offs) + (m_cop_sprite_dma_param & 0x3f));
2770            //space.write_word(m_cop_register[4] + offs + 2,space.read_word(m_cop_sprite_dma_src+2 + offs));
27002771            return;
27012772         }
27022773
r26062r26063
27162787            /* 8 + [4] */
27172788            /* 4 + [6] */
27182789
2719            //printf("%08x %08x %08x %08x %08x %08x %08x\n",cop_register[0],cop_register[1],cop_register[2],cop_register[3],cop_register[4],cop_register[5],cop_register[6]);
2790            //printf("%08x %08x %08x %08x %08x %08x %08x\n",m_cop_register[0],m_cop_register[1],m_cop_register[2],m_cop_register[3],m_cop_register[4],m_cop_register[5],m_cop_register[6]);
27202791
27212792            offs = (offset & 3) * 4;
27222793
2723            div = space.read_word(cop_register[4] + offs) + 1;
2724//              offs_val = space.read_word(cop_register[3] + offs);
2794            div = space.read_word(m_cop_register[4] + offs) + 1;
2795//              offs_val = space.read_word(m_cop_register[3] + offs);
27252796            //420 / 180 = 500 : 400 = 30 / 50 = 98 / 18
27262797
27272798            if(div == 0) { div = 1; }
27282799
2729            space.write_word((cop_register[6] + offs + 4), ((space.read_word(cop_register[5] + offs + 4)) / div));
2800            space.write_word((m_cop_register[6] + offs + 4), ((space.read_word(m_cop_register[5] + offs + 4)) / div));
27302801            return;
27312802         }
27322803
r26062r26063
27412812            /* 0 [1] */
27422813            /* 0xc [1] */
27432814
2744            cur_angle = space.read_byte(cop_register[1] + (0xc ^ 3));
2745            //space.write_byte(cop_register[1] + (0^3),space.read_byte(cop_register[1] + (0^3)) & 0xfb); //correct?
2815            cur_angle = space.read_byte(m_cop_register[1] + (0xc ^ 3));
2816            //space.write_byte(m_cop_register[1] + (0^3),space.read_byte(m_cop_register[1] + (0^3)) & 0xfb); //correct?
27462817
2747            if(cur_angle >= cop_angle_compare)
2818            if(cur_angle >= m_cop_angle_compare)
27482819            {
2749               cur_angle -= cop_angle_mod_val;
2750               if(cur_angle <= cop_angle_compare)
2820               cur_angle -= m_cop_angle_mod_val;
2821               if(cur_angle <= m_cop_angle_compare)
27512822               {
2752                  cur_angle = cop_angle_compare;
2753                  //space.write_byte(cop_register[1] + (0^3),space.read_byte(cop_register[1] + (0^3)) | 2);
2823                  cur_angle = m_cop_angle_compare;
2824                  //space.write_byte(m_cop_register[1] + (0^3),space.read_byte(m_cop_register[1] + (0^3)) | 2);
27542825               }
27552826            }
2756            else if(cur_angle <= cop_angle_compare)
2827            else if(cur_angle <= m_cop_angle_compare)
27572828            {
2758               cur_angle += cop_angle_mod_val;
2759               if(cur_angle >= cop_angle_compare)
2829               cur_angle += m_cop_angle_mod_val;
2830               if(cur_angle >= m_cop_angle_compare)
27602831               {
2761                  cur_angle = cop_angle_compare;
2762                  //space.write_byte(cop_register[1] + (0^3),space.read_byte(cop_register[1] + (0^3)) | 2);
2832                  cur_angle = m_cop_angle_compare;
2833                  //space.write_byte(m_cop_register[1] + (0^3),space.read_byte(m_cop_register[1] + (0^3)) | 2);
27632834               }
27642835            }
27652836
2766            space.write_byte(cop_register[1] + (0xc ^ 3),cur_angle);
2837            space.write_byte(m_cop_register[1] + (0xc ^ 3),cur_angle);
27672838            return;
27682839         }
27692840
r26062r26063
27742845         {
27752846            INT8 cur_angle;
27762847
2777            cur_angle = INT8(space.read_byte(cop_register[0] + (0x34 ^ 3)));
2778            //space.write_byte(cop_register[0] + (0^3),space.read_byte(cop_register[0] + (0^3)) & 0xfb); //correct?
2848            cur_angle = INT8(space.read_byte(m_cop_register[0] + (0x34 ^ 3)));
2849            //space.write_byte(m_cop_register[0] + (0^3),space.read_byte(m_cop_register[0] + (0^3)) & 0xfb); //correct?
27792850            /*
27802851            0x00      0x00          0x60            0x00
27812852            0x00      0x20          0x60            0x20
r26062r26063
27872858            0x00      0xe0          0x60            0xe0
27882859            */
27892860
2790            if(cur_angle > cop_angle_compare)
2861            if(cur_angle > m_cop_angle_compare)
27912862            {
2792               cur_angle -= cop_angle_mod_val;
2863               cur_angle -= m_cop_angle_mod_val;
27932864
2794               if(cur_angle < cop_angle_compare)
2795                  cur_angle = cop_angle_compare;
2865               if(cur_angle < m_cop_angle_compare)
2866                  cur_angle = m_cop_angle_compare;
27962867            }
2797            else if(cur_angle < cop_angle_compare)
2868            else if(cur_angle < m_cop_angle_compare)
27982869            {
2799               cur_angle += cop_angle_mod_val;
2870               cur_angle += m_cop_angle_mod_val;
28002871
2801               if(cur_angle > cop_angle_compare)
2802                  cur_angle = cop_angle_compare;
2872               if(cur_angle > m_cop_angle_compare)
2873                  cur_angle = m_cop_angle_compare;
28032874            }
28042875
2805            space.write_byte(cop_register[0] + (0x34 ^ 3),cur_angle);
2876            space.write_byte(m_cop_register[0] + (0x34 ^ 3),cur_angle);
28062877            return;
28072878         }
28082879
28092880         //(cupsoc) 1c | 5 | b07f | e38e | 984 ac4 d82 ac2 39b b9a b9a a9a
28102881         if(COP_CMD(0x984,0xac4,0xd82,0xac2,0x39b,0xb9a,0xb9a,0xa9a,5,0xb07f))
28112882         {
2812            int dy = space.read_dword(cop_register[2]+4) - space.read_dword(cop_register[0]+4);
2813            int dx = space.read_dword(cop_register[2]+8) - space.read_dword(cop_register[0]+8);
2883            int dy = space.read_dword(m_cop_register[2]+4) - space.read_dword(m_cop_register[0]+4);
2884            int dx = space.read_dword(m_cop_register[2]+8) - space.read_dword(m_cop_register[0]+8);
28142885
2815            cop_status = 7;
2886            m_cop_status = 7;
28162887            if(!dx) {
2817               cop_status |= 0x8000;
2818               cop_angle = 0;
2888               m_cop_status |= 0x8000;
2889               m_cop_angle = 0;
28192890            } else {
2820               cop_angle = atan(double(dy)/double(dx)) * 128.0 / M_PI;
2891               m_cop_angle = atan(double(dy)/double(dx)) * 128.0 / M_PI;
28212892               if(dx<0)
2822                  cop_angle += 0x80;
2893                  m_cop_angle += 0x80;
28232894            }
28242895
2825            r0 = dy;
2826            r1 = dx;
2896            m_r0 = dy;
2897            m_r1 = dx;
28272898
2828            //printf("%d %d %f %04x\n",dx,dy,atan(double(dy)/double(dx)) * 128 / M_PI,cop_angle);
2899            //printf("%d %d %f %04x\n",dx,dy,atan(double(dy)/double(dx)) * 128 / M_PI,m_cop_angle);
28292900
2830            if(cop_mcu_ram[offset] & 0x80)
2831               space.write_word(cop_register[0]+(0x34^2), cop_angle);
2901            if(m_cop_mcu_ram[offset] & 0x80)
2902               space.write_word(m_cop_register[0]+(0x34^2), m_cop_angle);
28322903            return;
28332904         }
28342905
r26062r26063
28372908         if(COP_CMD(0xac2,0x9e0,0x0a2,0x000,0x000,0x000,0x000,0x000,5,0xfffb))
28382909         {
28392910            UINT8 *ROM = space.machine().root_device().memregion("maincpu")->base();
2840            UINT32 rom_addr = (cop_rom_addr_hi << 16 | cop_rom_addr_lo) & ~1;
2911            UINT32 rom_addr = (m_cop_rom_addr_hi << 16 | m_cop_rom_addr_lo) & ~1;
28412912            UINT16 rom_data = (ROM[rom_addr + 0]) | (ROM[rom_addr + 1]<<8);
28422913
28432914            /* writes to some unemulated COP registers, then puts the result in here, adding a parameter taken from ROM */
2844            //space.write_word(cop_register[0]+(0x44 + offset * 4), rom_data);
2915            //space.write_word(m_cop_register[0]+(0x44 + offset * 4), rom_data);
28452916
2846            printf("%04x%04x %04x %04x\n",cop_rom_addr_hi,cop_rom_addr_lo,cop_rom_addr_unk,rom_data);
2917            printf("%04x%04x %04x %04x\n",m_cop_rom_addr_hi,m_cop_rom_addr_lo,m_cop_rom_addr_unk,rom_data);
28472918            return;
28482919         }
28492920
2850         printf("%04x\n",cop_mcu_ram[offset]);
2921         printf("%04x\n",m_cop_mcu_ram[offset]);
28512922         break;
28522923      }
28532924
r26062r26063
28562927      {
28572928         //seibu_cop_log("%06x: COPX execute current layer clear??? %04x\n", space.device().safe_pc(), data);
28582929
2859         if (cop_dma_trigger >= 0x80 && cop_dma_trigger <= 0x87)
2930         if (m_cop_dma_trigger >= 0x80 && m_cop_dma_trigger <= 0x87)
28602931         {
28612932            UINT32 src,dst,size,i;
28622933
28632934            /*
2864            Apparently all of those are just different DMA channels, brightness effects are done through a RAM table and the pal_brightness_val / mode
2935            Apparently all of those are just different DMA channels, brightness effects are done through a RAM table and the m_pal_brightness_val / mode
28652936            0x80 is used by Legionnaire
28662937            0x81 is used by SD Gundam and Godzilla
28672938            0x82 is used by Zero Team and X Se Dae
r26062r26063
28752946            */
28762947
28772948            //if(dma_trigger != 0x87)
2878            //printf("SRC: %08x %08x DST:%08x SIZE:%08x TRIGGER: %08x %02x %02x\n",cop_dma_src[cop_dma_trigger] << 6,cop_dma_fade_table * 0x400,cop_dma_dst[cop_dma_trigger] << 6,cop_dma_size[cop_dma_trigger] << 5,cop_dma_trigger,pal_brightness_val,pal_brightness_mode);
2949            //printf("SRC: %08x %08x DST:%08x SIZE:%08x TRIGGER: %08x %02x %02x\n",m_cop_dma_src[m_cop_dma_trigger] << 6,m_cop_dma_fade_table * 0x400,m_cop_dma_dst[m_cop_dma_trigger] << 6,m_cop_dma_size[m_cop_dma_trigger] << 5,m_cop_dma_trigger,m_pal_brightness_val,m_pal_brightness_mode);
28792950
2880            src = (cop_dma_src[cop_dma_trigger] << 6);
2881            dst = (cop_dma_dst[cop_dma_trigger] << 6);
2882            size = ((cop_dma_size[cop_dma_trigger] << 5) - (cop_dma_dst[cop_dma_trigger] << 6) + 0x20)/2;
2951            src = (m_cop_dma_src[m_cop_dma_trigger] << 6);
2952            dst = (m_cop_dma_dst[m_cop_dma_trigger] << 6);
2953            size = ((m_cop_dma_size[m_cop_dma_trigger] << 5) - (m_cop_dma_dst[m_cop_dma_trigger] << 6) + 0x20)/2;
28832954
28842955            for(i = 0;i < size;i++)
28852956            {
r26062r26063
28872958               int r,g,b;
28882959               int rt,gt,bt;
28892960
2890               if(pal_brightness_mode == 5)
2961               if(m_pal_brightness_mode == 5)
28912962               {
2892                  bt = ((space.read_word(src + (cop_dma_fade_table * 0x400))) & 0x7c00) >> 5;
2893                  bt = fade_table(bt|(pal_brightness_val ^ 0));
2963                  bt = ((space.read_word(src + (m_cop_dma_fade_table * 0x400))) & 0x7c00) >> 5;
2964                  bt = fade_table(bt|(m_pal_brightness_val ^ 0));
28942965                  b = ((space.read_word(src)) & 0x7c00) >> 5;
2895                  b = fade_table(b|(pal_brightness_val ^ 0x1f));
2966                  b = fade_table(b|(m_pal_brightness_val ^ 0x1f));
28962967                  pal_val = ((b + bt) & 0x1f) << 10;
2897                  gt = ((space.read_word(src + (cop_dma_fade_table * 0x400))) & 0x03e0);
2898                  gt = fade_table(gt|(pal_brightness_val ^ 0));
2968                  gt = ((space.read_word(src + (m_cop_dma_fade_table * 0x400))) & 0x03e0);
2969                  gt = fade_table(gt|(m_pal_brightness_val ^ 0));
28992970                  g = ((space.read_word(src)) & 0x03e0);
2900                  g = fade_table(g|(pal_brightness_val ^ 0x1f));
2971                  g = fade_table(g|(m_pal_brightness_val ^ 0x1f));
29012972                  pal_val |= ((g + gt) & 0x1f) << 5;
2902                  rt = ((space.read_word(src + (cop_dma_fade_table * 0x400))) & 0x001f) << 5;
2903                  rt = fade_table(rt|(pal_brightness_val ^ 0));
2973                  rt = ((space.read_word(src + (m_cop_dma_fade_table * 0x400))) & 0x001f) << 5;
2974                  rt = fade_table(rt|(m_pal_brightness_val ^ 0));
29042975                  r = ((space.read_word(src)) & 0x001f) << 5;
2905                  r = fade_table(r|(pal_brightness_val ^ 0x1f));
2976                  r = fade_table(r|(m_pal_brightness_val ^ 0x1f));
29062977                  pal_val |= ((r + rt) & 0x1f);
29072978               }
2908               else if(pal_brightness_mode == 4) //Denjin Makai
2979               else if(m_pal_brightness_mode == 4) //Denjin Makai
29092980               {
2910                  bt =(space.read_word(src + (cop_dma_fade_table * 0x400)) & 0x7c00) >> 10;
2981                  bt =(space.read_word(src + (m_cop_dma_fade_table * 0x400)) & 0x7c00) >> 10;
29112982                  b = (space.read_word(src) & 0x7c00) >> 10;
2912                  gt =(space.read_word(src + (cop_dma_fade_table * 0x400)) & 0x03e0) >> 5;
2983                  gt =(space.read_word(src + (m_cop_dma_fade_table * 0x400)) & 0x03e0) >> 5;
29132984                  g = (space.read_word(src) & 0x03e0) >> 5;
2914                  rt =(space.read_word(src + (cop_dma_fade_table * 0x400)) & 0x001f) >> 0;
2985                  rt =(space.read_word(src + (m_cop_dma_fade_table * 0x400)) & 0x001f) >> 0;
29152986                  r = (space.read_word(src) & 0x001f) >> 0;
29162987
2917                  if(pal_brightness_val == 0x10)
2988                  if(m_pal_brightness_val == 0x10)
29182989                     pal_val = bt << 10 | gt << 5 | rt << 0;
2919                  else if(pal_brightness_val == 0xff) // TODO: might be the back plane or it still doesn't do any mod, needs PCB tests
2990                  else if(m_pal_brightness_val == 0xff) // TODO: might be the back plane or it still doesn't do any mod, needs PCB tests
29202991                     pal_val = 0;
29212992                  else
29222993                  {
2923                     bt = fade_table(bt<<5|((pal_brightness_val*2) ^ 0));
2924                     b =  fade_table(b<<5|((pal_brightness_val*2) ^ 0x1f));
2994                     bt = fade_table(bt<<5|((m_pal_brightness_val*2) ^ 0));
2995                     b =  fade_table(b<<5|((m_pal_brightness_val*2) ^ 0x1f));
29252996                     pal_val = ((b + bt) & 0x1f) << 10;
2926                     gt = fade_table(gt<<5|((pal_brightness_val*2) ^ 0));
2927                     g =  fade_table(g<<5|((pal_brightness_val*2) ^ 0x1f));
2997                     gt = fade_table(gt<<5|((m_pal_brightness_val*2) ^ 0));
2998                     g =  fade_table(g<<5|((m_pal_brightness_val*2) ^ 0x1f));
29282999                     pal_val |= ((g + gt) & 0x1f) << 5;
2929                     rt = fade_table(rt<<5|((pal_brightness_val*2) ^ 0));
2930                     r =  fade_table(r<<5|((pal_brightness_val*2) ^ 0x1f));
3000                     rt = fade_table(rt<<5|((m_pal_brightness_val*2) ^ 0));
3001                     r =  fade_table(r<<5|((m_pal_brightness_val*2) ^ 0x1f));
29313002                     pal_val |= ((r + rt) & 0x1f);
29323003                  }
29333004               }
29343005               else
29353006               {
2936                  printf("Warning: palette DMA used with mode %02x!\n",pal_brightness_mode);
3007                  printf("Warning: palette DMA used with mode %02x!\n",m_pal_brightness_mode);
29373008                  pal_val = space.read_word(src);
29383009               }
29393010
r26062r26063
29463017         }
29473018
29483019         /* Seibu Cup Soccer trigger this*/
2949         if (cop_dma_trigger == 0x0e)
3020         if (m_cop_dma_trigger == 0x0e)
29503021         {
29513022            UINT32 src,dst,size,i;
29523023
2953            src = (cop_dma_src[cop_dma_trigger] << 6);
2954            dst = (cop_dma_dst[cop_dma_trigger] << 6);
2955            size = ((cop_dma_size[cop_dma_trigger] << 5) - (cop_dma_dst[cop_dma_trigger] << 6) + 0x20)/2;
3024            src = (m_cop_dma_src[m_cop_dma_trigger] << 6);
3025            dst = (m_cop_dma_dst[m_cop_dma_trigger] << 6);
3026            size = ((m_cop_dma_size[m_cop_dma_trigger] << 5) - (m_cop_dma_dst[m_cop_dma_trigger] << 6) + 0x20)/2;
29563027
29573028            for(i = 0;i < size;i++)
29583029            {
r26062r26063
29653036         }
29663037
29673038         /* do the fill  */
2968         if (cop_dma_trigger >= 0x118 && cop_dma_trigger <= 0x11f)
3039         if (m_cop_dma_trigger >= 0x118 && m_cop_dma_trigger <= 0x11f)
29693040         {
29703041            UINT32 length, address;
29713042            int i;
2972            if(cop_dma_dst[cop_dma_trigger] != 0x0000) // Invalid?
3043            if(m_cop_dma_dst[m_cop_dma_trigger] != 0x0000) // Invalid?
29733044               return;
29743045
2975            address = (cop_dma_src[cop_dma_trigger] << 6);
2976            length = (cop_dma_size[cop_dma_trigger]+1) << 5;
3046            address = (m_cop_dma_src[m_cop_dma_trigger] << 6);
3047            length = (m_cop_dma_size[m_cop_dma_trigger]+1) << 5;
29773048
29783049            //printf("%08x %08x\n",address,length);
29793050
29803051            for (i=address;i<address+length;i+=4)
29813052            {
2982               space.write_dword(i, fill_val);
3053               space.write_dword(i, m_fill_val);
29833054            }
29843055
29853056            return;
29863057         }
29873058
29883059         /* Godzilla specific */
2989         if (cop_dma_trigger == 0x116)
3060         if (m_cop_dma_trigger == 0x116)
29903061         {
29913062            UINT32 length, address;
29923063            int i;
29933064
2994            //if(cop_dma_dst[cop_dma_trigger] != 0x0000) // Invalid?
3065            //if(m_cop_dma_dst[m_cop_dma_trigger] != 0x0000) // Invalid?
29953066            //  return;
29963067
2997            address = (cop_dma_src[cop_dma_trigger] << 6);
2998            length = ((cop_dma_size[cop_dma_trigger]+1) << 4);
3068            address = (m_cop_dma_src[m_cop_dma_trigger] << 6);
3069            length = ((m_cop_dma_size[m_cop_dma_trigger]+1) << 4);
29993070
30003071            for (i=address;i<address+length;i+=4)
30013072            {
3002               space.write_dword(i, fill_val);
3073               space.write_dword(i, m_fill_val);
30033074            }
30043075
30053076            return;
30063077         }
30073078
30083079         /* private buffer copies */
3009         if ((cop_dma_trigger==0x14) || (cop_dma_trigger==0x15)) return;
3080         if ((m_cop_dma_trigger==0x14) || (m_cop_dma_trigger==0x15)) return;
30103081
3011         printf("SRC: %08x %08x DST:%08x SIZE:%08x TRIGGER: %08x\n",cop_dma_src[cop_dma_trigger] << 6,cop_dma_fade_table,cop_dma_dst[cop_dma_trigger] << 6,cop_dma_size[cop_dma_trigger] << 5,cop_dma_trigger);
3082         printf("SRC: %08x %08x DST:%08x SIZE:%08x TRIGGER: %08x\n",m_cop_dma_src[m_cop_dma_trigger] << 6,m_cop_dma_fade_table,m_cop_dma_dst[m_cop_dma_trigger] << 6,m_cop_dma_size[m_cop_dma_trigger] << 5,m_cop_dma_trigger);
30123083
30133084         break;
30143085      }
30153086
30163087      /* sort-DMA, oh my ... */
3017      case (0x054/2): { cop_sort_lookup = (cop_sort_lookup&0x0000ffff)|(cop_mcu_ram[offset]<<16); break; }
3018      case (0x056/2): { cop_sort_lookup = (cop_sort_lookup&0xffff0000)|(cop_mcu_ram[offset]<<0);  break; }
3019      case (0x050/2): { cop_sort_ram_addr = (cop_sort_ram_addr&0x0000ffff)|(cop_mcu_ram[offset]<<16); break; }
3020      case (0x052/2): { cop_sort_ram_addr = (cop_sort_ram_addr&0xffff0000)|(cop_mcu_ram[offset]<<0);  break; }
3021      case (0x058/2): { cop_sort_param = cop_mcu_ram[offset]; break; }
3088      case (0x054/2): { m_cop_sort_lookup = (m_cop_sort_lookup&0x0000ffff)|(m_cop_mcu_ram[offset]<<16); break; }
3089      case (0x056/2): { m_cop_sort_lookup = (m_cop_sort_lookup&0xffff0000)|(m_cop_mcu_ram[offset]<<0);  break; }
3090      case (0x050/2): { m_cop_sort_ram_addr = (m_cop_sort_ram_addr&0x0000ffff)|(m_cop_mcu_ram[offset]<<16); break; }
3091      case (0x052/2): { m_cop_sort_ram_addr = (m_cop_sort_ram_addr&0xffff0000)|(m_cop_mcu_ram[offset]<<0);  break; }
3092      case (0x058/2): { m_cop_sort_param = m_cop_mcu_ram[offset]; break; }
30223093
30233094      case (0x2fe/2):
30243095      {
30253096         UINT16 sort_size;
30263097
3027         sort_size = cop_mcu_ram[offset];
3098         sort_size = m_cop_mcu_ram[offset];
30283099
30293100         {
30303101            int i,j;
r26062r26063
30373108            {
30383109               for(j=i-2;j<sort_size;j+=2)
30393110               {
3040                  addri = cop_sort_ram_addr+space.read_word(cop_sort_lookup+i);
3041                  addrj = cop_sort_ram_addr+space.read_word(cop_sort_lookup+j);
3111                  addri = m_cop_sort_ram_addr+space.read_word(m_cop_sort_lookup+i);
3112                  addrj = m_cop_sort_ram_addr+space.read_word(m_cop_sort_lookup+j);
30423113
30433114                  vali = space.read_word(addri);
30443115                  valj = space.read_word(addrj);
30453116
30463117                  //printf("%08x %08x %04x %04x\n",addri,addrj,vali,valj);
30473118
3048                  switch(cop_sort_param)
3119                  switch(m_cop_sort_param)
30493120                  {
30503121                     case 2: xchg_flag = (vali > valj); break;
30513122                     case 1: xchg_flag = (vali < valj); break;
30523123                     case 0: xchg_flag = 0; break; /* ??? */
3053                     default: xchg_flag = 0; printf("Warning: sort-DMA used with param %02x\n",cop_sort_param); break;
3124                     default: xchg_flag = 0; printf("Warning: sort-DMA used with param %02x\n",m_cop_sort_param); break;
30543125                  }
30553126
30563127                  if(xchg_flag)
30573128                  {
30583129                     UINT16 xch_val;
30593130
3060                     xch_val = space.read_word(cop_sort_lookup+i);
3061                     space.write_word(cop_sort_lookup+i,space.read_word(cop_sort_lookup+j));
3062                     space.write_word(cop_sort_lookup+j,xch_val);
3131                     xch_val = space.read_word(m_cop_sort_lookup+i);
3132                     space.write_word(m_cop_sort_lookup+i,space.read_word(m_cop_sort_lookup+j));
3133                     space.write_word(m_cop_sort_lookup+j,xch_val);
30633134                  }
30643135               }
30653136            }
r26062r26063
30753146  Heated Barrel
30763147**********************************************************************************************/
30773148
3078READ16_HANDLER( heatbrl_mcu_r )
3149READ16_MEMBER( seibu_cop_legacy_device::heatbrl_mcu_r )
30793150{
30803151   if(offset >= 0x3c0/2 && offset <= 0x3df/2)
30813152         return space.machine().device<seibu_sound_device>("seibu_sound")->main_word_r(space,(offset >> 1) & 7,0xffff);
r26062r26063
30903161   return generic_cop_r(space, offset, mem_mask);
30913162}
30923163
3093WRITE16_HANDLER( heatbrl_mcu_w )
3164WRITE16_MEMBER( seibu_cop_legacy_device::heatbrl_mcu_w )
30943165{
3095   get_ram(space.machine());
3096   COMBINE_DATA(&cop_mcu_ram[offset]);
3166   COMBINE_DATA(&m_cop_mcu_ram[offset]);
30973167
30983168   /* external pin register, used for banking */
30993169   if(offset == 0x070/2)
31003170   {
3101      heatbrl_setgfxbank(space.machine(), cop_mcu_ram[offset]);
3171      heatbrl_setgfxbank(space.machine(), m_cop_mcu_ram[offset]);
31023172      return;
31033173   }
31043174
r26062r26063
31073177
31083178   if(offset >= 0x240/2 && offset <= 0x28f/2)
31093179   {
3110      seibu_common_video_regs_w(space,offset-0x240/2,cop_mcu_ram[offset],mem_mask);
3180      seibu_common_video_regs_w(space,offset-0x240/2,m_cop_mcu_ram[offset],mem_mask);
31113181      return;
31123182   }
31133183
31143184   if(offset >= 0x3c0/2 && offset <= 0x3df/2)
31153185   {
3116      space.machine().device<seibu_sound_device>("seibu_sound")->main_word_w(space,(offset >> 1) & 7,cop_mcu_ram[offset],0x00ff);
3186      space.machine().device<seibu_sound_device>("seibu_sound")->main_word_w(space,(offset >> 1) & 7,m_cop_mcu_ram[offset],0x00ff);
31173187      return;
31183188   }
31193189
r26062r26063
31263196  Seibu Cup Soccer
31273197**********************************************************************************************/
31283198
3129READ16_HANDLER( cupsoc_mcu_r )
3199READ16_MEMBER( seibu_cop_legacy_device::cupsoc_mcu_r )
31303200{
31313201   if(offset >= 0x300/2 && offset <= 0x31f/2)
31323202      return space.machine().device<seibu_sound_device>("seibu_sound")->main_word_r(space,(offset >> 1) & 7,0xffff);
r26062r26063
31463216   return generic_cop_r(space, offset, mem_mask);
31473217}
31483218
3149WRITE16_HANDLER( cupsoc_mcu_w )
3219WRITE16_MEMBER( seibu_cop_legacy_device::cupsoc_mcu_w )
31503220{
3151   get_ram(space.machine());
3152   COMBINE_DATA(&cop_mcu_ram[offset]);
3221   COMBINE_DATA(&m_cop_mcu_ram[offset]);
31533222
31543223   if(offset == 0x280/2) //irq ack / sprite buffering?
31553224      return;
31563225
31573226   if(offset >= 0x200/2 && offset <= 0x24f/2)
31583227   {
3159      seibu_common_video_regs_w(space,offset-0x200/2,cop_mcu_ram[offset],mem_mask);
3228      seibu_common_video_regs_w(space,offset-0x200/2,m_cop_mcu_ram[offset],mem_mask);
31603229      return;
31613230   }
31623231
31633232   if(offset >= 0x300/2 && offset <= 0x31f/2)
31643233   {
3165      space.machine().device<seibu_sound_device>("seibu_sound")->main_word_w(space,(offset >> 1) & 7,cop_mcu_ram[offset],0x00ff);
3234      space.machine().device<seibu_sound_device>("seibu_sound")->main_word_w(space,(offset >> 1) & 7,m_cop_mcu_ram[offset],0x00ff);
31663235      return;
31673236   }
31683237
31693238   generic_cop_w(space, offset, data, mem_mask);
31703239}
31713240
3172READ16_HANDLER( cupsocs_mcu_r )
3241READ16_MEMBER( seibu_cop_legacy_device::cupsocs_mcu_r )
31733242{
31743243   if(offset >= 0x340/2 && offset <= 0x35f/2)
31753244      return space.machine().device<seibu_sound_device>("seibu_sound")->main_word_r(space,(offset >> 1) & 7,0xffff);
r26062r26063
31893258   return generic_cop_r(space, offset, mem_mask);
31903259}
31913260
3192WRITE16_HANDLER( cupsocs_mcu_w )
3261WRITE16_MEMBER( seibu_cop_legacy_device::cupsocs_mcu_w )
31933262{
3194   get_ram(space.machine());
3195   COMBINE_DATA(&cop_mcu_ram[offset]);
3263   COMBINE_DATA(&m_cop_mcu_ram[offset]);
31963264
31973265   if(offset == 0x280/2) //irq ack / sprite buffering?
31983266      return;
31993267
32003268   if(offset >= 0x240/2 && offset <= 0x27f/2)
32013269   {
3202      seibu_common_video_regs_w(space,offset-0x240/2,cop_mcu_ram[offset],mem_mask);
3270      seibu_common_video_regs_w(space,offset-0x240/2,m_cop_mcu_ram[offset],mem_mask);
32033271      return;
32043272   }
32053273
32063274   if(offset >= 0x200/2 && offset <= 0x20f/2)
32073275   {
3208      seibu_common_video_regs_w(space,(offset-0x200/2)+(0x40/2),cop_mcu_ram[offset],mem_mask);
3276      seibu_common_video_regs_w(space,(offset-0x200/2)+(0x40/2),m_cop_mcu_ram[offset],mem_mask);
32093277      return;
32103278   }
32113279
32123280   if(offset >= 0x340/2 && offset <= 0x35f/2)
32133281   {
3214      space.machine().device<seibu_sound_device>("seibu_sound")->main_word_w(space,(offset >> 1) & 7,cop_mcu_ram[offset],0x00ff);
3282      space.machine().device<seibu_sound_device>("seibu_sound")->main_word_w(space,(offset >> 1) & 7,m_cop_mcu_ram[offset],0x00ff);
32153283      return;
32163284   }
32173285
r26062r26063
32223290  Godzilla
32233291**********************************************************************************************/
32243292
3225READ16_HANDLER( godzilla_mcu_r )
3293READ16_MEMBER( seibu_cop_legacy_device::godzilla_mcu_r )
32263294{
32273295   if(offset >= 0x300/2 && offset <= 0x31f/2)
32283296      return space.machine().device<seibu_sound_device>("seibu_sound")->main_word_r(space,(offset >> 1) & 7,0xffff);
r26062r26063
32373305   return generic_cop_r(space, offset, mem_mask);
32383306}
32393307
3240WRITE16_HANDLER( godzilla_mcu_w )
3308WRITE16_MEMBER( seibu_cop_legacy_device::godzilla_mcu_w )
32413309{
3242   get_ram(space.machine());
3243   COMBINE_DATA(&cop_mcu_ram[offset]);
3310   COMBINE_DATA(&m_cop_mcu_ram[offset]);
32443311
32453312   if(offset == 0x070/2)
32463313   {
3247      denjinmk_setgfxbank(space.machine(), cop_mcu_ram[offset]);
3314      denjinmk_setgfxbank(space.machine(), m_cop_mcu_ram[offset]);
32483315      return;
32493316   }
32503317
r26062r26063
32533320
32543321   if(offset >= 0x200/2 && offset <= 0x24f/2)
32553322   {
3256      seibu_common_video_regs_w(space,offset-0x200/2,cop_mcu_ram[offset],mem_mask);
3323      seibu_common_video_regs_w(space,offset-0x200/2,m_cop_mcu_ram[offset],mem_mask);
32573324      return;
32583325   }
32593326
32603327   if(offset >= 0x300/2 && offset <= 0x31f/2)
32613328   {
3262      space.machine().device<seibu_sound_device>("seibu_sound")->main_word_w(space,(offset >> 1) & 7,cop_mcu_ram[offset],0x00ff);
3329      space.machine().device<seibu_sound_device>("seibu_sound")->main_word_w(space,(offset >> 1) & 7,m_cop_mcu_ram[offset],0x00ff);
32633330      return;
32643331   }
32653332
r26062r26063
32703337  Denjin Makai
32713338**********************************************************************************************/
32723339
3273READ16_HANDLER( denjinmk_mcu_r )
3340READ16_MEMBER( seibu_cop_legacy_device::denjinmk_mcu_r )
32743341{
32753342   if(offset >= 0x300/2 && offset <= 0x31f/2)
32763343      return space.machine().device<seibu_sound_device>("seibu_sound")->main_word_r(space,(offset >> 1) & 7,0xffff);
r26062r26063
32903357   return generic_cop_r(space, offset, mem_mask);
32913358}
32923359
3293WRITE16_HANDLER( denjinmk_mcu_w )
3360WRITE16_MEMBER( seibu_cop_legacy_device::denjinmk_mcu_w )
32943361{
3295   get_ram(space.machine());
3296   COMBINE_DATA(&cop_mcu_ram[offset]);
3362   COMBINE_DATA(&m_cop_mcu_ram[offset]);
32973363
32983364   if(offset == 0x280/2) //irq ack / sprite buffering?
32993365      return;
33003366
33013367   if(offset == 0x070/2)
33023368   {
3303      denjinmk_setgfxbank(space.machine(), cop_mcu_ram[offset]);
3369      denjinmk_setgfxbank(space.machine(), m_cop_mcu_ram[offset]);
33043370      return;
33053371   }
33063372
33073373   if(offset >= 0x200/2 && offset <= 0x24f/2)
33083374   {
3309      seibu_common_video_regs_w(space,offset-0x200/2,cop_mcu_ram[offset],mem_mask);
3375      seibu_common_video_regs_w(space,offset-0x200/2,m_cop_mcu_ram[offset],mem_mask);
33103376      return;
33113377   }
33123378
33133379   if(offset >= 0x300/2 && offset <= 0x31f/2)
33143380   {
3315      space.machine().device<seibu_sound_device>("seibu_sound")->main_word_w(space,(offset >> 1) & 7,cop_mcu_ram[offset],0x00ff);
3381      space.machine().device<seibu_sound_device>("seibu_sound")->main_word_w(space,(offset >> 1) & 7,m_cop_mcu_ram[offset],0x00ff);
33163382      return;
33173383   }
33183384
r26062r26063
33233389  SD Gundam Sangokushi Rainbow Tairiku Senki
33243390**********************************************************************************************/
33253391
3326READ16_HANDLER( grainbow_mcu_r )
3392READ16_MEMBER( seibu_cop_legacy_device::grainbow_mcu_r )
33273393{
33283394   if(offset >= 0x300/2 && offset <= 0x31f/2)
33293395      return space.machine().device<seibu_sound_device>("seibu_sound")->main_word_r(space,(offset >> 1) & 7,0xffff);
r26062r26063
33443410}
33453411
33463412
3347WRITE16_HANDLER( grainbow_mcu_w )
3413WRITE16_MEMBER( seibu_cop_legacy_device::grainbow_mcu_w )
33483414{
3349   get_ram(space.machine());
3350   COMBINE_DATA(&cop_mcu_ram[offset]);
3415   COMBINE_DATA(&m_cop_mcu_ram[offset]);
33513416
33523417   if(offset == 0x280/2) //irq ack / sprite buffering?
33533418      return;
33543419
33553420   if(offset >= 0x200/2 && offset <= 0x24f/2)
33563421   {
3357      seibu_common_video_regs_w(space,offset-0x200/2,cop_mcu_ram[offset],mem_mask);
3422      seibu_common_video_regs_w(space,offset-0x200/2,m_cop_mcu_ram[offset],mem_mask);
33583423      return;
33593424   }
33603425
33613426   if(offset >= 0x300/2 && offset <= 0x31f/2)
33623427   {
3363      space.machine().device<seibu_sound_device>("seibu_sound")->main_word_w(space,(offset >> 1) & 7,cop_mcu_ram[offset],0x00ff);
3428      space.machine().device<seibu_sound_device>("seibu_sound")->main_word_w(space,(offset >> 1) & 7,m_cop_mcu_ram[offset],0x00ff);
33643429      return;
33653430   }
33663431
r26062r26063
33723437**********************************************************************************************/
33733438
33743439
3375READ16_HANDLER( legionna_mcu_r )
3440READ16_MEMBER( seibu_cop_legacy_device::legionna_mcu_r )
33763441{
33773442   if(offset >= 0x300/2 && offset <= 0x31f/2)
33783443      return space.machine().device<seibu_sound_device>("seibu_sound")->main_word_r(space,(offset >> 1) & 7,0xffff);
r26062r26063
33873452   return generic_cop_r(space, offset, mem_mask);
33883453}
33893454
3390WRITE16_HANDLER( legionna_mcu_w )
3455WRITE16_MEMBER( seibu_cop_legacy_device::legionna_mcu_w )
33913456{
3392   get_ram(space.machine());
3393   COMBINE_DATA(&cop_mcu_ram[offset]);
3457   COMBINE_DATA(&m_cop_mcu_ram[offset]);
33943458
33953459   if(offset == 0x070/2) //external pin: puts bit 13 high, delay, reads 0x748, writes bit 13 low
33963460      return;
r26062r26063
34003464
34013465   if(offset >= 0x200/2 && offset <= 0x24f/2)
34023466   {
3403      seibu_common_video_regs_w(space,offset-0x200/2,cop_mcu_ram[offset],mem_mask);
3467      seibu_common_video_regs_w(space,offset-0x200/2,m_cop_mcu_ram[offset],mem_mask);
34043468      return;
34053469   }
34063470
34073471   if(offset >= 0x300/2 && offset <= 0x31f/2)
34083472   {
3409      space.machine().device<seibu_sound_device>("seibu_sound")->main_word_w(space,(offset >> 1) & 7,cop_mcu_ram[offset],0x00ff);
3473      space.machine().device<seibu_sound_device>("seibu_sound")->main_word_w(space,(offset >> 1) & 7,m_cop_mcu_ram[offset],0x00ff);
34103474      return;
34113475   }
34123476
trunk/src/mame/machine/seicop.h
r26062r26063
1DECLARE_READ16_HANDLER( copdxbl_0_r );
2DECLARE_WRITE16_HANDLER( copdxbl_0_w );
31
4DECLARE_READ16_HANDLER( heatbrl_mcu_r );
5DECLARE_WRITE16_HANDLER( heatbrl_mcu_w );
6DECLARE_READ16_HANDLER( cupsoc_mcu_r );
7DECLARE_WRITE16_HANDLER( cupsoc_mcu_w );
8DECLARE_READ16_HANDLER( cupsocs_mcu_r );
9DECLARE_WRITE16_HANDLER( cupsocs_mcu_w );
10DECLARE_READ16_HANDLER( godzilla_mcu_r );
11DECLARE_WRITE16_HANDLER( godzilla_mcu_w );
12DECLARE_READ16_HANDLER( denjinmk_mcu_r );
13DECLARE_WRITE16_HANDLER( denjinmk_mcu_w );
14DECLARE_READ16_HANDLER( grainbow_mcu_r );
15DECLARE_WRITE16_HANDLER( grainbow_mcu_w );
16DECLARE_READ16_HANDLER( legionna_mcu_r );
17DECLARE_WRITE16_HANDLER( legionna_mcu_w );
2struct collision_info
3{
4      collision_info():
5      x(0),
6      y(0),
7      min_x(0),
8      min_y(0),
9      max_x(0),
10      max_y(0),
11      hitbox(0),
12      hitbox_x(0),
13      hitbox_y(0) {}
14     
15   int x,y;
16   INT16 min_x,min_y,max_x,max_y;
17   UINT16 hitbox;
18   UINT16 hitbox_x,hitbox_y;
19};
1820
19DECLARE_READ16_HANDLER( raiden2_mcu_r );
20DECLARE_WRITE16_HANDLER( raiden2_mcu_w );
21class seibu_cop_legacy_device : public device_t
22{
23public:
24seibu_cop_legacy_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
25
26   DECLARE_READ16_MEMBER( copdxbl_0_r );
27   DECLARE_WRITE16_MEMBER( copdxbl_0_w );
28
29   DECLARE_READ16_MEMBER( heatbrl_mcu_r );
30   DECLARE_WRITE16_MEMBER( heatbrl_mcu_w );
31   DECLARE_READ16_MEMBER( cupsoc_mcu_r );
32   DECLARE_WRITE16_MEMBER( cupsoc_mcu_w );
33   DECLARE_READ16_MEMBER( cupsocs_mcu_r );
34   DECLARE_WRITE16_MEMBER( cupsocs_mcu_w );
35   DECLARE_READ16_MEMBER( godzilla_mcu_r );
36   DECLARE_WRITE16_MEMBER( godzilla_mcu_w );
37   DECLARE_READ16_MEMBER( denjinmk_mcu_r );
38   DECLARE_WRITE16_MEMBER( denjinmk_mcu_w );
39   DECLARE_READ16_MEMBER( grainbow_mcu_r );
40   DECLARE_WRITE16_MEMBER( grainbow_mcu_w );
41   DECLARE_READ16_MEMBER( legionna_mcu_r );
42   DECLARE_WRITE16_MEMBER( legionna_mcu_w );
43
44   //DECLARE_READ16_MEMBER( raiden2_mcu_r );   unused
45   //DECLARE_WRITE16_MEMBER( raiden2_mcu_w );   unused
46
47protected:
48   // device-level overrides
49   virtual void device_config_complete();
50   virtual void device_start();
51   virtual void device_reset();
52
53private:
54   UINT16 *m_cop_mcu_ram;
55   UINT16 m_copd2_table[0x100];
56   UINT16 m_copd2_table_2[0x100/8];
57   UINT16 m_copd2_table_3[0x100/8];
58   UINT16 m_copd2_table_4[0x100/8];
59   UINT16 m_cop_438;
60   UINT16 m_cop_43a;
61   UINT16 m_cop_43c;
62   UINT16 m_cop_dma_src[0x200];
63   UINT16 m_cop_dma_size[0x200];
64   UINT16 m_cop_dma_dst[0x200];
65   UINT16 m_cop_dma_fade_table;
66   UINT16 m_cop_dma_trigger;
67   UINT16 m_cop_scale;
68   UINT8 m_cop_rng_max_value;
69   UINT16 m_copd2_offs;
70   UINT32 m_cop_register[8];
71   UINT16 m_seibu_vregs[0x50/2];
72   UINT16 m_cop_status,m_cop_dist,m_cop_angle;
73   UINT16 m_cop_hit_status;
74   INT16 m_cop_hit_val_x,m_cop_hit_val_y,m_cop_hit_val_z,m_cop_hit_val_unk;
75   UINT32 m_cop_sort_lookup,m_cop_sort_ram_addr,m_cop_sort_param;
76   INT8 m_cop_angle_compare;
77   INT8 m_cop_angle_mod_val;
78   struct collision_info m_cop_collision_info[2];
79   int m_r0, m_r1;
80   UINT16 m_cop_rom_addr_lo,m_cop_rom_addr_hi,m_cop_rom_addr_unk;
81   UINT16 m_u1,m_u2;
82   UINT32 m_fill_val;
83   UINT8 m_pal_brightness_val,m_pal_brightness_mode;
84   UINT32 m_cop_sprite_dma_src;
85   int m_cop_sprite_dma_abs_x,m_cop_sprite_dma_abs_y,m_cop_sprite_dma_size;
86   UINT32 m_cop_sprite_dma_param;
87
88   void copd2_set_tableoffset(UINT16 data);
89   void copd2_set_tabledata(UINT16 data);
90   DECLARE_WRITE16_MEMBER( seibu_common_video_regs_w );
91   void cop_take_hit_box_params(UINT8 offs);
92   UINT8 cop_calculate_collsion_detection();
93   DECLARE_READ16_MEMBER( generic_cop_r );
94   DECLARE_WRITE16_MEMBER( generic_cop_w );
95};
96
97extern const device_type SEIBU_COP_LEGACY;
98
99#define MCFG_SEIBU_COP_ADD(_tag) \
100   MCFG_DEVICE_ADD(_tag, SEIBU_COP_LEGACY, 0)
trunk/src/mame/drivers/legionna.c
r26062r26063
8484static ADDRESS_MAP_START( legionna_map, AS_PROGRAM, 16, legionna_state )
8585   AM_RANGE(0x000000, 0x07ffff) AM_ROM
8686   AM_RANGE(0x100000, 0x1003ff) AM_RAM
87   AM_RANGE(0x100400, 0x1007ff) AM_READWRITE_LEGACY(legionna_mcu_r, legionna_mcu_w) AM_SHARE("cop_mcu_ram")    /* COP mcu */
87   AM_RANGE(0x100400, 0x1007ff) AM_DEVREADWRITE("seibucop", seibu_cop_legacy_device, legionna_mcu_r, legionna_mcu_w) AM_SHARE("cop_mcu_ram")    /* COP mcu */
8888   AM_RANGE(0x101000, 0x1017ff) AM_RAM_WRITE(legionna_background_w) AM_SHARE("back_data")
8989   AM_RANGE(0x101800, 0x101fff) AM_RAM_WRITE(legionna_foreground_w) AM_SHARE("fore_data")
9090   AM_RANGE(0x102000, 0x1027ff) AM_RAM_WRITE(legionna_midground_w) AM_SHARE("mid_data")
r26062r26063
9999static ADDRESS_MAP_START( heatbrl_map, AS_PROGRAM, 16, legionna_state )
100100   AM_RANGE(0x000000, 0x07ffff) AM_ROM
101101   AM_RANGE(0x100000, 0x1003ff) AM_RAM
102   AM_RANGE(0x100400, 0x1007ff) AM_READWRITE_LEGACY(heatbrl_mcu_r, heatbrl_mcu_w) AM_SHARE("cop_mcu_ram")  /* COP mcu */
102   AM_RANGE(0x100400, 0x1007ff) AM_DEVREADWRITE("seibucop", seibu_cop_legacy_device, heatbrl_mcu_r, heatbrl_mcu_w) AM_SHARE("cop_mcu_ram")  /* COP mcu */
103103   AM_RANGE(0x100800, 0x100fff) AM_RAM_WRITE(legionna_background_w) AM_SHARE("back_data")
104104   AM_RANGE(0x101000, 0x1017ff) AM_RAM_WRITE(legionna_foreground_w) AM_SHARE("fore_data")
105105   AM_RANGE(0x101800, 0x101fff) AM_RAM_WRITE(legionna_midground_w) AM_SHARE("mid_data")
r26062r26063
112112static ADDRESS_MAP_START( godzilla_map, AS_PROGRAM, 16, legionna_state )
113113   AM_RANGE(0x000000, 0x07ffff) AM_ROM
114114   AM_RANGE(0x100000, 0x1003ff) AM_RAM
115   AM_RANGE(0x100400, 0x1007ff) AM_READWRITE_LEGACY(godzilla_mcu_r, godzilla_mcu_w) AM_SHARE("cop_mcu_ram")    /* COP mcu */
115   AM_RANGE(0x100400, 0x1007ff) AM_DEVREADWRITE("seibucop", seibu_cop_legacy_device, godzilla_mcu_r, godzilla_mcu_w) AM_SHARE("cop_mcu_ram")    /* COP mcu */
116116   AM_RANGE(0x100800, 0x100fff) AM_RAM
117117   AM_RANGE(0x101000, 0x101fff) AM_RAM_WRITE(legionna_background_w) AM_SHARE("back_data")
118118   AM_RANGE(0x102000, 0x1027ff) AM_RAM_WRITE(legionna_midground_w) AM_SHARE("mid_data")
r26062r26063
137137static ADDRESS_MAP_START( denjinmk_map, AS_PROGRAM, 16, legionna_state )
138138   AM_RANGE(0x000000, 0x0fffff) AM_ROM
139139   AM_RANGE(0x100000, 0x1003ff) AM_RAM
140   AM_RANGE(0x100400, 0x1007ff) AM_READWRITE_LEGACY(denjinmk_mcu_r, denjinmk_mcu_w) AM_SHARE("cop_mcu_ram")    /* COP mcu */
140   AM_RANGE(0x100400, 0x1007ff) AM_DEVREADWRITE("seibucop", seibu_cop_legacy_device, denjinmk_mcu_r, denjinmk_mcu_w) AM_SHARE("cop_mcu_ram")    /* COP mcu */
141141   AM_RANGE(0x100800, 0x100fff) AM_RAM
142142   AM_RANGE(0x101000, 0x1017ff) AM_RAM_WRITE(legionna_background_w) AM_SHARE("back_data")
143143   AM_RANGE(0x101800, 0x101fff) AM_RAM_WRITE(legionna_foreground_w) AM_SHARE("fore_data")
r26062r26063
154154static ADDRESS_MAP_START( grainbow_map, AS_PROGRAM, 16, legionna_state )
155155   AM_RANGE(0x000000, 0x0fffff) AM_ROM
156156   AM_RANGE(0x100000, 0x1003ff) AM_RAM
157   AM_RANGE(0x100400, 0x1007ff) AM_READWRITE_LEGACY(grainbow_mcu_r, grainbow_mcu_w) AM_SHARE("cop_mcu_ram")    /* COP mcu */
157   AM_RANGE(0x100400, 0x1007ff) AM_DEVREADWRITE("seibucop", seibu_cop_legacy_device, grainbow_mcu_r, grainbow_mcu_w) AM_SHARE("cop_mcu_ram")    /* COP mcu */
158158   AM_RANGE(0x100800, 0x100fff) AM_RAM_WRITE(legionna_background_w) AM_SHARE("back_data")
159159   AM_RANGE(0x101000, 0x1017ff) AM_RAM_WRITE(legionna_foreground_w) AM_SHARE("fore_data")
160160   AM_RANGE(0x101800, 0x101fff) AM_RAM_WRITE(legionna_midground_w) AM_SHARE("mid_data")
r26062r26063
170170static ADDRESS_MAP_START( cupsoc_mem, AS_PROGRAM, 16, legionna_state )
171171   AM_RANGE(0x000000, 0x0fffff) AM_ROM
172172   AM_RANGE(0x100000, 0x1003ff) AM_RAM
173   AM_RANGE(0x100400, 0x1007ff) AM_READWRITE_LEGACY(cupsoc_mcu_r,cupsoc_mcu_w) AM_SHARE("cop_mcu_ram")
173   AM_RANGE(0x100400, 0x1007ff) AM_DEVREADWRITE("seibucop", seibu_cop_legacy_device, cupsoc_mcu_r,cupsoc_mcu_w) AM_SHARE("cop_mcu_ram")
174174   AM_RANGE(0x100800, 0x100fff) AM_RAM_WRITE(legionna_background_w) AM_SHARE("back_data")
175175   AM_RANGE(0x101000, 0x1017ff) AM_RAM_WRITE(legionna_foreground_w) AM_SHARE("fore_data")
176176   AM_RANGE(0x101800, 0x101fff) AM_RAM_WRITE(legionna_midground_w) AM_SHARE("mid_data")
r26062r26063
189189static ADDRESS_MAP_START( cupsocs_mem, AS_PROGRAM, 16, legionna_state )
190190   AM_RANGE(0x000000, 0x0fffff) AM_ROM
191191   AM_RANGE(0x100000, 0x1003ff) AM_RAM
192   AM_RANGE(0x100400, 0x1007ff) AM_READWRITE_LEGACY(cupsocs_mcu_r,cupsocs_mcu_w) AM_SHARE("cop_mcu_ram")
192   AM_RANGE(0x100400, 0x1007ff) AM_DEVREADWRITE("seibucop", seibu_cop_legacy_device, cupsocs_mcu_r,cupsocs_mcu_w) AM_SHARE("cop_mcu_ram")
193193   AM_RANGE(0x100800, 0x100fff) AM_RAM_WRITE(legionna_background_w) AM_SHARE("back_data")
194194   AM_RANGE(0x101000, 0x1017ff) AM_RAM_WRITE(legionna_foreground_w) AM_SHARE("fore_data")
195195   AM_RANGE(0x101800, 0x101fff) AM_RAM_WRITE(legionna_midground_w) AM_SHARE("mid_data")
r26062r26063
208208static ADDRESS_MAP_START( cupsocbl_mem, AS_PROGRAM, 16, legionna_state )
209209   AM_RANGE(0x000000, 0x0fffff) AM_ROM
210210   //AM_RANGE(0x100000, 0x1003ff) AM_RAM
211   AM_RANGE(0x100000, 0x1007ff) AM_READWRITE_LEGACY(copdxbl_0_r,copdxbl_0_w) AM_SHARE("cop_mcu_ram")
211   AM_RANGE(0x100000, 0x1007ff) AM_DEVREADWRITE("seibucop", seibu_cop_legacy_device, copdxbl_0_r,copdxbl_0_w) AM_SHARE("cop_mcu_ram")
212212   AM_RANGE(0x100800, 0x100fff) AM_RAM_WRITE(legionna_background_w) AM_SHARE("back_data")
213213   AM_RANGE(0x101000, 0x1017ff) AM_RAM_WRITE(legionna_foreground_w) AM_SHARE("fore_data")
214214   AM_RANGE(0x101800, 0x101fff) AM_RAM_WRITE(legionna_midground_w) AM_SHARE("mid_data")
r26062r26063
10661066   MCFG_CPU_VBLANK_INT_DRIVER("screen", legionna_state,  irq4_line_hold)/* VBL */
10671067
10681068   SEIBU_SOUND_SYSTEM_CPU(14318180/4)
1069   
1070   MCFG_SEIBU_COP_ADD("seibucop")
10691071
10701072   /* video hardware */
10711073   MCFG_SCREEN_ADD("screen", RASTER)
r26062r26063
10941096   MCFG_CPU_VBLANK_INT_DRIVER("screen", legionna_state,  irq4_line_hold)/* VBL */
10951097
10961098   SEIBU_SOUND_SYSTEM_CPU(14318180/4)
1099   
1100   MCFG_SEIBU_COP_ADD("seibucop")
10971101
10981102   /* video hardware */
10991103   MCFG_SCREEN_ADD("screen", RASTER)
r26062r26063
11211125   MCFG_CPU_VBLANK_INT_DRIVER("screen", legionna_state,  irq4_line_hold)
11221126
11231127   SEIBU2_SOUND_SYSTEM_CPU(14318180/4)
1128   
1129   MCFG_SEIBU_COP_ADD("seibucop")
11241130
11251131   /* video hardware */
11261132   MCFG_SCREEN_ADD("screen", RASTER)
r26062r26063
11491155   MCFG_CPU_VBLANK_INT_DRIVER("screen", legionna_state,  irq4_line_hold)
11501156
11511157   SEIBU2_SOUND_SYSTEM_CPU(14318180/4)
1158   
1159   MCFG_SEIBU_COP_ADD("seibucop")
11521160
11531161   /* video hardware */
11541162   MCFG_SCREEN_ADD("screen", RASTER)
r26062r26063
11761184   MCFG_CPU_VBLANK_INT_DRIVER("screen", legionna_state,  irq4_line_hold)
11771185
11781186   SEIBU2_SOUND_SYSTEM_CPU(14318180/4)
1187   
1188   MCFG_SEIBU_COP_ADD("seibucop")
11791189
11801190   /* video hardware */
11811191   MCFG_SCREEN_ADD("screen", RASTER)
r26062r26063
12041214   MCFG_CPU_VBLANK_INT_DRIVER("screen", legionna_state,  irq4_line_hold)/* VBL */
12051215
12061216   SEIBU_SOUND_SYSTEM_CPU(14318180/4)
1217   
1218   MCFG_SEIBU_COP_ADD("seibucop")
12071219
12081220   /* video hardware */
12091221   MCFG_SCREEN_ADD("screen", RASTER)
r26062r26063
12351247   MCFG_CPU_PROGRAM_MAP(cupsocbl_mem)
12361248   MCFG_CPU_VBLANK_INT_DRIVER("screen", legionna_state,  irq4_line_hold) /* VBL */
12371249
1250   MCFG_SEIBU_COP_ADD("seibucop")
1251   
12381252   /*Different Sound hardware*/
12391253   //SEIBU_SOUND_SYSTEM_CPU(14318180/4)
12401254   MCFG_CPU_ADD("audiocpu", Z80,14318180/4)

Previous 199869 Revisions Next


© 1997-2024 The MAME Team