Previous 199869 Revisions Next

r31857 Monday 1st September, 2014 at 12:06:22 UTC by Osso
kaneko_calc3_device: "standardized" it some (nw)
[src/mame/drivers]kaneko16.c
[src/mame/machine]kaneko_calc3.c kaneko_calc3.h

trunk/src/mame/drivers/kaneko16.c
r31856r31857
717717static ADDRESS_MAP_START( shogwarr, AS_PROGRAM, 16, kaneko16_shogwarr_state )
718718   AM_RANGE(0x000000, 0x03ffff) AM_ROM     // ROM
719719   AM_RANGE(0x100000, 0x10ffff) AM_RAM AM_SHARE("mainram")     // Work RAM
720   AM_RANGE(0x200000, 0x20ffff) AM_DEVREADWRITE("calc3_prot", kaneko_calc3_device, calc3_mcu_ram_r, calc3_mcu_ram_w) // Shared With MCU
721   AM_RANGE(0x280000, 0x280001) AM_DEVWRITE("calc3_prot", kaneko_calc3_device, calc3_mcu_com0_w)
722   AM_RANGE(0x290000, 0x290001) AM_DEVWRITE("calc3_prot", kaneko_calc3_device, calc3_mcu_com1_w)
723   AM_RANGE(0x2b0000, 0x2b0001) AM_DEVWRITE("calc3_prot", kaneko_calc3_device, calc3_mcu_com2_w)
720   AM_RANGE(0x200000, 0x20ffff) AM_DEVREADWRITE("calc3_prot", kaneko_calc3_device, mcu_ram_r,mcu_ram_w) // Shared With MCU
721   AM_RANGE(0x280000, 0x280001) AM_DEVWRITE("calc3_prot", kaneko_calc3_device, mcu_com0_w)
722   AM_RANGE(0x290000, 0x290001) AM_DEVWRITE("calc3_prot", kaneko_calc3_device, mcu_com1_w)
723   AM_RANGE(0x2b0000, 0x2b0001) AM_DEVWRITE("calc3_prot", kaneko_calc3_device, mcu_com2_w)
724724   //AM_RANGE(0x2c0000, 0x2c0001) // run calc 3? or irq ack?
725   AM_RANGE(0x2d0000, 0x2d0001) AM_DEVWRITE("calc3_prot", kaneko_calc3_device, calc3_mcu_com3_w)
725   AM_RANGE(0x2d0000, 0x2d0001) AM_DEVWRITE("calc3_prot", kaneko_calc3_device, mcu_com3_w)
726726   AM_RANGE(0x380000, 0x380fff) AM_RAM_DEVWRITE("palette", palette_device, write) AM_SHARE("palette")    // Palette
727727   AM_RANGE(0x400000, 0x400001) AM_DEVREADWRITE8("oki1", okim6295_device, read, write, 0x00ff) // Samples
728728   AM_RANGE(0x480000, 0x480001) AM_DEVREADWRITE8("oki2", okim6295_device, read, write, 0x00ff)
trunk/src/mame/machine/kaneko_calc3.c
r31856r31857
2828const device_type KANEKO_CALC3 = &device_creator<kaneko_calc3_device>;
2929
3030kaneko_calc3_device::kaneko_calc3_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
31   : device_t(mconfig, KANEKO_CALC3, "Kaneko CALC3 MCU", tag, owner, clock, "kaneko_calc3", __FILE__)
31   : device_t(mconfig, KANEKO_CALC3, "Kaneko CALC3 MCU", tag, owner, clock, "kaneko_calc3", __FILE__),
32      m_mcu_status(0),
33      m_mcu_command_offset(0),
34      m_mcu_crc(0),
35      m_decryption_key_byte(0),
36      m_alternateswaps(0),
37      m_shift(0),
38      m_subtracttype(0),
39      m_mode(0),
40      m_blocksize_offset(0),
41      m_dataend(0),
42      m_database(0),
43      m_writeaddress(0),
44      m_writeaddress_current(0),
45      m_dsw_addr(0),
46      m_eeprom_addr(0),
47      m_poll_addr(0),
48      m_checksumaddress(0),
49      m_mcuram(NULL)
3250{
33   memset(&m_calc3, 0, sizeof m_calc3);
51   m_data_header[0] = m_data_header[1] = 0;
3452}
3553
3654
37TIMER_CALLBACK_MEMBER( kaneko_calc3_device::run_callback )
38{
39   calc3_mcu_run(machine());
40   reset_run_timer();
41}
42
4355void kaneko_calc3_device::device_start()
4456{
45   m_calc3_mcuram = (UINT16*)auto_alloc_array_clear(this->machine(), UINT16, 0x10000/2);
46   initial_scan_tables(this->machine());
47   m_runtimer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(kaneko_calc3_device::run_callback), this));
57   m_mcuram = (UINT16*)auto_alloc_array_clear(machine(), UINT16, 0x10000/2);
58   initial_scan_tables();
59   m_runtimer = timer_alloc(MCU_RUN_TIMER);
4860
4961
50   save_item(NAME(m_calc3.mcu_status));
51   save_item(NAME(m_calc3.mcu_command_offset));
52   save_item(NAME(m_calc3.mcu_crc));
53   save_item(NAME(m_calc3.decryption_key_byte));
54   save_item(NAME(m_calc3.alternateswaps));
55   save_item(NAME(m_calc3.shift));
56   save_item(NAME(m_calc3.subtracttype));
57   save_item(NAME(m_calc3.mode));
58   save_item(NAME(m_calc3.blocksize_offset));
59   save_item(NAME(m_calc3.dataend));
60   save_item(NAME(m_calc3.database));
61   save_item(NAME(m_calc3.data_header));
62   save_item(NAME(m_calc3.writeaddress));
63   save_item(NAME(m_calc3.writeaddress_current));
64   save_item(NAME(m_calc3.dsw_addr));
65   save_item(NAME(m_calc3.eeprom_addr));
66   save_item(NAME(m_calc3.poll_addr));
67   save_item(NAME(m_calc3.checksumaddress));
68   save_pointer(NAME(m_calc3_mcuram), 0x10000/2);
62   save_item(NAME(m_mcu_status));
63   save_item(NAME(m_mcu_command_offset));
64   save_item(NAME(m_mcu_crc));
65   save_item(NAME(m_decryption_key_byte));
66   save_item(NAME(m_alternateswaps));
67   save_item(NAME(m_shift));
68   save_item(NAME(m_subtracttype));
69   save_item(NAME(m_mode));
70   save_item(NAME(m_blocksize_offset));
71   save_item(NAME(m_dataend));
72   save_item(NAME(m_database));
73   save_item(NAME(m_data_header));
74   save_item(NAME(m_writeaddress));
75   save_item(NAME(m_writeaddress_current));
76   save_item(NAME(m_dsw_addr));
77   save_item(NAME(m_eeprom_addr));
78   save_item(NAME(m_poll_addr));
79   save_item(NAME(m_checksumaddress));
80   save_pointer(NAME(m_mcuram), 0x10000/2);
6981}
7082
7183void kaneko_calc3_device::device_reset()
7284{
73   calc3_mcu_init(this->machine());
85   mcu_init();
7486   reset_run_timer();
7587}
7688
r31856r31857
7991   m_runtimer->adjust(attotime::from_hz(59.1854));
8092}
8193
94void kaneko_calc3_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
95{
96   switch(id)
97   {
98   case MCU_RUN_TIMER:
99      mcu_run();
100      reset_run_timer();
101      break;
102   default:
103      assert_always(FALSE, "Unknown id in kaneko_calc3_device::device_timer");
104   }
105}
82106
83
84107/*
85108
86109MCU Initialization command:
r31856r31857
101124*/
102125
103126
104void kaneko_calc3_device::calc3_mcu_init(running_machine &machine)
127void kaneko_calc3_device::mcu_init()
105128{
106   calc3_t &calc3 = m_calc3;
107   calc3.mcu_status = 0;
108   calc3.mcu_command_offset = 0;
129   m_mcu_status = 0;
130   m_mcu_command_offset = 0;
109131}
110132
111READ16_MEMBER(kaneko_calc3_device::calc3_mcu_ram_r)
133READ16_MEMBER(kaneko_calc3_device::mcu_ram_r)
112134{
113   return m_calc3_mcuram[offset];
135   return m_mcuram[offset];
114136}
115137
116
117WRITE16_MEMBER(kaneko_calc3_device::calc3_mcu_ram_w)
138WRITE16_MEMBER(kaneko_calc3_device::mcu_ram_w)
118139{
119   COMBINE_DATA(&m_calc3_mcuram[offset]);
140   COMBINE_DATA(&m_mcuram[offset]);
120141}
121142
122void kaneko_calc3_device::calc3_mcu_com_w(offs_t offset, UINT16 data, UINT16 mem_mask, int _n_)
143void kaneko_calc3_device::mcu_com_w(offs_t offset, UINT16 data, UINT16 mem_mask, int _n_)
123144{
124   calc3_t &calc3 = m_calc3;
125145   logerror("calc3w %d %04x %04x\n", _n_, data, mem_mask);
126   calc3.mcu_status |= (1 << _n_);
146   m_mcu_status |= (1 << _n_);
127147}
128148
129WRITE16_MEMBER(kaneko_calc3_device::calc3_mcu_com0_w){ calc3_mcu_com_w(offset, data, mem_mask, 0); }
130WRITE16_MEMBER(kaneko_calc3_device::calc3_mcu_com1_w){ calc3_mcu_com_w(offset, data, mem_mask, 1); }
131WRITE16_MEMBER(kaneko_calc3_device::calc3_mcu_com2_w){ calc3_mcu_com_w(offset, data, mem_mask, 2); }
132WRITE16_MEMBER(kaneko_calc3_device::calc3_mcu_com3_w){ calc3_mcu_com_w(offset, data, mem_mask, 3); }
149WRITE16_MEMBER(kaneko_calc3_device::mcu_com0_w){ mcu_com_w(offset, data, mem_mask, 0); }
150WRITE16_MEMBER(kaneko_calc3_device::mcu_com1_w){ mcu_com_w(offset, data, mem_mask, 1); }
151WRITE16_MEMBER(kaneko_calc3_device::mcu_com2_w){ mcu_com_w(offset, data, mem_mask, 2); }
152WRITE16_MEMBER(kaneko_calc3_device::mcu_com3_w){ mcu_com_w(offset, data, mem_mask, 3); }
133153
134154
135155
136156/*
137157
138esentially the data rom is a linked list of encrypted blocks
158essentially the data rom is a linked list of encrypted blocks
139159
140160contains the following
141161ROM ADDRESS 0x0000 = the number of tables in this rom
r31856r31857
146166         - this is usually '3', but if it's larger than 3 it enables an 'inline encryption' mode, whereby the decryption table is stored in the
147167         - right before the length register
148168
149OFFSET 1 - a 'mode' register of some sort, usually 0,1,2 or 3 for used data, shogun also called a 'blank' command (length 0) with mode 8 and mode 6
169OFFSET 1 - a 'mode' register of some sort, usually 0,1,2 or 3 for used data, shogwarr also called a 'blank' command (length 0) with mode 8 and mode 6
150170         - seems to cause eeprom access and reset write addresses
151171
152172OFFSET 2 - unknown, might be some kind of 'step' register
r31856r31857
159179
160180OFFSET 4-5 (or after the inline decryption table) - the length of the current block (so that the start of the next block can be found)
161181
162OFFSET 6-size - data for thie block
182OFFSET 6-size - data for this block
163183
164184this continues for the number of blocks specified
165185after all the blocks there is a 0x1000 block of data which is the same between games
r31856r31857
181201   part of the table to be 0
182202*/
183203
184static const INT16 calc3_keydata[0x40*0x100] = {
204static const INT16 keydata[0x40*0x100] = {
1852050x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1862060x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
1872070x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
r31856r31857
12241244   return dat;
12251245}
12261246
1227
1228int kaneko_calc3_device::calc3_decompress_table(running_machine& machine, int tabnum, UINT8* dstram, int dstoffset)
1247int kaneko_calc3_device::decompress_table(int tabnum, UINT8* dstram, int dstoffset)
12291248{
1230   calc3_t &calc3 = m_calc3;
1231   address_space &space = machine.device(":maincpu")->memory().space(AS_PROGRAM);
1249   address_space &space = machine().device(":maincpu")->memory().space(AS_PROGRAM);
12321250   UINT8* datarom = memregion(":calc3_rom")->base();
12331251
12341252   UINT8 numregions;
r31856r31857
12601278   {
12611279      UINT16 inline_table_base = 0;
12621280      UINT16 inline_table_size = 0;
1263      calc3.database = offset;
1264      calc3.blocksize_offset =    datarom[offset+0]; // location of the 'block length'
1265      calc3.mode =                datarom[offset+1];
1266      calc3.alternateswaps =             datarom[offset+2];
1267      calc3.shift = (calc3.alternateswaps &0xf0)>>4;
1268      calc3.subtracttype = (calc3.alternateswaps &0x03);
1269      calc3.alternateswaps &= 0x0c;
1270      calc3.alternateswaps >>=2;
1281      m_database = offset;
1282      m_blocksize_offset =    datarom[offset+0]; // location of the 'block length'
1283      m_mode =                datarom[offset+1];
1284      m_alternateswaps =             datarom[offset+2];
1285      m_shift = (m_alternateswaps &0xf0)>>4;
1286      m_subtracttype = (m_alternateswaps &0x03);
1287      m_alternateswaps &= 0x0c;
1288      m_alternateswaps >>=2;
12711289
1272      calc3.decryption_key_byte = datarom[offset+3];
1290      m_decryption_key_byte = datarom[offset+3];
12731291
12741292
12751293      // if blocksize_offset > 3, it appears to specify the encryption table as 'inline' which can be of any size (odd or even) and loops over the bytes to decrypt
12761294      // the decryption key specified seems to be ignored?
1277      if (calc3.blocksize_offset>3)
1295      if (m_blocksize_offset>3)
12781296      {
12791297         inline_table_base = offset+4;
1280         inline_table_size = calc3.blocksize_offset-3;
1298         inline_table_size = m_blocksize_offset-3;
12811299      }
12821300
1283      offset+= calc3.blocksize_offset+1;
1301      offset+= m_blocksize_offset+1;
12841302      length = datarom[offset+0] | (datarom[offset+1]<<8);
12851303      offset+=2;
12861304
1287#if CALC3_VERBOSE_OUTPUT
1305#if VERBOSE_OUTPUT
12881306      if (inline_table_size)
12891307      {
1290         printf("Block %02x Found Base %04x - Inline Encryption (size %02x) - Mode? %02x Shift %01x Subtract Type %01x AltSwaps %01x Key (unused?) %02x Length %04x\n", tabnum, calc3.database, inline_table_size, calc3.shift, calc3.mode, calc3.subtracttype, calc3.alternateswaps, calc3.decryption_key_byte, length);
1308         printf("Block %02x Found Base %04x - Inline Encryption (size %02x) - Mode? %02x Shift %01x Subtract Type %01x AltSwaps %01x Key (unused?) %02x Length %04x\n", tabnum, m_database, inline_table_size, m_shift, m_mode, m_subtracttype, m_alternateswaps, m_decryption_key_byte, length);
12911309      }
12921310      else
12931311      {
1294         printf("Block %02x Found Base %04x - Mode? %02x Shift %01x Subtract Type %01x AltSwaps %01x Key %02x Length %04x\n", tabnum, calc3.database, calc3.mode, calc3.shift, calc3.subtracttype, calc3.alternateswaps, calc3.decryption_key_byte, length);
1312         printf("Block %02x Found Base %04x - Mode? %02x Shift %01x Subtract Type %01x AltSwaps %01x Key %02x Length %04x\n", tabnum, m_database, m_mode, m_shift, m_subtracttype, m_alternateswaps, m_decryption_key_byte, length);
12951313      }
12961314#endif
12971315      // copy + decrypt the table to the specified memory area
r31856r31857
13051323            //printf("CALC3: requested 0 length table!\n");
13061324            // -- seems to be 'reset stack' to default for the protection table writes
13071325
1308            // except this will break shogun going into game, must be specific conditions for
1326            // except this will break shogwarr going into game, must be specific conditions for
13091327            // this, or it can remember addresses and restore those
13101328
13111329            // hack, set it to a known address instead of trying to restore to anywhere specific..
r31856r31857
13141332
13151333            // !dstram is used because we don't want to process these during our initial table scan, only when the game asks!
13161334
1317            if (calc3.mode==0x06)
1335            if (m_mode==0x06)
13181336            {
1319               calc3.writeaddress_current = 0x202000; // this is reasoanble for brapboys, not sure about shogun, needs emulating properly!
1320               //calc3.writeaddress_current = 0x20c000;
1337               m_writeaddress_current = 0x202000; // this is reasonable for brapboys, not sure about shogwarr, needs emulating properly!
1338               //m_writeaddress_current = 0x20c000;
13211339            }
1322            else if (calc3.mode==0x07)
1340            else if (m_mode==0x07)
13231341            {
13241342               // also calls empty table with Mode? 07
13251343               // maybe they reset to different points?
13261344            }
1327            else if (calc3.mode==0x08 && !dstram)
1345            else if (m_mode==0x08 && !dstram)
13281346            {
13291347               //printf("save to eeprom\n");
13301348
r31856r31857
13331351
13341352                  for (i=0;i<0x80;i++)
13351353                  {
1336                     eeprom_space.write_byte(i, space.read_byte(calc3.eeprom_addr+0x200000+i));
1354                     eeprom_space.write_byte(i, space.read_byte(m_eeprom_addr+0x200000+i));
13371355                  }
13381356
13391357               }
r31856r31857
13601378
13611379
13621380               /* special case for Shogun Warriors table 0x40 */
1363               if (calc3.subtracttype==3 && calc3.alternateswaps ==0)
1381               if (m_subtracttype==3 && m_alternateswaps ==0)
13641382               {
13651383                  UINT8 inlinet = datarom[inline_table_base + (i%inline_table_size)];
13661384                  dat = datarom[offset+i];
r31856r31857
13811399                        UINT8 inlinet = datarom[inline_table_base + (i%inline_table_size)];
13821400                        dat = datarom[offset+i];
13831401                        dat -= inlinet;
1384                        dat = shift_bits(dat, calc3.shift);
1402                        dat = shift_bits(dat, m_shift);
13851403                     }
13861404                     else
13871405                     {
13881406                        UINT8 inlinet = datarom[inline_table_base + (i%inline_table_size)];
13891407                        dat = datarom[offset+i];
13901408
1391                        if (calc3.subtracttype!=0x02)
1409                        if (m_subtracttype!=0x02)
13921410                        {
13931411                           dat -= inlinet;
13941412                           dat -= extra[(i%inline_table_size)>>1];
r31856r31857
13991417                           dat += extra[(i%inline_table_size)>>1];
14001418                        }
14011419
1402                        dat = shift_bits(dat, 8-calc3.shift);
1420                        dat = shift_bits(dat, 8-m_shift);
14031421                     }
14041422                  }
14051423                  else
r31856r31857
14091427                        UINT8 inlinet = datarom[inline_table_base + (i%inline_table_size)];
14101428                        dat = datarom[offset+i];
14111429                        dat -= inlinet;
1412                        dat = shift_bits(dat, calc3.shift);
1430                        dat = shift_bits(dat, m_shift);
14131431                     }
14141432                     else
14151433                     {
14161434                        dat = datarom[offset+i];
14171435
1418                        if (calc3.subtracttype!=0x02)
1436                        if (m_subtracttype!=0x02)
14191437                        {
14201438                           dat -= extra2[(i%inline_table_size)>>1];
14211439                        }
r31856r31857
14231441                        {
14241442                           dat += extra2[(i%inline_table_size)>>1];
14251443                        }
1426                        dat = shift_bits(dat, 8-calc3.shift);
1444                        dat = shift_bits(dat, 8-m_shift);
14271445                     }
14281446                  }
14291447               }
r31856r31857
14391457                  }
14401458               }
14411459               else
1442                  calc3.data_header[local_counter]=dat;
1460                  m_data_header[local_counter]=dat;
14431461
14441462               ++local_counter;
14451463            }
14461464         }
14471465         else
14481466         {
1449            const INT16* key = calc3_keydata+(calc3.decryption_key_byte*0x40);
1467            const INT16* key = keydata+(m_decryption_key_byte*0x40);
14501468
14511469            if (key[0] == -1)
14521470            {
r31856r31857
14591477               UINT8 keydat = (UINT8)key[i&0x3f];
14601478
14611479               {
1462                  if (calc3.subtracttype==0)
1480                  if (m_subtracttype==0)
14631481                  {
14641482                     //dat = dat;
14651483                  }
1466                  else if (calc3.subtracttype==1)
1484                  else if (m_subtracttype==1)
14671485                  {
14681486                     if ((i&1)==1) dat += keydat;
14691487                     else dat -= keydat;
14701488                  }
1471                  else if (calc3.subtracttype==2)
1489                  else if (m_subtracttype==2)
14721490                  {
14731491                     if ((i&1)==0) dat += keydat;
14741492                     else dat -= keydat;
14751493                  }
1476                  else if (calc3.subtracttype==3)
1494                  else if (m_subtracttype==3)
14771495                  {
14781496                     dat -= keydat;
14791497                  }
14801498
1481                  if (calc3.alternateswaps == 0)
1499                  if (m_alternateswaps == 0)
14821500                  {
1483                     if ((i&1)==0) dat = shift_bits(dat, 8-calc3.shift);
1484                     else          dat = shift_bits(dat, calc3.shift);
1501                     if ((i&1)==0) dat = shift_bits(dat, 8-m_shift);
1502                     else          dat = shift_bits(dat, m_shift);
14851503                  }
1486                  else if (calc3.alternateswaps==1)
1504                  else if (m_alternateswaps==1)
14871505                  {
1488                     dat = shift_bits(dat, 8-calc3.shift);
1506                     dat = shift_bits(dat, 8-m_shift);
14891507                  }
1490                  else if (calc3.alternateswaps==2)
1508                  else if (m_alternateswaps==2)
14911509                  {
1492                     dat = shift_bits(dat, calc3.shift);
1510                     dat = shift_bits(dat, m_shift);
14931511                  }
1494                  else if (calc3.alternateswaps==3)
1512                  else if (m_alternateswaps==3)
14951513                  {
14961514                     // same as 0
1497                     if ((i&1)==0) dat = shift_bits(dat, 8-calc3.shift);
1498                     else          dat = shift_bits(dat, calc3.shift);
1515                     if ((i&1)==0) dat = shift_bits(dat, 8-m_shift);
1516                     else          dat = shift_bits(dat, m_shift);
14991517                  }
15001518               }
15011519
r31856r31857
15101528                  }
15111529               }
15121530               else
1513                  calc3.data_header[local_counter]=dat;
1531                  m_data_header[local_counter]=dat;
15141532
15151533               ++local_counter;
15161534
r31856r31857
15191537         }
15201538      }
15211539
1522      calc3.dataend = offset+length+1;
1540      m_dataend = offset+length+1;
15231541   }
15241542
1525   //printf("data base %04x data end %04x\n", calc3.database, calc3.dataend);
1543   //printf("data base %04x data end %04x\n", m_database, m_dataend);
15261544
15271545   return length;
15281546
15291547}
15301548
1531
1532
1533void kaneko_calc3_device::initial_scan_tables(running_machine& machine)
1549void kaneko_calc3_device::initial_scan_tables()
15341550{
1535   calc3_t &calc3 = m_calc3;
15361551   UINT8 numregions;
15371552   UINT8* datarom = memregion(":calc3_rom")->base();
15381553
15391554   int x;
15401555
1541   calc3.mcu_crc = 0;
1556   m_mcu_crc = 0;
15421557   for (x=0;x<0x20000;x++)
15431558   {
1544      calc3.mcu_crc+=datarom[x];
1559      m_mcu_crc+=datarom[x];
15451560   }
1546   //printf("crc %04x\n",calc3.mcu_crc);
1561   //printf("crc %04x\n",m_mcu_crc);
15471562   numregions = datarom[0];
15481563
15491564   for (x=0;x<numregions;x++)
15501565   {
15511566      dynamic_buffer tmpdstram(0x2000);
1552#if CALC3_VERBOSE_OUTPUT
1567#if VERBOSE_OUTPUT
15531568      int length;
15541569#endif
15551570
15561571      memset(tmpdstram, 0x00,0x2000);
15571572
1558#if CALC3_VERBOSE_OUTPUT
1559      length = calc3_decompress_table(machine, x, tmpdstram, 0);
1573#if VERBOSE_OUTPUT
1574      length = decompress_table(x, tmpdstram, 0);
15601575      // dump to file
15611576      if (length)
15621577      {
15631578         FILE *fp;
15641579         char filename[256];
15651580
1566         if (calc3.blocksize_offset==3)
1581         if (m_blocksize_offset==3)
15671582         {
15681583            sprintf(filename,"data_%s_table_%04x k%02x m%02x u%02x length %04x",
15691584                  machine().system().name,
1570                  x, calc3.decryption_key_byte, calc3.mode, calc3.alternateswaps, length);
1585                  x, m_decryption_key_byte, m_mode, m_alternateswaps, length);
15711586         }
15721587         else
15731588         {
15741589            sprintf(filename,"data_%s_table_%04x k%02x (use indirect size %02x) m%02x u%02x length %04x",
15751590               machine().system().name,
1576               x, calc3.decryption_key_byte, calc3.blocksize_offset-3, calc3.mode, calc3.alternateswaps, length);
1591               x, m_decryption_key_byte, m_blocksize_offset-3, m_mode, m_alternateswaps, length);
15771592         }
15781593
15791594         fp=fopen(filename, "w+b");
r31856r31857
15911606   // to that extra block of data
15921607
15931608   // dump out the 0x1000 sized block at the end
1594#if CALC3_VERBOSE_OUTPUT
1609#if VERBOSE_OUTPUT
15951610   {
15961611      FILE *fp;
15971612      char filename[256];
15981613
15991614      sprintf(filename,"data_%s_finalblock",
1600      machine.system().name);
1615      machine().system().name);
16011616
16021617      fp=fopen(filename, "w+b");
16031618      if (fp)
16041619      {
1605         fwrite(&datarom[calc3.dataend], 0x1000, 1, fp);
1620         fwrite(&datarom[m_dataend], 0x1000, 1, fp);
16061621         fclose(fp);
16071622      }
16081623   }
16091624#endif
16101625}
16111626
1612
1613
1614void kaneko_calc3_device::calc3_mcu_run(running_machine &machine)
1627void kaneko_calc3_device::mcu_run()
16151628{
1616   calc3_t &calc3 = m_calc3;
16171629   UINT16 mcu_command;
16181630   int i;
1619   address_space &space = machine.device(":maincpu")->memory().space(AS_PROGRAM);
1631   address_space &space = machine().device(":maincpu")->memory().space(AS_PROGRAM);
16201632
1621   if ( calc3.mcu_status != (1|2|4|8) )    return;
1633   if ( m_mcu_status != (1|2|4|8) )    return;
16221634
1623   if (calc3.dsw_addr) space.write_byte(calc3.dsw_addr+0x200000, ( ~ioport(":DSW1")->read())&0xff); // // DSW // dsw actually updates in realtime - mcu reads+writes it every frame
1635   if (m_dsw_addr) space.write_byte(m_dsw_addr+0x200000, ( ~ioport(":DSW1")->read())&0xff); // // DSW // dsw actually updates in realtime - mcu reads+writes it every frame
16241636
16251637
1626   //calc3.mcu_status = 0;
1638   //m_mcu_status = 0;
16271639
1628   mcu_command = m_calc3_mcuram[calc3.mcu_command_offset/2 + 0];
1640   mcu_command = m_mcuram[m_mcu_command_offset/2 + 0];
16291641
16301642   if (mcu_command == 0) return;
16311643
16321644   logerror("%s : MCU executed command at %04X: %04X\n",
1633      machine.describe_context(),calc3.mcu_command_offset,mcu_command);
1645      machine().describe_context(),m_mcu_command_offset,mcu_command);
16341646
16351647
16361648   if (mcu_command>0)
r31856r31857
16391651      if (mcu_command == 0xff)
16401652      {
16411653         // clear old command (handshake to main cpu)
1642         m_calc3_mcuram[(calc3.mcu_command_offset>>1)+0] = 0x0000;
1654         m_mcuram[(m_mcu_command_offset>>1)+0] = 0x0000;
16431655
16441656
1645         calc3.dsw_addr =           m_calc3_mcuram[(0>>1) + 1];
1646         calc3.eeprom_addr =        m_calc3_mcuram[(0>>1) + 2];
1647         calc3.mcu_command_offset = m_calc3_mcuram[(0>>1) + 3];
1648         calc3.poll_addr =          m_calc3_mcuram[(0>>1) + 4];
1649         calc3.checksumaddress =    m_calc3_mcuram[(0>>1) + 5];
1650         calc3.writeaddress =      (m_calc3_mcuram[(0>>1) + 6] << 16) |
1651                              (m_calc3_mcuram[(0>>1) + 7]);
1657         m_dsw_addr =           m_mcuram[(0>>1) + 1];
1658         m_eeprom_addr =        m_mcuram[(0>>1) + 2];
1659         m_mcu_command_offset = m_mcuram[(0>>1) + 3];
1660         m_poll_addr =          m_mcuram[(0>>1) + 4];
1661         m_checksumaddress =    m_mcuram[(0>>1) + 5];
1662         m_writeaddress =      (m_mcuram[(0>>1) + 6] << 16) |
1663                              (m_mcuram[(0>>1) + 7]);
16521664
16531665         // set our current write / stack pointer to the address specified
1654         calc3.writeaddress_current = calc3.writeaddress;
1655#if CALC3_VERBOSE_OUTPUT
1656         printf("Calc 3 Init Command - %04x DSW addr\n",  calc3.dsw_addr);
1657         printf("Calc 3 Init Command - %04x Eeprom Address\n",  calc3.eeprom_addr);
1658         printf("Calc 3 Init Command - %04x Future Commands Base\n",  calc3.mcu_command_offset);
1659         printf("Calc 3 Init Command - %04x Poll / Busy Address\n",  calc3.poll_addr);
1660         printf("Calc 3 Init Command - %04x ROM Checksum Address\n",  calc3.checksumaddress);
1661         printf("Calc 3 Init Command - %08x Data Write Address\n",  calc3.writeaddress);
1666         m_writeaddress_current = m_writeaddress;
1667#if VERBOSE_OUTPUT
1668         printf("Calc 3 Init Command - %04x DSW addr\n",  m_dsw_addr);
1669         printf("Calc 3 Init Command - %04x Eeprom Address\n",  m_eeprom_addr);
1670         printf("Calc 3 Init Command - %04x Future Commands Base\n",  m_mcu_command_offset);
1671         printf("Calc 3 Init Command - %04x Poll / Busy Address\n",  m_poll_addr);
1672         printf("Calc 3 Init Command - %04x ROM Checksum Address\n",  m_checksumaddress);
1673         printf("Calc 3 Init Command - %08x Data Write Address\n",  m_writeaddress);
16621674#endif
1663   //      space.write_byte(calc3.dsw_addr+0x200000, ( ~ioport("DSW1")->read())&0xff); // // DSW // dsw actually updates in realtime - mcu reads+writes it every frame
1675   //      space.write_byte(m_dsw_addr+0x200000, ( ~ioport("DSW1")->read())&0xff); // // DSW // dsw actually updates in realtime - mcu reads+writes it every frame
16641676
1665         m_calc3_mcuram[calc3.checksumaddress / 2] = calc3.mcu_crc;              // MCU Rom Checksum!
1677         m_mcuram[m_checksumaddress / 2] = m_mcu_crc;              // MCU Rom Checksum!
16661678
16671679#if 0
16681680         for (i=0;i<0x40;i++)
16691681         {
1670            m_calc3_mcuram[(calc3.eeprom_addr / 2)+i] = kaneko16_eeprom_data[i];//((eepromData[i]&0xff00)>>8) |  ((eepromData[i]&0x00ff)<<8);
1682            m_mcuram[(m_eeprom_addr / 2)+i] = kaneko16_eeprom_data[i];//((eepromData[i]&0xff00)>>8) |  ((eepromData[i]&0x00ff)<<8);
16711683         }
16721684#endif
16731685         {
r31856r31857
16751687
16761688            for (i=0;i<0x80;i++)
16771689            {
1678               space.write_byte(calc3.eeprom_addr+0x200000+i, eeprom_space.read_byte(i));
1690               space.write_byte(m_eeprom_addr+0x200000+i, eeprom_space.read_byte(i));
16791691            }
16801692
16811693         }
r31856r31857
16881700         int i;
16891701
16901702         // clear old command (handshake to main cpu)
1691         m_calc3_mcuram[calc3.mcu_command_offset>>1] = 0x0000;;
1703         m_mcuram[m_mcu_command_offset>>1] = 0x0000;;
16921704
16931705         logerror("Calc3 transfer request, %d transfers\n", num_transfers);
16941706
16951707         for (i=0;i<num_transfers;i++)
16961708         {
1697            int param1 = m_calc3_mcuram[(calc3.mcu_command_offset>>1) + 1 + (2*i)];
1698            int param2 = m_calc3_mcuram[(calc3.mcu_command_offset>>1) + 2 + (2*i)];
1709            int param1 = m_mcuram[(m_mcu_command_offset>>1) + 1 + (2*i)];
1710            int param2 = m_mcuram[(m_mcu_command_offset>>1) + 2 + (2*i)];
16991711            UINT8  commandtabl = (param1&0xff00) >> 8;
17001712            UINT16 commandaddr =param2;// (param1&0x00ff) | (param2&0xff00);
17011713            UINT8  commandunk =  (param1&0x00ff); // brap boys sets.. seems to cause further writebasck address displacement?? (when tested on hw it looked like a simple +, but that doesn't work for brapboys...)
1702#if CALC3_VERBOSE_OUTPUT
1714#if VERBOSE_OUTPUT
17031715            printf("transfer %d table %02x writeback address %04x unknown %02x\n", i, commandtabl, commandaddr, commandunk);
17041716#endif
17051717            {
17061718               int length;
17071719
1708               length = calc3_decompress_table(machine, commandtabl, 0, calc3.writeaddress_current-2);
1720               length = decompress_table(commandtabl, 0, m_writeaddress_current-2);
17091721
17101722               if (length)
17111723               {
17121724                  int write=commandaddr;
1713#if CALC3_VERBOSE_OUTPUT
1714                  printf("writing back address %08x to %08x %08x\n", calc3.writeaddress_current, commandaddr,write);
1725#if VERBOSE_OUTPUT
1726                  printf("writing back address %08x to %08x %08x\n", m_writeaddress_current, commandaddr,write);
17151727#endif
17161728
1717                  space.write_byte(write+0x200000, calc3.data_header[0]);
1718                  space.write_byte(write+0x200001, calc3.data_header[1]);
1729                  space.write_byte(write+0x200000, m_data_header[0]);
1730                  space.write_byte(write+0x200001, m_data_header[1]);
17191731
17201732                  write=commandaddr+(char)commandunk;
1721                  space.write_word(write+0x200000, (calc3.writeaddress_current>>16)&0xffff);
1722                  space.write_word(write+0x200002,  (calc3.writeaddress_current&0xffff));
1733                  space.write_word(write+0x200000, (m_writeaddress_current>>16)&0xffff);
1734                  space.write_word(write+0x200002,  (m_writeaddress_current&0xffff));
17231735
1724                  calc3.writeaddress_current += ((length+3)&(~1));
1736                  m_writeaddress_current += ((length+3)&(~1));
17251737               }
17261738
17271739            }
trunk/src/mame/machine/kaneko_calc3.h
r31856r31857
11/* CALC 3 */
22
3#define CALC3_VERBOSE_OUTPUT 0
3#define VERBOSE_OUTPUT 0
44
55
6struct calc3_t
7{
8   int mcu_status;
9   int mcu_command_offset;
10   UINT16 mcu_crc;
11   UINT8 decryption_key_byte;
12   UINT8 alternateswaps;
13   UINT8 shift;
14   UINT8 subtracttype;
15   UINT8 mode;
16   UINT8 blocksize_offset;
17   UINT16 dataend;
18   UINT16 database;
19   int data_header[2];
20   UINT32 writeaddress;
21   UINT32 writeaddress_current;
22   UINT16 dsw_addr;
23   UINT16 eeprom_addr;
24   UINT16 poll_addr;
25   UINT16 checksumaddress;
26};
276
28
29
30
317class kaneko_calc3_device : public device_t
328{
339public:
3410   kaneko_calc3_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
3511
36   DECLARE_READ16_MEMBER(calc3_mcu_ram_r);
37   DECLARE_WRITE16_MEMBER(calc3_mcu_ram_w);
12   DECLARE_READ16_MEMBER(mcu_ram_r);
13   DECLARE_WRITE16_MEMBER(mcu_ram_w);
3814
39   DECLARE_WRITE16_MEMBER(calc3_mcu_com0_w);
40   DECLARE_WRITE16_MEMBER(calc3_mcu_com1_w);
41   DECLARE_WRITE16_MEMBER(calc3_mcu_com2_w);
42   DECLARE_WRITE16_MEMBER(calc3_mcu_com3_w);
15   DECLARE_WRITE16_MEMBER(mcu_com0_w);
16   DECLARE_WRITE16_MEMBER(mcu_com1_w);
17   DECLARE_WRITE16_MEMBER(mcu_com2_w);
18   DECLARE_WRITE16_MEMBER(mcu_com3_w);
4319
4420   void reset_run_timer();
4521
46   void calc3_mcu_run(running_machine &machine);
47
22   void mcu_run();
23   
4824protected:
4925   virtual void device_start();
5026   virtual void device_reset();
27   virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
5128
5229private:
53   UINT16* m_calc3_mcuram;
54   void calc3_mcu_init(running_machine &machine);
55   void initial_scan_tables(running_machine& machine);
56   TIMER_CALLBACK_MEMBER(run_callback);
57
58   calc3_t m_calc3;
59   void calc3_mcu_com_w(offs_t offset, UINT16 data, UINT16 mem_mask, int _n_);
60   UINT8 shift_bits(UINT8 dat, int bits);
61   int calc3_decompress_table(running_machine& machine, int tabnum, UINT8* dstram, int dstoffset);
62
30   int m_mcu_status;
31   int m_mcu_command_offset;
32   UINT16 m_mcu_crc;
33   UINT8 m_decryption_key_byte;
34   UINT8 m_alternateswaps;
35   UINT8 m_shift;
36   UINT8 m_subtracttype;
37   UINT8 m_mode;
38   UINT8 m_blocksize_offset;
39   UINT16 m_dataend;
40   UINT16 m_database;
41   int m_data_header[2];
42   UINT32 m_writeaddress;
43   UINT32 m_writeaddress_current;
44   UINT16 m_dsw_addr;
45   UINT16 m_eeprom_addr;
46   UINT16 m_poll_addr;
47   UINT16 m_checksumaddress;
48   UINT16* m_mcuram;
6349   emu_timer* m_runtimer;
64
50   
51   enum
52   {
53      MCU_RUN_TIMER
54   };
55   
56   void mcu_init();
57   void initial_scan_tables();
58   void mcu_com_w(offs_t offset, UINT16 data, UINT16 mem_mask, int _n_);
59   UINT8 shift_bits(UINT8 dat, int bits);
60   int decompress_table(int tabnum, UINT8* dstram, int dstoffset);
6561};
6662
6763

Previous 199869 Revisions Next


© 1997-2024 The MAME Team