summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/machine/fd1089.h
blob: e8e106b51366b65ba752d4302edf9753ab9fcebb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// license:BSD-3-Clause
// copyright-holders:Nicola Salmoria, Andreas Naive, Charles MacDonald
/***************************************************************************

    Hitachi FD1089A/FD1089B encryption emulation

****************************************************************************

    Copyright Nicola Salmoria, Andreas Naive, and Charles MacDonald.

    All rights reserved.

***************************************************************************/

#ifndef __FD1089_H__
#define __FD1089_H__

#include "cpu/m68000/m68000.h"


//**************************************************************************
//  CONSTANTS
//**************************************************************************

// device type definition
extern const device_type FD1089A;
extern const device_type FD1089B;



//**************************************************************************
//  TYPE DEFINITIONS
//**************************************************************************

// ======================> fd1089_base_device

// base device, shared implementation between A and B variants
class fd1089_base_device : public m68000_device
{
public:
	// construction/destruction
	fd1089_base_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock, const char *shortname, const char *source);

	// explicit decryption helpers
	void decrypt(offs_t baseaddr, UINT32 size, offs_t regionoffs, UINT16 *opcodesptr, UINT16 *dataptr) { decrypt(baseaddr, size, &m_plaintext[regionoffs/2], opcodesptr, dataptr); }

protected:
	// device overrides
	virtual void device_start();

	// internal helpers
	UINT8 rearrange_key(UINT8 table, bool opcode);
	virtual UINT8 decode(UINT8 val, UINT8 key, bool opcode) = 0;
	UINT16 decrypt_one(offs_t addr, UINT16 val, const UINT8 *key, bool opcode);
	void decrypt(offs_t baseaddr, UINT32 size, const UINT16 *srcptr, UINT16 *opcodesptr, UINT16 *dataptr);

	// internal state
	const UINT8 *           m_key;
	std::vector<UINT16>          m_plaintext;
	required_shared_ptr<UINT16>  m_decrypted_opcodes;

	// internal types
	struct decrypt_parameters
	{
		UINT8 xorval;
		UINT8 s7,s6,s5,s4,s3,s2,s1,s0;
	};

	// static tables
	static const UINT8 s_basetable_fd1089[0x100];
	static const decrypt_parameters s_addr_params[16];
	static const decrypt_parameters s_data_params_a[16];
};


// ======================> fd1089a_device

// FD1089A variant
class fd1089a_device : public fd1089_base_device
{
public:
	// construction/destruction
	fd1089a_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);

protected:
	virtual UINT8 decode(UINT8 val, UINT8 key, bool opcode);
};


// ======================> fd1089b_device

// FD1089B variant
class fd1089b_device : public fd1089_base_device
{
public:
	// construction/destruction
	fd1089b_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);

protected:
	virtual UINT8 decode(UINT8 val, UINT8 key, bool opcode);
};


#endif