summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/includes/tx0.h
blob: 65b141269fec89a12ffaf6a42c0216bc91cec1a5 (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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
// license:GPL-2.0+
// copyright-holders:Raphael Nabet
/*****************************************************************************
 *
 * includes/tx0.h
 *
 ****************************************************************************/

#ifndef MAME_INCLUDES_TX0_H
#define MAME_INCLUDES_TX0_H

#include "video/crt.h"
#include "cpu/pdp1/tx0.h"

enum state_t
{
	MTS_UNSELECTED,
	MTS_SELECTING,
	MTS_SELECTED,
	MTS_UNSELECTING
};

enum backspace_state_t
{
	MTBSS_STATE0,
	MTBSS_STATE1,
	MTBSS_STATE2,
	MTBSS_STATE3,
	MTBSS_STATE4,
	MTBSS_STATE5,
	MTBSS_STATE6
};

enum state_2_t
{
	MTRDS_STATE0,
	MTRDS_STATE1,
	MTRDS_STATE2,
	MTRDS_STATE3,
	MTRDS_STATE4,
	MTRDS_STATE5,
	MTRDS_STATE6
};

enum state_3_t
{
	MTWTS_STATE0,
	MTWTS_STATE1,
	MTWTS_STATE2,
	MTWTS_STATE3
};

enum irg_pos_t
{
	MTIRGP_START,
	MTIRGP_ENDMINUS1,
	MTIRGP_END
};



/* tape reader registers */
struct tx0_tape_reader_t
{
	device_image_interface *fd; /* file descriptor of tape image */

	int motor_on;   /* 1-bit reader motor on */

	int rcl;        /* 1-bit reader clutch */
	int rc;         /* 2-bit reader counter */

	emu_timer *timer;   /* timer to simulate reader timing */
};



/* tape puncher registers */
struct tape_puncher_t
{
	device_image_interface *fd; /* file descriptor of tape image */

	emu_timer *timer;   /* timer to generate completion pulses */
};



/* typewriter registers */
struct tx0_typewriter_t
{
	device_image_interface *fd; /* file descriptor of output image */

	emu_timer *prt_timer;/* timer to generate completion pulses */
};


/* magnetic tape unit registers */
struct magtape_t
{
	device_image_interface *img;        /* image descriptor */

	state_t state;

	int command;
	int binary_flag;

	union
	{
		backspace_state_t backspace_state;
		struct
		{
			state_2_t state;
			int space_flag;
		} read;
		struct
		{
			state_3_t state;
			int counter;
		} write;
	} u;

	int sel_pending;
	int cpy_pending;

	irg_pos_t irg_pos;          /* position relative to inter-record gap */

	int long_parity;

	emu_timer *timer;   /* timer to simulate reader timing */
};


class tx0_state : public driver_device
{
public:
	tx0_state(const machine_config &mconfig, device_type type, const char *tag)
		: driver_device(mconfig, type, tag),
		m_maincpu(*this, "maincpu"),
		m_gfxdecode(*this, "gfxdecode"),
		m_palette(*this, "palette"),
		m_crt(*this, "crt"),
		m_csw(*this, "CSW"),
		m_twr(*this, "TWR.%u", 0)
	{ }

	tx0_tape_reader_t m_tape_reader;
	tape_puncher_t m_tape_puncher;
	tx0_typewriter_t m_typewriter;
	emu_timer *m_dis_timer;
	magtape_t m_magtape;
	int m_old_typewriter_keys[4];
	int m_old_control_keys;
	int m_old_tsr_keys;
	int m_tsr_index;
	int m_typewriter_color;
	bitmap_ind16 m_panel_bitmap;
	bitmap_ind16 m_typewriter_bitmap;
	int m_pos;
	int m_case_shift;
	void init_tx0();
	virtual void machine_start() override;
	virtual void machine_reset() override;
	virtual void video_start() override;
	DECLARE_PALETTE_INIT(tx0);
	uint32_t screen_update_tx0(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
	DECLARE_WRITE_LINE_MEMBER(screen_vblank_tx0);
	INTERRUPT_GEN_MEMBER(tx0_interrupt);
	TIMER_CALLBACK_MEMBER(reader_callback);
	TIMER_CALLBACK_MEMBER(puncher_callback);
	TIMER_CALLBACK_MEMBER(prt_callback);
	TIMER_CALLBACK_MEMBER(dis_callback);
	void tx0_machine_stop();
	required_device<tx0_device> m_maincpu;
	inline void tx0_plot_pixel(bitmap_ind16 &bitmap, int x, int y, uint32_t color);
	void tx0_plot(int x, int y);
	void tx0_draw_led(bitmap_ind16 &bitmap, int x, int y, int state);
	void tx0_draw_multipleled(bitmap_ind16 &bitmap, int x, int y, int value, int nb_bits);
	void tx0_draw_switch(bitmap_ind16 &bitmap, int x, int y, int state);
	void tx0_draw_multipleswitch(bitmap_ind16 &bitmap, int x, int y, int value, int nb_bits);
	void tx0_draw_char(bitmap_ind16 &bitmap, char character, int x, int y, int color);
	void tx0_draw_string(bitmap_ind16 &bitmap, const char *buf, int x, int y, int color);
	void tx0_draw_vline(bitmap_ind16 &bitmap, int x, int y, int height, int color);
	void tx0_draw_panel_backdrop(bitmap_ind16 &bitmap);
	void tx0_draw_panel(bitmap_ind16 &bitmap);
	void tx0_typewriter_linefeed();
	void tx0_typewriter_drawchar(int character);
	int tape_read(uint8_t *reply);
	void tape_write(uint8_t data);
	void begin_tape_read(int binary);
	void typewriter_out(uint8_t data);
	void schedule_select();
	void schedule_unselect();
	void tx0_keyboard();
	DECLARE_WRITE_LINE_MEMBER(tx0_io_cpy);
	DECLARE_WRITE_LINE_MEMBER(tx0_io_r1l);
	DECLARE_WRITE_LINE_MEMBER(tx0_io_r3l);
	DECLARE_WRITE_LINE_MEMBER(tx0_io_p6h);
	DECLARE_WRITE_LINE_MEMBER(tx0_io_p7h);
	DECLARE_WRITE_LINE_MEMBER(tx0_io_prt);
	DECLARE_WRITE_LINE_MEMBER(tx0_io_dis);
	DECLARE_WRITE_LINE_MEMBER(tx0_sel);
	DECLARE_WRITE_LINE_MEMBER(tx0_io_reset_callback);
	void magtape_callback();

	void tx0_64kw(machine_config &config);
	void tx0_8kw(machine_config &config);
	void tx0_64kw_map(address_map &map);
	void tx0_8kw_map(address_map &map);
private:
	required_device<gfxdecode_device> m_gfxdecode;
	required_device<palette_device> m_palette;
	required_device<crt_device> m_crt;
	required_ioport m_csw;
	required_ioport_array<4> m_twr;
};

/* defines for each bit and mask in input port "CSW" */
enum
{
	/* bit numbers */
	tx0_control_bit     = 0,

	tx0_stop_c0_bit     = 1,
	tx0_stop_c1_bit     = 2,
	tx0_gbl_cm_sel_bit  = 3,
	tx0_stop_bit        = 4,
	tx0_restart_bit     = 5,
	tx0_read_in_bit     = 6,

	tx0_toggle_dn_bit   = 12,
	tx0_toggle_up_bit   = 13,
	tx0_cm_sel_bit      = 14,
	tx0_lr_sel_bit      = 15,

	/* masks */
	tx0_control = (1 << tx0_control_bit),

	tx0_stop_cyc0 = (1 << tx0_stop_c0_bit),
	tx0_stop_cyc1 = (1 << tx0_stop_c1_bit),
	tx0_gbl_cm_sel = (1 << tx0_gbl_cm_sel_bit),
	tx0_stop = (1 << tx0_stop_bit),
	tx0_restart = (1 << tx0_restart_bit),
	tx0_read_in = (1 << tx0_read_in_bit),

	tx0_toggle_dn = (1 << tx0_toggle_dn_bit),
	tx0_toggle_up = (1 << tx0_toggle_up_bit),
	tx0_cm_sel = (1 << tx0_cm_sel_bit),
	tx0_lr_sel = (1 << tx0_lr_sel_bit)
};

/* defines for our font */
enum
{
	tx0_charnum = /*96*/128,    /* ASCII set + xx special characters */
									/* for whatever reason, 96 breaks some characters */

	tx0_fontdata_size = 8 * tx0_charnum
};

enum
{
	/* size and position of crt window */
	crt_window_width = /*511*/512,
	crt_window_height = /*511*/512,
	crt_window_offset_x = 0,
	crt_window_offset_y = 0,
	/* size and position of operator control panel window */
	panel_window_width = 272,
	panel_window_height = 264,
	panel_window_offset_x = crt_window_width,
	panel_window_offset_y = 0,
	/* size and position of typewriter window */
	typewriter_window_width = 640,
	typewriter_window_height = 160,
	typewriter_window_offset_x = 0,
	typewriter_window_offset_y = crt_window_height
};

enum
{
	total_width = crt_window_width + panel_window_width,
	total_height = crt_window_height + typewriter_window_height,

	/* respect 4:3 aspect ratio to keep pixels square */
	virtual_width_1 = ((total_width+3)/4)*4,
	virtual_height_1 = ((total_height+2)/3)*3,
	virtual_width_2 = virtual_height_1*4/3,
	virtual_height_2 = virtual_width_1*3/4,
	virtual_width = (virtual_width_1 > virtual_width_2) ? virtual_width_1 : virtual_width_2,
	virtual_height = (virtual_height_1 > virtual_height_2) ? virtual_height_1 : virtual_height_2
};

enum
{   /* refresh rate in Hz: can be changed at will */
	refresh_rate = 60
};

/* Color codes */
enum
{
	/* first pen_crt_num_levels colors used for CRT (with remanence) */
	pen_crt_num_levels = 69,
	pen_crt_max_intensity = pen_crt_num_levels-1,

	/* next colors used for control panel and typewriter */
	pen_black = pen_crt_num_levels,
	pen_white,
	pen_green,
	pen_dk_green,
	pen_red,
	pen_lt_gray,

	/* color constants for control panel */
	pen_panel_bg = pen_black,
	pen_panel_caption = pen_white,
	color_panel_caption = 0,
	pen_switch_nut = pen_lt_gray,
	pen_switch_button = pen_white,
	pen_lit_lamp = pen_green,
	pen_unlit_lamp = pen_dk_green,

	/* color constants for typewriter */
	pen_typewriter_bg = pen_white,
	color_typewriter_black = 1,     /* palette 1 = black on white */
	color_typewriter_red = 2,       /* palette 2 = red on white */

	/* color constants used for light pen */
	pen_lightpen_nonpressed = pen_red,
	pen_lightpen_pressed = pen_green
};


#endif // MAME_INCLUDES_TX0_H