summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/bus/a2bus/agat7ports.cpp
blob: d284ad2a9359fd08c6b01cc4e3ef3a950719c54b (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
// license:BSD-3-Clause
// copyright-holders:Sergey Svishchev
/*********************************************************************

    agat7_ports.c

    Implementation of the Agat-7 ports card (part number 3.089.106),
    configured as a printer port for Agat-Author text editor.

    To do: other configurations, if any.

    References:
    http://agatcomp.ru/Reading/ebooks-IKP-KPON/KPON.9/V1/AGAWT/SPT:prilojenie2.shtml

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

#include "emu.h"
#include "agat7ports.h"

//#define VERBOSE 1
#include "logmacro.h"

/***************************************************************************
    PARAMETERS
***************************************************************************/

//**************************************************************************
//  GLOBAL VARIABLES
//**************************************************************************

DEFINE_DEVICE_TYPE(A2BUS_AGAT7_PORTS, a2bus_agat7_ports_device, "a7ports", "Agat-7 Ports Card")

static INPUT_PORTS_START( agat_author )
	PORT_START("PRINTER_CFG")
	PORT_BIT(     0xd9, 0x00, IPT_UNUSED )
	PORT_DIPNAME( 0x02, 0x00, "Printer command set")
	PORT_DIPSETTING(    0x00, "CPA-80/FX-85/Gemini" )
	PORT_DIPSETTING(    0x02, "Mera D100" )
	PORT_DIPNAME( 0x24, 0x00, "Printer character set")
	PORT_DIPSETTING(    0x00, "KOI-8" )
	PORT_DIPSETTING(    0x04, "GOST" )
	PORT_DIPSETTING(    0x20, "CPA-80" )
	PORT_DIPSETTING(    0x24, "FX-85" )
INPUT_PORTS_END

/***************************************************************************
    FUNCTION PROTOTYPES
***************************************************************************/

//-------------------------------------------------
//  device_add_mconfig - add device configuration
//-------------------------------------------------

void a2bus_agat7_ports_device::device_add_mconfig(machine_config &config)
{
	I8255(config, m_d9);
	m_d9->out_pa_callback().set("cent_data_out", FUNC(output_latch_device::write));
	m_d9->out_pb_callback().set(FUNC(a2bus_agat7_ports_device::write_portb));
	m_d9->in_pc_callback().set(FUNC(a2bus_agat7_ports_device::read_portc));

	CENTRONICS(config, m_centronics, centronics_devices, "printer");
	m_centronics->busy_handler().set(FUNC(a2bus_agat7_ports_device::write_centronics_busy));
	output_latch_device &cent_data_out(OUTPUT_LATCH(config, "cent_data_out"));
	m_centronics->set_output_latch(cent_data_out);

	I8251(config, m_d10, 0);
}

//-------------------------------------------------
//  input_ports - device-specific input ports
//-------------------------------------------------

ioport_constructor a2bus_agat7_ports_device::device_input_ports() const
{
	return INPUT_PORTS_NAME(agat_author);
}


//**************************************************************************
//  LIVE DEVICE
//**************************************************************************

a2bus_agat7_ports_device::a2bus_agat7_ports_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock)
	: device_t(mconfig, type, tag, owner, clock)
	, device_a2bus_card_interface(mconfig, *this)
	, m_printer_cfg(*this, "PRINTER_CFG")
	, m_d9(*this, "d9")
	, m_d10(*this, "d10")
	, m_centronics(*this, "centronics")
{
}

a2bus_agat7_ports_device::a2bus_agat7_ports_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
	a2bus_agat7_ports_device(mconfig, A2BUS_AGAT7_PORTS, tag, owner, clock)
{
}

//-------------------------------------------------
//  device_start - device-specific startup
//-------------------------------------------------

void a2bus_agat7_ports_device::device_start()
{
	save_item(NAME(m_centronics_busy));
}

void a2bus_agat7_ports_device::device_reset()
{
	m_centronics_busy = false;
}

/*-------------------------------------------------
    read_c0nx - called for reads from this card's c0nx space
-------------------------------------------------*/

uint8_t a2bus_agat7_ports_device::read_c0nx(uint8_t offset)
{
	u8 data = 0xff;

	switch (offset & 8)
	{
	case 0:
		data = m_d9->read(offset & 3);
		break;

	case 8:
		data = m_d10->read(offset & 1);
		break;
	}

	return data;
}


/*-------------------------------------------------
    write_c0nx - called for writes to this card's c0nx space
-------------------------------------------------*/

void a2bus_agat7_ports_device::write_c0nx(uint8_t offset, uint8_t data)
{
	switch (offset & 8)
	{
	case 0:
		m_d9->write(offset & 3, data);
		break;

	case 8:
		m_d10->write(offset & 1, data);
		break;
	}
}

/*
 * 0    ODD
 * 1    EVEN
 * 4    INIT
 * 5    STROBE
 * 6    /INIT
 * 7    /STROBE
 */
WRITE8_MEMBER(a2bus_agat7_ports_device::write_portb)
{
	m_centronics->write_strobe(BIT(data, 5));
	m_centronics->write_init(BIT(data, 4));
}

/*
 * 1    dip CNTRLESC (0: CPA-80, FX-85, Gemini.  1: D100)
 * 2    dip ALF0
 * 3    dip A/BR (0: level, BUSY/READY.  1: edge, ACK)
 * 4    dip INVD (1: data are sent inverted)
 * 5    dip ALF1 (00: KOI-8, 01: GOST, 10: CPA-80, 11: FX-85)
 * 6    dip ABRLEV (0: BUSY, /ACK.  1: READY, ACK)
 * 7    ready signal from device
 */
READ8_MEMBER(a2bus_agat7_ports_device::read_portc)
{
	return (m_centronics_busy << 7) | m_printer_cfg->read();
}

WRITE_LINE_MEMBER(a2bus_agat7_ports_device::write_centronics_busy)
{
	m_centronics_busy = state;
}