1 // license:BSD-3-Clause
2 // copyright-holders:Roberto Lavarone
3 /*****************************************************************************
4  *
5  * includes/z80ne.h
6  *
7  * Nuova Elettronica Z80NE
8  *
9  * http://www.z80ne.com/
10  *
11  ****************************************************************************/
12 
13 #ifndef MAME_INCLUDES_Z80NE_H
14 #define MAME_INCLUDES_Z80NE_H
15 
16 #pragma once
17 
18 #include "video/mc6847.h"
19 #include "imagedev/cassette.h"
20 #include "imagedev/floppy.h"
21 #include "machine/ay31015.h"
22 #include "machine/clock.h"
23 #include "machine/kr2376.h"
24 #include "machine/ram.h"
25 #include "machine/wd_fdc.h"
26 
27 /***************************************************************************
28     CONSTANTS
29 ***************************************************************************/
30 
31 #define Z80NE_CPU_SPEED_HZ      1920000 /* 1.92 MHz */
32 
33 #define LX383_KEYS          16
34 #define LX383_DOWNSAMPLING  16
35 
36 #define LX385_TAPE_SAMPLE_FREQ 38400
37 
38 /* wave duration threshold */
39 enum z80netape_speed
40 {
41 	TAPE_300BPS  = 300, /*  300 bps */
42 	TAPE_600BPS  = 600, /*  600 bps */
43 	TAPE_1200BPS = 1200 /* 1200 bps */
44 };
45 
46 struct z80ne_cass_data_t {
47 	struct {
48 		int length;     /* time cassette level is at input.level */
49 		int level;      /* cassette level */
50 		int bit;        /* bit being read */
51 	} input;
52 	struct {
53 		int length;     /* time cassette level is at output.level */
54 		int level;      /* cassette level */
55 		int bit;        /* bit to output */
56 	} output;
57 	z80netape_speed speed;          /* 300 - 600 - 1200 */
58 	int wave_filter;
59 	int wave_length;
60 	int wave_short;
61 	int wave_long;
62 };
63 
64 
65 class z80ne_state : public driver_device
66 {
67 public:
z80ne_state(const machine_config & mconfig,device_type type,const char * tag)68 	z80ne_state(const machine_config &mconfig, device_type type, const char *tag)
69 		: driver_device(mconfig, type, tag),
70 		m_uart(*this, "uart"),
71 		m_uart_clock(*this, "uart_clock"),
72 		m_maincpu(*this, "maincpu"),
73 		m_cassette1(*this, "cassette"),
74 		m_cassette2(*this, "cassette2"),
75 		m_ram(*this, RAM_TAG),
76 		m_bank1(*this, "bank1"),
77 		m_bank2(*this, "bank2"),
78 		m_bank3(*this, "bank3"),
79 		m_bank4(*this, "bank4"),
80 		m_io_row0(*this, "ROW0"),
81 		m_io_row1(*this, "ROW1"),
82 		m_io_ctrl(*this, "CTRL"),
83 		m_io_rst(*this, "RST"),
84 		m_io_lx_385(*this, "LX.385"),
85 		m_lx383_digits(*this, "digit%u", 0U)
86 		, m_rom(*this, "maincpu")
87 		, m_mram(*this, "mainram")
88 	{ }
89 
90 	void z80ne(machine_config &config);
91 	void init_z80ne();
92 
93 	DECLARE_INPUT_CHANGED_MEMBER(z80ne_reset);
94 
95 protected:
96 	virtual void machine_start() override;
97 	virtual void machine_reset() override;
98 
99 	void base_reset();
100 	void save_state_vars();
101 
102 	DECLARE_FLOPPY_FORMATS(floppy_formats);
103 
104 	uint8_t m_lx383_scan_counter;
105 	uint8_t m_lx383_key[LX383_KEYS];
106 	int m_lx383_downsampler;
107 	uint8_t m_lx385_ctrl;
108 	emu_timer *m_cassette_timer;
109 	emu_timer *m_kbd_timer;
110 	z80ne_cass_data_t m_cass_data;
111 
112 	uint8_t lx383_r();
113 	void lx383_w(offs_t offset, uint8_t data);
114 	uint8_t lx385_ctrl_r();
115 	void lx385_ctrl_w(uint8_t data);
116 	DECLARE_WRITE_LINE_MEMBER(lx385_uart_tx_clock_w);
117 
118 	TIMER_CALLBACK_MEMBER(z80ne_cassette_tc);
119 	TIMER_CALLBACK_MEMBER(z80ne_kbd_scan);
120 
121 	virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) override;
122 
123 	memory_passthrough_handler *m_rom_shadow_tap;
124 	required_device<ay31015_device> m_uart;
125 	required_device<clock_device> m_uart_clock;
126 	required_device<cpu_device> m_maincpu;
127 	required_device<cassette_image_device> m_cassette1;
128 	required_device<cassette_image_device> m_cassette2;
129 	optional_device<ram_device> m_ram;
130 	optional_memory_bank m_bank1;
131 	optional_memory_bank m_bank2;
132 	optional_memory_bank m_bank3;
133 	optional_memory_bank m_bank4;
134 	required_ioport m_io_row0;
135 	required_ioport m_io_row1;
136 	required_ioport m_io_ctrl;
137 	required_ioport m_io_rst;
138 	required_ioport m_io_lx_385;
139 	output_finder<8> m_lx383_digits;
140 	required_region_ptr<u8> m_rom;
141 	optional_shared_ptr<u8> m_mram;
142 
143 	emu_timer *m_timer_nmi;
144 
145 	cassette_image_device *cassette_device_image();
146 
147 private:
148 	void mem_map(address_map &map);
149 	void io_map(address_map &map);
150 };
151 
152 class z80net_state : public z80ne_state
153 {
154 public:
z80net_state(const machine_config & mconfig,device_type type,const char * tag)155 	z80net_state(const machine_config &mconfig, device_type type, const char *tag)
156 		: z80ne_state(mconfig, type, tag),
157 		m_videoram(*this, "videoram"),
158 		m_vdg(*this, "mc6847"),
159 		m_lx387_kr2376(*this, "lx387_kr2376"),
160 		m_io_lx387_brk(*this, "LX387_BRK"),
161 		m_io_modifiers(*this, "MODIFIERS")
162 	{
163 	}
164 
165 	void lx387(machine_config &config);
166 	void z80net(machine_config &config);
167 
168 	DECLARE_INPUT_CHANGED_MEMBER(z80net_nmi);
169 
170 protected:
171 	virtual void machine_reset() override;
172 
173 	DECLARE_READ_LINE_MEMBER(lx387_shift_r);
174 	DECLARE_READ_LINE_MEMBER(lx387_control_r);
175 	uint8_t lx387_data_r();
176 	uint8_t lx388_mc6847_videoram_r(offs_t offset);
177 	uint8_t lx388_read_field_sync();
178 
179 	required_shared_ptr<uint8_t> m_videoram;
180 	required_device<mc6847_base_device> m_vdg;
181 	required_device<kr2376_device> m_lx387_kr2376;
182 	required_ioport m_io_lx387_brk;
183 	required_ioport m_io_modifiers;
184 
185 	void reset_lx387();
186 
187 	void io_map(address_map &map);
188 
189 private:
190 	void mem_map(address_map &map);
191 };
192 
193 class z80netb_state : public z80net_state
194 {
195 public:
z80netb_state(const machine_config & mconfig,device_type type,const char * tag)196 	z80netb_state(const machine_config &mconfig, device_type type, const char *tag)
197 		: z80net_state(mconfig, type, tag)
198 	{
199 	}
200 
201 	void z80netb(machine_config &config);
202 
203 protected:
204 	virtual void machine_reset() override;
205 
206 private:
207 	void mem_map(address_map &map);
208 };
209 
210 class z80netf_state : public z80netb_state
211 {
212 public:
z80netf_state(const machine_config & mconfig,device_type type,const char * tag)213 	z80netf_state(const machine_config &mconfig, device_type type, const char *tag)
214 		: z80netb_state(mconfig, type, tag),
215 		m_io_config(*this, "CONFIG"),
216 		m_floppy(*this, "wd1771:%u", 0U),
217 		m_wd1771(*this, "wd1771"),
218 		m_drv_led(*this, "drv%u", 0U)
219 	{
220 	}
221 
222 	void z80netf(machine_config &config);
223 
224 private:
225 	virtual void machine_start() override;
226 	virtual void machine_reset() override;
227 	virtual void driver_init() override;
228 
229 	struct wd17xx_state_t
230 	{
231 		int drq;
232 		int intrq;
233 		uint8_t drive; /* current drive */
234 		uint8_t head;  /* current head */
235 	};
236 
237 	void mem_map(address_map &map);
238 	void io_map(address_map &map);
239 
240 	void lx390_motor_w(uint8_t data);
241 	uint8_t lx390_fdc_r(offs_t offset);
242 	void lx390_fdc_w(offs_t offset, uint8_t data);
243 
244 	void reset_lx390_banking();
245 
246 	required_ioport m_io_config;
247 	required_device_array<floppy_connector, 4> m_floppy;
248 	required_device<fd1771_device> m_wd1771;
249 	wd17xx_state_t m_wd17xx_state;
250 	output_finder<2> m_drv_led;
251 };
252 
253 #endif // MAME_INCLUDES_Z80NE_H
254