trunk/src/mame/machine/decathlt.c
| r243131 | r243132 | |
| 1 | | /* The Decathlete 'protection' seems to be some kind of Huffman style compression on the graphics, |
| 2 | | the game uploads 2 dictionary tables (for different areas of the ROM) as well as an additional |
| 3 | | table with each one. The secondary table doesn't initially appear to be the data needed to |
| 4 | | build the trees required for decompression */ |
| 5 | | |
| 6 | | #include "emu.h" |
| 7 | | #include "includes/stv.h" |
| 8 | | |
| 9 | | /************************** |
| 10 | | * |
| 11 | | * Decathlete |
| 12 | | * |
| 13 | | **************************/ |
| 14 | | |
| 15 | | READ32_MEMBER( stv_state::decathlt_prot_r ) |
| 16 | | { |
| 17 | | // the offsets written to the protection device definitely only refer to 2 of the roms |
| 18 | | // it's a fair assumption to say that only those 2 are connected to the protection device |
| 19 | | UINT8 *ROM = (UINT8 *)memregion("abus")->base()+0x1000000; |
| 20 | | UINT32 *fake0 = (UINT32*)memregion( "fake0" )->base(); |
| 21 | | |
| 22 | | if (offset==2) |
| 23 | | { |
| 24 | | UINT32 retvalue = 0xffff; |
| 25 | | |
| 26 | | switch (m_decathlt_protregs[0]) |
| 27 | | { |
| 28 | | default: |
| 29 | | retvalue = ROM[(m_decathlt_protregs[0]*2)-2]; |
| 30 | | retvalue <<= 8; |
| 31 | | retvalue |= ROM[((m_decathlt_protregs[0]+1)*2)+1-2]; |
| 32 | | retvalue <<= 8; |
| 33 | | retvalue |= ROM[((m_decathlt_protregs[0]+1)*2)-2]; |
| 34 | | retvalue <<= 8; |
| 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; |
| 39 | | return retvalue; |
| 40 | | |
| 41 | | case 0x03228e4: |
| 42 | | if (fake0) retvalue = fake0[(((0x20080/4)+m_decathlt_lastcount))]; |
| 43 | | m_decathlt_lastcount++; |
| 44 | | return retvalue; |
| 45 | | |
| 46 | | case 0x00a9f3a: |
| 47 | | if (fake0) retvalue = fake0[(((0x00000/4)+m_decathlt_lastcount))]; |
| 48 | | m_decathlt_lastcount++; |
| 49 | | return retvalue; |
| 50 | | |
| 51 | | case 0x0213ab4: |
| 52 | | if (fake0) retvalue = fake0[(((0x40000/4)+m_decathlt_lastcount))]; |
| 53 | | m_decathlt_lastcount++; |
| 54 | | return retvalue; |
| 55 | | |
| 56 | | case 0x01efaf0: |
| 57 | | if (fake0) retvalue = fake0[(((0x60000/4)+m_decathlt_lastcount))]; |
| 58 | | m_decathlt_lastcount++; |
| 59 | | return retvalue; |
| 60 | | |
| 61 | | case 0x033f16c: |
| 62 | | case 0x038929c: |
| 63 | | |
| 64 | | |
| 65 | | |
| 66 | | case 0x00de05a: |
| 67 | | case 0x0334258: |
| 68 | | case 0x019fb82: |
| 69 | | case 0x033dbf6: |
| 70 | | case 0x0011ac6: |
| 71 | | case 0x00060dc: |
| 72 | | case 0x0000002: |
| 73 | | case 0x0008c90: |
| 74 | | case 0x035cdc8: |
| 75 | | case 0x0327960: |
| 76 | | case 0x0329b8c: |
| 77 | | case 0x00d6e92: |
| 78 | | case 0x000081e: |
| 79 | | case 0x00035d6: |
| 80 | | case 0x00089a6: |
| 81 | | case 0x03315f4: |
| 82 | | case 0x0023fe0: |
| 83 | | case 0x001e290: |
| 84 | | case 0x0026e86: |
| 85 | | case 0x0012494: |
| 86 | | case 0x001b35a: |
| 87 | | case 0x0018424: |
| 88 | | |
| 89 | | return retvalue; |
| 90 | | } |
| 91 | | |
| 92 | | |
| 93 | | } |
| 94 | | else |
| 95 | | { |
| 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]); |
| 97 | | } |
| 98 | | |
| 99 | | return m_decathlt_protregs[offset]; |
| 100 | | } |
| 101 | | |
| 102 | | |
| 103 | | void stv_state::write_prot_data(UINT32 data, UINT32 mem_mask, int offset, int which) |
| 104 | | { |
| 105 | | m_decathlt_protregs[offset] = (data&mem_mask)|(m_decathlt_protregs[offset]&~mem_mask); |
| 106 | | // m_decathlt_protregs[0] = 0x0c00000/4; |
| 107 | | |
| 108 | | if (offset==0) // seems to set a (scrambled?) source address |
| 109 | | { |
| 110 | | m_decathlt_part ^=1; |
| 111 | | |
| 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]); |
| 115 | | } |
| 116 | | |
| 117 | | if (offset==1) // uploads 2 tables... |
| 118 | | { |
| 119 | | if (mem_mask==0xffff0000) |
| 120 | | { |
| 121 | | if (data == 0x80000000) |
| 122 | | { |
| 123 | | // logerror("changed to upload mode 1\n"); |
| 124 | | m_decathlt_prot_uploadmode = 1; |
| 125 | | m_decathlt_prot_uploadoffset = 0; |
| 126 | | } |
| 127 | | else if (data == 0x80800000) |
| 128 | | { |
| 129 | | // logerror("changed to upload mode 2\n"); |
| 130 | | m_decathlt_prot_uploadmode = 2; |
| 131 | | m_decathlt_prot_uploadoffset = 0; |
| 132 | | } |
| 133 | | else |
| 134 | | { |
| 135 | | // logerror("unknown upload mode\n"); |
| 136 | | m_decathlt_prot_uploadmode = 2; |
| 137 | | m_decathlt_prot_uploadoffset = 0; |
| 138 | | } |
| 139 | | |
| 140 | | // logerror("ARGH! %08x %08x\n",mem_mask,data); |
| 141 | | } |
| 142 | | else if (mem_mask==0x0000ffff) |
| 143 | | { |
| 144 | | if (m_decathlt_prot_uploadmode==1) |
| 145 | | { |
| 146 | | if (m_decathlt_prot_uploadoffset>=24) |
| 147 | | { |
| 148 | | // logerror("upload mode 1 error, too big\n"); |
| 149 | | return; |
| 150 | | } |
| 151 | | |
| 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++; |
| 155 | | |
| 156 | | { |
| 157 | | /* 0x18 (24) values in this table, rom data is 0x1800000 long, maybe it has |
| 158 | | something to do with that? or 24-address bits? |
| 159 | | |
| 160 | | uploaded values appear to be 12-bit, some are repeated |
| 161 | | */ |
| 162 | | |
| 163 | | { |
| 164 | | FILE* fp; |
| 165 | | if (which==1) fp = fopen("table1x","wb"); |
| 166 | | else fp = fopen("table1","wb"); |
| 167 | | |
| 168 | | { |
| 169 | | fwrite(&m_decathlt_prottable1,24,2,fp); |
| 170 | | } |
| 171 | | fclose(fp); |
| 172 | | } |
| 173 | | } |
| 174 | | |
| 175 | | } |
| 176 | | else if (m_decathlt_prot_uploadmode==2) |
| 177 | | { |
| 178 | | if (m_decathlt_prot_uploadoffset>=128) |
| 179 | | { |
| 180 | | //logerror("upload mode 2 error, too big\n"); |
| 181 | | return; |
| 182 | | } |
| 183 | | |
| 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++; |
| 187 | | |
| 188 | | { |
| 189 | | /* the table uploaded here is a 256 byte table with 256 unique values, remaps something? */ |
| 190 | | |
| 191 | | { |
| 192 | | FILE* fp; |
| 193 | | if (which==1) fp = fopen("table2x","wb"); |
| 194 | | else fp = fopen("table2","wb"); |
| 195 | | |
| 196 | | { |
| 197 | | fwrite(&m_decathlt_prottable2,128,2,fp); |
| 198 | | } |
| 199 | | fclose(fp); |
| 200 | | } |
| 201 | | } |
| 202 | | } |
| 203 | | else |
| 204 | | { |
| 205 | | // logerror("unknown upload mode!\n"); |
| 206 | | } |
| 207 | | } |
| 208 | | } |
| 209 | | |
| 210 | | if (offset>1) |
| 211 | | { |
| 212 | | // logerror("higher offset write\n"); |
| 213 | | } |
| 214 | | |
| 215 | | } |
| 216 | | |
| 217 | | WRITE32_MEMBER( stv_state::decathlt_prot1_w ) |
| 218 | | { |
| 219 | | write_prot_data(data,mem_mask, offset, 0); |
| 220 | | |
| 221 | | } |
| 222 | | |
| 223 | | WRITE32_MEMBER( stv_state::decathlt_prot2_w ) |
| 224 | | { |
| 225 | | write_prot_data(data,mem_mask, offset, 1); |
| 226 | | |
| 227 | | |
| 228 | | } |
| 229 | | |
| 230 | | void stv_state::install_decathlt_protection() |
| 231 | | { |
| 232 | | /* It uploads 2 tables here, then performs what looks like a number of transfers, setting |
| 233 | | a source address of some kind (scrambled?) and then making many reads from a single address */ |
| 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)); |
| 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? */ |
| 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)); |
| 242 | | } |