trunk/src/mame/machine/decathlt.c
| r26358 | r26359 | |
| 4 | 4 | build the trees required for decompression */ |
| 5 | 5 | |
| 6 | 6 | #include "emu.h" |
| 7 | | #include "stvprot.h" |
| 8 | 7 | #include "includes/stv.h" |
| 9 | 8 | |
| 10 | 9 | /************************** |
| r26358 | r26359 | |
| 13 | 12 | * |
| 14 | 13 | **************************/ |
| 15 | 14 | |
| 16 | | |
| 17 | | static UINT32 decathlt_protregs[4]; |
| 18 | | static UINT32 decathlt_lastcount = 0; |
| 19 | | static UINT32 decathlt_part; |
| 20 | | static UINT32 decathlt_prot_uploadmode=0; |
| 21 | | static UINT32 decathlt_prot_uploadoffset=0; |
| 22 | | static UINT16 decathlt_prottable1[24]; |
| 23 | | static UINT16 decathlt_prottable2[128]; |
| 24 | | |
| 25 | | static READ32_HANDLER( decathlt_prot_r ) |
| 15 | READ32_MEMBER( stv_state::decathlt_prot_r ) |
| 26 | 16 | { |
| 27 | 17 | // the offsets written to the protection device definitely only refer to 2 of the roms |
| 28 | 18 | // 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(); |
| 31 | 21 | |
| 32 | 22 | if (offset==2) |
| 33 | 23 | { |
| 34 | 24 | UINT32 retvalue = 0xffff; |
| 35 | 25 | |
| 36 | | switch (decathlt_protregs[0]) |
| 26 | switch (m_decathlt_protregs[0]) |
| 37 | 27 | { |
| 38 | 28 | default: |
| 39 | | retvalue = ROM[(decathlt_protregs[0]*2)-2]; |
| 29 | retvalue = ROM[(m_decathlt_protregs[0]*2)-2]; |
| 40 | 30 | retvalue <<= 8; |
| 41 | | retvalue |= ROM[((decathlt_protregs[0]+1)*2)+1-2]; |
| 31 | retvalue |= ROM[((m_decathlt_protregs[0]+1)*2)+1-2]; |
| 42 | 32 | retvalue <<= 8; |
| 43 | | retvalue |= ROM[((decathlt_protregs[0]+1)*2)-2]; |
| 33 | retvalue |= ROM[((m_decathlt_protregs[0]+1)*2)-2]; |
| 44 | 34 | 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; |
| 49 | 39 | return retvalue; |
| 50 | 40 | |
| 51 | 41 | 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++; |
| 54 | 44 | return retvalue; |
| 55 | 45 | |
| 56 | 46 | 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++; |
| 59 | 49 | return retvalue; |
| 60 | 50 | |
| 61 | 51 | 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++; |
| 64 | 54 | return retvalue; |
| 65 | 55 | |
| 66 | 56 | 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++; |
| 69 | 59 | return retvalue; |
| 70 | 60 | |
| 71 | 61 | case 0x033f16c: |
| r26358 | r26359 | |
| 103 | 93 | } |
| 104 | 94 | else |
| 105 | 95 | { |
| 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]); |
| 107 | 97 | } |
| 108 | 98 | |
| 109 | | return decathlt_protregs[offset]; |
| 99 | return m_decathlt_protregs[offset]; |
| 110 | 100 | } |
| 111 | 101 | |
| 112 | 102 | |
| 113 | | void write_prot_data(UINT32 data, UINT32 mem_mask, int offset, int which) |
| 103 | void stv_state::write_prot_data(UINT32 data, UINT32 mem_mask, int offset, int which) |
| 114 | 104 | { |
| 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; |
| 117 | 107 | |
| 118 | 108 | if (offset==0) // seems to set a (scrambled?) source address |
| 119 | 109 | { |
| 120 | | decathlt_part ^=1; |
| 110 | m_decathlt_part ^=1; |
| 121 | 111 | |
| 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]); |
| 125 | 115 | } |
| 126 | 116 | |
| 127 | 117 | if (offset==1) // uploads 2 tables... |
| r26358 | r26359 | |
| 131 | 121 | if (data == 0x80000000) |
| 132 | 122 | { |
| 133 | 123 | // 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; |
| 136 | 126 | } |
| 137 | 127 | else if (data == 0x80800000) |
| 138 | 128 | { |
| 139 | 129 | // 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; |
| 142 | 132 | } |
| 143 | 133 | else |
| 144 | 134 | { |
| 145 | 135 | // 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; |
| 148 | 138 | } |
| 149 | 139 | |
| 150 | 140 | // logerror("ARGH! %08x %08x\n",mem_mask,data); |
| 151 | 141 | } |
| 152 | 142 | else if (mem_mask==0x0000ffff) |
| 153 | 143 | { |
| 154 | | if (decathlt_prot_uploadmode==1) |
| 144 | if (m_decathlt_prot_uploadmode==1) |
| 155 | 145 | { |
| 156 | | if (decathlt_prot_uploadoffset>=24) |
| 146 | if (m_decathlt_prot_uploadoffset>=24) |
| 157 | 147 | { |
| 158 | 148 | // logerror("upload mode 1 error, too big\n"); |
| 159 | 149 | return; |
| 160 | 150 | } |
| 161 | 151 | |
| 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++; |
| 165 | 155 | |
| 166 | 156 | { |
| 167 | 157 | /* 0x18 (24) values in this table, rom data is 0x1800000 long, maybe it has |
| r26358 | r26359 | |
| 176 | 166 | else fp = fopen("table1","wb"); |
| 177 | 167 | |
| 178 | 168 | { |
| 179 | | fwrite(&decathlt_prottable1,24,2,fp); |
| 169 | fwrite(&m_decathlt_prottable1,24,2,fp); |
| 180 | 170 | } |
| 181 | 171 | fclose(fp); |
| 182 | 172 | } |
| 183 | 173 | } |
| 184 | 174 | |
| 185 | 175 | } |
| 186 | | else if (decathlt_prot_uploadmode==2) |
| 176 | else if (m_decathlt_prot_uploadmode==2) |
| 187 | 177 | { |
| 188 | | if (decathlt_prot_uploadoffset>=128) |
| 178 | if (m_decathlt_prot_uploadoffset>=128) |
| 189 | 179 | { |
| 190 | 180 | //logerror("upload mode 2 error, too big\n"); |
| 191 | 181 | return; |
| 192 | 182 | } |
| 193 | 183 | |
| 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++; |
| 197 | 187 | |
| 198 | 188 | { |
| 199 | 189 | /* the table uploaded here is a 256 byte table with 256 unique values, remaps something? */ |
| r26358 | r26359 | |
| 204 | 194 | else fp = fopen("table2","wb"); |
| 205 | 195 | |
| 206 | 196 | { |
| 207 | | fwrite(&decathlt_prottable2,128,2,fp); |
| 197 | fwrite(&m_decathlt_prottable2,128,2,fp); |
| 208 | 198 | } |
| 209 | 199 | fclose(fp); |
| 210 | 200 | } |
| r26358 | r26359 | |
| 224 | 214 | |
| 225 | 215 | } |
| 226 | 216 | |
| 227 | | static WRITE32_HANDLER( decathlt_prot1_w ) |
| 217 | WRITE32_MEMBER( stv_state::decathlt_prot1_w ) |
| 228 | 218 | { |
| 229 | 219 | write_prot_data(data,mem_mask, offset, 0); |
| 230 | 220 | |
| 231 | 221 | } |
| 232 | 222 | |
| 233 | | static WRITE32_HANDLER( decathlt_prot2_w ) |
| 223 | WRITE32_MEMBER( stv_state::decathlt_prot2_w ) |
| 234 | 224 | { |
| 235 | 225 | write_prot_data(data,mem_mask, offset, 1); |
| 236 | 226 | |
| 237 | 227 | |
| 238 | 228 | } |
| 239 | 229 | |
| 240 | | void install_decathlt_protection(running_machine &machine) |
| 230 | void stv_state::install_decathlt_protection() |
| 241 | 231 | { |
| 242 | 232 | /* It uploads 2 tables here, then performs what looks like a number of transfers, setting |
| 243 | 233 | 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)); |
| 250 | 240 | /* 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)); |
| 252 | 242 | } |