Previous 199869 Revisions Next

r26359 Friday 22nd November, 2013 at 14:37:36 UTC by Osso
Moved decathlt protection (?) related functions into the driver class. Needs a fresh make depend. (nw)
[src/mame/drivers]stv.c
[src/mame/includes]stv.h
[src/mame/machine]decathlt.c stvprot.h

trunk/src/mame/drivers/stv.c
r26358r26359
4646#include "sound/scsp.h"
4747#include "sound/cdda.h"
4848#include "sound/dmadac.h"
49#include "machine/stvprot.h"
5049#include "machine/smpc.h"
5150#include "includes/stv.h"
5251#include "imagedev/chd_cd.h"
r26358r26359
907906
908907DRIVER_INIT_MEMBER(stv_state,decathlt)
909908{
910   install_decathlt_protection(machine());
909   m_decathlt_lastcount = 0;
910   m_decathlt_prot_uploadmode = 0;
911   m_decathlt_prot_uploadoffset = 0;
912   install_decathlt_protection();
911913   DRIVER_INIT_CALL(stv);
912914}
913915
trunk/src/mame/machine/stvprot.h
r26358r26359
1/* stvprot.h */
2
3void install_decathlt_protection(running_machine &machine);
trunk/src/mame/machine/decathlt.c
r26358r26359
44  build the trees required for decompression */
55
66#include "emu.h"
7#include "stvprot.h"
87#include "includes/stv.h"
98
109/**************************
r26358r26359
1312*
1413**************************/
1514
16
17static UINT32 decathlt_protregs[4];
18static UINT32 decathlt_lastcount = 0;
19static UINT32 decathlt_part;
20static UINT32 decathlt_prot_uploadmode=0;
21static UINT32 decathlt_prot_uploadoffset=0;
22static UINT16 decathlt_prottable1[24];
23static UINT16 decathlt_prottable2[128];
24
25static READ32_HANDLER( decathlt_prot_r )
15READ32_MEMBER( stv_state::decathlt_prot_r )
2616{
2717   // the offsets written to the protection device definitely only refer to 2 of the roms
2818   //  it's a fair assumption to say that only those 2 are connected to the protection device
29   UINT8 *ROM = (UINT8 *)space.machine().root_device().memregion("abus")->base()+0x1000000;
30   UINT32 *fake0 = (UINT32*)space.machine().root_device().memregion( "fake0" )->base();
19   UINT8 *ROM = (UINT8 *)memregion("abus")->base()+0x1000000;
20   UINT32 *fake0 = (UINT32*)memregion( "fake0" )->base();
3121
3222   if (offset==2)
3323   {
3424      UINT32 retvalue = 0xffff;
3525
36      switch (decathlt_protregs[0])
26      switch (m_decathlt_protregs[0])
3727      {
3828         default:
39         retvalue = ROM[(decathlt_protregs[0]*2)-2];
29         retvalue = ROM[(m_decathlt_protregs[0]*2)-2];
4030         retvalue <<= 8;
41         retvalue |= ROM[((decathlt_protregs[0]+1)*2)+1-2];
31         retvalue |= ROM[((m_decathlt_protregs[0]+1)*2)+1-2];
4232         retvalue <<= 8;
43         retvalue |= ROM[((decathlt_protregs[0]+1)*2)-2];
33         retvalue |= ROM[((m_decathlt_protregs[0]+1)*2)-2];
4434         retvalue <<= 8;
45         retvalue |= ROM[((decathlt_protregs[0]+2)*2)+1-2];
46         decathlt_lastcount++;
47         logerror("read addr %08x, blah_r %08x - read count count %08x\n", decathlt_protregs[0], retvalue, decathlt_lastcount*4);
48         decathlt_protregs[0]+=2;
35         retvalue |= ROM[((m_decathlt_protregs[0]+2)*2)+1-2];
36         m_decathlt_lastcount++;
37         logerror("read addr %08x, blah_r %08x - read count count %08x\n", m_decathlt_protregs[0], retvalue, m_decathlt_lastcount*4);
38         m_decathlt_protregs[0]+=2;
4939         return retvalue;
5040
5141         case 0x03228e4:
52            if (fake0) retvalue = fake0[(((0x20080/4)+decathlt_lastcount))];
53            decathlt_lastcount++;
42            if (fake0) retvalue = fake0[(((0x20080/4)+m_decathlt_lastcount))];
43            m_decathlt_lastcount++;
5444            return retvalue;
5545
5646         case 0x00a9f3a:
57            if (fake0) retvalue = fake0[(((0x00000/4)+decathlt_lastcount))];
58            decathlt_lastcount++;
47            if (fake0) retvalue = fake0[(((0x00000/4)+m_decathlt_lastcount))];
48            m_decathlt_lastcount++;
5949            return retvalue;
6050
6151         case 0x0213ab4:
62            if (fake0) retvalue = fake0[(((0x40000/4)+decathlt_lastcount))];
63            decathlt_lastcount++;
52            if (fake0) retvalue = fake0[(((0x40000/4)+m_decathlt_lastcount))];
53            m_decathlt_lastcount++;
6454            return retvalue;
6555
6656         case 0x01efaf0:
67            if (fake0) retvalue = fake0[(((0x60000/4)+decathlt_lastcount))];
68            decathlt_lastcount++;
57            if (fake0) retvalue = fake0[(((0x60000/4)+m_decathlt_lastcount))];
58            m_decathlt_lastcount++;
6959            return retvalue;
7060
7161         case 0x033f16c:
r26358r26359
10393   }
10494   else
10595   {
106      logerror("%06x Decathlete prot R offset %04x mask %08x regs %08x, %08x, %08x, %08x\n",space.device().safe_pc(), offset, mem_mask, decathlt_protregs[0], decathlt_protregs[1], decathlt_protregs[2], decathlt_protregs[3]);
96      logerror("%06x Decathlete prot R offset %04x mask %08x regs %08x, %08x, %08x, %08x\n", safe_pc(), offset, mem_mask, m_decathlt_protregs[0], m_decathlt_protregs[1], m_decathlt_protregs[2], m_decathlt_protregs[3]);
10797   }
10898
109   return decathlt_protregs[offset];
99   return m_decathlt_protregs[offset];
110100}
111101
112102
113void write_prot_data(UINT32 data, UINT32 mem_mask, int offset, int which)
103void stv_state::write_prot_data(UINT32 data, UINT32 mem_mask, int offset, int which)
114104{
115   decathlt_protregs[offset] = (data&mem_mask)|(decathlt_protregs[offset]&~mem_mask);
116//  decathlt_protregs[0] = 0x0c00000/4;
105   m_decathlt_protregs[offset] = (data&mem_mask)|(m_decathlt_protregs[offset]&~mem_mask);
106//  m_decathlt_protregs[0] = 0x0c00000/4;
117107
118108   if (offset==0) // seems to set a (scrambled?) source address
119109   {
120      decathlt_part ^=1;
110      m_decathlt_part ^=1;
121111
122      //if (decathlt_part==0) logerror("%d, last read count was %06x\n",which, decathlt_lastcount*4);
123      decathlt_lastcount = 0;
124      if (decathlt_part==1) logerror("%d Decathlete prot W offset %04x data %08x, %08x, >>> regs %08x <<<<, %08x, %08x, %08x\n",which, offset, data, decathlt_protregs[0], decathlt_protregs[0]*4, decathlt_protregs[1], decathlt_protregs[2], decathlt_protregs[3]);
112      //if (m_decathlt_part==0) logerror("%d, last read count was %06x\n",which, m_decathlt_lastcount*4);
113      m_decathlt_lastcount = 0;
114      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]);
125115   }
126116
127117   if (offset==1) // uploads 2 tables...
r26358r26359
131121         if (data == 0x80000000)
132122         {
133123         //  logerror("changed to upload mode 1\n");
134            decathlt_prot_uploadmode = 1;
135            decathlt_prot_uploadoffset = 0;
124            m_decathlt_prot_uploadmode = 1;
125            m_decathlt_prot_uploadoffset = 0;
136126         }
137127         else if (data == 0x80800000)
138128         {
139129         //  logerror("changed to upload mode 2\n");
140            decathlt_prot_uploadmode = 2;
141            decathlt_prot_uploadoffset = 0;
130            m_decathlt_prot_uploadmode = 2;
131            m_decathlt_prot_uploadoffset = 0;
142132         }
143133         else
144134         {
145135         //  logerror("unknown upload mode\n");
146            decathlt_prot_uploadmode = 2;
147            decathlt_prot_uploadoffset = 0;
136            m_decathlt_prot_uploadmode = 2;
137            m_decathlt_prot_uploadoffset = 0;
148138         }
149139
150140//          logerror("ARGH! %08x %08x\n",mem_mask,data);
151141      }
152142      else if (mem_mask==0x0000ffff)
153143      {
154         if (decathlt_prot_uploadmode==1)
144         if (m_decathlt_prot_uploadmode==1)
155145         {
156            if (decathlt_prot_uploadoffset>=24)
146            if (m_decathlt_prot_uploadoffset>=24)
157147            {
158148            //  logerror("upload mode 1 error, too big\n");
159149               return;
160150            }
161151
162            //logerror("uploading table 1 %04x %04x\n",decathlt_prot_uploadoffset, data&0xffff);
163            decathlt_prottable1[decathlt_prot_uploadoffset]=data&0xffff;
164            decathlt_prot_uploadoffset++;
152            //logerror("uploading table 1 %04x %04x\n",m_decathlt_prot_uploadoffset, data&0xffff);
153            m_decathlt_prottable1[m_decathlt_prot_uploadoffset]=data&0xffff;
154            m_decathlt_prot_uploadoffset++;
165155
166156            {
167157               /* 0x18 (24) values in this table, rom data is 0x1800000 long, maybe it has
r26358r26359
176166                  else fp = fopen("table1","wb");
177167
178168                  {
179                     fwrite(&decathlt_prottable1,24,2,fp);
169                     fwrite(&m_decathlt_prottable1,24,2,fp);
180170                  }
181171                  fclose(fp);
182172               }
183173            }
184174
185175         }
186         else if (decathlt_prot_uploadmode==2)
176         else if (m_decathlt_prot_uploadmode==2)
187177         {
188            if (decathlt_prot_uploadoffset>=128)
178            if (m_decathlt_prot_uploadoffset>=128)
189179            {
190180               //logerror("upload mode 2 error, too big\n");
191181               return;
192182            }
193183
194            //logerror("uploading table 2 %04x %04x\n",decathlt_prot_uploadoffset, data&0xffff);
195            decathlt_prottable2[decathlt_prot_uploadoffset]=data&0xffff;
196            decathlt_prot_uploadoffset++;
184            //logerror("uploading table 2 %04x %04x\n",m_decathlt_prot_uploadoffset, data&0xffff);
185            m_decathlt_prottable2[m_decathlt_prot_uploadoffset]=data&0xffff;
186            m_decathlt_prot_uploadoffset++;
197187
198188            {
199189               /* the table uploaded here is a 256 byte table with 256 unique values, remaps something? */
r26358r26359
204194                  else fp = fopen("table2","wb");
205195
206196                  {
207                     fwrite(&decathlt_prottable2,128,2,fp);
197                     fwrite(&m_decathlt_prottable2,128,2,fp);
208198                  }
209199                  fclose(fp);
210200               }
r26358r26359
224214
225215}
226216
227static WRITE32_HANDLER( decathlt_prot1_w )
217WRITE32_MEMBER( stv_state::decathlt_prot1_w )
228218{
229219   write_prot_data(data,mem_mask, offset, 0);
230220
231221}
232222
233static WRITE32_HANDLER( decathlt_prot2_w )
223WRITE32_MEMBER( stv_state::decathlt_prot2_w )
234224{
235225   write_prot_data(data,mem_mask, offset, 1);
236226
237227
238228}
239229
240void install_decathlt_protection(running_machine &machine)
230void stv_state::install_decathlt_protection()
241231{
242232   /* It uploads 2 tables here, then performs what looks like a number of transfers, setting
243233      a source address of some kind (scrambled?) and then making many reads from a single address */
244   memset(decathlt_protregs, 0, sizeof(decathlt_protregs));
245   decathlt_lastcount = 0;
246   decathlt_prot_uploadmode = 0;
247   decathlt_prot_uploadoffset = 0;
248   decathlt_part = 1;
249   machine.device("maincpu")->memory().space(AS_PROGRAM).install_legacy_readwrite_handler(0x37FFFF0, 0x37FFFFF, FUNC(decathlt_prot_r), FUNC(decathlt_prot1_w));
234   memset(m_decathlt_protregs, 0, sizeof(m_decathlt_protregs));
235   m_decathlt_lastcount = 0;
236   m_decathlt_prot_uploadmode = 0;
237   m_decathlt_prot_uploadoffset = 0;
238   m_decathlt_part = 1;
239   m_maincpu->space(AS_PROGRAM).install_readwrite_handler(0x37FFFF0, 0x37FFFFF, read32_delegate(FUNC(stv_state::decathlt_prot_r), this), write32_delegate(FUNC(stv_state::decathlt_prot1_w), this));
250240   /* 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? */
251   machine.device("maincpu")->memory().space(AS_PROGRAM).install_legacy_readwrite_handler(0x27FFFF0, 0x27FFFFF, FUNC(decathlt_prot_r), FUNC(decathlt_prot2_w));
241   m_maincpu->space(AS_PROGRAM).install_readwrite_handler(0x27FFFF0, 0x27FFFFF, read32_delegate(FUNC(stv_state::decathlt_prot_r), this), write32_delegate(FUNC(stv_state::decathlt_prot2_w), this));
252242}
trunk/src/mame/includes/stv.h
r26358r26359
763763   void install_rsgun_protection();
764764   void install_elandore_protection();
765765   void install_ffreveng_protection();
766
766   
767767   void stv_register_protection_savestates();   
768   
769   // Decathlete specific variables and functions (see machine/decathlt.c)
770   UINT32 m_decathlt_protregs[4];
771   UINT32 m_decathlt_lastcount;
772   UINT32 m_decathlt_part;
773   UINT32 m_decathlt_prot_uploadmode;
774   UINT32 m_decathlt_prot_uploadoffset;
775   UINT16 m_decathlt_prottable1[24];
776   UINT16 m_decathlt_prottable2[128];
777   
778   DECLARE_READ32_MEMBER( decathlt_prot_r );
779   DECLARE_WRITE32_MEMBER( decathlt_prot1_w );
780   DECLARE_WRITE32_MEMBER( decathlt_prot2_w );
781   void write_prot_data(UINT32 data, UINT32 mem_mask, int offset, int which);
782   void install_decathlt_protection();
768783};
769784
770785

Previous 199869 Revisions Next


© 1997-2024 The MAME Team