summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/includes/z80ne.h
blob: 0339c9e9d27cd7f218f042a6dcf69b10ae6f4e46 (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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
// license:BSD-3-Clause
// copyright-holders:Roberto Lavarone
/*****************************************************************************
 *
 * includes/z80ne.h
 *
 * Nuova Elettronica Z80NE
 *
 * http://www.z80ne.com/
 *
 ****************************************************************************/

#ifndef MAME_INCLUDES_Z80NE_H
#define MAME_INCLUDES_Z80NE_H

#pragma once

#include "video/mc6847.h"
#include "imagedev/cassette.h"
#include "machine/ay31015.h"
#include "machine/kr2376.h"
#include "machine/wd_fdc.h"

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

#define Z80NE_CPU_SPEED_HZ      1920000 /* 1.92 MHz */

#define LX383_KEYS          16
#define LX383_DOWNSAMPLING  16

#define LX385_TAPE_SAMPLE_FREQ 38400

/* wave duration threshold */
enum z80netape_speed
{
	TAPE_300BPS  = 300, /*  300 bps */
	TAPE_600BPS  = 600, /*  600 bps */
	TAPE_1200BPS = 1200 /* 1200 bps */
};

struct z80ne_cass_data_t {
	struct {
		int length;     /* time cassette level is at input.level */
		int level;      /* cassette level */
		int bit;        /* bit being read */
	} input;
	struct {
		int length;     /* time cassette level is at output.level */
		int level;      /* cassette level */
		int bit;        /* bit to output */
	} output;
	z80netape_speed speed;          /* 300 - 600 - 1200 */
	int wave_filter;
	int wave_length;
	int wave_short;
	int wave_long;
};


class z80ne_state : public driver_device
{
public:
	z80ne_state(const machine_config &mconfig, device_type type, const char *tag)
		: driver_device(mconfig, type, tag),
		m_vdg(*this, "mc6847"),
		m_videoram(*this, "videoram"),
		m_uart(*this, "uart"),
		m_lx387_kr2376(*this, "lx387_kr2376"),
		m_maincpu(*this, "z80ne"),
		m_cassette1(*this, "cassette"),
		m_cassette2(*this, "cassette2"),
		m_region_z80ne(*this, "z80ne"),
		m_bank1(*this, "bank1"),
		m_bank2(*this, "bank2"),
		m_bank3(*this, "bank3"),
		m_bank4(*this, "bank4"),
		m_io_row0(*this, "ROW0"),
		m_io_row1(*this, "ROW1"),
		m_io_ctrl(*this, "CTRL"),
		m_io_rst(*this, "RST"),
		m_io_lx_385(*this, "LX.385"),
		m_io_lx387_brk(*this, "LX387_BRK"),
		m_io_modifiers(*this, "MODIFIERS"),
		m_lx383_digits(*this, "digit%u", 0U)
	{
	}

	DECLARE_FLOPPY_FORMATS(floppy_formats);

	optional_device<mc6847_base_device> m_vdg;
	optional_shared_ptr<uint8_t> m_videoram;
	required_device<ay31015_device> m_uart;
	optional_device<kr2376_device> m_lx387_kr2376;
	uint8_t m_lx383_scan_counter;
	uint8_t m_lx383_key[LX383_KEYS];
	int m_lx383_downsampler;
	uint8_t m_lx385_ctrl;
	emu_timer *m_cassette_timer;
	emu_timer *m_kbd_timer;
	z80ne_cass_data_t m_cass_data;
	DECLARE_READ8_MEMBER(lx383_r);
	DECLARE_WRITE8_MEMBER(lx383_w);
	DECLARE_READ8_MEMBER(lx385_ctrl_r);
	DECLARE_WRITE8_MEMBER(lx385_ctrl_w);
	DECLARE_READ_LINE_MEMBER(lx387_shift_r);
	DECLARE_READ_LINE_MEMBER(lx387_control_r);
	DECLARE_READ8_MEMBER(lx387_data_r);
	DECLARE_READ8_MEMBER(lx388_read_field_sync);
	void init_z80net();
	void init_z80netb();
	void init_z80ne();
	void machine_start_z80ne()   ATTR_COLD;
	void machine_reset_z80ne();
	void machine_start_z80netb() ATTR_COLD;
	void machine_reset_z80netb();
	void machine_start_z80net()  ATTR_COLD;
	void machine_reset_z80net();
	void machine_reset_z80ne_base();
	DECLARE_INPUT_CHANGED_MEMBER(z80ne_reset);
	DECLARE_INPUT_CHANGED_MEMBER(z80ne_nmi);
	TIMER_CALLBACK_MEMBER(z80ne_cassette_tc);
	TIMER_CALLBACK_MEMBER(z80ne_kbd_scan);
	DECLARE_READ8_MEMBER(lx388_mc6847_videoram_r);

	void z80net(machine_config &config);
	void z80ne(machine_config &config);
	void z80netb(machine_config &config);
	void z80ne_io(address_map &map);
	void z80ne_mem(address_map &map);
	void z80net_io(address_map &map);
	void z80net_mem(address_map &map);
	void z80netb_mem(address_map &map);
protected:
	virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) override;

	required_device<cpu_device> m_maincpu;
	required_device<cassette_image_device> m_cassette1;
	required_device<cassette_image_device> m_cassette2;
	required_memory_region m_region_z80ne;
	optional_memory_bank m_bank1;
	optional_memory_bank m_bank2;
	optional_memory_bank m_bank3;
	optional_memory_bank m_bank4;
	required_ioport m_io_row0;
	required_ioport m_io_row1;
	required_ioport m_io_ctrl;
	required_ioport m_io_rst;
	required_ioport m_io_lx_385;
	optional_ioport m_io_lx387_brk;
	optional_ioport m_io_modifiers;
	output_finder<8> m_lx383_digits;

	emu_timer *m_timer_nmi;
	emu_timer *m_timer_reset;

	cassette_image_device *cassette_device_image();
	void reset_lx387();
	void reset_lx382_banking();
};

class z80netf_state : public z80ne_state
{
	struct wd17xx_state_t
	{
		int drq;
		int intrq;
		uint8_t drive; /* current drive */
		uint8_t head;  /* current head */
	};

public:
	z80netf_state(const machine_config &mconfig, device_type type, const char *tag)
		: z80ne_state(mconfig, type, tag),
		m_io_config(*this, "CONFIG"),
		m_floppy(*this, "wd1771:%u", 0U),
		m_wd1771(*this, "wd1771"),
		m_drv_led(*this, "drv%u", 0U)
	{
	}

	void init_z80netf();
	void z80netf(machine_config &config);
private:
	void z80netf_io(address_map &map);
	void z80netf_mem(address_map &map);

	void machine_start_z80netf() ATTR_COLD;
	void machine_reset_z80netf();

	DECLARE_WRITE8_MEMBER(lx390_motor_w);
	DECLARE_READ8_MEMBER(lx390_reset_bank);
	DECLARE_READ8_MEMBER(lx390_fdc_r);
	DECLARE_WRITE8_MEMBER(lx390_fdc_w);

	void reset_lx390_banking();

	required_ioport m_io_config;
	required_device_array<floppy_connector, 4> m_floppy;
	required_device<fd1771_device> m_wd1771;
	wd17xx_state_t m_wd17xx_state;
	output_finder<2> m_drv_led;
};

#endif // MAME_INCLUDES_Z80NE_H