summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/cpu/upd78k/upd78k2.h
blob: a18ceefb39623acd28a2dfe15db6ba6a21193ea7 (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
105
106
107
108
109
110
111
112
113
114
115
116
// license:BSD-3-Clause
// copyright-holders:AJR
/**********************************************************************

    NEC 78K/II series 8-bit single-chip microcontrollers

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

#ifndef MAME_CPU_UPD78K_UPD78K2_H
#define MAME_CPU_UPD78K_UPD78K2_H

#pragma once

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

// ======================> upd78k2_device

class upd78k2_device : public cpu_device
{
public:
	enum {
		UPD78K2_PC,
		UPD78K2_PSW, UPD78K2_RBS, UPD78K2_SP,
		UPD78K2_AX, UPD78K2_BC,
		UPD78K2_DE, UPD78K2_HL,
		UPD78K2_X, UPD78K2_A, UPD78K2_C, UPD78K2_B,
		UPD78K2_E, UPD78K2_D, UPD78K2_L, UPD78K2_H
	};

	// TODO: callbacks and configuration thereof

protected:
	upd78k2_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, u32 clock, int iram_bits, address_map_constructor mem_map, address_map_constructor sfr_map);

	// device-level overrides
	virtual void device_start() override;
	virtual void device_reset() override;

	// device_execute_interface overrides
	virtual void execute_run() override;
	virtual u64 execute_clocks_to_cycles(u64 clocks) const noexcept override { return (clocks + 2 - 1) / 2; }
	virtual u64 execute_cycles_to_clocks(u64 cycles) const noexcept override { return (cycles * 2); }

	// device_memory_interface overrides
	virtual space_config_vector memory_space_config() const override;

	// device_state_interface overrides
	virtual void state_string_export(const device_state_entry &entry, std::string &str) const override;

private:
	// internal memory map
	void iram_map(address_map &map);

	// internal helpers
	inline u8 register_base() const noexcept;

	// address spaces, caches & configuration
	address_space_config m_program_config;
	address_space_config m_iram_config;
	address_space_config m_sfr_config;
	const offs_t m_iram_addrmask;
	address_space *m_program_space;
	memory_access_cache<0, 0, ENDIANNESS_LITTLE> *m_program_cache;
	memory_access_cache<1, 0, ENDIANNESS_LITTLE> *m_iram_cache;
	address_space *m_sfr_space;

	// core registers and execution state
	u16 m_pc;
	u16 m_ppc;
	u8 m_psw;
	u16 m_sp;
	s32 m_icount;
};

// ======================> upd78210_device

class upd78210_device : public upd78k2_device
{
public:
	// device type constructor
	upd78210_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock);

protected:
	// device_disasm_interface overrides
	virtual std::unique_ptr<util::disasm_interface> create_disassembler() override;

private:
	// type-specific internal memory maps
	void sfr_map(address_map &map);
};

// ======================> upd78213_device

class upd78213_device : public upd78k2_device
{
public:
	// device type constructor
	upd78213_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock);

protected:
	// device_disasm_interface overrides
	virtual std::unique_ptr<util::disasm_interface> create_disassembler() override;

private:
	// type-specific internal memory maps
	void mem_map(address_map &map);
	void sfr_map(address_map &map);
};

// device type declarations
DECLARE_DEVICE_TYPE(UPD78210, upd78210_device)
DECLARE_DEVICE_TYPE(UPD78213, upd78213_device)

#endif // MAME_CPU_UPD78K_UPD78K2_H