summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/cpu/scmp/scmp.h
blob: 4efb1d531c655574655c7a816e3afdb8a3567fe8 (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
117
118
119
120
// license:BSD-3-Clause
// copyright-holders:Miodrag Milanovic
#ifndef __SCMP_H__
#define __SCMP_H__


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

enum
{
	SCMP_PC, SCMP_P1, SCMP_P2, SCMP_P3, SCMP_AC, SCMP_ER, SCMP_SR,
	SCMP_GENPC = STATE_GENPC,
	SCMP_GENSP = STATE_GENSP,
	SCMP_GENPCBASE = STATE_GENPCBASE
};


#define MCFG_SCMP_CONFIG(_flag_out_devcb, _sout_devcb, _sin_devcb, _sensea_devcb, _senseb_devcb, _halt_devcb) \
	scmp_device::set_flag_out_cb(*device, DEVCB_##_flag_out_devcb); \
	scmp_device::set_sout_cb(*device, DEVCB_##_sout_devcb); \
	scmp_device::set_sin_cb(*device, DEVCB_##_sin_devcb); \
	scmp_device::set_sensea_cb(*device, DEVCB_##_sensea_devcb); \
	scmp_device::set_senseb_cb(*device, DEVCB_##_senseb_devcb); \
	scmp_device::set_halt_cb(*device, DEVCB_##_halt_devcb);


class scmp_device : public cpu_device
{
public:
	// construction/destruction
	scmp_device(const machine_config &mconfig, std::string tag, device_t *owner, UINT32 clock);
	scmp_device(const machine_config &mconfig, device_type type, const char *name, std::string tag, device_t *owner, UINT32 clock, const char *shortname, const char *source);

	// static configuration helpers
	template<class _Object> static devcb_base &set_flag_out_cb(device_t &device, _Object object) { return downcast<scmp_device &>(device).m_flag_out_func.set_callback(object); }
	template<class _Object> static devcb_base &set_sout_cb(device_t &device, _Object object) { return downcast<scmp_device &>(device).m_sout_func.set_callback(object); }
	template<class _Object> static devcb_base &set_sin_cb(device_t &device, _Object object) { return downcast<scmp_device &>(device).m_sin_func.set_callback(object); }
	template<class _Object> static devcb_base &set_sensea_cb(device_t &device, _Object object) { return downcast<scmp_device &>(device).m_sensea_func.set_callback(object); }
	template<class _Object> static devcb_base &set_senseb_cb(device_t &device, _Object object) { return downcast<scmp_device &>(device).m_senseb_func.set_callback(object); }
	template<class _Object> static devcb_base &set_halt_cb(device_t &device, _Object object) { return downcast<scmp_device &>(device).m_halt_func.set_callback(object); }

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

	// device_execute_interface overrides
	virtual UINT32 execute_min_cycles() const override { return 5; }
	virtual UINT32 execute_max_cycles() const override { return 131593; }
	virtual UINT32 execute_input_lines() const override { return 0; }
	virtual void execute_run() override;

	// device_memory_interface overrides
	virtual const address_space_config *memory_space_config(address_spacenum spacenum = AS_0) const override { return (spacenum == AS_PROGRAM) ? &m_program_config : nullptr; }

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

	// device_disasm_interface overrides
	virtual UINT32 disasm_min_opcode_bytes() const override { return 1; }
	virtual UINT32 disasm_max_opcode_bytes() const override { return 2; }
	virtual offs_t disasm_disassemble(char *buffer, offs_t pc, const UINT8 *oprom, const UINT8 *opram, UINT32 options) override;

private:
	address_space_config m_program_config;

	PAIR    m_PC;
	PAIR    m_P1;
	PAIR    m_P2;
	PAIR    m_P3;
	UINT8   m_AC;
	UINT8   m_ER;
	UINT8   m_SR;

	address_space *m_program;
	direct_read_data *m_direct;
	int                 m_icount;

	devcb_write8       m_flag_out_func;
	devcb_write_line   m_sout_func;
	devcb_read_line    m_sin_func;
	devcb_read_line    m_sensea_func;
	devcb_read_line    m_senseb_func;
	devcb_write_line   m_halt_func;

	inline UINT16 ADD12(UINT16 addr, INT8 val);
	inline UINT8 ROP();
	inline UINT8 ARG();
	inline UINT8 RM(UINT32 a);
	inline void WM(UINT32 a, UINT8 v);
	inline void illegal(UINT8 opcode);
	inline PAIR *GET_PTR_REG(int num);
	inline void BIN_ADD(UINT8 val);
	inline void DEC_ADD(UINT8 val);
	inline UINT16 GET_ADDR(UINT8 code);
	void execute_one(int opcode);
	void take_interrupt();

};


class ins8060_device : public scmp_device
{
public:
	// construction/destruction
	ins8060_device(const machine_config &mconfig, std::string tag, device_t *owner, UINT32 clock);

protected:
	virtual UINT64 execute_clocks_to_cycles(UINT64 clocks) const override { return (clocks + 2 - 1) / 2; }
	virtual UINT64 execute_cycles_to_clocks(UINT64 cycles) const override { return (cycles * 2); }
};


extern const device_type SCMP;
extern const device_type INS8060;


#endif