Previous 199869 Revisions Next

r18821 Friday 2nd November, 2012 at 23:45:01 UTC by smf
more OO & consistent. (nw)
[src/mame/machine]fd1089.c fd1089.h

trunk/src/mame/machine/fd1089.c
r18820r18821
213213//  fd1089_base_device - constructor
214214//-------------------------------------------------
215215
216fd1089_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)
216fd1089_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)
219218{
220219   // override the name after the m68000 initializes
221   m_name.printf("FD1089%c", m_cputype);
220   m_name.cpy(name);
222221}
223222
223fd1089a_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}
224227
228fd1089b_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
225233//-------------------------------------------------
226234//  device_start - one-time device initialization
227235//-------------------------------------------------
r18820r18821
327335//  according to FD1089A rules
328336//-------------------------------------------------
329337
330UINT8 fd1089_base_device::decode_fd1089a(UINT8 val, UINT8 key, bool opcode)
338UINT8 fd1089a_device::decode(UINT8 val, UINT8 key, bool opcode)
331339{
332340   // special case - don't decrypt
333341   if (key == 0x40)
r18820r18821
387395//  according to FD1089B rules
388396//-------------------------------------------------
389397
390UINT8 fd1089_base_device::decode_fd1089b(UINT8 val, UINT8 key, bool opcode)
398UINT8 fd1089b_device::decode(UINT8 val, UINT8 key, bool opcode)
391399{
392400   // special case - don't decrypt
393401   if (key == 0x40)
r18820r18821
446454//  as either an opcode or as data
447455//-------------------------------------------------
448456
449UINT16 fd1089_base_device::decrypt_one(offs_t addr, UINT16 val, const UINT8 *key, bool opcode, char cputype)
457UINT16 fd1089_base_device::decrypt_one(offs_t addr, UINT16 val, const UINT8 *key, bool opcode)
450458{
451459   // pick the translation table from bits ff022a of the address
452460   int tbl_num =   ((addr & 0x000002) >> 1) |
r18820r18821
459467               ((val & 0x0040) >> 5) |
460468               ((val & 0xfc00) >> 8);
461469
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);
467471
468472   src =   ((src & 0x01) << 3) |
469473         ((src & 0x02) << 5) |
r18820r18821
483487   for (offs_t offset = 0; offset < size; offset += 2)
484488   {
485489      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);
488492   }
489493}
trunk/src/mame/machine/fd1089.h
r18820r18821
3737{
3838public:
3939   // 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);
4141
4242   // explicit decryption helpers
4343   void decrypt(offs_t baseaddr, UINT32 size, offs_t regionoffs, UINT16 *opcodesptr, UINT16 *dataptr) { decrypt(baseaddr, size, &m_plaintext[regionoffs/2], opcodesptr, dataptr); }
r18820r18821
4848
4949   // internal helpers
5050   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);
5453   void decrypt(offs_t baseaddr, UINT32 size, const UINT16 *srcptr, UINT16 *opcodesptr, UINT16 *dataptr);
5554
5655   // internal state
5756   const UINT8 *         m_key;
58   char               m_cputype;
5957   dynamic_array<UINT16>   m_plaintext;
6058   dynamic_array<UINT16>   m_decrypted_opcodes;
6159
r18820r18821
8078{
8179public:
8280   // 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
83protected:
84   virtual UINT8 decode(UINT8 val, UINT8 key, bool opcode);
8585};
8686
8787
r18820r18821
9292{
9393public:
9494   // 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
97protected:
98   virtual UINT8 decode(UINT8 val, UINT8 key, bool opcode);
9799};
98100
99101

Previous 199869 Revisions Next


© 1997-2024 The MAME Team