Previous 199869 Revisions Next

r34662 Tuesday 27th January, 2015 at 18:22:51 UTC by David Haywood
start using callbacks for decathlete style decompression (start of refactoring) (nw)
[src/mame/drivers]stv.c
[src/mame/includes]stv.h
[src/mame/machine]315-5838_317-0229_comp.c 315-5838_317-0229_comp.h

trunk/src/mame/drivers/stv.c
r243173r243174
10261026   MCFG_SET_READ_CALLBACK(stv_state, crypt_read_callback)
10271027MACHINE_CONFIG_END
10281028
1029
1030UINT16 stv_state::crypt_read_callback_ch1(UINT32 addr)
1031{
1032   return m_maincpu->space().read_word(0x02000000 + 0x1000000 + (addr * 2));
1033}
1034
1035UINT16 stv_state::crypt_read_callback_ch2(UINT32 addr)
1036{
1037   return m_maincpu->space().read_word(0x02000000 + 0x0000000 + (addr * 2));
1038}
1039
10291040static MACHINE_CONFIG_DERIVED( stv_5838, stv )
10301041   MCFG_DEVICE_ADD("315_5838", SEGA315_5838_COMP, 0)
1031//   MCFG_SET_5838_READ_CALLBACK(stv_state, crypt_read_callback)
1042   MCFG_SET_5838_READ_CALLBACK_CH1(stv_state, crypt_read_callback_ch1)
1043   MCFG_SET_5838_READ_CALLBACK_CH2(stv_state, crypt_read_callback_ch2)
10321044MACHINE_CONFIG_END
10331045
10341046
trunk/src/mame/includes/stv.h
r243173r243174
815815   optional_device<sega_315_5881_crypt_device> m_cryptdevice;
816816   optional_device<sega_315_5838_comp_device> m_5838crypt;
817817   UINT16 crypt_read_callback(UINT32 addr);
818   UINT16 crypt_read_callback_ch1(UINT32 addr);
819   UINT16 crypt_read_callback_ch2(UINT32 addr);
818820};
819821
820822
trunk/src/mame/machine/315-5838_317-0229_comp.c
r243173r243174
99   Decathlete uses it to compress ALL the game graphics, Dead or Alive uses it for a
1010   dumb security check, decompressing a single string.
1111
12   Each channel appears to be connected to a different set of ROMs, however there is
13   defintiely only 315-5838 single chip.
14
1215   Dead of Alive only uses a single channel, and has the source data in RAM, not ROM.
1316   This is similar to how some 5881 games were set up, with the ST-V versions decrypting
1417   data directly from ROM and the Model 2 ones using a RAM source buffer.
1518
19   Looking at the values read I don't think there is any address based encryption, for
20   example many blocks where you'd expect a zero fill start with repeating patterns
21   of 8f708f70 (different lengths) which would appear to relate to compressed 0x00 data
22
23   read addr 0071253c, blah_r 8f708f70 - read count count 00000004
24   read addr 00712540, blah_r 8f708f70 - read count count 00000008
25   read addr 00712544, blah_r 8f708f70 - read count count 0000000c
26   read addr 00712548, blah_r 8f708f70 - read count count 00000010
27   read addr 0071254c, blah_r 8f708f70 - read count count 00000014
28   read addr 00712550, blah_r 8f708f70 - read count count 00000018
29   read addr 00712554, blah_r 8f708f70 - read count count 0000001c
30
1631*/
1732
1833#include "emu.h"
r243173r243174
2035
2136extern const device_type SEGA315_5838_COMP = &device_creator<sega_315_5838_comp_device>;
2237
38//#define DEBUG_DATA_DUMP
2339
2440sega_315_5838_comp_device::sega_315_5838_comp_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
2541   : device_t(mconfig, SEGA315_5838_COMP, "Sega 315-5838 / 317-0029 Compression (Encryption?)", tag, owner, clock, "SEGA315_5838", __FILE__)
r243173r243174
3349   m_decathlt_lastcount = 0;
3450   m_decathlt_prot_uploadmode = 0;
3551   m_decathlt_prot_uploadoffset = 0;
52
53   m_read_ch1.bind_relative_to(*owner());
54   m_read_ch2.bind_relative_to(*owner());
3655}
3756
3857void sega_315_5838_comp_device::device_reset()
r243173r243174
5372*
5473**************************/
5574
56READ32_MEMBER( sega_315_5838_comp_device::decathlt_prot_r )
75#ifdef DEBUG_DATA_DUMP
76FILE* tempfile;
77#endif
78
79
80READ32_MEMBER(sega_315_5838_comp_device::decathlt_prot_r)
5781{
58   // the offsets written to the protection device definitely only refer to 2 of the roms
59   //  it's a fair assumption to say that only those 2 are connected to the protection device
60   UINT8 *ROM = (UINT8 *)memregion(":abus")->base()+0x1000000;
61   UINT32 *fake0 = (UINT32*)memregion( ":fake0" )->base();
82   return genericdecathlt_prot_r(offset, mem_mask, 0);
83}
6284
85READ32_MEMBER(sega_315_5838_comp_device::decathlt_prot_ch2_r)
86{
87   return genericdecathlt_prot_r(offset, mem_mask, 1);
88}
89
90
91UINT32 sega_315_5838_comp_device::genericdecathlt_prot_r(UINT32 offset, UINT32 mem_mask, int which)
92{
93
94//   UINT32 *fake0 = (UINT32*)memregion( ":fake0" )->base();
95
6396   if (offset==2)
6497   {
65      UINT32 retvalue = 0xffff;
98//      UINT32 retvalue = 0xffff;
6699
67100      switch (m_decathlt_protregs[0])
68101      {
69102         default:
70         retvalue = ROM[(m_decathlt_protregs[0]*2)-2];
71         retvalue <<= 8;
72         retvalue |= ROM[((m_decathlt_protregs[0]+1)*2)+1-2];
73         retvalue <<= 8;
74         retvalue |= ROM[((m_decathlt_protregs[0]+1)*2)-2];
75         retvalue <<= 8;
76         retvalue |= ROM[((m_decathlt_protregs[0]+2)*2)+1-2];
103
77104         m_decathlt_lastcount++;
78         logerror("read addr %08x, blah_r %08x - read count count %08x\n", m_decathlt_protregs[0], retvalue, m_decathlt_lastcount*4);
79         m_decathlt_protregs[0]+=2;
80         return retvalue;
81105
106         UINT32 tempdata = 0;
107
108         if (which == 0)
109         {
110            tempdata |= m_read_ch1(m_decathlt_protregs[0]) << 16;
111            m_decathlt_protregs[0]++;
112            tempdata |= m_read_ch1(m_decathlt_protregs[0]) << 0;
113            m_decathlt_protregs[0]++;
114         }
115         else
116         {
117            tempdata |= m_read_ch2(m_decathlt_protregs[0]) << 16;
118            m_decathlt_protregs[0]++;
119            tempdata |= m_read_ch2(m_decathlt_protregs[0]) << 0;
120            m_decathlt_protregs[0]++;
121         }
122
123         #ifdef DEBUG_DATA_DUMP
124         //printf("read addr %08x, blah_r %08x - read count count %08x\n", m_decathlt_protregs[0]*2, tempdata,  m_decathlt_lastcount*4);
125         fwrite(&tempdata, 1, 4, tempfile);
126         #else
127         logerror("read addr %08x, blah_r %08x - read count count %08x\n", m_decathlt_protregs[0]*2, tempdata,  m_decathlt_lastcount*4);
128         #endif
129
130         return tempdata;
131#if 0
82132         case 0x03228e4:
83133            if (fake0) retvalue = fake0[(((0x20080/4)+m_decathlt_lastcount))];
84134            m_decathlt_lastcount++;
r243173r243174
128178         case 0x0018424:
129179
130180            return retvalue;
181#endif
131182      }
132183
133184
r243173r243174
156207      //if (m_decathlt_part==0) logerror("%d, last read count was %06x\n",which, m_decathlt_lastcount*4);
157208      m_decathlt_lastcount = 0;
158209      if (m_decathlt_part==1) logerror("%d Decathlete prot W offset %04x data %08x, %08x, >>> regs %08x <<<<, %08x, %08x, %08x\n",which, offset, data, m_decathlt_protregs[0], m_decathlt_protregs[0]*4, m_decathlt_protregs[1], m_decathlt_protregs[2], m_decathlt_protregs[3]);
210
211#ifdef DEBUG_DATA_DUMP
212      if (mem_mask == 0x0000ffff)
213      {
214         if (tempfile)
215            fclose(tempfile);
216
217         char filename[256];
218         sprintf(filename, "%d_compressed_%08x", which, m_decathlt_protregs[0] );
219         tempfile = fopen(filename, "w+b");
220      }
221#endif
222
159223   }
160224
161225   if (offset==1) // uploads 2 tables...
r243173r243174
287351
288352   cpu->space(AS_PROGRAM).install_readwrite_handler(0x37FFFF0, 0x37FFFFF, read32_delegate(FUNC(sega_315_5838_comp_device::decathlt_prot_r), this), write32_delegate(FUNC(sega_315_5838_comp_device::decathlt_prot1_w), this));
289353   /* It accesses the device at this address too, with different tables, for the game textures, should it just act like a mirror, or a secondary device? */
290   cpu->space(AS_PROGRAM).install_readwrite_handler(0x27FFFF0, 0x27FFFFF, read32_delegate(FUNC(sega_315_5838_comp_device::decathlt_prot_r), this), write32_delegate(FUNC(sega_315_5838_comp_device::decathlt_prot2_w), this));
354   cpu->space(AS_PROGRAM).install_readwrite_handler(0x27FFFF0, 0x27FFFFF, read32_delegate(FUNC(sega_315_5838_comp_device::decathlt_prot_ch2_r), this), write32_delegate(FUNC(sega_315_5838_comp_device::decathlt_prot2_w), this));
291355}
292356
293357
trunk/src/mame/machine/315-5838_317-0229_comp.h
r243173r243174
44#ifndef __SEGA315_5838_COMP__
55#define __SEGA315_5838_COMP__
66
7typedef device_delegate<UINT16 (UINT32)> sega_m2_read_delegate;
7typedef device_delegate<UINT16 (UINT32)> sega_dec_read_delegate;
88
99extern const device_type SEGA315_5838_COMP;
1010
11#define MCFG_SET_5838_READ_CALLBACK( _class, _method) \
12   sega_315_5838_comp_device::set_read_cb(*device, sega_m2_read_delegate(&_class::_method, #_class "::" #_method, NULL, (_class *)0));
11#define MCFG_SET_5838_READ_CALLBACK_CH1( _class, _method) \
12   sega_315_5838_comp_device::set_read_cb_ch1(*device, sega_m2_read_delegate(&_class::_method, #_class "::" #_method, NULL, (_class *)0));
1313
14#define MCFG_SET_5838_READ_CALLBACK_CH2( _class, _method) \
15   sega_315_5838_comp_device::set_read_cb_ch2(*device, sega_m2_read_delegate(&_class::_method, #_class "::" #_method, NULL, (_class *)0));
1416
1517class sega_315_5838_comp_device :  public device_t
1618{
r243173r243174
1820   // construction/destruction
1921   sega_315_5838_comp_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
2022
21   sega_m2_read_delegate m_read;
23   sega_dec_read_delegate m_read_ch1;
24   sega_dec_read_delegate m_read_ch2;
2225
23   static void set_read_cb(device_t &device,sega_m2_read_delegate readcb)
26   static void set_read_cb_ch1(device_t &device,sega_dec_read_delegate readcb)
2427   {
2528      sega_315_5838_comp_device &dev = downcast<sega_315_5838_comp_device &>(device);
26      dev.m_read = readcb;
29      dev.m_read_ch1 = readcb;
2730   }
2831
32   static void set_read_cb_ch2(device_t &device,sega_dec_read_delegate readcb)
33   {
34      sega_315_5838_comp_device &dev = downcast<sega_315_5838_comp_device &>(device);
35      dev.m_read_ch2 = readcb;
36   }
37
2938   DECLARE_READ32_MEMBER(decathlt_prot_r);
39   DECLARE_READ32_MEMBER(decathlt_prot_ch2_r);;
40   UINT32 genericdecathlt_prot_r(UINT32 offset, UINT32 mem_mask, int which);
41
3042   void write_prot_data(UINT32 data, UINT32 mem_mask, int offset, int which);
3143   DECLARE_WRITE32_MEMBER(decathlt_prot1_w);
3244   DECLARE_WRITE32_MEMBER(decathlt_prot2_w);


Previous 199869 Revisions Next


© 1997-2024 The MAME Team