summaryrefslogtreecommitdiffstatshomepage
path: root/src/mess/includes/coco.h
blob: 6e8ff9f80b266df0ae0ad4b565e1dcd0afc4808e (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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
/***************************************************************************

    coco.h

    TRS-80 Radio Shack Color Computer Family

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

#pragma once

#ifndef __COCO__
#define __COCO__


#include "emu.h"
#include "imagedev/cassette.h"
#include "imagedev/bitbngr.h"
#include "machine/6821pia.h"
#include "machine/cococart.h"
#include "machine/coco_vhd.h"
#include "machine/ram.h"
#include "sound/dac.h"
#include "sound/wave.h"



//**************************************************************************
//  MACROS / CONSTANTS
//**************************************************************************

INPUT_PORTS_EXTERN( coco_analog_control );
INPUT_PORTS_EXTERN( coco_cart_autostart );

SLOT_INTERFACE_EXTERN( coco_cart );

/* constants */
#define JOYSTICK_DELTA			10
#define JOYSTICK_SENSITIVITY	100

/* devices */
#define MAINCPU_TAG					"maincpu"
#define PIA0_TAG					"pia0"
#define PIA1_TAG					"pia1"
#define SAM_TAG						"sam"
#define VDG_TAG						"vdg"
#define SCREEN_TAG					"screen"
#define DAC_TAG						"dac"
#define CARTRIDGE_TAG				"ext"
#define BITBANGER_TAG				"bitbanger"
#define VHD0_TAG					"vhd0"
#define VHD1_TAG					"vhd1"

/* inputs */
#define CTRL_SEL_TAG				"ctrl_sel"
#define HIRES_INTF_TAG				"hires_intf"
#define CART_AUTOSTART_TAG			"cart_autostart"
#define JOYSTICK_RX_TAG				"joystick_rx"
#define JOYSTICK_RY_TAG				"joystick_ry"
#define JOYSTICK_LX_TAG				"joystick_lx"
#define JOYSTICK_LY_TAG				"joystick_ly"
#define JOYSTICK_BUTTONS_TAG		"joystick_buttons"
#define RAT_MOUSE_RX_TAG			"rat_mouse_rx"
#define RAT_MOUSE_RY_TAG			"rat_mouse_ry"
#define RAT_MOUSE_LX_TAG			"rat_mouse_lx"
#define RAT_MOUSE_LY_TAG			"rat_mouse_ly"
#define RAT_MOUSE_BUTTONS_TAG		"rat_mouse_buttons"
#define DIECOM_LIGHTGUN_RX_TAG		"dclg_rx"
#define DIECOM_LIGHTGUN_RY_TAG		"dclg_ry"
#define DIECOM_LIGHTGUN_LX_TAG		"dclg_lx"
#define DIECOM_LIGHTGUN_LY_TAG		"dclg_ly"
#define DIECOM_LIGHTGUN_BUTTONS_TAG	"dclg_triggers"

MACHINE_CONFIG_EXTERN( coco_sound );



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

class coco_state : public driver_device
{
public:
	coco_state(const machine_config &mconfig, device_type type, const char *tag)
	: driver_device(mconfig, type, tag),
	  m_maincpu(*this, MAINCPU_TAG),
	  m_pia_0(*this, PIA0_TAG),
	  m_pia_1(*this, PIA1_TAG),
	  m_dac(*this, DAC_TAG),
	  m_wave(*this, WAVE_TAG),
	  m_cococart(*this, CARTRIDGE_TAG),
	  m_ram(*this, RAM_TAG),
	  m_cassette(*this, CASSETTE_TAG),
	  m_bitbanger(*this, BITBANGER_TAG),
	  m_vhd_0(*this, VHD0_TAG),
	  m_vhd_1(*this, VHD1_TAG)
	{
	}

	required_device<cpu_device> m_maincpu;
	required_device<pia6821_device> m_pia_0;
	required_device<pia6821_device> m_pia_1;
	required_device<dac_device> m_dac;
	required_device<device_t> m_wave;
	required_device<cococart_slot_device> m_cococart;
	required_device<ram_device> m_ram;
	required_device<cassette_image_device> m_cassette;
	optional_device<bitbanger_device> m_bitbanger;
	optional_device<coco_vhd_image_device> m_vhd_0;
	optional_device<coco_vhd_image_device> m_vhd_1;

	static const pia6821_interface pia0_config;
	static const pia6821_interface pia1_config;
	static const cococart_interface cartridge_config;
	static const bitbanger_config coco_bitbanger_config;
	static const cassette_interface coco_cassette_interface;

	/* driver update handlers */
	static INPUT_CHANGED(keyboard_changed);
	static INPUT_CHANGED(joystick_mode_changed);
	static void bitbanger_callback(running_machine &machine, UINT8 bit);

	/* IO */
	virtual DECLARE_READ8_MEMBER( ff00_read );
	virtual DECLARE_WRITE8_MEMBER( ff00_write );
	virtual DECLARE_READ8_MEMBER( ff20_read );
	virtual DECLARE_WRITE8_MEMBER( ff20_write );
	virtual DECLARE_READ8_MEMBER( ff40_read );
	virtual DECLARE_WRITE8_MEMBER( ff40_write );
	DECLARE_READ8_MEMBER( ff60_read );
	DECLARE_WRITE8_MEMBER( ff60_write );

	/* floating bus */
	DECLARE_READ8_MEMBER( floating_bus_read )	{ return floating_bus_read(); }

protected:
	/* device-level overrides */
	virtual void device_start();
	virtual void device_reset();
	virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);

	/* interrupts */
	virtual bool firq_get_line(void);
	virtual bool irq_get_line(void);
	void recalculate_irq(void);
	void recalculate_firq(void);

	/* changed handlers */
	virtual void pia1_pa_changed(void);
	virtual void pia1_pb_changed(void);
	virtual void bitbanger_changed(bool newvalue);

	/* miscellaneous */
	virtual void update_keyboard_input(UINT8 value, UINT8 z);
	virtual void cart_w(bool state);
	DECLARE_WRITE_LINE_MEMBER( cart_w ) { cart_w((bool) state); }
	virtual void update_cart_base(UINT8 *cart_base) = 0;

	/* PIA0 */
	DECLARE_WRITE8_MEMBER( pia0_pb_w );
	DECLARE_WRITE_LINE_MEMBER( pia0_ca2_w );
	DECLARE_WRITE_LINE_MEMBER( pia0_cb2_w );
	DECLARE_WRITE_LINE_MEMBER( pia0_irq_a );
	DECLARE_WRITE_LINE_MEMBER( pia0_irq_b );

	/* PIA1 */
	DECLARE_READ8_MEMBER( pia1_pa_r );
	DECLARE_READ8_MEMBER( pia1_pb_r );
	DECLARE_WRITE8_MEMBER( pia1_pa_w );
	DECLARE_WRITE8_MEMBER( pia1_pb_w );
	DECLARE_WRITE_LINE_MEMBER( pia1_ca2_w );
	DECLARE_WRITE_LINE_MEMBER( pia1_cb2_w );
	DECLARE_WRITE_LINE_MEMBER( pia1_firq_a );
	DECLARE_WRITE_LINE_MEMBER( pia1_firq_b );

private:
	// timer constants
	static const device_timer_id TIMER_HIRES_JOYSTICK_X = 0;
	static const device_timer_id TIMER_HIRES_JOYSTICK_Y = 1;
	static const device_timer_id TIMER_DIECOM_LIGHTGUN = 2;

	typedef enum
	{
		SOUNDMUX_SEL1 = 1,
		SOUNDMUX_SEL2 = 2,
		SOUNDMUX_ENABLE = 4
	} soundmux_status_t;

	typedef enum
	{
		JOYSTICK_NONE = 0x00,
		JOYSTICK_NORMAL = 0x01,
		JOYSTICK_RAT_MOUSE = 0x02,
		JOYSTICK_DIECOM_LIGHT_GUN = 0x03
	} joystick_type_t;

	typedef enum
	{
		HIRES_NONE = 0x00,
		HIRES_RIGHT = 0x01,
		HIRES_RIGHT_COCOMAX3 = 0x02,
		HIRES_LEFT = 0x03,
		HIRES_LEFT_COCOMAX3 = 0x04,
	} hires_type_t;

	typedef struct
	{
		ioport_port *m_input[2][2];
		ioport_port *m_buttons;

		UINT8 input(int joystick, int axis) const { return m_input[joystick][axis] ? m_input[joystick][axis]->read() : 0x00; }
		UINT8 buttons(void) const { return m_buttons ? m_buttons->read() : 0x00; }
	} analog_input_t;

	void analog_port_start(analog_input_t *analog, const char *rx_tag, const char *ry_tag, const char *lx_tag, const char *ly_tag, const char *buttons_tag);

	/* wrappers for configuration */
	joystick_type_t joystick_type(int index);
	hires_type_t hires_interface_type(void);
	bool is_joystick_hires(int joystick_index);

	soundmux_status_t soundmux_status(void);
	UINT8 sound_value(void);
	void update_sound(void);
	bool joyin(void);
	void poll_joystick(bool *joyin, UINT8 *buttons);
	void poll_keyboard(void);
	void poll_hires_joystick(void);
	void update_cassout(int cassout);
	void update_prinout(bool prinout);
	DECLARE_WRITE_LINE_MEMBER( bitbanger_callback );
	void diecom_lightgun_clock(void);

	/* thin wrappers for PIA output */
	UINT8 dac_output(void)	{ return m_dac_output; }	/* PA drives the DAC */
	bool sel1(void)			{ return m_pia_0->ca2_output() ? true : false; }
	bool sel2(void)			{ return m_pia_0->cb2_output() ? true : false; }
	bool snden(void)		{ return m_pia_1->cb2_output() ? true : false; }

	/* VHD selection */
	coco_vhd_image_device *current_vhd(void);

	/* floating bus */
	UINT8 floating_bus_read(void);

	/* disassembly override */
	static offs_t dasm_override(device_t &device, char *buffer, offs_t pc, const UINT8 *oprom, const UINT8 *opram, int options);

	/* input ports */
	ioport_port *m_keyboard[7];
	ioport_port *m_joystick_type_control;
	ioport_port *m_joystick_hires_control;
	analog_input_t m_joystick;
	analog_input_t m_rat_mouse;
	analog_input_t m_diecom_lightgun;

	/* DAC output */
	UINT8 m_dac_output;

	/* hires interface */
	emu_timer *m_hiresjoy_transition_timer[2];
	bool m_hiresjoy_ca;

	/* diecom lightgun */
	emu_timer *m_diecom_lightgun_timer;
	bool m_dclg_previous_bit;
	UINT8 m_dclg_output_h;
	UINT8 m_dclg_output_v;
	UINT8 m_dclg_state;
	UINT16 m_dclg_timer;

	/* VHD selection */
	UINT8 m_vhd_select;
};

#endif /* __COCO__ */