1 // license:BSD-3-Clause
2 // copyright-holders:Ernesto Corvi
3 
4 #include "cpu/m6805/m68705.h"
5 #include "cpu/m6800/m6801.h"
6 
7 #include "sound/2203intf.h"
8 #include "emupal.h"
9 #include "screen.h"
10 
11 class kikikai_state : public driver_device
12 {
13 public:
kikikai_state(const machine_config & mconfig,device_type type,const char * tag)14 	kikikai_state(const machine_config &mconfig, device_type type, const char *tag)
15 		: driver_device(mconfig, type, tag),
16 		m_maincpu(*this, "maincpu"),
17 		m_audiocpu(*this, "audiocpu"),
18 		m_screen(*this, "screen"),
19 		m_mcu_sharedram(*this, "mcu_sharedram"),
20 		m_mainram(*this, "mainram"),
21 		m_subcpu(*this, "sub"),
22 		m_mcu(*this, "mcu"),
23 		m_ymsnd(*this, "ymsnd"),
24 		m_gfxdecode(*this, "gfxdecode"),
25 		m_palette(*this, "palette")
26 	{
27 	}
28 
29 	void base(machine_config &config);
30 	void kicknrun(machine_config &config);
31 
32 protected:
33 	required_device<cpu_device>         m_maincpu;
34 	required_device<cpu_device>         m_audiocpu;
35 	required_device<screen_device>      m_screen;
36 	required_shared_ptr<u8> m_mcu_sharedram;
37 
38 	u32 screen_update_kicknrun(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
39 	u32 screen_update_kikikai(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
40 
41 	virtual void machine_start() override;
42 	virtual void machine_reset() override;
43 
44 private:
45 	/* memory pointers */
46 	required_shared_ptr<u8> m_mainram;
47 
48 	/* video-related */
49 	int      m_charbank;
50 
51 	/* devices */
52 	optional_device<cpu_device>         m_subcpu;   // kicknrun / mexico86 only
53 	optional_device<cpu_device>         m_mcu;
54 	required_device<ym2203_device>      m_ymsnd;
55 	required_device<gfxdecode_device>   m_gfxdecode;
56 	required_device<palette_device>     m_palette;
57 
58 	/* queue */
59 	//u8 m_queue[64];
60 	//int m_qfront;
61 	//int m_qstate;
62 	void kicknrun_sub_output_w(uint8_t data);
63 	virtual void main_f008_w(uint8_t data);
64 
65 	void main_bankswitch_w(uint8_t data);
66 	uint8_t kiki_ym2203_r(offs_t offset);
67 
68 	virtual INTERRUPT_GEN_MEMBER(kikikai_interrupt);
69 
70 	void main_map(address_map &map);
71 	void sound_map(address_map &map);
72 	void kicknrun_sub_cpu_map(address_map &map);
73 	void mcu_map(address_map& map);
74 
75 	/* Kiki KaiKai / Kick 'n Run MCU */
76 	uint8_t    m_ddr1;
77 	uint8_t    m_ddr2;
78 	uint8_t    m_ddr3;
79 	uint8_t    m_ddr4;
80 	uint8_t    m_port1_in;
81 	uint8_t    m_port2_in;
82 	uint8_t    m_port3_in;
83 	uint8_t    m_port4_in;
84 	uint8_t    m_port1_out;
85 	uint8_t    m_port2_out;
86 	uint8_t    m_port3_out;
87 	uint8_t    m_port4_out;
88 
89 	uint8_t kikikai_mcu_ddr1_r();
90 	void kikikai_mcu_ddr1_w(uint8_t data);
91 	uint8_t kikikai_mcu_ddr2_r();
92 	void kikikai_mcu_ddr2_w(uint8_t data);
93 	uint8_t kikikai_mcu_ddr3_r();
94 	void kikikai_mcu_ddr3_w(uint8_t data);
95 	uint8_t kikikai_mcu_ddr4_r();
96 	void kikikai_mcu_ddr4_w(uint8_t data);
97 	uint8_t kikikai_mcu_port1_r();
98 	void kikikai_mcu_port1_w(uint8_t data);
99 	uint8_t kikikai_mcu_port2_r();
100 	void kikikai_mcu_port2_w(uint8_t data);
101 	uint8_t kikikai_mcu_port3_r();
102 	void kikikai_mcu_port3_w(uint8_t data);
103 	uint8_t kikikai_mcu_port4_r();
104 	void kikikai_mcu_port4_w(uint8_t data);
105 };
106 
107 class mexico86_state : public kikikai_state
108 {
109 public:
mexico86_state(const machine_config & mconfig,device_type type,const char * tag)110 	mexico86_state(const machine_config& mconfig, device_type type, const char* tag)
111 		: kikikai_state(mconfig, type, tag),
112 		m_68705mcu(*this, "68705mcu")
113 	{
114 	}
115 
116 	void mexico86_68705(machine_config& config);
117 	void knightb(machine_config &config);
118 
119 protected:
120 	virtual void machine_start() override;
121 	virtual void machine_reset() override;
122 
123 private:
124 	virtual void main_f008_w(uint8_t data) override;
125 
126 	INTERRUPT_GEN_MEMBER(mexico86_m68705_interrupt);
127 	void mexico86_68705_port_a_w(u8 data);
128 	void mexico86_68705_port_b_w(offs_t offset, u8 data, u8 mem_mask = ~0);
129 
130 	optional_device<m68705p_device>     m_68705mcu;
131 
132 	/* mcu */
133 	/* mexico86 68705 protection */
134 	u8       m_port_a_out;
135 	u8       m_port_b_out;
136 	int      m_address;
137 	u8       m_latch;
138 
139 };
140 
141 class kikikai_simulation_state : public kikikai_state
142 {
143 public:
kikikai_simulation_state(const machine_config & mconfig,device_type type,const char * tag)144 	kikikai_simulation_state(const machine_config& mconfig, device_type type, const char* tag)
145 		: kikikai_state(mconfig, type, tag)
146 	{
147 	}
148 
149 	void kikikai(machine_config& config);
150 
151 protected:
152 	virtual void machine_start() override;
153 	virtual void machine_reset() override;
154 
155 private:
156 	virtual void main_f008_w(uint8_t data) override;
157 
158 	virtual INTERRUPT_GEN_MEMBER(kikikai_interrupt) override;
159 
160 	void mcu_simulate(  );
161 
162 	/* kikikai mcu simulation */
163 	int      m_kikikai_simulated_mcu_running;
164 	int      m_kikikai_simulated_mcu_initialised;
165 	bool     m_coin_last[2];
166 	u8       m_coin_fract;
167 };
168