trunk/src/mame/machine/fd1089.c
| r18820 | r18821 | |
| 213 | 213 | // fd1089_base_device - constructor |
| 214 | 214 | //------------------------------------------------- |
| 215 | 215 | |
| 216 | | fd1089_base_device::fd1089_base_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, UINT32 clock, char cputype) |
| 217 | | : m68000_device(mconfig, M68000, tag, owner, clock), |
| 218 | | m_cputype(cputype) |
| 216 | fd1089_base_device::fd1089_base_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock) |
| 217 | : m68000_device(mconfig, M68000, tag, owner, clock) |
| 219 | 218 | { |
| 220 | 219 | // override the name after the m68000 initializes |
| 221 | | m_name.printf("FD1089%c", m_cputype); |
| 220 | m_name.cpy(name); |
| 222 | 221 | } |
| 223 | 222 | |
| 223 | fd1089a_device::fd1089a_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) |
| 224 | : fd1089_base_device(mconfig, FD1089A, "FD1089A", tag, owner, clock) |
| 225 | { |
| 226 | } |
| 224 | 227 | |
| 228 | fd1089b_device::fd1089b_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) |
| 229 | : fd1089_base_device(mconfig, FD1089B, "FD1089B", tag, owner, clock) |
| 230 | { |
| 231 | } |
| 232 | |
| 225 | 233 | //------------------------------------------------- |
| 226 | 234 | // device_start - one-time device initialization |
| 227 | 235 | //------------------------------------------------- |
| r18820 | r18821 | |
| 327 | 335 | // according to FD1089A rules |
| 328 | 336 | //------------------------------------------------- |
| 329 | 337 | |
| 330 | | UINT8 fd1089_base_device::decode_fd1089a(UINT8 val, UINT8 key, bool opcode) |
| 338 | UINT8 fd1089a_device::decode(UINT8 val, UINT8 key, bool opcode) |
| 331 | 339 | { |
| 332 | 340 | // special case - don't decrypt |
| 333 | 341 | if (key == 0x40) |
| r18820 | r18821 | |
| 387 | 395 | // according to FD1089B rules |
| 388 | 396 | //------------------------------------------------- |
| 389 | 397 | |
| 390 | | UINT8 fd1089_base_device::decode_fd1089b(UINT8 val, UINT8 key, bool opcode) |
| 398 | UINT8 fd1089b_device::decode(UINT8 val, UINT8 key, bool opcode) |
| 391 | 399 | { |
| 392 | 400 | // special case - don't decrypt |
| 393 | 401 | if (key == 0x40) |
| r18820 | r18821 | |
| 446 | 454 | // as either an opcode or as data |
| 447 | 455 | //------------------------------------------------- |
| 448 | 456 | |
| 449 | | UINT16 fd1089_base_device::decrypt_one(offs_t addr, UINT16 val, const UINT8 *key, bool opcode, char cputype) |
| 457 | UINT16 fd1089_base_device::decrypt_one(offs_t addr, UINT16 val, const UINT8 *key, bool opcode) |
| 450 | 458 | { |
| 451 | 459 | // pick the translation table from bits ff022a of the address |
| 452 | 460 | int tbl_num = ((addr & 0x000002) >> 1) | |
| r18820 | r18821 | |
| 459 | 467 | ((val & 0x0040) >> 5) | |
| 460 | 468 | ((val & 0xfc00) >> 8); |
| 461 | 469 | |
| 462 | | switch (cputype) |
| 463 | | { |
| 464 | | case 'A': src = decode_fd1089a(src, key[tbl_num + (opcode ? 0 : 1) * 0x1000], opcode); break; |
| 465 | | case 'B': src = decode_fd1089b(src, key[tbl_num + (opcode ? 0 : 1) * 0x1000], opcode); break; |
| 466 | | } |
| 470 | src = decode(src, key[tbl_num + (opcode ? 0 : 1) * 0x1000], opcode); |
| 467 | 471 | |
| 468 | 472 | src = ((src & 0x01) << 3) | |
| 469 | 473 | ((src & 0x02) << 5) | |
| r18820 | r18821 | |
| 483 | 487 | for (offs_t offset = 0; offset < size; offset += 2) |
| 484 | 488 | { |
| 485 | 489 | UINT16 src = srcptr[offset / 2]; |
| 486 | | opcodesptr[offset / 2] = decrypt_one(baseaddr + offset, src, m_key, true, m_cputype); |
| 487 | | dataptr[offset / 2] = decrypt_one(baseaddr + offset, src, m_key, false, m_cputype); |
| 490 | opcodesptr[offset / 2] = decrypt_one(baseaddr + offset, src, m_key, true); |
| 491 | dataptr[offset / 2] = decrypt_one(baseaddr + offset, src, m_key, false); |
| 488 | 492 | } |
| 489 | 493 | } |
trunk/src/mame/machine/fd1089.h
| r18820 | r18821 | |
| 37 | 37 | { |
| 38 | 38 | public: |
| 39 | 39 | // construction/destruction |
| 40 | | fd1089_base_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, UINT32 clock, char cputype); |
| 40 | fd1089_base_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock); |
| 41 | 41 | |
| 42 | 42 | // explicit decryption helpers |
| 43 | 43 | void decrypt(offs_t baseaddr, UINT32 size, offs_t regionoffs, UINT16 *opcodesptr, UINT16 *dataptr) { decrypt(baseaddr, size, &m_plaintext[regionoffs/2], opcodesptr, dataptr); } |
| r18820 | r18821 | |
| 48 | 48 | |
| 49 | 49 | // internal helpers |
| 50 | 50 | UINT8 rearrange_key(UINT8 table, bool opcode); |
| 51 | | UINT8 decode_fd1089a(UINT8 val, UINT8 key, bool opcode); |
| 52 | | UINT8 decode_fd1089b(UINT8 val, UINT8 key, bool opcode); |
| 53 | | UINT16 decrypt_one(offs_t addr, UINT16 val, const UINT8 *key, bool opcode, char cputype); |
| 51 | virtual UINT8 decode(UINT8 val, UINT8 key, bool opcode) = 0; |
| 52 | UINT16 decrypt_one(offs_t addr, UINT16 val, const UINT8 *key, bool opcode); |
| 54 | 53 | void decrypt(offs_t baseaddr, UINT32 size, const UINT16 *srcptr, UINT16 *opcodesptr, UINT16 *dataptr); |
| 55 | 54 | |
| 56 | 55 | // internal state |
| 57 | 56 | const UINT8 * m_key; |
| 58 | | char m_cputype; |
| 59 | 57 | dynamic_array<UINT16> m_plaintext; |
| 60 | 58 | dynamic_array<UINT16> m_decrypted_opcodes; |
| 61 | 59 | |
| r18820 | r18821 | |
| 80 | 78 | { |
| 81 | 79 | public: |
| 82 | 80 | // construction/destruction |
| 83 | | fd1089a_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) |
| 84 | | : fd1089_base_device(mconfig, FD1089A, tag, owner, clock, 'A') { } |
| 81 | fd1089a_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); |
| 82 | |
| 83 | protected: |
| 84 | virtual UINT8 decode(UINT8 val, UINT8 key, bool opcode); |
| 85 | 85 | }; |
| 86 | 86 | |
| 87 | 87 | |
| r18820 | r18821 | |
| 92 | 92 | { |
| 93 | 93 | public: |
| 94 | 94 | // construction/destruction |
| 95 | | fd1089b_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) |
| 96 | | : fd1089_base_device(mconfig, FD1089B, tag, owner, clock, 'B') { } |
| 95 | fd1089b_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); |
| 96 | |
| 97 | protected: |
| 98 | virtual UINT8 decode(UINT8 val, UINT8 key, bool opcode); |
| 97 | 99 | }; |
| 98 | 100 | |
| 99 | 101 | |